Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

Unified Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2063823008: Adding IceConfig option to assume TURN/TURN candidate pairs will work. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Demonstrating another solution that doesn't require 2 enums. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
index cbf5e76a7ae23a13376e6f8aa76ad10559978fbe..30294cd943cc69477b290150c339eab0c6e0b66b 100644
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
@@ -32,15 +32,14 @@
#include "webrtc/base/thread.h"
#include "webrtc/base/virtualsocketserver.h"
-using cricket::kDefaultPortAllocatorFlags;
-using cricket::kMinimumStepDelay;
-using cricket::kDefaultStepDelay;
-using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET;
-using cricket::ServerAddresses;
-using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL;
+namespace {
+
using rtc::SocketAddress;
-static const int kDefaultTimeout = 1000;
+// Default timeout for tests in this file.
+// Should be large enough for slow buildbots to run the tests reliably.
+static const int kDefaultTimeout = 10000;
+
static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
cricket::PORTALLOCATOR_DISABLE_RELAY |
cricket::PORTALLOCATOR_DISABLE_TCP;
@@ -104,9 +103,9 @@ static const uint64_t kTiebreaker2 = 22222;
enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES };
-static cricket::IceConfig CreateIceConfig(int receiving_timeout,
- bool gather_continually,
- int backup_ping_interval = -1) {
+cricket::IceConfig CreateIceConfig(int receiving_timeout,
+ bool gather_continually,
+ int backup_ping_interval = -1) {
cricket::IceConfig config;
config.receiving_timeout = receiving_timeout;
config.gather_continually = gather_continually;
@@ -114,6 +113,25 @@ static cricket::IceConfig CreateIceConfig(int receiving_timeout,
return config;
}
+cricket::Candidate CreateUdpCandidate(const std::string& type,
+ const std::string& ip,
+ int port,
+ int priority,
+ const std::string& ufrag = "") {
+ cricket::Candidate c;
+ c.set_address(rtc::SocketAddress(ip, port));
+ c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
+ c.set_protocol(cricket::UDP_PROTOCOL_NAME);
+ c.set_priority(priority);
+ c.set_username(ufrag);
+ c.set_type(type);
+ return c;
+}
+
+} // namespace {
+
+namespace cricket {
+
// This test simulates 2 P2P endpoints that want to establish connectivity
// with each other over various network topologies and conditions, which can be
// specified in each individial test.
@@ -140,28 +158,36 @@ class P2PTransportChannelTestBase : public testing::Test,
nss_(new rtc::NATSocketServer(vss_.get())),
ss_(new rtc::FirewallSocketServer(nss_.get())),
ss_scope_(ss_.get()),
- stun_server_(cricket::TestStunServer::Create(main_, kStunAddr)),
+ stun_server_(TestStunServer::Create(main_, kStunAddr)),
turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr),
- relay_server_(main_, kRelayUdpIntAddr, kRelayUdpExtAddr,
- kRelayTcpIntAddr, kRelayTcpExtAddr,
- kRelaySslTcpIntAddr, kRelaySslTcpExtAddr),
- socks_server1_(ss_.get(), kSocksProxyAddrs[0],
- ss_.get(), kSocksProxyAddrs[0]),
- socks_server2_(ss_.get(), kSocksProxyAddrs[1],
- ss_.get(), kSocksProxyAddrs[1]),
+ relay_server_(main_,
+ kRelayUdpIntAddr,
+ kRelayUdpExtAddr,
+ kRelayTcpIntAddr,
+ kRelayTcpExtAddr,
+ kRelaySslTcpIntAddr,
+ kRelaySslTcpExtAddr),
+ socks_server1_(ss_.get(),
+ kSocksProxyAddrs[0],
+ ss_.get(),
+ kSocksProxyAddrs[0]),
+ socks_server2_(ss_.get(),
+ kSocksProxyAddrs[1],
+ ss_.get(),
+ kSocksProxyAddrs[1]),
clear_remote_candidates_ufrag_pwd_(false),
force_relay_(false) {
- ep1_.role_ = cricket::ICEROLE_CONTROLLING;
- ep2_.role_ = cricket::ICEROLE_CONTROLLED;
+ ep1_.role_ = ICEROLE_CONTROLLING;
+ ep2_.role_ = ICEROLE_CONTROLLED;
ServerAddresses stun_servers;
stun_servers.insert(kStunAddr);
- ep1_.allocator_.reset(new cricket::BasicPortAllocator(
- &ep1_.network_manager_,
- stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr));
- ep2_.allocator_.reset(new cricket::BasicPortAllocator(
- &ep2_.network_manager_,
- stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr));
+ ep1_.allocator_.reset(new BasicPortAllocator(
+ &ep1_.network_manager_, stun_servers, kRelayUdpIntAddr,
+ kRelayTcpIntAddr, kRelaySslTcpIntAddr));
+ ep2_.allocator_.reset(new BasicPortAllocator(
+ &ep2_.network_manager_, stun_servers, kRelayUdpIntAddr,
+ kRelayTcpIntAddr, kRelaySslTcpIntAddr));
}
protected:
@@ -215,29 +241,28 @@ class P2PTransportChannelTestBase : public testing::Test,
std::string name_; // TODO - Currently not used.
std::list<std::string> ch_packets_;
- std::unique_ptr<cricket::P2PTransportChannel> ch_;
+ std::unique_ptr<P2PTransportChannel> ch_;
};
struct CandidatesData : public rtc::MessageData {
- CandidatesData(cricket::TransportChannel* ch, const cricket::Candidate& c)
+ CandidatesData(TransportChannel* ch, const Candidate& c)
: channel(ch), candidates(1, c) {}
- CandidatesData(cricket::TransportChannel* ch,
- const std::vector<cricket::Candidate>& cc)
+ CandidatesData(TransportChannel* ch, const std::vector<Candidate>& cc)
: channel(ch), candidates(cc) {}
- cricket::TransportChannel* channel;
- cricket::Candidates candidates;
+ TransportChannel* channel;
+ Candidates candidates;
};
struct Endpoint {
Endpoint()
- : role_(cricket::ICEROLE_UNKNOWN),
+ : role_(ICEROLE_UNKNOWN),
tiebreaker_(0),
role_conflict_(false),
save_candidates_(false) {}
- bool HasChannel(cricket::TransportChannel* ch) {
+ bool HasChannel(TransportChannel* ch) {
return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get());
}
- ChannelData* GetChannelData(cricket::TransportChannel* ch) {
+ ChannelData* GetChannelData(TransportChannel* ch) {
if (!HasChannel(ch)) return NULL;
if (cd1_.ch_.get() == ch)
return &cd1_;
@@ -245,8 +270,8 @@ class P2PTransportChannelTestBase : public testing::Test,
return &cd2_;
}
- void SetIceRole(cricket::IceRole role) { role_ = role; }
- cricket::IceRole ice_role() { return role_; }
+ void SetIceRole(IceRole role) { role_ = role; }
+ IceRole ice_role() { return role_; }
void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; }
uint64_t GetIceTiebreaker() { return tiebreaker_; }
void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; }
@@ -259,17 +284,18 @@ class P2PTransportChannelTestBase : public testing::Test,
}
rtc::FakeNetworkManager network_manager_;
- std::unique_ptr<cricket::BasicPortAllocator> allocator_;
+ std::unique_ptr<BasicPortAllocator> allocator_;
ChannelData cd1_;
ChannelData cd2_;
- cricket::IceRole role_;
+ IceRole role_;
uint64_t tiebreaker_;
bool role_conflict_;
bool save_candidates_;
std::vector<CandidatesData*> saved_candidates_;
+ bool ready_to_send_ = false;
};
- ChannelData* GetChannelData(cricket::TransportChannel* channel) {
+ ChannelData* GetChannelData(TransportChannel* channel) {
if (ep1_.HasChannel(channel))
return ep1_.GetChannelData(channel);
else
@@ -282,13 +308,11 @@ class P2PTransportChannelTestBase : public testing::Test,
std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1];
std::string ice_pwd_ep2_cd1_ch = kIcePwd[1];
ep1_.cd1_.ch_.reset(CreateChannel(
- 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
- ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch,
- ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch));
+ 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd1_ch,
+ ice_pwd_ep1_cd1_ch, ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch));
ep2_.cd1_.ch_.reset(CreateChannel(
- 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
- ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch,
- ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch));
+ 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd1_ch,
+ ice_pwd_ep2_cd1_ch, ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch));
ep1_.cd1_.ch_->MaybeStartGathering();
ep2_.cd1_.ch_->MaybeStartGathering();
if (num == 2) {
@@ -297,26 +321,25 @@ class P2PTransportChannelTestBase : public testing::Test,
std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3];
std::string ice_pwd_ep2_cd2_ch = kIcePwd[3];
ep1_.cd2_.ch_.reset(CreateChannel(
- 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
- ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch,
- ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch));
+ 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd2_ch,
+ ice_pwd_ep1_cd2_ch, ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch));
ep2_.cd2_.ch_.reset(CreateChannel(
- 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
- ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch,
- ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch));
+ 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd2_ch,
+ ice_pwd_ep2_cd2_ch, ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch));
ep1_.cd2_.ch_->MaybeStartGathering();
ep2_.cd2_.ch_->MaybeStartGathering();
}
}
- cricket::P2PTransportChannel* CreateChannel(
- int endpoint,
- int component,
- const std::string& local_ice_ufrag,
- const std::string& local_ice_pwd,
- const std::string& remote_ice_ufrag,
- const std::string& remote_ice_pwd) {
- cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel(
+ P2PTransportChannel* CreateChannel(int endpoint,
+ int component,
+ const std::string& local_ice_ufrag,
+ const std::string& local_ice_pwd,
+ const std::string& remote_ice_ufrag,
+ const std::string& remote_ice_pwd) {
+ P2PTransportChannel* channel = new P2PTransportChannel(
"test content name", component, GetAllocator(endpoint));
+ channel->SignalReadyToSend.connect(
+ this, &P2PTransportChannelTestBase::OnReadyToSend);
channel->SignalCandidateGathered.connect(
this, &P2PTransportChannelTestBase::OnCandidateGathered);
channel->SignalCandidatesRemoved.connect(
@@ -342,10 +365,10 @@ class P2PTransportChannelTestBase : public testing::Test,
ep1_.cd2_.ch_.reset();
ep2_.cd2_.ch_.reset();
}
- cricket::P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); }
- cricket::P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); }
- cricket::P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); }
- cricket::P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); }
+ P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); }
+ P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); }
+ P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); }
+ P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); }
// Common results.
static const Result kLocalUdpToLocalUdp;
@@ -373,7 +396,7 @@ class P2PTransportChannelTestBase : public testing::Test,
return NULL;
}
}
- cricket::PortAllocator* GetAllocator(int endpoint) {
+ PortAllocator* GetAllocator(int endpoint) {
return GetEndpoint(endpoint)->allocator_.get();
}
void AddAddress(int endpoint, const SocketAddress& addr) {
@@ -399,7 +422,7 @@ class P2PTransportChannelTestBase : public testing::Test,
void SetAllocatorFlags(int endpoint, int flags) {
GetAllocator(endpoint)->set_flags(flags);
}
- void SetIceRole(int endpoint, cricket::IceRole role) {
+ void SetIceRole(int endpoint, IceRole role) {
GetEndpoint(endpoint)->SetIceRole(role);
}
void SetIceTiebreaker(int endpoint, uint64_t tiebreaker) {
@@ -591,12 +614,10 @@ class P2PTransportChannelTestBase : public testing::Test,
ep2_ch1()->receiving() && ep2_ch1()->writable(),
1000, 1000);
- const cricket::Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
- const cricket::Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
- const cricket::Candidate* old_remote_candidate1 =
- RemoteCandidate(ep1_ch1());
- const cricket::Candidate* old_remote_candidate2 =
- RemoteCandidate(ep2_ch1());
+ const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
+ const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
+ const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1());
+ const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1());
ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]);
ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
@@ -624,7 +645,7 @@ class P2PTransportChannelTestBase : public testing::Test,
void TestSignalRoleConflict() {
SetIceTiebreaker(0, kTiebreaker1); // Default EP1 is in controlling state.
- SetIceRole(1, cricket::ICEROLE_CONTROLLING);
+ SetIceRole(1, ICEROLE_CONTROLLING);
SetIceTiebreaker(1, kTiebreaker2);
// Creating channels with both channels role set to CONTROLLING.
@@ -646,10 +667,13 @@ class P2PTransportChannelTestBase : public testing::Test,
TestSendRecv(1);
}
+ void OnReadyToSend(TransportChannel* ch) {
+ GetEndpoint(ch)->ready_to_send_ = true;
+ }
+
// We pass the candidates directly to the other side.
- void OnCandidateGathered(cricket::TransportChannelImpl* ch,
- const cricket::Candidate& c) {
- if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE)
+ void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) {
+ if (force_relay_ && c.type() != RELAY_PORT_TYPE)
return;
if (GetEndpoint(ch)->save_candidates_) {
@@ -664,8 +688,8 @@ class P2PTransportChannelTestBase : public testing::Test,
GetEndpoint(endpoint)->save_candidates_ = true;
}
- void OnCandidatesRemoved(cricket::TransportChannelImpl* ch,
- const std::vector<cricket::Candidate>& candidates) {
+ void OnCandidatesRemoved(TransportChannelImpl* ch,
+ const std::vector<Candidate>& candidates) {
// Candidate removals are not paused.
CandidatesData* candidates_data = new CandidatesData(ch, candidates);
main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data);
@@ -675,12 +699,12 @@ class P2PTransportChannelTestBase : public testing::Test,
void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) {
for (auto& data : GetEndpoint(endpoint)->saved_candidates_) {
for (auto& candidate : data->candidates) {
- EXPECT_EQ(candidate.protocol(), cricket::TCP_PROTOCOL_NAME);
+ EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME);
EXPECT_EQ(candidate.tcptype(), tcptype);
- if (candidate.tcptype() == cricket::TCPTYPE_ACTIVE_STR) {
- EXPECT_EQ(candidate.address().port(), cricket::DISCARD_PORT);
- } else if (candidate.tcptype() == cricket::TCPTYPE_PASSIVE_STR) {
- EXPECT_NE(candidate.address().port(), cricket::DISCARD_PORT);
+ if (candidate.tcptype() == TCPTYPE_ACTIVE_STR) {
+ EXPECT_EQ(candidate.address().port(), DISCARD_PORT);
+ } else if (candidate.tcptype() == TCPTYPE_PASSIVE_STR) {
+ EXPECT_NE(candidate.address().port(), DISCARD_PORT);
} else {
FAIL() << "Unknown tcptype: " << candidate.tcptype();
}
@@ -703,7 +727,10 @@ class P2PTransportChannelTestBase : public testing::Test,
case MSG_ADD_CANDIDATES: {
std::unique_ptr<CandidatesData> data(
static_cast<CandidatesData*>(msg->pdata));
- cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel);
+ P2PTransportChannel* rch = GetRemoteChannel(data->channel);
+ if (!rch) {
+ return;
+ }
for (auto& c : data->candidates) {
if (clear_remote_candidates_ufrag_pwd_) {
c.set_username("");
@@ -718,8 +745,11 @@ class P2PTransportChannelTestBase : public testing::Test,
case MSG_REMOVE_CANDIDATES: {
std::unique_ptr<CandidatesData> data(
static_cast<CandidatesData*>(msg->pdata));
- cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel);
- for (cricket::Candidate& c : data->candidates) {
+ P2PTransportChannel* rch = GetRemoteChannel(data->channel);
+ if (!rch) {
+ return;
+ }
+ for (Candidate& c : data->candidates) {
LOG(LS_INFO) << "Removed remote candidate " << c.ToString();
rch->RemoveRemoteCandidate(c);
}
@@ -727,40 +757,40 @@ class P2PTransportChannelTestBase : public testing::Test,
}
}
}
- void OnReadPacket(cricket::TransportChannel* channel, const char* data,
- size_t len, const rtc::PacketTime& packet_time,
+ void OnReadPacket(TransportChannel* channel,
+ const char* data,
+ size_t len,
+ const rtc::PacketTime& packet_time,
int flags) {
std::list<std::string>& packets = GetPacketList(channel);
packets.push_front(std::string(data, len));
}
- void OnRoleConflict(cricket::TransportChannelImpl* channel) {
+ void OnRoleConflict(TransportChannelImpl* channel) {
GetEndpoint(channel)->OnRoleConflict(true);
- cricket::IceRole new_role =
- GetEndpoint(channel)->ice_role() == cricket::ICEROLE_CONTROLLING ?
- cricket::ICEROLE_CONTROLLED : cricket::ICEROLE_CONTROLLING;
+ IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING
+ ? ICEROLE_CONTROLLED
+ : ICEROLE_CONTROLLING;
channel->SetIceRole(new_role);
}
- int SendData(cricket::TransportChannel* channel,
- const char* data, size_t len) {
+ int SendData(TransportChannel* channel, const char* data, size_t len) {
rtc::PacketOptions options;
return channel->SendPacket(data, len, options, 0);
}
- bool CheckDataOnChannel(cricket::TransportChannel* channel,
- const char* data, int len) {
+ bool CheckDataOnChannel(TransportChannel* channel,
+ const char* data,
+ int len) {
return GetChannelData(channel)->CheckData(data, len);
}
- static const cricket::Candidate* LocalCandidate(
- cricket::P2PTransportChannel* ch) {
+ static const Candidate* LocalCandidate(P2PTransportChannel* ch) {
return (ch && ch->best_connection()) ?
&ch->best_connection()->local_candidate() : NULL;
}
- static const cricket::Candidate* RemoteCandidate(
- cricket::P2PTransportChannel* ch) {
+ static const Candidate* RemoteCandidate(P2PTransportChannel* ch) {
return (ch && ch->best_connection()) ?
&ch->best_connection()->remote_candidate() : NULL;
}
- Endpoint* GetEndpoint(cricket::TransportChannel* ch) {
+ Endpoint* GetEndpoint(TransportChannel* ch) {
if (ep1_.HasChannel(ch)) {
return &ep1_;
} else if (ep2_.HasChannel(ch)) {
@@ -769,8 +799,7 @@ class P2PTransportChannelTestBase : public testing::Test,
return NULL;
}
}
- cricket::P2PTransportChannel* GetRemoteChannel(
- cricket::TransportChannel* ch) {
+ P2PTransportChannel* GetRemoteChannel(TransportChannel* ch) {
if (ch == ep1_ch1())
return ep2_ch1();
else if (ch == ep1_ch2())
@@ -782,7 +811,7 @@ class P2PTransportChannelTestBase : public testing::Test,
else
return NULL;
}
- std::list<std::string>& GetPacketList(cricket::TransportChannel* ch) {
+ std::list<std::string>& GetPacketList(TransportChannel* ch) {
return GetChannelData(ch)->ch_packets_;
}
@@ -801,9 +830,9 @@ class P2PTransportChannelTestBase : public testing::Test,
std::unique_ptr<rtc::NATSocketServer> nss_;
std::unique_ptr<rtc::FirewallSocketServer> ss_;
rtc::SocketServerScope ss_scope_;
- std::unique_ptr<cricket::TestStunServer> stun_server_;
- cricket::TestTurnServer turn_server_;
- cricket::TestRelayServer relay_server_;
+ std::unique_ptr<TestStunServer> stun_server_;
+ TestTurnServer turn_server_;
+ TestRelayServer relay_server_;
rtc::SocksProxyServer socks_server1_;
rtc::SocksProxyServer socks_server2_;
Endpoint ep1_;
@@ -861,21 +890,17 @@ class P2PTransportChannelTest : public P2PTransportChannelTestBase {
int allocator_flags2) {
ServerAddresses stun_servers;
stun_servers.insert(kStunAddr);
- GetEndpoint(0)->allocator_.reset(
- new cricket::BasicPortAllocator(&(GetEndpoint(0)->network_manager_),
- stun_servers,
- rtc::SocketAddress(), rtc::SocketAddress(),
- rtc::SocketAddress()));
- GetEndpoint(1)->allocator_.reset(
- new cricket::BasicPortAllocator(&(GetEndpoint(1)->network_manager_),
- stun_servers,
- rtc::SocketAddress(), rtc::SocketAddress(),
- rtc::SocketAddress()));
-
- cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
+ GetEndpoint(0)->allocator_.reset(new BasicPortAllocator(
+ &(GetEndpoint(0)->network_manager_), stun_servers, rtc::SocketAddress(),
+ rtc::SocketAddress(), rtc::SocketAddress()));
+ GetEndpoint(1)->allocator_.reset(new BasicPortAllocator(
+ &(GetEndpoint(1)->network_manager_), stun_servers, rtc::SocketAddress(),
+ rtc::SocketAddress(), rtc::SocketAddress()));
+
+ RelayServerConfig turn_server(RELAY_TURN);
turn_server.credentials = kRelayCredentials;
turn_server.ports.push_back(
- cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
+ ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false));
GetEndpoint(0)->allocator_->AddTurnServer(turn_server);
GetEndpoint(1)->allocator_->AddTurnServer(turn_server);
@@ -1076,11 +1101,11 @@ TEST_F(P2PTransportChannelTest, GetStats) {
ep2_ch1()->receiving() && ep2_ch1()->writable(),
1000, 1000);
TestSendRecv(1);
- cricket::ConnectionInfos infos;
+ ConnectionInfos infos;
ASSERT_TRUE(ep1_ch1()->GetStats(&infos));
ASSERT_TRUE(infos.size() >= 1);
- cricket::ConnectionInfo* best_conn_info = nullptr;
- for (cricket::ConnectionInfo& info : infos) {
+ ConnectionInfo* best_conn_info = nullptr;
+ for (ConnectionInfo& info : infos) {
if (info.best_connection) {
best_conn_info = &info;
break;
@@ -1116,7 +1141,7 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
// The caller should have the best connection connected to the peer reflexive
// candidate.
- const cricket::Connection* best_connection = NULL;
+ const Connection* best_connection = NULL;
WAIT((best_connection = ep1_ch1()->best_connection()) != NULL, 2000);
EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type());
@@ -1190,7 +1215,7 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) {
ResumeCandidates(1);
- const cricket::Connection* best_connection = NULL;
+ const Connection* best_connection = NULL;
WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 2000);
// Wait to verify the connection is not culled.
@@ -1206,7 +1231,7 @@ TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) {
ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
CreateChannels(1);
- const cricket::Connection* best_connection = NULL;
+ const Connection* best_connection = NULL;
// Wait until the callee's connections are created.
WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000);
// Wait to see if they get culled; they shouldn't.
@@ -1261,9 +1286,9 @@ TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) {
SetAllocationStepDelay(0, kMinimumStepDelay);
SetAllocationStepDelay(1, kMinimumStepDelay);
- int kOnlyLocalTcpPorts = cricket::PORTALLOCATOR_DISABLE_UDP |
- cricket::PORTALLOCATOR_DISABLE_STUN |
- cricket::PORTALLOCATOR_DISABLE_RELAY;
+ int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP |
+ PORTALLOCATOR_DISABLE_STUN |
+ PORTALLOCATOR_DISABLE_RELAY;
// Disable all protocols except TCP.
SetAllocatorFlags(0, kOnlyLocalTcpPorts);
SetAllocatorFlags(1, kOnlyLocalTcpPorts);
@@ -1277,8 +1302,8 @@ TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) {
CreateChannels(1);
// Verify tcp candidates.
- VerifySavedTcpCandidates(0, cricket::TCPTYPE_PASSIVE_STR);
- VerifySavedTcpCandidates(1, cricket::TCPTYPE_ACTIVE_STR);
+ VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR);
+ VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR);
// Resume candidates.
ResumeCandidates(0);
@@ -1308,27 +1333,27 @@ TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) {
AddAddress(0, kPublicAddrs[0]);
AddAddress(1, kPublicAddrs[1]);
- SetIceRole(0, cricket::ICEROLE_CONTROLLING);
+ SetIceRole(0, ICEROLE_CONTROLLING);
SetIceTiebreaker(0, kTiebreaker1);
- SetIceRole(1, cricket::ICEROLE_CONTROLLING);
+ SetIceRole(1, ICEROLE_CONTROLLING);
SetIceTiebreaker(1, kTiebreaker2);
CreateChannels(1);
EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000);
- const std::vector<cricket::PortInterface *> ports_before = ep1_ch1()->ports();
+ const std::vector<PortInterface*> ports_before = ep1_ch1()->ports();
for (size_t i = 0; i < ports_before.size(); ++i) {
- EXPECT_EQ(cricket::ICEROLE_CONTROLLING, ports_before[i]->GetIceRole());
+ EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole());
EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker());
}
- ep1_ch1()->SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED);
ep1_ch1()->SetIceTiebreaker(kTiebreaker2);
- const std::vector<cricket::PortInterface *> ports_after = ep1_ch1()->ports();
+ const std::vector<PortInterface*> ports_after = ep1_ch1()->ports();
for (size_t i = 0; i < ports_after.size(); ++i) {
- EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole());
+ EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole());
// SetIceTiebreaker after Connect() has been called will fail. So expect the
// original value.
EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker());
@@ -1386,8 +1411,8 @@ TEST_F(P2PTransportChannelTest, TestIPv6Connections) {
SetAllocationStepDelay(1, kMinimumStepDelay);
// Enable IPv6
- SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6);
- SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6);
+ SetAllocatorFlags(0, PORTALLOCATOR_ENABLE_IPV6);
+ SetAllocatorFlags(1, PORTALLOCATOR_ENABLE_IPV6);
CreateChannels(1);
@@ -1407,8 +1432,8 @@ TEST_F(P2PTransportChannelTest, TestIPv6Connections) {
TEST_F(P2PTransportChannelTest, TestForceTurn) {
ConfigureEndpoints(
NAT_PORT_RESTRICTED, NAT_SYMMETRIC,
- kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET,
- kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
+ kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET,
+ kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET);
set_force_relay(true);
SetAllocationStepDelay(0, kMinimumStepDelay);
@@ -1440,7 +1465,7 @@ TEST_F(P2PTransportChannelTest, TestContinualGathering) {
SetAllocationStepDelay(0, kDefaultStepDelay);
SetAllocationStepDelay(1, kDefaultStepDelay);
CreateChannels(1);
- cricket::IceConfig config = CreateIceConfig(1000, true);
+ IceConfig config = CreateIceConfig(1000, true);
ep1_ch1()->SetIceConfig(config);
// By default, ep2 does not gather continually.
@@ -1448,13 +1473,12 @@ TEST_F(P2PTransportChannelTest, TestContinualGathering) {
ep1_ch1()->receiving() && ep1_ch1()->writable() &&
ep2_ch1()->receiving() && ep2_ch1()->writable(),
1000, 1000);
- WAIT(cricket::IceGatheringState::kIceGatheringComplete ==
- ep1_ch1()->gathering_state(),
+ WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(),
1000);
- EXPECT_EQ(cricket::IceGatheringState::kIceGatheringGathering,
+ EXPECT_EQ(IceGatheringState::kIceGatheringGathering,
ep1_ch1()->gathering_state());
// By now, ep2 should have completed gathering.
- EXPECT_EQ(cricket::IceGatheringState::kIceGatheringComplete,
+ EXPECT_EQ(IceGatheringState::kIceGatheringComplete,
ep2_ch1()->gathering_state());
DestroyChannels();
@@ -1473,9 +1497,9 @@ TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) {
allocator_1->turn_servers(), pool_size);
allocator_2->SetConfiguration(allocator_2->stun_servers(),
allocator_2->turn_servers(), pool_size);
- const cricket::PortAllocatorSession* pooled_session_1 =
+ const PortAllocatorSession* pooled_session_1 =
allocator_1->GetPooledSession();
- const cricket::PortAllocatorSession* pooled_session_2 =
+ const PortAllocatorSession* pooled_session_2 =
allocator_2->GetPooledSession();
ASSERT_NE(nullptr, pooled_session_1);
ASSERT_NE(nullptr, pooled_session_2);
@@ -1516,9 +1540,9 @@ TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) {
allocator_1->turn_servers(), pool_size);
allocator_2->SetConfiguration(allocator_2->stun_servers(),
allocator_2->turn_servers(), pool_size);
- const cricket::PortAllocatorSession* pooled_session_1 =
+ const PortAllocatorSession* pooled_session_1 =
allocator_1->GetPooledSession();
- const cricket::PortAllocatorSession* pooled_session_2 =
+ const PortAllocatorSession* pooled_session_2 =
allocator_2->GetPooledSession();
ASSERT_NE(nullptr, pooled_session_1);
ASSERT_NE(nullptr, pooled_session_2);
@@ -1546,6 +1570,40 @@ TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) {
ep2_ch1()->best_connection()->port()));
}
+// Test that when the "presume_writable_when_fully_relayed" flag is set to
+// false and there's a TURN-TURN candidate pair, it's presume to be writable
+// as soon as it's created.
+TEST_F(P2PTransportChannelTest, TestTurnToTurnPresumedWritable) {
+ ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
+ kDefaultPortAllocatorFlags);
+ // Only configure one channel so we can control when the remote candidate
+ // is added.
+ GetEndpoint(0)->cd1_.ch_.reset(
+ CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0],
+ kIcePwd[0], kIceUfrag[1], kIcePwd[1]));
+ IceConfig config;
+ config.presume_writable_when_fully_relayed = true;
+ ep1_ch1()->SetIceConfig(config);
+ ep1_ch1()->MaybeStartGathering();
+ EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete,
+ ep1_ch1()->gathering_state(), kDefaultTimeout);
+ // Add two remote candidates; a host candidate (with higher priority)
+ // and TURN candidate.
+ ep1_ch1()->AddRemoteCandidate(
+ CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ ep1_ch1()->AddRemoteCandidate(
+ CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
+ // Expect that the TURN-TURN candidate pair will be prioritized since it's
+ // "probably writable".
+ EXPECT_TRUE(ep1_ch1()->best_connection() != nullptr);
+ EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
+ EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
+ // Also expect that the channel instantly indicates that it's writable since
+ // it has a TURN-TURN pair.
+ EXPECT_TRUE(ep1_ch1()->writable());
+ EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
+}
+
// Test what happens when we have 2 users behind the same NAT. This can lead
// to interesting behavior because the STUN server will only give out the
// address of the outermost NAT.
@@ -1620,7 +1678,7 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) {
RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
// Make the receiving timeout shorter for testing.
- cricket::IceConfig config = CreateIceConfig(1000, false);
+ IceConfig config = CreateIceConfig(1000, false);
ep1_ch1()->SetIceConfig(config);
ep2_ch1()->SetIceConfig(config);
@@ -1628,8 +1686,8 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) {
LOG(LS_INFO) << "Failing over...";
fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]);
// The best connections will switch, so keep references to them.
- const cricket::Connection* best_connection1 = ep1_ch1()->best_connection();
- const cricket::Connection* best_connection2 = ep2_ch1()->best_connection();
+ const Connection* best_connection1 = ep1_ch1()->best_connection();
+ const Connection* best_connection2 = ep2_ch1()->best_connection();
// We should detect loss of receiving within 1 second or so.
EXPECT_TRUE_WAIT(
!best_connection1->receiving() && !best_connection2->receiving(), 3000);
@@ -1672,7 +1730,7 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) {
RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
// Make the receiving timeout shorter for testing.
- cricket::IceConfig config = CreateIceConfig(1000, false);
+ IceConfig config = CreateIceConfig(1000, false);
ep1_ch1()->SetIceConfig(config);
ep2_ch1()->SetIceConfig(config);
@@ -1680,8 +1738,8 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) {
LOG(LS_INFO) << "Failing over...";
fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
// The best connections will switch, so keep references to them.
- const cricket::Connection* best_connection1 = ep1_ch1()->best_connection();
- const cricket::Connection* best_connection2 = ep2_ch1()->best_connection();
+ const Connection* best_connection1 = ep1_ch1()->best_connection();
+ const Connection* best_connection2 = ep2_ch1()->best_connection();
// We should detect loss of receiving within 1 second or so.
EXPECT_TRUE_WAIT(
!best_connection1->receiving() && !best_connection2->receiving(), 3000);
@@ -1784,11 +1842,10 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) {
ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval));
// After the state becomes COMPLETED, the backup connection will be pinged
// once every |backup_ping_interval| milliseconds.
- ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == cricket::STATE_COMPLETED, 1000);
- const std::vector<cricket::Connection*>& connections =
- ep2_ch1()->connections();
+ ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000);
+ const std::vector<Connection*>& connections = ep2_ch1()->connections();
ASSERT_EQ(2U, connections.size());
- cricket::Connection* backup_conn = connections[1];
+ Connection* backup_conn = connections[1];
EXPECT_TRUE_WAIT(backup_conn->writable(), 3000);
int64_t last_ping_response_ms = backup_conn->last_ping_response_received();
EXPECT_TRUE_WAIT(
@@ -1807,10 +1864,10 @@ TEST_F(P2PTransportChannelMultihomedTest, TestGetState) {
CreateChannels(1);
// Both transport channels will reach STATE_COMPLETED quickly.
- EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
- ep1_ch1()->GetState(), 1000);
- EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
- ep2_ch1()->GetState(), 1000);
+ EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(),
+ 1000);
+ EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(),
+ 1000);
}
// Tests that when a network interface becomes inactive, if and only if
@@ -1909,8 +1966,8 @@ class P2PTransportChannelPingTest : public testing::Test,
ss_scope_(vss_.get()) {}
protected:
- void PrepareChannel(cricket::P2PTransportChannel* ch) {
- ch->SetIceRole(cricket::ICEROLE_CONTROLLING);
+ void PrepareChannel(P2PTransportChannel* ch) {
+ ch->SetIceRole(ICEROLE_CONTROLLING);
ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]);
ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
ch->SignalSelectedCandidatePairChanged.connect(
@@ -1921,54 +1978,39 @@ class P2PTransportChannelPingTest : public testing::Test,
this, &P2PTransportChannelPingTest::OnChannelStateChanged);
}
- cricket::Candidate CreateHostCandidate(const std::string& ip,
- int port,
- int priority,
- const std::string& ufrag = "") {
- cricket::Candidate c;
- c.set_address(rtc::SocketAddress(ip, port));
- c.set_component(1);
- c.set_protocol(cricket::UDP_PROTOCOL_NAME);
- c.set_priority(priority);
- c.set_username(ufrag);
- c.set_type(cricket::LOCAL_PORT_TYPE);
- return c;
- }
-
- cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch,
- const std::string& ip,
- int port_num) {
+ Connection* WaitForConnectionTo(P2PTransportChannel* ch,
+ const std::string& ip,
+ int port_num) {
EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
return GetConnectionTo(ch, ip, port_num);
}
- cricket::Port* GetPort(cricket::P2PTransportChannel* ch) {
+ Port* GetPort(P2PTransportChannel* ch) {
if (ch->ports().empty()) {
return nullptr;
}
- return static_cast<cricket::Port*>(ch->ports()[0]);
+ return static_cast<Port*>(ch->ports()[0]);
}
- cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch,
- const std::string& ip,
- int port_num) {
- cricket::Port* port = GetPort(ch);
+ Connection* GetConnectionTo(P2PTransportChannel* ch,
+ const std::string& ip,
+ int port_num) {
+ Port* port = GetPort(ch);
if (!port) {
return nullptr;
}
return port->GetConnection(rtc::SocketAddress(ip, port_num));
}
- cricket::Connection* FindNextPingableConnectionAndPingIt(
- cricket::P2PTransportChannel* ch) {
- cricket::Connection* conn = ch->FindNextPingableConnection();
+ Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) {
+ Connection* conn = ch->FindNextPingableConnection();
if (conn) {
ch->MarkConnectionPinged(conn);
}
return conn;
}
- int SendData(cricket::TransportChannel& channel,
+ int SendData(TransportChannel& channel,
const char* data,
size_t len,
int packet_id) {
@@ -1978,25 +2020,23 @@ class P2PTransportChannelPingTest : public testing::Test,
}
void OnSelectedCandidatePairChanged(
- cricket::TransportChannel* transport_channel,
- cricket::CandidatePairInterface* selected_candidate_pair,
+ TransportChannel* transport_channel,
+ CandidatePairInterface* selected_candidate_pair,
int last_sent_packet_id) {
last_selected_candidate_pair_ = selected_candidate_pair;
last_sent_packet_id_ = last_sent_packet_id;
}
- void ReceivePingOnConnection(cricket::Connection* conn,
+ void ReceivePingOnConnection(Connection* conn,
const std::string& remote_ufrag,
int priority) {
- cricket::IceMessage msg;
- msg.SetType(cricket::STUN_BINDING_REQUEST);
- msg.AddAttribute(new cricket::StunByteStringAttribute(
- cricket::STUN_ATTR_USERNAME,
+ IceMessage msg;
+ msg.SetType(STUN_BINDING_REQUEST);
+ msg.AddAttribute(new StunByteStringAttribute(
+ STUN_ATTR_USERNAME,
conn->local_candidate().username() + ":" + remote_ufrag));
- msg.AddAttribute(new cricket::StunUInt32Attribute(
- cricket::STUN_ATTR_PRIORITY, priority));
- msg.SetTransactionID(
- rtc::CreateRandomString(cricket::kStunTransactionIdLength));
+ msg.AddAttribute(new StunUInt32Attribute(STUN_ATTR_PRIORITY, priority));
+ msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength));
msg.AddMessageIntegrity(conn->local_candidate().password());
msg.AddFingerprint();
rtc::ByteBufferWriter buf;
@@ -2004,42 +2044,42 @@ class P2PTransportChannelPingTest : public testing::Test,
conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0));
}
- void OnReadyToSend(cricket::TransportChannel* channel) {
+ void OnReadyToSend(TransportChannel* channel) {
channel_ready_to_send_ = true;
}
- void OnChannelStateChanged(cricket::TransportChannelImpl* channel) {
+ void OnChannelStateChanged(TransportChannelImpl* channel) {
channel_state_ = channel->GetState();
}
- cricket::CandidatePairInterface* last_selected_candidate_pair() {
+ CandidatePairInterface* last_selected_candidate_pair() {
return last_selected_candidate_pair_;
}
int last_sent_packet_id() { return last_sent_packet_id_; }
bool channel_ready_to_send() { return channel_ready_to_send_; }
void reset_channel_ready_to_send() { channel_ready_to_send_ = false; }
- cricket::TransportChannelState channel_state() { return channel_state_; }
+ TransportChannelState channel_state() { return channel_state_; }
private:
std::unique_ptr<rtc::PhysicalSocketServer> pss_;
std::unique_ptr<rtc::VirtualSocketServer> vss_;
rtc::SocketServerScope ss_scope_;
- cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr;
+ CandidatePairInterface* last_selected_candidate_pair_ = nullptr;
int last_sent_packet_id_ = -1;
bool channel_ready_to_send_ = false;
- cricket::TransportChannelState channel_state_ = cricket::STATE_INIT;
+ TransportChannelState channel_state_ = STATE_INIT;
};
TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("trigger checks", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
@@ -2055,16 +2095,16 @@ TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
}
TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("ping sufficiently", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("ping sufficiently", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
@@ -2078,16 +2118,16 @@ TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
}
TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("trigger checks", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
@@ -2104,18 +2144,18 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
}
TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("state change", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
// Pruning the connection reduces the set of active connections and changes
// the channel state.
conn1->Prune();
- EXPECT_EQ_WAIT(cricket::STATE_FAILED, channel_state(), kDefaultTimeout);
+ EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout);
}
// Test adding remote candidates with different ufrags. If a remote candidate
@@ -2125,16 +2165,17 @@ TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
// credentials arrive. If a remote candidate is added with the current ICE
// ufrag, its pwd and generation will be set properly.
TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("add candidate", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("add candidate", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
// Add a candidate with a future ufrag.
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1, kIceUfrag[2]));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(
+ CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2]));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
- const cricket::Candidate& candidate = conn1->remote_candidate();
+ const Candidate& candidate = conn1->remote_candidate();
EXPECT_EQ(kIceUfrag[2], candidate.username());
EXPECT_TRUE(candidate.password().empty());
EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr);
@@ -2148,22 +2189,24 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
// Add a candidate with an old ufrag. No connection will be created.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2, kIceUfrag[1]));
+ ch.AddRemoteCandidate(
+ CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1]));
rtc::Thread::Current()->ProcessMessages(500);
EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
// Add a candidate with the current ufrag, its pwd and generation will be
// assigned, even if the generation is not set.
- ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 0, kIceUfrag[2]));
- cricket::Connection* conn3 = nullptr;
+ ch.AddRemoteCandidate(
+ CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 0, kIceUfrag[2]));
+ Connection* conn3 = nullptr;
ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr,
3000);
- const cricket::Candidate& new_candidate = conn3->remote_candidate();
+ const Candidate& new_candidate = conn3->remote_candidate();
EXPECT_EQ(kIcePwd[2], new_candidate.password());
EXPECT_EQ(1U, new_candidate.generation());
// Check that the pwd of all remote candidates are properly assigned.
- for (const cricket::RemoteCandidate& candidate : ch.remote_candidates()) {
+ for (const RemoteCandidate& candidate : ch.remote_candidates()) {
EXPECT_TRUE(candidate.username() == kIceUfrag[1] ||
candidate.username() == kIceUfrag[2]);
if (candidate.username() == kIceUfrag[1]) {
@@ -2175,22 +2218,22 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
}
TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("connection resurrection", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("connection resurrection", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
// Create conn1 and keep track of original candidate priority.
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
uint32_t remote_priority = conn1->remote_candidate().priority();
// Create a higher priority candidate and make the connection
// receiving/writable. This will prune conn1.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing();
conn2->ReceivedPingResponse();
@@ -2202,34 +2245,34 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
// Create a minimal STUN message with prflx priority.
- cricket::IceMessage request;
- request.SetType(cricket::STUN_BINDING_REQUEST);
- request.AddAttribute(new cricket::StunByteStringAttribute(
- cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
- uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
- request.AddAttribute(new cricket::StunUInt32Attribute(
- cricket::STUN_ATTR_PRIORITY, prflx_priority));
+ IceMessage request;
+ request.SetType(STUN_BINDING_REQUEST);
+ request.AddAttribute(
+ new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
+ uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
+ request.AddAttribute(
+ new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
EXPECT_NE(prflx_priority, remote_priority);
- cricket::Port* port = GetPort(&ch);
+ Port* port = GetPort(&ch);
// conn1 should be resurrected with original priority.
- port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
+ &request, kIceUfrag[1], false);
conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
// conn3, a real prflx connection, should have prflx priority.
- port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1);
ASSERT_TRUE(conn3 != nullptr);
EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority);
}
TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
// Default receiving timeout and checking receiving interval should not be too
// small.
@@ -2240,8 +2283,8 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
EXPECT_EQ(50, ch.check_receiving_interval());
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPing();
@@ -2258,14 +2301,14 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
// best connection changes and SignalReadyToSend will be fired if the new best
// connection is writable.
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
EXPECT_EQ(conn1, last_selected_candidate_pair());
@@ -2279,8 +2322,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
SendData(ch, data, len, ++last_packet_id);
// When a higher priority candidate comes in, the new connection is chosen
// as the best connection.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
EXPECT_EQ(conn2, ch.best_connection());
EXPECT_EQ(conn2, last_selected_candidate_pair());
@@ -2291,8 +2334,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// connection will be set as the best connection, even though
// its priority is lower.
SendData(ch, data, len, ++last_packet_id);
- ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1));
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
// Because it has a lower priority, the best connection is still conn2.
EXPECT_EQ(conn2, ch.best_connection());
@@ -2310,8 +2353,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// it will not be set as the best connection because the best connection
// is nominated by the controlling side.
SendData(ch, data, len, ++last_packet_id);
- ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100));
- cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100));
+ Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
ASSERT_TRUE(conn4 != nullptr);
EXPECT_EQ(conn3, ch.best_connection());
// But if it is nominated via use_candidate and writable, it will be set as
@@ -2336,24 +2379,24 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// request contains the use_candidate attribute. Plus, it will also sends back
// a ping response and set the ICE pwd in the remote candidate appropriately.
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
// A minimal STUN message with prflx priority.
- cricket::IceMessage request;
- request.SetType(cricket::STUN_BINDING_REQUEST);
- request.AddAttribute(new cricket::StunByteStringAttribute(
- cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
- uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
- request.AddAttribute(new cricket::StunUInt32Attribute(
- cricket::STUN_ATTR_PRIORITY, prflx_priority));
- cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch));
- port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ IceMessage request;
+ request.SetType(STUN_BINDING_REQUEST);
+ request.AddAttribute(
+ new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
+ uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
+ request.AddAttribute(
+ new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
+ TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
+ port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_TRUE(port->sent_binding_response());
EXPECT_EQ(conn1, ch.best_connection());
@@ -2362,8 +2405,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
port->set_sent_binding_response(false);
// Another connection is nominated via use_candidate.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
// Because it has a lower priority, the best connection is still conn1.
EXPECT_EQ(conn1, ch.best_connection());
@@ -2377,9 +2420,9 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
// Another request with unknown address, it will not be set as the best
// connection because the best connection was nominated by the controlling
// side.
- port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
EXPECT_TRUE(port->sent_binding_response());
conn3->ReceivedPingResponse(); // Become writable.
@@ -2388,11 +2431,10 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
// However if the request contains use_candidate attribute, it will be
// selected as the best connection.
- request.AddAttribute(
- new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE));
- port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
+ request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
+ port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
ASSERT_TRUE(conn4 != nullptr);
EXPECT_TRUE(port->sent_binding_response());
// conn4 is not the best connection yet because it is not writable.
@@ -2405,9 +2447,9 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
port->set_sent_binding_response(false);
ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
- port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5),
- cricket::PROTO_UDP, &request, kIceUfrag[2], false);
- cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP,
+ &request, kIceUfrag[2], false);
+ Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
ASSERT_TRUE(conn5 != nullptr);
EXPECT_TRUE(port->sent_binding_response());
EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password());
@@ -2418,22 +2460,22 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
// at which point the controlled side will select that connection as
// the "best connection".
TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("receiving state change", 1, &pa);
PrepareChannel(&ch);
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
// If a data packet is received on conn2, the best connection should
// switch to conn2 because the controlled side must mirror the media path
// chosen by the controlling side.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing(); // Start receiving.
// Do not switch because it is not writable.
@@ -2447,19 +2489,18 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
// Now another STUN message with an unknown address and use_candidate will
// nominate the best connection.
- cricket::IceMessage request;
- request.SetType(cricket::STUN_BINDING_REQUEST);
- request.AddAttribute(new cricket::StunByteStringAttribute(
- cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
- uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
- request.AddAttribute(new cricket::StunUInt32Attribute(
- cricket::STUN_ATTR_PRIORITY, prflx_priority));
+ IceMessage request;
+ request.SetType(STUN_BINDING_REQUEST);
+ request.AddAttribute(
+ new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
+ uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
request.AddAttribute(
- new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE));
- cricket::Port* port = GetPort(&ch);
- port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3),
- cricket::PROTO_UDP, &request, kIceUfrag[1], false);
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
+ request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
+ Port* port = GetPort(&ch);
+ port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
+ &request, kIceUfrag[1], false);
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet.
conn3->ReceivedPingResponse(); // Become writable.
@@ -2476,8 +2517,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
// Test that if a new remote candidate has the same address and port with
// an old one, it will be used to create a new connection.
TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("candidate reuse", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("candidate reuse", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
@@ -2485,16 +2526,16 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
const int port_num = 1;
// kIceUfrag[1] is the current generation ufrag.
- cricket::Candidate candidate =
- CreateHostCandidate(host_address, port_num, 1, kIceUfrag[1]);
+ Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address,
+ port_num, 1, kIceUfrag[1]);
ch.AddRemoteCandidate(candidate);
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num);
+ Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(0u, conn1->remote_candidate().generation());
// Simply adding the same candidate again won't create a new connection.
ch.AddRemoteCandidate(candidate);
- cricket::Connection* conn2 = GetConnectionTo(&ch, host_address, port_num);
+ Connection* conn2 = GetConnectionTo(&ch, host_address, port_num);
EXPECT_EQ(conn1, conn2);
// Update the ufrag of the candidate and add it again.
@@ -2515,22 +2556,22 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
// When the current best connection is strong, lower-priority connections will
// be pruned. Otherwise, lower-priority connections are kept.
TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
- ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
+ ch.SetIceRole(ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
conn1->ReceivedPingResponse(); // Becomes writable and receiving
// When a higher-priority, nominated candidate comes in, the connections with
// lower-priority are pruned.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(); // Becomes writable and receiving
conn2->set_nominated(true);
@@ -2541,8 +2582,8 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
// Wait until conn2 becomes not receiving.
EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
- ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1));
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
// The best connection should still be conn2. Even through conn3 has lower
// priority and is not receiving/writable, it is not pruned because the best
@@ -2553,41 +2594,40 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
// Test that GetState returns the state correctly.
TEST_F(P2PTransportChannelPingTest, TestGetState) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState());
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState());
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
// Now there are two connections, so the transport channel is connecting.
- EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState());
+ EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
// |conn1| becomes writable and receiving; it then should prune |conn2|.
conn1->ReceivedPingResponse();
EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
- EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
+ EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
conn1->Prune(); // All connections are pruned.
// Need to wait until the channel state is updated.
- EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(),
- 1000);
+ EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
}
// Test that when a low-priority connection is pruned, it is not deleted
// right away, and it can become active and be pruned again.
TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.SetIceConfig(CreateIceConfig(1000, false));
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
conn1->ReceivedPingResponse(); // Becomes writable and receiving
@@ -2596,53 +2636,53 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
// not be deleted right away. Once the current best connection becomes not
// receiving, |conn2| will start to ping and upon receiving the ping response,
// it will become the best connection.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
EXPECT_TRUE_WAIT(!conn2->active(), 1000);
// |conn2| should not send a ping yet.
- EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state());
- EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
+ EXPECT_EQ(Connection::STATE_WAITING, conn2->state());
+ EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
// Wait for |conn1| becoming not receiving.
EXPECT_TRUE_WAIT(!conn1->receiving(), 3000);
// Make sure conn2 is not deleted.
conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
- EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000);
+ EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000);
conn2->ReceivedPingResponse();
EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000);
- EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState());
+ EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
// When |conn1| comes back again, |conn2| will be pruned again.
conn1->ReceivedPingResponse();
EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000);
EXPECT_TRUE_WAIT(!conn2->active(), 1000);
- EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
+ EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
}
// Test that if all connections in a channel has timed out on writing, they
// will all be deleted. We use Prune to simulate write_time_out.
TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
// Have one connection only but later becomes write-time-out.
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPing(); // Becomes receiving
conn1->Prune();
EXPECT_TRUE_WAIT(ch.connections().empty(), 1000);
// Have two connections but both become write-time-out later.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing(); // Becomes receiving
- ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 2));
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 2));
+ Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
conn3->ReceivedPing(); // Becomes receiving
// Now prune both conn2 and conn3; they will be deleted soon.
@@ -2656,14 +2696,14 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
// connection belonging to an old session becomes writable, it won't stop
// the current port allocator session.
TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
- cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
- cricket::P2PTransportChannel ch("test channel", 1, &pa);
+ FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ P2PTransportChannel ch("test channel", 1, &pa);
PrepareChannel(&ch);
ch.SetIceConfig(CreateIceConfig(2000, false));
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
- cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
+ Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPingResponse(); // Becomes writable and receiving
EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
@@ -2679,8 +2719,8 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
// But if a new connection created from the new session becomes writable,
// it will stop the current session.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100));
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(); // Becomes writable and receiving
EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
@@ -2692,26 +2732,23 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
P2PTransportChannelMostLikelyToWorkFirstTest()
: turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
network_manager_.AddInterface(kPublicAddrs[0]);
- allocator_.reset(new cricket::BasicPortAllocator(
+ allocator_.reset(new BasicPortAllocator(
&network_manager_, ServerAddresses(), rtc::SocketAddress(),
rtc::SocketAddress(), rtc::SocketAddress()));
- allocator_->set_flags(allocator_->flags() |
- cricket::PORTALLOCATOR_DISABLE_STUN |
- cricket::PORTALLOCATOR_DISABLE_TCP);
- cricket::RelayServerConfig config(cricket::RELAY_TURN);
+ allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN |
+ PORTALLOCATOR_DISABLE_TCP);
+ RelayServerConfig config(RELAY_TURN);
config.credentials = kRelayCredentials;
- config.ports.push_back(
- cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
+ config.ports.push_back(ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false));
allocator_->AddTurnServer(config);
allocator_->set_step_delay(kMinimumStepDelay);
}
- cricket::P2PTransportChannel& StartTransportChannel(
+ P2PTransportChannel& StartTransportChannel(
bool prioritize_most_likely_to_work,
int max_strong_interval) {
- channel_.reset(
- new cricket::P2PTransportChannel("checks", 1, nullptr, allocator()));
- cricket::IceConfig config = channel_->config();
+ channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator()));
+ IceConfig config = channel_->config();
config.prioritize_most_likely_candidate_pairs =
prioritize_most_likely_to_work;
config.max_strong_interval = max_strong_interval;
@@ -2722,8 +2759,8 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
return *channel_.get();
}
- cricket::BasicPortAllocator* allocator() { return allocator_.get(); }
- cricket::TestTurnServer* turn_server() { return &turn_server_; }
+ BasicPortAllocator* allocator() { return allocator_.get(); }
+ TestTurnServer* turn_server() { return &turn_server_; }
// This verifies the next pingable connection has the expected candidates'
// types and, for relay local candidate, the expected relay protocol and ping
@@ -2731,30 +2768,20 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
void VerifyNextPingableConnection(
const std::string& local_candidate_type,
const std::string& remote_candidate_type,
- const std::string& relay_protocol_type = cricket::UDP_PROTOCOL_NAME) {
- cricket::Connection* conn =
- FindNextPingableConnectionAndPingIt(channel_.get());
+ const std::string& relay_protocol_type = UDP_PROTOCOL_NAME) {
+ Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get());
EXPECT_EQ(conn->local_candidate().type(), local_candidate_type);
- if (conn->local_candidate().type() == cricket::RELAY_PORT_TYPE) {
+ if (conn->local_candidate().type() == RELAY_PORT_TYPE) {
EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type);
}
EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type);
}
- cricket::Candidate CreateRelayCandidate(const std::string& ip,
- int port,
- int priority,
- const std::string& ufrag = "") {
- cricket::Candidate c = CreateHostCandidate(ip, port, priority, ufrag);
- c.set_type(cricket::RELAY_PORT_TYPE);
- return c;
- }
-
private:
- std::unique_ptr<cricket::BasicPortAllocator> allocator_;
+ std::unique_ptr<BasicPortAllocator> allocator_;
rtc::FakeNetworkManager network_manager_;
- cricket::TestTurnServer turn_server_;
- std::unique_ptr<cricket::P2PTransportChannel> channel_;
+ TestTurnServer turn_server_;
+ std::unique_ptr<P2PTransportChannel> channel_;
};
// Test that Relay/Relay connections will be pinged first when no other
@@ -2763,33 +2790,32 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
TestRelayRelayFirstWhenNothingPingedYet) {
const int max_strong_interval = 100;
- cricket::P2PTransportChannel& ch =
- StartTransportChannel(true, max_strong_interval);
+ P2PTransportChannel& ch = StartTransportChannel(true, max_strong_interval);
EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
- EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
- ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
// Relay/Relay should be the first pingable connection.
- cricket::Connection* conn = FindNextPingableConnectionAndPingIt(&ch);
- EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE);
- EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
+ Connection* conn = FindNextPingableConnectionAndPingIt(&ch);
+ EXPECT_EQ(conn->local_candidate().type(), RELAY_PORT_TYPE);
+ EXPECT_EQ(conn->remote_candidate().type(), RELAY_PORT_TYPE);
// Unless that we have a trigger check waiting to be pinged.
- cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
- EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE);
+ Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE);
conn2->ReceivedPing();
EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
// Make conn3 the best connection.
- cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
- EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
+ Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE);
conn3->ReceivedPingResponse();
ASSERT_TRUE(conn3->writable());
conn3->ReceivedPing();
@@ -2819,107 +2845,95 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
// in the first round.
TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
TestRelayRelayFirstWhenEverythingPinged) {
- cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
+ P2PTransportChannel& ch = StartTransportChannel(true, 100);
EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
- EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
- ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
// Initially, only have Local/Local and Local/Relay.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::LOCAL_PORT_TYPE);
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE);
// Remote Relay candidate arrives.
- ch.AddRemoteCandidate(CreateRelayCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
// Relay/Relay should be the first since it hasn't been pinged before.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
// Local/Relay is the final one.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
// Now, every connection has been pinged once. The next one should be
// Relay/Relay.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
}
// Test that when we receive a new remote candidate, they will be tried first
// before we re-ping Relay/Relay connections again.
TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
TestNoStarvationOnNonRelayConnection) {
- cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
+ P2PTransportChannel& ch = StartTransportChannel(true, 100);
EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
- EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
- ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
// Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
// Next, ping Local/Relay.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
// Remote Local candidate arrives.
- ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
// Local/Local should be the first since it hasn't been pinged before.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE);
// Relay/Local is the final one.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE);
// Now, every connection has been pinged once. The next one should be
// Relay/Relay.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
}
// Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay,
// followed by the rest.
TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) {
// Add a Tcp Turn server.
- turn_server()->AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
- cricket::RelayServerConfig config(cricket::RELAY_TURN);
+ turn_server()->AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
+ RelayServerConfig config(RELAY_TURN);
config.credentials = kRelayCredentials;
- config.ports.push_back(
- cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false));
+ config.ports.push_back(ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false));
allocator()->AddTurnServer(config);
- cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
+ P2PTransportChannel& ch = StartTransportChannel(true, 100);
EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000);
- EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
- EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
- EXPECT_EQ(ch.ports()[2]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[2]->Type(), RELAY_PORT_TYPE);
// Remote Relay candidate arrives.
- ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000);
// UDP Relay/Relay should be pinged first.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
// TCP Relay/Relay is the next.
- VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
- cricket::RELAY_PORT_TYPE,
- cricket::TCP_PROTOCOL_NAME);
+ VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
+ TCP_PROTOCOL_NAME);
// Finally, Local/Relay will be pinged.
- VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
- cricket::RELAY_PORT_TYPE);
+ VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
}
+
+} // namespace cricket {

Powered by Google App Engine
This is Rietveld 408576698