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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 TestPhysicalInternal(SocketAddress("::1", 0)); | 261 TestPhysicalInternal(SocketAddress("::1", 0)); |
262 } else { | 262 } else { |
263 LOG(LS_WARNING) << "No IPv6, skipping"; | 263 LOG(LS_WARNING) << "No IPv6, skipping"; |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 namespace { | 267 namespace { |
268 | 268 |
269 class TestVirtualSocketServer : public VirtualSocketServer { | 269 class TestVirtualSocketServer : public VirtualSocketServer { |
270 public: | 270 public: |
271 explicit TestVirtualSocketServer(SocketServer* ss) | |
272 : VirtualSocketServer(ss), | |
273 ss_(ss) {} | |
274 // Expose this publicly | 271 // Expose this publicly |
275 IPAddress GetNextIP(int af) { return VirtualSocketServer::GetNextIP(af); } | 272 IPAddress GetNextIP(int af) { return VirtualSocketServer::GetNextIP(af); } |
276 | |
277 private: | |
278 std::unique_ptr<SocketServer> ss_; | |
279 }; | 273 }; |
280 | 274 |
281 } // namespace | 275 } // namespace |
282 | 276 |
283 void TestVirtualInternal(int family) { | 277 void TestVirtualInternal(int family) { |
284 std::unique_ptr<TestVirtualSocketServer> int_vss( | 278 std::unique_ptr<TestVirtualSocketServer> int_vss( |
285 new TestVirtualSocketServer(new PhysicalSocketServer())); | 279 new TestVirtualSocketServer()); |
286 std::unique_ptr<TestVirtualSocketServer> ext_vss( | 280 std::unique_ptr<TestVirtualSocketServer> ext_vss( |
287 new TestVirtualSocketServer(new PhysicalSocketServer())); | 281 new TestVirtualSocketServer()); |
288 | 282 |
289 SocketAddress int_addr; | 283 SocketAddress int_addr; |
290 SocketAddress ext_addrs[4]; | 284 SocketAddress ext_addrs[4]; |
291 int_addr.SetIP(int_vss->GetNextIP(family)); | 285 int_addr.SetIP(int_vss->GetNextIP(family)); |
292 ext_addrs[0].SetIP(ext_vss->GetNextIP(int_addr.family())); | 286 ext_addrs[0].SetIP(ext_vss->GetNextIP(int_addr.family())); |
293 ext_addrs[1].SetIP(ext_vss->GetNextIP(int_addr.family())); | 287 ext_addrs[1].SetIP(ext_vss->GetNextIP(int_addr.family())); |
294 ext_addrs[2].SetIP(ext_addrs[0].ipaddr()); | 288 ext_addrs[2].SetIP(ext_addrs[0].ipaddr()); |
295 ext_addrs[3].SetIP(ext_addrs[1].ipaddr()); | 289 ext_addrs[3].SetIP(ext_addrs[1].ipaddr()); |
296 | 290 |
297 TestBindings(int_vss.get(), int_addr, ext_vss.get(), ext_addrs); | 291 TestBindings(int_vss.get(), int_addr, ext_vss.get(), ext_addrs); |
(...skipping 11 matching lines...) Expand all Loading... |
309 LOG(LS_WARNING) << "No IPv6, skipping"; | 303 LOG(LS_WARNING) << "No IPv6, skipping"; |
310 } | 304 } |
311 } | 305 } |
312 | 306 |
313 class NatTcpTest : public testing::Test, public sigslot::has_slots<> { | 307 class NatTcpTest : public testing::Test, public sigslot::has_slots<> { |
314 public: | 308 public: |
315 NatTcpTest() | 309 NatTcpTest() |
316 : int_addr_("192.168.0.1", 0), | 310 : int_addr_("192.168.0.1", 0), |
317 ext_addr_("10.0.0.1", 0), | 311 ext_addr_("10.0.0.1", 0), |
318 connected_(false), | 312 connected_(false), |
319 int_pss_(new PhysicalSocketServer()), | 313 int_vss_(new TestVirtualSocketServer()), |
320 ext_pss_(new PhysicalSocketServer()), | 314 ext_vss_(new TestVirtualSocketServer()), |
321 int_vss_(new TestVirtualSocketServer(int_pss_)), | |
322 ext_vss_(new TestVirtualSocketServer(ext_pss_)), | |
323 int_thread_(new Thread(int_vss_.get())), | 315 int_thread_(new Thread(int_vss_.get())), |
324 ext_thread_(new Thread(ext_vss_.get())), | 316 ext_thread_(new Thread(ext_vss_.get())), |
325 nat_(new NATServer(NAT_OPEN_CONE, int_vss_.get(), int_addr_, int_addr_, | 317 nat_(new NATServer(NAT_OPEN_CONE, |
326 ext_vss_.get(), ext_addr_)), | 318 int_vss_.get(), |
| 319 int_addr_, |
| 320 int_addr_, |
| 321 ext_vss_.get(), |
| 322 ext_addr_)), |
327 natsf_(new NATSocketFactory(int_vss_.get(), | 323 natsf_(new NATSocketFactory(int_vss_.get(), |
328 nat_->internal_udp_address(), | 324 nat_->internal_udp_address(), |
329 nat_->internal_tcp_address())) { | 325 nat_->internal_tcp_address())) { |
330 int_thread_->Start(); | 326 int_thread_->Start(); |
331 ext_thread_->Start(); | 327 ext_thread_->Start(); |
332 } | 328 } |
333 | 329 |
334 void OnConnectEvent(AsyncSocket* socket) { | 330 void OnConnectEvent(AsyncSocket* socket) { |
335 connected_ = true; | 331 connected_ = true; |
336 } | 332 } |
337 | 333 |
338 void OnAcceptEvent(AsyncSocket* socket) { | 334 void OnAcceptEvent(AsyncSocket* socket) { |
339 accepted_.reset(server_->Accept(nullptr)); | 335 accepted_.reset(server_->Accept(nullptr)); |
340 } | 336 } |
341 | 337 |
342 void OnCloseEvent(AsyncSocket* socket, int error) { | 338 void OnCloseEvent(AsyncSocket* socket, int error) { |
343 } | 339 } |
344 | 340 |
345 void ConnectEvents() { | 341 void ConnectEvents() { |
346 server_->SignalReadEvent.connect(this, &NatTcpTest::OnAcceptEvent); | 342 server_->SignalReadEvent.connect(this, &NatTcpTest::OnAcceptEvent); |
347 client_->SignalConnectEvent.connect(this, &NatTcpTest::OnConnectEvent); | 343 client_->SignalConnectEvent.connect(this, &NatTcpTest::OnConnectEvent); |
348 } | 344 } |
349 | 345 |
350 SocketAddress int_addr_; | 346 SocketAddress int_addr_; |
351 SocketAddress ext_addr_; | 347 SocketAddress ext_addr_; |
352 bool connected_; | 348 bool connected_; |
353 PhysicalSocketServer* int_pss_; | |
354 PhysicalSocketServer* ext_pss_; | |
355 std::unique_ptr<TestVirtualSocketServer> int_vss_; | 349 std::unique_ptr<TestVirtualSocketServer> int_vss_; |
356 std::unique_ptr<TestVirtualSocketServer> ext_vss_; | 350 std::unique_ptr<TestVirtualSocketServer> ext_vss_; |
357 std::unique_ptr<Thread> int_thread_; | 351 std::unique_ptr<Thread> int_thread_; |
358 std::unique_ptr<Thread> ext_thread_; | 352 std::unique_ptr<Thread> ext_thread_; |
359 std::unique_ptr<NATServer> nat_; | 353 std::unique_ptr<NATServer> nat_; |
360 std::unique_ptr<NATSocketFactory> natsf_; | 354 std::unique_ptr<NATSocketFactory> natsf_; |
361 std::unique_ptr<AsyncSocket> client_; | 355 std::unique_ptr<AsyncSocket> client_; |
362 std::unique_ptr<AsyncSocket> server_; | 356 std::unique_ptr<AsyncSocket> server_; |
363 std::unique_ptr<AsyncSocket> accepted_; | 357 std::unique_ptr<AsyncSocket> accepted_; |
364 }; | 358 }; |
(...skipping 21 matching lines...) Expand all Loading... |
386 size_t len = strlen(buf); | 380 size_t len = strlen(buf); |
387 | 381 |
388 in->Send(buf, len); | 382 in->Send(buf, len); |
389 SocketAddress trans_addr; | 383 SocketAddress trans_addr; |
390 EXPECT_TRUE(out->CheckNextPacket(buf, len, &trans_addr)); | 384 EXPECT_TRUE(out->CheckNextPacket(buf, len, &trans_addr)); |
391 | 385 |
392 out->Send(buf, len); | 386 out->Send(buf, len); |
393 EXPECT_TRUE(in->CheckNextPacket(buf, len, &trans_addr)); | 387 EXPECT_TRUE(in->CheckNextPacket(buf, len, &trans_addr)); |
394 } | 388 } |
395 // #endif | 389 // #endif |
OLD | NEW |