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