Commit a318c2be authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[remoting][FTL] FTL signaling integration into remoting_me2me_host

* Implement a MuxingSignalStrategy to be used exclusively by
  JingleSessionManager to handle messages from both signal strategies.
* Integrate all the signaling stuff into remoting_me2me_host, which can
  be enabled by passing a `--enable-ftl-signaling` flag.

This has been tested with ftl_signaling_playground and I'm able to
finish candidate exchange for ~99% of the attempt. I did see one DCHECK
failure when JingleSession receives a duplicated message, but that will
be tracked and fixed in a different bug/CL.

Bug: 947337
Change-Id: Id6a6a183041a2668a0dd31deb735b01ceb4c4aec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1565537
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Reviewed-by: default avatarJoe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652608}
parent 547bbd6a
This diff is collapsed.
...@@ -28,6 +28,8 @@ static_library("signaling") { ...@@ -28,6 +28,8 @@ static_library("signaling") {
"log_to_server.cc", "log_to_server.cc",
"log_to_server.h", "log_to_server.h",
"message_reception_channel.h", "message_reception_channel.h",
"muxing_signal_strategy.cc",
"muxing_signal_strategy.h",
"push_notification_subscriber.cc", "push_notification_subscriber.cc",
"push_notification_subscriber.h", "push_notification_subscriber.h",
"registration_manager.h", "registration_manager.h",
......
...@@ -367,7 +367,10 @@ void FtlSignalStrategy::Core::SendMessage(const SignalingAddress& receiver, ...@@ -367,7 +367,10 @@ void FtlSignalStrategy::Core::SendMessage(const SignalingAddress& receiver,
std::string receiver_registration_id; std::string receiver_registration_id;
bool get_info_result = bool get_info_result =
receiver.GetFtlInfo(&receiver_username, &receiver_registration_id); receiver.GetFtlInfo(&receiver_username, &receiver_registration_id);
DCHECK(get_info_result); if (!get_info_result) {
LOG(DFATAL) << "Receiver is not in FTL address: " << receiver.jid();
return;
}
HOST_LOG << "Sending outgoing stanza:\n" HOST_LOG << "Sending outgoing stanza:\n"
<< "Receiver: " << receiver_username << "\n" << "Receiver: " << receiver_username << "\n"
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/signaling/muxing_signal_strategy.h"
#include <utility>
#include "base/logging.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "remoting/signaling/ftl_signal_strategy.h"
#include "remoting/signaling/xmpp_signal_strategy.h"
#include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
namespace remoting {
MuxingSignalStrategy::MuxingSignalStrategy(
FtlSignalStrategy* ftl_signal_strategy,
XmppSignalStrategy* xmpp_signal_strategy) {
DETACH_FROM_SEQUENCE(sequence_checker_);
ftl_signal_strategy_ = ftl_signal_strategy;
xmpp_signal_strategy_ = xmpp_signal_strategy;
DCHECK(ftl_signal_strategy_);
DCHECK(xmpp_signal_strategy_);
ftl_signal_strategy_->AddListener(this);
xmpp_signal_strategy_->AddListener(this);
}
MuxingSignalStrategy::~MuxingSignalStrategy() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ftl_signal_strategy_->RemoveListener(this);
xmpp_signal_strategy_->RemoveListener(this);
}
const SignalingAddress& MuxingSignalStrategy::GetLocalAddress() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
CHECK(!current_local_address_.empty())
<< "GetLocalAddress() can only be called inside "
<< "OnSignalStrategyIncomingStanza().";
return current_local_address_;
}
void MuxingSignalStrategy::AddListener(SignalStrategy::Listener* listener) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
listeners_.AddObserver(listener);
}
void MuxingSignalStrategy::RemoveListener(SignalStrategy::Listener* listener) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
listeners_.RemoveObserver(listener);
}
bool MuxingSignalStrategy::SendStanza(
std::unique_ptr<jingle_xmpp::XmlElement> stanza) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
SignalStrategy* strategy = SignalStrategyForStanza(stanza.get());
if (!strategy) {
return false;
}
return strategy->SendStanza(std::move(stanza));
}
std::string MuxingSignalStrategy::GetNextId() {
return base::NumberToString(base::RandUint64());
}
SignalStrategy* MuxingSignalStrategy::SignalStrategyForStanza(
const jingle_xmpp::XmlElement* stanza) {
std::string error;
SignalingAddress receiver =
SignalingAddress::Parse(stanza, SignalingAddress::TO, &error);
if (!error.empty()) {
LOG(DFATAL) << "Failed to parse receiver address: " << error;
return nullptr;
}
if (receiver.channel() == SignalingAddress::Channel::FTL) {
return ftl_signal_strategy_;
}
return xmpp_signal_strategy_;
}
void MuxingSignalStrategy::OnSignalStrategyStateChange(State state) {
// This is not needed by JingleSessionManager, and forwarding state change
// from two signal strategies may also cause unexpected behavior, so we just
// silently drop the call.
}
bool MuxingSignalStrategy::OnSignalStrategyIncomingStanza(
const jingle_xmpp::XmlElement* stanza) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
SignalStrategy* strategy = SignalStrategyForStanza(stanza);
DCHECK(current_local_address_.empty());
current_local_address_ = strategy->GetLocalAddress();
bool message_handled = false;
for (auto& listener : listeners_) {
if (listener.OnSignalStrategyIncomingStanza(stanza)) {
message_handled = true;
break;
}
}
current_local_address_ = SignalingAddress();
return message_handled;
}
void MuxingSignalStrategy::Connect() {
NOTREACHED();
}
void MuxingSignalStrategy::Disconnect() {
NOTREACHED();
}
SignalStrategy::State MuxingSignalStrategy::GetState() const {
NOTREACHED();
return State::DISCONNECTED;
}
SignalStrategy::Error MuxingSignalStrategy::GetError() const {
NOTREACHED();
return Error::NETWORK_ERROR;
}
} // namespace remoting
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_SIGNALING_MUXING_SIGNAL_STRATEGY_H_
#define REMOTING_SIGNALING_MUXING_SIGNAL_STRATEGY_H_
#include <memory>
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/sequence_checker.h"
#include "remoting/signaling/signal_strategy.h"
#include "remoting/signaling/signaling_address.h"
namespace remoting {
class FtlSignalStrategy;
class XmppSignalStrategy;
// WARNING: This class is designed to be used exclusively by
// JingleSessionManager on the host during the XMPP->FTL signaling migration
// process. It doesn't support anything other than sending and receiving
// stanzas. Use (Ftl|Xmpp)SignalStrategy directly if possible.
//
// MuxingSignalStrategy multiplexes FtlSignalStrategy and XmppSignalStrategy.
// It can accept stanzas with FTL or XMPP receiver and forward them to the
// proper SignalStrategy.
class MuxingSignalStrategy final : public SignalStrategy,
public SignalStrategy::Listener {
public:
// Raw pointers must outlive |this|.
MuxingSignalStrategy(FtlSignalStrategy* ftl_signal_strategy,
XmppSignalStrategy* xmpp_signal_strategy);
~MuxingSignalStrategy() override;
// SignalStrategy implementations.
// GetLocalAddress() can only be called inside
// OnSignalStrategyIncomingStanza().
const SignalingAddress& GetLocalAddress() const override;
// Note that OnSignalStrategyStateChange() WON'T be called on the listener.
void AddListener(SignalStrategy::Listener* listener) override;
void RemoveListener(SignalStrategy::Listener* listener) override;
bool SendStanza(std::unique_ptr<jingle_xmpp::XmlElement> stanza) override;
std::string GetNextId() override;
private:
SignalStrategy* SignalStrategyForStanza(
const jingle_xmpp::XmlElement* stanza);
// These methods are not supported. Caller should directly call them on the
// underlying signal strategies instead.
void Connect() override;
void Disconnect() override;
State GetState() const override;
Error GetError() const override;
// SignalStrategy::Listener implementations.
void OnSignalStrategyStateChange(State state) override;
bool OnSignalStrategyIncomingStanza(
const jingle_xmpp::XmlElement* stanza) override;
base::ObserverList<SignalStrategy::Listener> listeners_;
FtlSignalStrategy* ftl_signal_strategy_ = nullptr;
XmppSignalStrategy* xmpp_signal_strategy_ = nullptr;
SignalingAddress current_local_address_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(MuxingSignalStrategy);
};
} // namespace remoting
#endif // REMOTING_SIGNALING_MUXING_SIGNAL_STRATEGY_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment