OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 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 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 13 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
14 #include "webrtc/p2p/base/relayport.h" | 14 #include "webrtc/p2p/base/relayport.h" |
15 #include "webrtc/p2p/base/relayserver.h" | 15 #include "webrtc/p2p/base/relayserver.h" |
16 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
17 #include "webrtc/base/helpers.h" | 17 #include "webrtc/base/helpers.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/physicalsocketserver.h" | |
20 #include "webrtc/base/socketadapters.h" | 19 #include "webrtc/base/socketadapters.h" |
21 #include "webrtc/base/socketaddress.h" | 20 #include "webrtc/base/socketaddress.h" |
22 #include "webrtc/base/ssladapter.h" | 21 #include "webrtc/base/ssladapter.h" |
23 #include "webrtc/base/thread.h" | 22 #include "webrtc/base/thread.h" |
24 #include "webrtc/base/virtualsocketserver.h" | 23 #include "webrtc/base/virtualsocketserver.h" |
25 | 24 |
26 using rtc::SocketAddress; | 25 using rtc::SocketAddress; |
27 | 26 |
28 static const SocketAddress kLocalAddress = SocketAddress("192.168.1.2", 0); | 27 static const SocketAddress kLocalAddress = SocketAddress("192.168.1.2", 0); |
29 static const SocketAddress kRelayUdpAddr = SocketAddress("99.99.99.1", 5000); | 28 static const SocketAddress kRelayUdpAddr = SocketAddress("99.99.99.1", 5000); |
30 static const SocketAddress kRelayTcpAddr = SocketAddress("99.99.99.2", 5001); | 29 static const SocketAddress kRelayTcpAddr = SocketAddress("99.99.99.2", 5001); |
31 static const SocketAddress kRelaySslAddr = SocketAddress("99.99.99.3", 443); | 30 static const SocketAddress kRelaySslAddr = SocketAddress("99.99.99.3", 443); |
32 static const SocketAddress kRelayExtAddr = SocketAddress("99.99.99.3", 5002); | 31 static const SocketAddress kRelayExtAddr = SocketAddress("99.99.99.3", 5002); |
33 | 32 |
34 static const int kTimeoutMs = 1000; | 33 static const int kTimeoutMs = 1000; |
35 static const int kMaxTimeoutMs = 5000; | 34 static const int kMaxTimeoutMs = 5000; |
36 | 35 |
37 // Tests connecting a RelayPort to a fake relay server | 36 // Tests connecting a RelayPort to a fake relay server |
38 // (cricket::RelayServer) using all currently available protocols. The | 37 // (cricket::RelayServer) using all currently available protocols. The |
39 // network layer is faked out by using a VirtualSocketServer for | 38 // network layer is faked out by using a VirtualSocketServer for |
40 // creating sockets. The test will monitor the current state of the | 39 // creating sockets. The test will monitor the current state of the |
41 // RelayPort and created sockets by listening for signals such as, | 40 // RelayPort and created sockets by listening for signals such as, |
42 // SignalConnectFailure, SignalConnectTimeout, SignalSocketClosed and | 41 // SignalConnectFailure, SignalConnectTimeout, SignalSocketClosed and |
43 // SignalReadPacket. | 42 // SignalReadPacket. |
44 class RelayPortTest : public testing::Test, | 43 class RelayPortTest : public testing::Test, |
45 public sigslot::has_slots<> { | 44 public sigslot::has_slots<> { |
46 public: | 45 public: |
47 RelayPortTest() | 46 RelayPortTest() |
48 : physical_socket_server_(new rtc::PhysicalSocketServer), | 47 : virtual_socket_server_(new rtc::VirtualSocketServer()), |
49 virtual_socket_server_(new rtc::VirtualSocketServer( | |
50 physical_socket_server_.get())), | |
51 main_(virtual_socket_server_.get()), | 48 main_(virtual_socket_server_.get()), |
52 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), | 49 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), |
53 socket_factory_(rtc::Thread::Current()), | 50 socket_factory_(rtc::Thread::Current()), |
54 username_(rtc::CreateRandomString(16)), | 51 username_(rtc::CreateRandomString(16)), |
55 password_(rtc::CreateRandomString(16)), | 52 password_(rtc::CreateRandomString(16)), |
56 relay_port_(cricket::RelayPort::Create(&main_, &socket_factory_, | 53 relay_port_(cricket::RelayPort::Create(&main_, |
| 54 &socket_factory_, |
57 &network_, | 55 &network_, |
58 kLocalAddress.ipaddr(), | 56 kLocalAddress.ipaddr(), |
59 0, 0, username_, password_)), | 57 0, |
60 relay_server_(new cricket::RelayServer(&main_)) { | 58 0, |
61 } | 59 username_, |
| 60 password_)), |
| 61 relay_server_(new cricket::RelayServer(&main_)) {} |
62 | 62 |
63 void OnReadPacket(rtc::AsyncPacketSocket* socket, | 63 void OnReadPacket(rtc::AsyncPacketSocket* socket, |
64 const char* data, size_t size, | 64 const char* data, size_t size, |
65 const rtc::SocketAddress& remote_addr, | 65 const rtc::SocketAddress& remote_addr, |
66 const rtc::PacketTime& packet_time) { | 66 const rtc::PacketTime& packet_time) { |
67 received_packet_count_[socket]++; | 67 received_packet_count_[socket]++; |
68 } | 68 } |
69 | 69 |
70 void OnConnectFailure(const cricket::ProtocolAddress* addr) { | 70 void OnConnectFailure(const cricket::ProtocolAddress* addr) { |
71 failed_connections_.push_back(*addr); | 71 failed_connections_.push_back(*addr); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 if (soft_timedout_connections_[i].address == addr->address && | 239 if (soft_timedout_connections_[i].address == addr->address && |
240 soft_timedout_connections_[i].proto == addr->proto) { | 240 soft_timedout_connections_[i].proto == addr->proto) { |
241 return true; | 241 return true; |
242 } | 242 } |
243 } | 243 } |
244 return false; | 244 return false; |
245 } | 245 } |
246 | 246 |
247 typedef std::map<rtc::AsyncPacketSocket*, int> PacketMap; | 247 typedef std::map<rtc::AsyncPacketSocket*, int> PacketMap; |
248 | 248 |
249 std::unique_ptr<rtc::PhysicalSocketServer> physical_socket_server_; | |
250 std::unique_ptr<rtc::VirtualSocketServer> virtual_socket_server_; | 249 std::unique_ptr<rtc::VirtualSocketServer> virtual_socket_server_; |
251 rtc::AutoSocketServerThread main_; | 250 rtc::AutoSocketServerThread main_; |
252 rtc::Network network_; | 251 rtc::Network network_; |
253 rtc::BasicPacketSocketFactory socket_factory_; | 252 rtc::BasicPacketSocketFactory socket_factory_; |
254 std::string username_; | 253 std::string username_; |
255 std::string password_; | 254 std::string password_; |
256 std::unique_ptr<cricket::RelayPort> relay_port_; | 255 std::unique_ptr<cricket::RelayPort> relay_port_; |
257 std::unique_ptr<cricket::RelayServer> relay_server_; | 256 std::unique_ptr<cricket::RelayServer> relay_server_; |
258 std::vector<cricket::ProtocolAddress> failed_connections_; | 257 std::vector<cricket::ProtocolAddress> failed_connections_; |
259 std::vector<cricket::ProtocolAddress> soft_timedout_connections_; | 258 std::vector<cricket::ProtocolAddress> soft_timedout_connections_; |
260 PacketMap received_packet_count_; | 259 PacketMap received_packet_count_; |
261 }; | 260 }; |
262 | 261 |
263 TEST_F(RelayPortTest, ConnectUdp) { | 262 TEST_F(RelayPortTest, ConnectUdp) { |
264 TestConnectUdp(); | 263 TestConnectUdp(); |
265 } | 264 } |
266 | 265 |
267 TEST_F(RelayPortTest, ConnectTcp) { | 266 TEST_F(RelayPortTest, ConnectTcp) { |
268 TestConnectTcp(); | 267 TestConnectTcp(); |
269 } | 268 } |
270 | 269 |
271 TEST_F(RelayPortTest, ConnectSslTcp) { | 270 TEST_F(RelayPortTest, ConnectSslTcp) { |
272 TestConnectSslTcp(); | 271 TestConnectSslTcp(); |
273 } | 272 } |
OLD | NEW |