OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "webrtc/base/logging.h" | 26 #include "webrtc/base/logging.h" |
27 #include "webrtc/base/natserver.h" | 27 #include "webrtc/base/natserver.h" |
28 #include "webrtc/base/natsocketfactory.h" | 28 #include "webrtc/base/natsocketfactory.h" |
29 #include "webrtc/base/physicalsocketserver.h" | 29 #include "webrtc/base/physicalsocketserver.h" |
30 #include "webrtc/base/proxyserver.h" | 30 #include "webrtc/base/proxyserver.h" |
31 #include "webrtc/base/socketaddress.h" | 31 #include "webrtc/base/socketaddress.h" |
32 #include "webrtc/base/ssladapter.h" | 32 #include "webrtc/base/ssladapter.h" |
33 #include "webrtc/base/thread.h" | 33 #include "webrtc/base/thread.h" |
34 #include "webrtc/base/virtualsocketserver.h" | 34 #include "webrtc/base/virtualsocketserver.h" |
35 | 35 |
36 using cricket::kDefaultPortAllocatorFlags; | 36 namespace { |
37 using cricket::kMinimumStepDelay; | 37 |
38 using cricket::kDefaultStepDelay; | |
39 using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET; | |
40 using cricket::ServerAddresses; | |
41 using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL; | |
42 using rtc::SocketAddress; | 38 using rtc::SocketAddress; |
43 | 39 |
44 static const int kDefaultTimeout = 1000; | 40 // Default timeout for tests in this file. |
| 41 // Should be large enough for slow buildbots to run the tests reliably. |
| 42 static const int kDefaultTimeout = 10000; |
| 43 |
45 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | | 44 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | |
46 cricket::PORTALLOCATOR_DISABLE_RELAY | | 45 cricket::PORTALLOCATOR_DISABLE_RELAY | |
47 cricket::PORTALLOCATOR_DISABLE_TCP; | 46 cricket::PORTALLOCATOR_DISABLE_TCP; |
48 static const int LOW_RTT = 20; | 47 static const int LOW_RTT = 20; |
49 // Addresses on the public internet. | 48 // Addresses on the public internet. |
50 static const SocketAddress kPublicAddrs[2] = | 49 static const SocketAddress kPublicAddrs[2] = |
51 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; | 50 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; |
52 // IPv6 Addresses on the public internet. | 51 // IPv6 Addresses on the public internet. |
53 static const SocketAddress kIPv6PublicAddrs[2] = { | 52 static const SocketAddress kIPv6PublicAddrs[2] = { |
54 SocketAddress("2400:4030:1:2c00:be30:abcd:efab:cdef", 0), | 53 SocketAddress("2400:4030:1:2c00:be30:abcd:efab:cdef", 0), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", | 98 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", |
100 "TESTICEPWD00000000000001", | 99 "TESTICEPWD00000000000001", |
101 "TESTICEPWD00000000000002", | 100 "TESTICEPWD00000000000002", |
102 "TESTICEPWD00000000000003"}; | 101 "TESTICEPWD00000000000003"}; |
103 | 102 |
104 static const uint64_t kTiebreaker1 = 11111; | 103 static const uint64_t kTiebreaker1 = 11111; |
105 static const uint64_t kTiebreaker2 = 22222; | 104 static const uint64_t kTiebreaker2 = 22222; |
106 | 105 |
107 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES }; | 106 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES }; |
108 | 107 |
109 static cricket::IceConfig CreateIceConfig(int receiving_timeout, | 108 cricket::IceConfig CreateIceConfig(int receiving_timeout, |
110 bool gather_continually, | 109 bool gather_continually, |
111 int backup_ping_interval = -1) { | 110 int backup_ping_interval = -1) { |
112 cricket::IceConfig config; | 111 cricket::IceConfig config; |
113 config.receiving_timeout = receiving_timeout; | 112 config.receiving_timeout = receiving_timeout; |
114 config.gather_continually = gather_continually; | 113 config.gather_continually = gather_continually; |
115 config.backup_connection_ping_interval = backup_ping_interval; | 114 config.backup_connection_ping_interval = backup_ping_interval; |
116 return config; | 115 return config; |
117 } | 116 } |
118 | 117 |
| 118 cricket::Candidate CreateUdpCandidate(const std::string& type, |
| 119 const std::string& ip, |
| 120 int port, |
| 121 int priority, |
| 122 const std::string& ufrag = "") { |
| 123 cricket::Candidate c; |
| 124 c.set_address(rtc::SocketAddress(ip, port)); |
| 125 c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 126 c.set_protocol(cricket::UDP_PROTOCOL_NAME); |
| 127 c.set_priority(priority); |
| 128 c.set_username(ufrag); |
| 129 c.set_type(type); |
| 130 return c; |
| 131 } |
| 132 |
| 133 } // namespace { |
| 134 |
| 135 namespace cricket { |
| 136 |
119 // This test simulates 2 P2P endpoints that want to establish connectivity | 137 // This test simulates 2 P2P endpoints that want to establish connectivity |
120 // with each other over various network topologies and conditions, which can be | 138 // with each other over various network topologies and conditions, which can be |
121 // specified in each individial test. | 139 // specified in each individial test. |
122 // A virtual network (via VirtualSocketServer) along with virtual firewalls and | 140 // A virtual network (via VirtualSocketServer) along with virtual firewalls and |
123 // NATs (via Firewall/NATSocketServer) are used to simulate the various network | 141 // NATs (via Firewall/NATSocketServer) are used to simulate the various network |
124 // conditions. We can configure the IP addresses of the endpoints, | 142 // conditions. We can configure the IP addresses of the endpoints, |
125 // block various types of connectivity, or add arbitrary levels of NAT. | 143 // block various types of connectivity, or add arbitrary levels of NAT. |
126 // We also run a STUN server and a relay server on the virtual network to allow | 144 // We also run a STUN server and a relay server on the virtual network to allow |
127 // our typical P2P mechanisms to do their thing. | 145 // our typical P2P mechanisms to do their thing. |
128 // For each case, we expect the P2P stack to eventually settle on a specific | 146 // For each case, we expect the P2P stack to eventually settle on a specific |
129 // form of connectivity to the other side. The test checks that the P2P | 147 // form of connectivity to the other side. The test checks that the P2P |
130 // negotiation successfully establishes connectivity within a certain time, | 148 // negotiation successfully establishes connectivity within a certain time, |
131 // and that the result is what we expect. | 149 // and that the result is what we expect. |
132 // Note that this class is a base class for use by other tests, who will provide | 150 // Note that this class is a base class for use by other tests, who will provide |
133 // specialized test behavior. | 151 // specialized test behavior. |
134 class P2PTransportChannelTestBase : public testing::Test, | 152 class P2PTransportChannelTestBase : public testing::Test, |
135 public rtc::MessageHandler, | 153 public rtc::MessageHandler, |
136 public sigslot::has_slots<> { | 154 public sigslot::has_slots<> { |
137 public: | 155 public: |
138 P2PTransportChannelTestBase() | 156 P2PTransportChannelTestBase() |
139 : main_(rtc::Thread::Current()), | 157 : main_(rtc::Thread::Current()), |
140 pss_(new rtc::PhysicalSocketServer), | 158 pss_(new rtc::PhysicalSocketServer), |
141 vss_(new rtc::VirtualSocketServer(pss_.get())), | 159 vss_(new rtc::VirtualSocketServer(pss_.get())), |
142 nss_(new rtc::NATSocketServer(vss_.get())), | 160 nss_(new rtc::NATSocketServer(vss_.get())), |
143 ss_(new rtc::FirewallSocketServer(nss_.get())), | 161 ss_(new rtc::FirewallSocketServer(nss_.get())), |
144 ss_scope_(ss_.get()), | 162 ss_scope_(ss_.get()), |
145 stun_server_(cricket::TestStunServer::Create(main_, kStunAddr)), | 163 stun_server_(TestStunServer::Create(main_, kStunAddr)), |
146 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), | 164 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), |
147 relay_server_(main_, kRelayUdpIntAddr, kRelayUdpExtAddr, | 165 relay_server_(main_, |
148 kRelayTcpIntAddr, kRelayTcpExtAddr, | 166 kRelayUdpIntAddr, |
149 kRelaySslTcpIntAddr, kRelaySslTcpExtAddr), | 167 kRelayUdpExtAddr, |
150 socks_server1_(ss_.get(), kSocksProxyAddrs[0], | 168 kRelayTcpIntAddr, |
151 ss_.get(), kSocksProxyAddrs[0]), | 169 kRelayTcpExtAddr, |
152 socks_server2_(ss_.get(), kSocksProxyAddrs[1], | 170 kRelaySslTcpIntAddr, |
153 ss_.get(), kSocksProxyAddrs[1]), | 171 kRelaySslTcpExtAddr), |
| 172 socks_server1_(ss_.get(), |
| 173 kSocksProxyAddrs[0], |
| 174 ss_.get(), |
| 175 kSocksProxyAddrs[0]), |
| 176 socks_server2_(ss_.get(), |
| 177 kSocksProxyAddrs[1], |
| 178 ss_.get(), |
| 179 kSocksProxyAddrs[1]), |
154 force_relay_(false) { | 180 force_relay_(false) { |
155 ep1_.role_ = cricket::ICEROLE_CONTROLLING; | 181 ep1_.role_ = ICEROLE_CONTROLLING; |
156 ep2_.role_ = cricket::ICEROLE_CONTROLLED; | 182 ep2_.role_ = ICEROLE_CONTROLLED; |
157 | 183 |
158 ServerAddresses stun_servers; | 184 ServerAddresses stun_servers; |
159 stun_servers.insert(kStunAddr); | 185 stun_servers.insert(kStunAddr); |
160 ep1_.allocator_.reset(new cricket::BasicPortAllocator( | 186 ep1_.allocator_.reset(new BasicPortAllocator( |
161 &ep1_.network_manager_, | 187 &ep1_.network_manager_, stun_servers, kRelayUdpIntAddr, |
162 stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); | 188 kRelayTcpIntAddr, kRelaySslTcpIntAddr)); |
163 ep2_.allocator_.reset(new cricket::BasicPortAllocator( | 189 ep2_.allocator_.reset(new BasicPortAllocator( |
164 &ep2_.network_manager_, | 190 &ep2_.network_manager_, stun_servers, kRelayUdpIntAddr, |
165 stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); | 191 kRelayTcpIntAddr, kRelaySslTcpIntAddr)); |
166 } | 192 } |
167 | 193 |
168 protected: | 194 protected: |
169 enum Config { | 195 enum Config { |
170 OPEN, // Open to the Internet | 196 OPEN, // Open to the Internet |
171 NAT_FULL_CONE, // NAT, no filtering | 197 NAT_FULL_CONE, // NAT, no filtering |
172 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv | 198 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv |
173 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv | 199 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv |
174 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings | 200 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings |
175 NAT_DOUBLE_CONE, // Double NAT, both cone | 201 NAT_DOUBLE_CONE, // Double NAT, both cone |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 if (!ch_packets_.empty()) { | 235 if (!ch_packets_.empty()) { |
210 std::string packet = ch_packets_.front(); | 236 std::string packet = ch_packets_.front(); |
211 ret = (packet == std::string(data, len)); | 237 ret = (packet == std::string(data, len)); |
212 ch_packets_.pop_front(); | 238 ch_packets_.pop_front(); |
213 } | 239 } |
214 return ret; | 240 return ret; |
215 } | 241 } |
216 | 242 |
217 std::string name_; // TODO - Currently not used. | 243 std::string name_; // TODO - Currently not used. |
218 std::list<std::string> ch_packets_; | 244 std::list<std::string> ch_packets_; |
219 std::unique_ptr<cricket::P2PTransportChannel> ch_; | 245 std::unique_ptr<P2PTransportChannel> ch_; |
220 }; | 246 }; |
221 | 247 |
222 struct CandidatesData : public rtc::MessageData { | 248 struct CandidatesData : public rtc::MessageData { |
223 CandidatesData(cricket::TransportChannel* ch, const cricket::Candidate& c) | 249 CandidatesData(TransportChannel* ch, const Candidate& c) |
224 : channel(ch), candidates(1, c) {} | 250 : channel(ch), candidates(1, c) {} |
225 CandidatesData(cricket::TransportChannel* ch, | 251 CandidatesData(TransportChannel* ch, const std::vector<Candidate>& cc) |
226 const std::vector<cricket::Candidate>& cc) | |
227 : channel(ch), candidates(cc) {} | 252 : channel(ch), candidates(cc) {} |
228 cricket::TransportChannel* channel; | 253 TransportChannel* channel; |
229 cricket::Candidates candidates; | 254 Candidates candidates; |
230 }; | 255 }; |
231 | 256 |
232 struct Endpoint { | 257 struct Endpoint { |
233 Endpoint() | 258 Endpoint() |
234 : role_(cricket::ICEROLE_UNKNOWN), | 259 : role_(ICEROLE_UNKNOWN), |
235 tiebreaker_(0), | 260 tiebreaker_(0), |
236 role_conflict_(false), | 261 role_conflict_(false), |
237 save_candidates_(false) {} | 262 save_candidates_(false) {} |
238 bool HasChannel(cricket::TransportChannel* ch) { | 263 bool HasChannel(TransportChannel* ch) { |
239 return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get()); | 264 return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get()); |
240 } | 265 } |
241 ChannelData* GetChannelData(cricket::TransportChannel* ch) { | 266 ChannelData* GetChannelData(TransportChannel* ch) { |
242 if (!HasChannel(ch)) return NULL; | 267 if (!HasChannel(ch)) return NULL; |
243 if (cd1_.ch_.get() == ch) | 268 if (cd1_.ch_.get() == ch) |
244 return &cd1_; | 269 return &cd1_; |
245 else | 270 else |
246 return &cd2_; | 271 return &cd2_; |
247 } | 272 } |
248 | 273 |
249 void SetIceRole(cricket::IceRole role) { role_ = role; } | 274 void SetIceRole(IceRole role) { role_ = role; } |
250 cricket::IceRole ice_role() { return role_; } | 275 IceRole ice_role() { return role_; } |
251 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } | 276 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } |
252 uint64_t GetIceTiebreaker() { return tiebreaker_; } | 277 uint64_t GetIceTiebreaker() { return tiebreaker_; } |
253 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } | 278 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } |
254 bool role_conflict() { return role_conflict_; } | 279 bool role_conflict() { return role_conflict_; } |
255 void SetAllocationStepDelay(uint32_t delay) { | 280 void SetAllocationStepDelay(uint32_t delay) { |
256 allocator_->set_step_delay(delay); | 281 allocator_->set_step_delay(delay); |
257 } | 282 } |
258 void SetAllowTcpListen(bool allow_tcp_listen) { | 283 void SetAllowTcpListen(bool allow_tcp_listen) { |
259 allocator_->set_allow_tcp_listen(allow_tcp_listen); | 284 allocator_->set_allow_tcp_listen(allow_tcp_listen); |
260 } | 285 } |
261 | 286 |
262 rtc::FakeNetworkManager network_manager_; | 287 rtc::FakeNetworkManager network_manager_; |
263 std::unique_ptr<cricket::BasicPortAllocator> allocator_; | 288 std::unique_ptr<BasicPortAllocator> allocator_; |
264 ChannelData cd1_; | 289 ChannelData cd1_; |
265 ChannelData cd2_; | 290 ChannelData cd2_; |
266 cricket::IceRole role_; | 291 IceRole role_; |
267 uint64_t tiebreaker_; | 292 uint64_t tiebreaker_; |
268 bool role_conflict_; | 293 bool role_conflict_; |
269 bool save_candidates_; | 294 bool save_candidates_; |
270 std::vector<CandidatesData*> saved_candidates_; | 295 std::vector<CandidatesData*> saved_candidates_; |
| 296 bool ready_to_send_ = false; |
271 }; | 297 }; |
272 | 298 |
273 ChannelData* GetChannelData(cricket::TransportChannel* channel) { | 299 ChannelData* GetChannelData(TransportChannel* channel) { |
274 if (ep1_.HasChannel(channel)) | 300 if (ep1_.HasChannel(channel)) |
275 return ep1_.GetChannelData(channel); | 301 return ep1_.GetChannelData(channel); |
276 else | 302 else |
277 return ep2_.GetChannelData(channel); | 303 return ep2_.GetChannelData(channel); |
278 } | 304 } |
279 | 305 |
280 void CreateChannels(int num) { | 306 void CreateChannels(int num) { |
281 std::string ice_ufrag_ep1_cd1_ch = kIceUfrag[0]; | 307 std::string ice_ufrag_ep1_cd1_ch = kIceUfrag[0]; |
282 std::string ice_pwd_ep1_cd1_ch = kIcePwd[0]; | 308 std::string ice_pwd_ep1_cd1_ch = kIcePwd[0]; |
283 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1]; | 309 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1]; |
284 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1]; | 310 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1]; |
285 ep1_.cd1_.ch_.reset(CreateChannel( | 311 ep1_.cd1_.ch_.reset(CreateChannel( |
286 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, | 312 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd1_ch, |
287 ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch, | 313 ice_pwd_ep1_cd1_ch, ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch)); |
288 ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch)); | |
289 ep2_.cd1_.ch_.reset(CreateChannel( | 314 ep2_.cd1_.ch_.reset(CreateChannel( |
290 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, | 315 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd1_ch, |
291 ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch, | 316 ice_pwd_ep2_cd1_ch, ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch)); |
292 ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch)); | |
293 ep1_.cd1_.ch_->MaybeStartGathering(); | 317 ep1_.cd1_.ch_->MaybeStartGathering(); |
294 ep2_.cd1_.ch_->MaybeStartGathering(); | 318 ep2_.cd1_.ch_->MaybeStartGathering(); |
295 if (num == 2) { | 319 if (num == 2) { |
296 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2]; | 320 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2]; |
297 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2]; | 321 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2]; |
298 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3]; | 322 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3]; |
299 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3]; | 323 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3]; |
300 ep1_.cd2_.ch_.reset(CreateChannel( | 324 ep1_.cd2_.ch_.reset(CreateChannel( |
301 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, | 325 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd2_ch, |
302 ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch, | 326 ice_pwd_ep1_cd2_ch, ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch)); |
303 ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch)); | |
304 ep2_.cd2_.ch_.reset(CreateChannel( | 327 ep2_.cd2_.ch_.reset(CreateChannel( |
305 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, | 328 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd2_ch, |
306 ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch, | 329 ice_pwd_ep2_cd2_ch, ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch)); |
307 ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch)); | |
308 ep1_.cd2_.ch_->MaybeStartGathering(); | 330 ep1_.cd2_.ch_->MaybeStartGathering(); |
309 ep2_.cd2_.ch_->MaybeStartGathering(); | 331 ep2_.cd2_.ch_->MaybeStartGathering(); |
310 } | 332 } |
311 } | 333 } |
312 cricket::P2PTransportChannel* CreateChannel( | 334 P2PTransportChannel* CreateChannel(int endpoint, |
313 int endpoint, | 335 int component, |
314 int component, | 336 const std::string& local_ice_ufrag, |
315 const std::string& local_ice_ufrag, | 337 const std::string& local_ice_pwd, |
316 const std::string& local_ice_pwd, | 338 const std::string& remote_ice_ufrag, |
317 const std::string& remote_ice_ufrag, | 339 const std::string& remote_ice_pwd) { |
318 const std::string& remote_ice_pwd) { | 340 P2PTransportChannel* channel = new P2PTransportChannel( |
319 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( | |
320 "test content name", component, GetAllocator(endpoint)); | 341 "test content name", component, GetAllocator(endpoint)); |
| 342 channel->SignalReadyToSend.connect( |
| 343 this, &P2PTransportChannelTestBase::OnReadyToSend); |
321 channel->SignalCandidateGathered.connect( | 344 channel->SignalCandidateGathered.connect( |
322 this, &P2PTransportChannelTestBase::OnCandidateGathered); | 345 this, &P2PTransportChannelTestBase::OnCandidateGathered); |
323 channel->SignalCandidatesRemoved.connect( | 346 channel->SignalCandidatesRemoved.connect( |
324 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); | 347 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); |
325 channel->SignalReadPacket.connect( | 348 channel->SignalReadPacket.connect( |
326 this, &P2PTransportChannelTestBase::OnReadPacket); | 349 this, &P2PTransportChannelTestBase::OnReadPacket); |
327 channel->SignalRoleConflict.connect( | 350 channel->SignalRoleConflict.connect( |
328 this, &P2PTransportChannelTestBase::OnRoleConflict); | 351 this, &P2PTransportChannelTestBase::OnRoleConflict); |
329 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); | 352 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); |
330 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { | 353 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { |
331 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); | 354 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); |
332 } | 355 } |
333 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); | 356 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); |
334 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); | 357 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); |
335 channel->Connect(); | 358 channel->Connect(); |
336 return channel; | 359 return channel; |
337 } | 360 } |
338 void DestroyChannels() { | 361 void DestroyChannels() { |
339 ep1_.cd1_.ch_.reset(); | 362 ep1_.cd1_.ch_.reset(); |
340 ep2_.cd1_.ch_.reset(); | 363 ep2_.cd1_.ch_.reset(); |
341 ep1_.cd2_.ch_.reset(); | 364 ep1_.cd2_.ch_.reset(); |
342 ep2_.cd2_.ch_.reset(); | 365 ep2_.cd2_.ch_.reset(); |
343 } | 366 } |
344 cricket::P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } | 367 P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } |
345 cricket::P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } | 368 P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } |
346 cricket::P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); } | 369 P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); } |
347 cricket::P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); } | 370 P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); } |
348 | 371 |
349 // Common results. | 372 // Common results. |
350 static const Result kLocalUdpToLocalUdp; | 373 static const Result kLocalUdpToLocalUdp; |
351 static const Result kLocalUdpToStunUdp; | 374 static const Result kLocalUdpToStunUdp; |
352 static const Result kLocalUdpToPrflxUdp; | 375 static const Result kLocalUdpToPrflxUdp; |
353 static const Result kPrflxUdpToLocalUdp; | 376 static const Result kPrflxUdpToLocalUdp; |
354 static const Result kStunUdpToLocalUdp; | 377 static const Result kStunUdpToLocalUdp; |
355 static const Result kStunUdpToStunUdp; | 378 static const Result kStunUdpToStunUdp; |
356 static const Result kPrflxUdpToStunUdp; | 379 static const Result kPrflxUdpToStunUdp; |
357 static const Result kLocalUdpToRelayUdp; | 380 static const Result kLocalUdpToRelayUdp; |
358 static const Result kPrflxUdpToRelayUdp; | 381 static const Result kPrflxUdpToRelayUdp; |
359 static const Result kLocalTcpToLocalTcp; | 382 static const Result kLocalTcpToLocalTcp; |
360 static const Result kLocalTcpToPrflxTcp; | 383 static const Result kLocalTcpToPrflxTcp; |
361 static const Result kPrflxTcpToLocalTcp; | 384 static const Result kPrflxTcpToLocalTcp; |
362 | 385 |
363 rtc::NATSocketServer* nat() { return nss_.get(); } | 386 rtc::NATSocketServer* nat() { return nss_.get(); } |
364 rtc::FirewallSocketServer* fw() { return ss_.get(); } | 387 rtc::FirewallSocketServer* fw() { return ss_.get(); } |
365 | 388 |
366 Endpoint* GetEndpoint(int endpoint) { | 389 Endpoint* GetEndpoint(int endpoint) { |
367 if (endpoint == 0) { | 390 if (endpoint == 0) { |
368 return &ep1_; | 391 return &ep1_; |
369 } else if (endpoint == 1) { | 392 } else if (endpoint == 1) { |
370 return &ep2_; | 393 return &ep2_; |
371 } else { | 394 } else { |
372 return NULL; | 395 return NULL; |
373 } | 396 } |
374 } | 397 } |
375 cricket::PortAllocator* GetAllocator(int endpoint) { | 398 PortAllocator* GetAllocator(int endpoint) { |
376 return GetEndpoint(endpoint)->allocator_.get(); | 399 return GetEndpoint(endpoint)->allocator_.get(); |
377 } | 400 } |
378 void AddAddress(int endpoint, const SocketAddress& addr) { | 401 void AddAddress(int endpoint, const SocketAddress& addr) { |
379 GetEndpoint(endpoint)->network_manager_.AddInterface(addr); | 402 GetEndpoint(endpoint)->network_manager_.AddInterface(addr); |
380 } | 403 } |
381 void AddAddress(int endpoint, | 404 void AddAddress(int endpoint, |
382 const SocketAddress& addr, | 405 const SocketAddress& addr, |
383 const std::string& ifname, | 406 const std::string& ifname, |
384 rtc::AdapterType adapter_type) { | 407 rtc::AdapterType adapter_type) { |
385 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname, | 408 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname, |
386 adapter_type); | 409 adapter_type); |
387 } | 410 } |
388 void RemoveAddress(int endpoint, const SocketAddress& addr) { | 411 void RemoveAddress(int endpoint, const SocketAddress& addr) { |
389 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr); | 412 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr); |
390 } | 413 } |
391 void SetProxy(int endpoint, rtc::ProxyType type) { | 414 void SetProxy(int endpoint, rtc::ProxyType type) { |
392 rtc::ProxyInfo info; | 415 rtc::ProxyInfo info; |
393 info.type = type; | 416 info.type = type; |
394 info.address = (type == rtc::PROXY_HTTPS) ? | 417 info.address = (type == rtc::PROXY_HTTPS) ? |
395 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint]; | 418 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint]; |
396 GetAllocator(endpoint)->set_proxy("unittest/1.0", info); | 419 GetAllocator(endpoint)->set_proxy("unittest/1.0", info); |
397 } | 420 } |
398 void SetAllocatorFlags(int endpoint, int flags) { | 421 void SetAllocatorFlags(int endpoint, int flags) { |
399 GetAllocator(endpoint)->set_flags(flags); | 422 GetAllocator(endpoint)->set_flags(flags); |
400 } | 423 } |
401 void SetIceRole(int endpoint, cricket::IceRole role) { | 424 void SetIceRole(int endpoint, IceRole role) { |
402 GetEndpoint(endpoint)->SetIceRole(role); | 425 GetEndpoint(endpoint)->SetIceRole(role); |
403 } | 426 } |
404 void SetIceTiebreaker(int endpoint, uint64_t tiebreaker) { | 427 void SetIceTiebreaker(int endpoint, uint64_t tiebreaker) { |
405 GetEndpoint(endpoint)->SetIceTiebreaker(tiebreaker); | 428 GetEndpoint(endpoint)->SetIceTiebreaker(tiebreaker); |
406 } | 429 } |
407 bool GetRoleConflict(int endpoint) { | 430 bool GetRoleConflict(int endpoint) { |
408 return GetEndpoint(endpoint)->role_conflict(); | 431 return GetEndpoint(endpoint)->role_conflict(); |
409 } | 432 } |
410 void SetAllocationStepDelay(int endpoint, uint32_t delay) { | 433 void SetAllocationStepDelay(int endpoint, uint32_t delay) { |
411 return GetEndpoint(endpoint)->SetAllocationStepDelay(delay); | 434 return GetEndpoint(endpoint)->SetAllocationStepDelay(delay); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 // restart the ice gathering. Finally it waits for the transport to select a | 606 // restart the ice gathering. Finally it waits for the transport to select a |
584 // new connection using the newly generated ice candidates. | 607 // new connection using the newly generated ice candidates. |
585 // Before calling this function the end points must be configured. | 608 // Before calling this function the end points must be configured. |
586 void TestHandleIceUfragPasswordChanged() { | 609 void TestHandleIceUfragPasswordChanged() { |
587 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 610 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
588 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 611 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
589 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 612 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
590 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 613 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
591 1000, 1000); | 614 1000, 1000); |
592 | 615 |
593 const cricket::Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); | 616 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); |
594 const cricket::Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); | 617 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); |
595 const cricket::Candidate* old_remote_candidate1 = | 618 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1()); |
596 RemoteCandidate(ep1_ch1()); | 619 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1()); |
597 const cricket::Candidate* old_remote_candidate2 = | |
598 RemoteCandidate(ep2_ch1()); | |
599 | 620 |
600 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); | 621 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); |
601 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 622 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
602 ep1_ch1()->MaybeStartGathering(); | 623 ep1_ch1()->MaybeStartGathering(); |
603 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); | 624 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); |
604 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 625 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
605 ep2_ch1()->MaybeStartGathering(); | 626 ep2_ch1()->MaybeStartGathering(); |
606 | 627 |
607 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != | 628 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != |
608 old_local_candidate1->generation(), | 629 old_local_candidate1->generation(), |
609 1000, 1000); | 630 1000, 1000); |
610 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != | 631 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != |
611 old_local_candidate2->generation(), | 632 old_local_candidate2->generation(), |
612 1000, 1000); | 633 1000, 1000); |
613 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != | 634 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != |
614 old_remote_candidate1->generation(), | 635 old_remote_candidate1->generation(), |
615 1000, 1000); | 636 1000, 1000); |
616 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep2_ch1())->generation() != | 637 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep2_ch1())->generation() != |
617 old_remote_candidate2->generation(), | 638 old_remote_candidate2->generation(), |
618 1000, 1000); | 639 1000, 1000); |
619 EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation()); | 640 EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation()); |
620 EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation()); | 641 EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation()); |
621 } | 642 } |
622 | 643 |
623 void TestSignalRoleConflict() { | 644 void TestSignalRoleConflict() { |
624 SetIceTiebreaker(0, kTiebreaker1); // Default EP1 is in controlling state. | 645 SetIceTiebreaker(0, kTiebreaker1); // Default EP1 is in controlling state. |
625 | 646 |
626 SetIceRole(1, cricket::ICEROLE_CONTROLLING); | 647 SetIceRole(1, ICEROLE_CONTROLLING); |
627 SetIceTiebreaker(1, kTiebreaker2); | 648 SetIceTiebreaker(1, kTiebreaker2); |
628 | 649 |
629 // Creating channels with both channels role set to CONTROLLING. | 650 // Creating channels with both channels role set to CONTROLLING. |
630 CreateChannels(1); | 651 CreateChannels(1); |
631 // Since both the channels initiated with controlling state and channel2 | 652 // Since both the channels initiated with controlling state and channel2 |
632 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. | 653 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. |
633 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); | 654 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); |
634 EXPECT_FALSE(GetRoleConflict(1)); | 655 EXPECT_FALSE(GetRoleConflict(1)); |
635 | 656 |
636 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && | 657 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
637 ep1_ch1()->writable() && | 658 ep1_ch1()->writable() && |
638 ep2_ch1()->receiving() && | 659 ep2_ch1()->receiving() && |
639 ep2_ch1()->writable(), | 660 ep2_ch1()->writable(), |
640 1000); | 661 1000); |
641 | 662 |
642 EXPECT_TRUE(ep1_ch1()->best_connection() && | 663 EXPECT_TRUE(ep1_ch1()->best_connection() && |
643 ep2_ch1()->best_connection()); | 664 ep2_ch1()->best_connection()); |
644 | 665 |
645 TestSendRecv(1); | 666 TestSendRecv(1); |
646 } | 667 } |
647 | 668 |
| 669 void OnReadyToSend(TransportChannel* ch) { |
| 670 GetEndpoint(ch)->ready_to_send_ = true; |
| 671 } |
| 672 |
648 // We pass the candidates directly to the other side. | 673 // We pass the candidates directly to the other side. |
649 void OnCandidateGathered(cricket::TransportChannelImpl* ch, | 674 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { |
650 const cricket::Candidate& c) { | 675 if (force_relay_ && c.type() != RELAY_PORT_TYPE) |
651 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) | |
652 return; | 676 return; |
653 | 677 |
654 if (GetEndpoint(ch)->save_candidates_) { | 678 if (GetEndpoint(ch)->save_candidates_) { |
655 GetEndpoint(ch)->saved_candidates_.push_back(new CandidatesData(ch, c)); | 679 GetEndpoint(ch)->saved_candidates_.push_back(new CandidatesData(ch, c)); |
656 } else { | 680 } else { |
657 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, | 681 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, |
658 new CandidatesData(ch, c)); | 682 new CandidatesData(ch, c)); |
659 } | 683 } |
660 } | 684 } |
661 | 685 |
662 void PauseCandidates(int endpoint) { | 686 void PauseCandidates(int endpoint) { |
663 GetEndpoint(endpoint)->save_candidates_ = true; | 687 GetEndpoint(endpoint)->save_candidates_ = true; |
664 } | 688 } |
665 | 689 |
666 void OnCandidatesRemoved(cricket::TransportChannelImpl* ch, | 690 void OnCandidatesRemoved(TransportChannelImpl* ch, |
667 const std::vector<cricket::Candidate>& candidates) { | 691 const std::vector<Candidate>& candidates) { |
668 // Candidate removals are not paused. | 692 // Candidate removals are not paused. |
669 CandidatesData* candidates_data = new CandidatesData(ch, candidates); | 693 CandidatesData* candidates_data = new CandidatesData(ch, candidates); |
670 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data); | 694 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data); |
671 } | 695 } |
672 | 696 |
673 // Tcp candidate verification has to be done when they are generated. | 697 // Tcp candidate verification has to be done when they are generated. |
674 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) { | 698 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) { |
675 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) { | 699 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) { |
676 for (auto& candidate : data->candidates) { | 700 for (auto& candidate : data->candidates) { |
677 EXPECT_EQ(candidate.protocol(), cricket::TCP_PROTOCOL_NAME); | 701 EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME); |
678 EXPECT_EQ(candidate.tcptype(), tcptype); | 702 EXPECT_EQ(candidate.tcptype(), tcptype); |
679 if (candidate.tcptype() == cricket::TCPTYPE_ACTIVE_STR) { | 703 if (candidate.tcptype() == TCPTYPE_ACTIVE_STR) { |
680 EXPECT_EQ(candidate.address().port(), cricket::DISCARD_PORT); | 704 EXPECT_EQ(candidate.address().port(), DISCARD_PORT); |
681 } else if (candidate.tcptype() == cricket::TCPTYPE_PASSIVE_STR) { | 705 } else if (candidate.tcptype() == TCPTYPE_PASSIVE_STR) { |
682 EXPECT_NE(candidate.address().port(), cricket::DISCARD_PORT); | 706 EXPECT_NE(candidate.address().port(), DISCARD_PORT); |
683 } else { | 707 } else { |
684 FAIL() << "Unknown tcptype: " << candidate.tcptype(); | 708 FAIL() << "Unknown tcptype: " << candidate.tcptype(); |
685 } | 709 } |
686 } | 710 } |
687 } | 711 } |
688 } | 712 } |
689 | 713 |
690 void ResumeCandidates(int endpoint) { | 714 void ResumeCandidates(int endpoint) { |
691 Endpoint* ed = GetEndpoint(endpoint); | 715 Endpoint* ed = GetEndpoint(endpoint); |
692 std::vector<CandidatesData*>::iterator it = ed->saved_candidates_.begin(); | 716 std::vector<CandidatesData*>::iterator it = ed->saved_candidates_.begin(); |
693 for (; it != ed->saved_candidates_.end(); ++it) { | 717 for (; it != ed->saved_candidates_.end(); ++it) { |
694 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, *it); | 718 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, *it); |
695 } | 719 } |
696 ed->saved_candidates_.clear(); | 720 ed->saved_candidates_.clear(); |
697 ed->save_candidates_ = false; | 721 ed->save_candidates_ = false; |
698 } | 722 } |
699 | 723 |
700 void OnMessage(rtc::Message* msg) { | 724 void OnMessage(rtc::Message* msg) { |
701 switch (msg->message_id) { | 725 switch (msg->message_id) { |
702 case MSG_ADD_CANDIDATES: { | 726 case MSG_ADD_CANDIDATES: { |
703 std::unique_ptr<CandidatesData> data( | 727 std::unique_ptr<CandidatesData> data( |
704 static_cast<CandidatesData*>(msg->pdata)); | 728 static_cast<CandidatesData*>(msg->pdata)); |
705 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); | 729 P2PTransportChannel* rch = GetRemoteChannel(data->channel); |
| 730 if (!rch) { |
| 731 return; |
| 732 } |
706 for (auto& c : data->candidates) { | 733 for (auto& c : data->candidates) { |
707 if (remote_ice_credential_source_ != FROM_CANDIDATE) { | 734 if (remote_ice_credential_source_ != FROM_CANDIDATE) { |
708 c.set_username(""); | 735 c.set_username(""); |
709 c.set_password(""); | 736 c.set_password(""); |
710 } | 737 } |
711 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" | 738 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" |
712 << rch->component() << "): " << c.ToString(); | 739 << rch->component() << "): " << c.ToString(); |
713 rch->AddRemoteCandidate(c); | 740 rch->AddRemoteCandidate(c); |
714 } | 741 } |
715 break; | 742 break; |
716 } | 743 } |
717 case MSG_REMOVE_CANDIDATES: { | 744 case MSG_REMOVE_CANDIDATES: { |
718 std::unique_ptr<CandidatesData> data( | 745 std::unique_ptr<CandidatesData> data( |
719 static_cast<CandidatesData*>(msg->pdata)); | 746 static_cast<CandidatesData*>(msg->pdata)); |
720 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); | 747 P2PTransportChannel* rch = GetRemoteChannel(data->channel); |
721 for (cricket::Candidate& c : data->candidates) { | 748 if (!rch) { |
| 749 return; |
| 750 } |
| 751 for (Candidate& c : data->candidates) { |
722 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); | 752 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); |
723 rch->RemoveRemoteCandidate(c); | 753 rch->RemoveRemoteCandidate(c); |
724 } | 754 } |
725 break; | 755 break; |
726 } | 756 } |
727 } | 757 } |
728 } | 758 } |
729 void OnReadPacket(cricket::TransportChannel* channel, const char* data, | 759 void OnReadPacket(TransportChannel* channel, |
730 size_t len, const rtc::PacketTime& packet_time, | 760 const char* data, |
| 761 size_t len, |
| 762 const rtc::PacketTime& packet_time, |
731 int flags) { | 763 int flags) { |
732 std::list<std::string>& packets = GetPacketList(channel); | 764 std::list<std::string>& packets = GetPacketList(channel); |
733 packets.push_front(std::string(data, len)); | 765 packets.push_front(std::string(data, len)); |
734 } | 766 } |
735 void OnRoleConflict(cricket::TransportChannelImpl* channel) { | 767 void OnRoleConflict(TransportChannelImpl* channel) { |
736 GetEndpoint(channel)->OnRoleConflict(true); | 768 GetEndpoint(channel)->OnRoleConflict(true); |
737 cricket::IceRole new_role = | 769 IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING |
738 GetEndpoint(channel)->ice_role() == cricket::ICEROLE_CONTROLLING ? | 770 ? ICEROLE_CONTROLLED |
739 cricket::ICEROLE_CONTROLLED : cricket::ICEROLE_CONTROLLING; | 771 : ICEROLE_CONTROLLING; |
740 channel->SetIceRole(new_role); | 772 channel->SetIceRole(new_role); |
741 } | 773 } |
742 | 774 |
743 int SendData(cricket::TransportChannel* channel, | 775 int SendData(TransportChannel* channel, const char* data, size_t len) { |
744 const char* data, size_t len) { | |
745 rtc::PacketOptions options; | 776 rtc::PacketOptions options; |
746 return channel->SendPacket(data, len, options, 0); | 777 return channel->SendPacket(data, len, options, 0); |
747 } | 778 } |
748 bool CheckDataOnChannel(cricket::TransportChannel* channel, | 779 bool CheckDataOnChannel(TransportChannel* channel, |
749 const char* data, int len) { | 780 const char* data, |
| 781 int len) { |
750 return GetChannelData(channel)->CheckData(data, len); | 782 return GetChannelData(channel)->CheckData(data, len); |
751 } | 783 } |
752 static const cricket::Candidate* LocalCandidate( | 784 static const Candidate* LocalCandidate(P2PTransportChannel* ch) { |
753 cricket::P2PTransportChannel* ch) { | |
754 return (ch && ch->best_connection()) ? | 785 return (ch && ch->best_connection()) ? |
755 &ch->best_connection()->local_candidate() : NULL; | 786 &ch->best_connection()->local_candidate() : NULL; |
756 } | 787 } |
757 static const cricket::Candidate* RemoteCandidate( | 788 static const Candidate* RemoteCandidate(P2PTransportChannel* ch) { |
758 cricket::P2PTransportChannel* ch) { | |
759 return (ch && ch->best_connection()) ? | 789 return (ch && ch->best_connection()) ? |
760 &ch->best_connection()->remote_candidate() : NULL; | 790 &ch->best_connection()->remote_candidate() : NULL; |
761 } | 791 } |
762 Endpoint* GetEndpoint(cricket::TransportChannel* ch) { | 792 Endpoint* GetEndpoint(TransportChannel* ch) { |
763 if (ep1_.HasChannel(ch)) { | 793 if (ep1_.HasChannel(ch)) { |
764 return &ep1_; | 794 return &ep1_; |
765 } else if (ep2_.HasChannel(ch)) { | 795 } else if (ep2_.HasChannel(ch)) { |
766 return &ep2_; | 796 return &ep2_; |
767 } else { | 797 } else { |
768 return NULL; | 798 return NULL; |
769 } | 799 } |
770 } | 800 } |
771 cricket::P2PTransportChannel* GetRemoteChannel( | 801 P2PTransportChannel* GetRemoteChannel(TransportChannel* ch) { |
772 cricket::TransportChannel* ch) { | |
773 if (ch == ep1_ch1()) | 802 if (ch == ep1_ch1()) |
774 return ep2_ch1(); | 803 return ep2_ch1(); |
775 else if (ch == ep1_ch2()) | 804 else if (ch == ep1_ch2()) |
776 return ep2_ch2(); | 805 return ep2_ch2(); |
777 else if (ch == ep2_ch1()) | 806 else if (ch == ep2_ch1()) |
778 return ep1_ch1(); | 807 return ep1_ch1(); |
779 else if (ch == ep2_ch2()) | 808 else if (ch == ep2_ch2()) |
780 return ep1_ch2(); | 809 return ep1_ch2(); |
781 else | 810 else |
782 return NULL; | 811 return NULL; |
783 } | 812 } |
784 std::list<std::string>& GetPacketList(cricket::TransportChannel* ch) { | 813 std::list<std::string>& GetPacketList(TransportChannel* ch) { |
785 return GetChannelData(ch)->ch_packets_; | 814 return GetChannelData(ch)->ch_packets_; |
786 } | 815 } |
787 | 816 |
788 enum RemoteIceCredentialSource { FROM_CANDIDATE, FROM_SETICECREDENTIALS }; | 817 enum RemoteIceCredentialSource { FROM_CANDIDATE, FROM_SETICECREDENTIALS }; |
789 | 818 |
790 // How does the test pass ICE credentials to the P2PTransportChannel? | 819 // How does the test pass ICE credentials to the P2PTransportChannel? |
791 // On the candidate itself, or through SetIceCredentials? | 820 // On the candidate itself, or through SetIceCredentials? |
792 // Goes through the candidate itself by default. | 821 // Goes through the candidate itself by default. |
793 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { | 822 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { |
794 remote_ice_credential_source_ = source; | 823 remote_ice_credential_source_ = source; |
795 } | 824 } |
796 | 825 |
797 void set_force_relay(bool relay) { | 826 void set_force_relay(bool relay) { |
798 force_relay_ = relay; | 827 force_relay_ = relay; |
799 } | 828 } |
800 | 829 |
801 private: | 830 private: |
802 rtc::Thread* main_; | 831 rtc::Thread* main_; |
803 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 832 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
804 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 833 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
805 std::unique_ptr<rtc::NATSocketServer> nss_; | 834 std::unique_ptr<rtc::NATSocketServer> nss_; |
806 std::unique_ptr<rtc::FirewallSocketServer> ss_; | 835 std::unique_ptr<rtc::FirewallSocketServer> ss_; |
807 rtc::SocketServerScope ss_scope_; | 836 rtc::SocketServerScope ss_scope_; |
808 std::unique_ptr<cricket::TestStunServer> stun_server_; | 837 std::unique_ptr<TestStunServer> stun_server_; |
809 cricket::TestTurnServer turn_server_; | 838 TestTurnServer turn_server_; |
810 cricket::TestRelayServer relay_server_; | 839 TestRelayServer relay_server_; |
811 rtc::SocksProxyServer socks_server1_; | 840 rtc::SocksProxyServer socks_server1_; |
812 rtc::SocksProxyServer socks_server2_; | 841 rtc::SocksProxyServer socks_server2_; |
813 Endpoint ep1_; | 842 Endpoint ep1_; |
814 Endpoint ep2_; | 843 Endpoint ep2_; |
815 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; | 844 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; |
816 bool force_relay_; | 845 bool force_relay_; |
817 }; | 846 }; |
818 | 847 |
819 // The tests have only a few outcomes, which we predefine. | 848 // The tests have only a few outcomes, which we predefine. |
820 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 849 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 // Just test every combination of the configs in the Config enum. | 887 // Just test every combination of the configs in the Config enum. |
859 class P2PTransportChannelTest : public P2PTransportChannelTestBase { | 888 class P2PTransportChannelTest : public P2PTransportChannelTestBase { |
860 protected: | 889 protected: |
861 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; | 890 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; |
862 void ConfigureEndpoints(Config config1, | 891 void ConfigureEndpoints(Config config1, |
863 Config config2, | 892 Config config2, |
864 int allocator_flags1, | 893 int allocator_flags1, |
865 int allocator_flags2) { | 894 int allocator_flags2) { |
866 ServerAddresses stun_servers; | 895 ServerAddresses stun_servers; |
867 stun_servers.insert(kStunAddr); | 896 stun_servers.insert(kStunAddr); |
868 GetEndpoint(0)->allocator_.reset( | 897 GetEndpoint(0)->allocator_.reset(new BasicPortAllocator( |
869 new cricket::BasicPortAllocator(&(GetEndpoint(0)->network_manager_), | 898 &(GetEndpoint(0)->network_manager_), stun_servers, rtc::SocketAddress(), |
870 stun_servers, | 899 rtc::SocketAddress(), rtc::SocketAddress())); |
871 rtc::SocketAddress(), rtc::SocketAddress(), | 900 GetEndpoint(1)->allocator_.reset(new BasicPortAllocator( |
872 rtc::SocketAddress())); | 901 &(GetEndpoint(1)->network_manager_), stun_servers, rtc::SocketAddress(), |
873 GetEndpoint(1)->allocator_.reset( | 902 rtc::SocketAddress(), rtc::SocketAddress())); |
874 new cricket::BasicPortAllocator(&(GetEndpoint(1)->network_manager_), | |
875 stun_servers, | |
876 rtc::SocketAddress(), rtc::SocketAddress(), | |
877 rtc::SocketAddress())); | |
878 | 903 |
879 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); | 904 RelayServerConfig turn_server(RELAY_TURN); |
880 turn_server.credentials = kRelayCredentials; | 905 turn_server.credentials = kRelayCredentials; |
881 turn_server.ports.push_back( | 906 turn_server.ports.push_back( |
882 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); | 907 ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false)); |
883 GetEndpoint(0)->allocator_->AddTurnServer(turn_server); | 908 GetEndpoint(0)->allocator_->AddTurnServer(turn_server); |
884 GetEndpoint(1)->allocator_->AddTurnServer(turn_server); | 909 GetEndpoint(1)->allocator_->AddTurnServer(turn_server); |
885 | 910 |
886 int delay = kMinimumStepDelay; | 911 int delay = kMinimumStepDelay; |
887 ConfigureEndpoint(0, config1); | 912 ConfigureEndpoint(0, config1); |
888 SetAllocatorFlags(0, allocator_flags1); | 913 SetAllocatorFlags(0, allocator_flags1); |
889 SetAllocationStepDelay(0, delay); | 914 SetAllocationStepDelay(0, delay); |
890 ConfigureEndpoint(1, config2); | 915 ConfigureEndpoint(1, config2); |
891 SetAllocatorFlags(1, allocator_flags2); | 916 SetAllocatorFlags(1, allocator_flags2); |
892 SetAllocationStepDelay(1, delay); | 917 SetAllocationStepDelay(1, delay); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 | 1108 |
1084 // Test the operation of GetStats. | 1109 // Test the operation of GetStats. |
1085 TEST_F(P2PTransportChannelTest, GetStats) { | 1110 TEST_F(P2PTransportChannelTest, GetStats) { |
1086 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1111 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1087 kDefaultPortAllocatorFlags); | 1112 kDefaultPortAllocatorFlags); |
1088 CreateChannels(1); | 1113 CreateChannels(1); |
1089 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1114 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1090 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1115 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1091 1000, 1000); | 1116 1000, 1000); |
1092 TestSendRecv(1); | 1117 TestSendRecv(1); |
1093 cricket::ConnectionInfos infos; | 1118 ConnectionInfos infos; |
1094 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); | 1119 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); |
1095 ASSERT_TRUE(infos.size() >= 1); | 1120 ASSERT_TRUE(infos.size() >= 1); |
1096 cricket::ConnectionInfo* best_conn_info = nullptr; | 1121 ConnectionInfo* best_conn_info = nullptr; |
1097 for (cricket::ConnectionInfo& info : infos) { | 1122 for (ConnectionInfo& info : infos) { |
1098 if (info.best_connection) { | 1123 if (info.best_connection) { |
1099 best_conn_info = &info; | 1124 best_conn_info = &info; |
1100 break; | 1125 break; |
1101 } | 1126 } |
1102 } | 1127 } |
1103 ASSERT_TRUE(best_conn_info != nullptr); | 1128 ASSERT_TRUE(best_conn_info != nullptr); |
1104 EXPECT_TRUE(best_conn_info->new_connection); | 1129 EXPECT_TRUE(best_conn_info->new_connection); |
1105 EXPECT_TRUE(best_conn_info->receiving); | 1130 EXPECT_TRUE(best_conn_info->receiving); |
1106 EXPECT_TRUE(best_conn_info->writable); | 1131 EXPECT_TRUE(best_conn_info->writable); |
1107 EXPECT_FALSE(best_conn_info->timeout); | 1132 EXPECT_FALSE(best_conn_info->timeout); |
(...skipping 15 matching lines...) Expand all Loading... |
1123 CreateChannels(1); | 1148 CreateChannels(1); |
1124 // Only have remote credentials come in for ep2, not ep1. | 1149 // Only have remote credentials come in for ep2, not ep1. |
1125 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1150 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
1126 | 1151 |
1127 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1152 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
1128 // candidate. | 1153 // candidate. |
1129 PauseCandidates(1); | 1154 PauseCandidates(1); |
1130 | 1155 |
1131 // The caller should have the best connection connected to the peer reflexive | 1156 // The caller should have the best connection connected to the peer reflexive |
1132 // candidate. | 1157 // candidate. |
1133 const cricket::Connection* best_connection = NULL; | 1158 const Connection* best_connection = NULL; |
1134 WAIT((best_connection = ep1_ch1()->best_connection()) != NULL, 2000); | 1159 WAIT((best_connection = ep1_ch1()->best_connection()) != NULL, 2000); |
1135 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1160 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); |
1136 | 1161 |
1137 // Because we don't have a remote pwd, we don't ping yet. | 1162 // Because we don't have a remote pwd, we don't ping yet. |
1138 EXPECT_EQ(kIceUfrag[1], | 1163 EXPECT_EQ(kIceUfrag[1], |
1139 ep1_ch1()->best_connection()->remote_candidate().username()); | 1164 ep1_ch1()->best_connection()->remote_candidate().username()); |
1140 EXPECT_EQ("", ep1_ch1()->best_connection()->remote_candidate().password()); | 1165 EXPECT_EQ("", ep1_ch1()->best_connection()->remote_candidate().password()); |
1141 // Because we don't have ICE credentials yet, we don't know the generation. | 1166 // Because we don't have ICE credentials yet, we don't know the generation. |
1142 EXPECT_EQ(0u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1167 EXPECT_EQ(0u, ep1_ch1()->best_connection()->remote_candidate().generation()); |
1143 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); | 1168 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1222 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
1198 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1223 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
1199 // After setting the remote ICE credentials, the password and generation | 1224 // After setting the remote ICE credentials, the password and generation |
1200 // of the peer reflexive candidate should be updated. | 1225 // of the peer reflexive candidate should be updated. |
1201 EXPECT_EQ(kIcePwd[1], | 1226 EXPECT_EQ(kIcePwd[1], |
1202 ep1_ch1()->best_connection()->remote_candidate().password()); | 1227 ep1_ch1()->best_connection()->remote_candidate().password()); |
1203 EXPECT_EQ(1u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1228 EXPECT_EQ(1u, ep1_ch1()->best_connection()->remote_candidate().generation()); |
1204 | 1229 |
1205 ResumeCandidates(1); | 1230 ResumeCandidates(1); |
1206 | 1231 |
1207 const cricket::Connection* best_connection = NULL; | 1232 const Connection* best_connection = NULL; |
1208 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 2000); | 1233 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 2000); |
1209 | 1234 |
1210 // Wait to verify the connection is not culled. | 1235 // Wait to verify the connection is not culled. |
1211 WAIT(ep1_ch1()->writable(), 2000); | 1236 WAIT(ep1_ch1()->writable(), 2000); |
1212 EXPECT_EQ(ep2_ch1()->best_connection(), best_connection); | 1237 EXPECT_EQ(ep2_ch1()->best_connection(), best_connection); |
1213 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1238 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); |
1214 DestroyChannels(); | 1239 DestroyChannels(); |
1215 } | 1240 } |
1216 | 1241 |
1217 // Test that we properly create a connection on a STUN ping from unknown address | 1242 // Test that we properly create a connection on a STUN ping from unknown address |
1218 // when the signaling is slow, even if the new candidate is created due to the | 1243 // when the signaling is slow, even if the new candidate is created due to the |
1219 // remote peer doing an ICE restart, pairing this candidate across generations. | 1244 // remote peer doing an ICE restart, pairing this candidate across generations. |
1220 // | 1245 // |
1221 // Previously this wasn't working due to a bug where the peer reflexive | 1246 // Previously this wasn't working due to a bug where the peer reflexive |
1222 // candidate was only updated for the newest generation candidate pairs, and | 1247 // candidate was only updated for the newest generation candidate pairs, and |
1223 // not older-generation candidate pairs created by pairing candidates across | 1248 // not older-generation candidate pairs created by pairing candidates across |
1224 // generations. This resulted in the old-generation prflx candidate being | 1249 // generations. This resulted in the old-generation prflx candidate being |
1225 // prioritized above new-generation candidate pairs. | 1250 // prioritized above new-generation candidate pairs. |
1226 TEST_F(P2PTransportChannelTest, | 1251 TEST_F(P2PTransportChannelTest, |
1227 PeerReflexiveCandidateBeforeSignalingWithIceRestart) { | 1252 PeerReflexiveCandidateBeforeSignalingWithIceRestart) { |
1228 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1253 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1229 kDefaultPortAllocatorFlags); | 1254 kDefaultPortAllocatorFlags); |
1230 // Only gather relay candidates, so that when the prflx candidate arrives | 1255 // Only gather relay candidates, so that when the prflx candidate arrives |
1231 // it's prioritized above the current candidate pair. | 1256 // it's prioritized above the current candidate pair. |
1232 GetEndpoint(0)->allocator_->set_candidate_filter(cricket::CF_RELAY); | 1257 GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY); |
1233 GetEndpoint(1)->allocator_->set_candidate_filter(cricket::CF_RELAY); | 1258 GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY); |
1234 // Setting this allows us to control when SetRemoteIceCredentials is called. | 1259 // Setting this allows us to control when SetRemoteIceCredentials is called. |
1235 set_remote_ice_credential_source(FROM_CANDIDATE); | 1260 set_remote_ice_credential_source(FROM_CANDIDATE); |
1236 CreateChannels(1); | 1261 CreateChannels(1); |
1237 // Wait for the initial connection to be made. | 1262 // Wait for the initial connection to be made. |
1238 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1263 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
1239 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1264 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
1240 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1265 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1241 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1266 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1242 kDefaultTimeout); | 1267 kDefaultTimeout); |
1243 | 1268 |
1244 // Simulate an ICE restart on ep2, but don't signal the candidate or new | 1269 // Simulate an ICE restart on ep2, but don't signal the candidate or new |
1245 // ICE credentials until after a prflx connection has been made. | 1270 // ICE credentials until after a prflx connection has been made. |
1246 PauseCandidates(1); | 1271 PauseCandidates(1); |
1247 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1272 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); |
1248 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1273 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
1249 ep2_ch1()->MaybeStartGathering(); | 1274 ep2_ch1()->MaybeStartGathering(); |
1250 | 1275 |
1251 // The caller should have the best connection connected to the peer reflexive | 1276 // The caller should have the best connection connected to the peer reflexive |
1252 // candidate. | 1277 // candidate. |
1253 EXPECT_EQ_WAIT("prflx", | 1278 EXPECT_EQ_WAIT("prflx", |
1254 ep1_ch1()->best_connection()->remote_candidate().type(), | 1279 ep1_ch1()->best_connection()->remote_candidate().type(), |
1255 kDefaultTimeout); | 1280 kDefaultTimeout); |
1256 const cricket::Connection* prflx_best_connection = | 1281 const Connection* prflx_best_connection = ep1_ch1()->best_connection(); |
1257 ep1_ch1()->best_connection(); | |
1258 | 1282 |
1259 // Now simulate the ICE restart on ep1. | 1283 // Now simulate the ICE restart on ep1. |
1260 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); | 1284 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); |
1261 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 1285 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
1262 ep1_ch1()->MaybeStartGathering(); | 1286 ep1_ch1()->MaybeStartGathering(); |
1263 | 1287 |
1264 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses | 1288 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses |
1265 // their information to update the peer reflexive candidate. | 1289 // their information to update the peer reflexive candidate. |
1266 ResumeCandidates(1); | 1290 ResumeCandidates(1); |
1267 | 1291 |
1268 EXPECT_EQ_WAIT("relay", | 1292 EXPECT_EQ_WAIT("relay", |
1269 ep1_ch1()->best_connection()->remote_candidate().type(), | 1293 ep1_ch1()->best_connection()->remote_candidate().type(), |
1270 kDefaultTimeout); | 1294 kDefaultTimeout); |
1271 EXPECT_EQ(prflx_best_connection, ep1_ch1()->best_connection()); | 1295 EXPECT_EQ(prflx_best_connection, ep1_ch1()->best_connection()); |
1272 DestroyChannels(); | 1296 DestroyChannels(); |
1273 } | 1297 } |
1274 | 1298 |
1275 // Test that if remote candidates don't have ufrag and pwd, we still work. | 1299 // Test that if remote candidates don't have ufrag and pwd, we still work. |
1276 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { | 1300 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { |
1277 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); | 1301 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); |
1278 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1302 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1279 kDefaultPortAllocatorFlags); | 1303 kDefaultPortAllocatorFlags); |
1280 CreateChannels(1); | 1304 CreateChannels(1); |
1281 const cricket::Connection* best_connection = NULL; | 1305 const Connection* best_connection = NULL; |
1282 // Wait until the callee's connections are created. | 1306 // Wait until the callee's connections are created. |
1283 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000); | 1307 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000); |
1284 // Wait to see if they get culled; they shouldn't. | 1308 // Wait to see if they get culled; they shouldn't. |
1285 WAIT(ep2_ch1()->best_connection() != best_connection, 1000); | 1309 WAIT(ep2_ch1()->best_connection() != best_connection, 1000); |
1286 EXPECT_TRUE(ep2_ch1()->best_connection() == best_connection); | 1310 EXPECT_TRUE(ep2_ch1()->best_connection() == best_connection); |
1287 DestroyChannels(); | 1311 DestroyChannels(); |
1288 } | 1312 } |
1289 | 1313 |
1290 // Test that a host behind NAT cannot be reached when incoming_only | 1314 // Test that a host behind NAT cannot be reached when incoming_only |
1291 // is set to true. | 1315 // is set to true. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 DestroyChannels(); | 1350 DestroyChannels(); |
1327 } | 1351 } |
1328 | 1352 |
1329 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { | 1353 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { |
1330 AddAddress(0, kPublicAddrs[0]); | 1354 AddAddress(0, kPublicAddrs[0]); |
1331 AddAddress(1, kPublicAddrs[1]); | 1355 AddAddress(1, kPublicAddrs[1]); |
1332 | 1356 |
1333 SetAllocationStepDelay(0, kMinimumStepDelay); | 1357 SetAllocationStepDelay(0, kMinimumStepDelay); |
1334 SetAllocationStepDelay(1, kMinimumStepDelay); | 1358 SetAllocationStepDelay(1, kMinimumStepDelay); |
1335 | 1359 |
1336 int kOnlyLocalTcpPorts = cricket::PORTALLOCATOR_DISABLE_UDP | | 1360 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP | |
1337 cricket::PORTALLOCATOR_DISABLE_STUN | | 1361 PORTALLOCATOR_DISABLE_STUN | |
1338 cricket::PORTALLOCATOR_DISABLE_RELAY; | 1362 PORTALLOCATOR_DISABLE_RELAY; |
1339 // Disable all protocols except TCP. | 1363 // Disable all protocols except TCP. |
1340 SetAllocatorFlags(0, kOnlyLocalTcpPorts); | 1364 SetAllocatorFlags(0, kOnlyLocalTcpPorts); |
1341 SetAllocatorFlags(1, kOnlyLocalTcpPorts); | 1365 SetAllocatorFlags(1, kOnlyLocalTcpPorts); |
1342 | 1366 |
1343 SetAllowTcpListen(0, true); // actpass. | 1367 SetAllowTcpListen(0, true); // actpass. |
1344 SetAllowTcpListen(1, false); // active. | 1368 SetAllowTcpListen(1, false); // active. |
1345 | 1369 |
1346 // We want SetRemoteIceCredentials to be called as it normally would. | 1370 // We want SetRemoteIceCredentials to be called as it normally would. |
1347 // Otherwise we won't know what credentials to use for the expected | 1371 // Otherwise we won't know what credentials to use for the expected |
1348 // prflx TCP candidates. | 1372 // prflx TCP candidates. |
1349 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); | 1373 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); |
1350 | 1374 |
1351 // Pause candidate so we could verify the candidate properties. | 1375 // Pause candidate so we could verify the candidate properties. |
1352 PauseCandidates(0); | 1376 PauseCandidates(0); |
1353 PauseCandidates(1); | 1377 PauseCandidates(1); |
1354 CreateChannels(1); | 1378 CreateChannels(1); |
1355 | 1379 |
1356 // Verify tcp candidates. | 1380 // Verify tcp candidates. |
1357 VerifySavedTcpCandidates(0, cricket::TCPTYPE_PASSIVE_STR); | 1381 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR); |
1358 VerifySavedTcpCandidates(1, cricket::TCPTYPE_ACTIVE_STR); | 1382 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR); |
1359 | 1383 |
1360 // Resume candidates. | 1384 // Resume candidates. |
1361 ResumeCandidates(0); | 1385 ResumeCandidates(0); |
1362 ResumeCandidates(1); | 1386 ResumeCandidates(1); |
1363 | 1387 |
1364 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1388 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1365 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1389 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1366 1000); | 1390 1000); |
1367 EXPECT_TRUE( | 1391 EXPECT_TRUE( |
1368 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1392 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1369 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1393 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1370 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1394 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1371 | 1395 |
1372 TestSendRecv(1); | 1396 TestSendRecv(1); |
1373 DestroyChannels(); | 1397 DestroyChannels(); |
1374 } | 1398 } |
1375 | 1399 |
1376 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { | 1400 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { |
1377 AddAddress(0, kPublicAddrs[0]); | 1401 AddAddress(0, kPublicAddrs[0]); |
1378 AddAddress(1, kPublicAddrs[1]); | 1402 AddAddress(1, kPublicAddrs[1]); |
1379 TestSignalRoleConflict(); | 1403 TestSignalRoleConflict(); |
1380 } | 1404 } |
1381 | 1405 |
1382 // Tests that the ice configs (protocol, tiebreaker and role) can be passed | 1406 // Tests that the ice configs (protocol, tiebreaker and role) can be passed |
1383 // down to ports. | 1407 // down to ports. |
1384 // Disable on Windows because it is flaky. | 1408 // Disable on Windows because it is flaky. |
1385 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6019 | 1409 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6019 |
1386 #if defined(WEBRTC_WIN) | 1410 #if defined(WEBRTC_WIN) |
1387 #define MAYBE_TestIceConfigWillPassDownToPort DISABLED_TestIceConfigWillPassDown
ToPort | 1411 #define MAYBE_TestIceConfigWillPassDownToPort \ |
| 1412 DISABLED_TestIceConfigWillPassDownToPort |
1388 #else | 1413 #else |
1389 #define MAYBE_TestIceConfigWillPassDownToPort TestIceConfigWillPassDownToPort | 1414 #define MAYBE_TestIceConfigWillPassDownToPort TestIceConfigWillPassDownToPort |
1390 #endif | 1415 #endif |
1391 TEST_F(P2PTransportChannelTest, MAYBE_TestIceConfigWillPassDownToPort) { | 1416 TEST_F(P2PTransportChannelTest, MAYBE_TestIceConfigWillPassDownToPort) { |
1392 AddAddress(0, kPublicAddrs[0]); | 1417 AddAddress(0, kPublicAddrs[0]); |
1393 AddAddress(1, kPublicAddrs[1]); | 1418 AddAddress(1, kPublicAddrs[1]); |
1394 | 1419 |
1395 SetIceRole(0, cricket::ICEROLE_CONTROLLING); | 1420 SetIceRole(0, ICEROLE_CONTROLLING); |
1396 SetIceTiebreaker(0, kTiebreaker1); | 1421 SetIceTiebreaker(0, kTiebreaker1); |
1397 SetIceRole(1, cricket::ICEROLE_CONTROLLING); | 1422 SetIceRole(1, ICEROLE_CONTROLLING); |
1398 SetIceTiebreaker(1, kTiebreaker2); | 1423 SetIceTiebreaker(1, kTiebreaker2); |
1399 | 1424 |
1400 CreateChannels(1); | 1425 CreateChannels(1); |
1401 | 1426 |
1402 EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000); | 1427 EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000); |
1403 | 1428 |
1404 const std::vector<cricket::PortInterface *> ports_before = ep1_ch1()->ports(); | 1429 const std::vector<PortInterface*> ports_before = ep1_ch1()->ports(); |
1405 for (size_t i = 0; i < ports_before.size(); ++i) { | 1430 for (size_t i = 0; i < ports_before.size(); ++i) { |
1406 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); | 1431 EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); |
1407 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); | 1432 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); |
1408 } | 1433 } |
1409 | 1434 |
1410 ep1_ch1()->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1435 ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED); |
1411 ep1_ch1()->SetIceTiebreaker(kTiebreaker2); | 1436 ep1_ch1()->SetIceTiebreaker(kTiebreaker2); |
1412 | 1437 |
1413 const std::vector<cricket::PortInterface *> ports_after = ep1_ch1()->ports(); | 1438 const std::vector<PortInterface*> ports_after = ep1_ch1()->ports(); |
1414 for (size_t i = 0; i < ports_after.size(); ++i) { | 1439 for (size_t i = 0; i < ports_after.size(); ++i) { |
1415 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); | 1440 EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); |
1416 // SetIceTiebreaker after Connect() has been called will fail. So expect the | 1441 // SetIceTiebreaker after Connect() has been called will fail. So expect the |
1417 // original value. | 1442 // original value. |
1418 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); | 1443 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); |
1419 } | 1444 } |
1420 | 1445 |
1421 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && | 1446 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
1422 ep1_ch1()->writable() && | 1447 ep1_ch1()->writable() && |
1423 ep2_ch1()->receiving() && | 1448 ep2_ch1()->receiving() && |
1424 ep2_ch1()->writable(), | 1449 ep2_ch1()->writable(), |
1425 1000); | 1450 1000); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 TEST_F(P2PTransportChannelTest, TestIPv6Connections) { | 1488 TEST_F(P2PTransportChannelTest, TestIPv6Connections) { |
1464 AddAddress(0, kIPv6PublicAddrs[0]); | 1489 AddAddress(0, kIPv6PublicAddrs[0]); |
1465 AddAddress(0, kPublicAddrs[0]); | 1490 AddAddress(0, kPublicAddrs[0]); |
1466 AddAddress(1, kIPv6PublicAddrs[1]); | 1491 AddAddress(1, kIPv6PublicAddrs[1]); |
1467 AddAddress(1, kPublicAddrs[1]); | 1492 AddAddress(1, kPublicAddrs[1]); |
1468 | 1493 |
1469 SetAllocationStepDelay(0, kMinimumStepDelay); | 1494 SetAllocationStepDelay(0, kMinimumStepDelay); |
1470 SetAllocationStepDelay(1, kMinimumStepDelay); | 1495 SetAllocationStepDelay(1, kMinimumStepDelay); |
1471 | 1496 |
1472 // Enable IPv6 | 1497 // Enable IPv6 |
1473 SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6); | 1498 SetAllocatorFlags(0, PORTALLOCATOR_ENABLE_IPV6); |
1474 SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6); | 1499 SetAllocatorFlags(1, PORTALLOCATOR_ENABLE_IPV6); |
1475 | 1500 |
1476 CreateChannels(1); | 1501 CreateChannels(1); |
1477 | 1502 |
1478 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1503 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1479 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1504 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1480 1000); | 1505 1000); |
1481 EXPECT_TRUE( | 1506 EXPECT_TRUE( |
1482 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1507 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1483 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && | 1508 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && |
1484 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); | 1509 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); |
1485 | 1510 |
1486 TestSendRecv(1); | 1511 TestSendRecv(1); |
1487 DestroyChannels(); | 1512 DestroyChannels(); |
1488 } | 1513 } |
1489 | 1514 |
1490 // Testing forceful TURN connections. | 1515 // Testing forceful TURN connections. |
1491 TEST_F(P2PTransportChannelTest, TestForceTurn) { | 1516 TEST_F(P2PTransportChannelTest, TestForceTurn) { |
1492 ConfigureEndpoints( | 1517 ConfigureEndpoints( |
1493 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, | 1518 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, |
1494 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, | 1519 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET, |
1495 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1520 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1496 set_force_relay(true); | 1521 set_force_relay(true); |
1497 | 1522 |
1498 SetAllocationStepDelay(0, kMinimumStepDelay); | 1523 SetAllocationStepDelay(0, kMinimumStepDelay); |
1499 SetAllocationStepDelay(1, kMinimumStepDelay); | 1524 SetAllocationStepDelay(1, kMinimumStepDelay); |
1500 | 1525 |
1501 CreateChannels(1); | 1526 CreateChannels(1); |
1502 | 1527 |
1503 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1528 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1504 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1529 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1505 2000); | 1530 2000); |
(...skipping 11 matching lines...) Expand all Loading... |
1517 } | 1542 } |
1518 | 1543 |
1519 // Test that if continual gathering is set to true, ICE gathering state will | 1544 // Test that if continual gathering is set to true, ICE gathering state will |
1520 // not change to "Complete", and vice versa. | 1545 // not change to "Complete", and vice versa. |
1521 TEST_F(P2PTransportChannelTest, TestContinualGathering) { | 1546 TEST_F(P2PTransportChannelTest, TestContinualGathering) { |
1522 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1547 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1523 kDefaultPortAllocatorFlags); | 1548 kDefaultPortAllocatorFlags); |
1524 SetAllocationStepDelay(0, kDefaultStepDelay); | 1549 SetAllocationStepDelay(0, kDefaultStepDelay); |
1525 SetAllocationStepDelay(1, kDefaultStepDelay); | 1550 SetAllocationStepDelay(1, kDefaultStepDelay); |
1526 CreateChannels(1); | 1551 CreateChannels(1); |
1527 cricket::IceConfig config = CreateIceConfig(1000, true); | 1552 IceConfig config = CreateIceConfig(1000, true); |
1528 ep1_ch1()->SetIceConfig(config); | 1553 ep1_ch1()->SetIceConfig(config); |
1529 // By default, ep2 does not gather continually. | 1554 // By default, ep2 does not gather continually. |
1530 | 1555 |
1531 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && | 1556 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && |
1532 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1557 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1533 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1558 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1534 1000, 1000); | 1559 1000, 1000); |
1535 WAIT(cricket::IceGatheringState::kIceGatheringComplete == | 1560 WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(), |
1536 ep1_ch1()->gathering_state(), | |
1537 1000); | 1561 1000); |
1538 EXPECT_EQ(cricket::IceGatheringState::kIceGatheringGathering, | 1562 EXPECT_EQ(IceGatheringState::kIceGatheringGathering, |
1539 ep1_ch1()->gathering_state()); | 1563 ep1_ch1()->gathering_state()); |
1540 // By now, ep2 should have completed gathering. | 1564 // By now, ep2 should have completed gathering. |
1541 EXPECT_EQ(cricket::IceGatheringState::kIceGatheringComplete, | 1565 EXPECT_EQ(IceGatheringState::kIceGatheringComplete, |
1542 ep2_ch1()->gathering_state()); | 1566 ep2_ch1()->gathering_state()); |
1543 | 1567 |
1544 DestroyChannels(); | 1568 DestroyChannels(); |
1545 } | 1569 } |
1546 | 1570 |
1547 // Test that a connection succeeds when the P2PTransportChannel uses a pooled | 1571 // Test that a connection succeeds when the P2PTransportChannel uses a pooled |
1548 // PortAllocatorSession that has not yet finished gathering candidates. | 1572 // PortAllocatorSession that has not yet finished gathering candidates. |
1549 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) { | 1573 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) { |
1550 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1574 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1551 kDefaultPortAllocatorFlags); | 1575 kDefaultPortAllocatorFlags); |
1552 // First create a pooled session for each endpoint. | 1576 // First create a pooled session for each endpoint. |
1553 auto& allocator_1 = GetEndpoint(0)->allocator_; | 1577 auto& allocator_1 = GetEndpoint(0)->allocator_; |
1554 auto& allocator_2 = GetEndpoint(1)->allocator_; | 1578 auto& allocator_2 = GetEndpoint(1)->allocator_; |
1555 int pool_size = 1; | 1579 int pool_size = 1; |
1556 allocator_1->SetConfiguration(allocator_1->stun_servers(), | 1580 allocator_1->SetConfiguration(allocator_1->stun_servers(), |
1557 allocator_1->turn_servers(), pool_size); | 1581 allocator_1->turn_servers(), pool_size); |
1558 allocator_2->SetConfiguration(allocator_2->stun_servers(), | 1582 allocator_2->SetConfiguration(allocator_2->stun_servers(), |
1559 allocator_2->turn_servers(), pool_size); | 1583 allocator_2->turn_servers(), pool_size); |
1560 const cricket::PortAllocatorSession* pooled_session_1 = | 1584 const PortAllocatorSession* pooled_session_1 = |
1561 allocator_1->GetPooledSession(); | 1585 allocator_1->GetPooledSession(); |
1562 const cricket::PortAllocatorSession* pooled_session_2 = | 1586 const PortAllocatorSession* pooled_session_2 = |
1563 allocator_2->GetPooledSession(); | 1587 allocator_2->GetPooledSession(); |
1564 ASSERT_NE(nullptr, pooled_session_1); | 1588 ASSERT_NE(nullptr, pooled_session_1); |
1565 ASSERT_NE(nullptr, pooled_session_2); | 1589 ASSERT_NE(nullptr, pooled_session_2); |
1566 // Sanity check that pooled sessions haven't gathered anything yet. | 1590 // Sanity check that pooled sessions haven't gathered anything yet. |
1567 EXPECT_TRUE(pooled_session_1->ReadyPorts().empty()); | 1591 EXPECT_TRUE(pooled_session_1->ReadyPorts().empty()); |
1568 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty()); | 1592 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty()); |
1569 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty()); | 1593 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty()); |
1570 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty()); | 1594 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty()); |
1571 // Now let the endpoints connect and try exchanging some data. | 1595 // Now let the endpoints connect and try exchanging some data. |
1572 CreateChannels(1); | 1596 CreateChannels(1); |
(...skipping 20 matching lines...) Expand all Loading... |
1593 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1617 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1594 kDefaultPortAllocatorFlags); | 1618 kDefaultPortAllocatorFlags); |
1595 // First create a pooled session for each endpoint. | 1619 // First create a pooled session for each endpoint. |
1596 auto& allocator_1 = GetEndpoint(0)->allocator_; | 1620 auto& allocator_1 = GetEndpoint(0)->allocator_; |
1597 auto& allocator_2 = GetEndpoint(1)->allocator_; | 1621 auto& allocator_2 = GetEndpoint(1)->allocator_; |
1598 int pool_size = 1; | 1622 int pool_size = 1; |
1599 allocator_1->SetConfiguration(allocator_1->stun_servers(), | 1623 allocator_1->SetConfiguration(allocator_1->stun_servers(), |
1600 allocator_1->turn_servers(), pool_size); | 1624 allocator_1->turn_servers(), pool_size); |
1601 allocator_2->SetConfiguration(allocator_2->stun_servers(), | 1625 allocator_2->SetConfiguration(allocator_2->stun_servers(), |
1602 allocator_2->turn_servers(), pool_size); | 1626 allocator_2->turn_servers(), pool_size); |
1603 const cricket::PortAllocatorSession* pooled_session_1 = | 1627 const PortAllocatorSession* pooled_session_1 = |
1604 allocator_1->GetPooledSession(); | 1628 allocator_1->GetPooledSession(); |
1605 const cricket::PortAllocatorSession* pooled_session_2 = | 1629 const PortAllocatorSession* pooled_session_2 = |
1606 allocator_2->GetPooledSession(); | 1630 allocator_2->GetPooledSession(); |
1607 ASSERT_NE(nullptr, pooled_session_1); | 1631 ASSERT_NE(nullptr, pooled_session_1); |
1608 ASSERT_NE(nullptr, pooled_session_2); | 1632 ASSERT_NE(nullptr, pooled_session_2); |
1609 // Wait for the pooled sessions to finish gathering before the | 1633 // Wait for the pooled sessions to finish gathering before the |
1610 // P2PTransportChannels try to use them. | 1634 // P2PTransportChannels try to use them. |
1611 EXPECT_TRUE_WAIT(pooled_session_1->CandidatesAllocationDone() && | 1635 EXPECT_TRUE_WAIT(pooled_session_1->CandidatesAllocationDone() && |
1612 pooled_session_2->CandidatesAllocationDone(), | 1636 pooled_session_2->CandidatesAllocationDone(), |
1613 kDefaultTimeout); | 1637 kDefaultTimeout); |
1614 // Now let the endpoints connect and try exchanging some data. | 1638 // Now let the endpoints connect and try exchanging some data. |
1615 CreateChannels(1); | 1639 CreateChannels(1); |
1616 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && | 1640 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && |
1617 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1641 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1618 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1642 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1619 1000, 1000); | 1643 1000, 1000); |
1620 TestSendRecv(1); | 1644 TestSendRecv(1); |
1621 // Make sure the P2PTransportChannels are actually using ports from the | 1645 // Make sure the P2PTransportChannels are actually using ports from the |
1622 // pooled sessions. | 1646 // pooled sessions. |
1623 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); | 1647 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); |
1624 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); | 1648 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); |
1625 EXPECT_NE(pooled_ports_1.end(), | 1649 EXPECT_NE(pooled_ports_1.end(), |
1626 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), | 1650 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), |
1627 ep1_ch1()->best_connection()->port())); | 1651 ep1_ch1()->best_connection()->port())); |
1628 EXPECT_NE(pooled_ports_2.end(), | 1652 EXPECT_NE(pooled_ports_2.end(), |
1629 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), | 1653 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), |
1630 ep2_ch1()->best_connection()->port())); | 1654 ep2_ch1()->best_connection()->port())); |
1631 } | 1655 } |
1632 | 1656 |
| 1657 // Test that when the "presume_writable_when_fully_relayed" flag is set to |
| 1658 // false and there's a TURN-TURN candidate pair, it's presume to be writable |
| 1659 // as soon as it's created. |
| 1660 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { |
| 1661 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1662 kDefaultPortAllocatorFlags); |
| 1663 // Only configure one channel so we can control when the remote candidate |
| 1664 // is added. |
| 1665 GetEndpoint(0)->cd1_.ch_.reset( |
| 1666 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], |
| 1667 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); |
| 1668 IceConfig config; |
| 1669 config.presume_writable_when_fully_relayed = true; |
| 1670 ep1_ch1()->SetIceConfig(config); |
| 1671 ep1_ch1()->MaybeStartGathering(); |
| 1672 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, |
| 1673 ep1_ch1()->gathering_state(), kDefaultTimeout); |
| 1674 // Add two remote candidates; a host candidate (with higher priority) |
| 1675 // and TURN candidate. |
| 1676 ep1_ch1()->AddRemoteCandidate( |
| 1677 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
| 1678 ep1_ch1()->AddRemoteCandidate( |
| 1679 CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0)); |
| 1680 // Expect that the TURN-TURN candidate pair will be prioritized since it's |
| 1681 // "probably writable". |
| 1682 EXPECT_TRUE(ep1_ch1()->best_connection() != nullptr); |
| 1683 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); |
| 1684 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); |
| 1685 // Also expect that the channel instantly indicates that it's writable since |
| 1686 // it has a TURN-TURN pair. |
| 1687 EXPECT_TRUE(ep1_ch1()->writable()); |
| 1688 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); |
| 1689 } |
| 1690 |
| 1691 // Test that a presumed-writable TURN<->TURN connection is preferred above an |
| 1692 // unreliable connection (one that has failed to be pinged for some time). |
| 1693 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { |
| 1694 rtc::ScopedFakeClock fake_clock; |
| 1695 |
| 1696 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
| 1697 kDefaultPortAllocatorFlags); |
| 1698 IceConfig config; |
| 1699 config.presume_writable_when_fully_relayed = true; |
| 1700 GetEndpoint(0)->cd1_.ch_.reset( |
| 1701 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], |
| 1702 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); |
| 1703 GetEndpoint(1)->cd1_.ch_.reset( |
| 1704 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1], |
| 1705 kIcePwd[1], kIceUfrag[0], kIcePwd[0])); |
| 1706 ep1_ch1()->SetIceConfig(config); |
| 1707 ep2_ch1()->SetIceConfig(config); |
| 1708 ep1_ch1()->MaybeStartGathering(); |
| 1709 ep2_ch1()->MaybeStartGathering(); |
| 1710 // Wait for initial connection as usual. |
| 1711 EXPECT_TRUE_SIMULATED_WAIT( |
| 1712 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1713 ep1_ch1()->best_connection()->writable() && ep2_ch1()->receiving() && |
| 1714 ep2_ch1()->writable() && ep2_ch1()->best_connection()->writable(), |
| 1715 1000, fake_clock); |
| 1716 const Connection* old_best_connection = ep1_ch1()->best_connection(); |
| 1717 // Destroy the second channel and wait for the current connection on the |
| 1718 // first channel to become "unreliable", making it no longer writable. |
| 1719 GetEndpoint(1)->cd1_.ch_.reset(); |
| 1720 EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable(), 10000, fake_clock); |
| 1721 EXPECT_NE(nullptr, ep1_ch1()->best_connection()); |
| 1722 // Add a remote TURN candidate. The first channel should still have a TURN |
| 1723 // port available to make a TURN<->TURN pair that's presumed writable. |
| 1724 ep1_ch1()->AddRemoteCandidate( |
| 1725 CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0)); |
| 1726 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); |
| 1727 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); |
| 1728 EXPECT_TRUE(ep1_ch1()->writable()); |
| 1729 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); |
| 1730 EXPECT_NE(old_best_connection, ep1_ch1()->best_connection()); |
| 1731 // Explitly destroy channels, before fake clock is destroyed. |
| 1732 DestroyChannels(); |
| 1733 } |
| 1734 |
1633 // Test what happens when we have 2 users behind the same NAT. This can lead | 1735 // Test what happens when we have 2 users behind the same NAT. This can lead |
1634 // to interesting behavior because the STUN server will only give out the | 1736 // to interesting behavior because the STUN server will only give out the |
1635 // address of the outermost NAT. | 1737 // address of the outermost NAT. |
1636 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { | 1738 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { |
1637 protected: | 1739 protected: |
1638 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { | 1740 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { |
1639 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); | 1741 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); |
1640 rtc::NATSocketServer::Translator* outer_nat = | 1742 rtc::NATSocketServer::Translator* outer_nat = |
1641 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], | 1743 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], |
1642 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); | 1744 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 | 1800 |
1699 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1801 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1700 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1802 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1701 1000, 1000); | 1803 1000, 1000); |
1702 EXPECT_TRUE( | 1804 EXPECT_TRUE( |
1703 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1805 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1704 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1806 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1705 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1807 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1706 | 1808 |
1707 // Make the receiving timeout shorter for testing. | 1809 // Make the receiving timeout shorter for testing. |
1708 cricket::IceConfig config = CreateIceConfig(1000, false); | 1810 IceConfig config = CreateIceConfig(1000, false); |
1709 ep1_ch1()->SetIceConfig(config); | 1811 ep1_ch1()->SetIceConfig(config); |
1710 ep2_ch1()->SetIceConfig(config); | 1812 ep2_ch1()->SetIceConfig(config); |
1711 | 1813 |
1712 // Blackhole any traffic to or from the public addrs. | 1814 // Blackhole any traffic to or from the public addrs. |
1713 LOG(LS_INFO) << "Failing over..."; | 1815 LOG(LS_INFO) << "Failing over..."; |
1714 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); | 1816 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); |
1715 // The best connections will switch, so keep references to them. | 1817 // The best connections will switch, so keep references to them. |
1716 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); | 1818 const Connection* best_connection1 = ep1_ch1()->best_connection(); |
1717 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); | 1819 const Connection* best_connection2 = ep2_ch1()->best_connection(); |
1718 // We should detect loss of receiving within 1 second or so. | 1820 // We should detect loss of receiving within 1 second or so. |
1719 EXPECT_TRUE_WAIT( | 1821 EXPECT_TRUE_WAIT( |
1720 !best_connection1->receiving() && !best_connection2->receiving(), 3000); | 1822 !best_connection1->receiving() && !best_connection2->receiving(), 3000); |
1721 | 1823 |
1722 // We should switch over to use the alternate addr immediately on both sides | 1824 // We should switch over to use the alternate addr immediately on both sides |
1723 // when we are not receiving. | 1825 // when we are not receiving. |
1724 EXPECT_TRUE_WAIT( | 1826 EXPECT_TRUE_WAIT( |
1725 ep1_ch1()->best_connection()->receiving() && | 1827 ep1_ch1()->best_connection()->receiving() && |
1726 ep2_ch1()->best_connection()->receiving(), 1000); | 1828 ep2_ch1()->best_connection()->receiving(), 1000); |
1727 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); | 1829 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); |
(...skipping 22 matching lines...) Expand all Loading... |
1750 CreateChannels(1); | 1852 CreateChannels(1); |
1751 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1853 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1752 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1854 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1753 1000, 1000); | 1855 1000, 1000); |
1754 EXPECT_TRUE( | 1856 EXPECT_TRUE( |
1755 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1857 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1756 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1858 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1757 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1859 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1758 | 1860 |
1759 // Make the receiving timeout shorter for testing. | 1861 // Make the receiving timeout shorter for testing. |
1760 cricket::IceConfig config = CreateIceConfig(1000, false); | 1862 IceConfig config = CreateIceConfig(1000, false); |
1761 ep1_ch1()->SetIceConfig(config); | 1863 ep1_ch1()->SetIceConfig(config); |
1762 ep2_ch1()->SetIceConfig(config); | 1864 ep2_ch1()->SetIceConfig(config); |
1763 | 1865 |
1764 // Blackhole any traffic to or from the public addrs. | 1866 // Blackhole any traffic to or from the public addrs. |
1765 LOG(LS_INFO) << "Failing over..."; | 1867 LOG(LS_INFO) << "Failing over..."; |
1766 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); | 1868 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
1767 // The best connections will switch, so keep references to them. | 1869 // The best connections will switch, so keep references to them. |
1768 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); | 1870 const Connection* best_connection1 = ep1_ch1()->best_connection(); |
1769 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); | 1871 const Connection* best_connection2 = ep2_ch1()->best_connection(); |
1770 // We should detect loss of receiving within 1 second or so. | 1872 // We should detect loss of receiving within 1 second or so. |
1771 EXPECT_TRUE_WAIT( | 1873 EXPECT_TRUE_WAIT( |
1772 !best_connection1->receiving() && !best_connection2->receiving(), 3000); | 1874 !best_connection1->receiving() && !best_connection2->receiving(), 3000); |
1773 | 1875 |
1774 // We should switch over to use the alternate addr immediately on both sides | 1876 // We should switch over to use the alternate addr immediately on both sides |
1775 // when we are not receiving. | 1877 // when we are not receiving. |
1776 EXPECT_TRUE_WAIT( | 1878 EXPECT_TRUE_WAIT( |
1777 ep1_ch1()->best_connection()->receiving() && | 1879 ep1_ch1()->best_connection()->receiving() && |
1778 ep2_ch1()->best_connection()->receiving(), 1000); | 1880 ep2_ch1()->best_connection()->receiving(), 1000); |
1779 EXPECT_TRUE( | 1881 EXPECT_TRUE( |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 | 1964 |
1863 // Create channels and let them go writable, as usual. | 1965 // Create channels and let them go writable, as usual. |
1864 CreateChannels(1); | 1966 CreateChannels(1); |
1865 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1967 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1866 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1968 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1867 1000, 1000); | 1969 1000, 1000); |
1868 int backup_ping_interval = 2000; | 1970 int backup_ping_interval = 2000; |
1869 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval)); | 1971 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval)); |
1870 // After the state becomes COMPLETED, the backup connection will be pinged | 1972 // After the state becomes COMPLETED, the backup connection will be pinged |
1871 // once every |backup_ping_interval| milliseconds. | 1973 // once every |backup_ping_interval| milliseconds. |
1872 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == cricket::STATE_COMPLETED, 1000); | 1974 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); |
1873 const std::vector<cricket::Connection*>& connections = | 1975 const std::vector<Connection*>& connections = ep2_ch1()->connections(); |
1874 ep2_ch1()->connections(); | |
1875 ASSERT_EQ(2U, connections.size()); | 1976 ASSERT_EQ(2U, connections.size()); |
1876 cricket::Connection* backup_conn = connections[1]; | 1977 Connection* backup_conn = connections[1]; |
1877 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); | 1978 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); |
1878 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); | 1979 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); |
1879 EXPECT_TRUE_WAIT( | 1980 EXPECT_TRUE_WAIT( |
1880 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); | 1981 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); |
1881 int time_elapsed = | 1982 int time_elapsed = |
1882 backup_conn->last_ping_response_received() - last_ping_response_ms; | 1983 backup_conn->last_ping_response_received() - last_ping_response_ms; |
1883 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; | 1984 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; |
1884 EXPECT_GE(time_elapsed, backup_ping_interval); | 1985 EXPECT_GE(time_elapsed, backup_ping_interval); |
1885 } | 1986 } |
1886 | 1987 |
1887 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { | 1988 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { |
1888 AddAddress(0, kAlternateAddrs[0]); | 1989 AddAddress(0, kAlternateAddrs[0]); |
1889 AddAddress(0, kPublicAddrs[0]); | 1990 AddAddress(0, kPublicAddrs[0]); |
1890 AddAddress(1, kPublicAddrs[1]); | 1991 AddAddress(1, kPublicAddrs[1]); |
1891 // Create channels and let them go writable, as usual. | 1992 // Create channels and let them go writable, as usual. |
1892 CreateChannels(1); | 1993 CreateChannels(1); |
1893 | 1994 |
1894 // Both transport channels will reach STATE_COMPLETED quickly. | 1995 // Both transport channels will reach STATE_COMPLETED quickly. |
1895 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, | 1996 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(), |
1896 ep1_ch1()->GetState(), 1000); | 1997 1000); |
1897 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, | 1998 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(), |
1898 ep2_ch1()->GetState(), 1000); | 1999 1000); |
1899 } | 2000 } |
1900 | 2001 |
1901 // Tests that when a network interface becomes inactive, if and only if | 2002 // Tests that when a network interface becomes inactive, if and only if |
1902 // Continual Gathering is enabled, the ports associated with that network | 2003 // Continual Gathering is enabled, the ports associated with that network |
1903 // will be removed from the port list of the channel, and the respective | 2004 // will be removed from the port list of the channel, and the respective |
1904 // remote candidates on the other participant will be removed eventually. | 2005 // remote candidates on the other participant will be removed eventually. |
1905 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { | 2006 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { |
1906 AddAddress(0, kPublicAddrs[0]); | 2007 AddAddress(0, kPublicAddrs[0]); |
1907 AddAddress(1, kPublicAddrs[1]); | 2008 AddAddress(1, kPublicAddrs[1]); |
1908 // Create channels and let them go writable, as usual. | 2009 // Create channels and let them go writable, as usual. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 // pings. | 2088 // pings. |
1988 class P2PTransportChannelPingTest : public testing::Test, | 2089 class P2PTransportChannelPingTest : public testing::Test, |
1989 public sigslot::has_slots<> { | 2090 public sigslot::has_slots<> { |
1990 public: | 2091 public: |
1991 P2PTransportChannelPingTest() | 2092 P2PTransportChannelPingTest() |
1992 : pss_(new rtc::PhysicalSocketServer), | 2093 : pss_(new rtc::PhysicalSocketServer), |
1993 vss_(new rtc::VirtualSocketServer(pss_.get())), | 2094 vss_(new rtc::VirtualSocketServer(pss_.get())), |
1994 ss_scope_(vss_.get()) {} | 2095 ss_scope_(vss_.get()) {} |
1995 | 2096 |
1996 protected: | 2097 protected: |
1997 void PrepareChannel(cricket::P2PTransportChannel* ch) { | 2098 void PrepareChannel(P2PTransportChannel* ch) { |
1998 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2099 ch->SetIceRole(ICEROLE_CONTROLLING); |
1999 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 2100 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |
2000 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2101 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2001 ch->SignalSelectedCandidatePairChanged.connect( | 2102 ch->SignalSelectedCandidatePairChanged.connect( |
2002 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); | 2103 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); |
2003 ch->SignalReadyToSend.connect(this, | 2104 ch->SignalReadyToSend.connect(this, |
2004 &P2PTransportChannelPingTest::OnReadyToSend); | 2105 &P2PTransportChannelPingTest::OnReadyToSend); |
2005 ch->SignalStateChanged.connect( | 2106 ch->SignalStateChanged.connect( |
2006 this, &P2PTransportChannelPingTest::OnChannelStateChanged); | 2107 this, &P2PTransportChannelPingTest::OnChannelStateChanged); |
2007 } | 2108 } |
2008 | 2109 |
2009 cricket::Candidate CreateHostCandidate(const std::string& ip, | 2110 Connection* WaitForConnectionTo(P2PTransportChannel* ch, |
2010 int port, | 2111 const std::string& ip, |
2011 int priority, | 2112 int port_num) { |
2012 const std::string& ufrag = "") { | |
2013 cricket::Candidate c; | |
2014 c.set_address(rtc::SocketAddress(ip, port)); | |
2015 c.set_component(1); | |
2016 c.set_protocol(cricket::UDP_PROTOCOL_NAME); | |
2017 c.set_priority(priority); | |
2018 c.set_username(ufrag); | |
2019 c.set_type(cricket::LOCAL_PORT_TYPE); | |
2020 return c; | |
2021 } | |
2022 | |
2023 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, | |
2024 const std::string& ip, | |
2025 int port_num) { | |
2026 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); | 2113 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); |
2027 return GetConnectionTo(ch, ip, port_num); | 2114 return GetConnectionTo(ch, ip, port_num); |
2028 } | 2115 } |
2029 | 2116 |
2030 cricket::Port* GetPort(cricket::P2PTransportChannel* ch) { | 2117 Port* GetPort(P2PTransportChannel* ch) { |
2031 if (ch->ports().empty()) { | 2118 if (ch->ports().empty()) { |
2032 return nullptr; | 2119 return nullptr; |
2033 } | 2120 } |
2034 return static_cast<cricket::Port*>(ch->ports()[0]); | 2121 return static_cast<Port*>(ch->ports()[0]); |
2035 } | 2122 } |
2036 | 2123 |
2037 cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch, | 2124 Connection* GetConnectionTo(P2PTransportChannel* ch, |
2038 const std::string& ip, | 2125 const std::string& ip, |
2039 int port_num) { | 2126 int port_num) { |
2040 cricket::Port* port = GetPort(ch); | 2127 Port* port = GetPort(ch); |
2041 if (!port) { | 2128 if (!port) { |
2042 return nullptr; | 2129 return nullptr; |
2043 } | 2130 } |
2044 return port->GetConnection(rtc::SocketAddress(ip, port_num)); | 2131 return port->GetConnection(rtc::SocketAddress(ip, port_num)); |
2045 } | 2132 } |
2046 | 2133 |
2047 cricket::Connection* FindNextPingableConnectionAndPingIt( | 2134 Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) { |
2048 cricket::P2PTransportChannel* ch) { | 2135 Connection* conn = ch->FindNextPingableConnection(); |
2049 cricket::Connection* conn = ch->FindNextPingableConnection(); | |
2050 if (conn) { | 2136 if (conn) { |
2051 ch->MarkConnectionPinged(conn); | 2137 ch->MarkConnectionPinged(conn); |
2052 } | 2138 } |
2053 return conn; | 2139 return conn; |
2054 } | 2140 } |
2055 | 2141 |
2056 int SendData(cricket::TransportChannel& channel, | 2142 int SendData(TransportChannel& channel, |
2057 const char* data, | 2143 const char* data, |
2058 size_t len, | 2144 size_t len, |
2059 int packet_id) { | 2145 int packet_id) { |
2060 rtc::PacketOptions options; | 2146 rtc::PacketOptions options; |
2061 options.packet_id = packet_id; | 2147 options.packet_id = packet_id; |
2062 return channel.SendPacket(data, len, options, 0); | 2148 return channel.SendPacket(data, len, options, 0); |
2063 } | 2149 } |
2064 | 2150 |
2065 void OnSelectedCandidatePairChanged( | 2151 void OnSelectedCandidatePairChanged( |
2066 cricket::TransportChannel* transport_channel, | 2152 TransportChannel* transport_channel, |
2067 cricket::CandidatePairInterface* selected_candidate_pair, | 2153 CandidatePairInterface* selected_candidate_pair, |
2068 int last_sent_packet_id) { | 2154 int last_sent_packet_id) { |
2069 last_selected_candidate_pair_ = selected_candidate_pair; | 2155 last_selected_candidate_pair_ = selected_candidate_pair; |
2070 last_sent_packet_id_ = last_sent_packet_id; | 2156 last_sent_packet_id_ = last_sent_packet_id; |
2071 } | 2157 } |
2072 | 2158 |
2073 void ReceivePingOnConnection(cricket::Connection* conn, | 2159 void ReceivePingOnConnection(Connection* conn, |
2074 const std::string& remote_ufrag, | 2160 const std::string& remote_ufrag, |
2075 int priority) { | 2161 int priority) { |
2076 cricket::IceMessage msg; | 2162 IceMessage msg; |
2077 msg.SetType(cricket::STUN_BINDING_REQUEST); | 2163 msg.SetType(STUN_BINDING_REQUEST); |
2078 msg.AddAttribute(new cricket::StunByteStringAttribute( | 2164 msg.AddAttribute(new StunByteStringAttribute( |
2079 cricket::STUN_ATTR_USERNAME, | 2165 STUN_ATTR_USERNAME, |
2080 conn->local_candidate().username() + ":" + remote_ufrag)); | 2166 conn->local_candidate().username() + ":" + remote_ufrag)); |
2081 msg.AddAttribute(new cricket::StunUInt32Attribute( | 2167 msg.AddAttribute(new StunUInt32Attribute(STUN_ATTR_PRIORITY, priority)); |
2082 cricket::STUN_ATTR_PRIORITY, priority)); | 2168 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); |
2083 msg.SetTransactionID( | |
2084 rtc::CreateRandomString(cricket::kStunTransactionIdLength)); | |
2085 msg.AddMessageIntegrity(conn->local_candidate().password()); | 2169 msg.AddMessageIntegrity(conn->local_candidate().password()); |
2086 msg.AddFingerprint(); | 2170 msg.AddFingerprint(); |
2087 rtc::ByteBufferWriter buf; | 2171 rtc::ByteBufferWriter buf; |
2088 msg.Write(&buf); | 2172 msg.Write(&buf); |
2089 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); | 2173 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); |
2090 } | 2174 } |
2091 | 2175 |
2092 void OnReadyToSend(cricket::TransportChannel* channel) { | 2176 void OnReadyToSend(TransportChannel* channel) { |
2093 channel_ready_to_send_ = true; | 2177 channel_ready_to_send_ = true; |
2094 } | 2178 } |
2095 void OnChannelStateChanged(cricket::TransportChannelImpl* channel) { | 2179 void OnChannelStateChanged(TransportChannelImpl* channel) { |
2096 channel_state_ = channel->GetState(); | 2180 channel_state_ = channel->GetState(); |
2097 } | 2181 } |
2098 | 2182 |
2099 cricket::CandidatePairInterface* last_selected_candidate_pair() { | 2183 CandidatePairInterface* last_selected_candidate_pair() { |
2100 return last_selected_candidate_pair_; | 2184 return last_selected_candidate_pair_; |
2101 } | 2185 } |
2102 int last_sent_packet_id() { return last_sent_packet_id_; } | 2186 int last_sent_packet_id() { return last_sent_packet_id_; } |
2103 bool channel_ready_to_send() { return channel_ready_to_send_; } | 2187 bool channel_ready_to_send() { return channel_ready_to_send_; } |
2104 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } | 2188 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } |
2105 cricket::TransportChannelState channel_state() { return channel_state_; } | 2189 TransportChannelState channel_state() { return channel_state_; } |
2106 | 2190 |
2107 private: | 2191 private: |
2108 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 2192 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
2109 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 2193 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
2110 rtc::SocketServerScope ss_scope_; | 2194 rtc::SocketServerScope ss_scope_; |
2111 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; | 2195 CandidatePairInterface* last_selected_candidate_pair_ = nullptr; |
2112 int last_sent_packet_id_ = -1; | 2196 int last_sent_packet_id_ = -1; |
2113 bool channel_ready_to_send_ = false; | 2197 bool channel_ready_to_send_ = false; |
2114 cricket::TransportChannelState channel_state_ = cricket::STATE_INIT; | 2198 TransportChannelState channel_state_ = STATE_INIT; |
2115 }; | 2199 }; |
2116 | 2200 |
2117 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 2201 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
2118 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2202 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2119 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 2203 P2PTransportChannel ch("trigger checks", 1, &pa); |
2120 PrepareChannel(&ch); | 2204 PrepareChannel(&ch); |
2121 ch.Connect(); | 2205 ch.Connect(); |
2122 ch.MaybeStartGathering(); | 2206 ch.MaybeStartGathering(); |
2123 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2207 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2124 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2208 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
2125 | 2209 |
2126 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2210 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2127 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2211 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2128 ASSERT_TRUE(conn1 != nullptr); | 2212 ASSERT_TRUE(conn1 != nullptr); |
2129 ASSERT_TRUE(conn2 != nullptr); | 2213 ASSERT_TRUE(conn2 != nullptr); |
2130 | 2214 |
2131 // Before a triggered check, the first connection to ping is the | 2215 // Before a triggered check, the first connection to ping is the |
2132 // highest priority one. | 2216 // highest priority one. |
2133 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2217 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
2134 | 2218 |
2135 // Receiving a ping causes a triggered check which should make conn1 | 2219 // Receiving a ping causes a triggered check which should make conn1 |
2136 // be pinged first instead of conn2, even though conn2 has a higher | 2220 // be pinged first instead of conn2, even though conn2 has a higher |
2137 // priority. | 2221 // priority. |
2138 conn1->ReceivedPing(); | 2222 conn1->ReceivedPing(); |
2139 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); | 2223 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
2140 } | 2224 } |
2141 | 2225 |
2142 TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) { | 2226 TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) { |
2143 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2227 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2144 cricket::P2PTransportChannel ch("ping sufficiently", 1, &pa); | 2228 P2PTransportChannel ch("ping sufficiently", 1, &pa); |
2145 PrepareChannel(&ch); | 2229 PrepareChannel(&ch); |
2146 ch.Connect(); | 2230 ch.Connect(); |
2147 ch.MaybeStartGathering(); | 2231 ch.MaybeStartGathering(); |
2148 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2232 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2149 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2233 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
2150 | 2234 |
2151 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2235 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2152 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2236 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2153 ASSERT_TRUE(conn1 != nullptr); | 2237 ASSERT_TRUE(conn1 != nullptr); |
2154 ASSERT_TRUE(conn2 != nullptr); | 2238 ASSERT_TRUE(conn2 != nullptr); |
2155 | 2239 |
2156 // Low-priority connection becomes writable so that the other connection | 2240 // Low-priority connection becomes writable so that the other connection |
2157 // is not pruned. | 2241 // is not pruned. |
2158 conn1->ReceivedPingResponse(LOW_RTT); | 2242 conn1->ReceivedPingResponse(LOW_RTT); |
2159 EXPECT_TRUE_WAIT( | 2243 EXPECT_TRUE_WAIT( |
2160 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && | 2244 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && |
2161 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, | 2245 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, |
2162 kDefaultTimeout); | 2246 kDefaultTimeout); |
2163 } | 2247 } |
2164 | 2248 |
2165 // Verify that the connections are pinged at the right time. | 2249 // Verify that the connections are pinged at the right time. |
2166 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { | 2250 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { |
2167 rtc::ScopedFakeClock clock; | 2251 rtc::ScopedFakeClock clock; |
2168 int RTT_RATIO = 4; | 2252 int RTT_RATIO = 4; |
2169 int SCHEDULING_RANGE = 200; | 2253 int SCHEDULING_RANGE = 200; |
2170 int RTT_RANGE = 10; | 2254 int RTT_RANGE = 10; |
2171 | 2255 |
2172 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2256 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2173 cricket::P2PTransportChannel ch("TestChannel", 1, &pa); | 2257 P2PTransportChannel ch("TestChannel", 1, &pa); |
2174 PrepareChannel(&ch); | 2258 PrepareChannel(&ch); |
2175 ch.Connect(); | 2259 ch.Connect(); |
2176 ch.MaybeStartGathering(); | 2260 ch.MaybeStartGathering(); |
2177 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2261 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2178 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2262 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2179 | 2263 |
2180 ASSERT_TRUE(conn != nullptr); | 2264 ASSERT_TRUE(conn != nullptr); |
2181 SIMULATED_WAIT(conn->num_pings_sent() == 1, kDefaultTimeout, clock); | 2265 SIMULATED_WAIT(conn->num_pings_sent() == 1, kDefaultTimeout, clock); |
2182 | 2266 |
2183 // Initializing. | 2267 // Initializing. |
2184 | 2268 |
2185 int64_t start = clock.TimeNanos(); | 2269 int64_t start = clock.TimeNanos(); |
2186 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, | 2270 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, |
2187 kDefaultTimeout, clock); | 2271 kDefaultTimeout, clock); |
2188 int64_t ping_interval_ms = (clock.TimeNanos() - start) / | 2272 int64_t ping_interval_ms = (clock.TimeNanos() - start) / |
2189 rtc::kNumNanosecsPerMillisec / | 2273 rtc::kNumNanosecsPerMillisec / |
2190 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); | 2274 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); |
2191 EXPECT_EQ(ping_interval_ms, cricket::WEAK_PING_INTERVAL); | 2275 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL); |
2192 | 2276 |
2193 // Stabilizing. | 2277 // Stabilizing. |
2194 | 2278 |
2195 conn->ReceivedPingResponse(LOW_RTT); | 2279 conn->ReceivedPingResponse(LOW_RTT); |
2196 int ping_sent_before = conn->num_pings_sent(); | 2280 int ping_sent_before = conn->num_pings_sent(); |
2197 start = clock.TimeNanos(); | 2281 start = clock.TimeNanos(); |
2198 // The connection becomes strong but not stable because we haven't been able | 2282 // The connection becomes strong but not stable because we haven't been able |
2199 // to converge the RTT. | 2283 // to converge the RTT. |
2200 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); | 2284 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
2201 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; | 2285 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
2202 EXPECT_GE(ping_interval_ms, | 2286 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); |
2203 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); | |
2204 EXPECT_LE(ping_interval_ms, | 2287 EXPECT_LE(ping_interval_ms, |
2205 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + | 2288 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); |
2206 SCHEDULING_RANGE); | |
2207 | 2289 |
2208 // Stabilized. | 2290 // Stabilized. |
2209 | 2291 |
2210 // The connection becomes stable after receiving more than RTT_RATIO rtt | 2292 // The connection becomes stable after receiving more than RTT_RATIO rtt |
2211 // samples. | 2293 // samples. |
2212 for (int i = 0; i < RTT_RATIO; i++) { | 2294 for (int i = 0; i < RTT_RATIO; i++) { |
2213 conn->ReceivedPingResponse(LOW_RTT); | 2295 conn->ReceivedPingResponse(LOW_RTT); |
2214 } | 2296 } |
2215 ping_sent_before = conn->num_pings_sent(); | 2297 ping_sent_before = conn->num_pings_sent(); |
2216 start = clock.TimeNanos(); | 2298 start = clock.TimeNanos(); |
2217 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); | 2299 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
2218 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; | 2300 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
2219 EXPECT_GE(ping_interval_ms, | 2301 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL); |
2220 cricket::STABLE_WRITABLE_CONNECTION_PING_INTERVAL); | 2302 EXPECT_LE(ping_interval_ms, |
2221 EXPECT_LE( | 2303 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); |
2222 ping_interval_ms, | |
2223 cricket::STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); | |
2224 | 2304 |
2225 // Destabilized. | 2305 // Destabilized. |
2226 | 2306 |
2227 conn->ReceivedPingResponse(LOW_RTT); | 2307 conn->ReceivedPingResponse(LOW_RTT); |
2228 // Create a in-flight ping. | 2308 // Create a in-flight ping. |
2229 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); | 2309 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); |
2230 start = clock.TimeNanos(); | 2310 start = clock.TimeNanos(); |
2231 // In-flight ping timeout and the connection will be unstable. | 2311 // In-flight ping timeout and the connection will be unstable. |
2232 SIMULATED_WAIT( | 2312 SIMULATED_WAIT( |
2233 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, | 2313 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, |
2234 clock); | 2314 clock); |
2235 int64_t duration_ms = | 2315 int64_t duration_ms = |
2236 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; | 2316 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
2237 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); | 2317 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); |
2238 EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE); | 2318 EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE); |
2239 // The connection become unstable due to not receiving ping responses. | 2319 // The connection become unstable due to not receiving ping responses. |
2240 ping_sent_before = conn->num_pings_sent(); | 2320 ping_sent_before = conn->num_pings_sent(); |
2241 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); | 2321 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
2242 // The interval is expected to be | 2322 // The interval is expected to be |
2243 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL. | 2323 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL. |
2244 start = clock.TimeNanos(); | 2324 start = clock.TimeNanos(); |
2245 ping_sent_before = conn->num_pings_sent(); | 2325 ping_sent_before = conn->num_pings_sent(); |
2246 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); | 2326 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
2247 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; | 2327 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
2248 EXPECT_GE(ping_interval_ms, | 2328 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); |
2249 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); | |
2250 EXPECT_LE(ping_interval_ms, | 2329 EXPECT_LE(ping_interval_ms, |
2251 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + | 2330 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); |
2252 SCHEDULING_RANGE); | |
2253 } | 2331 } |
2254 | 2332 |
2255 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { | 2333 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
2256 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2334 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2257 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 2335 P2PTransportChannel ch("trigger checks", 1, &pa); |
2258 PrepareChannel(&ch); | 2336 PrepareChannel(&ch); |
2259 ch.Connect(); | 2337 ch.Connect(); |
2260 ch.MaybeStartGathering(); | 2338 ch.MaybeStartGathering(); |
2261 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2339 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2262 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2340 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
2263 | 2341 |
2264 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2342 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2265 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2343 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2266 ASSERT_TRUE(conn1 != nullptr); | 2344 ASSERT_TRUE(conn1 != nullptr); |
2267 ASSERT_TRUE(conn2 != nullptr); | 2345 ASSERT_TRUE(conn2 != nullptr); |
2268 | 2346 |
2269 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2347 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
2270 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); | 2348 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
2271 conn1->ReceivedPingResponse(LOW_RTT); | 2349 conn1->ReceivedPingResponse(LOW_RTT); |
2272 ASSERT_TRUE(conn1->writable()); | 2350 ASSERT_TRUE(conn1->writable()); |
2273 conn1->ReceivedPing(); | 2351 conn1->ReceivedPing(); |
2274 | 2352 |
2275 // Ping received, but the connection is already writable, so no | 2353 // Ping received, but the connection is already writable, so no |
2276 // "triggered check" and conn2 is pinged before conn1 because it has | 2354 // "triggered check" and conn2 is pinged before conn1 because it has |
2277 // a higher priority. | 2355 // a higher priority. |
2278 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2356 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
2279 } | 2357 } |
2280 | 2358 |
2281 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { | 2359 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { |
2282 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2360 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2283 cricket::P2PTransportChannel ch("Do not ping failed connections", 1, &pa); | 2361 P2PTransportChannel ch("Do not ping failed connections", 1, &pa); |
2284 PrepareChannel(&ch); | 2362 PrepareChannel(&ch); |
2285 ch.Connect(); | 2363 ch.Connect(); |
2286 ch.MaybeStartGathering(); | 2364 ch.MaybeStartGathering(); |
2287 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2365 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2288 | 2366 |
2289 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2367 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2290 ASSERT_TRUE(conn1 != nullptr); | 2368 ASSERT_TRUE(conn1 != nullptr); |
2291 | 2369 |
2292 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); | 2370 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); |
2293 conn1->Prune(); // A pruned connection may still be pingable. | 2371 conn1->Prune(); // A pruned connection may still be pingable. |
2294 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); | 2372 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); |
2295 conn1->FailAndPrune(); | 2373 conn1->FailAndPrune(); |
2296 EXPECT_TRUE(nullptr == ch.FindNextPingableConnection()); | 2374 EXPECT_TRUE(nullptr == ch.FindNextPingableConnection()); |
2297 } | 2375 } |
2298 | 2376 |
2299 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { | 2377 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { |
2300 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2378 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2301 cricket::P2PTransportChannel ch("state change", 1, &pa); | 2379 P2PTransportChannel ch("state change", 1, &pa); |
2302 PrepareChannel(&ch); | 2380 PrepareChannel(&ch); |
2303 ch.Connect(); | 2381 ch.Connect(); |
2304 ch.MaybeStartGathering(); | 2382 ch.MaybeStartGathering(); |
2305 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2383 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2306 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2384 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2307 ASSERT_TRUE(conn1 != nullptr); | 2385 ASSERT_TRUE(conn1 != nullptr); |
2308 // Pruning the connection reduces the set of active connections and changes | 2386 // Pruning the connection reduces the set of active connections and changes |
2309 // the channel state. | 2387 // the channel state. |
2310 conn1->Prune(); | 2388 conn1->Prune(); |
2311 EXPECT_EQ_WAIT(cricket::STATE_FAILED, channel_state(), kDefaultTimeout); | 2389 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); |
2312 } | 2390 } |
2313 | 2391 |
2314 // Test adding remote candidates with different ufrags. If a remote candidate | 2392 // Test adding remote candidates with different ufrags. If a remote candidate |
2315 // is added with an old ufrag, it will be discarded. If it is added with a | 2393 // is added with an old ufrag, it will be discarded. If it is added with a |
2316 // ufrag that was not seen before, it will be used to create connections | 2394 // ufrag that was not seen before, it will be used to create connections |
2317 // although the ICE pwd in the remote candidate will be set when the ICE | 2395 // although the ICE pwd in the remote candidate will be set when the ICE |
2318 // credentials arrive. If a remote candidate is added with the current ICE | 2396 // credentials arrive. If a remote candidate is added with the current ICE |
2319 // ufrag, its pwd and generation will be set properly. | 2397 // ufrag, its pwd and generation will be set properly. |
2320 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { | 2398 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
2321 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2399 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2322 cricket::P2PTransportChannel ch("add candidate", 1, &pa); | 2400 P2PTransportChannel ch("add candidate", 1, &pa); |
2323 PrepareChannel(&ch); | 2401 PrepareChannel(&ch); |
2324 ch.Connect(); | 2402 ch.Connect(); |
2325 ch.MaybeStartGathering(); | 2403 ch.MaybeStartGathering(); |
2326 // Add a candidate with a future ufrag. | 2404 // Add a candidate with a future ufrag. |
2327 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); | 2405 ch.AddRemoteCandidate( |
2328 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2406 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2])); |
| 2407 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2329 ASSERT_TRUE(conn1 != nullptr); | 2408 ASSERT_TRUE(conn1 != nullptr); |
2330 const cricket::Candidate& candidate = conn1->remote_candidate(); | 2409 const Candidate& candidate = conn1->remote_candidate(); |
2331 EXPECT_EQ(kIceUfrag[2], candidate.username()); | 2410 EXPECT_EQ(kIceUfrag[2], candidate.username()); |
2332 EXPECT_TRUE(candidate.password().empty()); | 2411 EXPECT_TRUE(candidate.password().empty()); |
2333 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); | 2412 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); |
2334 | 2413 |
2335 // Set the remote credentials with the "future" ufrag. | 2414 // Set the remote credentials with the "future" ufrag. |
2336 // This should set the ICE pwd in the remote candidate of |conn1|, making | 2415 // This should set the ICE pwd in the remote candidate of |conn1|, making |
2337 // it pingable. | 2416 // it pingable. |
2338 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 2417 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
2339 EXPECT_EQ(kIceUfrag[2], candidate.username()); | 2418 EXPECT_EQ(kIceUfrag[2], candidate.username()); |
2340 EXPECT_EQ(kIcePwd[2], candidate.password()); | 2419 EXPECT_EQ(kIcePwd[2], candidate.password()); |
2341 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); | 2420 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
2342 | 2421 |
2343 // Add a candidate with an old ufrag. No connection will be created. | 2422 // Add a candidate with an old ufrag. No connection will be created. |
2344 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2, kIceUfrag[1])); | 2423 ch.AddRemoteCandidate( |
| 2424 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1])); |
2345 rtc::Thread::Current()->ProcessMessages(500); | 2425 rtc::Thread::Current()->ProcessMessages(500); |
2346 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); | 2426 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); |
2347 | 2427 |
2348 // Add a candidate with the current ufrag, its pwd and generation will be | 2428 // Add a candidate with the current ufrag, its pwd and generation will be |
2349 // assigned, even if the generation is not set. | 2429 // assigned, even if the generation is not set. |
2350 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 0, kIceUfrag[2])); | 2430 ch.AddRemoteCandidate( |
2351 cricket::Connection* conn3 = nullptr; | 2431 CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 0, kIceUfrag[2])); |
| 2432 Connection* conn3 = nullptr; |
2352 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr, | 2433 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr, |
2353 3000); | 2434 3000); |
2354 const cricket::Candidate& new_candidate = conn3->remote_candidate(); | 2435 const Candidate& new_candidate = conn3->remote_candidate(); |
2355 EXPECT_EQ(kIcePwd[2], new_candidate.password()); | 2436 EXPECT_EQ(kIcePwd[2], new_candidate.password()); |
2356 EXPECT_EQ(1U, new_candidate.generation()); | 2437 EXPECT_EQ(1U, new_candidate.generation()); |
2357 | 2438 |
2358 // Check that the pwd of all remote candidates are properly assigned. | 2439 // Check that the pwd of all remote candidates are properly assigned. |
2359 for (const cricket::RemoteCandidate& candidate : ch.remote_candidates()) { | 2440 for (const RemoteCandidate& candidate : ch.remote_candidates()) { |
2360 EXPECT_TRUE(candidate.username() == kIceUfrag[1] || | 2441 EXPECT_TRUE(candidate.username() == kIceUfrag[1] || |
2361 candidate.username() == kIceUfrag[2]); | 2442 candidate.username() == kIceUfrag[2]); |
2362 if (candidate.username() == kIceUfrag[1]) { | 2443 if (candidate.username() == kIceUfrag[1]) { |
2363 EXPECT_EQ(kIcePwd[1], candidate.password()); | 2444 EXPECT_EQ(kIcePwd[1], candidate.password()); |
2364 } else if (candidate.username() == kIceUfrag[2]) { | 2445 } else if (candidate.username() == kIceUfrag[2]) { |
2365 EXPECT_EQ(kIcePwd[2], candidate.password()); | 2446 EXPECT_EQ(kIcePwd[2], candidate.password()); |
2366 } | 2447 } |
2367 } | 2448 } |
2368 } | 2449 } |
2369 | 2450 |
2370 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { | 2451 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { |
2371 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2452 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2372 cricket::P2PTransportChannel ch("connection resurrection", 1, &pa); | 2453 P2PTransportChannel ch("connection resurrection", 1, &pa); |
2373 PrepareChannel(&ch); | 2454 PrepareChannel(&ch); |
2374 ch.Connect(); | 2455 ch.Connect(); |
2375 ch.MaybeStartGathering(); | 2456 ch.MaybeStartGathering(); |
2376 | 2457 |
2377 // Create conn1 and keep track of original candidate priority. | 2458 // Create conn1 and keep track of original candidate priority. |
2378 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2459 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2379 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2460 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2380 ASSERT_TRUE(conn1 != nullptr); | 2461 ASSERT_TRUE(conn1 != nullptr); |
2381 uint32_t remote_priority = conn1->remote_candidate().priority(); | 2462 uint32_t remote_priority = conn1->remote_candidate().priority(); |
2382 | 2463 |
2383 // Create a higher priority candidate and make the connection | 2464 // Create a higher priority candidate and make the connection |
2384 // receiving/writable. This will prune conn1. | 2465 // receiving/writable. This will prune conn1. |
2385 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2466 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
2386 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2467 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2387 ASSERT_TRUE(conn2 != nullptr); | 2468 ASSERT_TRUE(conn2 != nullptr); |
2388 conn2->ReceivedPing(); | 2469 conn2->ReceivedPing(); |
2389 conn2->ReceivedPingResponse(LOW_RTT); | 2470 conn2->ReceivedPingResponse(LOW_RTT); |
2390 | 2471 |
2391 // Wait for conn1 to be pruned. | 2472 // Wait for conn1 to be pruned. |
2392 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2473 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
2393 // Destroy the connection to test SignalUnknownAddress. | 2474 // Destroy the connection to test SignalUnknownAddress. |
2394 conn1->Destroy(); | 2475 conn1->Destroy(); |
2395 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); | 2476 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); |
2396 | 2477 |
2397 // Create a minimal STUN message with prflx priority. | 2478 // Create a minimal STUN message with prflx priority. |
2398 cricket::IceMessage request; | 2479 IceMessage request; |
2399 request.SetType(cricket::STUN_BINDING_REQUEST); | 2480 request.SetType(STUN_BINDING_REQUEST); |
2400 request.AddAttribute(new cricket::StunByteStringAttribute( | 2481 request.AddAttribute( |
2401 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2482 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); |
2402 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2483 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; |
2403 request.AddAttribute(new cricket::StunUInt32Attribute( | 2484 request.AddAttribute( |
2404 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 2485 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); |
2405 EXPECT_NE(prflx_priority, remote_priority); | 2486 EXPECT_NE(prflx_priority, remote_priority); |
2406 | 2487 |
2407 cricket::Port* port = GetPort(&ch); | 2488 Port* port = GetPort(&ch); |
2408 // conn1 should be resurrected with original priority. | 2489 // conn1 should be resurrected with original priority. |
2409 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 2490 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, |
2410 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2491 &request, kIceUfrag[1], false); |
2411 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2492 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2412 ASSERT_TRUE(conn1 != nullptr); | 2493 ASSERT_TRUE(conn1 != nullptr); |
2413 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); | 2494 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); |
2414 | 2495 |
2415 // conn3, a real prflx connection, should have prflx priority. | 2496 // conn3, a real prflx connection, should have prflx priority. |
2416 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), | 2497 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP, |
2417 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2498 &request, kIceUfrag[1], false); |
2418 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); | 2499 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); |
2419 ASSERT_TRUE(conn3 != nullptr); | 2500 ASSERT_TRUE(conn3 != nullptr); |
2420 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); | 2501 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); |
2421 } | 2502 } |
2422 | 2503 |
2423 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { | 2504 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { |
2424 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2505 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2425 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2506 P2PTransportChannel ch("receiving state change", 1, &pa); |
2426 PrepareChannel(&ch); | 2507 PrepareChannel(&ch); |
2427 // Default receiving timeout and checking receiving interval should not be too | 2508 // Default receiving timeout and checking receiving interval should not be too |
2428 // small. | 2509 // small. |
2429 EXPECT_LE(1000, ch.receiving_timeout()); | 2510 EXPECT_LE(1000, ch.receiving_timeout()); |
2430 EXPECT_LE(200, ch.check_receiving_interval()); | 2511 EXPECT_LE(200, ch.check_receiving_interval()); |
2431 ch.SetIceConfig(CreateIceConfig(500, false)); | 2512 ch.SetIceConfig(CreateIceConfig(500, false)); |
2432 EXPECT_EQ(500, ch.receiving_timeout()); | 2513 EXPECT_EQ(500, ch.receiving_timeout()); |
2433 EXPECT_EQ(50, ch.check_receiving_interval()); | 2514 EXPECT_EQ(50, ch.check_receiving_interval()); |
2434 ch.Connect(); | 2515 ch.Connect(); |
2435 ch.MaybeStartGathering(); | 2516 ch.MaybeStartGathering(); |
2436 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2517 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2437 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2518 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2438 ASSERT_TRUE(conn1 != nullptr); | 2519 ASSERT_TRUE(conn1 != nullptr); |
2439 | 2520 |
2440 conn1->ReceivedPing(); | 2521 conn1->ReceivedPing(); |
2441 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2522 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2442 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 2523 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); |
2443 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 2524 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
2444 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 2525 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
2445 } | 2526 } |
2446 | 2527 |
2447 // The controlled side will select a connection as the "best connection" based | 2528 // The controlled side will select a connection as the "best connection" based |
2448 // on priority until the controlling side nominates a connection, at which | 2529 // on priority until the controlling side nominates a connection, at which |
2449 // point the controlled side will select that connection as the | 2530 // point the controlled side will select that connection as the |
2450 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the | 2531 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the |
2451 // best connection changes and SignalReadyToSend will be fired if the new best | 2532 // best connection changes and SignalReadyToSend will be fired if the new best |
2452 // connection is writable. | 2533 // connection is writable. |
2453 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 2534 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
2454 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2535 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2455 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2536 P2PTransportChannel ch("receiving state change", 1, &pa); |
2456 PrepareChannel(&ch); | 2537 PrepareChannel(&ch); |
2457 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2538 ch.SetIceRole(ICEROLE_CONTROLLED); |
2458 ch.Connect(); | 2539 ch.Connect(); |
2459 ch.MaybeStartGathering(); | 2540 ch.MaybeStartGathering(); |
2460 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2541 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2461 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2542 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2462 ASSERT_TRUE(conn1 != nullptr); | 2543 ASSERT_TRUE(conn1 != nullptr); |
2463 EXPECT_EQ(conn1, ch.best_connection()); | 2544 EXPECT_EQ(conn1, ch.best_connection()); |
2464 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 2545 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
2465 EXPECT_EQ(-1, last_sent_packet_id()); | 2546 EXPECT_EQ(-1, last_sent_packet_id()); |
2466 // Channel is not ready to send because it is not writable. | 2547 // Channel is not ready to send because it is not writable. |
2467 EXPECT_FALSE(channel_ready_to_send()); | 2548 EXPECT_FALSE(channel_ready_to_send()); |
2468 | 2549 |
2469 int last_packet_id = 0; | 2550 int last_packet_id = 0; |
2470 const char* data = "ABCDEFGH"; | 2551 const char* data = "ABCDEFGH"; |
2471 int len = static_cast<int>(strlen(data)); | 2552 int len = static_cast<int>(strlen(data)); |
2472 SendData(ch, data, len, ++last_packet_id); | 2553 SendData(ch, data, len, ++last_packet_id); |
2473 // When a higher priority candidate comes in, the new connection is chosen | 2554 // When a higher priority candidate comes in, the new connection is chosen |
2474 // as the best connection. | 2555 // as the best connection. |
2475 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2556 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); |
2476 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2557 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2477 ASSERT_TRUE(conn2 != nullptr); | 2558 ASSERT_TRUE(conn2 != nullptr); |
2478 EXPECT_EQ(conn2, ch.best_connection()); | 2559 EXPECT_EQ(conn2, ch.best_connection()); |
2479 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 2560 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
2480 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2561 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2481 EXPECT_FALSE(channel_ready_to_send()); | 2562 EXPECT_FALSE(channel_ready_to_send()); |
2482 | 2563 |
2483 // If a stun request with use-candidate attribute arrives, the receiving | 2564 // If a stun request with use-candidate attribute arrives, the receiving |
2484 // connection will be set as the best connection, even though | 2565 // connection will be set as the best connection, even though |
2485 // its priority is lower. | 2566 // its priority is lower. |
2486 SendData(ch, data, len, ++last_packet_id); | 2567 SendData(ch, data, len, ++last_packet_id); |
2487 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2568 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); |
2488 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2569 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2489 ASSERT_TRUE(conn3 != nullptr); | 2570 ASSERT_TRUE(conn3 != nullptr); |
2490 // Because it has a lower priority, the best connection is still conn2. | 2571 // Because it has a lower priority, the best connection is still conn2. |
2491 EXPECT_EQ(conn2, ch.best_connection()); | 2572 EXPECT_EQ(conn2, ch.best_connection()); |
2492 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 2573 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
2493 // But if it is nominated via use_candidate, it is chosen as the best | 2574 // But if it is nominated via use_candidate, it is chosen as the best |
2494 // connection. | 2575 // connection. |
2495 conn3->set_nominated(true); | 2576 conn3->set_nominated(true); |
2496 conn3->SignalNominated(conn3); | 2577 conn3->SignalNominated(conn3); |
2497 EXPECT_EQ(conn3, ch.best_connection()); | 2578 EXPECT_EQ(conn3, ch.best_connection()); |
2498 EXPECT_EQ(conn3, last_selected_candidate_pair()); | 2579 EXPECT_EQ(conn3, last_selected_candidate_pair()); |
2499 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2580 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2500 EXPECT_TRUE(channel_ready_to_send()); | 2581 EXPECT_TRUE(channel_ready_to_send()); |
2501 | 2582 |
2502 // Even if another higher priority candidate arrives, | 2583 // Even if another higher priority candidate arrives, |
2503 // it will not be set as the best connection because the best connection | 2584 // it will not be set as the best connection because the best connection |
2504 // is nominated by the controlling side. | 2585 // is nominated by the controlling side. |
2505 SendData(ch, data, len, ++last_packet_id); | 2586 SendData(ch, data, len, ++last_packet_id); |
2506 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); | 2587 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); |
2507 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2588 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
2508 ASSERT_TRUE(conn4 != nullptr); | 2589 ASSERT_TRUE(conn4 != nullptr); |
2509 EXPECT_EQ(conn3, ch.best_connection()); | 2590 EXPECT_EQ(conn3, ch.best_connection()); |
2510 // But if it is nominated via use_candidate and writable, it will be set as | 2591 // But if it is nominated via use_candidate and writable, it will be set as |
2511 // the best connection. | 2592 // the best connection. |
2512 conn4->set_nominated(true); | 2593 conn4->set_nominated(true); |
2513 conn4->SignalNominated(conn4); | 2594 conn4->SignalNominated(conn4); |
2514 // Not switched yet because conn4 is not writable. | 2595 // Not switched yet because conn4 is not writable. |
2515 EXPECT_EQ(conn3, ch.best_connection()); | 2596 EXPECT_EQ(conn3, ch.best_connection()); |
2516 reset_channel_ready_to_send(); | 2597 reset_channel_ready_to_send(); |
2517 // The best connection switches after conn4 becomes writable. | 2598 // The best connection switches after conn4 becomes writable. |
2518 conn4->ReceivedPingResponse(LOW_RTT); | 2599 conn4->ReceivedPingResponse(LOW_RTT); |
2519 EXPECT_EQ(conn4, ch.best_connection()); | 2600 EXPECT_EQ(conn4, ch.best_connection()); |
2520 EXPECT_EQ(conn4, last_selected_candidate_pair()); | 2601 EXPECT_EQ(conn4, last_selected_candidate_pair()); |
2521 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2602 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2522 // SignalReadyToSend is fired again because conn4 is writable. | 2603 // SignalReadyToSend is fired again because conn4 is writable. |
2523 EXPECT_TRUE(channel_ready_to_send()); | 2604 EXPECT_TRUE(channel_ready_to_send()); |
2524 } | 2605 } |
2525 | 2606 |
2526 // The controlled side will select a connection as the "best connection" based | 2607 // The controlled side will select a connection as the "best connection" based |
2527 // on requests from an unknown address before the controlling side nominates | 2608 // on requests from an unknown address before the controlling side nominates |
2528 // a connection, and will nominate a connection from an unknown address if the | 2609 // a connection, and will nominate a connection from an unknown address if the |
2529 // request contains the use_candidate attribute. Plus, it will also sends back | 2610 // request contains the use_candidate attribute. Plus, it will also sends back |
2530 // a ping response and set the ICE pwd in the remote candidate appropriately. | 2611 // a ping response and set the ICE pwd in the remote candidate appropriately. |
2531 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { | 2612 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
2532 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2613 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2533 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2614 P2PTransportChannel ch("receiving state change", 1, &pa); |
2534 PrepareChannel(&ch); | 2615 PrepareChannel(&ch); |
2535 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2616 ch.SetIceRole(ICEROLE_CONTROLLED); |
2536 ch.Connect(); | 2617 ch.Connect(); |
2537 ch.MaybeStartGathering(); | 2618 ch.MaybeStartGathering(); |
2538 // A minimal STUN message with prflx priority. | 2619 // A minimal STUN message with prflx priority. |
2539 cricket::IceMessage request; | 2620 IceMessage request; |
2540 request.SetType(cricket::STUN_BINDING_REQUEST); | 2621 request.SetType(STUN_BINDING_REQUEST); |
2541 request.AddAttribute(new cricket::StunByteStringAttribute( | 2622 request.AddAttribute( |
2542 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2623 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); |
2543 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2624 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; |
2544 request.AddAttribute(new cricket::StunUInt32Attribute( | 2625 request.AddAttribute( |
2545 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 2626 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); |
2546 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch)); | 2627 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); |
2547 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 2628 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, |
2548 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2629 &request, kIceUfrag[1], false); |
2549 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2630 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2550 ASSERT_TRUE(conn1 != nullptr); | 2631 ASSERT_TRUE(conn1 != nullptr); |
2551 EXPECT_TRUE(port->sent_binding_response()); | 2632 EXPECT_TRUE(port->sent_binding_response()); |
2552 EXPECT_EQ(conn1, ch.best_connection()); | 2633 EXPECT_EQ(conn1, ch.best_connection()); |
2553 conn1->ReceivedPingResponse(LOW_RTT); | 2634 conn1->ReceivedPingResponse(LOW_RTT); |
2554 EXPECT_EQ(conn1, ch.best_connection()); | 2635 EXPECT_EQ(conn1, ch.best_connection()); |
2555 port->set_sent_binding_response(false); | 2636 port->set_sent_binding_response(false); |
2556 | 2637 |
2557 // Another connection is nominated via use_candidate. | 2638 // Another connection is nominated via use_candidate. |
2558 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2639 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
2559 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2640 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2560 ASSERT_TRUE(conn2 != nullptr); | 2641 ASSERT_TRUE(conn2 != nullptr); |
2561 // Because it has a lower priority, the best connection is still conn1. | 2642 // Because it has a lower priority, the best connection is still conn1. |
2562 EXPECT_EQ(conn1, ch.best_connection()); | 2643 EXPECT_EQ(conn1, ch.best_connection()); |
2563 // When it is nominated via use_candidate and writable, it is chosen as the | 2644 // When it is nominated via use_candidate and writable, it is chosen as the |
2564 // best connection. | 2645 // best connection. |
2565 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. | 2646 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. |
2566 conn2->set_nominated(true); | 2647 conn2->set_nominated(true); |
2567 conn2->SignalNominated(conn2); | 2648 conn2->SignalNominated(conn2); |
2568 EXPECT_EQ(conn2, ch.best_connection()); | 2649 EXPECT_EQ(conn2, ch.best_connection()); |
2569 | 2650 |
2570 // Another request with unknown address, it will not be set as the best | 2651 // Another request with unknown address, it will not be set as the best |
2571 // connection because the best connection was nominated by the controlling | 2652 // connection because the best connection was nominated by the controlling |
2572 // side. | 2653 // side. |
2573 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 2654 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, |
2574 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2655 &request, kIceUfrag[1], false); |
2575 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2656 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2576 ASSERT_TRUE(conn3 != nullptr); | 2657 ASSERT_TRUE(conn3 != nullptr); |
2577 EXPECT_TRUE(port->sent_binding_response()); | 2658 EXPECT_TRUE(port->sent_binding_response()); |
2578 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 2659 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
2579 EXPECT_EQ(conn2, ch.best_connection()); | 2660 EXPECT_EQ(conn2, ch.best_connection()); |
2580 port->set_sent_binding_response(false); | 2661 port->set_sent_binding_response(false); |
2581 | 2662 |
2582 // However if the request contains use_candidate attribute, it will be | 2663 // However if the request contains use_candidate attribute, it will be |
2583 // selected as the best connection. | 2664 // selected as the best connection. |
2584 request.AddAttribute( | 2665 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); |
2585 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 2666 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP, |
2586 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), | 2667 &request, kIceUfrag[1], false); |
2587 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2668 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
2588 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | |
2589 ASSERT_TRUE(conn4 != nullptr); | 2669 ASSERT_TRUE(conn4 != nullptr); |
2590 EXPECT_TRUE(port->sent_binding_response()); | 2670 EXPECT_TRUE(port->sent_binding_response()); |
2591 // conn4 is not the best connection yet because it is not writable. | 2671 // conn4 is not the best connection yet because it is not writable. |
2592 EXPECT_EQ(conn2, ch.best_connection()); | 2672 EXPECT_EQ(conn2, ch.best_connection()); |
2593 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. | 2673 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. |
2594 EXPECT_EQ(conn4, ch.best_connection()); | 2674 EXPECT_EQ(conn4, ch.best_connection()); |
2595 | 2675 |
2596 // Test that the request from an unknown address contains a ufrag from an old | 2676 // Test that the request from an unknown address contains a ufrag from an old |
2597 // generation. | 2677 // generation. |
2598 port->set_sent_binding_response(false); | 2678 port->set_sent_binding_response(false); |
2599 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 2679 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
2600 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 2680 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
2601 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), | 2681 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, |
2602 cricket::PROTO_UDP, &request, kIceUfrag[2], false); | 2682 &request, kIceUfrag[2], false); |
2603 cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); | 2683 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); |
2604 ASSERT_TRUE(conn5 != nullptr); | 2684 ASSERT_TRUE(conn5 != nullptr); |
2605 EXPECT_TRUE(port->sent_binding_response()); | 2685 EXPECT_TRUE(port->sent_binding_response()); |
2606 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); | 2686 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); |
2607 } | 2687 } |
2608 | 2688 |
2609 // The controlled side will select a connection as the "best connection" | 2689 // The controlled side will select a connection as the "best connection" |
2610 // based on media received until the controlling side nominates a connection, | 2690 // based on media received until the controlling side nominates a connection, |
2611 // at which point the controlled side will select that connection as | 2691 // at which point the controlled side will select that connection as |
2612 // the "best connection". | 2692 // the "best connection". |
2613 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { | 2693 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
2614 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2694 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2615 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2695 P2PTransportChannel ch("receiving state change", 1, &pa); |
2616 PrepareChannel(&ch); | 2696 PrepareChannel(&ch); |
2617 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2697 ch.SetIceRole(ICEROLE_CONTROLLED); |
2618 ch.Connect(); | 2698 ch.Connect(); |
2619 ch.MaybeStartGathering(); | 2699 ch.MaybeStartGathering(); |
2620 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10)); | 2700 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10)); |
2621 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2701 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2622 ASSERT_TRUE(conn1 != nullptr); | 2702 ASSERT_TRUE(conn1 != nullptr); |
2623 EXPECT_EQ(conn1, ch.best_connection()); | 2703 EXPECT_EQ(conn1, ch.best_connection()); |
2624 | 2704 |
2625 // If a data packet is received on conn2, the best connection should | 2705 // If a data packet is received on conn2, the best connection should |
2626 // switch to conn2 because the controlled side must mirror the media path | 2706 // switch to conn2 because the controlled side must mirror the media path |
2627 // chosen by the controlling side. | 2707 // chosen by the controlling side. |
2628 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2708 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
2629 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2709 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2630 ASSERT_TRUE(conn2 != nullptr); | 2710 ASSERT_TRUE(conn2 != nullptr); |
2631 conn2->ReceivedPing(); // Start receiving. | 2711 conn2->ReceivedPing(); // Start receiving. |
2632 // Do not switch because it is not writable. | 2712 // Do not switch because it is not writable. |
2633 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2713 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2634 EXPECT_EQ(conn1, ch.best_connection()); | 2714 EXPECT_EQ(conn1, ch.best_connection()); |
2635 | 2715 |
2636 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. | 2716 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. |
2637 // Switch because it is writable. | 2717 // Switch because it is writable. |
2638 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); | 2718 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); |
2639 EXPECT_EQ(conn2, ch.best_connection()); | 2719 EXPECT_EQ(conn2, ch.best_connection()); |
2640 | 2720 |
2641 // Now another STUN message with an unknown address and use_candidate will | 2721 // Now another STUN message with an unknown address and use_candidate will |
2642 // nominate the best connection. | 2722 // nominate the best connection. |
2643 cricket::IceMessage request; | 2723 IceMessage request; |
2644 request.SetType(cricket::STUN_BINDING_REQUEST); | 2724 request.SetType(STUN_BINDING_REQUEST); |
2645 request.AddAttribute(new cricket::StunByteStringAttribute( | |
2646 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | |
2647 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | |
2648 request.AddAttribute(new cricket::StunUInt32Attribute( | |
2649 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | |
2650 request.AddAttribute( | 2725 request.AddAttribute( |
2651 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 2726 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); |
2652 cricket::Port* port = GetPort(&ch); | 2727 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; |
2653 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 2728 request.AddAttribute( |
2654 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2729 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); |
2655 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2730 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); |
| 2731 Port* port = GetPort(&ch); |
| 2732 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, |
| 2733 &request, kIceUfrag[1], false); |
| 2734 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2656 ASSERT_TRUE(conn3 != nullptr); | 2735 ASSERT_TRUE(conn3 != nullptr); |
2657 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet. | 2736 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet. |
2658 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 2737 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
2659 EXPECT_EQ(conn3, ch.best_connection()); | 2738 EXPECT_EQ(conn3, ch.best_connection()); |
2660 | 2739 |
2661 // Now another data packet will not switch the best connection because the | 2740 // Now another data packet will not switch the best connection because the |
2662 // best connection was nominated by the controlling side. | 2741 // best connection was nominated by the controlling side. |
2663 conn2->ReceivedPing(); | 2742 conn2->ReceivedPing(); |
2664 conn2->ReceivedPingResponse(LOW_RTT); | 2743 conn2->ReceivedPingResponse(LOW_RTT); |
2665 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 2744 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
2666 EXPECT_EQ(conn3, ch.best_connection()); | 2745 EXPECT_EQ(conn3, ch.best_connection()); |
2667 } | 2746 } |
2668 | 2747 |
2669 // Test that if a new remote candidate has the same address and port with | 2748 // Test that if a new remote candidate has the same address and port with |
2670 // an old one, it will be used to create a new connection. | 2749 // an old one, it will be used to create a new connection. |
2671 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { | 2750 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { |
2672 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2751 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2673 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa); | 2752 P2PTransportChannel ch("candidate reuse", 1, &pa); |
2674 PrepareChannel(&ch); | 2753 PrepareChannel(&ch); |
2675 ch.Connect(); | 2754 ch.Connect(); |
2676 ch.MaybeStartGathering(); | 2755 ch.MaybeStartGathering(); |
2677 const std::string host_address = "1.1.1.1"; | 2756 const std::string host_address = "1.1.1.1"; |
2678 const int port_num = 1; | 2757 const int port_num = 1; |
2679 | 2758 |
2680 // kIceUfrag[1] is the current generation ufrag. | 2759 // kIceUfrag[1] is the current generation ufrag. |
2681 cricket::Candidate candidate = | 2760 Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address, |
2682 CreateHostCandidate(host_address, port_num, 1, kIceUfrag[1]); | 2761 port_num, 1, kIceUfrag[1]); |
2683 ch.AddRemoteCandidate(candidate); | 2762 ch.AddRemoteCandidate(candidate); |
2684 cricket::Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num); | 2763 Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num); |
2685 ASSERT_TRUE(conn1 != nullptr); | 2764 ASSERT_TRUE(conn1 != nullptr); |
2686 EXPECT_EQ(0u, conn1->remote_candidate().generation()); | 2765 EXPECT_EQ(0u, conn1->remote_candidate().generation()); |
2687 | 2766 |
2688 // Simply adding the same candidate again won't create a new connection. | 2767 // Simply adding the same candidate again won't create a new connection. |
2689 ch.AddRemoteCandidate(candidate); | 2768 ch.AddRemoteCandidate(candidate); |
2690 cricket::Connection* conn2 = GetConnectionTo(&ch, host_address, port_num); | 2769 Connection* conn2 = GetConnectionTo(&ch, host_address, port_num); |
2691 EXPECT_EQ(conn1, conn2); | 2770 EXPECT_EQ(conn1, conn2); |
2692 | 2771 |
2693 // Update the ufrag of the candidate and add it again. | 2772 // Update the ufrag of the candidate and add it again. |
2694 candidate.set_username(kIceUfrag[2]); | 2773 candidate.set_username(kIceUfrag[2]); |
2695 ch.AddRemoteCandidate(candidate); | 2774 ch.AddRemoteCandidate(candidate); |
2696 conn2 = GetConnectionTo(&ch, host_address, port_num); | 2775 conn2 = GetConnectionTo(&ch, host_address, port_num); |
2697 EXPECT_NE(conn1, conn2); | 2776 EXPECT_NE(conn1, conn2); |
2698 EXPECT_EQ(kIceUfrag[2], conn2->remote_candidate().username()); | 2777 EXPECT_EQ(kIceUfrag[2], conn2->remote_candidate().username()); |
2699 EXPECT_EQ(1u, conn2->remote_candidate().generation()); | 2778 EXPECT_EQ(1u, conn2->remote_candidate().generation()); |
2700 | 2779 |
2701 // Verify that a ping with the new ufrag can be received on the new | 2780 // Verify that a ping with the new ufrag can be received on the new |
2702 // connection. | 2781 // connection. |
2703 EXPECT_EQ(0, conn2->last_ping_received()); | 2782 EXPECT_EQ(0, conn2->last_ping_received()); |
2704 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); | 2783 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); |
2705 EXPECT_TRUE(conn2->last_ping_received() > 0); | 2784 EXPECT_TRUE(conn2->last_ping_received() > 0); |
2706 } | 2785 } |
2707 | 2786 |
2708 // When the current best connection is strong, lower-priority connections will | 2787 // When the current best connection is strong, lower-priority connections will |
2709 // be pruned. Otherwise, lower-priority connections are kept. | 2788 // be pruned. Otherwise, lower-priority connections are kept. |
2710 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 2789 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
2711 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2790 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2712 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2791 P2PTransportChannel ch("test channel", 1, &pa); |
2713 PrepareChannel(&ch); | 2792 PrepareChannel(&ch); |
2714 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2793 ch.SetIceRole(ICEROLE_CONTROLLED); |
2715 ch.Connect(); | 2794 ch.Connect(); |
2716 ch.MaybeStartGathering(); | 2795 ch.MaybeStartGathering(); |
2717 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2796 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2718 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2797 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2719 ASSERT_TRUE(conn1 != nullptr); | 2798 ASSERT_TRUE(conn1 != nullptr); |
2720 EXPECT_EQ(conn1, ch.best_connection()); | 2799 EXPECT_EQ(conn1, ch.best_connection()); |
2721 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 2800 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2722 | 2801 |
2723 // When a higher-priority, nominated candidate comes in, the connections with | 2802 // When a higher-priority, nominated candidate comes in, the connections with |
2724 // lower-priority are pruned. | 2803 // lower-priority are pruned. |
2725 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2804 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); |
2726 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2805 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2727 ASSERT_TRUE(conn2 != nullptr); | 2806 ASSERT_TRUE(conn2 != nullptr); |
2728 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 2807 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2729 conn2->set_nominated(true); | 2808 conn2->set_nominated(true); |
2730 conn2->SignalNominated(conn2); | 2809 conn2->SignalNominated(conn2); |
2731 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2810 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
2732 | 2811 |
2733 ch.SetIceConfig(CreateIceConfig(500, false)); | 2812 ch.SetIceConfig(CreateIceConfig(500, false)); |
2734 // Wait until conn2 becomes not receiving. | 2813 // Wait until conn2 becomes not receiving. |
2735 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 2814 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
2736 | 2815 |
2737 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2816 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); |
2738 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2817 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2739 ASSERT_TRUE(conn3 != nullptr); | 2818 ASSERT_TRUE(conn3 != nullptr); |
2740 // The best connection should still be conn2. Even through conn3 has lower | 2819 // The best connection should still be conn2. Even through conn3 has lower |
2741 // priority and is not receiving/writable, it is not pruned because the best | 2820 // priority and is not receiving/writable, it is not pruned because the best |
2742 // connection is not receiving. | 2821 // connection is not receiving. |
2743 WAIT(conn3->pruned(), 1000); | 2822 WAIT(conn3->pruned(), 1000); |
2744 EXPECT_FALSE(conn3->pruned()); | 2823 EXPECT_FALSE(conn3->pruned()); |
2745 } | 2824 } |
2746 | 2825 |
2747 // Test that GetState returns the state correctly. | 2826 // Test that GetState returns the state correctly. |
2748 TEST_F(P2PTransportChannelPingTest, TestGetState) { | 2827 TEST_F(P2PTransportChannelPingTest, TestGetState) { |
2749 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2828 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2750 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2829 P2PTransportChannel ch("test channel", 1, &pa); |
2751 PrepareChannel(&ch); | 2830 PrepareChannel(&ch); |
2752 ch.Connect(); | 2831 ch.Connect(); |
2753 ch.MaybeStartGathering(); | 2832 ch.MaybeStartGathering(); |
2754 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); | 2833 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); |
2755 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2834 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
2756 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2835 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
2757 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2836 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2758 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2837 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2759 ASSERT_TRUE(conn1 != nullptr); | 2838 ASSERT_TRUE(conn1 != nullptr); |
2760 ASSERT_TRUE(conn2 != nullptr); | 2839 ASSERT_TRUE(conn2 != nullptr); |
2761 // Now there are two connections, so the transport channel is connecting. | 2840 // Now there are two connections, so the transport channel is connecting. |
2762 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2841 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); |
2763 // |conn1| becomes writable and receiving; it then should prune |conn2|. | 2842 // |conn1| becomes writable and receiving; it then should prune |conn2|. |
2764 conn1->ReceivedPingResponse(LOW_RTT); | 2843 conn1->ReceivedPingResponse(LOW_RTT); |
2765 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | 2844 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); |
2766 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2845 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2767 conn1->Prune(); // All connections are pruned. | 2846 conn1->Prune(); // All connections are pruned. |
2768 // Need to wait until the channel state is updated. | 2847 // Need to wait until the channel state is updated. |
2769 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), | 2848 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); |
2770 1000); | |
2771 } | 2849 } |
2772 | 2850 |
2773 // Test that when a low-priority connection is pruned, it is not deleted | 2851 // Test that when a low-priority connection is pruned, it is not deleted |
2774 // right away, and it can become active and be pruned again. | 2852 // right away, and it can become active and be pruned again. |
2775 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 2853 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
2776 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2854 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2777 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2855 P2PTransportChannel ch("test channel", 1, &pa); |
2778 PrepareChannel(&ch); | 2856 PrepareChannel(&ch); |
2779 ch.SetIceConfig(CreateIceConfig(1000, false)); | 2857 ch.SetIceConfig(CreateIceConfig(1000, false)); |
2780 ch.Connect(); | 2858 ch.Connect(); |
2781 ch.MaybeStartGathering(); | 2859 ch.MaybeStartGathering(); |
2782 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2860 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
2783 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2861 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2784 ASSERT_TRUE(conn1 != nullptr); | 2862 ASSERT_TRUE(conn1 != nullptr); |
2785 EXPECT_EQ(conn1, ch.best_connection()); | 2863 EXPECT_EQ(conn1, ch.best_connection()); |
2786 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 2864 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2787 | 2865 |
2788 // Add a low-priority connection |conn2|, which will be pruned, but it will | 2866 // Add a low-priority connection |conn2|, which will be pruned, but it will |
2789 // not be deleted right away. Once the current best connection becomes not | 2867 // not be deleted right away. Once the current best connection becomes not |
2790 // receiving, |conn2| will start to ping and upon receiving the ping response, | 2868 // receiving, |conn2| will start to ping and upon receiving the ping response, |
2791 // it will become the best connection. | 2869 // it will become the best connection. |
2792 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2870 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
2793 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2871 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2794 ASSERT_TRUE(conn2 != nullptr); | 2872 ASSERT_TRUE(conn2 != nullptr); |
2795 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2873 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
2796 // |conn2| should not send a ping yet. | 2874 // |conn2| should not send a ping yet. |
2797 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); | 2875 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); |
2798 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2876 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2799 // Wait for |conn1| becoming not receiving. | 2877 // Wait for |conn1| becoming not receiving. |
2800 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); | 2878 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); |
2801 // Make sure conn2 is not deleted. | 2879 // Make sure conn2 is not deleted. |
2802 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2880 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2803 ASSERT_TRUE(conn2 != nullptr); | 2881 ASSERT_TRUE(conn2 != nullptr); |
2804 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000); | 2882 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); |
2805 conn2->ReceivedPingResponse(LOW_RTT); | 2883 conn2->ReceivedPingResponse(LOW_RTT); |
2806 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000); | 2884 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000); |
2807 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2885 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); |
2808 | 2886 |
2809 // When |conn1| comes back again, |conn2| will be pruned again. | 2887 // When |conn1| comes back again, |conn2| will be pruned again. |
2810 conn1->ReceivedPingResponse(LOW_RTT); | 2888 conn1->ReceivedPingResponse(LOW_RTT); |
2811 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); | 2889 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); |
2812 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2890 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
2813 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2891 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2814 } | 2892 } |
2815 | 2893 |
2816 // Test that if all connections in a channel has timed out on writing, they | 2894 // Test that if all connections in a channel has timed out on writing, they |
2817 // will all be deleted. We use Prune to simulate write_time_out. | 2895 // will all be deleted. We use Prune to simulate write_time_out. |
2818 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 2896 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
2819 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2897 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2820 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2898 P2PTransportChannel ch("test channel", 1, &pa); |
2821 PrepareChannel(&ch); | 2899 PrepareChannel(&ch); |
2822 ch.Connect(); | 2900 ch.Connect(); |
2823 ch.MaybeStartGathering(); | 2901 ch.MaybeStartGathering(); |
2824 // Have one connection only but later becomes write-time-out. | 2902 // Have one connection only but later becomes write-time-out. |
2825 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2903 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
2826 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2904 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2827 ASSERT_TRUE(conn1 != nullptr); | 2905 ASSERT_TRUE(conn1 != nullptr); |
2828 conn1->ReceivedPing(); // Becomes receiving | 2906 conn1->ReceivedPing(); // Becomes receiving |
2829 conn1->Prune(); | 2907 conn1->Prune(); |
2830 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); | 2908 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
2831 | 2909 |
2832 // Have two connections but both become write-time-out later. | 2910 // Have two connections but both become write-time-out later. |
2833 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2911 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
2834 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2912 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2835 ASSERT_TRUE(conn2 != nullptr); | 2913 ASSERT_TRUE(conn2 != nullptr); |
2836 conn2->ReceivedPing(); // Becomes receiving | 2914 conn2->ReceivedPing(); // Becomes receiving |
2837 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 2)); | 2915 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 2)); |
2838 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2916 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2839 ASSERT_TRUE(conn3 != nullptr); | 2917 ASSERT_TRUE(conn3 != nullptr); |
2840 conn3->ReceivedPing(); // Becomes receiving | 2918 conn3->ReceivedPing(); // Becomes receiving |
2841 // Now prune both conn2 and conn3; they will be deleted soon. | 2919 // Now prune both conn2 and conn3; they will be deleted soon. |
2842 conn2->Prune(); | 2920 conn2->Prune(); |
2843 conn3->Prune(); | 2921 conn3->Prune(); |
2844 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); | 2922 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
2845 } | 2923 } |
2846 | 2924 |
2847 // Tests that after a port allocator session is started, it will be stopped | 2925 // Tests that after a port allocator session is started, it will be stopped |
2848 // when a new connection becomes writable and receiving. Also tests that if a | 2926 // when a new connection becomes writable and receiving. Also tests that if a |
2849 // connection belonging to an old session becomes writable, it won't stop | 2927 // connection belonging to an old session becomes writable, it won't stop |
2850 // the current port allocator session. | 2928 // the current port allocator session. |
2851 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { | 2929 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
2852 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2930 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2853 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2931 P2PTransportChannel ch("test channel", 1, &pa); |
2854 PrepareChannel(&ch); | 2932 PrepareChannel(&ch); |
2855 ch.SetIceConfig(CreateIceConfig(2000, false)); | 2933 ch.SetIceConfig(CreateIceConfig(2000, false)); |
2856 ch.Connect(); | 2934 ch.Connect(); |
2857 ch.MaybeStartGathering(); | 2935 ch.MaybeStartGathering(); |
2858 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2936 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
2859 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2937 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2860 ASSERT_TRUE(conn1 != nullptr); | 2938 ASSERT_TRUE(conn1 != nullptr); |
2861 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 2939 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2862 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2940 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2863 | 2941 |
2864 // Start a new session. Even though conn1, which belongs to an older | 2942 // Start a new session. Even though conn1, which belongs to an older |
2865 // session, becomes unwritable and writable again, it should not stop the | 2943 // session, becomes unwritable and writable again, it should not stop the |
2866 // current session. | 2944 // current session. |
2867 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2945 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2868 ch.MaybeStartGathering(); | 2946 ch.MaybeStartGathering(); |
2869 conn1->Prune(); | 2947 conn1->Prune(); |
2870 conn1->ReceivedPingResponse(LOW_RTT); | 2948 conn1->ReceivedPingResponse(LOW_RTT); |
2871 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); | 2949 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); |
2872 | 2950 |
2873 // But if a new connection created from the new session becomes writable, | 2951 // But if a new connection created from the new session becomes writable, |
2874 // it will stop the current session. | 2952 // it will stop the current session. |
2875 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100)); | 2953 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); |
2876 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2954 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2877 ASSERT_TRUE(conn2 != nullptr); | 2955 ASSERT_TRUE(conn2 != nullptr); |
2878 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 2956 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2879 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2957 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2880 } | 2958 } |
2881 | 2959 |
2882 // Test that the ICE role is updated even on ports with inactive networks when | 2960 // Test that the ICE role is updated even on ports with inactive networks when |
2883 // doing continual gathering. These ports may still have connections that need | 2961 // doing continual gathering. These ports may still have connections that need |
2884 // a correct role, in case the network becomes active before the connection is | 2962 // a correct role, in case the network becomes active before the connection is |
2885 // destroyed. | 2963 // destroyed. |
2886 TEST_F(P2PTransportChannelPingTest, | 2964 TEST_F(P2PTransportChannelPingTest, |
2887 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) { | 2965 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) { |
2888 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2966 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2889 cricket::P2PTransportChannel ch( | 2967 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); |
2890 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); | |
2891 // Starts with ICEROLE_CONTROLLING. | 2968 // Starts with ICEROLE_CONTROLLING. |
2892 PrepareChannel(&ch); | 2969 PrepareChannel(&ch); |
2893 cricket::IceConfig config = CreateIceConfig(1000, true); | 2970 IceConfig config = CreateIceConfig(1000, true); |
2894 ch.SetIceConfig(config); | 2971 ch.SetIceConfig(config); |
2895 ch.Connect(); | 2972 ch.Connect(); |
2896 ch.MaybeStartGathering(); | 2973 ch.MaybeStartGathering(); |
2897 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2974 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2898 | 2975 |
2899 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2976 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2900 ASSERT_TRUE(conn != nullptr); | 2977 ASSERT_TRUE(conn != nullptr); |
2901 | 2978 |
2902 // Make the fake port signal that its network is inactive, then change the | 2979 // Make the fake port signal that its network is inactive, then change the |
2903 // ICE role and expect it to be updated. | 2980 // ICE role and expect it to be updated. |
2904 conn->port()->SignalNetworkInactive(conn->port()); | 2981 conn->port()->SignalNetworkInactive(conn->port()); |
2905 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2982 ch.SetIceRole(ICEROLE_CONTROLLED); |
2906 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole()); | 2983 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); |
2907 } | 2984 } |
2908 | 2985 |
2909 // Test that the ICE role is updated even on ports with inactive networks. | 2986 // Test that the ICE role is updated even on ports with inactive networks. |
2910 // These ports may still have connections that need a correct role, for the | 2987 // These ports may still have connections that need a correct role, for the |
2911 // pings sent by those connections until they're replaced by newer-generation | 2988 // pings sent by those connections until they're replaced by newer-generation |
2912 // connections. | 2989 // connections. |
2913 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { | 2990 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { |
2914 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2991 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2915 cricket::P2PTransportChannel ch( | 2992 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); |
2916 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); | |
2917 // Starts with ICEROLE_CONTROLLING. | 2993 // Starts with ICEROLE_CONTROLLING. |
2918 PrepareChannel(&ch); | 2994 PrepareChannel(&ch); |
2919 ch.Connect(); | 2995 ch.Connect(); |
2920 ch.MaybeStartGathering(); | 2996 ch.MaybeStartGathering(); |
2921 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2997 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2922 | 2998 |
2923 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2999 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2924 ASSERT_TRUE(conn != nullptr); | 3000 ASSERT_TRUE(conn != nullptr); |
2925 | 3001 |
2926 // Do an ICE restart, change the role, and expect the old port to have its | 3002 // Do an ICE restart, change the role, and expect the old port to have its |
2927 // role updated. | 3003 // role updated. |
2928 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 3004 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2929 ch.MaybeStartGathering(); | 3005 ch.MaybeStartGathering(); |
2930 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 3006 ch.SetIceRole(ICEROLE_CONTROLLED); |
2931 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole()); | 3007 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); |
2932 } | 3008 } |
2933 | 3009 |
2934 // Test that after some amount of time without receiving data, the connection | 3010 // Test that after some amount of time without receiving data, the connection |
2935 // and port are destroyed. | 3011 // and port are destroyed. |
2936 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) { | 3012 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) { |
2937 rtc::ScopedFakeClock fake_clock; | 3013 rtc::ScopedFakeClock fake_clock; |
2938 | 3014 |
2939 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3015 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2940 cricket::P2PTransportChannel ch( | 3016 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); |
2941 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); | |
2942 PrepareChannel(&ch); | 3017 PrepareChannel(&ch); |
2943 // Only a controlled channel should expect its ports to be destroyed. | 3018 // Only a controlled channel should expect its ports to be destroyed. |
2944 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 3019 ch.SetIceRole(ICEROLE_CONTROLLED); |
2945 ch.Connect(); | 3020 ch.Connect(); |
2946 ch.MaybeStartGathering(); | 3021 ch.MaybeStartGathering(); |
2947 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 3022 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2948 | 3023 |
2949 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3024 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2950 ASSERT_TRUE(conn != nullptr); | 3025 ASSERT_TRUE(conn != nullptr); |
2951 | 3026 |
2952 // Simulate 2 minutes going by. This should be enough time for the port to | 3027 // Simulate 2 minutes going by. This should be enough time for the port to |
2953 // time out. | 3028 // time out. |
2954 for (int second = 0; second < 120; ++second) { | 3029 for (int second = 0; second < 120; ++second) { |
2955 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); | 3030 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); |
2956 } | 3031 } |
2957 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1)); | 3032 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1)); |
2958 EXPECT_EQ(nullptr, GetPort(&ch)); | 3033 EXPECT_EQ(nullptr, GetPort(&ch)); |
2959 } | 3034 } |
2960 | 3035 |
2961 class P2PTransportChannelMostLikelyToWorkFirstTest | 3036 class P2PTransportChannelMostLikelyToWorkFirstTest |
2962 : public P2PTransportChannelPingTest { | 3037 : public P2PTransportChannelPingTest { |
2963 public: | 3038 public: |
2964 P2PTransportChannelMostLikelyToWorkFirstTest() | 3039 P2PTransportChannelMostLikelyToWorkFirstTest() |
2965 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { | 3040 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { |
2966 network_manager_.AddInterface(kPublicAddrs[0]); | 3041 network_manager_.AddInterface(kPublicAddrs[0]); |
2967 allocator_.reset(new cricket::BasicPortAllocator( | 3042 allocator_.reset(new BasicPortAllocator( |
2968 &network_manager_, ServerAddresses(), rtc::SocketAddress(), | 3043 &network_manager_, ServerAddresses(), rtc::SocketAddress(), |
2969 rtc::SocketAddress(), rtc::SocketAddress())); | 3044 rtc::SocketAddress(), rtc::SocketAddress())); |
2970 allocator_->set_flags(allocator_->flags() | | 3045 allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN | |
2971 cricket::PORTALLOCATOR_DISABLE_STUN | | 3046 PORTALLOCATOR_DISABLE_TCP); |
2972 cricket::PORTALLOCATOR_DISABLE_TCP); | 3047 RelayServerConfig config(RELAY_TURN); |
2973 cricket::RelayServerConfig config(cricket::RELAY_TURN); | |
2974 config.credentials = kRelayCredentials; | 3048 config.credentials = kRelayCredentials; |
2975 config.ports.push_back( | 3049 config.ports.push_back(ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false)); |
2976 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); | |
2977 allocator_->AddTurnServer(config); | 3050 allocator_->AddTurnServer(config); |
2978 allocator_->set_step_delay(kMinimumStepDelay); | 3051 allocator_->set_step_delay(kMinimumStepDelay); |
2979 } | 3052 } |
2980 | 3053 |
2981 cricket::P2PTransportChannel& StartTransportChannel( | 3054 P2PTransportChannel& StartTransportChannel( |
2982 bool prioritize_most_likely_to_work, | 3055 bool prioritize_most_likely_to_work, |
2983 int stable_writable_connection_ping_interval) { | 3056 int stable_writable_connection_ping_interval) { |
2984 channel_.reset( | 3057 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator())); |
2985 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator())); | 3058 IceConfig config = channel_->config(); |
2986 cricket::IceConfig config = channel_->config(); | |
2987 config.prioritize_most_likely_candidate_pairs = | 3059 config.prioritize_most_likely_candidate_pairs = |
2988 prioritize_most_likely_to_work; | 3060 prioritize_most_likely_to_work; |
2989 config.stable_writable_connection_ping_interval = | 3061 config.stable_writable_connection_ping_interval = |
2990 stable_writable_connection_ping_interval; | 3062 stable_writable_connection_ping_interval; |
2991 channel_->SetIceConfig(config); | 3063 channel_->SetIceConfig(config); |
2992 PrepareChannel(channel_.get()); | 3064 PrepareChannel(channel_.get()); |
2993 channel_->Connect(); | 3065 channel_->Connect(); |
2994 channel_->MaybeStartGathering(); | 3066 channel_->MaybeStartGathering(); |
2995 return *channel_.get(); | 3067 return *channel_.get(); |
2996 } | 3068 } |
2997 | 3069 |
2998 cricket::BasicPortAllocator* allocator() { return allocator_.get(); } | 3070 BasicPortAllocator* allocator() { return allocator_.get(); } |
2999 cricket::TestTurnServer* turn_server() { return &turn_server_; } | 3071 TestTurnServer* turn_server() { return &turn_server_; } |
3000 | 3072 |
3001 // This verifies the next pingable connection has the expected candidates' | 3073 // This verifies the next pingable connection has the expected candidates' |
3002 // types and, for relay local candidate, the expected relay protocol and ping | 3074 // types and, for relay local candidate, the expected relay protocol and ping |
3003 // it. | 3075 // it. |
3004 void VerifyNextPingableConnection( | 3076 void VerifyNextPingableConnection( |
3005 const std::string& local_candidate_type, | 3077 const std::string& local_candidate_type, |
3006 const std::string& remote_candidate_type, | 3078 const std::string& remote_candidate_type, |
3007 const std::string& relay_protocol_type = cricket::UDP_PROTOCOL_NAME) { | 3079 const std::string& relay_protocol_type = UDP_PROTOCOL_NAME) { |
3008 cricket::Connection* conn = | 3080 Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get()); |
3009 FindNextPingableConnectionAndPingIt(channel_.get()); | |
3010 EXPECT_EQ(conn->local_candidate().type(), local_candidate_type); | 3081 EXPECT_EQ(conn->local_candidate().type(), local_candidate_type); |
3011 if (conn->local_candidate().type() == cricket::RELAY_PORT_TYPE) { | 3082 if (conn->local_candidate().type() == RELAY_PORT_TYPE) { |
3012 EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type); | 3083 EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type); |
3013 } | 3084 } |
3014 EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type); | 3085 EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type); |
3015 } | 3086 } |
3016 | 3087 |
3017 cricket::Candidate CreateRelayCandidate(const std::string& ip, | |
3018 int port, | |
3019 int priority, | |
3020 const std::string& ufrag = "") { | |
3021 cricket::Candidate c = CreateHostCandidate(ip, port, priority, ufrag); | |
3022 c.set_type(cricket::RELAY_PORT_TYPE); | |
3023 return c; | |
3024 } | |
3025 | |
3026 private: | 3088 private: |
3027 std::unique_ptr<cricket::BasicPortAllocator> allocator_; | 3089 std::unique_ptr<BasicPortAllocator> allocator_; |
3028 rtc::FakeNetworkManager network_manager_; | 3090 rtc::FakeNetworkManager network_manager_; |
3029 cricket::TestTurnServer turn_server_; | 3091 TestTurnServer turn_server_; |
3030 std::unique_ptr<cricket::P2PTransportChannel> channel_; | 3092 std::unique_ptr<P2PTransportChannel> channel_; |
3031 }; | 3093 }; |
3032 | 3094 |
3033 // Test that Relay/Relay connections will be pinged first when no other | 3095 // Test that Relay/Relay connections will be pinged first when no other |
3034 // connections have been pinged yet, unless we need to ping a trigger check or | 3096 // connections have been pinged yet, unless we need to ping a trigger check or |
3035 // we have a best connection. | 3097 // we have a best connection. |
3036 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, | 3098 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
3037 TestRelayRelayFirstWhenNothingPingedYet) { | 3099 TestRelayRelayFirstWhenNothingPingedYet) { |
3038 const int max_strong_interval = 100; | 3100 const int max_strong_interval = 100; |
3039 cricket::P2PTransportChannel& ch = | 3101 P2PTransportChannel& ch = StartTransportChannel(true, max_strong_interval); |
3040 StartTransportChannel(true, max_strong_interval); | |
3041 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); | 3102 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
3042 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); | 3103 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); |
3043 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); | 3104 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); |
3044 | 3105 |
3045 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); | 3106 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); |
3046 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 3107 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
3047 | 3108 |
3048 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); | 3109 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
3049 | 3110 |
3050 // Relay/Relay should be the first pingable connection. | 3111 // Relay/Relay should be the first pingable connection. |
3051 cricket::Connection* conn = FindNextPingableConnectionAndPingIt(&ch); | 3112 Connection* conn = FindNextPingableConnectionAndPingIt(&ch); |
3052 EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE); | 3113 EXPECT_EQ(conn->local_candidate().type(), RELAY_PORT_TYPE); |
3053 EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE); | 3114 EXPECT_EQ(conn->remote_candidate().type(), RELAY_PORT_TYPE); |
3054 | 3115 |
3055 // Unless that we have a trigger check waiting to be pinged. | 3116 // Unless that we have a trigger check waiting to be pinged. |
3056 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3117 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3057 EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE); | 3118 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); |
3058 EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE); | 3119 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); |
3059 conn2->ReceivedPing(); | 3120 conn2->ReceivedPing(); |
3060 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 3121 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
3061 | 3122 |
3062 // Make conn3 the best connection. | 3123 // Make conn3 the best connection. |
3063 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3124 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3064 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); | 3125 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE); |
3065 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); | 3126 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE); |
3066 conn3->ReceivedPingResponse(LOW_RTT); | 3127 conn3->ReceivedPingResponse(LOW_RTT); |
3067 ASSERT_TRUE(conn3->writable()); | 3128 ASSERT_TRUE(conn3->writable()); |
3068 conn3->ReceivedPing(); | 3129 conn3->ReceivedPing(); |
3069 | 3130 |
3070 /* | 3131 /* |
3071 | 3132 |
3072 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix | 3133 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix |
3073 the flakiness. The following test becomes flaky because we now ping the | 3134 the flakiness. The following test becomes flaky because we now ping the |
3074 connections with fast rates until every connection is pinged at least three | 3135 connections with fast rates until every connection is pinged at least three |
3075 times. The best connection may have been pinged before |max_strong_interval|, | 3136 times. The best connection may have been pinged before |max_strong_interval|, |
3076 so it may not be the next connection to be pinged as expected in the test. | 3137 so it may not be the next connection to be pinged as expected in the test. |
3077 | 3138 |
3078 // Verify that conn3 will be the "best connection" since it is readable and | 3139 // Verify that conn3 will be the "best connection" since it is readable and |
3079 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next | 3140 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next |
3080 // pingable connection. | 3141 // pingable connection. |
3081 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); | 3142 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); |
3082 WAIT(false, max_strong_interval + 100); | 3143 WAIT(false, max_strong_interval + 100); |
3083 conn3->ReceivedPingResponse(LOW_RTT); | 3144 conn3->ReceivedPingResponse(LOW_RTT); |
3084 ASSERT_TRUE(conn3->writable()); | 3145 ASSERT_TRUE(conn3->writable()); |
3085 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); | 3146 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); |
3086 | 3147 |
3087 */ | 3148 */ |
3088 } | 3149 } |
3089 | 3150 |
3090 // Test that Relay/Relay connections will be pinged first when everything has | 3151 // Test that Relay/Relay connections will be pinged first when everything has |
3091 // been pinged even if the Relay/Relay connection wasn't the first to be pinged | 3152 // been pinged even if the Relay/Relay connection wasn't the first to be pinged |
3092 // in the first round. | 3153 // in the first round. |
3093 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, | 3154 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
3094 TestRelayRelayFirstWhenEverythingPinged) { | 3155 TestRelayRelayFirstWhenEverythingPinged) { |
3095 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100); | 3156 P2PTransportChannel& ch = StartTransportChannel(true, 100); |
3096 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); | 3157 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
3097 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); | 3158 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); |
3098 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); | 3159 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); |
3099 | 3160 |
3100 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 3161 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
3101 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); | 3162 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); |
3102 | 3163 |
3103 // Initially, only have Local/Local and Local/Relay. | 3164 // Initially, only have Local/Local and Local/Relay. |
3104 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 3165 VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE); |
3105 cricket::LOCAL_PORT_TYPE); | 3166 VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE); |
3106 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | |
3107 cricket::LOCAL_PORT_TYPE); | |
3108 | 3167 |
3109 // Remote Relay candidate arrives. | 3168 // Remote Relay candidate arrives. |
3110 ch.AddRemoteCandidate(CreateRelayCandidate("2.2.2.2", 2, 2)); | 3169 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 2)); |
3111 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); | 3170 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
3112 | 3171 |
3113 // Relay/Relay should be the first since it hasn't been pinged before. | 3172 // Relay/Relay should be the first since it hasn't been pinged before. |
3114 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3173 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); |
3115 cricket::RELAY_PORT_TYPE); | |
3116 | 3174 |
3117 // Local/Relay is the final one. | 3175 // Local/Relay is the final one. |
3118 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 3176 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3119 cricket::RELAY_PORT_TYPE); | |
3120 | 3177 |
3121 // Now, every connection has been pinged once. The next one should be | 3178 // Now, every connection has been pinged once. The next one should be |
3122 // Relay/Relay. | 3179 // Relay/Relay. |
3123 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3180 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); |
3124 cricket::RELAY_PORT_TYPE); | |
3125 } | 3181 } |
3126 | 3182 |
3127 // Test that when we receive a new remote candidate, they will be tried first | 3183 // Test that when we receive a new remote candidate, they will be tried first |
3128 // before we re-ping Relay/Relay connections again. | 3184 // before we re-ping Relay/Relay connections again. |
3129 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, | 3185 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
3130 TestNoStarvationOnNonRelayConnection) { | 3186 TestNoStarvationOnNonRelayConnection) { |
3131 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100); | 3187 P2PTransportChannel& ch = StartTransportChannel(true, 100); |
3132 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); | 3188 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
3133 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); | 3189 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); |
3134 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); | 3190 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); |
3135 | 3191 |
3136 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); | 3192 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); |
3137 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); | 3193 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); |
3138 | 3194 |
3139 // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first. | 3195 // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first. |
3140 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3196 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); |
3141 cricket::RELAY_PORT_TYPE); | |
3142 | 3197 |
3143 // Next, ping Local/Relay. | 3198 // Next, ping Local/Relay. |
3144 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 3199 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3145 cricket::RELAY_PORT_TYPE); | |
3146 | 3200 |
3147 // Remote Local candidate arrives. | 3201 // Remote Local candidate arrives. |
3148 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 3202 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
3149 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); | 3203 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
3150 | 3204 |
3151 // Local/Local should be the first since it hasn't been pinged before. | 3205 // Local/Local should be the first since it hasn't been pinged before. |
3152 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 3206 VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE); |
3153 cricket::LOCAL_PORT_TYPE); | |
3154 | 3207 |
3155 // Relay/Local is the final one. | 3208 // Relay/Local is the final one. |
3156 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3209 VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE); |
3157 cricket::LOCAL_PORT_TYPE); | |
3158 | 3210 |
3159 // Now, every connection has been pinged once. The next one should be | 3211 // Now, every connection has been pinged once. The next one should be |
3160 // Relay/Relay. | 3212 // Relay/Relay. |
3161 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3213 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); |
3162 cricket::RELAY_PORT_TYPE); | |
3163 } | 3214 } |
3164 | 3215 |
3165 // Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay, | 3216 // Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay, |
3166 // followed by the rest. | 3217 // followed by the rest. |
3167 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) { | 3218 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) { |
3168 // Add a Tcp Turn server. | 3219 // Add a Tcp Turn server. |
3169 turn_server()->AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 3220 turn_server()->AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
3170 cricket::RelayServerConfig config(cricket::RELAY_TURN); | 3221 RelayServerConfig config(RELAY_TURN); |
3171 config.credentials = kRelayCredentials; | 3222 config.credentials = kRelayCredentials; |
3172 config.ports.push_back( | 3223 config.ports.push_back(ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false)); |
3173 cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false)); | |
3174 allocator()->AddTurnServer(config); | 3224 allocator()->AddTurnServer(config); |
3175 | 3225 |
3176 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100); | 3226 P2PTransportChannel& ch = StartTransportChannel(true, 100); |
3177 EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000); | 3227 EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000); |
3178 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); | 3228 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); |
3179 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); | 3229 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); |
3180 EXPECT_EQ(ch.ports()[2]->Type(), cricket::RELAY_PORT_TYPE); | 3230 EXPECT_EQ(ch.ports()[2]->Type(), RELAY_PORT_TYPE); |
3181 | 3231 |
3182 // Remote Relay candidate arrives. | 3232 // Remote Relay candidate arrives. |
3183 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); | 3233 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); |
3184 EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000); | 3234 EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000); |
3185 | 3235 |
3186 // UDP Relay/Relay should be pinged first. | 3236 // UDP Relay/Relay should be pinged first. |
3187 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3237 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); |
3188 cricket::RELAY_PORT_TYPE); | |
3189 | 3238 |
3190 // TCP Relay/Relay is the next. | 3239 // TCP Relay/Relay is the next. |
3191 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3240 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
3192 cricket::RELAY_PORT_TYPE, | 3241 TCP_PROTOCOL_NAME); |
3193 cricket::TCP_PROTOCOL_NAME); | |
3194 | 3242 |
3195 // Finally, Local/Relay will be pinged. | 3243 // Finally, Local/Relay will be pinged. |
3196 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 3244 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3197 cricket::RELAY_PORT_TYPE); | |
3198 } | 3245 } |
| 3246 |
| 3247 } // namespace cricket { |
OLD | NEW |