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