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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 SocketAddress remote_address_; | 374 SocketAddress remote_address_; |
375 std::unique_ptr<StunMessage> remote_request_; | 375 std::unique_ptr<StunMessage> remote_request_; |
376 std::string remote_frag_; | 376 std::string remote_frag_; |
377 bool nominated_; | 377 bool nominated_; |
378 bool connection_ready_to_send_ = false; | 378 bool connection_ready_to_send_ = false; |
379 }; | 379 }; |
380 | 380 |
381 class PortTest : public testing::Test, public sigslot::has_slots<> { | 381 class PortTest : public testing::Test, public sigslot::has_slots<> { |
382 public: | 382 public: |
383 PortTest() | 383 PortTest() |
384 : main_(rtc::Thread::Current()), | 384 : pss_(new rtc::PhysicalSocketServer), |
385 pss_(new rtc::PhysicalSocketServer), | |
386 ss_(new rtc::VirtualSocketServer(pss_.get())), | 385 ss_(new rtc::VirtualSocketServer(pss_.get())), |
387 ss_scope_(ss_.get()), | 386 main_(ss_.get()), |
388 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), | 387 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), |
389 socket_factory_(rtc::Thread::Current()), | 388 socket_factory_(rtc::Thread::Current()), |
390 nat_factory1_(ss_.get(), kNatAddr1, SocketAddress()), | 389 nat_factory1_(ss_.get(), kNatAddr1, SocketAddress()), |
391 nat_factory2_(ss_.get(), kNatAddr2, SocketAddress()), | 390 nat_factory2_(ss_.get(), kNatAddr2, SocketAddress()), |
392 nat_socket_factory1_(&nat_factory1_), | 391 nat_socket_factory1_(&nat_factory1_), |
393 nat_socket_factory2_(&nat_factory2_), | 392 nat_socket_factory2_(&nat_factory2_), |
394 stun_server_(TestStunServer::Create(main_, kStunAddr)), | 393 stun_server_(TestStunServer::Create(&main_, kStunAddr)), |
395 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), | 394 turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr), |
396 relay_server_(main_, | 395 relay_server_(&main_, |
397 kRelayUdpIntAddr, | 396 kRelayUdpIntAddr, |
398 kRelayUdpExtAddr, | 397 kRelayUdpExtAddr, |
399 kRelayTcpIntAddr, | 398 kRelayTcpIntAddr, |
400 kRelayTcpExtAddr, | 399 kRelayTcpExtAddr, |
401 kRelaySslTcpIntAddr, | 400 kRelaySslTcpIntAddr, |
402 kRelaySslTcpExtAddr), | 401 kRelaySslTcpExtAddr), |
403 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), | 402 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), |
404 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), | 403 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), |
405 role_conflict_(false), | 404 role_conflict_(false), |
406 ports_destroyed_(0) { | 405 ports_destroyed_(0) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 484 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
486 TestConnectivity("ssltcp", port1, RelayName(rtype, proto), port2, | 485 TestConnectivity("ssltcp", port1, RelayName(rtype, proto), port2, |
487 rtype == RELAY_GTURN, false, true, true); | 486 rtype == RELAY_GTURN, false, true, true); |
488 } | 487 } |
489 // helpers for above functions | 488 // helpers for above functions |
490 UDPPort* CreateUdpPort(const SocketAddress& addr) { | 489 UDPPort* CreateUdpPort(const SocketAddress& addr) { |
491 return CreateUdpPort(addr, &socket_factory_); | 490 return CreateUdpPort(addr, &socket_factory_); |
492 } | 491 } |
493 UDPPort* CreateUdpPort(const SocketAddress& addr, | 492 UDPPort* CreateUdpPort(const SocketAddress& addr, |
494 PacketSocketFactory* socket_factory) { | 493 PacketSocketFactory* socket_factory) { |
495 return UDPPort::Create(main_, socket_factory, &network_, addr.ipaddr(), 0, | 494 return UDPPort::Create(&main_, socket_factory, &network_, addr.ipaddr(), 0, |
496 0, username_, password_, std::string(), true); | 495 0, username_, password_, std::string(), true); |
497 } | 496 } |
498 TCPPort* CreateTcpPort(const SocketAddress& addr) { | 497 TCPPort* CreateTcpPort(const SocketAddress& addr) { |
499 return CreateTcpPort(addr, &socket_factory_); | 498 return CreateTcpPort(addr, &socket_factory_); |
500 } | 499 } |
501 TCPPort* CreateTcpPort(const SocketAddress& addr, | 500 TCPPort* CreateTcpPort(const SocketAddress& addr, |
502 PacketSocketFactory* socket_factory) { | 501 PacketSocketFactory* socket_factory) { |
503 return TCPPort::Create(main_, socket_factory, &network_, | 502 return TCPPort::Create(&main_, socket_factory, &network_, |
504 addr.ipaddr(), 0, 0, username_, password_, | 503 addr.ipaddr(), 0, 0, username_, password_, |
505 true); | 504 true); |
506 } | 505 } |
507 StunPort* CreateStunPort(const SocketAddress& addr, | 506 StunPort* CreateStunPort(const SocketAddress& addr, |
508 rtc::PacketSocketFactory* factory) { | 507 rtc::PacketSocketFactory* factory) { |
509 ServerAddresses stun_servers; | 508 ServerAddresses stun_servers; |
510 stun_servers.insert(kStunAddr); | 509 stun_servers.insert(kStunAddr); |
511 return StunPort::Create(main_, factory, &network_, | 510 return StunPort::Create(&main_, factory, &network_, |
512 addr.ipaddr(), 0, 0, | 511 addr.ipaddr(), 0, 0, |
513 username_, password_, stun_servers, | 512 username_, password_, stun_servers, |
514 std::string()); | 513 std::string()); |
515 } | 514 } |
516 Port* CreateRelayPort(const SocketAddress& addr, RelayType rtype, | 515 Port* CreateRelayPort(const SocketAddress& addr, RelayType rtype, |
517 ProtocolType int_proto, ProtocolType ext_proto) { | 516 ProtocolType int_proto, ProtocolType ext_proto) { |
518 if (rtype == RELAY_TURN) { | 517 if (rtype == RELAY_TURN) { |
519 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); | 518 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); |
520 } else { | 519 } else { |
521 return CreateGturnPort(addr, int_proto, ext_proto); | 520 return CreateGturnPort(addr, int_proto, ext_proto); |
522 } | 521 } |
523 } | 522 } |
524 TurnPort* CreateTurnPort(const SocketAddress& addr, | 523 TurnPort* CreateTurnPort(const SocketAddress& addr, |
525 PacketSocketFactory* socket_factory, | 524 PacketSocketFactory* socket_factory, |
526 ProtocolType int_proto, ProtocolType ext_proto) { | 525 ProtocolType int_proto, ProtocolType ext_proto) { |
527 SocketAddress server_addr = | 526 SocketAddress server_addr = |
528 int_proto == PROTO_TCP ? kTurnTcpIntAddr : kTurnUdpIntAddr; | 527 int_proto == PROTO_TCP ? kTurnTcpIntAddr : kTurnUdpIntAddr; |
529 return CreateTurnPort(addr, socket_factory, int_proto, ext_proto, | 528 return CreateTurnPort(addr, socket_factory, int_proto, ext_proto, |
530 server_addr); | 529 server_addr); |
531 } | 530 } |
532 TurnPort* CreateTurnPort(const SocketAddress& addr, | 531 TurnPort* CreateTurnPort(const SocketAddress& addr, |
533 PacketSocketFactory* socket_factory, | 532 PacketSocketFactory* socket_factory, |
534 ProtocolType int_proto, ProtocolType ext_proto, | 533 ProtocolType int_proto, ProtocolType ext_proto, |
535 const rtc::SocketAddress& server_addr) { | 534 const rtc::SocketAddress& server_addr) { |
536 return TurnPort::Create(main_, socket_factory, &network_, addr.ipaddr(), 0, | 535 return TurnPort::Create(&main_, socket_factory, &network_, addr.ipaddr(), 0, |
537 0, username_, password_, | 536 0, username_, password_, |
538 ProtocolAddress(server_addr, int_proto), | 537 ProtocolAddress(server_addr, int_proto), |
539 kRelayCredentials, 0, std::string()); | 538 kRelayCredentials, 0, std::string()); |
540 } | 539 } |
541 RelayPort* CreateGturnPort(const SocketAddress& addr, | 540 RelayPort* CreateGturnPort(const SocketAddress& addr, |
542 ProtocolType int_proto, ProtocolType ext_proto) { | 541 ProtocolType int_proto, ProtocolType ext_proto) { |
543 RelayPort* port = CreateGturnPort(addr); | 542 RelayPort* port = CreateGturnPort(addr); |
544 SocketAddress addrs[] = | 543 SocketAddress addrs[] = |
545 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; | 544 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; |
546 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); | 545 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); |
547 return port; | 546 return port; |
548 } | 547 } |
549 RelayPort* CreateGturnPort(const SocketAddress& addr) { | 548 RelayPort* CreateGturnPort(const SocketAddress& addr) { |
550 // TODO(pthatcher): Remove GTURN. | 549 // TODO(pthatcher): Remove GTURN. |
551 // Generate a username with length of 16 for Gturn only. | 550 // Generate a username with length of 16 for Gturn only. |
552 std::string username = rtc::CreateRandomString(kGturnUserNameLength); | 551 std::string username = rtc::CreateRandomString(kGturnUserNameLength); |
553 return RelayPort::Create(main_, &socket_factory_, &network_, addr.ipaddr(), | 552 return RelayPort::Create(&main_, &socket_factory_, &network_, addr.ipaddr(), |
554 0, 0, username, password_); | 553 0, 0, username, password_); |
555 // TODO: Add an external address for ext_proto, so that the | 554 // TODO: Add an external address for ext_proto, so that the |
556 // other side can connect to this port using a non-UDP protocol. | 555 // other side can connect to this port using a non-UDP protocol. |
557 } | 556 } |
558 rtc::NATServer* CreateNatServer(const SocketAddress& addr, | 557 rtc::NATServer* CreateNatServer(const SocketAddress& addr, |
559 rtc::NATType type) { | 558 rtc::NATType type) { |
560 return new rtc::NATServer(type, ss_.get(), addr, addr, ss_.get(), addr); | 559 return new rtc::NATServer(type, ss_.get(), addr, addr, ss_.get(), addr); |
561 } | 560 } |
562 static const char* StunName(NATType type) { | 561 static const char* StunName(NATType type) { |
563 switch (type) { | 562 switch (type) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 IceMessage* CreateStunMessageWithUsername(int type, | 759 IceMessage* CreateStunMessageWithUsername(int type, |
761 const std::string& username) { | 760 const std::string& username) { |
762 IceMessage* msg = CreateStunMessage(type); | 761 IceMessage* msg = CreateStunMessage(type); |
763 msg->AddAttribute( | 762 msg->AddAttribute( |
764 rtc::MakeUnique<StunByteStringAttribute>(STUN_ATTR_USERNAME, username)); | 763 rtc::MakeUnique<StunByteStringAttribute>(STUN_ATTR_USERNAME, username)); |
765 return msg; | 764 return msg; |
766 } | 765 } |
767 TestPort* CreateTestPort(const rtc::SocketAddress& addr, | 766 TestPort* CreateTestPort(const rtc::SocketAddress& addr, |
768 const std::string& username, | 767 const std::string& username, |
769 const std::string& password) { | 768 const std::string& password) { |
770 TestPort* port = new TestPort(main_, "test", &socket_factory_, &network_, | 769 TestPort* port = new TestPort(&main_, "test", &socket_factory_, &network_, |
771 addr.ipaddr(), 0, 0, username, password); | 770 addr.ipaddr(), 0, 0, username, password); |
772 port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict); | 771 port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict); |
773 return port; | 772 return port; |
774 } | 773 } |
775 TestPort* CreateTestPort(const rtc::SocketAddress& addr, | 774 TestPort* CreateTestPort(const rtc::SocketAddress& addr, |
776 const std::string& username, | 775 const std::string& username, |
777 const std::string& password, | 776 const std::string& password, |
778 cricket::IceRole role, | 777 cricket::IceRole role, |
779 int tiebreaker) { | 778 int tiebreaker) { |
780 TestPort* port = CreateTestPort(addr, username, password); | 779 TestPort* port = CreateTestPort(addr, username, password); |
(...skipping 14 matching lines...) Expand all Loading... |
795 void OnDestroyed(PortInterface* port) { ++ports_destroyed_; } | 794 void OnDestroyed(PortInterface* port) { ++ports_destroyed_; } |
796 int ports_destroyed() const { return ports_destroyed_; } | 795 int ports_destroyed() const { return ports_destroyed_; } |
797 | 796 |
798 rtc::BasicPacketSocketFactory* nat_socket_factory1() { | 797 rtc::BasicPacketSocketFactory* nat_socket_factory1() { |
799 return &nat_socket_factory1_; | 798 return &nat_socket_factory1_; |
800 } | 799 } |
801 | 800 |
802 rtc::VirtualSocketServer* vss() { return ss_.get(); } | 801 rtc::VirtualSocketServer* vss() { return ss_.get(); } |
803 | 802 |
804 private: | 803 private: |
805 rtc::Thread* main_; | |
806 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 804 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
807 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 805 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
808 rtc::SocketServerScope ss_scope_; | 806 rtc::AutoSocketServerThread main_; |
809 rtc::Network network_; | 807 rtc::Network network_; |
810 rtc::BasicPacketSocketFactory socket_factory_; | 808 rtc::BasicPacketSocketFactory socket_factory_; |
811 std::unique_ptr<rtc::NATServer> nat_server1_; | 809 std::unique_ptr<rtc::NATServer> nat_server1_; |
812 std::unique_ptr<rtc::NATServer> nat_server2_; | 810 std::unique_ptr<rtc::NATServer> nat_server2_; |
813 rtc::NATSocketFactory nat_factory1_; | 811 rtc::NATSocketFactory nat_factory1_; |
814 rtc::NATSocketFactory nat_factory2_; | 812 rtc::NATSocketFactory nat_factory2_; |
815 rtc::BasicPacketSocketFactory nat_socket_factory1_; | 813 rtc::BasicPacketSocketFactory nat_socket_factory1_; |
816 rtc::BasicPacketSocketFactory nat_socket_factory2_; | 814 rtc::BasicPacketSocketFactory nat_socket_factory2_; |
817 std::unique_ptr<TestStunServer> stun_server_; | 815 std::unique_ptr<TestStunServer> stun_server_; |
818 TestTurnServer turn_server_; | 816 TestTurnServer turn_server_; |
(...skipping 2062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2881 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); | 2879 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); |
2882 EXPECT_NE(conn1, conn2); | 2880 EXPECT_NE(conn1, conn2); |
2883 conn_in_use = port->GetConnection(address); | 2881 conn_in_use = port->GetConnection(address); |
2884 EXPECT_EQ(conn2, conn_in_use); | 2882 EXPECT_EQ(conn2, conn_in_use); |
2885 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation()); | 2883 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation()); |
2886 | 2884 |
2887 // Make sure the new connection was not deleted. | 2885 // Make sure the new connection was not deleted. |
2888 rtc::Thread::Current()->ProcessMessages(300); | 2886 rtc::Thread::Current()->ProcessMessages(300); |
2889 EXPECT_TRUE(port->GetConnection(address) != nullptr); | 2887 EXPECT_TRUE(port->GetConnection(address) != nullptr); |
2890 } | 2888 } |
OLD | NEW |