diff --git a/talk/app/webrtc/datachannel_unittest.cc b/talk/app/webrtc/datachannel_unittest.cc index 2b2609753..69060b751 100644 --- a/talk/app/webrtc/datachannel_unittest.cc +++ b/talk/app/webrtc/datachannel_unittest.cc @@ -44,20 +44,22 @@ const uint32 kFakeSsrc = 1; class CreateSessionDescriptionObserverForTest : public talk_base::RefCountedObject { public: - CreateSessionDescriptionObserverForTest() : description_(NULL) {} - virtual void OnSuccess(SessionDescriptionInterface* desc) { - description_ = desc; + description_.reset(desc); } virtual void OnFailure(const std::string& error) {} - SessionDescriptionInterface* description() { return description_; } + SessionDescriptionInterface* description() { return description_.get(); } + + SessionDescriptionInterface* ReleaseDescription() { + return description_.release(); + } protected: ~CreateSessionDescriptionObserverForTest() {} private: - SessionDescriptionInterface* description_; + talk_base::scoped_ptr description_; }; class SctpDataChannelTest : public testing::Test { @@ -96,7 +98,8 @@ class SctpDataChannelTest : public testing::Test { session_.CreateOffer(observer.get(), NULL); EXPECT_TRUE_WAIT(observer->description() != NULL, 1000); ASSERT_TRUE(observer->description() != NULL); - ASSERT_TRUE(session_.SetLocalDescription(observer->description(), NULL)); + ASSERT_TRUE(session_.SetLocalDescription(observer->ReleaseDescription(), + NULL)); webrtc_data_channel_ = webrtc::DataChannel::Create(&session_, "test", NULL); // Connect to the media channel. diff --git a/talk/app/webrtc/webrtcsdp_unittest.cc b/talk/app/webrtc/webrtcsdp_unittest.cc index 19697d703..9e4c66072 100644 --- a/talk/app/webrtc/webrtcsdp_unittest.cc +++ b/talk/app/webrtc/webrtcsdp_unittest.cc @@ -1118,11 +1118,13 @@ class WebRtcSdpTest : public testing::Test { "a=rtpmap:103 ISAC/16000\r\n" "a=rtpmap:104 CELT/32000/2\r\n" "a=rtpmap:102 ISAC/32000/1\r\n" - "a=fmtp:111 0-15,66,70 "; + "a=fmtp:111 0-15,66,70\r\n" + "a=fmtp:111 "; std::ostringstream os; - os << "minptime=" << params.min_ptime << " stereo=" << params.stereo - << " sprop-stereo=" << params.sprop_stereo - << " useinbandfec=" << params.useinband + os << "minptime=" << params.min_ptime + << "; stereo=" << params.stereo + << "; sprop-stereo=" << params.sprop_stereo + << "; useinbandfec=" << params.useinband << " maxaveragebitrate=" << params.maxaveragebitrate << "\r\n" << "a=ptime:" << params.ptime << "\r\n" << "a=maxptime:" << params.max_ptime << "\r\n"; diff --git a/talk/app/webrtc/webrtcsession_unittest.cc b/talk/app/webrtc/webrtcsession_unittest.cc index 7c8af5216..bcb209a0a 100644 --- a/talk/app/webrtc/webrtcsession_unittest.cc +++ b/talk/app/webrtc/webrtcsession_unittest.cc @@ -210,19 +210,22 @@ class WebRtcSessionCreateSDPObserverForTest kFailed, kSucceeded, }; - WebRtcSessionCreateSDPObserverForTest() - : description_(NULL), state_(kInit) {} + WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {} // CreateSessionDescriptionObserver implementation. virtual void OnSuccess(SessionDescriptionInterface* desc) { - description_ = desc; + description_.reset(desc); state_ = kSucceeded; } virtual void OnFailure(const std::string& error) { state_ = kFailed; } - SessionDescriptionInterface* description() { return description_; } + SessionDescriptionInterface* description() { return description_.get(); } + + SessionDescriptionInterface* ReleaseDescription() { + return description_.release(); + } State state() const { return state_; } @@ -230,7 +233,7 @@ class WebRtcSessionCreateSDPObserverForTest ~WebRtcSessionCreateSDPObserverForTest() {} private: - SessionDescriptionInterface* description_; + talk_base::scoped_ptr description_; State state_; }; @@ -346,7 +349,7 @@ class WebRtcSessionTest : public testing::Test { EXPECT_TRUE_WAIT( observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, 1000); - return observer->description(); + return observer->ReleaseDescription(); } SessionDescriptionInterface* CreateAnswer( @@ -357,7 +360,7 @@ class WebRtcSessionTest : public testing::Test { EXPECT_TRUE_WAIT( observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, 1000); - return observer->description(); + return observer->ReleaseDescription(); } bool ChannelsExist() { diff --git a/talk/p2p/base/dtlstransportchannel.cc b/talk/p2p/base/dtlstransportchannel.cc index 9d6b92e70..6cf400c97 100644 --- a/talk/p2p/base/dtlstransportchannel.cc +++ b/talk/p2p/base/dtlstransportchannel.cc @@ -149,8 +149,12 @@ void DtlsTransportChannelWrapper::Reset() { dtls_state_ = STATE_ACCEPTED; } -bool DtlsTransportChannelWrapper::SetLocalIdentity(talk_base::SSLIdentity* - identity) { +bool DtlsTransportChannelWrapper::SetLocalIdentity( + talk_base::SSLIdentity* identity) { + if (dtls_state_ == STATE_OPEN && identity == local_identity_) { + return true; + } + // TODO(ekr@rtfm.com): Forbid this if Connect() has been called. if (dtls_state_ != STATE_NONE) { LOG_J(LS_ERROR, this) << "Can't set DTLS local identity in this state"; @@ -167,7 +171,7 @@ bool DtlsTransportChannelWrapper::SetLocalIdentity(talk_base::SSLIdentity* return true; } -void DtlsTransportChannelWrapper::SetRole(TransportRole role) { +void DtlsTransportChannelWrapper::SetIceRole(IceRole role) { // TODO(ekr@rtfm.com): Forbid this if Connect() has been called. ASSERT(dtls_state_ < STATE_ACCEPTED); @@ -175,16 +179,24 @@ void DtlsTransportChannelWrapper::SetRole(TransportRole role) { // The endpoint that is the offerer MUST [...] be prepared to receive // a client_hello before it receives the answer. // (IOW, the offerer is the server, and the answerer is the client). - dtls_role_ = (role == ROLE_CONTROLLING) ? + dtls_role_ = (role == ICEROLE_CONTROLLING) ? talk_base::SSL_SERVER : talk_base::SSL_CLIENT; - channel_->SetRole(role); + channel_->SetIceRole(role); } -bool DtlsTransportChannelWrapper::SetRemoteFingerprint(const std::string& - digest_alg, - const uint8* digest, - size_t digest_len) { +bool DtlsTransportChannelWrapper::SetRemoteFingerprint( + const std::string& digest_alg, + const uint8* digest, + size_t digest_len) { + + talk_base::Buffer remote_fingerprint_value(digest, digest_len); + + if ((dtls_state_ == STATE_OPEN) && + (remote_fingerprint_value_ == remote_fingerprint_value)) { + return true; + } + // Allow SetRemoteFingerprint with a NULL digest even if SetLocalIdentity // hasn't been called. if (dtls_state_ > STATE_OFFERED || @@ -200,7 +212,7 @@ bool DtlsTransportChannelWrapper::SetRemoteFingerprint(const std::string& } // At this point we know we are doing DTLS - remote_fingerprint_value_.SetData(digest, digest_len); + remote_fingerprint_value.TransferTo(&remote_fingerprint_value_); remote_fingerprint_algorithm_ = digest_alg; if (!SetupDtls()) { diff --git a/talk/p2p/base/dtlstransportchannel.h b/talk/p2p/base/dtlstransportchannel.h index 395df9ba0..8321024df 100644 --- a/talk/p2p/base/dtlstransportchannel.h +++ b/talk/p2p/base/dtlstransportchannel.h @@ -121,10 +121,10 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { TransportChannelImpl* channel); virtual ~DtlsTransportChannelWrapper(); - virtual void SetRole(TransportRole role); + virtual void SetIceRole(IceRole ice_role); // Returns current transport role of the channel. - virtual TransportRole GetRole() const { - return channel_->GetRole(); + virtual IceRole GetIceRole() const { + return channel_->GetIceRole(); } virtual bool SetLocalIdentity(talk_base::SSLIdentity *identity); @@ -146,10 +146,7 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { virtual bool GetStats(ConnectionInfos* infos) { return channel_->GetStats(infos); } - virtual void SetSessionId(const std::string& session_id) { - channel_->SetSessionId(session_id); - } - virtual const std::string& SessionId() const { + virtual const std::string SessionId() const { return channel_->SessionId(); } @@ -182,8 +179,8 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl { virtual Transport* GetTransport() { return transport_; } - virtual void SetTiebreaker(uint64 tiebreaker) { - channel_->SetTiebreaker(tiebreaker); + virtual void SetIceTiebreaker(uint64 tiebreaker) { + channel_->SetIceTiebreaker(tiebreaker); } virtual void SetIceProtocolType(IceProtocolType type) { channel_->SetIceProtocolType(type); diff --git a/talk/p2p/base/dtlstransportchannel_unittest.cc b/talk/p2p/base/dtlstransportchannel_unittest.cc index 8d124b085..c46839f5e 100644 --- a/talk/p2p/base/dtlstransportchannel_unittest.cc +++ b/talk/p2p/base/dtlstransportchannel_unittest.cc @@ -81,13 +81,14 @@ class DtlsTestClient : public sigslot::has_slots<> { ASSERT(identity_.get() != NULL); use_dtls_srtp_ = true; } - void SetupChannels(int count, cricket::TransportRole role) { + void SetupChannels(int count, cricket::IceRole role) { transport_.reset(new cricket::DtlsTransport( signaling_thread_, worker_thread_, "dtls content name", NULL, identity_.get())); transport_->SetAsync(true); - transport_->SetRole(role); - transport_->SetTiebreaker((role == cricket::ROLE_CONTROLLING) ? 1 : 2); + transport_->SetIceRole(role); + transport_->SetIceTiebreaker( + (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); transport_->SignalWritableState.connect(this, &DtlsTestClient::OnTransportWritableState); @@ -402,8 +403,8 @@ class DtlsTransportChannelTest : public testing::Test { return true; } void Negotiate() { - client1_.SetupChannels(channel_ct_, cricket::ROLE_CONTROLLING); - client2_.SetupChannels(channel_ct_, cricket::ROLE_CONTROLLED); + client1_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLING); + client2_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLED); client2_.Negotiate(&client1_); client1_.Negotiate(&client2_); } @@ -432,13 +433,13 @@ TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); ASSERT_TRUE(channel1 != NULL); ASSERT_TRUE(channel2 != NULL); - EXPECT_EQ(cricket::ROLE_CONTROLLING, channel1->GetRole()); - EXPECT_EQ(1U, channel1->tiebreaker()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); + EXPECT_EQ(1U, channel1->IceTiebreaker()); EXPECT_EQ(cricket::ICEPROTO_RFC5245, channel1->protocol()); EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); - EXPECT_EQ(cricket::ROLE_CONTROLLED, channel2->GetRole()); - EXPECT_EQ(2U, channel2->tiebreaker()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); + EXPECT_EQ(2U, channel2->IceTiebreaker()); EXPECT_EQ(cricket::ICEPROTO_RFC5245, channel2->protocol()); } @@ -451,13 +452,13 @@ TEST_F(DtlsTransportChannelTest, TestChannelSetupGice) { cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); ASSERT_TRUE(channel1 != NULL); ASSERT_TRUE(channel2 != NULL); - EXPECT_EQ(cricket::ROLE_CONTROLLING, channel1->GetRole()); - EXPECT_EQ(1U, channel1->tiebreaker()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); + EXPECT_EQ(1U, channel1->IceTiebreaker()); EXPECT_EQ(cricket::ICEPROTO_GOOGLE, channel1->protocol()); EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); - EXPECT_EQ(cricket::ROLE_CONTROLLED, channel2->GetRole()); - EXPECT_EQ(2U, channel2->tiebreaker()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); + EXPECT_EQ(2U, channel2->IceTiebreaker()); EXPECT_EQ(cricket::ICEPROTO_GOOGLE, channel2->protocol()); } diff --git a/talk/p2p/base/fakesession.h b/talk/p2p/base/fakesession.h index 2146abdf4..6b96c60e6 100644 --- a/talk/p2p/base/fakesession.h +++ b/talk/p2p/base/fakesession.h @@ -67,7 +67,7 @@ class FakeTransportChannel : public TransportChannelImpl, async_(false), identity_(NULL), do_dtls_(false), - role_(ROLE_UNKNOWN), + role_(ICEROLE_UNKNOWN), tiebreaker_(0), ice_proto_(ICEPROTO_HYBRID), remote_ice_mode_(ICEMODE_FULL), @@ -77,7 +77,7 @@ class FakeTransportChannel : public TransportChannelImpl, Reset(); } - uint64 tiebreaker() const { return tiebreaker_; } + uint64 IceTiebreaker() const { return tiebreaker_; } TransportProtocol protocol() const { return ice_proto_; } IceMode remote_ice_mode() const { return remote_ice_mode_; } const std::string& ice_ufrag() const { return ice_ufrag_; } @@ -96,9 +96,9 @@ class FakeTransportChannel : public TransportChannelImpl, return transport_; } - virtual void SetRole(TransportRole role) { role_ = role; } - virtual TransportRole GetRole() const { return role_; } - virtual void SetTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } + virtual void SetIceRole(IceRole role) { role_ = role; } + virtual IceRole GetIceRole() const { return role_; } + virtual void SetIceTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } virtual void SetIceProtocolType(IceProtocolType type) { ice_proto_ = type; } virtual void SetIceCredentials(const std::string& ice_ufrag, const std::string& ice_pwd) { @@ -266,7 +266,7 @@ class FakeTransportChannel : public TransportChannelImpl, bool do_dtls_; std::vector srtp_ciphers_; std::string chosen_srtp_cipher_; - TransportRole role_; + IceRole role_; uint64 tiebreaker_; IceProtocolType ice_proto_; std::string ice_ufrag_; diff --git a/talk/p2p/base/p2ptransportchannel.cc b/talk/p2p/base/p2ptransportchannel.cc index 95a61985c..7a72d1008 100644 --- a/talk/p2p/base/p2ptransportchannel.cc +++ b/talk/p2p/base/p2ptransportchannel.cc @@ -169,7 +169,7 @@ P2PTransportChannel::P2PTransportChannel(const std::string& content_name, was_writable_(false), protocol_type_(ICEPROTO_GOOGLE), remote_ice_mode_(ICEMODE_FULL), - role_(ROLE_UNKNOWN), + ice_role_(ICEROLE_UNKNOWN), tiebreaker_(0), remote_candidate_generation_(0) { } @@ -215,18 +215,18 @@ void P2PTransportChannel::AddConnection(Connection* connection) { this, &P2PTransportChannel::OnUseCandidate); } -void P2PTransportChannel::SetRole(TransportRole role) { +void P2PTransportChannel::SetIceRole(IceRole ice_role) { ASSERT(worker_thread_ == talk_base::Thread::Current()); - if (role_ != role) { - role_ = role; + if (ice_role_ != ice_role) { + ice_role_ = ice_role; for (std::vector::iterator it = ports_.begin(); it != ports_.end(); ++it) { - (*it)->SetRole(role_); + (*it)->SetIceRole(ice_role); } } } -void P2PTransportChannel::SetTiebreaker(uint64 tiebreaker) { +void P2PTransportChannel::SetIceTiebreaker(uint64 tiebreaker) { ASSERT(worker_thread_ == talk_base::Thread::Current()); if (!ports_.empty()) { LOG(LS_ERROR) @@ -362,8 +362,8 @@ void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, // if one is pending. port->SetIceProtocolType(protocol_type_); - port->SetRole(role_); - port->SetTiebreaker(tiebreaker_); + port->SetIceRole(ice_role_); + port->SetIceTiebreaker(tiebreaker_); ports_.push_back(port); port->SignalUnknownAddress.connect( this, &P2PTransportChannel::OnUnknownAddress); @@ -580,7 +580,7 @@ void P2PTransportChannel::OnSignalingReady() { void P2PTransportChannel::OnUseCandidate(Connection* conn) { ASSERT(worker_thread_ == talk_base::Thread::Current()); - ASSERT(role_ == ROLE_CONTROLLED); + ASSERT(ice_role_ == ICEROLE_CONTROLLED); ASSERT(protocol_type_ == ICEPROTO_RFC5245); if (conn->write_state() == Connection::STATE_WRITABLE) { if (best_connection_ != conn) { @@ -887,7 +887,7 @@ void P2PTransportChannel::SortConnections() { // CONTROLLING agent. // If necessary, switch to the new choice. - if (protocol_type_ != ICEPROTO_RFC5245 || role_ == ROLE_CONTROLLING) { + if (protocol_type_ != ICEPROTO_RFC5245 || ice_role_ == ICEROLE_CONTROLLING) { if (ShouldSwitch(best_connection_, top_connection)) SwitchBestConnectionTo(top_connection); } @@ -1121,7 +1121,7 @@ Connection* P2PTransportChannel::FindNextPingableConnection() { void P2PTransportChannel::PingConnection(Connection* conn) { bool use_candidate = false; if (protocol_type_ == ICEPROTO_RFC5245) { - if (remote_ice_mode_ == ICEMODE_FULL && role_ == ROLE_CONTROLLING) { + if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { use_candidate = (conn == best_connection_) || (best_connection_ == NULL) || (!best_connection_->writable()) || @@ -1141,7 +1141,7 @@ void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { // Update the best connection if the state change is from pending best // connection and role is controlled. - if (protocol_type_ == ICEPROTO_RFC5245 && role_ == ROLE_CONTROLLED) { + if (protocol_type_ == ICEPROTO_RFC5245 && ice_role_ == ICEROLE_CONTROLLED) { if (connection == pending_best_connection_ && connection->writable()) { pending_best_connection_ = NULL; SwitchBestConnectionTo(connection); diff --git a/talk/p2p/base/p2ptransportchannel.h b/talk/p2p/base/p2ptransportchannel.h index 420769d3f..74a448380 100644 --- a/talk/p2p/base/p2ptransportchannel.h +++ b/talk/p2p/base/p2ptransportchannel.h @@ -75,9 +75,9 @@ class P2PTransportChannel : public TransportChannelImpl, // From TransportChannelImpl: virtual Transport* GetTransport() { return transport_; } - virtual void SetRole(TransportRole role); - virtual TransportRole GetRole() const { return role_; } - virtual void SetTiebreaker(uint64 tiebreaker); + virtual void SetIceRole(IceRole role); + virtual IceRole GetIceRole() const { return ice_role_; } + virtual void SetIceTiebreaker(uint64 tiebreaker); virtual void SetIceProtocolType(IceProtocolType type); virtual void SetIceCredentials(const std::string& ice_ufrag, const std::string& ice_pwd); @@ -184,7 +184,7 @@ class P2PTransportChannel : public TransportChannelImpl, std::string remote_ice_pwd_; IceProtocolType protocol_type_; IceMode remote_ice_mode_; - TransportRole role_; + IceRole ice_role_; uint64 tiebreaker_; uint32 remote_candidate_generation_; diff --git a/talk/p2p/base/p2ptransportchannel_unittest.cc b/talk/p2p/base/p2ptransportchannel_unittest.cc index e331eac95..32504debb 100644 --- a/talk/p2p/base/p2ptransportchannel_unittest.cc +++ b/talk/p2p/base/p2ptransportchannel_unittest.cc @@ -134,8 +134,8 @@ class P2PTransportChannelTestBase : public testing::Test, socks_server2_(ss_.get(), kSocksProxyAddrs[1], ss_.get(), kSocksProxyAddrs[1]), clear_remote_candidates_ufrag_pwd_(false) { - ep1_.role_ = cricket::ROLE_CONTROLLING; - ep2_.role_ = cricket::ROLE_CONTROLLED; + ep1_.role_ = cricket::ICEROLE_CONTROLLING; + ep2_.role_ = cricket::ICEROLE_CONTROLLED; ep1_.allocator_.reset(new cricket::BasicPortAllocator( &ep1_.network_manager_, kStunAddr, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); @@ -198,7 +198,7 @@ class P2PTransportChannelTestBase : public testing::Test, }; struct Endpoint { - Endpoint() : signaling_delay_(0), role_(cricket::ROLE_UNKNOWN), + Endpoint() : signaling_delay_(0), role_(cricket::ICEROLE_UNKNOWN), tiebreaker_(0), role_conflict_(false), protocol_type_(cricket::ICEPROTO_GOOGLE) {} bool HasChannel(cricket::TransportChannel* ch) { @@ -213,14 +213,14 @@ class P2PTransportChannelTestBase : public testing::Test, } void SetSignalingDelay(int delay) { signaling_delay_ = delay; } - void SetRole(cricket::TransportRole role) { role_ = role; } - cricket::TransportRole role() { return role_; } + void SetIceRole(cricket::IceRole role) { role_ = role; } + cricket::IceRole ice_role() { return role_; } void SetIceProtocolType(cricket::IceProtocolType type) { protocol_type_ = type; } cricket::IceProtocolType protocol_type() { return protocol_type_; } - void SetTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } - uint64 GetTiebreaker() { return tiebreaker_; } + void SetIceTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } + uint64 GetIceTiebreaker() { return tiebreaker_; } void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } bool role_conflict() { return role_conflict_; } void SetAllocationStepDelay(uint32 delay) { @@ -235,7 +235,7 @@ class P2PTransportChannelTestBase : public testing::Test, ChannelData cd1_; ChannelData cd2_; int signaling_delay_; - cricket::TransportRole role_; + cricket::IceRole role_; uint64 tiebreaker_; bool role_conflict_; cricket::IceProtocolType protocol_type_; @@ -317,8 +317,8 @@ class P2PTransportChannelTestBase : public testing::Test, // candidates. Some unit tests rely on this not being set. channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); } - channel->SetRole(GetEndpoint(endpoint)->role()); - channel->SetTiebreaker(GetEndpoint(endpoint)->GetTiebreaker()); + channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); + channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); channel->Connect(); return channel; } @@ -389,11 +389,11 @@ class P2PTransportChannelTestBase : public testing::Test, void SetIceProtocol(int endpoint, cricket::IceProtocolType type) { GetEndpoint(endpoint)->SetIceProtocolType(type); } - void SetIceRole(int endpoint, cricket::TransportRole role) { - GetEndpoint(endpoint)->SetRole(role); + void SetIceRole(int endpoint, cricket::IceRole role) { + GetEndpoint(endpoint)->SetIceRole(role); } - void SetTiebreaker(int endpoint, uint64 tiebreaker) { - GetEndpoint(endpoint)->SetTiebreaker(tiebreaker); + void SetIceTiebreaker(int endpoint, uint64 tiebreaker) { + GetEndpoint(endpoint)->SetIceTiebreaker(tiebreaker); } bool GetRoleConflict(int endpoint) { return GetEndpoint(endpoint)->role_conflict(); @@ -557,11 +557,11 @@ class P2PTransportChannelTestBase : public testing::Test, void TestSignalRoleConflict() { SetIceProtocol(0, cricket::ICEPROTO_RFC5245); - SetTiebreaker(0, kTiebreaker1); // Default EP1 is in controlling state. + SetIceTiebreaker(0, kTiebreaker1); // Default EP1 is in controlling state. SetIceProtocol(1, cricket::ICEPROTO_RFC5245); - SetIceRole(1, cricket::ROLE_CONTROLLING); - SetTiebreaker(1, kTiebreaker2); + SetIceRole(1, cricket::ICEROLE_CONTROLLING); + SetIceTiebreaker(1, kTiebreaker2); // Creating channels with both channels role set to CONTROLLING. CreateChannels(1); @@ -613,10 +613,10 @@ class P2PTransportChannelTestBase : public testing::Test, } void OnRoleConflict(cricket::TransportChannelImpl* channel) { GetEndpoint(channel)->OnRoleConflict(true); - cricket::TransportRole new_role = - GetEndpoint(channel)->role() == cricket::ROLE_CONTROLLING ? - cricket::ROLE_CONTROLLED : cricket::ROLE_CONTROLLING; - channel->SetRole(new_role); + cricket::IceRole new_role = + GetEndpoint(channel)->ice_role() == cricket::ICEROLE_CONTROLLING ? + cricket::ICEROLE_CONTROLLED : cricket::ICEROLE_CONTROLLING; + channel->SetIceRole(new_role); } int SendData(cricket::TransportChannel* channel, const char* data, size_t len) { @@ -1455,18 +1455,18 @@ TEST_F(P2PTransportChannelTest, TestIceRoleConflictWithBundle) { TestSignalRoleConflict(); } -// Tests that the ice configs (protocol, tiebreaker and role can be passed down -// to ports. +// Tests that the ice configs (protocol, tiebreaker and role) can be passed +// down to ports. TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) { AddAddress(0, kPublicAddrs[0]); AddAddress(1, kPublicAddrs[1]); - SetIceRole(0, cricket::ROLE_CONTROLLING); + SetIceRole(0, cricket::ICEROLE_CONTROLLING); SetIceProtocol(0, cricket::ICEPROTO_GOOGLE); - SetTiebreaker(0, kTiebreaker1); - SetIceRole(1, cricket::ROLE_CONTROLLING); + SetIceTiebreaker(0, kTiebreaker1); + SetIceRole(1, cricket::ICEROLE_CONTROLLING); SetIceProtocol(1, cricket::ICEPROTO_RFC5245); - SetTiebreaker(1, kTiebreaker2); + SetIceTiebreaker(1, kTiebreaker2); CreateChannels(1); @@ -1474,22 +1474,22 @@ TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) { const std::vector ports_before = ep1_ch1()->ports(); for (size_t i = 0; i < ports_before.size(); ++i) { - EXPECT_EQ(cricket::ROLE_CONTROLLING, ports_before[i]->Role()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); EXPECT_EQ(cricket::ICEPROTO_GOOGLE, ports_before[i]->IceProtocol()); - EXPECT_EQ(kTiebreaker1, ports_before[i]->Tiebreaker()); + EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); } - ep1_ch1()->SetRole(cricket::ROLE_CONTROLLED); + ep1_ch1()->SetIceRole(cricket::ICEROLE_CONTROLLED); ep1_ch1()->SetIceProtocolType(cricket::ICEPROTO_RFC5245); - ep1_ch1()->SetTiebreaker(kTiebreaker2); + ep1_ch1()->SetIceTiebreaker(kTiebreaker2); const std::vector ports_after = ep1_ch1()->ports(); for (size_t i = 0; i < ports_after.size(); ++i) { - EXPECT_EQ(cricket::ROLE_CONTROLLED, ports_before[i]->Role()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); EXPECT_EQ(cricket::ICEPROTO_RFC5245, ports_before[i]->IceProtocol()); - // SetTiebreaker after Connect() has been called will fail. So expect the + // SetIceTiebreaker after Connect() has been called will fail. So expect the // original value. - EXPECT_EQ(kTiebreaker1, ports_before[i]->Tiebreaker()); + EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); } EXPECT_TRUE_WAIT(ep1_ch1()->readable() && diff --git a/talk/p2p/base/port.cc b/talk/p2p/base/port.cc index 0f12122e9..b2bfea185 100644 --- a/talk/p2p/base/port.cc +++ b/talk/p2p/base/port.cc @@ -179,7 +179,7 @@ Port::Port(talk_base::Thread* thread, talk_base::Network* network, lifetime_(LT_PRESTART), enable_port_packets_(false), ice_protocol_(ICEPROTO_GOOGLE), - role_(ROLE_UNKNOWN), + ice_role_(ICEROLE_UNKNOWN), tiebreaker_(0), shared_socket_(true) { Construct(); @@ -205,7 +205,7 @@ Port::Port(talk_base::Thread* thread, const std::string& type, lifetime_(LT_PRESTART), enable_port_packets_(false), ice_protocol_(ICEPROTO_GOOGLE), - role_(ROLE_UNKNOWN), + ice_role_(ICEROLE_UNKNOWN), tiebreaker_(0), shared_socket_(false) { ASSERT(factory_ != NULL); @@ -490,12 +490,12 @@ bool Port::MaybeIceRoleConflict( const std::string& remote_ufrag) { // Validate ICE_CONTROLLING or ICE_CONTROLLED attributes. bool ret = true; - TransportRole remote_ice_role = ROLE_UNKNOWN; + IceRole remote_ice_role = ICEROLE_UNKNOWN; uint64 remote_tiebreaker = 0; const StunUInt64Attribute* stun_attr = stun_msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); if (stun_attr) { - remote_ice_role = ROLE_CONTROLLING; + remote_ice_role = ICEROLE_CONTROLLING; remote_tiebreaker = stun_attr->value(); } @@ -503,21 +503,21 @@ bool Port::MaybeIceRoleConflict( // tie breaker value received in the ping message matches port // tiebreaker value this must be a loopback call. // We will treat this as valid scenario. - if (remote_ice_role == ROLE_CONTROLLING && + if (remote_ice_role == ICEROLE_CONTROLLING && username_fragment() == remote_ufrag && - remote_tiebreaker == Tiebreaker()) { + remote_tiebreaker == IceTiebreaker()) { return true; } stun_attr = stun_msg->GetUInt64(STUN_ATTR_ICE_CONTROLLED); if (stun_attr) { - remote_ice_role = ROLE_CONTROLLED; + remote_ice_role = ICEROLE_CONTROLLED; remote_tiebreaker = stun_attr->value(); } - switch (role_) { - case ROLE_CONTROLLING: - if (ROLE_CONTROLLING == remote_ice_role) { + switch (ice_role_) { + case ICEROLE_CONTROLLING: + if (ICEROLE_CONTROLLING == remote_ice_role) { if (remote_tiebreaker >= tiebreaker_) { SignalRoleConflict(this); } else { @@ -528,8 +528,8 @@ bool Port::MaybeIceRoleConflict( } } break; - case ROLE_CONTROLLED: - if (ROLE_CONTROLLED == remote_ice_role) { + case ICEROLE_CONTROLLED: + if (ICEROLE_CONTROLLED == remote_ice_role) { if (remote_tiebreaker < tiebreaker_) { SignalRoleConflict(this); } else { @@ -761,9 +761,9 @@ class ConnectionRequest : public StunRequest { // Adding ICE-specific attributes to the STUN request message. if (connection_->port()->IsStandardIce()) { // Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role. - if (connection_->port()->Role() == ROLE_CONTROLLING) { + if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) { request->AddAttribute(new StunUInt64Attribute( - STUN_ATTR_ICE_CONTROLLING, connection_->port()->Tiebreaker())); + STUN_ATTR_ICE_CONTROLLING, connection_->port()->IceTiebreaker())); // Since we are trying aggressive nomination, sending USE-CANDIDATE // attribute in every ping. // If we are dealing with a ice-lite end point, nomination flag @@ -773,9 +773,9 @@ class ConnectionRequest : public StunRequest { request->AddAttribute(new StunByteStringAttribute( STUN_ATTR_USE_CANDIDATE)); } - } else if (connection_->port()->Role() == ROLE_CONTROLLED) { + } else if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLED) { request->AddAttribute(new StunUInt64Attribute( - STUN_ATTR_ICE_CONTROLLED, connection_->port()->Tiebreaker())); + STUN_ATTR_ICE_CONTROLLED, connection_->port()->IceTiebreaker())); } else { ASSERT(false); } @@ -856,11 +856,11 @@ uint64 Connection::priority() const { // agent. Let D be the priority for the candidate provided by the // controlled agent. // pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0) - TransportRole role = port_->Role(); - if (role != ROLE_UNKNOWN) { + IceRole role = port_->GetIceRole(); + if (role != ICEROLE_UNKNOWN) { uint32 g = 0; uint32 d = 0; - if (role == ROLE_CONTROLLING) { + if (role == ICEROLE_CONTROLLING) { g = local_candidate().priority(); d = remote_candidate_.priority(); } else { @@ -977,7 +977,7 @@ void Connection::OnReadPacket(const char* data, size_t size) { set_write_state(STATE_WRITE_INIT); if ((port_->IsStandardIce()) && - (port_->Role() == ROLE_CONTROLLED)) { + (port_->GetIceRole() == ICEROLE_CONTROLLED)) { const StunByteStringAttribute* use_candidate_attr = msg->GetByteString(STUN_ATTR_USE_CANDIDATE); if (use_candidate_attr) diff --git a/talk/p2p/base/port.h b/talk/p2p/base/port.h index c1021c72b..f533f627b 100644 --- a/talk/p2p/base/port.h +++ b/talk/p2p/base/port.h @@ -142,11 +142,11 @@ class Port : public PortInterface, public talk_base::MessageHandler, virtual IceProtocolType IceProtocol() const { return ice_protocol_; } // Methods to set/get ICE role and tiebreaker values. - void SetRole(TransportRole role) { role_ = role; } - TransportRole Role() const { return role_; } + IceRole GetIceRole() const { return ice_role_; } + void SetIceRole(IceRole role) { ice_role_ = role; } - void SetTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } - uint64 Tiebreaker() const { return tiebreaker_; } + void SetIceTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } + uint64 IceTiebreaker() const { return tiebreaker_; } virtual bool SharedSocket() const { return shared_socket_; } @@ -369,7 +369,7 @@ class Port : public PortInterface, public talk_base::MessageHandler, enum Lifetime { LT_PRESTART, LT_PRETIMEOUT, LT_POSTTIMEOUT } lifetime_; bool enable_port_packets_; IceProtocolType ice_protocol_; - TransportRole role_; + IceRole ice_role_; uint64 tiebreaker_; bool shared_socket_; diff --git a/talk/p2p/base/port_unittest.cc b/talk/p2p/base/port_unittest.cc index 2feeee2ed..cecefdaee 100644 --- a/talk/p2p/base/port_unittest.cc +++ b/talk/p2p/base/port_unittest.cc @@ -548,12 +548,12 @@ class PortTest : public testing::Test, public sigslot::has_slots<> { const std::string& username, const std::string& password, cricket::IceProtocolType type, - cricket::TransportRole role, + cricket::IceRole role, int tiebreaker) { TestPort* port = CreateTestPort(addr, username, password); port->SetIceProtocolType(type); - port->SetRole(role); - port->SetTiebreaker(tiebreaker); + port->SetIceRole(role); + port->SetIceTiebreaker(tiebreaker); return port; } @@ -1013,27 +1013,27 @@ TEST_F(PortTest, TestSslTcpToSslTcpRelay) { TEST_F(PortTest, TestLocalToLocalAsIce) { SetIceProtocolType(cricket::ICEPROTO_RFC5245); UDPPort* port1 = CreateUdpPort(kLocalAddr1); - port1->SetRole(cricket::ROLE_CONTROLLING); - port1->SetTiebreaker(kTiebreaker1); + port1->SetIceRole(cricket::ICEROLE_CONTROLLING); + port1->SetIceTiebreaker(kTiebreaker1); ASSERT_EQ(cricket::ICEPROTO_RFC5245, port1->IceProtocol()); UDPPort* port2 = CreateUdpPort(kLocalAddr2); - port2->SetRole(cricket::ROLE_CONTROLLED); - port2->SetTiebreaker(kTiebreaker2); + port2->SetIceRole(cricket::ICEROLE_CONTROLLED); + port2->SetIceTiebreaker(kTiebreaker2); ASSERT_EQ(cricket::ICEPROTO_RFC5245, port2->IceProtocol()); // Same parameters as TestLocalToLocal above. TestConnectivity("udp", port1, "udp", port2, true, true, true, true); } // This test is trying to validate a successful and failure scenario in a -// loopback test when protocol is RFC5245. For success tiebreaker, username +// loopback test when protocol is RFC5245. For success IceTiebreaker, username // should remain equal to the request generated by the port and role of port // must be in controlling. TEST_F(PortTest, TestLoopbackCallAsIce) { talk_base::scoped_ptr lport( CreateTestPort(kLocalAddr1, "lfrag", "lpass")); lport->SetIceProtocolType(ICEPROTO_RFC5245); - lport->SetRole(cricket::ROLE_CONTROLLING); - lport->SetTiebreaker(kTiebreaker1); + lport->SetIceRole(cricket::ICEROLE_CONTROLLING); + lport->SetIceTiebreaker(kTiebreaker1); lport->PrepareAddress(); ASSERT_FALSE(lport->Candidates().empty()); Connection* conn = lport->CreateConnection(lport->Candidates()[0], @@ -1049,7 +1049,8 @@ TEST_F(PortTest, TestLoopbackCallAsIce) { msg = lport->last_stun_msg(); EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); - // If the tiebreaker value is different from port, we expect a error response. + // If the tiebreaker value is different from port, we expect a error + // response. lport->Reset(); lport->AddCandidateAddress(kLocalAddr2); // Creating a different connection as |conn| is in STATE_READABLE. @@ -1091,13 +1092,13 @@ TEST_F(PortTest, TestIceRoleConflict) { talk_base::scoped_ptr lport( CreateTestPort(kLocalAddr1, "lfrag", "lpass")); lport->SetIceProtocolType(ICEPROTO_RFC5245); - lport->SetRole(cricket::ROLE_CONTROLLING); - lport->SetTiebreaker(kTiebreaker1); + lport->SetIceRole(cricket::ICEROLE_CONTROLLING); + lport->SetIceTiebreaker(kTiebreaker1); talk_base::scoped_ptr rport( CreateTestPort(kLocalAddr2, "rfrag", "rpass")); rport->SetIceProtocolType(ICEPROTO_RFC5245); - rport->SetRole(cricket::ROLE_CONTROLLING); - rport->SetTiebreaker(kTiebreaker2); + rport->SetIceRole(cricket::ICEROLE_CONTROLLING); + rport->SetIceTiebreaker(kTiebreaker2); lport->PrepareAddress(); rport->PrepareAddress(); @@ -1307,11 +1308,11 @@ TEST_F(PortTest, TestSendStunMessageAsIce) { talk_base::scoped_ptr rport( CreateTestPort(kLocalAddr2, "rfrag", "rpass")); lport->SetIceProtocolType(ICEPROTO_RFC5245); - lport->SetRole(cricket::ROLE_CONTROLLING); - lport->SetTiebreaker(kTiebreaker1); + lport->SetIceRole(cricket::ICEROLE_CONTROLLING); + lport->SetIceTiebreaker(kTiebreaker1); rport->SetIceProtocolType(ICEPROTO_RFC5245); - rport->SetRole(cricket::ROLE_CONTROLLED); - rport->SetTiebreaker(kTiebreaker2); + rport->SetIceRole(cricket::ICEROLE_CONTROLLED); + rport->SetIceTiebreaker(kTiebreaker2); // Send a fake ping from lport to rport. lport->PrepareAddress(); @@ -1342,7 +1343,7 @@ TEST_F(PortTest, TestSendStunMessageAsIce) { const StunUInt64Attribute* ice_controlling_attr = msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); ASSERT_TRUE(ice_controlling_attr != NULL); - EXPECT_EQ(lport->Tiebreaker(), ice_controlling_attr->value()); + EXPECT_EQ(lport->IceTiebreaker(), ice_controlling_attr->value()); EXPECT_TRUE(msg->GetByteString(STUN_ATTR_ICE_CONTROLLED) == NULL); EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); EXPECT_TRUE(msg->GetUInt32(STUN_ATTR_FINGERPRINT) != NULL); @@ -1423,7 +1424,7 @@ TEST_F(PortTest, TestSendStunMessageAsIce) { const StunUInt64Attribute* ice_controlled_attr = msg->GetUInt64(STUN_ATTR_ICE_CONTROLLED); ASSERT_TRUE(ice_controlled_attr != NULL); - EXPECT_EQ(rport->Tiebreaker(), ice_controlled_attr->value()); + EXPECT_EQ(rport->IceTiebreaker(), ice_controlled_attr->value()); EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL); // Request should include ping count. @@ -1449,11 +1450,11 @@ TEST_F(PortTest, TestUseCandidateAttribute) { talk_base::scoped_ptr rport( CreateTestPort(kLocalAddr2, "rfrag", "rpass")); lport->SetIceProtocolType(ICEPROTO_RFC5245); - lport->SetRole(cricket::ROLE_CONTROLLING); - lport->SetTiebreaker(kTiebreaker1); + lport->SetIceRole(cricket::ICEROLE_CONTROLLING); + lport->SetIceTiebreaker(kTiebreaker1); rport->SetIceProtocolType(ICEPROTO_RFC5245); - rport->SetRole(cricket::ROLE_CONTROLLED); - rport->SetTiebreaker(kTiebreaker2); + rport->SetIceRole(cricket::ICEROLE_CONTROLLED); + rport->SetIceTiebreaker(kTiebreaker2); // Send a fake ping from lport to rport. lport->PrepareAddress(); @@ -1834,8 +1835,8 @@ TEST_F(PortTest, TestHandleStunBindingIndication) { talk_base::scoped_ptr lport( CreateTestPort(kLocalAddr2, "lfrag", "lpass")); lport->SetIceProtocolType(ICEPROTO_RFC5245); - lport->SetRole(cricket::ROLE_CONTROLLING); - lport->SetTiebreaker(kTiebreaker1); + lport->SetIceRole(cricket::ICEROLE_CONTROLLING); + lport->SetIceTiebreaker(kTiebreaker1); // Verifying encoding and decoding STUN indication message. talk_base::scoped_ptr in_msg, out_msg; @@ -1857,8 +1858,8 @@ TEST_F(PortTest, TestHandleStunBindingIndication) { talk_base::scoped_ptr rport( CreateTestPort(kLocalAddr2, "rfrag", "rpass")); rport->SetIceProtocolType(ICEPROTO_RFC5245); - rport->SetRole(cricket::ROLE_CONTROLLED); - rport->SetTiebreaker(kTiebreaker2); + rport->SetIceRole(cricket::ICEROLE_CONTROLLED); + rport->SetIceTiebreaker(kTiebreaker2); lport->PrepareAddress(); rport->PrepareAddress(); @@ -1928,16 +1929,16 @@ TEST_F(PortTest, TestComputeCandidatePriority) { TEST_F(PortTest, TestPortProxyProperties) { talk_base::scoped_ptr port( CreateTestPort(kLocalAddr1, "name", "pass")); - port->SetRole(cricket::ROLE_CONTROLLING); - port->SetTiebreaker(kTiebreaker1); + port->SetIceRole(cricket::ICEROLE_CONTROLLING); + port->SetIceTiebreaker(kTiebreaker1); // Create a proxy port. talk_base::scoped_ptr proxy(new PortProxy()); proxy->set_impl(port.get()); EXPECT_EQ(port->Type(), proxy->Type()); EXPECT_EQ(port->Network(), proxy->Network()); - EXPECT_EQ(port->Role(), proxy->Role()); - EXPECT_EQ(port->Tiebreaker(), proxy->Tiebreaker()); + EXPECT_EQ(port->GetIceRole(), proxy->GetIceRole()); + EXPECT_EQ(port->IceTiebreaker(), proxy->IceTiebreaker()); } // In the case of shared socket, one port may be shared by local and stun. @@ -2080,8 +2081,8 @@ TEST_F(PortTest, TestConnectionPriority) { // RFC 5245 // pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0) - lport->SetRole(cricket::ROLE_CONTROLLING); - rport->SetRole(cricket::ROLE_CONTROLLED); + lport->SetIceRole(cricket::ICEROLE_CONTROLLING); + rport->SetIceRole(cricket::ICEROLE_CONTROLLED); Connection* lconn = lport->CreateConnection( rport->Candidates()[0], Port::ORIGIN_MESSAGE); #if defined(WIN32) @@ -2090,8 +2091,8 @@ TEST_F(PortTest, TestConnectionPriority) { EXPECT_EQ(0x2001EE9FC003D0BLLU, lconn->priority()); #endif - lport->SetRole(cricket::ROLE_CONTROLLED); - rport->SetRole(cricket::ROLE_CONTROLLING); + lport->SetIceRole(cricket::ICEROLE_CONTROLLED); + rport->SetIceRole(cricket::ICEROLE_CONTROLLING); Connection* rconn = rport->CreateConnection( lport->Candidates()[0], Port::ORIGIN_MESSAGE); #if defined(WIN32) @@ -2200,11 +2201,11 @@ TEST_F(PortTest, TestTimeoutForNeverWritable) { TEST_F(PortTest, TestIceLiteConnectivity) { TestPort* ice_full_port = CreateTestPort( kLocalAddr1, "lfrag", "lpass", cricket::ICEPROTO_RFC5245, - cricket::ROLE_CONTROLLING, kTiebreaker1); + cricket::ICEROLE_CONTROLLING, kTiebreaker1); talk_base::scoped_ptr ice_lite_port(CreateTestPort( kLocalAddr2, "rfrag", "rpass", cricket::ICEPROTO_RFC5245, - cricket::ROLE_CONTROLLED, kTiebreaker2)); + cricket::ICEROLE_CONTROLLED, kTiebreaker2)); // Setup TestChannel. This behaves like FULL mode client. TestChannel ch1(ice_full_port, ice_lite_port.get()); ch1.SetIceMode(ICEMODE_FULL); diff --git a/talk/p2p/base/portinterface.h b/talk/p2p/base/portinterface.h index ec34bf135..b956f9abe 100644 --- a/talk/p2p/base/portinterface.h +++ b/talk/p2p/base/portinterface.h @@ -64,11 +64,11 @@ class PortInterface { virtual IceProtocolType IceProtocol() const = 0; // Methods to set/get ICE role and tiebreaker values. - virtual void SetRole(TransportRole role) = 0; - virtual TransportRole Role() const = 0; + virtual void SetIceRole(IceRole role) = 0; + virtual IceRole GetIceRole() const = 0; - virtual void SetTiebreaker(uint64 tiebreaker) = 0; - virtual uint64 Tiebreaker() const = 0; + virtual void SetIceTiebreaker(uint64 tiebreaker) = 0; + virtual uint64 IceTiebreaker() const = 0; virtual bool SharedSocket() const = 0; diff --git a/talk/p2p/base/portproxy.cc b/talk/p2p/base/portproxy.cc index 63fd02653..2c6119aa5 100644 --- a/talk/p2p/base/portproxy.cc +++ b/talk/p2p/base/portproxy.cc @@ -58,24 +58,24 @@ IceProtocolType PortProxy::IceProtocol() const { } // Methods to set/get ICE role and tiebreaker values. -void PortProxy::SetRole(TransportRole role) { +void PortProxy::SetIceRole(IceRole role) { ASSERT(impl_ != NULL); - impl_->SetRole(role); + impl_->SetIceRole(role); } -TransportRole PortProxy::Role() const { +IceRole PortProxy::GetIceRole() const { ASSERT(impl_ != NULL); - return impl_->Role(); + return impl_->GetIceRole(); } -void PortProxy::SetTiebreaker(uint64 tiebreaker) { +void PortProxy::SetIceTiebreaker(uint64 tiebreaker) { ASSERT(impl_ != NULL); - impl_->SetTiebreaker(tiebreaker); + impl_->SetIceTiebreaker(tiebreaker); } -uint64 PortProxy::Tiebreaker() const { +uint64 PortProxy::IceTiebreaker() const { ASSERT(impl_ != NULL); - return impl_->Tiebreaker(); + return impl_->IceTiebreaker(); } bool PortProxy::SharedSocket() const { diff --git a/talk/p2p/base/portproxy.h b/talk/p2p/base/portproxy.h index 8653c0972..25808ea36 100644 --- a/talk/p2p/base/portproxy.h +++ b/talk/p2p/base/portproxy.h @@ -52,11 +52,11 @@ class PortProxy : public PortInterface, public sigslot::has_slots<> { virtual IceProtocolType IceProtocol() const; // Methods to set/get ICE role and tiebreaker values. - virtual void SetRole(TransportRole role); - virtual TransportRole Role() const; + virtual void SetIceRole(IceRole role); + virtual IceRole GetIceRole() const; - virtual void SetTiebreaker(uint64 tiebreaker); - virtual uint64 Tiebreaker() const; + virtual void SetIceTiebreaker(uint64 tiebreaker); + virtual uint64 IceTiebreaker() const; virtual bool SharedSocket() const; diff --git a/talk/p2p/base/rawtransportchannel.h b/talk/p2p/base/rawtransportchannel.h index 3c9c33088..0f606b727 100644 --- a/talk/p2p/base/rawtransportchannel.h +++ b/talk/p2p/base/rawtransportchannel.h @@ -74,7 +74,6 @@ class RawTransportChannel : public TransportChannelImpl, const std::string& ice_pwd) {} virtual void SetRemoteIceCredentials(const std::string& ice_ufrag, const std::string& ice_pwd) {} - virtual TransportRole GetRole() const { return ROLE_UNKNOWN; } // Creates an allocator session to start figuring out which type of // port we should send to the other client. This will send @@ -94,8 +93,9 @@ class RawTransportChannel : public TransportChannelImpl, void OnRemoteAddress(const talk_base::SocketAddress& remote_address); // Below ICE specific virtual methods not implemented. - virtual void SetRole(TransportRole role) {} - virtual void SetTiebreaker(uint64 tiebreaker) {} + virtual IceRole GetIceRole() const { return ICEROLE_UNKNOWN; } + virtual void SetIceRole(IceRole role) {} + virtual void SetIceTiebreaker(uint64 tiebreaker) {} virtual void SetIceProtocolType(IceProtocolType type) {} virtual void SetIceUfrag(const std::string& ice_ufrag) {} virtual void SetIcePwd(const std::string& ice_pwd) {} diff --git a/talk/p2p/base/session.cc b/talk/p2p/base/session.cc index d70aaf501..74eda019c 100644 --- a/talk/p2p/base/session.cc +++ b/talk/p2p/base/session.cc @@ -194,7 +194,6 @@ TransportChannelImpl* TransportProxy::GetOrCreateChannelProxyImpl( TransportChannelImpl* impl = transport_->get()->GetChannel(component); if (impl == NULL) { impl = transport_->get()->CreateChannel(component); - impl->SetSessionId(sid_); } return impl; } @@ -239,8 +238,8 @@ bool TransportProxy::SetupMux(TransportProxy* target) { return true; } -void TransportProxy::SetRole(TransportRole role) { - transport_->get()->SetRole(role); +void TransportProxy::SetIceRole(IceRole role) { + transport_->get()->SetIceRole(role); } bool TransportProxy::SetLocalTransportDescription( @@ -471,8 +470,8 @@ TransportProxy* BaseSession::GetOrCreateTransportProxy( return transproxy; Transport* transport = CreateTransport(content_name); - transport->SetRole(initiator_ ? ROLE_CONTROLLING : ROLE_CONTROLLED); - transport->SetTiebreaker(ice_tiebreaker_); + transport->SetIceRole(initiator_ ? ICEROLE_CONTROLLING : ICEROLE_CONTROLLED); + transport->SetIceTiebreaker(ice_tiebreaker_); // TODO: Connect all the Transport signals to TransportProxy // then to the BaseSession. transport->SignalConnecting.connect( @@ -743,8 +742,8 @@ void BaseSession::OnRoleConflict() { for (TransportMap::iterator iter = transports_.begin(); iter != transports_.end(); ++iter) { // Role will be reverse of initial role setting. - TransportRole role = initiator_ ? ROLE_CONTROLLED : ROLE_CONTROLLING; - iter->second->SetRole(role); + IceRole role = initiator_ ? ICEROLE_CONTROLLED : ICEROLE_CONTROLLING; + iter->second->SetIceRole(role); } } diff --git a/talk/p2p/base/session.h b/talk/p2p/base/session.h index af3424065..e05e3c0ac 100644 --- a/talk/p2p/base/session.h +++ b/talk/p2p/base/session.h @@ -140,7 +140,7 @@ class TransportProxy : public sigslot::has_slots<>, bool SetupMux(TransportProxy* proxy); // Simple functions that thunk down to the same functions on Transport. - void SetRole(TransportRole role); + void SetIceRole(IceRole role); void SetIdentity(talk_base::SSLIdentity* identity); bool SetLocalTransportDescription(const TransportDescription& description, ContentAction action); diff --git a/talk/p2p/base/transport.cc b/talk/p2p/base/transport.cc index 1402472b4..6ccd90b02 100644 --- a/talk/p2p/base/transport.cc +++ b/talk/p2p/base/transport.cc @@ -55,7 +55,7 @@ enum { MSG_CONNECTING = 13, MSG_CANDIDATEALLOCATIONCOMPLETE = 14, MSG_ROLECONFLICT = 15, - MSG_SETROLE = 16, + MSG_SETICEROLE = 16, MSG_SETLOCALDESCRIPTION = 17, MSG_SETREMOTEDESCRIPTION = 18, MSG_GETSTATS = 19, @@ -89,10 +89,10 @@ struct TransportDescriptionParams : public talk_base::MessageData { bool result; }; -struct TransportRoleParam : public talk_base::MessageData { - explicit TransportRoleParam(TransportRole role) : role(role) {} +struct IceRoleParam : public talk_base::MessageData { + explicit IceRoleParam(IceRole role) : role(role) {} - TransportRole role; + IceRole role; }; struct StatsParam : public talk_base::MessageData { @@ -125,7 +125,7 @@ Transport::Transport(talk_base::Thread* signaling_thread, writable_(TRANSPORT_STATE_NONE), was_writable_(false), connect_requested_(false), - role_(ROLE_UNKNOWN), + ice_role_(ICEROLE_UNKNOWN), tiebreaker_(0), protocol_(ICEPROTO_HYBRID), remote_ice_mode_(ICEMODE_FULL) { @@ -136,9 +136,9 @@ Transport::~Transport() { ASSERT(destroyed_); } -void Transport::SetRole(TransportRole role) { - TransportRoleParam param(role); - worker_thread()->Send(this, MSG_SETROLE, ¶m); +void Transport::SetIceRole(IceRole role) { + IceRoleParam param(role); + worker_thread()->Send(this, MSG_SETICEROLE, ¶m); } void Transport::SetIdentity(talk_base::SSLIdentity* identity) { @@ -192,8 +192,8 @@ TransportChannelImpl* Transport::CreateChannel_w(int component) { } // Push down our transport state to the new channel. - impl->SetRole(role_); - impl->SetTiebreaker(tiebreaker_); + impl->SetIceRole(ice_role_); + impl->SetIceTiebreaker(tiebreaker_); if (local_description_) { ApplyLocalTransportDescription_w(impl); if (remote_description_) { @@ -599,12 +599,12 @@ void Transport::OnRoleConflict(TransportChannelImpl* channel) { signaling_thread_->Post(this, MSG_ROLECONFLICT); } -void Transport::SetRole_w(TransportRole role) { +void Transport::SetIceRole_w(IceRole role) { talk_base::CritScope cs(&crit_); - role_ = role; + ice_role_ = role; for (ChannelMap::iterator iter = channels_.begin(); iter != channels_.end(); ++iter) { - iter->second->SetRole(role_); + iter->second->SetIceRole(ice_role_); } } @@ -706,11 +706,11 @@ bool Transport::NegotiateTransportDescription_w(ContentAction local_role_) { } protocol_ = answer_proto == ICEPROTO_HYBRID ? ICEPROTO_GOOGLE : answer_proto; - // If transport is in ROLE_CONTROLLED and remote end point supports only + // If transport is in ICEROLE_CONTROLLED and remote end point supports only // ice_lite, this local end point should take CONTROLLING role. - if (role_ == ROLE_CONTROLLED && + if (ice_role_ == ICEROLE_CONTROLLED && remote_description_->ice_mode == ICEMODE_LITE) { - SetRole_w(ROLE_CONTROLLING); + SetIceRole_w(ICEROLE_CONTROLLING); } // Update remote ice_mode to all existing channels. @@ -789,10 +789,10 @@ void Transport::OnMessage(talk_base::Message* msg) { case MSG_ROLECONFLICT: SignalRoleConflict(); break; - case MSG_SETROLE: { - TransportRoleParam* param = - static_cast(msg->pdata); - SetRole_w(param->role); + case MSG_SETICEROLE: { + IceRoleParam* param = + static_cast(msg->pdata); + SetIceRole_w(param->role); } break; case MSG_SETLOCALDESCRIPTION: { diff --git a/talk/p2p/base/transport.h b/talk/p2p/base/transport.h index b712406aa..63c37343a 100644 --- a/talk/p2p/base/transport.h +++ b/talk/p2p/base/transport.h @@ -128,13 +128,6 @@ class TransportParser { virtual ~TransportParser() {} }; -// Whether our side of the call is driving the negotiation, or the other side. -enum TransportRole { - ROLE_CONTROLLING = 0, - ROLE_CONTROLLED, - ROLE_UNKNOWN -}; - // For "writable" and "readable", we need to differentiate between // none, all, and some. enum TransportState { @@ -244,11 +237,11 @@ class Transport : public talk_base::MessageHandler, // Returns whether the client has requested the channels to connect. bool connect_requested() const { return connect_requested_; } - void SetRole(TransportRole role); - TransportRole role() const { return role_; } + void SetIceRole(IceRole role); + IceRole ice_role() const { return ice_role_; } - void SetTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } - uint64 tiebreaker() { return tiebreaker_; } + void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } + uint64 IceTiebreaker() { return tiebreaker_; } // Must be called before applying local session description. void SetIdentity(talk_base::SSLIdentity* identity); @@ -455,7 +448,7 @@ class Transport : public talk_base::MessageHandler, void OnChannelCandidateReady_s(); - void SetRole_w(TransportRole role); + void SetIceRole_w(IceRole role); void SetRemoteIceMode_w(IceMode mode); bool SetLocalTransportDescription_w(const TransportDescription& desc, ContentAction action); @@ -473,7 +466,7 @@ class Transport : public talk_base::MessageHandler, TransportState writable_; bool was_writable_; bool connect_requested_; - TransportRole role_; + IceRole ice_role_; uint64 tiebreaker_; TransportProtocol protocol_; IceMode remote_ice_mode_; diff --git a/talk/p2p/base/transport_unittest.cc b/talk/p2p/base/transport_unittest.cc index 446fda581..f9bebdfa5 100644 --- a/talk/p2p/base/transport_unittest.cc +++ b/talk/p2p/base/transport_unittest.cc @@ -43,7 +43,7 @@ using cricket::Transport; using cricket::FakeTransport; using cricket::TransportChannel; using cricket::FakeTransportChannel; -using cricket::TransportRole; +using cricket::IceRole; using cricket::TransportDescription; using cricket::WriteError; using cricket::ParseError; @@ -139,19 +139,19 @@ TEST_F(TransportTest, TestDestroyAllClearsPosts) { } // This test verifies channels are created with proper ICE -// role, tiebreaker and remote ice mode and credentials after offer and answer -// negotiations. +// role, tiebreaker and remote ice mode and credentials after offer and +// answer negotiations. TEST_F(TransportTest, TestChannelIceParameters) { - transport_->SetRole(cricket::ROLE_CONTROLLING); - transport_->SetTiebreaker(99U); + transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); + transport_->SetIceTiebreaker(99U); cricket::TransportDescription local_desc( cricket::NS_JINGLE_ICE_UDP, std::vector(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, NULL, cricket::Candidates()); ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, cricket::CA_OFFER)); - EXPECT_EQ(cricket::ROLE_CONTROLLING, transport_->role()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); EXPECT_TRUE(SetupChannel()); - EXPECT_EQ(cricket::ROLE_CONTROLLING, channel_->GetRole()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); EXPECT_EQ(kIceUfrag1, channel_->ice_ufrag()); EXPECT_EQ(kIcePwd1, channel_->ice_pwd()); @@ -161,12 +161,12 @@ TEST_F(TransportTest, TestChannelIceParameters) { kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, NULL, cricket::Candidates()); ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, cricket::CA_ANSWER)); - EXPECT_EQ(cricket::ROLE_CONTROLLING, channel_->GetRole()); - EXPECT_EQ(99U, channel_->tiebreaker()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); + EXPECT_EQ(99U, channel_->IceTiebreaker()); EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); // Changing the transport role from CONTROLLING to CONTROLLED. - transport_->SetRole(cricket::ROLE_CONTROLLED); - EXPECT_EQ(cricket::ROLE_CONTROLLED, channel_->GetRole()); + transport_->SetIceRole(cricket::ICEROLE_CONTROLLED); + EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel_->GetIceRole()); EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); EXPECT_EQ(kIceUfrag1, channel_->remote_ice_ufrag()); EXPECT_EQ(kIcePwd1, channel_->remote_ice_pwd()); @@ -174,7 +174,7 @@ TEST_F(TransportTest, TestChannelIceParameters) { // Tests channel role is reversed after receiving ice-lite from remote. TEST_F(TransportTest, TestSetRemoteIceLiteInOffer) { - transport_->SetRole(cricket::ROLE_CONTROLLED); + transport_->SetIceRole(cricket::ICEROLE_CONTROLLED); cricket::TransportDescription remote_desc( cricket::NS_JINGLE_ICE_UDP, std::vector(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, NULL, cricket::Candidates()); @@ -185,23 +185,23 @@ TEST_F(TransportTest, TestSetRemoteIceLiteInOffer) { kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, NULL, cricket::Candidates()); ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, cricket::CA_ANSWER)); - EXPECT_EQ(cricket::ROLE_CONTROLLING, transport_->role()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); EXPECT_TRUE(SetupChannel()); - EXPECT_EQ(cricket::ROLE_CONTROLLING, channel_->GetRole()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); EXPECT_EQ(cricket::ICEMODE_LITE, channel_->remote_ice_mode()); } // Tests ice-lite in remote answer. TEST_F(TransportTest, TestSetRemoteIceLiteInAnswer) { - transport_->SetRole(cricket::ROLE_CONTROLLING); + transport_->SetIceRole(cricket::ICEROLE_CONTROLLING); cricket::TransportDescription local_desc( cricket::NS_JINGLE_ICE_UDP, std::vector(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, NULL, cricket::Candidates()); ASSERT_TRUE(transport_->SetLocalTransportDescription(local_desc, cricket::CA_OFFER)); - EXPECT_EQ(cricket::ROLE_CONTROLLING, transport_->role()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, transport_->ice_role()); EXPECT_TRUE(SetupChannel()); - EXPECT_EQ(cricket::ROLE_CONTROLLING, channel_->GetRole()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); // Channels will be created in ICEFULL_MODE. EXPECT_EQ(cricket::ICEMODE_FULL, channel_->remote_ice_mode()); cricket::TransportDescription remote_desc( @@ -209,7 +209,7 @@ TEST_F(TransportTest, TestSetRemoteIceLiteInAnswer) { kIceUfrag1, kIcePwd1, cricket::ICEMODE_LITE, NULL, cricket::Candidates()); ASSERT_TRUE(transport_->SetRemoteTransportDescription(remote_desc, cricket::CA_ANSWER)); - EXPECT_EQ(cricket::ROLE_CONTROLLING, channel_->GetRole()); + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel_->GetIceRole()); // After receiving remote description with ICEMODE_LITE, channel should // have mode set to ICEMODE_LITE. EXPECT_EQ(cricket::ICEMODE_LITE, channel_->remote_ice_mode()); diff --git a/talk/p2p/base/transportchannel.h b/talk/p2p/base/transportchannel.h index 4027e76f8..2b09f54b8 100644 --- a/talk/p2p/base/transportchannel.h +++ b/talk/p2p/base/transportchannel.h @@ -61,13 +61,10 @@ class TransportChannel : public sigslot::has_slots<> { readable_(false), writable_(false) {} virtual ~TransportChannel() {} + // TODO(mallinath) - Remove this API, as it's no longer useful. // Returns the session id of this channel. - virtual const std::string& SessionId() const { return session_id_; } - // Sets session id which created this transport channel. - // This is called from TransportProxy::GetOrCreateImpl. - virtual void SetSessionId(const std::string& session_id) { - session_id_ = session_id; - } + virtual const std::string SessionId() const { return std::string(); } + const std::string& content_name() const { return content_name_; } int component() const { return component_; } @@ -92,8 +89,10 @@ class TransportChannel : public sigslot::has_slots<> { // Returns the most recent error that occurred on this channel. virtual int GetError() = 0; + // TODO(mallinath) - Move this to TransportChannelImpl, after channel.cc + // no longer needs it. // Returns current transportchannel ICE role. - virtual TransportRole GetRole() const = 0; + virtual IceRole GetIceRole() const = 0; // Returns the current stats for this connection. virtual bool GetStats(ConnectionInfos* infos) { @@ -149,7 +148,6 @@ class TransportChannel : public sigslot::has_slots<> { private: - std::string session_id_; // Used mostly for debugging. std::string content_name_; int component_; diff --git a/talk/p2p/base/transportchannelimpl.h b/talk/p2p/base/transportchannelimpl.h index f1b84cbaa..32e2471f1 100644 --- a/talk/p2p/base/transportchannelimpl.h +++ b/talk/p2p/base/transportchannelimpl.h @@ -50,8 +50,8 @@ class TransportChannelImpl : public TransportChannel { virtual Transport* GetTransport() = 0; // For ICE channels. - virtual void SetRole(TransportRole role) = 0; - virtual void SetTiebreaker(uint64 tiebreaker) = 0; + virtual void SetIceRole(IceRole role) = 0; + virtual void SetIceTiebreaker(uint64 tiebreaker) = 0; // To toggle G-ICE/ICE. virtual void SetIceProtocolType(IceProtocolType type) = 0; // SetIceCredentials only need to be implemented by the ICE diff --git a/talk/p2p/base/transportchannelproxy.cc b/talk/p2p/base/transportchannelproxy.cc index fd8fe6a69..b25f75751 100644 --- a/talk/p2p/base/transportchannelproxy.cc +++ b/talk/p2p/base/transportchannelproxy.cc @@ -168,12 +168,12 @@ bool TransportChannelProxy::ExportKeyingMaterial(const std::string& label, result, result_len); } -TransportRole TransportChannelProxy::GetRole() const { +IceRole TransportChannelProxy::GetIceRole() const { ASSERT(talk_base::Thread::Current() == worker_thread_); if (!impl_) { - return ROLE_UNKNOWN; + return ICEROLE_UNKNOWN; } - return impl_->GetRole(); + return impl_->GetIceRole(); } void TransportChannelProxy::OnReadableState(TransportChannel* channel) { diff --git a/talk/p2p/base/transportchannelproxy.h b/talk/p2p/base/transportchannelproxy.h index 03d95b447..828c0ae05 100644 --- a/talk/p2p/base/transportchannelproxy.h +++ b/talk/p2p/base/transportchannelproxy.h @@ -66,7 +66,7 @@ class TransportChannelProxy : public TransportChannel, virtual int SendPacket(const char* data, size_t len, int flags); virtual int SetOption(talk_base::Socket::Option opt, int value); virtual int GetError(); - virtual TransportRole GetRole() const; + virtual IceRole GetIceRole() const; virtual bool GetStats(ConnectionInfos* infos); virtual bool IsDtlsActive() const; virtual bool SetSrtpCiphers(const std::vector& ciphers); diff --git a/talk/p2p/base/transportdescription.h b/talk/p2p/base/transportdescription.h index 3406118c7..92da8d66c 100644 --- a/talk/p2p/base/transportdescription.h +++ b/talk/p2p/base/transportdescription.h @@ -62,6 +62,13 @@ enum TransportProtocol { // TODO(juberti): remove this. typedef TransportProtocol IceProtocolType; +// Whether our side of the call is driving the negotiation, or the other side. +enum IceRole { + ICEROLE_CONTROLLING = 0, + ICEROLE_CONTROLLED, + ICEROLE_UNKNOWN +}; + // ICE RFC 5245 implementation type. enum IceMode { ICEMODE_FULL, // As defined in http://tools.ietf.org/html/rfc5245#section-4.1 diff --git a/talk/session/media/channel.cc b/talk/session/media/channel.cc index 379c55376..1bce2acdc 100644 --- a/talk/session/media/channel.cc +++ b/talk/session/media/channel.cc @@ -1004,7 +1004,7 @@ bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { std::vector *send_key, *recv_key; - if (channel->GetRole() == ROLE_CONTROLLING) { + if (channel->GetIceRole() == ICEROLE_CONTROLLING) { send_key = &server_write_key; recv_key = &client_write_key; } else {