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 |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
15 #include "webrtc/base/helpers.h" | 15 #include "webrtc/base/helpers.h" |
16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
17 #include "webrtc/base/physicalsocketserver.h" | |
18 #include "webrtc/base/ptr_util.h" | 17 #include "webrtc/base/ptr_util.h" |
19 #include "webrtc/base/socketaddress.h" | 18 #include "webrtc/base/socketaddress.h" |
20 #include "webrtc/base/ssladapter.h" | 19 #include "webrtc/base/ssladapter.h" |
21 #include "webrtc/base/testclient.h" | 20 #include "webrtc/base/testclient.h" |
22 #include "webrtc/base/thread.h" | 21 #include "webrtc/base/thread.h" |
23 #include "webrtc/base/virtualsocketserver.h" | 22 #include "webrtc/base/virtualsocketserver.h" |
24 #include "webrtc/p2p/base/relayserver.h" | 23 #include "webrtc/p2p/base/relayserver.h" |
25 | 24 |
26 using rtc::SocketAddress; | 25 using rtc::SocketAddress; |
27 using namespace cricket; | 26 using namespace cricket; |
28 | 27 |
29 static const uint32_t LIFETIME = 4; // seconds | 28 static const uint32_t LIFETIME = 4; // seconds |
30 static const SocketAddress server_int_addr("127.0.0.1", 5000); | 29 static const SocketAddress server_int_addr("127.0.0.1", 5000); |
31 static const SocketAddress server_ext_addr("127.0.0.1", 5001); | 30 static const SocketAddress server_ext_addr("127.0.0.1", 5001); |
32 static const SocketAddress client1_addr("127.0.0.1", 6000 + (rand() % 1000)); | 31 static const SocketAddress client1_addr("127.0.0.1", 6000 + (rand() % 1000)); |
33 static const SocketAddress client2_addr("127.0.0.1", 7000 + (rand() % 1000)); | 32 static const SocketAddress client2_addr("127.0.0.1", 7000 + (rand() % 1000)); |
34 static const char* bad = "this is a completely nonsensical message whose only " | 33 static const char* bad = "this is a completely nonsensical message whose only " |
35 "purpose is to make the parser go 'ack'. it doesn't " | 34 "purpose is to make the parser go 'ack'. it doesn't " |
36 "look anything like a normal stun message"; | 35 "look anything like a normal stun message"; |
37 static const char* msg1 = "spamspamspamspamspamspamspambakedbeansspam"; | 36 static const char* msg1 = "spamspamspamspamspamspamspambakedbeansspam"; |
38 static const char* msg2 = "Lobster Thermidor a Crevette with a mornay sauce..."; | 37 static const char* msg2 = "Lobster Thermidor a Crevette with a mornay sauce..."; |
39 | 38 |
40 class RelayServerTest : public testing::Test { | 39 class RelayServerTest : public testing::Test { |
41 public: | 40 public: |
42 RelayServerTest() | 41 RelayServerTest() |
43 : pss_(new rtc::PhysicalSocketServer), | 42 : ss_(new rtc::VirtualSocketServer()), |
44 ss_(new rtc::VirtualSocketServer(pss_.get())), | |
45 thread_(ss_.get()), | 43 thread_(ss_.get()), |
46 username_(rtc::CreateRandomString(12)), | 44 username_(rtc::CreateRandomString(12)), |
47 password_(rtc::CreateRandomString(12)) {} | 45 password_(rtc::CreateRandomString(12)) {} |
48 | 46 |
49 protected: | 47 protected: |
50 virtual void SetUp() { | 48 virtual void SetUp() { |
51 server_.reset(new RelayServer(rtc::Thread::Current())); | 49 server_.reset(new RelayServer(rtc::Thread::Current())); |
52 | 50 |
53 server_->AddInternalSocket( | 51 server_->AddInternalSocket( |
54 rtc::AsyncUDPSocket::Create(ss_.get(), server_int_addr)); | 52 rtc::AsyncUDPSocket::Create(ss_.get(), server_int_addr)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 attr->SetValue(val); | 157 attr->SetValue(val); |
160 msg->AddAttribute(std::move(attr)); | 158 msg->AddAttribute(std::move(attr)); |
161 } | 159 } |
162 static void AddDestinationAttr(StunMessage* msg, const SocketAddress& addr) { | 160 static void AddDestinationAttr(StunMessage* msg, const SocketAddress& addr) { |
163 auto attr = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); | 161 auto attr = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); |
164 attr->SetIP(addr.ipaddr()); | 162 attr->SetIP(addr.ipaddr()); |
165 attr->SetPort(addr.port()); | 163 attr->SetPort(addr.port()); |
166 msg->AddAttribute(std::move(attr)); | 164 msg->AddAttribute(std::move(attr)); |
167 } | 165 } |
168 | 166 |
169 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | |
170 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 167 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
171 rtc::AutoSocketServerThread thread_; | 168 rtc::AutoSocketServerThread thread_; |
172 std::unique_ptr<RelayServer> server_; | 169 std::unique_ptr<RelayServer> server_; |
173 std::unique_ptr<rtc::TestClient> client1_; | 170 std::unique_ptr<rtc::TestClient> client1_; |
174 std::unique_ptr<rtc::TestClient> client2_; | 171 std::unique_ptr<rtc::TestClient> client2_; |
175 std::string username_; | 172 std::string username_; |
176 std::string password_; | 173 std::string password_; |
177 }; | 174 }; |
178 | 175 |
179 // Send a complete nonsense message and verify that it is eaten. | 176 // Send a complete nonsense message and verify that it is eaten. |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 504 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
508 ASSERT_TRUE(err != NULL); | 505 ASSERT_TRUE(err != NULL); |
509 EXPECT_EQ(6, err->eclass()); | 506 EXPECT_EQ(6, err->eclass()); |
510 EXPECT_EQ(0, err->number()); | 507 EXPECT_EQ(0, err->number()); |
511 EXPECT_EQ("Operation Not Supported", err->reason()); | 508 EXPECT_EQ("Operation Not Supported", err->reason()); |
512 | 509 |
513 // Also verify that traffic from the external client is ignored. | 510 // Also verify that traffic from the external client is ignored. |
514 SendRaw2(msg2, static_cast<int>(strlen(msg2))); | 511 SendRaw2(msg2, static_cast<int>(strlen(msg2))); |
515 EXPECT_TRUE(ReceiveRaw1().empty()); | 512 EXPECT_TRUE(ReceiveRaw1().empty()); |
516 } | 513 } |
OLD | NEW |