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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 267 } |
274 | 268 |
275 void OnUnknownAddress(PortInterface* port, const SocketAddress& addr, | 269 void OnUnknownAddress(PortInterface* port, const SocketAddress& addr, |
276 ProtocolType proto, | 270 ProtocolType proto, |
277 IceMessage* msg, const std::string& rf, | 271 IceMessage* msg, const std::string& rf, |
278 bool /*port_muxed*/) { | 272 bool /*port_muxed*/) { |
279 ASSERT_EQ(src_.get(), port); | 273 ASSERT_EQ(src_.get(), port); |
280 if (!remote_address_.IsNil()) { | 274 if (!remote_address_.IsNil()) { |
281 ASSERT_EQ(remote_address_, addr); | 275 ASSERT_EQ(remote_address_, addr); |
282 } | 276 } |
283 // MI and PRIORITY attribute should be present in ping requests when port | |
284 // is in ICEPROTO_RFC5245 mode. | |
285 const cricket::StunUInt32Attribute* priority_attr = | 277 const cricket::StunUInt32Attribute* priority_attr = |
286 msg->GetUInt32(STUN_ATTR_PRIORITY); | 278 msg->GetUInt32(STUN_ATTR_PRIORITY); |
287 const cricket::StunByteStringAttribute* mi_attr = | 279 const cricket::StunByteStringAttribute* mi_attr = |
288 msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); | 280 msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); |
289 const cricket::StunUInt32Attribute* fingerprint_attr = | 281 const cricket::StunUInt32Attribute* fingerprint_attr = |
290 msg->GetUInt32(STUN_ATTR_FINGERPRINT); | 282 msg->GetUInt32(STUN_ATTR_FINGERPRINT); |
291 if (src_->IceProtocol() == cricket::ICEPROTO_RFC5245) { | 283 EXPECT_TRUE(priority_attr != NULL); |
292 EXPECT_TRUE(priority_attr != NULL); | 284 EXPECT_TRUE(mi_attr != NULL); |
293 EXPECT_TRUE(mi_attr != NULL); | 285 EXPECT_TRUE(fingerprint_attr != NULL); |
294 EXPECT_TRUE(fingerprint_attr != NULL); | |
295 } else { | |
296 EXPECT_TRUE(priority_attr == NULL); | |
297 EXPECT_TRUE(mi_attr == NULL); | |
298 EXPECT_TRUE(fingerprint_attr == NULL); | |
299 } | |
300 remote_address_ = addr; | 286 remote_address_ = addr; |
301 remote_request_.reset(CopyStunMessage(msg)); | 287 remote_request_.reset(CopyStunMessage(msg)); |
302 remote_frag_ = rf; | 288 remote_frag_ = rf; |
303 } | 289 } |
304 | 290 |
305 void OnDestroyed(Connection* conn) { | 291 void OnDestroyed(Connection* conn) { |
306 ASSERT_EQ(conn_, conn); | 292 ASSERT_EQ(conn_, conn); |
307 LOG(INFO) << "OnDestroy connection " << conn << " deleted"; | 293 LOG(INFO) << "OnDestroy connection " << conn << " deleted"; |
308 conn_ = NULL; | 294 conn_ = NULL; |
309 // When the connection is destroyed, also clear these fields so future | 295 // When the connection is destroyed, also clear these fields so future |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), | 337 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), |
352 relay_server_(main_, | 338 relay_server_(main_, |
353 kRelayUdpIntAddr, | 339 kRelayUdpIntAddr, |
354 kRelayUdpExtAddr, | 340 kRelayUdpExtAddr, |
355 kRelayTcpIntAddr, | 341 kRelayTcpIntAddr, |
356 kRelayTcpExtAddr, | 342 kRelayTcpExtAddr, |
357 kRelaySslTcpIntAddr, | 343 kRelaySslTcpIntAddr, |
358 kRelaySslTcpExtAddr), | 344 kRelaySslTcpExtAddr), |
359 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), | 345 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), |
360 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), | 346 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), |
361 ice_protocol_(cricket::ICEPROTO_GOOGLE), | |
362 role_conflict_(false), | 347 role_conflict_(false), |
363 destroyed_(false) { | 348 destroyed_(false) { |
364 network_.AddIP(rtc::IPAddress(INADDR_ANY)); | 349 network_.AddIP(rtc::IPAddress(INADDR_ANY)); |
365 } | 350 } |
366 | 351 |
367 protected: | 352 protected: |
368 void TestLocalToLocal() { | 353 void TestLocalToLocal() { |
369 Port* port1 = CreateUdpPort(kLocalAddr1); | 354 Port* port1 = CreateUdpPort(kLocalAddr1); |
| 355 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
370 Port* port2 = CreateUdpPort(kLocalAddr2); | 356 Port* port2 = CreateUdpPort(kLocalAddr2); |
| 357 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
371 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); | 358 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); |
372 } | 359 } |
373 void TestLocalToStun(NATType ntype) { | 360 void TestLocalToStun(NATType ntype) { |
374 Port* port1 = CreateUdpPort(kLocalAddr1); | 361 Port* port1 = CreateUdpPort(kLocalAddr1); |
| 362 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
375 nat_server2_.reset(CreateNatServer(kNatAddr2, ntype)); | 363 nat_server2_.reset(CreateNatServer(kNatAddr2, ntype)); |
376 Port* port2 = CreateStunPort(kLocalAddr2, &nat_socket_factory2_); | 364 Port* port2 = CreateStunPort(kLocalAddr2, &nat_socket_factory2_); |
| 365 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
377 TestConnectivity("udp", port1, StunName(ntype), port2, | 366 TestConnectivity("udp", port1, StunName(ntype), port2, |
378 ntype == NAT_OPEN_CONE, true, | 367 ntype == NAT_OPEN_CONE, true, |
379 ntype != NAT_SYMMETRIC, true); | 368 ntype != NAT_SYMMETRIC, true); |
380 } | 369 } |
381 void TestLocalToRelay(RelayType rtype, ProtocolType proto) { | 370 void TestLocalToRelay(RelayType rtype, ProtocolType proto) { |
382 Port* port1 = CreateUdpPort(kLocalAddr1); | 371 Port* port1 = CreateUdpPort(kLocalAddr1); |
| 372 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
383 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_UDP); | 373 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_UDP); |
| 374 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
384 TestConnectivity("udp", port1, RelayName(rtype, proto), port2, | 375 TestConnectivity("udp", port1, RelayName(rtype, proto), port2, |
385 rtype == RELAY_GTURN, true, true, true); | 376 rtype == RELAY_GTURN, true, true, true); |
386 } | 377 } |
387 void TestStunToLocal(NATType ntype) { | 378 void TestStunToLocal(NATType ntype) { |
388 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype)); | 379 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype)); |
389 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); | 380 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); |
| 381 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
390 Port* port2 = CreateUdpPort(kLocalAddr2); | 382 Port* port2 = CreateUdpPort(kLocalAddr2); |
| 383 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
391 TestConnectivity(StunName(ntype), port1, "udp", port2, | 384 TestConnectivity(StunName(ntype), port1, "udp", port2, |
392 true, ntype != NAT_SYMMETRIC, true, true); | 385 true, ntype != NAT_SYMMETRIC, true, true); |
393 } | 386 } |
394 void TestStunToStun(NATType ntype1, NATType ntype2) { | 387 void TestStunToStun(NATType ntype1, NATType ntype2) { |
395 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype1)); | 388 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype1)); |
396 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); | 389 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); |
| 390 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
397 nat_server2_.reset(CreateNatServer(kNatAddr2, ntype2)); | 391 nat_server2_.reset(CreateNatServer(kNatAddr2, ntype2)); |
398 Port* port2 = CreateStunPort(kLocalAddr2, &nat_socket_factory2_); | 392 Port* port2 = CreateStunPort(kLocalAddr2, &nat_socket_factory2_); |
| 393 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
399 TestConnectivity(StunName(ntype1), port1, StunName(ntype2), port2, | 394 TestConnectivity(StunName(ntype1), port1, StunName(ntype2), port2, |
400 ntype2 == NAT_OPEN_CONE, | 395 ntype2 == NAT_OPEN_CONE, |
401 ntype1 != NAT_SYMMETRIC, ntype2 != NAT_SYMMETRIC, | 396 ntype1 != NAT_SYMMETRIC, ntype2 != NAT_SYMMETRIC, |
402 ntype1 + ntype2 < (NAT_PORT_RESTRICTED + NAT_SYMMETRIC)); | 397 ntype1 + ntype2 < (NAT_PORT_RESTRICTED + NAT_SYMMETRIC)); |
403 } | 398 } |
404 void TestStunToRelay(NATType ntype, RelayType rtype, ProtocolType proto) { | 399 void TestStunToRelay(NATType ntype, RelayType rtype, ProtocolType proto) { |
405 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype)); | 400 nat_server1_.reset(CreateNatServer(kNatAddr1, ntype)); |
406 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); | 401 Port* port1 = CreateStunPort(kLocalAddr1, &nat_socket_factory1_); |
| 402 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
407 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_UDP); | 403 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_UDP); |
| 404 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
408 TestConnectivity(StunName(ntype), port1, RelayName(rtype, proto), port2, | 405 TestConnectivity(StunName(ntype), port1, RelayName(rtype, proto), port2, |
409 rtype == RELAY_GTURN, ntype != NAT_SYMMETRIC, true, true); | 406 rtype == RELAY_GTURN, ntype != NAT_SYMMETRIC, true, true); |
410 } | 407 } |
411 void TestTcpToTcp() { | 408 void TestTcpToTcp() { |
412 Port* port1 = CreateTcpPort(kLocalAddr1); | 409 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 410 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
413 Port* port2 = CreateTcpPort(kLocalAddr2); | 411 Port* port2 = CreateTcpPort(kLocalAddr2); |
| 412 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
414 TestConnectivity("tcp", port1, "tcp", port2, true, false, true, true); | 413 TestConnectivity("tcp", port1, "tcp", port2, true, false, true, true); |
415 } | 414 } |
416 void TestTcpToRelay(RelayType rtype, ProtocolType proto) { | 415 void TestTcpToRelay(RelayType rtype, ProtocolType proto) { |
417 Port* port1 = CreateTcpPort(kLocalAddr1); | 416 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 417 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
418 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_TCP); | 418 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_TCP); |
| 419 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
419 TestConnectivity("tcp", port1, RelayName(rtype, proto), port2, | 420 TestConnectivity("tcp", port1, RelayName(rtype, proto), port2, |
420 rtype == RELAY_GTURN, false, true, true); | 421 rtype == RELAY_GTURN, false, true, true); |
421 } | 422 } |
422 void TestSslTcpToRelay(RelayType rtype, ProtocolType proto) { | 423 void TestSslTcpToRelay(RelayType rtype, ProtocolType proto) { |
423 Port* port1 = CreateTcpPort(kLocalAddr1); | 424 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 425 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
424 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_SSLTCP); | 426 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_SSLTCP); |
| 427 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
425 TestConnectivity("ssltcp", port1, RelayName(rtype, proto), port2, | 428 TestConnectivity("ssltcp", port1, RelayName(rtype, proto), port2, |
426 rtype == RELAY_GTURN, false, true, true); | 429 rtype == RELAY_GTURN, false, true, true); |
427 } | 430 } |
428 // helpers for above functions | 431 // helpers for above functions |
429 UDPPort* CreateUdpPort(const SocketAddress& addr) { | 432 UDPPort* CreateUdpPort(const SocketAddress& addr) { |
430 return CreateUdpPort(addr, &socket_factory_); | 433 return CreateUdpPort(addr, &socket_factory_); |
431 } | 434 } |
432 UDPPort* CreateUdpPort(const SocketAddress& addr, | 435 UDPPort* CreateUdpPort(const SocketAddress& addr, |
433 PacketSocketFactory* socket_factory) { | 436 PacketSocketFactory* socket_factory) { |
434 UDPPort* port = UDPPort::Create(main_, socket_factory, &network_, | 437 return UDPPort::Create(main_, socket_factory, &network_, |
435 addr.ipaddr(), 0, 0, username_, password_, | 438 addr.ipaddr(), 0, 0, username_, password_, |
436 std::string()); | 439 std::string()); |
437 port->SetIceProtocolType(ice_protocol_); | |
438 return port; | |
439 } | 440 } |
440 TCPPort* CreateTcpPort(const SocketAddress& addr) { | 441 TCPPort* CreateTcpPort(const SocketAddress& addr) { |
441 TCPPort* port = CreateTcpPort(addr, &socket_factory_); | 442 return CreateTcpPort(addr, &socket_factory_); |
442 port->SetIceProtocolType(ice_protocol_); | |
443 return port; | |
444 } | 443 } |
445 TCPPort* CreateTcpPort(const SocketAddress& addr, | 444 TCPPort* CreateTcpPort(const SocketAddress& addr, |
446 PacketSocketFactory* socket_factory) { | 445 PacketSocketFactory* socket_factory) { |
447 TCPPort* port = TCPPort::Create(main_, socket_factory, &network_, | 446 return TCPPort::Create(main_, socket_factory, &network_, |
448 addr.ipaddr(), 0, 0, username_, password_, | 447 addr.ipaddr(), 0, 0, username_, password_, |
449 true); | 448 true); |
450 port->SetIceProtocolType(ice_protocol_); | |
451 return port; | |
452 } | 449 } |
453 StunPort* CreateStunPort(const SocketAddress& addr, | 450 StunPort* CreateStunPort(const SocketAddress& addr, |
454 rtc::PacketSocketFactory* factory) { | 451 rtc::PacketSocketFactory* factory) { |
455 ServerAddresses stun_servers; | 452 ServerAddresses stun_servers; |
456 stun_servers.insert(kStunAddr); | 453 stun_servers.insert(kStunAddr); |
457 StunPort* port = StunPort::Create(main_, factory, &network_, | 454 return StunPort::Create(main_, factory, &network_, |
458 addr.ipaddr(), 0, 0, | 455 addr.ipaddr(), 0, 0, |
459 username_, password_, stun_servers, | 456 username_, password_, stun_servers, |
460 std::string()); | 457 std::string()); |
461 port->SetIceProtocolType(ice_protocol_); | |
462 return port; | |
463 } | 458 } |
464 Port* CreateRelayPort(const SocketAddress& addr, RelayType rtype, | 459 Port* CreateRelayPort(const SocketAddress& addr, RelayType rtype, |
465 ProtocolType int_proto, ProtocolType ext_proto) { | 460 ProtocolType int_proto, ProtocolType ext_proto) { |
466 if (rtype == RELAY_TURN) { | 461 if (rtype == RELAY_TURN) { |
467 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); | 462 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); |
468 } else { | 463 } else { |
469 return CreateGturnPort(addr, int_proto, ext_proto); | 464 return CreateGturnPort(addr, int_proto, ext_proto); |
470 } | 465 } |
471 } | 466 } |
472 TurnPort* CreateTurnPort(const SocketAddress& addr, | 467 TurnPort* CreateTurnPort(const SocketAddress& addr, |
473 PacketSocketFactory* socket_factory, | 468 PacketSocketFactory* socket_factory, |
474 ProtocolType int_proto, ProtocolType ext_proto) { | 469 ProtocolType int_proto, ProtocolType ext_proto) { |
475 return CreateTurnPort(addr, socket_factory, | 470 return CreateTurnPort(addr, socket_factory, |
476 int_proto, ext_proto, kTurnUdpIntAddr); | 471 int_proto, ext_proto, kTurnUdpIntAddr); |
477 } | 472 } |
478 TurnPort* CreateTurnPort(const SocketAddress& addr, | 473 TurnPort* CreateTurnPort(const SocketAddress& addr, |
479 PacketSocketFactory* socket_factory, | 474 PacketSocketFactory* socket_factory, |
480 ProtocolType int_proto, ProtocolType ext_proto, | 475 ProtocolType int_proto, ProtocolType ext_proto, |
481 const rtc::SocketAddress& server_addr) { | 476 const rtc::SocketAddress& server_addr) { |
482 TurnPort* port = TurnPort::Create(main_, socket_factory, &network_, | 477 return TurnPort::Create(main_, socket_factory, &network_, |
483 addr.ipaddr(), 0, 0, | 478 addr.ipaddr(), 0, 0, |
484 username_, password_, ProtocolAddress( | 479 username_, password_, ProtocolAddress( |
485 server_addr, PROTO_UDP), | 480 server_addr, PROTO_UDP), |
486 kRelayCredentials, 0, | 481 kRelayCredentials, 0, |
487 std::string()); | 482 std::string()); |
488 port->SetIceProtocolType(ice_protocol_); | |
489 return port; | |
490 } | 483 } |
491 RelayPort* CreateGturnPort(const SocketAddress& addr, | 484 RelayPort* CreateGturnPort(const SocketAddress& addr, |
492 ProtocolType int_proto, ProtocolType ext_proto) { | 485 ProtocolType int_proto, ProtocolType ext_proto) { |
493 RelayPort* port = CreateGturnPort(addr); | 486 RelayPort* port = CreateGturnPort(addr); |
494 SocketAddress addrs[] = | 487 SocketAddress addrs[] = |
495 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; | 488 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; |
496 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); | 489 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); |
497 return port; | 490 return port; |
498 } | 491 } |
499 RelayPort* CreateGturnPort(const SocketAddress& addr) { | 492 RelayPort* CreateGturnPort(const SocketAddress& addr) { |
500 RelayPort* port = RelayPort::Create(main_, &socket_factory_, &network_, | 493 // TODO(pthatcher): Remove GTURN. |
501 addr.ipaddr(), 0, 0, | 494 return RelayPort::Create(main_, &socket_factory_, &network_, |
502 username_, password_); | 495 addr.ipaddr(), 0, 0, |
| 496 username_, password_); |
503 // TODO: Add an external address for ext_proto, so that the | 497 // TODO: Add an external address for ext_proto, so that the |
504 // other side can connect to this port using a non-UDP protocol. | 498 // other side can connect to this port using a non-UDP protocol. |
505 port->SetIceProtocolType(ice_protocol_); | |
506 return port; | |
507 } | 499 } |
508 rtc::NATServer* CreateNatServer(const SocketAddress& addr, | 500 rtc::NATServer* CreateNatServer(const SocketAddress& addr, |
509 rtc::NATType type) { | 501 rtc::NATType type) { |
510 return new rtc::NATServer(type, ss_.get(), addr, addr, ss_.get(), addr); | 502 return new rtc::NATServer(type, ss_.get(), addr, addr, ss_.get(), addr); |
511 } | 503 } |
512 static const char* StunName(NATType type) { | 504 static const char* StunName(NATType type) { |
513 switch (type) { | 505 switch (type) { |
514 case NAT_OPEN_CONE: return "stun(open cone)"; | 506 case NAT_OPEN_CONE: return "stun(open cone)"; |
515 case NAT_ADDR_RESTRICTED: return "stun(addr restricted)"; | 507 case NAT_ADDR_RESTRICTED: return "stun(addr restricted)"; |
516 case NAT_PORT_RESTRICTED: return "stun(port restricted)"; | 508 case NAT_PORT_RESTRICTED: return "stun(port restricted)"; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kTimeout); | 582 EXPECT_TRUE_WAIT(!ch2->conn()->connected(), kTimeout); |
591 | 583 |
592 // Destroy channel2 connection to get ready for new incoming TCPConnection. | 584 // Destroy channel2 connection to get ready for new incoming TCPConnection. |
593 ch2->conn()->Destroy(); | 585 ch2->conn()->Destroy(); |
594 EXPECT_TRUE_WAIT(ch2->conn() == NULL, kTimeout); | 586 EXPECT_TRUE_WAIT(ch2->conn() == NULL, kTimeout); |
595 } | 587 } |
596 | 588 |
597 void TestTcpReconnect(bool ping_after_disconnected, | 589 void TestTcpReconnect(bool ping_after_disconnected, |
598 bool send_after_disconnected) { | 590 bool send_after_disconnected) { |
599 Port* port1 = CreateTcpPort(kLocalAddr1); | 591 Port* port1 = CreateTcpPort(kLocalAddr1); |
| 592 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
600 Port* port2 = CreateTcpPort(kLocalAddr2); | 593 Port* port2 = CreateTcpPort(kLocalAddr2); |
| 594 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
601 | 595 |
602 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 596 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
603 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 597 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
604 | 598 |
605 // Set up channels and ensure both ports will be deleted. | 599 // Set up channels and ensure both ports will be deleted. |
606 TestChannel ch1(port1, port2); | 600 TestChannel ch1(port1, port2); |
607 TestChannel ch2(port2, port1); | 601 TestChannel ch2(port2, port1); |
608 EXPECT_EQ(0, ch1.complete_count()); | 602 EXPECT_EQ(0, ch1.complete_count()); |
609 EXPECT_EQ(0, ch2.complete_count()); | 603 EXPECT_EQ(0, ch2.complete_count()); |
610 | 604 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 kTcpReconnectTimeout + kTimeout); | 645 kTcpReconnectTimeout + kTimeout); |
652 } | 646 } |
653 | 647 |
654 // Tear down and ensure that goes smoothly. | 648 // Tear down and ensure that goes smoothly. |
655 ch1.Stop(); | 649 ch1.Stop(); |
656 ch2.Stop(); | 650 ch2.Stop(); |
657 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); | 651 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); |
658 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); | 652 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); |
659 } | 653 } |
660 | 654 |
661 void SetIceProtocolType(cricket::IceProtocolType protocol) { | |
662 ice_protocol_ = protocol; | |
663 } | |
664 | |
665 IceMessage* CreateStunMessage(int type) { | 655 IceMessage* CreateStunMessage(int type) { |
666 IceMessage* msg = new IceMessage(); | 656 IceMessage* msg = new IceMessage(); |
667 msg->SetType(type); | 657 msg->SetType(type); |
668 msg->SetTransactionID("TESTTESTTEST"); | 658 msg->SetTransactionID("TESTTESTTEST"); |
669 return msg; | 659 return msg; |
670 } | 660 } |
671 IceMessage* CreateStunMessageWithUsername(int type, | 661 IceMessage* CreateStunMessageWithUsername(int type, |
672 const std::string& username) { | 662 const std::string& username) { |
673 IceMessage* msg = CreateStunMessage(type); | 663 IceMessage* msg = CreateStunMessage(type); |
674 msg->AddAttribute( | 664 msg->AddAttribute( |
675 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); | 665 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); |
676 return msg; | 666 return msg; |
677 } | 667 } |
678 TestPort* CreateTestPort(const rtc::SocketAddress& addr, | 668 TestPort* CreateTestPort(const rtc::SocketAddress& addr, |
679 const std::string& username, | 669 const std::string& username, |
680 const std::string& password) { | 670 const std::string& password) { |
681 TestPort* port = new TestPort(main_, "test", &socket_factory_, &network_, | 671 TestPort* port = new TestPort(main_, "test", &socket_factory_, &network_, |
682 addr.ipaddr(), 0, 0, username, password); | 672 addr.ipaddr(), 0, 0, username, password); |
683 port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict); | 673 port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict); |
684 return port; | 674 return port; |
685 } | 675 } |
686 TestPort* CreateTestPort(const rtc::SocketAddress& addr, | 676 TestPort* CreateTestPort(const rtc::SocketAddress& addr, |
687 const std::string& username, | 677 const std::string& username, |
688 const std::string& password, | 678 const std::string& password, |
689 cricket::IceProtocolType type, | |
690 cricket::IceRole role, | 679 cricket::IceRole role, |
691 int tiebreaker) { | 680 int tiebreaker) { |
692 TestPort* port = CreateTestPort(addr, username, password); | 681 TestPort* port = CreateTestPort(addr, username, password); |
693 port->SetIceProtocolType(type); | |
694 port->SetIceRole(role); | 682 port->SetIceRole(role); |
695 port->SetIceTiebreaker(tiebreaker); | 683 port->SetIceTiebreaker(tiebreaker); |
696 return port; | 684 return port; |
697 } | 685 } |
698 | 686 |
699 void OnRoleConflict(PortInterface* port) { | 687 void OnRoleConflict(PortInterface* port) { |
700 role_conflict_ = true; | 688 role_conflict_ = true; |
701 } | 689 } |
702 bool role_conflict() const { return role_conflict_; } | 690 bool role_conflict() const { return role_conflict_; } |
703 | 691 |
(...skipping 21 matching lines...) Expand all Loading... |
725 rtc::scoped_ptr<rtc::NATServer> nat_server2_; | 713 rtc::scoped_ptr<rtc::NATServer> nat_server2_; |
726 rtc::NATSocketFactory nat_factory1_; | 714 rtc::NATSocketFactory nat_factory1_; |
727 rtc::NATSocketFactory nat_factory2_; | 715 rtc::NATSocketFactory nat_factory2_; |
728 rtc::BasicPacketSocketFactory nat_socket_factory1_; | 716 rtc::BasicPacketSocketFactory nat_socket_factory1_; |
729 rtc::BasicPacketSocketFactory nat_socket_factory2_; | 717 rtc::BasicPacketSocketFactory nat_socket_factory2_; |
730 scoped_ptr<TestStunServer> stun_server_; | 718 scoped_ptr<TestStunServer> stun_server_; |
731 TestTurnServer turn_server_; | 719 TestTurnServer turn_server_; |
732 TestRelayServer relay_server_; | 720 TestRelayServer relay_server_; |
733 std::string username_; | 721 std::string username_; |
734 std::string password_; | 722 std::string password_; |
735 cricket::IceProtocolType ice_protocol_; | |
736 bool role_conflict_; | 723 bool role_conflict_; |
737 bool destroyed_; | 724 bool destroyed_; |
738 }; | 725 }; |
739 | 726 |
740 void PortTest::TestConnectivity(const char* name1, Port* port1, | 727 void PortTest::TestConnectivity(const char* name1, Port* port1, |
741 const char* name2, Port* port2, | 728 const char* name2, Port* port2, |
742 bool accept, bool same_addr1, | 729 bool accept, bool same_addr1, |
743 bool same_addr2, bool possible) { | 730 bool same_addr2, bool possible) { |
744 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; | 731 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; |
745 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 732 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 } | 1160 } |
1174 | 1161 |
1175 TEST_F(PortTest, TestSslTcpToSslTcpRelay) { | 1162 TEST_F(PortTest, TestSslTcpToSslTcpRelay) { |
1176 TestSslTcpToRelay(PROTO_SSLTCP); | 1163 TestSslTcpToRelay(PROTO_SSLTCP); |
1177 } | 1164 } |
1178 */ | 1165 */ |
1179 | 1166 |
1180 // This test case verifies standard ICE features in STUN messages. Currently it | 1167 // This test case verifies standard ICE features in STUN messages. Currently it |
1181 // verifies Message Integrity attribute in STUN messages and username in STUN | 1168 // verifies Message Integrity attribute in STUN messages and username in STUN |
1182 // binding request will have colon (":") between remote and local username. | 1169 // binding request will have colon (":") between remote and local username. |
1183 TEST_F(PortTest, TestLocalToLocalAsIce) { | 1170 TEST_F(PortTest, TestLocalToLocalStandard) { |
1184 SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
1185 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 1171 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
1186 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1172 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1187 port1->SetIceTiebreaker(kTiebreaker1); | 1173 port1->SetIceTiebreaker(kTiebreaker1); |
1188 ASSERT_EQ(cricket::ICEPROTO_RFC5245, port1->IceProtocol()); | |
1189 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 1174 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
1190 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1175 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
1191 port2->SetIceTiebreaker(kTiebreaker2); | 1176 port2->SetIceTiebreaker(kTiebreaker2); |
1192 ASSERT_EQ(cricket::ICEPROTO_RFC5245, port2->IceProtocol()); | |
1193 // Same parameters as TestLocalToLocal above. | 1177 // Same parameters as TestLocalToLocal above. |
1194 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); | 1178 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); |
1195 } | 1179 } |
1196 | 1180 |
1197 // This test is trying to validate a successful and failure scenario in a | 1181 // This test is trying to validate a successful and failure scenario in a |
1198 // loopback test when protocol is RFC5245. For success IceTiebreaker, username | 1182 // loopback test when protocol is RFC5245. For success IceTiebreaker, username |
1199 // should remain equal to the request generated by the port and role of port | 1183 // should remain equal to the request generated by the port and role of port |
1200 // must be in controlling. | 1184 // must be in controlling. |
1201 TEST_F(PortTest, TestLoopbackCallAsIce) { | 1185 TEST_F(PortTest, TestLoopbackCal) { |
1202 rtc::scoped_ptr<TestPort> lport( | 1186 rtc::scoped_ptr<TestPort> lport( |
1203 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1187 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
1204 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
1205 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1188 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1206 lport->SetIceTiebreaker(kTiebreaker1); | 1189 lport->SetIceTiebreaker(kTiebreaker1); |
1207 lport->PrepareAddress(); | 1190 lport->PrepareAddress(); |
1208 ASSERT_FALSE(lport->Candidates().empty()); | 1191 ASSERT_FALSE(lport->Candidates().empty()); |
1209 Connection* conn = lport->CreateConnection(lport->Candidates()[0], | 1192 Connection* conn = lport->CreateConnection(lport->Candidates()[0], |
1210 Port::ORIGIN_MESSAGE); | 1193 Port::ORIGIN_MESSAGE); |
1211 conn->Ping(0); | 1194 conn->Ping(0); |
1212 | 1195 |
1213 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1196 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
1214 IceMessage* msg = lport->last_stun_msg(); | 1197 IceMessage* msg = lport->last_stun_msg(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 } | 1238 } |
1256 | 1239 |
1257 // This test verifies role conflict signal is received when there is | 1240 // This test verifies role conflict signal is received when there is |
1258 // conflict in the role. In this case both ports are in controlling and | 1241 // conflict in the role. In this case both ports are in controlling and |
1259 // |rport| has higher tiebreaker value than |lport|. Since |lport| has lower | 1242 // |rport| has higher tiebreaker value than |lport|. Since |lport| has lower |
1260 // value of tiebreaker, when it receives ping request from |rport| it will | 1243 // value of tiebreaker, when it receives ping request from |rport| it will |
1261 // send role conflict signal. | 1244 // send role conflict signal. |
1262 TEST_F(PortTest, TestIceRoleConflict) { | 1245 TEST_F(PortTest, TestIceRoleConflict) { |
1263 rtc::scoped_ptr<TestPort> lport( | 1246 rtc::scoped_ptr<TestPort> lport( |
1264 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1247 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
1265 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
1266 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1248 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1267 lport->SetIceTiebreaker(kTiebreaker1); | 1249 lport->SetIceTiebreaker(kTiebreaker1); |
1268 rtc::scoped_ptr<TestPort> rport( | 1250 rtc::scoped_ptr<TestPort> rport( |
1269 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1251 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
1270 rport->SetIceProtocolType(ICEPROTO_RFC5245); | |
1271 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1252 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1272 rport->SetIceTiebreaker(kTiebreaker2); | 1253 rport->SetIceTiebreaker(kTiebreaker2); |
1273 | 1254 |
1274 lport->PrepareAddress(); | 1255 lport->PrepareAddress(); |
1275 rport->PrepareAddress(); | 1256 rport->PrepareAddress(); |
1276 ASSERT_FALSE(lport->Candidates().empty()); | 1257 ASSERT_FALSE(lport->Candidates().empty()); |
1277 ASSERT_FALSE(rport->Candidates().empty()); | 1258 ASSERT_FALSE(rport->Candidates().empty()); |
1278 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 1259 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
1279 Port::ORIGIN_MESSAGE); | 1260 Port::ORIGIN_MESSAGE); |
1280 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], | 1261 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], |
1281 Port::ORIGIN_MESSAGE); | 1262 Port::ORIGIN_MESSAGE); |
1282 rconn->Ping(0); | 1263 rconn->Ping(0); |
1283 | 1264 |
1284 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); | 1265 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); |
1285 IceMessage* msg = rport->last_stun_msg(); | 1266 IceMessage* msg = rport->last_stun_msg(); |
1286 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1267 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
1287 // Send rport binding request to lport. | 1268 // Send rport binding request to lport. |
1288 lconn->OnReadPacket(rport->last_stun_buf()->Data(), | 1269 lconn->OnReadPacket(rport->last_stun_buf()->Data(), |
1289 rport->last_stun_buf()->Length(), | 1270 rport->last_stun_buf()->Length(), |
1290 rtc::PacketTime()); | 1271 rtc::PacketTime()); |
1291 | 1272 |
1292 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1273 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
1293 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); | 1274 EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type()); |
1294 EXPECT_TRUE(role_conflict()); | 1275 EXPECT_TRUE(role_conflict()); |
1295 } | 1276 } |
1296 | 1277 |
1297 TEST_F(PortTest, TestTcpNoDelay) { | 1278 TEST_F(PortTest, TestTcpNoDelay) { |
1298 TCPPort* port1 = CreateTcpPort(kLocalAddr1); | 1279 TCPPort* port1 = CreateTcpPort(kLocalAddr1); |
| 1280 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1299 int option_value = -1; | 1281 int option_value = -1; |
1300 int success = port1->GetOption(rtc::Socket::OPT_NODELAY, | 1282 int success = port1->GetOption(rtc::Socket::OPT_NODELAY, |
1301 &option_value); | 1283 &option_value); |
1302 ASSERT_EQ(0, success); // GetOption() should complete successfully w/ 0 | 1284 ASSERT_EQ(0, success); // GetOption() should complete successfully w/ 0 |
1303 ASSERT_EQ(1, option_value); | 1285 ASSERT_EQ(1, option_value); |
1304 delete port1; | 1286 delete port1; |
1305 } | 1287 } |
1306 | 1288 |
1307 TEST_F(PortTest, TestDelayedBindingUdp) { | 1289 TEST_F(PortTest, TestDelayedBindingUdp) { |
1308 FakeAsyncPacketSocket *socket = new FakeAsyncPacketSocket(); | 1290 FakeAsyncPacketSocket *socket = new FakeAsyncPacketSocket(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 EXPECT_EQ(rtc::DSCP_CS7, dscp); | 1450 EXPECT_EQ(rtc::DSCP_CS7, dscp); |
1469 // This will verify correct value returned without the socket. | 1451 // This will verify correct value returned without the socket. |
1470 rtc::scoped_ptr<TurnPort> turnport2(CreateTurnPort( | 1452 rtc::scoped_ptr<TurnPort> turnport2(CreateTurnPort( |
1471 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 1453 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
1472 EXPECT_EQ(0, turnport2->SetOption(rtc::Socket::OPT_DSCP, | 1454 EXPECT_EQ(0, turnport2->SetOption(rtc::Socket::OPT_DSCP, |
1473 rtc::DSCP_CS6)); | 1455 rtc::DSCP_CS6)); |
1474 EXPECT_EQ(0, turnport2->GetOption(rtc::Socket::OPT_DSCP, &dscp)); | 1456 EXPECT_EQ(0, turnport2->GetOption(rtc::Socket::OPT_DSCP, &dscp)); |
1475 EXPECT_EQ(rtc::DSCP_CS6, dscp); | 1457 EXPECT_EQ(rtc::DSCP_CS6, dscp); |
1476 } | 1458 } |
1477 | 1459 |
1478 // Test sending STUN messages in GICE format. | 1460 // Test sending STUN messages. |
1479 TEST_F(PortTest, TestSendStunMessageAsGice) { | 1461 TEST_F(PortTest, TestSendStunMessage) { |
1480 rtc::scoped_ptr<TestPort> lport( | 1462 rtc::scoped_ptr<TestPort> lport( |
1481 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1463 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
1482 rtc::scoped_ptr<TestPort> rport( | 1464 rtc::scoped_ptr<TestPort> rport( |
1483 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1465 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
1484 lport->SetIceProtocolType(ICEPROTO_GOOGLE); | |
1485 rport->SetIceProtocolType(ICEPROTO_GOOGLE); | |
1486 | |
1487 // Send a fake ping from lport to rport. | |
1488 lport->PrepareAddress(); | |
1489 rport->PrepareAddress(); | |
1490 ASSERT_FALSE(rport->Candidates().empty()); | |
1491 Connection* conn = lport->CreateConnection(rport->Candidates()[0], | |
1492 Port::ORIGIN_MESSAGE); | |
1493 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); | |
1494 conn->Ping(0); | |
1495 | |
1496 // Check that it's a proper BINDING-REQUEST. | |
1497 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | |
1498 IceMessage* msg = lport->last_stun_msg(); | |
1499 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | |
1500 EXPECT_FALSE(msg->IsLegacy()); | |
1501 const StunByteStringAttribute* username_attr = msg->GetByteString( | |
1502 STUN_ATTR_USERNAME); | |
1503 ASSERT_TRUE(username_attr != NULL); | |
1504 EXPECT_EQ("rfraglfrag", username_attr->GetString()); | |
1505 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); | |
1506 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); | |
1507 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); | |
1508 | |
1509 // Save a copy of the BINDING-REQUEST for use below. | |
1510 rtc::scoped_ptr<IceMessage> request(CopyStunMessage(msg)); | |
1511 | |
1512 // Respond with a BINDING-RESPONSE. | |
1513 rport->SendBindingResponse(request.get(), lport->Candidates()[0].address()); | |
1514 msg = rport->last_stun_msg(); | |
1515 ASSERT_TRUE(msg != NULL); | |
1516 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); | |
1517 EXPECT_FALSE(msg->IsLegacy()); | |
1518 username_attr = msg->GetByteString(STUN_ATTR_USERNAME); | |
1519 ASSERT_TRUE(username_attr != NULL); // GICE has a username in the response. | |
1520 EXPECT_EQ("rfraglfrag", username_attr->GetString()); | |
1521 const StunAddressAttribute* addr_attr = msg->GetAddress( | |
1522 STUN_ATTR_MAPPED_ADDRESS); | |
1523 ASSERT_TRUE(addr_attr != NULL); | |
1524 EXPECT_EQ(lport->Candidates()[0].address(), addr_attr->GetAddress()); | |
1525 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_XOR_MAPPED_ADDRESS) == NULL); | |
1526 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); | |
1527 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); | |
1528 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); | |
1529 | |
1530 // Respond with a BINDING-ERROR-RESPONSE. This wouldn't happen in real life, | |
1531 // but we can do it here. | |
1532 rport->SendBindingErrorResponse(request.get(), | |
1533 rport->Candidates()[0].address(), | |
1534 STUN_ERROR_SERVER_ERROR, | |
1535 STUN_ERROR_REASON_SERVER_ERROR); | |
1536 msg = rport->last_stun_msg(); | |
1537 ASSERT_TRUE(msg != NULL); | |
1538 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, msg->type()); | |
1539 EXPECT_FALSE(msg->IsLegacy()); | |
1540 username_attr = msg->GetByteString(STUN_ATTR_USERNAME); | |
1541 ASSERT_TRUE(username_attr != NULL); // GICE has a username in the response. | |
1542 EXPECT_EQ("rfraglfrag", username_attr->GetString()); | |
1543 const StunErrorCodeAttribute* error_attr = msg->GetErrorCode(); | |
1544 ASSERT_TRUE(error_attr != NULL); | |
1545 // The GICE wire format for error codes is incorrect. | |
1546 EXPECT_EQ(STUN_ERROR_SERVER_ERROR_AS_GICE, error_attr->code()); | |
1547 EXPECT_EQ(STUN_ERROR_SERVER_ERROR / 256, error_attr->eclass()); | |
1548 EXPECT_EQ(STUN_ERROR_SERVER_ERROR % 256, error_attr->number()); | |
1549 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), error_attr->reason()); | |
1550 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); | |
1551 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); | |
1552 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); | |
1553 } | |
1554 | |
1555 // Test sending STUN messages in ICE format. | |
1556 TEST_F(PortTest, TestSendStunMessageAsIce) { | |
1557 rtc::scoped_ptr<TestPort> lport( | |
1558 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | |
1559 rtc::scoped_ptr<TestPort> rport( | |
1560 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
1561 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
1562 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1466 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1563 lport->SetIceTiebreaker(kTiebreaker1); | 1467 lport->SetIceTiebreaker(kTiebreaker1); |
1564 rport->SetIceProtocolType(ICEPROTO_RFC5245); | |
1565 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1468 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
1566 rport->SetIceTiebreaker(kTiebreaker2); | 1469 rport->SetIceTiebreaker(kTiebreaker2); |
1567 | 1470 |
1568 // Send a fake ping from lport to rport. | 1471 // Send a fake ping from lport to rport. |
1569 lport->PrepareAddress(); | 1472 lport->PrepareAddress(); |
1570 rport->PrepareAddress(); | 1473 rport->PrepareAddress(); |
1571 ASSERT_FALSE(rport->Candidates().empty()); | 1474 ASSERT_FALSE(rport->Candidates().empty()); |
1572 Connection* lconn = lport->CreateConnection( | 1475 Connection* lconn = lport->CreateConnection( |
1573 rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1476 rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
1574 Connection* rconn = rport->CreateConnection( | 1477 Connection* rconn = rport->CreateConnection( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 retransmit_attr = msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); | 1596 retransmit_attr = msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); |
1694 ASSERT_TRUE(retransmit_attr != NULL); | 1597 ASSERT_TRUE(retransmit_attr != NULL); |
1695 EXPECT_EQ(2U, retransmit_attr->value()); | 1598 EXPECT_EQ(2U, retransmit_attr->value()); |
1696 } | 1599 } |
1697 | 1600 |
1698 TEST_F(PortTest, TestUseCandidateAttribute) { | 1601 TEST_F(PortTest, TestUseCandidateAttribute) { |
1699 rtc::scoped_ptr<TestPort> lport( | 1602 rtc::scoped_ptr<TestPort> lport( |
1700 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1603 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
1701 rtc::scoped_ptr<TestPort> rport( | 1604 rtc::scoped_ptr<TestPort> rport( |
1702 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1605 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
1703 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
1704 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1606 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1705 lport->SetIceTiebreaker(kTiebreaker1); | 1607 lport->SetIceTiebreaker(kTiebreaker1); |
1706 rport->SetIceProtocolType(ICEPROTO_RFC5245); | |
1707 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1608 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
1708 rport->SetIceTiebreaker(kTiebreaker2); | 1609 rport->SetIceTiebreaker(kTiebreaker2); |
1709 | 1610 |
1710 // Send a fake ping from lport to rport. | 1611 // Send a fake ping from lport to rport. |
1711 lport->PrepareAddress(); | 1612 lport->PrepareAddress(); |
1712 rport->PrepareAddress(); | 1613 rport->PrepareAddress(); |
1713 ASSERT_FALSE(rport->Candidates().empty()); | 1614 ASSERT_FALSE(rport->Candidates().empty()); |
1714 Connection* lconn = lport->CreateConnection( | 1615 Connection* lconn = lport->CreateConnection( |
1715 rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1616 rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
1716 lconn->Ping(0); | 1617 lconn->Ping(0); |
1717 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1618 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
1718 IceMessage* msg = lport->last_stun_msg(); | 1619 IceMessage* msg = lport->last_stun_msg(); |
1719 const StunUInt64Attribute* ice_controlling_attr = | 1620 const StunUInt64Attribute* ice_controlling_attr = |
1720 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); | 1621 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); |
1721 ASSERT_TRUE(ice_controlling_attr != NULL); | 1622 ASSERT_TRUE(ice_controlling_attr != NULL); |
1722 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( | 1623 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( |
1723 STUN_ATTR_USE_CANDIDATE); | 1624 STUN_ATTR_USE_CANDIDATE); |
1724 ASSERT_TRUE(use_candidate_attr != NULL); | 1625 ASSERT_TRUE(use_candidate_attr != NULL); |
1725 } | 1626 } |
1726 | 1627 |
1727 // Test handling STUN messages in GICE format. | 1628 // Test handling STUN messages. |
1728 TEST_F(PortTest, TestHandleStunMessageAsGice) { | 1629 TEST_F(PortTest, TestHandleStunMessage) { |
1729 // Our port will act as the "remote" port. | 1630 // Our port will act as the "remote" port. |
1730 rtc::scoped_ptr<TestPort> port( | 1631 rtc::scoped_ptr<TestPort> port( |
1731 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1632 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
1732 port->SetIceProtocolType(ICEPROTO_GOOGLE); | |
1733 | 1633 |
1734 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1634 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
1735 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1635 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
1736 rtc::SocketAddress addr(kLocalAddr1); | |
1737 std::string username; | |
1738 | |
1739 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. | |
1740 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
1741 "rfraglfrag")); | |
1742 WriteStunMessage(in_msg.get(), buf.get()); | |
1743 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1744 out_msg.accept(), &username)); | |
1745 EXPECT_TRUE(out_msg.get() != NULL); // Succeeds, since this is GICE. | |
1746 EXPECT_EQ("lfrag", username); | |
1747 | |
1748 // Add M-I; should be ignored and rest of message parsed normally. | |
1749 in_msg->AddMessageIntegrity("password"); | |
1750 WriteStunMessage(in_msg.get(), buf.get()); | |
1751 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1752 out_msg.accept(), &username)); | |
1753 EXPECT_TRUE(out_msg.get() != NULL); | |
1754 EXPECT_EQ("lfrag", username); | |
1755 | |
1756 // BINDING-RESPONSE with username, as done in GICE. Should succeed. | |
1757 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_RESPONSE, | |
1758 "rfraglfrag")); | |
1759 in_msg->AddAttribute( | |
1760 new StunAddressAttribute(STUN_ATTR_MAPPED_ADDRESS, kLocalAddr2)); | |
1761 WriteStunMessage(in_msg.get(), buf.get()); | |
1762 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1763 out_msg.accept(), &username)); | |
1764 EXPECT_TRUE(out_msg.get() != NULL); | |
1765 EXPECT_EQ("", username); | |
1766 | |
1767 // BINDING-RESPONSE without username. Should be tolerated as well. | |
1768 in_msg.reset(CreateStunMessage(STUN_BINDING_RESPONSE)); | |
1769 in_msg->AddAttribute( | |
1770 new StunAddressAttribute(STUN_ATTR_MAPPED_ADDRESS, kLocalAddr2)); | |
1771 WriteStunMessage(in_msg.get(), buf.get()); | |
1772 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1773 out_msg.accept(), &username)); | |
1774 EXPECT_TRUE(out_msg.get() != NULL); | |
1775 EXPECT_EQ("", username); | |
1776 | |
1777 // BINDING-ERROR-RESPONSE with username and error code. | |
1778 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_ERROR_RESPONSE, | |
1779 "rfraglfrag")); | |
1780 in_msg->AddAttribute(new StunErrorCodeAttribute(STUN_ATTR_ERROR_CODE, | |
1781 STUN_ERROR_SERVER_ERROR_AS_GICE, STUN_ERROR_REASON_SERVER_ERROR)); | |
1782 WriteStunMessage(in_msg.get(), buf.get()); | |
1783 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1784 out_msg.accept(), &username)); | |
1785 ASSERT_TRUE(out_msg.get() != NULL); | |
1786 EXPECT_EQ("", username); | |
1787 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); | |
1788 // GetStunMessage doesn't unmunge the GICE error code (happens downstream). | |
1789 EXPECT_EQ(STUN_ERROR_SERVER_ERROR_AS_GICE, out_msg->GetErrorCode()->code()); | |
1790 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), | |
1791 out_msg->GetErrorCode()->reason()); | |
1792 } | |
1793 | |
1794 // Test handling STUN messages in ICE format. | |
1795 TEST_F(PortTest, TestHandleStunMessageAsIce) { | |
1796 // Our port will act as the "remote" port. | |
1797 rtc::scoped_ptr<TestPort> port( | |
1798 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
1799 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
1800 | |
1801 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
1802 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
1803 rtc::SocketAddress addr(kLocalAddr1); | 1636 rtc::SocketAddress addr(kLocalAddr1); |
1804 std::string username; | 1637 std::string username; |
1805 | 1638 |
1806 // BINDING-REQUEST from local to remote with valid ICE username, | 1639 // BINDING-REQUEST from local to remote with valid ICE username, |
1807 // MESSAGE-INTEGRITY, and FINGERPRINT. | 1640 // MESSAGE-INTEGRITY, and FINGERPRINT. |
1808 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 1641 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
1809 "rfrag:lfrag")); | 1642 "rfrag:lfrag")); |
1810 in_msg->AddMessageIntegrity("rpass"); | 1643 in_msg->AddMessageIntegrity("rpass"); |
1811 in_msg->AddFingerprint(); | 1644 in_msg->AddFingerprint(); |
1812 WriteStunMessage(in_msg.get(), buf.get()); | 1645 WriteStunMessage(in_msg.get(), buf.get()); |
(...skipping 23 matching lines...) Expand all Loading... |
1836 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1669 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
1837 out_msg.accept(), &username)); | 1670 out_msg.accept(), &username)); |
1838 EXPECT_TRUE(out_msg.get() != NULL); | 1671 EXPECT_TRUE(out_msg.get() != NULL); |
1839 EXPECT_EQ("", username); | 1672 EXPECT_EQ("", username); |
1840 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); | 1673 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); |
1841 EXPECT_EQ(STUN_ERROR_SERVER_ERROR, out_msg->GetErrorCode()->code()); | 1674 EXPECT_EQ(STUN_ERROR_SERVER_ERROR, out_msg->GetErrorCode()->code()); |
1842 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), | 1675 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), |
1843 out_msg->GetErrorCode()->reason()); | 1676 out_msg->GetErrorCode()->reason()); |
1844 } | 1677 } |
1845 | 1678 |
1846 // This test verifies port can handle ICE messages in Hybrid mode and switches | 1679 // Tests handling of ICE binding requests with missing or incorrect usernames. |
1847 // ICEPROTO_RFC5245 mode after successfully handling the message. | 1680 TEST_F(PortTest, TestHandleStunMessageBadUsername) { |
1848 TEST_F(PortTest, TestHandleStunMessageAsIceInHybridMode) { | |
1849 // Our port will act as the "remote" port. | |
1850 rtc::scoped_ptr<TestPort> port( | 1681 rtc::scoped_ptr<TestPort> port( |
1851 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1682 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
1852 port->SetIceProtocolType(ICEPROTO_HYBRID); | |
1853 | 1683 |
1854 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1684 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
1855 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1685 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
1856 rtc::SocketAddress addr(kLocalAddr1); | |
1857 std::string username; | |
1858 | |
1859 // BINDING-REQUEST from local to remote with valid ICE username, | |
1860 // MESSAGE-INTEGRITY, and FINGERPRINT. | |
1861 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
1862 "rfrag:lfrag")); | |
1863 in_msg->AddMessageIntegrity("rpass"); | |
1864 in_msg->AddFingerprint(); | |
1865 WriteStunMessage(in_msg.get(), buf.get()); | |
1866 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1867 out_msg.accept(), &username)); | |
1868 EXPECT_TRUE(out_msg.get() != NULL); | |
1869 EXPECT_EQ("lfrag", username); | |
1870 EXPECT_EQ(ICEPROTO_RFC5245, port->IceProtocol()); | |
1871 } | |
1872 | |
1873 // This test verifies port can handle GICE messages in Hybrid mode and switches | |
1874 // ICEPROTO_GOOGLE mode after successfully handling the message. | |
1875 TEST_F(PortTest, TestHandleStunMessageAsGiceInHybridMode) { | |
1876 // Our port will act as the "remote" port. | |
1877 rtc::scoped_ptr<TestPort> port( | |
1878 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
1879 port->SetIceProtocolType(ICEPROTO_HYBRID); | |
1880 | |
1881 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
1882 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
1883 rtc::SocketAddress addr(kLocalAddr1); | |
1884 std::string username; | |
1885 | |
1886 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. | |
1887 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
1888 "rfraglfrag")); | |
1889 WriteStunMessage(in_msg.get(), buf.get()); | |
1890 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1891 out_msg.accept(), &username)); | |
1892 EXPECT_TRUE(out_msg.get() != NULL); // Succeeds, since this is GICE. | |
1893 EXPECT_EQ("lfrag", username); | |
1894 EXPECT_EQ(ICEPROTO_GOOGLE, port->IceProtocol()); | |
1895 } | |
1896 | |
1897 // Verify port is not switched out of RFC5245 mode if GICE message is received | |
1898 // in that mode. | |
1899 TEST_F(PortTest, TestHandleStunMessageAsGiceInIceMode) { | |
1900 // Our port will act as the "remote" port. | |
1901 rtc::scoped_ptr<TestPort> port( | |
1902 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
1903 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
1904 | |
1905 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
1906 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
1907 rtc::SocketAddress addr(kLocalAddr1); | |
1908 std::string username; | |
1909 | |
1910 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. | |
1911 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
1912 "rfraglfrag")); | |
1913 WriteStunMessage(in_msg.get(), buf.get()); | |
1914 // Should fail as there is no MI and fingerprint. | |
1915 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1916 out_msg.accept(), &username)); | |
1917 EXPECT_EQ(ICEPROTO_RFC5245, port->IceProtocol()); | |
1918 } | |
1919 | |
1920 | |
1921 // Tests handling of GICE binding requests with missing or incorrect usernames. | |
1922 TEST_F(PortTest, TestHandleStunMessageAsGiceBadUsername) { | |
1923 rtc::scoped_ptr<TestPort> port( | |
1924 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
1925 port->SetIceProtocolType(ICEPROTO_GOOGLE); | |
1926 | |
1927 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
1928 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
1929 rtc::SocketAddress addr(kLocalAddr1); | |
1930 std::string username; | |
1931 | |
1932 // BINDING-REQUEST with no username. | |
1933 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); | |
1934 WriteStunMessage(in_msg.get(), buf.get()); | |
1935 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1936 out_msg.accept(), &username)); | |
1937 EXPECT_TRUE(out_msg.get() == NULL); | |
1938 EXPECT_EQ("", username); | |
1939 EXPECT_EQ(STUN_ERROR_BAD_REQUEST_AS_GICE, port->last_stun_error_code()); | |
1940 | |
1941 // BINDING-REQUEST with empty username. | |
1942 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, "")); | |
1943 WriteStunMessage(in_msg.get(), buf.get()); | |
1944 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1945 out_msg.accept(), &username)); | |
1946 EXPECT_TRUE(out_msg.get() == NULL); | |
1947 EXPECT_EQ("", username); | |
1948 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); | |
1949 | |
1950 // BINDING-REQUEST with too-short username. | |
1951 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, "lfra")); | |
1952 WriteStunMessage(in_msg.get(), buf.get()); | |
1953 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1954 out_msg.accept(), &username)); | |
1955 EXPECT_TRUE(out_msg.get() == NULL); | |
1956 EXPECT_EQ("", username); | |
1957 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); | |
1958 | |
1959 // BINDING-REQUEST with reversed username. | |
1960 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
1961 "lfragrfrag")); | |
1962 WriteStunMessage(in_msg.get(), buf.get()); | |
1963 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1964 out_msg.accept(), &username)); | |
1965 EXPECT_TRUE(out_msg.get() == NULL); | |
1966 EXPECT_EQ("", username); | |
1967 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); | |
1968 | |
1969 // BINDING-REQUEST with garbage username. | |
1970 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
1971 "abcdefgh")); | |
1972 WriteStunMessage(in_msg.get(), buf.get()); | |
1973 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
1974 out_msg.accept(), &username)); | |
1975 EXPECT_TRUE(out_msg.get() == NULL); | |
1976 EXPECT_EQ("", username); | |
1977 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); | |
1978 } | |
1979 | |
1980 // Tests handling of ICE binding requests with missing or incorrect usernames. | |
1981 TEST_F(PortTest, TestHandleStunMessageAsIceBadUsername) { | |
1982 rtc::scoped_ptr<TestPort> port( | |
1983 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
1984 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
1985 | |
1986 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
1987 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
1988 rtc::SocketAddress addr(kLocalAddr1); | 1686 rtc::SocketAddress addr(kLocalAddr1); |
1989 std::string username; | 1687 std::string username; |
1990 | 1688 |
1991 // BINDING-REQUEST with no username. | 1689 // BINDING-REQUEST with no username. |
1992 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); | 1690 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); |
1993 in_msg->AddMessageIntegrity("rpass"); | 1691 in_msg->AddMessageIntegrity("rpass"); |
1994 in_msg->AddFingerprint(); | 1692 in_msg->AddFingerprint(); |
1995 WriteStunMessage(in_msg.get(), buf.get()); | 1693 WriteStunMessage(in_msg.get(), buf.get()); |
1996 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1694 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
1997 out_msg.accept(), &username)); | 1695 out_msg.accept(), &username)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 in_msg->AddMessageIntegrity("rpass"); | 1737 in_msg->AddMessageIntegrity("rpass"); |
2040 in_msg->AddFingerprint(); | 1738 in_msg->AddFingerprint(); |
2041 WriteStunMessage(in_msg.get(), buf.get()); | 1739 WriteStunMessage(in_msg.get(), buf.get()); |
2042 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1740 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
2043 out_msg.accept(), &username)); | 1741 out_msg.accept(), &username)); |
2044 EXPECT_TRUE(out_msg.get() == NULL); | 1742 EXPECT_TRUE(out_msg.get() == NULL); |
2045 EXPECT_EQ("", username); | 1743 EXPECT_EQ("", username); |
2046 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); | 1744 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); |
2047 } | 1745 } |
2048 | 1746 |
2049 // Test handling STUN messages (as ICE) with missing or malformed M-I. | 1747 // Test handling STUN messages with missing or malformed M-I. |
2050 TEST_F(PortTest, TestHandleStunMessageAsIceBadMessageIntegrity) { | 1748 TEST_F(PortTest, TestHandleStunMessageBadMessageIntegrity) { |
2051 // Our port will act as the "remote" port. | 1749 // Our port will act as the "remote" port. |
2052 rtc::scoped_ptr<TestPort> port( | 1750 rtc::scoped_ptr<TestPort> port( |
2053 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1751 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
2054 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
2055 | 1752 |
2056 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1753 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
2057 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1754 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
2058 rtc::SocketAddress addr(kLocalAddr1); | 1755 rtc::SocketAddress addr(kLocalAddr1); |
2059 std::string username; | 1756 std::string username; |
2060 | 1757 |
2061 // BINDING-REQUEST from local to remote with valid ICE username and | 1758 // BINDING-REQUEST from local to remote with valid ICE username and |
2062 // FINGERPRINT, but no MESSAGE-INTEGRITY. | 1759 // FINGERPRINT, but no MESSAGE-INTEGRITY. |
2063 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 1760 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
2064 "rfrag:lfrag")); | 1761 "rfrag:lfrag")); |
(...skipping 16 matching lines...) Expand all Loading... |
2081 out_msg.accept(), &username)); | 1778 out_msg.accept(), &username)); |
2082 EXPECT_TRUE(out_msg.get() == NULL); | 1779 EXPECT_TRUE(out_msg.get() == NULL); |
2083 EXPECT_EQ("", username); | 1780 EXPECT_EQ("", username); |
2084 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); | 1781 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); |
2085 | 1782 |
2086 // TODO: BINDING-RESPONSES and BINDING-ERROR-RESPONSES are checked | 1783 // TODO: BINDING-RESPONSES and BINDING-ERROR-RESPONSES are checked |
2087 // by the Connection, not the Port, since they require the remote username. | 1784 // by the Connection, not the Port, since they require the remote username. |
2088 // Change this test to pass in data via Connection::OnReadPacket instead. | 1785 // Change this test to pass in data via Connection::OnReadPacket instead. |
2089 } | 1786 } |
2090 | 1787 |
2091 // Test handling STUN messages (as ICE) with missing or malformed FINGERPRINT. | 1788 // Test handling STUN messages with missing or malformed FINGERPRINT. |
2092 TEST_F(PortTest, TestHandleStunMessageAsIceBadFingerprint) { | 1789 TEST_F(PortTest, TestHandleStunMessageBadFingerprint) { |
2093 // Our port will act as the "remote" port. | 1790 // Our port will act as the "remote" port. |
2094 rtc::scoped_ptr<TestPort> port( | 1791 rtc::scoped_ptr<TestPort> port( |
2095 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1792 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
2096 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
2097 | 1793 |
2098 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1794 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
2099 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1795 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
2100 rtc::SocketAddress addr(kLocalAddr1); | 1796 rtc::SocketAddress addr(kLocalAddr1); |
2101 std::string username; | 1797 std::string username; |
2102 | 1798 |
2103 // BINDING-REQUEST from local to remote with valid ICE username and | 1799 // BINDING-REQUEST from local to remote with valid ICE username and |
2104 // MESSAGE-INTEGRITY, but no FINGERPRINT; GetStunMessage should fail. | 1800 // MESSAGE-INTEGRITY, but no FINGERPRINT; GetStunMessage should fail. |
2105 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 1801 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
2106 "rfrag:lfrag")); | 1802 "rfrag:lfrag")); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 | 1844 |
2149 // Now, add a fingerprint, but munge the message so it's not valid. | 1845 // Now, add a fingerprint, but munge the message so it's not valid. |
2150 in_msg->AddFingerprint(); | 1846 in_msg->AddFingerprint(); |
2151 in_msg->SetTransactionID("TESTTESTBADD"); | 1847 in_msg->SetTransactionID("TESTTESTBADD"); |
2152 WriteStunMessage(in_msg.get(), buf.get()); | 1848 WriteStunMessage(in_msg.get(), buf.get()); |
2153 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1849 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
2154 out_msg.accept(), &username)); | 1850 out_msg.accept(), &username)); |
2155 EXPECT_EQ(0, port->last_stun_error_code()); | 1851 EXPECT_EQ(0, port->last_stun_error_code()); |
2156 } | 1852 } |
2157 | 1853 |
2158 // Test handling of STUN binding indication messages (as ICE). STUN binding | 1854 // Test handling of STUN binding indication messages . STUN binding |
2159 // indications are allowed only to the connection which is in read mode. | 1855 // indications are allowed only to the connection which is in read mode. |
2160 TEST_F(PortTest, TestHandleStunBindingIndication) { | 1856 TEST_F(PortTest, TestHandleStunBindingIndication) { |
2161 rtc::scoped_ptr<TestPort> lport( | 1857 rtc::scoped_ptr<TestPort> lport( |
2162 CreateTestPort(kLocalAddr2, "lfrag", "lpass")); | 1858 CreateTestPort(kLocalAddr2, "lfrag", "lpass")); |
2163 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
2164 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1859 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
2165 lport->SetIceTiebreaker(kTiebreaker1); | 1860 lport->SetIceTiebreaker(kTiebreaker1); |
2166 | 1861 |
2167 // Verifying encoding and decoding STUN indication message. | 1862 // Verifying encoding and decoding STUN indication message. |
2168 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1863 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
2169 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1864 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
2170 rtc::SocketAddress addr(kLocalAddr1); | 1865 rtc::SocketAddress addr(kLocalAddr1); |
2171 std::string username; | 1866 std::string username; |
2172 | 1867 |
2173 in_msg.reset(CreateStunMessage(STUN_BINDING_INDICATION)); | 1868 in_msg.reset(CreateStunMessage(STUN_BINDING_INDICATION)); |
2174 in_msg->AddFingerprint(); | 1869 in_msg->AddFingerprint(); |
2175 WriteStunMessage(in_msg.get(), buf.get()); | 1870 WriteStunMessage(in_msg.get(), buf.get()); |
2176 EXPECT_TRUE(lport->GetStunMessage(buf->Data(), buf->Length(), addr, | 1871 EXPECT_TRUE(lport->GetStunMessage(buf->Data(), buf->Length(), addr, |
2177 out_msg.accept(), &username)); | 1872 out_msg.accept(), &username)); |
2178 EXPECT_TRUE(out_msg.get() != NULL); | 1873 EXPECT_TRUE(out_msg.get() != NULL); |
2179 EXPECT_EQ(out_msg->type(), STUN_BINDING_INDICATION); | 1874 EXPECT_EQ(out_msg->type(), STUN_BINDING_INDICATION); |
2180 EXPECT_EQ("", username); | 1875 EXPECT_EQ("", username); |
2181 | 1876 |
2182 // Verify connection can handle STUN indication and updates | 1877 // Verify connection can handle STUN indication and updates |
2183 // last_ping_received. | 1878 // last_ping_received. |
2184 rtc::scoped_ptr<TestPort> rport( | 1879 rtc::scoped_ptr<TestPort> rport( |
2185 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1880 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
2186 rport->SetIceProtocolType(ICEPROTO_RFC5245); | |
2187 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1881 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
2188 rport->SetIceTiebreaker(kTiebreaker2); | 1882 rport->SetIceTiebreaker(kTiebreaker2); |
2189 | 1883 |
2190 lport->PrepareAddress(); | 1884 lport->PrepareAddress(); |
2191 rport->PrepareAddress(); | 1885 rport->PrepareAddress(); |
2192 ASSERT_FALSE(lport->Candidates().empty()); | 1886 ASSERT_FALSE(lport->Candidates().empty()); |
2193 ASSERT_FALSE(rport->Candidates().empty()); | 1887 ASSERT_FALSE(rport->Candidates().empty()); |
2194 | 1888 |
2195 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 1889 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
2196 Port::ORIGIN_MESSAGE); | 1890 Port::ORIGIN_MESSAGE); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2379 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 2073 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
2380 turnport->PrepareAddress(); | 2074 turnport->PrepareAddress(); |
2381 ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kTimeout); | 2075 ASSERT_EQ_WAIT(1U, turnport->Candidates().size(), kTimeout); |
2382 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), | 2076 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), |
2383 turnport->Candidates()[0].address().ipaddr()); | 2077 turnport->Candidates()[0].address().ipaddr()); |
2384 EXPECT_EQ(kNatAddr1.ipaddr(), | 2078 EXPECT_EQ(kNatAddr1.ipaddr(), |
2385 turnport->Candidates()[0].related_address().ipaddr()); | 2079 turnport->Candidates()[0].related_address().ipaddr()); |
2386 } | 2080 } |
2387 | 2081 |
2388 // Test priority value overflow handling when preference is set to 3. | 2082 // Test priority value overflow handling when preference is set to 3. |
2389 TEST_F(PortTest, TestCandidatePreference) { | 2083 TEST_F(PortTest, TestCandidatePriority) { |
2390 cricket::Candidate cand1; | 2084 cricket::Candidate cand1; |
2391 cand1.set_preference(3); | 2085 cand1.set_priority(3); |
2392 cricket::Candidate cand2; | 2086 cricket::Candidate cand2; |
2393 cand2.set_preference(1); | 2087 cand2.set_priority(1); |
2394 EXPECT_TRUE(cand1.preference() > cand2.preference()); | 2088 EXPECT_TRUE(cand1.priority() > cand2.priority()); |
2395 } | 2089 } |
2396 | 2090 |
2397 // Test the Connection priority is calculated correctly. | 2091 // Test the Connection priority is calculated correctly. |
2398 TEST_F(PortTest, TestConnectionPriority) { | 2092 TEST_F(PortTest, TestConnectionPriority) { |
2399 rtc::scoped_ptr<TestPort> lport( | 2093 rtc::scoped_ptr<TestPort> lport( |
2400 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 2094 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
2401 lport->set_type_preference(cricket::ICE_TYPE_PREFERENCE_HOST); | 2095 lport->set_type_preference(cricket::ICE_TYPE_PREFERENCE_HOST); |
2402 rtc::scoped_ptr<TestPort> rport( | 2096 rtc::scoped_ptr<TestPort> rport( |
2403 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 2097 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
2404 rport->set_type_preference(cricket::ICE_TYPE_PREFERENCE_RELAY); | 2098 rport->set_type_preference(cricket::ICE_TYPE_PREFERENCE_RELAY); |
(...skipping 23 matching lines...) Expand all Loading... |
2428 lport->Candidates()[0], Port::ORIGIN_MESSAGE); | 2122 lport->Candidates()[0], Port::ORIGIN_MESSAGE); |
2429 #if defined(WEBRTC_WIN) | 2123 #if defined(WEBRTC_WIN) |
2430 EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority()); | 2124 EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority()); |
2431 #else | 2125 #else |
2432 EXPECT_EQ(0x2001EE9FC003D0ALLU, rconn->priority()); | 2126 EXPECT_EQ(0x2001EE9FC003D0ALLU, rconn->priority()); |
2433 #endif | 2127 #endif |
2434 } | 2128 } |
2435 | 2129 |
2436 TEST_F(PortTest, TestWritableState) { | 2130 TEST_F(PortTest, TestWritableState) { |
2437 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2131 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2132 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
2438 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2133 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2134 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
2439 | 2135 |
2440 // Set up channels. | 2136 // Set up channels. |
2441 TestChannel ch1(port1, port2); | 2137 TestChannel ch1(port1, port2); |
2442 TestChannel ch2(port2, port1); | 2138 TestChannel ch2(port2, port1); |
2443 | 2139 |
2444 // Acquire addresses. | 2140 // Acquire addresses. |
2445 ch1.Start(); | 2141 ch1.Start(); |
2446 ch2.Start(); | 2142 ch2.Start(); |
2447 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2143 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
2448 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); | 2144 ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2497 | 2193 |
2498 // Now that the connection has completely timed out, data send should fail. | 2194 // Now that the connection has completely timed out, data send should fail. |
2499 EXPECT_EQ(SOCKET_ERROR, ch1.conn()->Send(data, data_size, options)); | 2195 EXPECT_EQ(SOCKET_ERROR, ch1.conn()->Send(data, data_size, options)); |
2500 | 2196 |
2501 ch1.Stop(); | 2197 ch1.Stop(); |
2502 ch2.Stop(); | 2198 ch2.Stop(); |
2503 } | 2199 } |
2504 | 2200 |
2505 TEST_F(PortTest, TestTimeoutForNeverWritable) { | 2201 TEST_F(PortTest, TestTimeoutForNeverWritable) { |
2506 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2202 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2203 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
2507 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2204 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2205 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
2508 | 2206 |
2509 // Set up channels. | 2207 // Set up channels. |
2510 TestChannel ch1(port1, port2); | 2208 TestChannel ch1(port1, port2); |
2511 TestChannel ch2(port2, port1); | 2209 TestChannel ch2(port2, port1); |
2512 | 2210 |
2513 // Acquire addresses. | 2211 // Acquire addresses. |
2514 ch1.Start(); | 2212 ch1.Start(); |
2515 ch2.Start(); | 2213 ch2.Start(); |
2516 | 2214 |
2517 ch1.CreateConnection(); | 2215 ch1.CreateConnection(); |
2518 ASSERT_TRUE(ch1.conn() != NULL); | 2216 ASSERT_TRUE(ch1.conn() != NULL); |
2519 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); | 2217 EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state()); |
2520 | 2218 |
2521 // Attempt to go directly to write timeout. | 2219 // Attempt to go directly to write timeout. |
2522 for (uint32 i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { | 2220 for (uint32 i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) { |
2523 ch1.Ping(i); | 2221 ch1.Ping(i); |
2524 } | 2222 } |
2525 ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + 500u); | 2223 ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + 500u); |
2526 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); | 2224 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); |
2527 } | 2225 } |
2528 | 2226 |
2529 // This test verifies the connection setup between ICEMODE_FULL | 2227 // This test verifies the connection setup between ICEMODE_FULL |
2530 // and ICEMODE_LITE. | 2228 // and ICEMODE_LITE. |
2531 // In this test |ch1| behaves like FULL mode client and we have created | 2229 // In this test |ch1| behaves like FULL mode client and we have created |
2532 // port which responds to the ping message just like LITE client. | 2230 // port which responds to the ping message just like LITE client. |
2533 TEST_F(PortTest, TestIceLiteConnectivity) { | 2231 TEST_F(PortTest, TestIceLiteConnectivity) { |
2534 TestPort* ice_full_port = CreateTestPort( | 2232 TestPort* ice_full_port = CreateTestPort( |
2535 kLocalAddr1, "lfrag", "lpass", cricket::ICEPROTO_RFC5245, | 2233 kLocalAddr1, "lfrag", "lpass", |
2536 cricket::ICEROLE_CONTROLLING, kTiebreaker1); | 2234 cricket::ICEROLE_CONTROLLING, kTiebreaker1); |
2537 | 2235 |
2538 rtc::scoped_ptr<TestPort> ice_lite_port(CreateTestPort( | 2236 rtc::scoped_ptr<TestPort> ice_lite_port(CreateTestPort( |
2539 kLocalAddr2, "rfrag", "rpass", cricket::ICEPROTO_RFC5245, | 2237 kLocalAddr2, "rfrag", "rpass", |
2540 cricket::ICEROLE_CONTROLLED, kTiebreaker2)); | 2238 cricket::ICEROLE_CONTROLLED, kTiebreaker2)); |
2541 // Setup TestChannel. This behaves like FULL mode client. | 2239 // Setup TestChannel. This behaves like FULL mode client. |
2542 TestChannel ch1(ice_full_port, ice_lite_port.get()); | 2240 TestChannel ch1(ice_full_port, ice_lite_port.get()); |
2543 ch1.SetIceMode(ICEMODE_FULL); | 2241 ch1.SetIceMode(ICEMODE_FULL); |
2544 | 2242 |
2545 // Start gathering candidates. | 2243 // Start gathering candidates. |
2546 ch1.Start(); | 2244 ch1.Start(); |
2547 ice_lite_port->PrepareAddress(); | 2245 ice_lite_port->PrepareAddress(); |
2548 | 2246 |
2549 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2247 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2588 // Send ping. This must have USE_CANDIDATE_ATTR. | 2286 // Send ping. This must have USE_CANDIDATE_ATTR. |
2589 ch1.Ping(); | 2287 ch1.Ping(); |
2590 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); | 2288 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); |
2591 msg = ice_full_port->last_stun_msg(); | 2289 msg = ice_full_port->last_stun_msg(); |
2592 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); | 2290 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); |
2593 ch1.Stop(); | 2291 ch1.Stop(); |
2594 } | 2292 } |
2595 | 2293 |
2596 // This test case verifies that the CONTROLLING port does not time out. | 2294 // This test case verifies that the CONTROLLING port does not time out. |
2597 TEST_F(PortTest, TestControllingNoTimeout) { | 2295 TEST_F(PortTest, TestControllingNoTimeout) { |
2598 SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
2599 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2296 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
2600 ConnectToSignalDestroyed(port1); | 2297 ConnectToSignalDestroyed(port1); |
2601 port1->set_timeout_delay(10); // milliseconds | 2298 port1->set_timeout_delay(10); // milliseconds |
2602 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2299 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
2603 port1->SetIceTiebreaker(kTiebreaker1); | 2300 port1->SetIceTiebreaker(kTiebreaker1); |
2604 | 2301 |
2605 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2302 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
2606 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2303 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
2607 port2->SetIceTiebreaker(kTiebreaker2); | 2304 port2->SetIceTiebreaker(kTiebreaker2); |
2608 | 2305 |
2609 // Set up channels and ensure both ports will be deleted. | 2306 // Set up channels and ensure both ports will be deleted. |
2610 TestChannel ch1(port1, port2); | 2307 TestChannel ch1(port1, port2); |
2611 TestChannel ch2(port2, port1); | 2308 TestChannel ch2(port2, port1); |
2612 | 2309 |
2613 // Simulate a connection that succeeds, and then is destroyed. | 2310 // Simulate a connection that succeeds, and then is destroyed. |
2614 StartConnectAndStopChannels(&ch1, &ch2); | 2311 StartConnectAndStopChannels(&ch1, &ch2); |
2615 | 2312 |
2616 // After the connection is destroyed, the port should not be destroyed. | 2313 // After the connection is destroyed, the port should not be destroyed. |
2617 rtc::Thread::Current()->ProcessMessages(kTimeout); | 2314 rtc::Thread::Current()->ProcessMessages(kTimeout); |
2618 EXPECT_FALSE(destroyed()); | 2315 EXPECT_FALSE(destroyed()); |
2619 } | 2316 } |
2620 | 2317 |
2621 // This test case verifies that the CONTROLLED port does time out, but only | 2318 // This test case verifies that the CONTROLLED port does time out, but only |
2622 // after connectivity is lost. | 2319 // after connectivity is lost. |
2623 TEST_F(PortTest, TestControlledTimeout) { | 2320 TEST_F(PortTest, TestControlledTimeout) { |
2624 SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
2625 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2321 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
2626 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2322 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
2627 port1->SetIceTiebreaker(kTiebreaker1); | 2323 port1->SetIceTiebreaker(kTiebreaker1); |
2628 | 2324 |
2629 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2325 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
2630 ConnectToSignalDestroyed(port2); | 2326 ConnectToSignalDestroyed(port2); |
2631 port2->set_timeout_delay(10); // milliseconds | 2327 port2->set_timeout_delay(10); // milliseconds |
2632 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2328 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
2633 port2->SetIceTiebreaker(kTiebreaker2); | 2329 port2->SetIceTiebreaker(kTiebreaker2); |
2634 | 2330 |
2635 // The connection must not be destroyed before a connection is attempted. | 2331 // The connection must not be destroyed before a connection is attempted. |
2636 EXPECT_FALSE(destroyed()); | 2332 EXPECT_FALSE(destroyed()); |
2637 | 2333 |
2638 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 2334 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
2639 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 2335 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
2640 | 2336 |
2641 // Set up channels and ensure both ports will be deleted. | 2337 // Set up channels and ensure both ports will be deleted. |
2642 TestChannel ch1(port1, port2); | 2338 TestChannel ch1(port1, port2); |
2643 TestChannel ch2(port2, port1); | 2339 TestChannel ch2(port2, port1); |
2644 | 2340 |
2645 // Simulate a connection that succeeds, and then is destroyed. | 2341 // Simulate a connection that succeeds, and then is destroyed. |
2646 StartConnectAndStopChannels(&ch1, &ch2); | 2342 StartConnectAndStopChannels(&ch1, &ch2); |
2647 | 2343 |
2648 // The controlled port should be destroyed after 10 milliseconds. | 2344 // The controlled port should be destroyed after 10 milliseconds. |
2649 EXPECT_TRUE_WAIT(destroyed(), kTimeout); | 2345 EXPECT_TRUE_WAIT(destroyed(), kTimeout); |
2650 } | 2346 } |
OLD | NEW |