| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | 57 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); |
| 58 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); | 58 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); |
| 59 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", STUN_SERVER_PORT); | 59 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", STUN_SERVER_PORT); |
| 60 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); | 60 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); |
| 61 static const RelayCredentials kRelayCredentials("test", "test"); | 61 static const RelayCredentials kRelayCredentials("test", "test"); |
| 62 | 62 |
| 63 // TODO: Update these when RFC5245 is completely supported. | 63 // TODO: Update these when RFC5245 is completely supported. |
| 64 // Magic value of 30 is from RFC3484, for IPv4 addresses. | 64 // Magic value of 30 is from RFC3484, for IPv4 addresses. |
| 65 static const uint32 kDefaultPrflxPriority = ICE_TYPE_PREFERENCE_PRFLX << 24 | | 65 static const uint32 kDefaultPrflxPriority = ICE_TYPE_PREFERENCE_PRFLX << 24 | |
| 66 30 << 8 | (256 - ICE_CANDIDATE_COMPONENT_DEFAULT); | 66 30 << 8 | (256 - ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 67 static const int STUN_ERROR_BAD_REQUEST_AS_GICE = |
| 68 STUN_ERROR_BAD_REQUEST / 256 * 100 + STUN_ERROR_BAD_REQUEST % 256; |
| 69 static const int STUN_ERROR_UNAUTHORIZED_AS_GICE = |
| 70 STUN_ERROR_UNAUTHORIZED / 256 * 100 + STUN_ERROR_UNAUTHORIZED % 256; |
| 71 static const int STUN_ERROR_SERVER_ERROR_AS_GICE = |
| 72 STUN_ERROR_SERVER_ERROR / 256 * 100 + STUN_ERROR_SERVER_ERROR % 256; |
| 67 | 73 |
| 68 static const int kTiebreaker1 = 11111; | 74 static const int kTiebreaker1 = 11111; |
| 69 static const int kTiebreaker2 = 22222; | 75 static const int kTiebreaker2 = 22222; |
| 70 | 76 |
| 71 static const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; | 77 static const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; |
| 72 | 78 |
| 73 static Candidate GetCandidate(Port* port) { | 79 static Candidate GetCandidate(Port* port) { |
| 74 assert(port->Candidates().size() >= 1); | 80 assert(port->Candidates().size() == 1); |
| 75 return port->Candidates()[0]; | 81 return port->Candidates()[0]; |
| 76 } | 82 } |
| 77 | 83 |
| 78 static SocketAddress GetAddress(Port* port) { | 84 static SocketAddress GetAddress(Port* port) { |
| 79 return GetCandidate(port).address(); | 85 return GetCandidate(port).address(); |
| 80 } | 86 } |
| 81 | 87 |
| 82 static IceMessage* CopyStunMessage(const IceMessage* src) { | 88 static IceMessage* CopyStunMessage(const IceMessage* src) { |
| 83 IceMessage* dst = new IceMessage(); | 89 IceMessage* dst = new IceMessage(); |
| 84 ByteBuffer buf; | 90 ByteBuffer buf; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 277 } |
| 272 | 278 |
| 273 void OnUnknownAddress(PortInterface* port, const SocketAddress& addr, | 279 void OnUnknownAddress(PortInterface* port, const SocketAddress& addr, |
| 274 ProtocolType proto, | 280 ProtocolType proto, |
| 275 IceMessage* msg, const std::string& rf, | 281 IceMessage* msg, const std::string& rf, |
| 276 bool /*port_muxed*/) { | 282 bool /*port_muxed*/) { |
| 277 ASSERT_EQ(port_.get(), port); | 283 ASSERT_EQ(port_.get(), port); |
| 278 if (!remote_address_.IsNil()) { | 284 if (!remote_address_.IsNil()) { |
| 279 ASSERT_EQ(remote_address_, addr); | 285 ASSERT_EQ(remote_address_, addr); |
| 280 } | 286 } |
| 287 // MI and PRIORITY attribute should be present in ping requests when port |
| 288 // is in ICEPROTO_RFC5245 mode. |
| 281 const cricket::StunUInt32Attribute* priority_attr = | 289 const cricket::StunUInt32Attribute* priority_attr = |
| 282 msg->GetUInt32(STUN_ATTR_PRIORITY); | 290 msg->GetUInt32(STUN_ATTR_PRIORITY); |
| 283 const cricket::StunByteStringAttribute* mi_attr = | 291 const cricket::StunByteStringAttribute* mi_attr = |
| 284 msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); | 292 msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); |
| 285 const cricket::StunUInt32Attribute* fingerprint_attr = | 293 const cricket::StunUInt32Attribute* fingerprint_attr = |
| 286 msg->GetUInt32(STUN_ATTR_FINGERPRINT); | 294 msg->GetUInt32(STUN_ATTR_FINGERPRINT); |
| 287 EXPECT_TRUE(priority_attr != NULL); | 295 if (port_->IceProtocol() == cricket::ICEPROTO_RFC5245) { |
| 288 EXPECT_TRUE(mi_attr != NULL); | 296 EXPECT_TRUE(priority_attr != NULL); |
| 289 EXPECT_TRUE(fingerprint_attr != NULL); | 297 EXPECT_TRUE(mi_attr != NULL); |
| 298 EXPECT_TRUE(fingerprint_attr != NULL); |
| 299 } else { |
| 300 EXPECT_TRUE(priority_attr == NULL); |
| 301 EXPECT_TRUE(mi_attr == NULL); |
| 302 EXPECT_TRUE(fingerprint_attr == NULL); |
| 303 } |
| 290 remote_address_ = addr; | 304 remote_address_ = addr; |
| 291 remote_request_.reset(CopyStunMessage(msg)); | 305 remote_request_.reset(CopyStunMessage(msg)); |
| 292 remote_frag_ = rf; | 306 remote_frag_ = rf; |
| 293 } | 307 } |
| 294 | 308 |
| 295 void OnDestroyed(Connection* conn) { | 309 void OnDestroyed(Connection* conn) { |
| 296 ASSERT_EQ(conn_, conn); | 310 ASSERT_EQ(conn_, conn); |
| 297 LOG(INFO) << "OnDestroy connection " << conn << " deleted"; | 311 LOG(INFO) << "OnDestroy connection " << conn << " deleted"; |
| 298 conn_ = NULL; | 312 conn_ = NULL; |
| 299 // When the connection is destroyed, also clear these fields so future | 313 // When the connection is destroyed, also clear these fields so future |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), | 368 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), |
| 355 relay_server_(main_, | 369 relay_server_(main_, |
| 356 kRelayUdpIntAddr, | 370 kRelayUdpIntAddr, |
| 357 kRelayUdpExtAddr, | 371 kRelayUdpExtAddr, |
| 358 kRelayTcpIntAddr, | 372 kRelayTcpIntAddr, |
| 359 kRelayTcpExtAddr, | 373 kRelayTcpExtAddr, |
| 360 kRelaySslTcpIntAddr, | 374 kRelaySslTcpIntAddr, |
| 361 kRelaySslTcpExtAddr), | 375 kRelaySslTcpExtAddr), |
| 362 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), | 376 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), |
| 363 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), | 377 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), |
| 378 ice_protocol_(cricket::ICEPROTO_GOOGLE), |
| 364 role_conflict_(false), | 379 role_conflict_(false), |
| 365 destroyed_(false) { | 380 destroyed_(false) { |
| 366 network_.AddIP(rtc::IPAddress(INADDR_ANY)); | 381 network_.AddIP(rtc::IPAddress(INADDR_ANY)); |
| 367 } | 382 } |
| 368 | 383 |
| 369 protected: | 384 protected: |
| 370 void TestLocalToLocal() { | 385 void TestLocalToLocal() { |
| 371 Port* port1 = CreateUdpPort(kLocalAddr1); | 386 Port* port1 = CreateUdpPort(kLocalAddr1); |
| 372 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 373 Port* port2 = CreateUdpPort(kLocalAddr2); | 387 Port* port2 = CreateUdpPort(kLocalAddr2); |
| 374 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 375 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); | 388 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); |
| 376 } | 389 } |
| 377 void TestLocalToStun(NATType ntype) { | 390 void TestLocalToStun(NATType ntype) { |
| 378 Port* port1 = CreateUdpPort(kLocalAddr1); | 391 Port* port1 = CreateUdpPort(kLocalAddr1); |
| 379 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 380 nat_server2_.reset(CreateNatServer(kNatAddr2, ntype)); | 392 nat_server2_.reset(CreateNatServer(kNatAddr2, ntype)); |
| 381 Port* port2 = CreateStunPort(kLocalAddr2, &nat_socket_factory2_); | 393 Port* port2 = CreateStunPort(kLocalAddr2, &nat_socket_factory2_); |
| 382 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 383 TestConnectivity("udp", port1, StunName(ntype), port2, | 394 TestConnectivity("udp", port1, StunName(ntype), port2, |
| 384 ntype == NAT_OPEN_CONE, true, | 395 ntype == NAT_OPEN_CONE, true, |
| 385 ntype != NAT_SYMMETRIC, true); | 396 ntype != NAT_SYMMETRIC, true); |
| 386 } | 397 } |
| 387 void TestLocalToRelay(RelayType rtype, ProtocolType proto) { | 398 void TestLocalToRelay(RelayType rtype, ProtocolType proto) { |
| 388 Port* port1 = CreateUdpPort(kLocalAddr1); | 399 Port* port1 = CreateUdpPort(kLocalAddr1); |
| 389 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 390 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_UDP); | 400 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_UDP); |
| 391 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 392 TestConnectivity("udp", port1, RelayName(rtype, proto), port2, | 401 TestConnectivity("udp", port1, RelayName(rtype, proto), port2, |
| 393 rtype == RELAY_GTURN, true, true, true); | 402 rtype == RELAY_GTURN, true, true, true); |
| 394 } | 403 } |
| 395 void TestStunToLocal(NATType ntype) { | 404 void TestStunToLocal(NATType ntype) { |
| 396 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype)); | 405 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype)); |
| 397 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); | 406 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); |
| 398 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 399 Port* port2 = CreateUdpPort(kLocalAddr2); | 407 Port* port2 = CreateUdpPort(kLocalAddr2); |
| 400 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 401 TestConnectivity(StunName(ntype), port1, "udp", port2, | 408 TestConnectivity(StunName(ntype), port1, "udp", port2, |
| 402 true, ntype != NAT_SYMMETRIC, true, true); | 409 true, ntype != NAT_SYMMETRIC, true, true); |
| 403 } | 410 } |
| 404 void TestStunToStun(NATType ntype1, NATType ntype2) { | 411 void TestStunToStun(NATType ntype1, NATType ntype2) { |
| 405 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype1)); | 412 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype1)); |
| 406 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); | 413 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); |
| 407 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 408 nat_server2_.reset(CreateNatServer(kNatAddr2, ntype2)); | 414 nat_server2_.reset(CreateNatServer(kNatAddr2, ntype2)); |
| 409 Port* port2 = CreateStunPort(kLocalAddr2, &nat_socket_factory2_); | 415 Port* port2 = CreateStunPort(kLocalAddr2, &nat_socket_factory2_); |
| 410 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 411 TestConnectivity(StunName(ntype1), port1, StunName(ntype2), port2, | 416 TestConnectivity(StunName(ntype1), port1, StunName(ntype2), port2, |
| 412 ntype2 == NAT_OPEN_CONE, | 417 ntype2 == NAT_OPEN_CONE, |
| 413 ntype1 != NAT_SYMMETRIC, ntype2 != NAT_SYMMETRIC, | 418 ntype1 != NAT_SYMMETRIC, ntype2 != NAT_SYMMETRIC, |
| 414 ntype1 + ntype2 < (NAT_PORT_RESTRICTED + NAT_SYMMETRIC)); | 419 ntype1 + ntype2 < (NAT_PORT_RESTRICTED + NAT_SYMMETRIC)); |
| 415 } | 420 } |
| 416 void TestStunToRelay(NATType ntype, RelayType rtype, ProtocolType proto) { | 421 void TestStunToRelay(NATType ntype, RelayType rtype, ProtocolType proto) { |
| 417 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype)); | 422 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype)); |
| 418 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); | 423 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); |
| 419 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 420 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_UDP); | 424 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_UDP); |
| 421 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 422 TestConnectivity(StunName(ntype), port1, RelayName(rtype, proto), port2, | 425 TestConnectivity(StunName(ntype), port1, RelayName(rtype, proto), port2, |
| 423 rtype == RELAY_GTURN, ntype != NAT_SYMMETRIC, true, true); | 426 rtype == RELAY_GTURN, ntype != NAT_SYMMETRIC, true, true); |
| 424 } | 427 } |
| 425 void TestTcpToTcp() { | 428 void TestTcpToTcp() { |
| 426 Port* port1 = CreateTcpPort(kLocalAddr1); | 429 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 427 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 428 Port* port2 = CreateTcpPort(kLocalAddr2); | 430 Port* port2 = CreateTcpPort(kLocalAddr2); |
| 429 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 430 TestConnectivity("tcp", port1, "tcp", port2, true, false, true, true); | 431 TestConnectivity("tcp", port1, "tcp", port2, true, false, true, true); |
| 431 } | 432 } |
| 432 void TestTcpToRelay(RelayType rtype, ProtocolType proto) { | 433 void TestTcpToRelay(RelayType rtype, ProtocolType proto) { |
| 433 Port* port1 = CreateTcpPort(kLocalAddr1); | 434 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 434 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 435 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_TCP); | 435 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_TCP); |
| 436 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 437 TestConnectivity("tcp", port1, RelayName(rtype, proto), port2, | 436 TestConnectivity("tcp", port1, RelayName(rtype, proto), port2, |
| 438 rtype == RELAY_GTURN, false, true, true); | 437 rtype == RELAY_GTURN, false, true, true); |
| 439 } | 438 } |
| 440 void TestSslTcpToRelay(RelayType rtype, ProtocolType proto) { | 439 void TestSslTcpToRelay(RelayType rtype, ProtocolType proto) { |
| 441 Port* port1 = CreateTcpPort(kLocalAddr1); | 440 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 442 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 443 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_SSLTCP); | 441 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_SSLTCP); |
| 444 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 445 TestConnectivity("ssltcp", port1, RelayName(rtype, proto), port2, | 442 TestConnectivity("ssltcp", port1, RelayName(rtype, proto), port2, |
| 446 rtype == RELAY_GTURN, false, true, true); | 443 rtype == RELAY_GTURN, false, true, true); |
| 447 } | 444 } |
| 448 // helpers for above functions | 445 // helpers for above functions |
| 449 UDPPort* CreateUdpPort(const SocketAddress& addr) { | 446 UDPPort* CreateUdpPort(const SocketAddress& addr) { |
| 450 return CreateUdpPort(addr, &socket_factory_); | 447 return CreateUdpPort(addr, &socket_factory_); |
| 451 } | 448 } |
| 452 UDPPort* CreateUdpPort(const SocketAddress& addr, | 449 UDPPort* CreateUdpPort(const SocketAddress& addr, |
| 453 PacketSocketFactory* socket_factory) { | 450 PacketSocketFactory* socket_factory) { |
| 454 return UDPPort::Create(main_, socket_factory, &network_, | 451 UDPPort* port = UDPPort::Create(main_, socket_factory, &network_, |
| 455 addr.ipaddr(), 0, 0, username_, password_, | 452 addr.ipaddr(), 0, 0, username_, password_, |
| 456 std::string(), false); | 453 std::string(), false); |
| 454 port->SetIceProtocolType(ice_protocol_); |
| 455 return port; |
| 457 } | 456 } |
| 458 TCPPort* CreateTcpPort(const SocketAddress& addr) { | 457 TCPPort* CreateTcpPort(const SocketAddress& addr) { |
| 459 return CreateTcpPort(addr, &socket_factory_); | 458 TCPPort* port = CreateTcpPort(addr, &socket_factory_); |
| 459 port->SetIceProtocolType(ice_protocol_); |
| 460 return port; |
| 460 } | 461 } |
| 461 TCPPort* CreateTcpPort(const SocketAddress& addr, | 462 TCPPort* CreateTcpPort(const SocketAddress& addr, |
| 462 PacketSocketFactory* socket_factory) { | 463 PacketSocketFactory* socket_factory) { |
| 463 return TCPPort::Create(main_, socket_factory, &network_, | 464 TCPPort* port = TCPPort::Create(main_, socket_factory, &network_, |
| 464 addr.ipaddr(), 0, 0, username_, password_, | 465 addr.ipaddr(), 0, 0, username_, password_, |
| 465 true); | 466 true); |
| 467 port->SetIceProtocolType(ice_protocol_); |
| 468 return port; |
| 466 } | 469 } |
| 467 StunPort* CreateStunPort(const SocketAddress& addr, | 470 StunPort* CreateStunPort(const SocketAddress& addr, |
| 468 rtc::PacketSocketFactory* factory) { | 471 rtc::PacketSocketFactory* factory) { |
| 469 ServerAddresses stun_servers; | 472 ServerAddresses stun_servers; |
| 470 stun_servers.insert(kStunAddr); | 473 stun_servers.insert(kStunAddr); |
| 471 return StunPort::Create(main_, factory, &network_, | 474 StunPort* port = StunPort::Create(main_, factory, &network_, |
| 472 addr.ipaddr(), 0, 0, | 475 addr.ipaddr(), 0, 0, |
| 473 username_, password_, stun_servers, | 476 username_, password_, stun_servers, |
| 474 std::string()); | 477 std::string()); |
| 478 port->SetIceProtocolType(ice_protocol_); |
| 479 return port; |
| 475 } | 480 } |
| 476 Port* CreateRelayPort(const SocketAddress& addr, RelayType rtype, | 481 Port* CreateRelayPort(const SocketAddress& addr, RelayType rtype, |
| 477 ProtocolType int_proto, ProtocolType ext_proto) { | 482 ProtocolType int_proto, ProtocolType ext_proto) { |
| 478 if (rtype == RELAY_TURN) { | 483 if (rtype == RELAY_TURN) { |
| 479 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); | 484 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); |
| 480 } else { | 485 } else { |
| 481 return CreateGturnPort(addr, int_proto, ext_proto); | 486 return CreateGturnPort(addr, int_proto, ext_proto); |
| 482 } | 487 } |
| 483 } | 488 } |
| 484 TurnPort* CreateTurnPort(const SocketAddress& addr, | 489 TurnPort* CreateTurnPort(const SocketAddress& addr, |
| 485 PacketSocketFactory* socket_factory, | 490 PacketSocketFactory* socket_factory, |
| 486 ProtocolType int_proto, ProtocolType ext_proto) { | 491 ProtocolType int_proto, ProtocolType ext_proto) { |
| 487 return CreateTurnPort(addr, socket_factory, | 492 return CreateTurnPort(addr, socket_factory, |
| 488 int_proto, ext_proto, kTurnUdpIntAddr); | 493 int_proto, ext_proto, kTurnUdpIntAddr); |
| 489 } | 494 } |
| 490 TurnPort* CreateTurnPort(const SocketAddress& addr, | 495 TurnPort* CreateTurnPort(const SocketAddress& addr, |
| 491 PacketSocketFactory* socket_factory, | 496 PacketSocketFactory* socket_factory, |
| 492 ProtocolType int_proto, ProtocolType ext_proto, | 497 ProtocolType int_proto, ProtocolType ext_proto, |
| 493 const rtc::SocketAddress& server_addr) { | 498 const rtc::SocketAddress& server_addr) { |
| 494 return TurnPort::Create(main_, socket_factory, &network_, | 499 TurnPort* port = TurnPort::Create(main_, socket_factory, &network_, |
| 495 addr.ipaddr(), 0, 0, | 500 addr.ipaddr(), 0, 0, |
| 496 username_, password_, ProtocolAddress( | 501 username_, password_, ProtocolAddress( |
| 497 server_addr, PROTO_UDP), | 502 server_addr, PROTO_UDP), |
| 498 kRelayCredentials, 0, | 503 kRelayCredentials, 0, |
| 499 std::string()); | 504 std::string()); |
| 505 port->SetIceProtocolType(ice_protocol_); |
| 506 return port; |
| 500 } | 507 } |
| 501 RelayPort* CreateGturnPort(const SocketAddress& addr, | 508 RelayPort* CreateGturnPort(const SocketAddress& addr, |
| 502 ProtocolType int_proto, ProtocolType ext_proto) { | 509 ProtocolType int_proto, ProtocolType ext_proto) { |
| 503 RelayPort* port = CreateGturnPort(addr); | 510 RelayPort* port = CreateGturnPort(addr); |
| 504 SocketAddress addrs[] = | 511 SocketAddress addrs[] = |
| 505 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; | 512 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; |
| 506 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); | 513 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); |
| 507 return port; | 514 return port; |
| 508 } | 515 } |
| 509 RelayPort* CreateGturnPort(const SocketAddress& addr) { | 516 RelayPort* CreateGturnPort(const SocketAddress& addr) { |
| 510 // TODO(pthatcher): Remove GTURN. | 517 RelayPort* port = RelayPort::Create(main_, &socket_factory_, &network_, |
| 511 return RelayPort::Create(main_, &socket_factory_, &network_, | 518 addr.ipaddr(), 0, 0, |
| 512 addr.ipaddr(), 0, 0, | 519 username_, password_); |
| 513 username_, password_); | |
| 514 // TODO: Add an external address for ext_proto, so that the | 520 // TODO: Add an external address for ext_proto, so that the |
| 515 // other side can connect to this port using a non-UDP protocol. | 521 // other side can connect to this port using a non-UDP protocol. |
| 522 port->SetIceProtocolType(ice_protocol_); |
| 523 return port; |
| 516 } | 524 } |
| 517 rtc::NATServer* CreateNatServer(const SocketAddress& addr, | 525 rtc::NATServer* CreateNatServer(const SocketAddress& addr, |
| 518 rtc::NATType type) { | 526 rtc::NATType type) { |
| 519 return new rtc::NATServer(type, ss_.get(), addr, addr, ss_.get(), addr); | 527 return new rtc::NATServer(type, ss_.get(), addr, addr, ss_.get(), addr); |
| 520 } | 528 } |
| 521 static const char* StunName(NATType type) { | 529 static const char* StunName(NATType type) { |
| 522 switch (type) { | 530 switch (type) { |
| 523 case NAT_OPEN_CONE: return "stun(open cone)"; | 531 case NAT_OPEN_CONE: return "stun(open cone)"; |
| 524 case NAT_ADDR_RESTRICTED: return "stun(addr restricted)"; | 532 case NAT_ADDR_RESTRICTED: return "stun(addr restricted)"; |
| 525 case NAT_PORT_RESTRICTED: return "stun(port restricted)"; | 533 case NAT_PORT_RESTRICTED: return "stun(port restricted)"; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 | 616 |
| 609 // Speed up destroying ch2's connection such that the test is ready to | 617 // Speed up destroying ch2's connection such that the test is ready to |
| 610 // accept a new connection from ch1 before ch1's connection destroys itself. | 618 // accept a new connection from ch1 before ch1's connection destroys itself. |
| 611 ch2->conn()->Destroy(); | 619 ch2->conn()->Destroy(); |
| 612 EXPECT_TRUE_WAIT(ch2->conn() == NULL, kTimeout); | 620 EXPECT_TRUE_WAIT(ch2->conn() == NULL, kTimeout); |
| 613 } | 621 } |
| 614 | 622 |
| 615 void TestTcpReconnect(bool ping_after_disconnected, | 623 void TestTcpReconnect(bool ping_after_disconnected, |
| 616 bool send_after_disconnected) { | 624 bool send_after_disconnected) { |
| 617 Port* port1 = CreateTcpPort(kLocalAddr1); | 625 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 618 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 619 Port* port2 = CreateTcpPort(kLocalAddr2); | 626 Port* port2 = CreateTcpPort(kLocalAddr2); |
| 620 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 621 | 627 |
| 622 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 628 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 623 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 629 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 624 | 630 |
| 625 // Set up channels and ensure both ports will be deleted. | 631 // Set up channels and ensure both ports will be deleted. |
| 626 TestChannel ch1(port1); | 632 TestChannel ch1(port1); |
| 627 TestChannel ch2(port2); | 633 TestChannel ch2(port2); |
| 628 EXPECT_EQ(0, ch1.complete_count()); | 634 EXPECT_EQ(0, ch1.complete_count()); |
| 629 EXPECT_EQ(0, ch2.complete_count()); | 635 EXPECT_EQ(0, ch2.complete_count()); |
| 630 | 636 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 EXPECT_TRUE(!ch2.conn()); | 687 EXPECT_TRUE(!ch2.conn()); |
| 682 } | 688 } |
| 683 | 689 |
| 684 // Tear down and ensure that goes smoothly. | 690 // Tear down and ensure that goes smoothly. |
| 685 ch1.Stop(); | 691 ch1.Stop(); |
| 686 ch2.Stop(); | 692 ch2.Stop(); |
| 687 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); | 693 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); |
| 688 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); | 694 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); |
| 689 } | 695 } |
| 690 | 696 |
| 697 void SetIceProtocolType(cricket::IceProtocolType protocol) { |
| 698 ice_protocol_ = protocol; |
| 699 } |
| 700 |
| 691 IceMessage* CreateStunMessage(int type) { | 701 IceMessage* CreateStunMessage(int type) { |
| 692 IceMessage* msg = new IceMessage(); | 702 IceMessage* msg = new IceMessage(); |
| 693 msg->SetType(type); | 703 msg->SetType(type); |
| 694 msg->SetTransactionID("TESTTESTTEST"); | 704 msg->SetTransactionID("TESTTESTTEST"); |
| 695 return msg; | 705 return msg; |
| 696 } | 706 } |
| 697 IceMessage* CreateStunMessageWithUsername(int type, | 707 IceMessage* CreateStunMessageWithUsername(int type, |
| 698 const std::string& username) { | 708 const std::string& username) { |
| 699 IceMessage* msg = CreateStunMessage(type); | 709 IceMessage* msg = CreateStunMessage(type); |
| 700 msg->AddAttribute( | 710 msg->AddAttribute( |
| 701 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); | 711 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); |
| 702 return msg; | 712 return msg; |
| 703 } | 713 } |
| 704 TestPort* CreateTestPort(const rtc::SocketAddress& addr, | 714 TestPort* CreateTestPort(const rtc::SocketAddress& addr, |
| 705 const std::string& username, | 715 const std::string& username, |
| 706 const std::string& password) { | 716 const std::string& password) { |
| 707 TestPort* port = new TestPort(main_, "test", &socket_factory_, &network_, | 717 TestPort* port = new TestPort(main_, "test", &socket_factory_, &network_, |
| 708 addr.ipaddr(), 0, 0, username, password); | 718 addr.ipaddr(), 0, 0, username, password); |
| 709 port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict); | 719 port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict); |
| 710 return port; | 720 return port; |
| 711 } | 721 } |
| 712 TestPort* CreateTestPort(const rtc::SocketAddress& addr, | 722 TestPort* CreateTestPort(const rtc::SocketAddress& addr, |
| 713 const std::string& username, | 723 const std::string& username, |
| 714 const std::string& password, | 724 const std::string& password, |
| 725 cricket::IceProtocolType type, |
| 715 cricket::IceRole role, | 726 cricket::IceRole role, |
| 716 int tiebreaker) { | 727 int tiebreaker) { |
| 717 TestPort* port = CreateTestPort(addr, username, password); | 728 TestPort* port = CreateTestPort(addr, username, password); |
| 729 port->SetIceProtocolType(type); |
| 718 port->SetIceRole(role); | 730 port->SetIceRole(role); |
| 719 port->SetIceTiebreaker(tiebreaker); | 731 port->SetIceTiebreaker(tiebreaker); |
| 720 return port; | 732 return port; |
| 721 } | 733 } |
| 722 | 734 |
| 723 void OnRoleConflict(PortInterface* port) { | 735 void OnRoleConflict(PortInterface* port) { |
| 724 role_conflict_ = true; | 736 role_conflict_ = true; |
| 725 } | 737 } |
| 726 bool role_conflict() const { return role_conflict_; } | 738 bool role_conflict() const { return role_conflict_; } |
| 727 | 739 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 752 rtc::scoped_ptr<rtc::NATServer> nat_server2_; | 764 rtc::scoped_ptr<rtc::NATServer> nat_server2_; |
| 753 rtc::NATSocketFactory nat_factory1_; | 765 rtc::NATSocketFactory nat_factory1_; |
| 754 rtc::NATSocketFactory nat_factory2_; | 766 rtc::NATSocketFactory nat_factory2_; |
| 755 rtc::BasicPacketSocketFactory nat_socket_factory1_; | 767 rtc::BasicPacketSocketFactory nat_socket_factory1_; |
| 756 rtc::BasicPacketSocketFactory nat_socket_factory2_; | 768 rtc::BasicPacketSocketFactory nat_socket_factory2_; |
| 757 scoped_ptr<TestStunServer> stun_server_; | 769 scoped_ptr<TestStunServer> stun_server_; |
| 758 TestTurnServer turn_server_; | 770 TestTurnServer turn_server_; |
| 759 TestRelayServer relay_server_; | 771 TestRelayServer relay_server_; |
| 760 std::string username_; | 772 std::string username_; |
| 761 std::string password_; | 773 std::string password_; |
| 774 cricket::IceProtocolType ice_protocol_; |
| 762 bool role_conflict_; | 775 bool role_conflict_; |
| 763 bool destroyed_; | 776 bool destroyed_; |
| 764 }; | 777 }; |
| 765 | 778 |
| 766 void PortTest::TestConnectivity(const char* name1, Port* port1, | 779 void PortTest::TestConnectivity(const char* name1, Port* port1, |
| 767 const char* name2, Port* port2, | 780 const char* name2, Port* port2, |
| 768 bool accept, bool same_addr1, | 781 bool accept, bool same_addr1, |
| 769 bool same_addr2, bool possible) { | 782 bool same_addr2, bool possible) { |
| 770 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; | 783 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; |
| 771 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 784 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 } | 1239 } |
| 1227 | 1240 |
| 1228 TEST_F(PortTest, TestSslTcpToSslTcpRelay) { | 1241 TEST_F(PortTest, TestSslTcpToSslTcpRelay) { |
| 1229 TestSslTcpToRelay(PROTO_SSLTCP); | 1242 TestSslTcpToRelay(PROTO_SSLTCP); |
| 1230 } | 1243 } |
| 1231 */ | 1244 */ |
| 1232 | 1245 |
| 1233 // This test case verifies standard ICE features in STUN messages. Currently it | 1246 // This test case verifies standard ICE features in STUN messages. Currently it |
| 1234 // verifies Message Integrity attribute in STUN messages and username in STUN | 1247 // verifies Message Integrity attribute in STUN messages and username in STUN |
| 1235 // binding request will have colon (":") between remote and local username. | 1248 // binding request will have colon (":") between remote and local username. |
| 1236 TEST_F(PortTest, TestLocalToLocalStandard) { | 1249 TEST_F(PortTest, TestLocalToLocalAsIce) { |
| 1250 SetIceProtocolType(cricket::ICEPROTO_RFC5245); |
| 1237 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 1251 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 1238 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1252 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1239 port1->SetIceTiebreaker(kTiebreaker1); | 1253 port1->SetIceTiebreaker(kTiebreaker1); |
| 1254 ASSERT_EQ(cricket::ICEPROTO_RFC5245, port1->IceProtocol()); |
| 1240 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 1255 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 1241 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1256 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1242 port2->SetIceTiebreaker(kTiebreaker2); | 1257 port2->SetIceTiebreaker(kTiebreaker2); |
| 1258 ASSERT_EQ(cricket::ICEPROTO_RFC5245, port2->IceProtocol()); |
| 1243 // Same parameters as TestLocalToLocal above. | 1259 // Same parameters as TestLocalToLocal above. |
| 1244 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); | 1260 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); |
| 1245 } | 1261 } |
| 1246 | 1262 |
| 1247 // This test is trying to validate a successful and failure scenario in a | 1263 // This test is trying to validate a successful and failure scenario in a |
| 1248 // loopback test when protocol is RFC5245. For success IceTiebreaker, username | 1264 // loopback test when protocol is RFC5245. For success IceTiebreaker, username |
| 1249 // should remain equal to the request generated by the port and role of port | 1265 // should remain equal to the request generated by the port and role of port |
| 1250 // must be in controlling. | 1266 // must be in controlling. |
| 1251 TEST_F(PortTest, TestLoopbackCal) { | 1267 TEST_F(PortTest, TestLoopbackCallAsIce) { |
| 1252 rtc::scoped_ptr<TestPort> lport( | 1268 rtc::scoped_ptr<TestPort> lport( |
| 1253 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1269 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1270 lport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1254 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1271 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1255 lport->SetIceTiebreaker(kTiebreaker1); | 1272 lport->SetIceTiebreaker(kTiebreaker1); |
| 1256 lport->PrepareAddress(); | 1273 lport->PrepareAddress(); |
| 1257 ASSERT_FALSE(lport->Candidates().empty()); | 1274 ASSERT_FALSE(lport->Candidates().empty()); |
| 1258 Connection* conn = lport->CreateConnection(lport->Candidates()[0], | 1275 Connection* conn = lport->CreateConnection(lport->Candidates()[0], |
| 1259 Port::ORIGIN_MESSAGE); | 1276 Port::ORIGIN_MESSAGE); |
| 1260 conn->Ping(0); | 1277 conn->Ping(0); |
| 1261 | 1278 |
| 1262 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1279 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
| 1263 IceMessage* msg = lport->last_stun_msg(); | 1280 IceMessage* msg = lport->last_stun_msg(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 } | 1321 } |
| 1305 | 1322 |
| 1306 // This test verifies role conflict signal is received when there is | 1323 // This test verifies role conflict signal is received when there is |
| 1307 // conflict in the role. In this case both ports are in controlling and | 1324 // conflict in the role. In this case both ports are in controlling and |
| 1308 // |rport| has higher tiebreaker value than |lport|. Since |lport| has lower | 1325 // |rport| has higher tiebreaker value than |lport|. Since |lport| has lower |
| 1309 // value of tiebreaker, when it receives ping request from |rport| it will | 1326 // value of tiebreaker, when it receives ping request from |rport| it will |
| 1310 // send role conflict signal. | 1327 // send role conflict signal. |
| 1311 TEST_F(PortTest, TestIceRoleConflict) { | 1328 TEST_F(PortTest, TestIceRoleConflict) { |
| 1312 rtc::scoped_ptr<TestPort> lport( | 1329 rtc::scoped_ptr<TestPort> lport( |
| 1313 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1330 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1331 lport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1314 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1332 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1315 lport->SetIceTiebreaker(kTiebreaker1); | 1333 lport->SetIceTiebreaker(kTiebreaker1); |
| 1316 rtc::scoped_ptr<TestPort> rport( | 1334 rtc::scoped_ptr<TestPort> rport( |
| 1317 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1335 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1336 rport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1318 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1337 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1319 rport->SetIceTiebreaker(kTiebreaker2); | 1338 rport->SetIceTiebreaker(kTiebreaker2); |
| 1320 | 1339 |
| 1321 lport->PrepareAddress(); | 1340 lport->PrepareAddress(); |
| 1322 rport->PrepareAddress(); | 1341 rport->PrepareAddress(); |
| 1323 ASSERT_FALSE(lport->Candidates().empty()); | 1342 ASSERT_FALSE(lport->Candidates().empty()); |
| 1324 ASSERT_FALSE(rport->Candidates().empty()); | 1343 ASSERT_FALSE(rport->Candidates().empty()); |
| 1325 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 1344 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
| 1326 Port::ORIGIN_MESSAGE); | 1345 Port::ORIGIN_MESSAGE); |
| 1327 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], | 1346 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], |
| 1328 Port::ORIGIN_MESSAGE); | 1347 Port::ORIGIN_MESSAGE); |
| 1329 rconn->Ping(0); | 1348 rconn->Ping(0); |
| 1330 | 1349 |
| 1331 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); | 1350 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); |
| 1332 IceMessage* msg = rport->last_stun_msg(); | 1351 IceMessage* msg = rport->last_stun_msg(); |
| 1333 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1352 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
| 1334 // Send rport binding request to lport. | 1353 // Send rport binding request to lport. |
| 1335 lconn->OnReadPacket(rport->last_stun_buf()->Data(), | 1354 lconn->OnReadPacket(rport->last_stun_buf()->Data(), |
| 1336 rport->last_stun_buf()->Length(), | 1355 rport->last_stun_buf()->Length(), |
| 1337 rtc::PacketTime()); | 1356 rtc::PacketTime()); |
| 1338 | 1357 |
| 1339 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1358 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
| 1340 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); | 1359 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); |
| 1341 EXPECT_TRUE(role_conflict()); | 1360 EXPECT_TRUE(role_conflict()); |
| 1342 } | 1361 } |
| 1343 | 1362 |
| 1344 TEST_F(PortTest, TestTcpNoDelay) { | 1363 TEST_F(PortTest, TestTcpNoDelay) { |
| 1345 TCPPort* port1 = CreateTcpPort(kLocalAddr1); | 1364 TCPPort* port1 = CreateTcpPort(kLocalAddr1); |
| 1346 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 1347 int option_value = -1; | 1365 int option_value = -1; |
| 1348 int success = port1->GetOption(rtc::Socket::OPT_NODELAY, | 1366 int success = port1->GetOption(rtc::Socket::OPT_NODELAY, |
| 1349 &option_value); | 1367 &option_value); |
| 1350 ASSERT_EQ(0, success); // GetOption() should complete successfully w/ 0 | 1368 ASSERT_EQ(0, success); // GetOption() should complete successfully w/ 0 |
| 1351 ASSERT_EQ(1, option_value); | 1369 ASSERT_EQ(1, option_value); |
| 1352 delete port1; | 1370 delete port1; |
| 1353 } | 1371 } |
| 1354 | 1372 |
| 1355 TEST_F(PortTest, TestDelayedBindingUdp) { | 1373 TEST_F(PortTest, TestDelayedBindingUdp) { |
| 1356 FakeAsyncPacketSocket *socket = new FakeAsyncPacketSocket(); | 1374 FakeAsyncPacketSocket *socket = new FakeAsyncPacketSocket(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 EXPECT_EQ(rtc::DSCP_CS7, dscp); | 1534 EXPECT_EQ(rtc::DSCP_CS7, dscp); |
| 1517 // This will verify correct value returned without the socket. | 1535 // This will verify correct value returned without the socket. |
| 1518 rtc::scoped_ptr<TurnPort> turnport2(CreateTurnPort( | 1536 rtc::scoped_ptr<TurnPort> turnport2(CreateTurnPort( |
| 1519 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 1537 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
| 1520 EXPECT_EQ(0, turnport2->SetOption(rtc::Socket::OPT_DSCP, | 1538 EXPECT_EQ(0, turnport2->SetOption(rtc::Socket::OPT_DSCP, |
| 1521 rtc::DSCP_CS6)); | 1539 rtc::DSCP_CS6)); |
| 1522 EXPECT_EQ(0, turnport2->GetOption(rtc::Socket::OPT_DSCP, &dscp)); | 1540 EXPECT_EQ(0, turnport2->GetOption(rtc::Socket::OPT_DSCP, &dscp)); |
| 1523 EXPECT_EQ(rtc::DSCP_CS6, dscp); | 1541 EXPECT_EQ(rtc::DSCP_CS6, dscp); |
| 1524 } | 1542 } |
| 1525 | 1543 |
| 1526 // Test sending STUN messages. | 1544 // Test sending STUN messages in GICE format. |
| 1527 TEST_F(PortTest, TestSendStunMessage) { | 1545 TEST_F(PortTest, TestSendStunMessageAsGice) { |
| 1528 rtc::scoped_ptr<TestPort> lport( | 1546 rtc::scoped_ptr<TestPort> lport( |
| 1529 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1547 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1530 rtc::scoped_ptr<TestPort> rport( | 1548 rtc::scoped_ptr<TestPort> rport( |
| 1531 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1549 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1550 lport->SetIceProtocolType(ICEPROTO_GOOGLE); |
| 1551 rport->SetIceProtocolType(ICEPROTO_GOOGLE); |
| 1552 |
| 1553 // Send a fake ping from lport to rport. |
| 1554 lport->PrepareAddress(); |
| 1555 rport->PrepareAddress(); |
| 1556 ASSERT_FALSE(rport->Candidates().empty()); |
| 1557 Connection* conn = lport->CreateConnection(rport->Candidates()[0], |
| 1558 Port::ORIGIN_MESSAGE); |
| 1559 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); |
| 1560 conn->Ping(0); |
| 1561 |
| 1562 // Check that it's a proper BINDING-REQUEST. |
| 1563 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
| 1564 IceMessage* msg = lport->last_stun_msg(); |
| 1565 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
| 1566 EXPECT_FALSE(msg->IsLegacy()); |
| 1567 const StunByteStringAttribute* username_attr = msg->GetByteString( |
| 1568 STUN_ATTR_USERNAME); |
| 1569 ASSERT_TRUE(username_attr != NULL); |
| 1570 EXPECT_EQ("rfraglfrag", username_attr->GetString()); |
| 1571 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); |
| 1572 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); |
| 1573 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); |
| 1574 |
| 1575 // Save a copy of the BINDING-REQUEST for use below. |
| 1576 rtc::scoped_ptr<IceMessage> request(CopyStunMessage(msg)); |
| 1577 |
| 1578 // Respond with a BINDING-RESPONSE. |
| 1579 rport->SendBindingResponse(request.get(), lport->Candidates()[0].address()); |
| 1580 msg = rport->last_stun_msg(); |
| 1581 ASSERT_TRUE(msg != NULL); |
| 1582 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); |
| 1583 EXPECT_FALSE(msg->IsLegacy()); |
| 1584 username_attr = msg->GetByteString(STUN_ATTR_USERNAME); |
| 1585 ASSERT_TRUE(username_attr != NULL); // GICE has a username in the response. |
| 1586 EXPECT_EQ("rfraglfrag", username_attr->GetString()); |
| 1587 const StunAddressAttribute* addr_attr = msg->GetAddress( |
| 1588 STUN_ATTR_MAPPED_ADDRESS); |
| 1589 ASSERT_TRUE(addr_attr != NULL); |
| 1590 EXPECT_EQ(lport->Candidates()[0].address(), addr_attr->GetAddress()); |
| 1591 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_XOR_MAPPED_ADDRESS) == NULL); |
| 1592 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); |
| 1593 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); |
| 1594 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); |
| 1595 |
| 1596 // Respond with a BINDING-ERROR-RESPONSE. This wouldn't happen in real life, |
| 1597 // but we can do it here. |
| 1598 rport->SendBindingErrorResponse(request.get(), |
| 1599 rport->Candidates()[0].address(), |
| 1600 STUN_ERROR_SERVER_ERROR, |
| 1601 STUN_ERROR_REASON_SERVER_ERROR); |
| 1602 msg = rport->last_stun_msg(); |
| 1603 ASSERT_TRUE(msg != NULL); |
| 1604 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, msg->type()); |
| 1605 EXPECT_FALSE(msg->IsLegacy()); |
| 1606 username_attr = msg->GetByteString(STUN_ATTR_USERNAME); |
| 1607 ASSERT_TRUE(username_attr != NULL); // GICE has a username in the response. |
| 1608 EXPECT_EQ("rfraglfrag", username_attr->GetString()); |
| 1609 const StunErrorCodeAttribute* error_attr = msg->GetErrorCode(); |
| 1610 ASSERT_TRUE(error_attr != NULL); |
| 1611 // The GICE wire format for error codes is incorrect. |
| 1612 EXPECT_EQ(STUN_ERROR_SERVER_ERROR_AS_GICE, error_attr->code()); |
| 1613 EXPECT_EQ(STUN_ERROR_SERVER_ERROR / 256, error_attr->eclass()); |
| 1614 EXPECT_EQ(STUN_ERROR_SERVER_ERROR % 256, error_attr->number()); |
| 1615 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), error_attr->reason()); |
| 1616 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); |
| 1617 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); |
| 1618 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); |
| 1619 } |
| 1620 |
| 1621 // Test sending STUN messages in ICE format. |
| 1622 TEST_F(PortTest, TestSendStunMessageAsIce) { |
| 1623 rtc::scoped_ptr<TestPort> lport( |
| 1624 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1625 rtc::scoped_ptr<TestPort> rport( |
| 1626 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1627 lport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1532 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1628 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1533 lport->SetIceTiebreaker(kTiebreaker1); | 1629 lport->SetIceTiebreaker(kTiebreaker1); |
| 1630 rport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1534 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1631 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1535 rport->SetIceTiebreaker(kTiebreaker2); | 1632 rport->SetIceTiebreaker(kTiebreaker2); |
| 1536 | 1633 |
| 1537 // Send a fake ping from lport to rport. | 1634 // Send a fake ping from lport to rport. |
| 1538 lport->PrepareAddress(); | 1635 lport->PrepareAddress(); |
| 1539 rport->PrepareAddress(); | 1636 rport->PrepareAddress(); |
| 1540 ASSERT_FALSE(rport->Candidates().empty()); | 1637 ASSERT_FALSE(rport->Candidates().empty()); |
| 1541 Connection* lconn = lport->CreateConnection( | 1638 Connection* lconn = lport->CreateConnection( |
| 1542 rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1639 rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
| 1543 Connection* rconn = rport->CreateConnection( | 1640 Connection* rconn = rport->CreateConnection( |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 retransmit_attr = msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); | 1759 retransmit_attr = msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); |
| 1663 ASSERT_TRUE(retransmit_attr != NULL); | 1760 ASSERT_TRUE(retransmit_attr != NULL); |
| 1664 EXPECT_EQ(2U, retransmit_attr->value()); | 1761 EXPECT_EQ(2U, retransmit_attr->value()); |
| 1665 } | 1762 } |
| 1666 | 1763 |
| 1667 TEST_F(PortTest, TestUseCandidateAttribute) { | 1764 TEST_F(PortTest, TestUseCandidateAttribute) { |
| 1668 rtc::scoped_ptr<TestPort> lport( | 1765 rtc::scoped_ptr<TestPort> lport( |
| 1669 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1766 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1670 rtc::scoped_ptr<TestPort> rport( | 1767 rtc::scoped_ptr<TestPort> rport( |
| 1671 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1768 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1769 lport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1672 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1770 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1673 lport->SetIceTiebreaker(kTiebreaker1); | 1771 lport->SetIceTiebreaker(kTiebreaker1); |
| 1772 rport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1674 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1773 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1675 rport->SetIceTiebreaker(kTiebreaker2); | 1774 rport->SetIceTiebreaker(kTiebreaker2); |
| 1676 | 1775 |
| 1677 // Send a fake ping from lport to rport. | 1776 // Send a fake ping from lport to rport. |
| 1678 lport->PrepareAddress(); | 1777 lport->PrepareAddress(); |
| 1679 rport->PrepareAddress(); | 1778 rport->PrepareAddress(); |
| 1680 ASSERT_FALSE(rport->Candidates().empty()); | 1779 ASSERT_FALSE(rport->Candidates().empty()); |
| 1681 Connection* lconn = lport->CreateConnection( | 1780 Connection* lconn = lport->CreateConnection( |
| 1682 rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1781 rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
| 1683 lconn->Ping(0); | 1782 lconn->Ping(0); |
| 1684 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1783 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
| 1685 IceMessage* msg = lport->last_stun_msg(); | 1784 IceMessage* msg = lport->last_stun_msg(); |
| 1686 const StunUInt64Attribute* ice_controlling_attr = | 1785 const StunUInt64Attribute* ice_controlling_attr = |
| 1687 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); | 1786 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); |
| 1688 ASSERT_TRUE(ice_controlling_attr != NULL); | 1787 ASSERT_TRUE(ice_controlling_attr != NULL); |
| 1689 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( | 1788 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( |
| 1690 STUN_ATTR_USE_CANDIDATE); | 1789 STUN_ATTR_USE_CANDIDATE); |
| 1691 ASSERT_TRUE(use_candidate_attr != NULL); | 1790 ASSERT_TRUE(use_candidate_attr != NULL); |
| 1692 } | 1791 } |
| 1693 | 1792 |
| 1694 // Test handling STUN messages. | 1793 // Test handling STUN messages in GICE format. |
| 1695 TEST_F(PortTest, TestHandleStunMessage) { | 1794 TEST_F(PortTest, TestHandleStunMessageAsGice) { |
| 1696 // Our port will act as the "remote" port. | 1795 // Our port will act as the "remote" port. |
| 1697 rtc::scoped_ptr<TestPort> port( | 1796 rtc::scoped_ptr<TestPort> port( |
| 1698 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1797 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1798 port->SetIceProtocolType(ICEPROTO_GOOGLE); |
| 1699 | 1799 |
| 1700 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1800 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1701 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1801 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1802 rtc::SocketAddress addr(kLocalAddr1); |
| 1803 std::string username; |
| 1804 |
| 1805 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. |
| 1806 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 1807 "rfraglfrag")); |
| 1808 WriteStunMessage(in_msg.get(), buf.get()); |
| 1809 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1810 out_msg.accept(), &username)); |
| 1811 EXPECT_TRUE(out_msg.get() != NULL); // Succeeds, since this is GICE. |
| 1812 EXPECT_EQ("lfrag", username); |
| 1813 |
| 1814 // Add M-I; should be ignored and rest of message parsed normally. |
| 1815 in_msg->AddMessageIntegrity("password"); |
| 1816 WriteStunMessage(in_msg.get(), buf.get()); |
| 1817 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1818 out_msg.accept(), &username)); |
| 1819 EXPECT_TRUE(out_msg.get() != NULL); |
| 1820 EXPECT_EQ("lfrag", username); |
| 1821 |
| 1822 // BINDING-RESPONSE with username, as done in GICE. Should succeed. |
| 1823 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_RESPONSE, |
| 1824 "rfraglfrag")); |
| 1825 in_msg->AddAttribute( |
| 1826 new StunAddressAttribute(STUN_ATTR_MAPPED_ADDRESS, kLocalAddr2)); |
| 1827 WriteStunMessage(in_msg.get(), buf.get()); |
| 1828 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1829 out_msg.accept(), &username)); |
| 1830 EXPECT_TRUE(out_msg.get() != NULL); |
| 1831 EXPECT_EQ("", username); |
| 1832 |
| 1833 // BINDING-RESPONSE without username. Should be tolerated as well. |
| 1834 in_msg.reset(CreateStunMessage(STUN_BINDING_RESPONSE)); |
| 1835 in_msg->AddAttribute( |
| 1836 new StunAddressAttribute(STUN_ATTR_MAPPED_ADDRESS, kLocalAddr2)); |
| 1837 WriteStunMessage(in_msg.get(), buf.get()); |
| 1838 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1839 out_msg.accept(), &username)); |
| 1840 EXPECT_TRUE(out_msg.get() != NULL); |
| 1841 EXPECT_EQ("", username); |
| 1842 |
| 1843 // BINDING-ERROR-RESPONSE with username and error code. |
| 1844 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_ERROR_RESPONSE, |
| 1845 "rfraglfrag")); |
| 1846 in_msg->AddAttribute(new StunErrorCodeAttribute(STUN_ATTR_ERROR_CODE, |
| 1847 STUN_ERROR_SERVER_ERROR_AS_GICE, STUN_ERROR_REASON_SERVER_ERROR)); |
| 1848 WriteStunMessage(in_msg.get(), buf.get()); |
| 1849 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1850 out_msg.accept(), &username)); |
| 1851 ASSERT_TRUE(out_msg.get() != NULL); |
| 1852 EXPECT_EQ("", username); |
| 1853 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); |
| 1854 // GetStunMessage doesn't unmunge the GICE error code (happens downstream). |
| 1855 EXPECT_EQ(STUN_ERROR_SERVER_ERROR_AS_GICE, out_msg->GetErrorCode()->code()); |
| 1856 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), |
| 1857 out_msg->GetErrorCode()->reason()); |
| 1858 } |
| 1859 |
| 1860 // Test handling STUN messages in ICE format. |
| 1861 TEST_F(PortTest, TestHandleStunMessageAsIce) { |
| 1862 // Our port will act as the "remote" port. |
| 1863 rtc::scoped_ptr<TestPort> port( |
| 1864 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1865 port->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1866 |
| 1867 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1868 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1702 rtc::SocketAddress addr(kLocalAddr1); | 1869 rtc::SocketAddress addr(kLocalAddr1); |
| 1703 std::string username; | 1870 std::string username; |
| 1704 | 1871 |
| 1705 // BINDING-REQUEST from local to remote with valid ICE username, | 1872 // BINDING-REQUEST from local to remote with valid ICE username, |
| 1706 // MESSAGE-INTEGRITY, and FINGERPRINT. | 1873 // MESSAGE-INTEGRITY, and FINGERPRINT. |
| 1707 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 1874 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 1708 "rfrag:lfrag")); | 1875 "rfrag:lfrag")); |
| 1709 in_msg->AddMessageIntegrity("rpass"); | 1876 in_msg->AddMessageIntegrity("rpass"); |
| 1710 in_msg->AddFingerprint(); | 1877 in_msg->AddFingerprint(); |
| 1711 WriteStunMessage(in_msg.get(), buf.get()); | 1878 WriteStunMessage(in_msg.get(), buf.get()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1735 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1902 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1736 out_msg.accept(), &username)); | 1903 out_msg.accept(), &username)); |
| 1737 EXPECT_TRUE(out_msg.get() != NULL); | 1904 EXPECT_TRUE(out_msg.get() != NULL); |
| 1738 EXPECT_EQ("", username); | 1905 EXPECT_EQ("", username); |
| 1739 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); | 1906 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); |
| 1740 EXPECT_EQ(STUN_ERROR_SERVER_ERROR, out_msg->GetErrorCode()->code()); | 1907 EXPECT_EQ(STUN_ERROR_SERVER_ERROR, out_msg->GetErrorCode()->code()); |
| 1741 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), | 1908 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), |
| 1742 out_msg->GetErrorCode()->reason()); | 1909 out_msg->GetErrorCode()->reason()); |
| 1743 } | 1910 } |
| 1744 | 1911 |
| 1745 // Tests handling of ICE binding requests with missing or incorrect usernames. | 1912 // This test verifies port can handle ICE messages in Hybrid mode and switches |
| 1746 TEST_F(PortTest, TestHandleStunMessageBadUsername) { | 1913 // ICEPROTO_RFC5245 mode after successfully handling the message. |
| 1914 TEST_F(PortTest, TestHandleStunMessageAsIceInHybridMode) { |
| 1915 // Our port will act as the "remote" port. |
| 1747 rtc::scoped_ptr<TestPort> port( | 1916 rtc::scoped_ptr<TestPort> port( |
| 1748 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1917 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1918 port->SetIceProtocolType(ICEPROTO_HYBRID); |
| 1749 | 1919 |
| 1750 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1920 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1751 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1921 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1922 rtc::SocketAddress addr(kLocalAddr1); |
| 1923 std::string username; |
| 1924 |
| 1925 // BINDING-REQUEST from local to remote with valid ICE username, |
| 1926 // MESSAGE-INTEGRITY, and FINGERPRINT. |
| 1927 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 1928 "rfrag:lfrag")); |
| 1929 in_msg->AddMessageIntegrity("rpass"); |
| 1930 in_msg->AddFingerprint(); |
| 1931 WriteStunMessage(in_msg.get(), buf.get()); |
| 1932 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1933 out_msg.accept(), &username)); |
| 1934 EXPECT_TRUE(out_msg.get() != NULL); |
| 1935 EXPECT_EQ("lfrag", username); |
| 1936 EXPECT_EQ(ICEPROTO_RFC5245, port->IceProtocol()); |
| 1937 } |
| 1938 |
| 1939 // This test verifies port can handle GICE messages in Hybrid mode and switches |
| 1940 // ICEPROTO_GOOGLE mode after successfully handling the message. |
| 1941 TEST_F(PortTest, TestHandleStunMessageAsGiceInHybridMode) { |
| 1942 // Our port will act as the "remote" port. |
| 1943 rtc::scoped_ptr<TestPort> port( |
| 1944 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1945 port->SetIceProtocolType(ICEPROTO_HYBRID); |
| 1946 |
| 1947 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1948 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1949 rtc::SocketAddress addr(kLocalAddr1); |
| 1950 std::string username; |
| 1951 |
| 1952 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. |
| 1953 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 1954 "rfraglfrag")); |
| 1955 WriteStunMessage(in_msg.get(), buf.get()); |
| 1956 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1957 out_msg.accept(), &username)); |
| 1958 EXPECT_TRUE(out_msg.get() != NULL); // Succeeds, since this is GICE. |
| 1959 EXPECT_EQ("lfrag", username); |
| 1960 EXPECT_EQ(ICEPROTO_GOOGLE, port->IceProtocol()); |
| 1961 } |
| 1962 |
| 1963 // Verify port is not switched out of RFC5245 mode if GICE message is received |
| 1964 // in that mode. |
| 1965 TEST_F(PortTest, TestHandleStunMessageAsGiceInIceMode) { |
| 1966 // Our port will act as the "remote" port. |
| 1967 rtc::scoped_ptr<TestPort> port( |
| 1968 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1969 port->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1970 |
| 1971 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1972 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1973 rtc::SocketAddress addr(kLocalAddr1); |
| 1974 std::string username; |
| 1975 |
| 1976 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. |
| 1977 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 1978 "rfraglfrag")); |
| 1979 WriteStunMessage(in_msg.get(), buf.get()); |
| 1980 // Should fail as there is no MI and fingerprint. |
| 1981 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1982 out_msg.accept(), &username)); |
| 1983 EXPECT_EQ(ICEPROTO_RFC5245, port->IceProtocol()); |
| 1984 } |
| 1985 |
| 1986 |
| 1987 // Tests handling of GICE binding requests with missing or incorrect usernames. |
| 1988 TEST_F(PortTest, TestHandleStunMessageAsGiceBadUsername) { |
| 1989 rtc::scoped_ptr<TestPort> port( |
| 1990 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1991 port->SetIceProtocolType(ICEPROTO_GOOGLE); |
| 1992 |
| 1993 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1994 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1995 rtc::SocketAddress addr(kLocalAddr1); |
| 1996 std::string username; |
| 1997 |
| 1998 // BINDING-REQUEST with no username. |
| 1999 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); |
| 2000 WriteStunMessage(in_msg.get(), buf.get()); |
| 2001 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 2002 out_msg.accept(), &username)); |
| 2003 EXPECT_TRUE(out_msg.get() == NULL); |
| 2004 EXPECT_EQ("", username); |
| 2005 EXPECT_EQ(STUN_ERROR_BAD_REQUEST_AS_GICE, port->last_stun_error_code()); |
| 2006 |
| 2007 // BINDING-REQUEST with empty username. |
| 2008 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, "")); |
| 2009 WriteStunMessage(in_msg.get(), buf.get()); |
| 2010 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 2011 out_msg.accept(), &username)); |
| 2012 EXPECT_TRUE(out_msg.get() == NULL); |
| 2013 EXPECT_EQ("", username); |
| 2014 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); |
| 2015 |
| 2016 // BINDING-REQUEST with too-short username. |
| 2017 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, "lfra")); |
| 2018 WriteStunMessage(in_msg.get(), buf.get()); |
| 2019 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 2020 out_msg.accept(), &username)); |
| 2021 EXPECT_TRUE(out_msg.get() == NULL); |
| 2022 EXPECT_EQ("", username); |
| 2023 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); |
| 2024 |
| 2025 // BINDING-REQUEST with reversed username. |
| 2026 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 2027 "lfragrfrag")); |
| 2028 WriteStunMessage(in_msg.get(), buf.get()); |
| 2029 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 2030 out_msg.accept(), &username)); |
| 2031 EXPECT_TRUE(out_msg.get() == NULL); |
| 2032 EXPECT_EQ("", username); |
| 2033 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); |
| 2034 |
| 2035 // BINDING-REQUEST with garbage username. |
| 2036 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 2037 "abcdefgh")); |
| 2038 WriteStunMessage(in_msg.get(), buf.get()); |
| 2039 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 2040 out_msg.accept(), &username)); |
| 2041 EXPECT_TRUE(out_msg.get() == NULL); |
| 2042 EXPECT_EQ("", username); |
| 2043 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); |
| 2044 } |
| 2045 |
| 2046 // Tests handling of ICE binding requests with missing or incorrect usernames. |
| 2047 TEST_F(PortTest, TestHandleStunMessageAsIceBadUsername) { |
| 2048 rtc::scoped_ptr<TestPort> port( |
| 2049 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 2050 port->SetIceProtocolType(ICEPROTO_RFC5245); |
| 2051 |
| 2052 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 2053 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1752 rtc::SocketAddress addr(kLocalAddr1); | 2054 rtc::SocketAddress addr(kLocalAddr1); |
| 1753 std::string username; | 2055 std::string username; |
| 1754 | 2056 |
| 1755 // BINDING-REQUEST with no username. | 2057 // BINDING-REQUEST with no username. |
| 1756 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); | 2058 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); |
| 1757 in_msg->AddMessageIntegrity("rpass"); | 2059 in_msg->AddMessageIntegrity("rpass"); |
| 1758 in_msg->AddFingerprint(); | 2060 in_msg->AddFingerprint(); |
| 1759 WriteStunMessage(in_msg.get(), buf.get()); | 2061 WriteStunMessage(in_msg.get(), buf.get()); |
| 1760 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 2062 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1761 out_msg.accept(), &username)); | 2063 out_msg.accept(), &username)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 in_msg->AddMessageIntegrity("rpass"); | 2105 in_msg->AddMessageIntegrity("rpass"); |
| 1804 in_msg->AddFingerprint(); | 2106 in_msg->AddFingerprint(); |
| 1805 WriteStunMessage(in_msg.get(), buf.get()); | 2107 WriteStunMessage(in_msg.get(), buf.get()); |
| 1806 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 2108 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1807 out_msg.accept(), &username)); | 2109 out_msg.accept(), &username)); |
| 1808 EXPECT_TRUE(out_msg.get() == NULL); | 2110 EXPECT_TRUE(out_msg.get() == NULL); |
| 1809 EXPECT_EQ("", username); | 2111 EXPECT_EQ("", username); |
| 1810 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); | 2112 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); |
| 1811 } | 2113 } |
| 1812 | 2114 |
| 1813 // Test handling STUN messages with missing or malformed M-I. | 2115 // Test handling STUN messages (as ICE) with missing or malformed M-I. |
| 1814 TEST_F(PortTest, TestHandleStunMessageBadMessageIntegrity) { | 2116 TEST_F(PortTest, TestHandleStunMessageAsIceBadMessageIntegrity) { |
| 1815 // Our port will act as the "remote" port. | 2117 // Our port will act as the "remote" port. |
| 1816 rtc::scoped_ptr<TestPort> port( | 2118 rtc::scoped_ptr<TestPort> port( |
| 1817 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 2119 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 2120 port->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1818 | 2121 |
| 1819 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 2122 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1820 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 2123 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1821 rtc::SocketAddress addr(kLocalAddr1); | 2124 rtc::SocketAddress addr(kLocalAddr1); |
| 1822 std::string username; | 2125 std::string username; |
| 1823 | 2126 |
| 1824 // BINDING-REQUEST from local to remote with valid ICE username and | 2127 // BINDING-REQUEST from local to remote with valid ICE username and |
| 1825 // FINGERPRINT, but no MESSAGE-INTEGRITY. | 2128 // FINGERPRINT, but no MESSAGE-INTEGRITY. |
| 1826 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 2129 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 1827 "rfrag:lfrag")); | 2130 "rfrag:lfrag")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1844 out_msg.accept(), &username)); | 2147 out_msg.accept(), &username)); |
| 1845 EXPECT_TRUE(out_msg.get() == NULL); | 2148 EXPECT_TRUE(out_msg.get() == NULL); |
| 1846 EXPECT_EQ("", username); | 2149 EXPECT_EQ("", username); |
| 1847 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); | 2150 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); |
| 1848 | 2151 |
| 1849 // TODO: BINDING-RESPONSES and BINDING-ERROR-RESPONSES are checked | 2152 // TODO: BINDING-RESPONSES and BINDING-ERROR-RESPONSES are checked |
| 1850 // by the Connection, not the Port, since they require the remote username. | 2153 // by the Connection, not the Port, since they require the remote username. |
| 1851 // Change this test to pass in data via Connection::OnReadPacket instead. | 2154 // Change this test to pass in data via Connection::OnReadPacket instead. |
| 1852 } | 2155 } |
| 1853 | 2156 |
| 1854 // Test handling STUN messages with missing or malformed FINGERPRINT. | 2157 // Test handling STUN messages (as ICE) with missing or malformed FINGERPRINT. |
| 1855 TEST_F(PortTest, TestHandleStunMessageBadFingerprint) { | 2158 TEST_F(PortTest, TestHandleStunMessageAsIceBadFingerprint) { |
| 1856 // Our port will act as the "remote" port. | 2159 // Our port will act as the "remote" port. |
| 1857 rtc::scoped_ptr<TestPort> port( | 2160 rtc::scoped_ptr<TestPort> port( |
| 1858 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 2161 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 2162 port->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1859 | 2163 |
| 1860 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 2164 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1861 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 2165 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1862 rtc::SocketAddress addr(kLocalAddr1); | 2166 rtc::SocketAddress addr(kLocalAddr1); |
| 1863 std::string username; | 2167 std::string username; |
| 1864 | 2168 |
| 1865 // BINDING-REQUEST from local to remote with valid ICE username and | 2169 // BINDING-REQUEST from local to remote with valid ICE username and |
| 1866 // MESSAGE-INTEGRITY, but no FINGERPRINT; GetStunMessage should fail. | 2170 // MESSAGE-INTEGRITY, but no FINGERPRINT; GetStunMessage should fail. |
| 1867 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 2171 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 1868 "rfrag:lfrag")); | 2172 "rfrag:lfrag")); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 | 2214 |
| 1911 // Now, add a fingerprint, but munge the message so it's not valid. | 2215 // Now, add a fingerprint, but munge the message so it's not valid. |
| 1912 in_msg->AddFingerprint(); | 2216 in_msg->AddFingerprint(); |
| 1913 in_msg->SetTransactionID("TESTTESTBADD"); | 2217 in_msg->SetTransactionID("TESTTESTBADD"); |
| 1914 WriteStunMessage(in_msg.get(), buf.get()); | 2218 WriteStunMessage(in_msg.get(), buf.get()); |
| 1915 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 2219 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1916 out_msg.accept(), &username)); | 2220 out_msg.accept(), &username)); |
| 1917 EXPECT_EQ(0, port->last_stun_error_code()); | 2221 EXPECT_EQ(0, port->last_stun_error_code()); |
| 1918 } | 2222 } |
| 1919 | 2223 |
| 1920 // Test handling of STUN binding indication messages . STUN binding | 2224 // Test handling of STUN binding indication messages (as ICE). STUN binding |
| 1921 // indications are allowed only to the connection which is in read mode. | 2225 // indications are allowed only to the connection which is in read mode. |
| 1922 TEST_F(PortTest, TestHandleStunBindingIndication) { | 2226 TEST_F(PortTest, TestHandleStunBindingIndication) { |
| 1923 rtc::scoped_ptr<TestPort> lport( | 2227 rtc::scoped_ptr<TestPort> lport( |
| 1924 CreateTestPort(kLocalAddr2, "lfrag", "lpass")); | 2228 CreateTestPort(kLocalAddr2, "lfrag", "lpass")); |
| 2229 lport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1925 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2230 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1926 lport->SetIceTiebreaker(kTiebreaker1); | 2231 lport->SetIceTiebreaker(kTiebreaker1); |
| 1927 | 2232 |
| 1928 // Verifying encoding and decoding STUN indication message. | 2233 // Verifying encoding and decoding STUN indication message. |
| 1929 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 2234 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1930 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 2235 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1931 rtc::SocketAddress addr(kLocalAddr1); | 2236 rtc::SocketAddress addr(kLocalAddr1); |
| 1932 std::string username; | 2237 std::string username; |
| 1933 | 2238 |
| 1934 in_msg.reset(CreateStunMessage(STUN_BINDING_INDICATION)); | 2239 in_msg.reset(CreateStunMessage(STUN_BINDING_INDICATION)); |
| 1935 in_msg->AddFingerprint(); | 2240 in_msg->AddFingerprint(); |
| 1936 WriteStunMessage(in_msg.get(), buf.get()); | 2241 WriteStunMessage(in_msg.get(), buf.get()); |
| 1937 EXPECT_TRUE(lport->GetStunMessage(buf->Data(), buf->Length(), addr, | 2242 EXPECT_TRUE(lport->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1938 out_msg.accept(), &username)); | 2243 out_msg.accept(), &username)); |
| 1939 EXPECT_TRUE(out_msg.get() != NULL); | 2244 EXPECT_TRUE(out_msg.get() != NULL); |
| 1940 EXPECT_EQ(out_msg->type(), STUN_BINDING_INDICATION); | 2245 EXPECT_EQ(out_msg->type(), STUN_BINDING_INDICATION); |
| 1941 EXPECT_EQ("", username); | 2246 EXPECT_EQ("", username); |
| 1942 | 2247 |
| 1943 // Verify connection can handle STUN indication and updates | 2248 // Verify connection can handle STUN indication and updates |
| 1944 // last_ping_received. | 2249 // last_ping_received. |
| 1945 rtc::scoped_ptr<TestPort> rport( | 2250 rtc::scoped_ptr<TestPort> rport( |
| 1946 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 2251 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 2252 rport->SetIceProtocolType(ICEPROTO_RFC5245); |
| 1947 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2253 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1948 rport->SetIceTiebreaker(kTiebreaker2); | 2254 rport->SetIceTiebreaker(kTiebreaker2); |
| 1949 | 2255 |
| 1950 lport->PrepareAddress(); | 2256 lport->PrepareAddress(); |
| 1951 rport->PrepareAddress(); | 2257 rport->PrepareAddress(); |
| 1952 ASSERT_FALSE(lport->Candidates().empty()); | 2258 ASSERT_FALSE(lport->Candidates().empty()); |
| 1953 ASSERT_FALSE(rport->Candidates().empty()); | 2259 ASSERT_FALSE(rport->Candidates().empty()); |
| 1954 | 2260 |
| 1955 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 2261 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
| 1956 Port::ORIGIN_MESSAGE); | 2262 Port::ORIGIN_MESSAGE); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2139 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 2445 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
| 2140 turnport->PrepareAddress(); | 2446 turnport->PrepareAddress(); |
| 2141 ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kTimeout); | 2447 ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kTimeout); |
| 2142 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), | 2448 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), |
| 2143 turnport->Candidates()[0].address().ipaddr()); | 2449 turnport->Candidates()[0].address().ipaddr()); |
| 2144 EXPECT_EQ(kNatAddr1.ipaddr(), | 2450 EXPECT_EQ(kNatAddr1.ipaddr(), |
| 2145 turnport->Candidates()[0].related_address().ipaddr()); | 2451 turnport->Candidates()[0].related_address().ipaddr()); |
| 2146 } | 2452 } |
| 2147 | 2453 |
| 2148 // Test priority value overflow handling when preference is set to 3. | 2454 // Test priority value overflow handling when preference is set to 3. |
| 2149 TEST_F(PortTest, TestCandidatePriority) { | 2455 TEST_F(PortTest, TestCandidatePreference) { |
| 2150 cricket::Candidate cand1; | 2456 cricket::Candidate cand1; |
| 2151 cand1.set_priority(3); | 2457 cand1.set_preference(3); |
| 2152 cricket::Candidate cand2; | 2458 cricket::Candidate cand2; |
| 2153 cand2.set_priority(1); | 2459 cand2.set_preference(1); |
| 2154 EXPECT_TRUE(cand1.priority() > cand2.priority()); | 2460 EXPECT_TRUE(cand1.preference() > cand2.preference()); |
| 2155 } | 2461 } |
| 2156 | 2462 |
| 2157 // Test the Connection priority is calculated correctly. | 2463 // Test the Connection priority is calculated correctly. |
| 2158 TEST_F(PortTest, TestConnectionPriority) { | 2464 TEST_F(PortTest, TestConnectionPriority) { |
| 2159 rtc::scoped_ptr<TestPort> lport( | 2465 rtc::scoped_ptr<TestPort> lport( |
| 2160 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 2466 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 2161 lport->set_type_preference(cricket::ICE_TYPE_PREFERENCE_HOST); | 2467 lport->set_type_preference(cricket::ICE_TYPE_PREFERENCE_HOST); |
| 2162 rtc::scoped_ptr<TestPort> rport( | 2468 rtc::scoped_ptr<TestPort> rport( |
| 2163 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 2469 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 2164 rport->set_type_preference(cricket::ICE_TYPE_PREFERENCE_RELAY); | 2470 rport->set_type_preference(cricket::ICE_TYPE_PREFERENCE_RELAY); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2188 lport->Candidates()[0], Port::ORIGIN_MESSAGE); | 2494 lport->Candidates()[0], Port::ORIGIN_MESSAGE); |
| 2189 #if defined(WEBRTC_WIN) | 2495 #if defined(WEBRTC_WIN) |
| 2190 EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority()); | 2496 EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority()); |
| 2191 #else | 2497 #else |
| 2192 EXPECT_EQ(0x2001EE9FC003D0ALLU, rconn->priority()); | 2498 EXPECT_EQ(0x2001EE9FC003D0ALLU, rconn->priority()); |
| 2193 #endif | 2499 #endif |
| 2194 } | 2500 } |
| 2195 | 2501 |
| 2196 TEST_F(PortTest, TestWritableState) { | 2502 TEST_F(PortTest, TestWritableState) { |
| 2197 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2503 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2198 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 2199 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2504 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2200 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 2201 | 2505 |
| 2202 // Set up channels. | 2506 // Set up channels. |
| 2203 TestChannel ch1(port1); | 2507 TestChannel ch1(port1); |
| 2204 TestChannel ch2(port2); | 2508 TestChannel ch2(port2); |
| 2205 | 2509 |
| 2206 // Acquire addresses. | 2510 // Acquire addresses. |
| 2207 ch1.Start(); | 2511 ch1.Start(); |
| 2208 ch2.Start(); | 2512 ch2.Start(); |
| 2209 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2513 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
| 2210 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 2514 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2259 | 2563 |
| 2260 // Now that the connection has completely timed out, data send should fail. | 2564 // Now that the connection has completely timed out, data send should fail. |
| 2261 EXPECT_EQ(SOCKET_ERROR, ch1.conn()->Send(data, data_size, options)); | 2565 EXPECT_EQ(SOCKET_ERROR, ch1.conn()->Send(data, data_size, options)); |
| 2262 | 2566 |
| 2263 ch1.Stop(); | 2567 ch1.Stop(); |
| 2264 ch2.Stop(); | 2568 ch2.Stop(); |
| 2265 } | 2569 } |
| 2266 | 2570 |
| 2267 TEST_F(PortTest, TestTimeoutForNeverWritable) { | 2571 TEST_F(PortTest, TestTimeoutForNeverWritable) { |
| 2268 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2572 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2269 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | |
| 2270 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2573 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2271 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 2272 | 2574 |
| 2273 // Set up channels. | 2575 // Set up channels. |
| 2274 TestChannel ch1(port1); | 2576 TestChannel ch1(port1); |
| 2275 TestChannel ch2(port2); | 2577 TestChannel ch2(port2); |
| 2276 | 2578 |
| 2277 // Acquire addresses. | 2579 // Acquire addresses. |
| 2278 ch1.Start(); | 2580 ch1.Start(); |
| 2279 ch2.Start(); | 2581 ch2.Start(); |
| 2280 | 2582 |
| 2281 ch1.CreateConnection(GetCandidate(port2)); | 2583 ch1.CreateConnection(GetCandidate(port2)); |
| 2282 ASSERT_TRUE(ch1.conn() != NULL); | 2584 ASSERT_TRUE(ch1.conn() != NULL); |
| 2283 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); | 2585 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); |
| 2284 | 2586 |
| 2285 // Attempt to go directly to write timeout. | 2587 // Attempt to go directly to write timeout. |
| 2286 for (uint32 i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { | 2588 for (uint32 i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { |
| 2287 ch1.Ping(i); | 2589 ch1.Ping(i); |
| 2288 } | 2590 } |
| 2289 ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + 500u); | 2591 ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + 500u); |
| 2290 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); | 2592 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); |
| 2291 } | 2593 } |
| 2292 | 2594 |
| 2293 // This test verifies the connection setup between ICEMODE_FULL | 2595 // This test verifies the connection setup between ICEMODE_FULL |
| 2294 // and ICEMODE_LITE. | 2596 // and ICEMODE_LITE. |
| 2295 // In this test |ch1| behaves like FULL mode client and we have created | 2597 // In this test |ch1| behaves like FULL mode client and we have created |
| 2296 // port which responds to the ping message just like LITE client. | 2598 // port which responds to the ping message just like LITE client. |
| 2297 TEST_F(PortTest, TestIceLiteConnectivity) { | 2599 TEST_F(PortTest, TestIceLiteConnectivity) { |
| 2298 TestPort* ice_full_port = CreateTestPort( | 2600 TestPort* ice_full_port = CreateTestPort( |
| 2299 kLocalAddr1, "lfrag", "lpass", | 2601 kLocalAddr1, "lfrag", "lpass", cricket::ICEPROTO_RFC5245, |
| 2300 cricket::ICEROLE_CONTROLLING, kTiebreaker1); | 2602 cricket::ICEROLE_CONTROLLING, kTiebreaker1); |
| 2301 | 2603 |
| 2302 rtc::scoped_ptr<TestPort> ice_lite_port(CreateTestPort( | 2604 rtc::scoped_ptr<TestPort> ice_lite_port(CreateTestPort( |
| 2303 kLocalAddr2, "rfrag", "rpass", | 2605 kLocalAddr2, "rfrag", "rpass", cricket::ICEPROTO_RFC5245, |
| 2304 cricket::ICEROLE_CONTROLLED, kTiebreaker2)); | 2606 cricket::ICEROLE_CONTROLLED, kTiebreaker2)); |
| 2305 // Setup TestChannel. This behaves like FULL mode client. | 2607 // Setup TestChannel. This behaves like FULL mode client. |
| 2306 TestChannel ch1(ice_full_port); | 2608 TestChannel ch1(ice_full_port); |
| 2307 ch1.SetIceMode(ICEMODE_FULL); | 2609 ch1.SetIceMode(ICEMODE_FULL); |
| 2308 | 2610 |
| 2309 // Start gathering candidates. | 2611 // Start gathering candidates. |
| 2310 ch1.Start(); | 2612 ch1.Start(); |
| 2311 ice_lite_port->PrepareAddress(); | 2613 ice_lite_port->PrepareAddress(); |
| 2312 | 2614 |
| 2313 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2615 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2352 // Send ping. This must have USE_CANDIDATE_ATTR. | 2654 // Send ping. This must have USE_CANDIDATE_ATTR. |
| 2353 ch1.Ping(); | 2655 ch1.Ping(); |
| 2354 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); | 2656 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); |
| 2355 msg = ice_full_port->last_stun_msg(); | 2657 msg = ice_full_port->last_stun_msg(); |
| 2356 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); | 2658 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); |
| 2357 ch1.Stop(); | 2659 ch1.Stop(); |
| 2358 } | 2660 } |
| 2359 | 2661 |
| 2360 // This test case verifies that the CONTROLLING port does not time out. | 2662 // This test case verifies that the CONTROLLING port does not time out. |
| 2361 TEST_F(PortTest, TestControllingNoTimeout) { | 2663 TEST_F(PortTest, TestControllingNoTimeout) { |
| 2664 SetIceProtocolType(cricket::ICEPROTO_RFC5245); |
| 2362 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2665 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2363 ConnectToSignalDestroyed(port1); | 2666 ConnectToSignalDestroyed(port1); |
| 2364 port1->set_timeout_delay(10); // milliseconds | 2667 port1->set_timeout_delay(10); // milliseconds |
| 2365 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2668 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2366 port1->SetIceTiebreaker(kTiebreaker1); | 2669 port1->SetIceTiebreaker(kTiebreaker1); |
| 2367 | 2670 |
| 2368 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2671 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2369 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2672 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2370 port2->SetIceTiebreaker(kTiebreaker2); | 2673 port2->SetIceTiebreaker(kTiebreaker2); |
| 2371 | 2674 |
| 2372 // Set up channels and ensure both ports will be deleted. | 2675 // Set up channels and ensure both ports will be deleted. |
| 2373 TestChannel ch1(port1); | 2676 TestChannel ch1(port1); |
| 2374 TestChannel ch2(port2); | 2677 TestChannel ch2(port2); |
| 2375 | 2678 |
| 2376 // Simulate a connection that succeeds, and then is destroyed. | 2679 // Simulate a connection that succeeds, and then is destroyed. |
| 2377 StartConnectAndStopChannels(&ch1, &ch2); | 2680 StartConnectAndStopChannels(&ch1, &ch2); |
| 2378 | 2681 |
| 2379 // After the connection is destroyed, the port should not be destroyed. | 2682 // After the connection is destroyed, the port should not be destroyed. |
| 2380 rtc::Thread::Current()->ProcessMessages(kTimeout); | 2683 rtc::Thread::Current()->ProcessMessages(kTimeout); |
| 2381 EXPECT_FALSE(destroyed()); | 2684 EXPECT_FALSE(destroyed()); |
| 2382 } | 2685 } |
| 2383 | 2686 |
| 2384 // This test case verifies that the CONTROLLED port does time out, but only | 2687 // This test case verifies that the CONTROLLED port does time out, but only |
| 2385 // after connectivity is lost. | 2688 // after connectivity is lost. |
| 2386 TEST_F(PortTest, TestControlledTimeout) { | 2689 TEST_F(PortTest, TestControlledTimeout) { |
| 2690 SetIceProtocolType(cricket::ICEPROTO_RFC5245); |
| 2387 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2691 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2388 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2692 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2389 port1->SetIceTiebreaker(kTiebreaker1); | 2693 port1->SetIceTiebreaker(kTiebreaker1); |
| 2390 | 2694 |
| 2391 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2695 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2392 ConnectToSignalDestroyed(port2); | 2696 ConnectToSignalDestroyed(port2); |
| 2393 port2->set_timeout_delay(10); // milliseconds | 2697 port2->set_timeout_delay(10); // milliseconds |
| 2394 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2698 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2395 port2->SetIceTiebreaker(kTiebreaker2); | 2699 port2->SetIceTiebreaker(kTiebreaker2); |
| 2396 | 2700 |
| 2397 // The connection must not be destroyed before a connection is attempted. | 2701 // The connection must not be destroyed before a connection is attempted. |
| 2398 EXPECT_FALSE(destroyed()); | 2702 EXPECT_FALSE(destroyed()); |
| 2399 | 2703 |
| 2400 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 2704 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 2401 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 2705 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 2402 | 2706 |
| 2403 // Set up channels and ensure both ports will be deleted. | 2707 // Set up channels and ensure both ports will be deleted. |
| 2404 TestChannel ch1(port1); | 2708 TestChannel ch1(port1); |
| 2405 TestChannel ch2(port2); | 2709 TestChannel ch2(port2); |
| 2406 | 2710 |
| 2407 // Simulate a connection that succeeds, and then is destroyed. | 2711 // Simulate a connection that succeeds, and then is destroyed. |
| 2408 StartConnectAndStopChannels(&ch1, &ch2); | 2712 StartConnectAndStopChannels(&ch1, &ch2); |
| 2409 | 2713 |
| 2410 // The controlled port should be destroyed after 10 milliseconds. | 2714 // The controlled port should be destroyed after 10 milliseconds. |
| 2411 EXPECT_TRUE_WAIT(destroyed(), kTimeout); | 2715 EXPECT_TRUE_WAIT(destroyed(), kTimeout); |
| 2412 } | 2716 } |
| OLD | NEW |