| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 static const SocketAddress kNatAddr1("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); | 51 static const SocketAddress kNatAddr1("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); |
| 52 static const SocketAddress kNatAddr2("88.88.88.88", rtc::NAT_SERVER_UDP_PORT); | 52 static const SocketAddress kNatAddr2("88.88.88.88", rtc::NAT_SERVER_UDP_PORT); |
| 53 static const SocketAddress kStunAddr("99.99.99.1", STUN_SERVER_PORT); | 53 static const SocketAddress kStunAddr("99.99.99.1", STUN_SERVER_PORT); |
| 54 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); | 54 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); |
| 55 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); | 55 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); |
| 56 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); | 56 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); |
| 57 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); | 57 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); |
| 58 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | 58 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); |
| 59 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); | 59 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); |
| 60 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", STUN_SERVER_PORT); | 60 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", STUN_SERVER_PORT); |
| 61 static const SocketAddress kTurnTcpIntAddr("99.99.99.4", 5010); |
| 61 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); | 62 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); |
| 62 static const RelayCredentials kRelayCredentials("test", "test"); | 63 static const RelayCredentials kRelayCredentials("test", "test"); |
| 63 | 64 |
| 64 // TODO: Update these when RFC5245 is completely supported. | 65 // TODO: Update these when RFC5245 is completely supported. |
| 65 // Magic value of 30 is from RFC3484, for IPv4 addresses. | 66 // Magic value of 30 is from RFC3484, for IPv4 addresses. |
| 66 static const uint32_t kDefaultPrflxPriority = | 67 static const uint32_t kDefaultPrflxPriority = |
| 67 ICE_TYPE_PREFERENCE_PRFLX << 24 | 30 << 8 | | 68 ICE_TYPE_PREFERENCE_PRFLX << 24 | 30 << 8 | |
| 68 (256 - ICE_CANDIDATE_COMPONENT_DEFAULT); | 69 (256 - ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 69 | 70 |
| 70 static const int kTiebreaker1 = 11111; | 71 static const int kTiebreaker1 = 11111; |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 ProtocolType int_proto, ProtocolType ext_proto) { | 491 ProtocolType int_proto, ProtocolType ext_proto) { |
| 491 if (rtype == RELAY_TURN) { | 492 if (rtype == RELAY_TURN) { |
| 492 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); | 493 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); |
| 493 } else { | 494 } else { |
| 494 return CreateGturnPort(addr, int_proto, ext_proto); | 495 return CreateGturnPort(addr, int_proto, ext_proto); |
| 495 } | 496 } |
| 496 } | 497 } |
| 497 TurnPort* CreateTurnPort(const SocketAddress& addr, | 498 TurnPort* CreateTurnPort(const SocketAddress& addr, |
| 498 PacketSocketFactory* socket_factory, | 499 PacketSocketFactory* socket_factory, |
| 499 ProtocolType int_proto, ProtocolType ext_proto) { | 500 ProtocolType int_proto, ProtocolType ext_proto) { |
| 500 return CreateTurnPort(addr, socket_factory, | 501 SocketAddress server_addr = |
| 501 int_proto, ext_proto, kTurnUdpIntAddr); | 502 int_proto == PROTO_TCP ? kTurnTcpIntAddr : kTurnUdpIntAddr; |
| 503 return CreateTurnPort(addr, socket_factory, int_proto, ext_proto, |
| 504 server_addr); |
| 502 } | 505 } |
| 503 TurnPort* CreateTurnPort(const SocketAddress& addr, | 506 TurnPort* CreateTurnPort(const SocketAddress& addr, |
| 504 PacketSocketFactory* socket_factory, | 507 PacketSocketFactory* socket_factory, |
| 505 ProtocolType int_proto, ProtocolType ext_proto, | 508 ProtocolType int_proto, ProtocolType ext_proto, |
| 506 const rtc::SocketAddress& server_addr) { | 509 const rtc::SocketAddress& server_addr) { |
| 507 return TurnPort::Create(main_, socket_factory, &network_, | 510 return TurnPort::Create(main_, socket_factory, &network_, addr.ipaddr(), 0, |
| 508 addr.ipaddr(), 0, 0, | 511 0, username_, password_, |
| 509 username_, password_, ProtocolAddress( | 512 ProtocolAddress(server_addr, int_proto), |
| 510 server_addr, PROTO_UDP), | 513 kRelayCredentials, 0, std::string()); |
| 511 kRelayCredentials, 0, | |
| 512 std::string()); | |
| 513 } | 514 } |
| 514 RelayPort* CreateGturnPort(const SocketAddress& addr, | 515 RelayPort* CreateGturnPort(const SocketAddress& addr, |
| 515 ProtocolType int_proto, ProtocolType ext_proto) { | 516 ProtocolType int_proto, ProtocolType ext_proto) { |
| 516 RelayPort* port = CreateGturnPort(addr); | 517 RelayPort* port = CreateGturnPort(addr); |
| 517 SocketAddress addrs[] = | 518 SocketAddress addrs[] = |
| 518 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; | 519 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; |
| 519 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); | 520 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); |
| 520 return port; | 521 return port; |
| 521 } | 522 } |
| 522 RelayPort* CreateGturnPort(const SocketAddress& addr) { | 523 RelayPort* CreateGturnPort(const SocketAddress& addr) { |
| (...skipping 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2155 SocketAddress kTurnUdpExtAddr2("99.99.98.5", 0); | 2156 SocketAddress kTurnUdpExtAddr2("99.99.98.5", 0); |
| 2156 TestTurnServer turn_server2( | 2157 TestTurnServer turn_server2( |
| 2157 rtc::Thread::Current(), kTurnUdpIntAddr2, kTurnUdpExtAddr2); | 2158 rtc::Thread::Current(), kTurnUdpIntAddr2, kTurnUdpExtAddr2); |
| 2158 rtc::scoped_ptr<Port> turnport3(CreateTurnPort( | 2159 rtc::scoped_ptr<Port> turnport3(CreateTurnPort( |
| 2159 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP, | 2160 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP, |
| 2160 kTurnUdpIntAddr2)); | 2161 kTurnUdpIntAddr2)); |
| 2161 turnport3->PrepareAddress(); | 2162 turnport3->PrepareAddress(); |
| 2162 ASSERT_EQ_WAIT(1U, turnport3->Candidates().size(), kTimeout); | 2163 ASSERT_EQ_WAIT(1U, turnport3->Candidates().size(), kTimeout); |
| 2163 EXPECT_NE(turnport3->Candidates()[0].foundation(), | 2164 EXPECT_NE(turnport3->Candidates()[0].foundation(), |
| 2164 turnport2->Candidates()[0].foundation()); | 2165 turnport2->Candidates()[0].foundation()); |
| 2166 |
| 2167 // Start a TCP turn server, and check that two turn candidates have |
| 2168 // different foundations if their relay protocols are different. |
| 2169 TestTurnServer turn_server3(rtc::Thread::Current(), kTurnTcpIntAddr, |
| 2170 kTurnUdpExtAddr, PROTO_TCP); |
| 2171 rtc::scoped_ptr<Port> turnport4( |
| 2172 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_TCP, PROTO_UDP)); |
| 2173 turnport4->PrepareAddress(); |
| 2174 ASSERT_EQ_WAIT(1U, turnport4->Candidates().size(), kTimeout); |
| 2175 EXPECT_NE(turnport2->Candidates()[0].foundation(), |
| 2176 turnport4->Candidates()[0].foundation()); |
| 2165 } | 2177 } |
| 2166 | 2178 |
| 2167 // This test verifies the related addresses of different types of | 2179 // This test verifies the related addresses of different types of |
| 2168 // ICE candiates. | 2180 // ICE candiates. |
| 2169 TEST_F(PortTest, TestCandidateRelatedAddress) { | 2181 TEST_F(PortTest, TestCandidateRelatedAddress) { |
| 2170 rtc::scoped_ptr<rtc::NATServer> nat_server( | 2182 rtc::scoped_ptr<rtc::NATServer> nat_server( |
| 2171 CreateNatServer(kNatAddr1, NAT_OPEN_CONE)); | 2183 CreateNatServer(kNatAddr1, NAT_OPEN_CONE)); |
| 2172 rtc::scoped_ptr<UDPPort> udpport(CreateUdpPort(kLocalAddr1)); | 2184 rtc::scoped_ptr<UDPPort> udpport(CreateUdpPort(kLocalAddr1)); |
| 2173 udpport->PrepareAddress(); | 2185 udpport->PrepareAddress(); |
| 2174 // For UDPPort, related address will be empty. | 2186 // For UDPPort, related address will be empty. |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2524 rtc::scoped_ptr<Port> tcp_port(CreateTcpPort(kLocalAddr1)); | 2536 rtc::scoped_ptr<Port> tcp_port(CreateTcpPort(kLocalAddr1)); |
| 2525 EXPECT_TRUE(tcp_port->SupportsProtocol(TCP_PROTOCOL_NAME)); | 2537 EXPECT_TRUE(tcp_port->SupportsProtocol(TCP_PROTOCOL_NAME)); |
| 2526 EXPECT_TRUE(tcp_port->SupportsProtocol(SSLTCP_PROTOCOL_NAME)); | 2538 EXPECT_TRUE(tcp_port->SupportsProtocol(SSLTCP_PROTOCOL_NAME)); |
| 2527 EXPECT_FALSE(tcp_port->SupportsProtocol(UDP_PROTOCOL_NAME)); | 2539 EXPECT_FALSE(tcp_port->SupportsProtocol(UDP_PROTOCOL_NAME)); |
| 2528 | 2540 |
| 2529 rtc::scoped_ptr<Port> turn_port( | 2541 rtc::scoped_ptr<Port> turn_port( |
| 2530 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 2542 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
| 2531 EXPECT_TRUE(turn_port->SupportsProtocol(UDP_PROTOCOL_NAME)); | 2543 EXPECT_TRUE(turn_port->SupportsProtocol(UDP_PROTOCOL_NAME)); |
| 2532 EXPECT_FALSE(turn_port->SupportsProtocol(TCP_PROTOCOL_NAME)); | 2544 EXPECT_FALSE(turn_port->SupportsProtocol(TCP_PROTOCOL_NAME)); |
| 2533 } | 2545 } |
| OLD | NEW |