Commit d0e4b0e2 authored by Joe Downing's avatar Joe Downing Committed by Commit Bot

Remove 'RelayMode' from TransportContext

Since we no longer need to juggle TURN and GTURN ICE configs, we can
remove the relay_mode_ member and code needed for it.  This simplifies
things a bit in preparation for the removal of the ICE Config caching
logic.

Change-Id: Ibcc34368c6f3df943cbcb6b1365bc87d30af2dec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2187201Reviewed-by: default avatarYuwei Huang <yuweih@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#766526}
parent 2622bb33
...@@ -391,8 +391,6 @@ TEST_F(It2MeHostTest, IceConfig) { ...@@ -391,8 +391,6 @@ TEST_F(It2MeHostTest, IceConfig) {
ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_); ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_);
protocol::IceConfig ice_config; protocol::IceConfig ice_config;
GetHost()->transport_context_for_tests()->set_relay_mode(
protocol::TransportContext::TURN);
GetHost()->transport_context_for_tests()->GetIceConfig( GetHost()->transport_context_for_tests()->GetIceConfig(
base::Bind(&ReceiveIceConfig, &ice_config)); base::Bind(&ReceiveIceConfig, &ice_config));
EXPECT_EQ(ice_config.stun_servers[0].hostname(), kTestStunServer); EXPECT_EQ(ice_config.stun_servers[0].hostname(), kTestStunServer);
......
...@@ -88,20 +88,20 @@ void TransportContext::Prepare() { ...@@ -88,20 +88,20 @@ void TransportContext::Prepare() {
void TransportContext::GetIceConfig(const GetIceConfigCallback& callback) { void TransportContext::GetIceConfig(const GetIceConfigCallback& callback) {
EnsureFreshIceConfig(); EnsureFreshIceConfig();
// If there is a pending |ice_config_request_| for the current |relay_mode_| // If there is a pending |ice_config_request_| then delay the callback until
// then delay the callback until the request is finished. // the request is finished.
if (ice_config_request_[relay_mode_]) { if (ice_config_request_) {
pending_ice_config_callbacks_[relay_mode_].push_back(callback); pending_ice_config_callbacks_.push_back(callback);
} else { } else {
HOST_LOG << "Using cached ICE Config."; HOST_LOG << "Using cached ICE Config.";
PrintIceConfig(ice_config_[relay_mode_]); PrintIceConfig(ice_config_);
callback.Run(ice_config_[relay_mode_]); callback.Run(ice_config_);
} }
} }
void TransportContext::EnsureFreshIceConfig() { void TransportContext::EnsureFreshIceConfig() {
// Check if request is already pending. // Check if request is already pending.
if (ice_config_request_[relay_mode_]) { if (ice_config_request_) {
HOST_LOG << "ICE Config request is already pending."; HOST_LOG << "ICE Config request is already pending.";
return; return;
} }
...@@ -113,34 +113,26 @@ void TransportContext::EnsureFreshIceConfig() { ...@@ -113,34 +113,26 @@ void TransportContext::EnsureFreshIceConfig() {
return; return;
} }
if (ice_config_[relay_mode_].is_null() || if ((base::Time::Now() + kMinimumIceConfigLifetime) >
base::Time::Now() + kMinimumIceConfigLifetime > ice_config_.expiration_time) {
ice_config_[relay_mode_].expiration_time) {
std::unique_ptr<IceConfigRequest> request;
switch (relay_mode_) {
case RelayMode::TURN:
#if defined(OS_NACL) #if defined(OS_NACL)
NOTREACHED() << "TURN is not supported on NACL"; NOTREACHED() << "TURN is not supported on NACL";
#else #else
request = std::make_unique<RemotingIceConfigRequest>(); ice_config_request_ = std::make_unique<RemotingIceConfigRequest>();
ice_config_request_->Send(
base::BindOnce(&TransportContext::OnIceConfig, base::Unretained(this)));
#endif #endif
break;
}
ice_config_request_[relay_mode_] = std::move(request);
ice_config_request_[relay_mode_]->Send(base::BindOnce(
&TransportContext::OnIceConfig, base::Unretained(this), relay_mode_));
} }
} }
void TransportContext::OnIceConfig(RelayMode relay_mode, void TransportContext::OnIceConfig(const IceConfig& ice_config) {
const IceConfig& ice_config) { ice_config_ = ice_config;
ice_config_[relay_mode] = ice_config; ice_config_request_.reset();
ice_config_request_[relay_mode].reset();
HOST_LOG << "Using newly requested ICE Config:"; HOST_LOG << "Using newly requested ICE Config:";
PrintIceConfig(ice_config); PrintIceConfig(ice_config);
auto& callback_list = pending_ice_config_callbacks_[relay_mode]; auto& callback_list = pending_ice_config_callbacks_;
while (!callback_list.empty()) { while (!callback_list.empty()) {
callback_list.begin()->Run(ice_config); callback_list.begin()->Run(ice_config);
callback_list.pop_front(); callback_list.pop_front();
...@@ -148,8 +140,7 @@ void TransportContext::OnIceConfig(RelayMode relay_mode, ...@@ -148,8 +140,7 @@ void TransportContext::OnIceConfig(RelayMode relay_mode,
} }
int TransportContext::GetTurnMaxRateKbps() const { int TransportContext::GetTurnMaxRateKbps() const {
DCHECK_EQ(relay_mode_, RelayMode::TURN); return ice_config_.max_bitrate_kbps;
return ice_config_[RelayMode::TURN].max_bitrate_kbps;
} }
} // namespace protocol } // namespace protocol
......
...@@ -35,14 +35,6 @@ class IceConfigRequest; ...@@ -35,14 +35,6 @@ class IceConfigRequest;
// TURN configuration. // TURN configuration.
class TransportContext : public base::RefCountedThreadSafe<TransportContext> { class TransportContext : public base::RefCountedThreadSafe<TransportContext> {
public: public:
// TODO(yuweih): See if we still need this enum.
enum RelayMode {
TURN,
LAST_RELAYMODE = TURN
};
static const int kNumRelayModes = RelayMode::LAST_RELAYMODE + 1;
typedef base::Callback<void(const IceConfig& ice_config)> typedef base::Callback<void(const IceConfig& ice_config)>
GetIceConfigCallback; GetIceConfigCallback;
...@@ -54,13 +46,9 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { ...@@ -54,13 +46,9 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> {
TransportRole role); TransportRole role);
void set_turn_ice_config(const IceConfig& ice_config) { void set_turn_ice_config(const IceConfig& ice_config) {
ice_config_[TURN] = ice_config; ice_config_ = ice_config;
} }
// Sets relay mode for all future calls of GetIceConfig(). Doesn't affect
// previous GetIceConfig() requests.
void set_relay_mode(RelayMode relay_mode) { relay_mode_ = relay_mode; }
// Sets a reference to the NetworkManager that holds the list of // Sets a reference to the NetworkManager that holds the list of
// network interfaces. If the NetworkManager is deleted while this // network interfaces. If the NetworkManager is deleted while this
// TransportContext is live, the caller should set this to nullptr. // TransportContext is live, the caller should set this to nullptr.
...@@ -98,25 +86,20 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { ...@@ -98,25 +86,20 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> {
~TransportContext(); ~TransportContext();
void EnsureFreshIceConfig(); void EnsureFreshIceConfig();
void OnIceConfig(RelayMode relay_mode, const IceConfig& ice_config); void OnIceConfig(const IceConfig& ice_config);
std::unique_ptr<PortAllocatorFactory> port_allocator_factory_; std::unique_ptr<PortAllocatorFactory> port_allocator_factory_;
std::unique_ptr<UrlRequestFactory> url_request_factory_; std::unique_ptr<UrlRequestFactory> url_request_factory_;
NetworkSettings network_settings_; NetworkSettings network_settings_;
TransportRole role_; TransportRole role_;
RelayMode relay_mode_ = RelayMode::TURN;
rtc::NetworkManager* network_manager_ = nullptr; rtc::NetworkManager* network_manager_ = nullptr;
std::array<std::unique_ptr<IceConfigRequest>, kNumRelayModes> std::unique_ptr<IceConfigRequest> ice_config_request_;
ice_config_request_; IceConfig ice_config_ = {};
std::array<IceConfig, kNumRelayModes> ice_config_;
// When there is an active |ice_config_request_| stores list of callbacks to // Called once |ice_config_request_| completes.
// be called once the request is finished. std::list<GetIceConfigCallback> pending_ice_config_callbacks_;
std::array<std::list<GetIceConfigCallback>, kNumRelayModes>
pending_ice_config_callbacks_;
DISALLOW_COPY_AND_ASSIGN(TransportContext); DISALLOW_COPY_AND_ASSIGN(TransportContext);
}; };
......
...@@ -404,8 +404,6 @@ WebrtcTransport::WebrtcTransport( ...@@ -404,8 +404,6 @@ WebrtcTransport::WebrtcTransport(
: transport_context_(transport_context), : transport_context_(transport_context),
event_handler_(event_handler), event_handler_(event_handler),
handshake_hmac_(crypto::HMAC::SHA256) { handshake_hmac_(crypto::HMAC::SHA256) {
transport_context_->set_relay_mode(TransportContext::RelayMode::TURN);
video_encoder_factory_ = new WebrtcDummyVideoEncoderFactory(); video_encoder_factory_ = new WebrtcDummyVideoEncoderFactory();
std::unique_ptr<cricket::PortAllocator> port_allocator = std::unique_ptr<cricket::PortAllocator> port_allocator =
transport_context_->port_allocator_factory()->CreatePortAllocator( transport_context_->port_allocator_factory()->CreatePortAllocator(
......
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