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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 139 } |
140 | 140 |
141 static StunMessage* CreateStunMessage(int type) { | 141 static StunMessage* CreateStunMessage(int type) { |
142 StunMessage* msg = new RelayMessage(); | 142 StunMessage* msg = new RelayMessage(); |
143 msg->SetType(type); | 143 msg->SetType(type); |
144 msg->SetTransactionID( | 144 msg->SetTransactionID( |
145 rtc::CreateRandomString(kStunTransactionIdLength)); | 145 rtc::CreateRandomString(kStunTransactionIdLength)); |
146 return msg; | 146 return msg; |
147 } | 147 } |
148 static void AddMagicCookieAttr(StunMessage* msg) { | 148 static void AddMagicCookieAttr(StunMessage* msg) { |
149 StunByteStringAttribute* attr = | 149 auto attr = StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE); |
150 StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE); | |
151 attr->CopyBytes(TURN_MAGIC_COOKIE_VALUE, sizeof(TURN_MAGIC_COOKIE_VALUE)); | 150 attr->CopyBytes(TURN_MAGIC_COOKIE_VALUE, sizeof(TURN_MAGIC_COOKIE_VALUE)); |
152 msg->AddAttribute(attr); | 151 msg->AddAttribute(std::move(attr)); |
153 } | 152 } |
154 static void AddUsernameAttr(StunMessage* msg, const std::string& val) { | 153 static void AddUsernameAttr(StunMessage* msg, const std::string& val) { |
155 StunByteStringAttribute* attr = | 154 auto attr = StunAttribute::CreateByteString(STUN_ATTR_USERNAME); |
156 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); | |
157 attr->CopyBytes(val.c_str(), val.size()); | 155 attr->CopyBytes(val.c_str(), val.size()); |
158 msg->AddAttribute(attr); | 156 msg->AddAttribute(std::move(attr)); |
159 } | 157 } |
160 static void AddLifetimeAttr(StunMessage* msg, int val) { | 158 static void AddLifetimeAttr(StunMessage* msg, int val) { |
161 StunUInt32Attribute* attr = | 159 auto attr = StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME); |
162 StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME); | |
163 attr->SetValue(val); | 160 attr->SetValue(val); |
164 msg->AddAttribute(attr); | 161 msg->AddAttribute(std::move(attr)); |
165 } | 162 } |
166 static void AddDestinationAttr(StunMessage* msg, const SocketAddress& addr) { | 163 static void AddDestinationAttr(StunMessage* msg, const SocketAddress& addr) { |
167 StunAddressAttribute* attr = | 164 auto attr = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); |
168 StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); | |
169 attr->SetIP(addr.ipaddr()); | 165 attr->SetIP(addr.ipaddr()); |
170 attr->SetPort(addr.port()); | 166 attr->SetPort(addr.port()); |
171 msg->AddAttribute(attr); | 167 msg->AddAttribute(std::move(attr)); |
172 } | 168 } |
173 | 169 |
174 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 170 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
175 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 171 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
176 rtc::SocketServerScope ss_scope_; | 172 rtc::SocketServerScope ss_scope_; |
177 std::unique_ptr<RelayServer> server_; | 173 std::unique_ptr<RelayServer> server_; |
178 std::unique_ptr<rtc::TestClient> client1_; | 174 std::unique_ptr<rtc::TestClient> client1_; |
179 std::unique_ptr<rtc::TestClient> client2_; | 175 std::unique_ptr<rtc::TestClient> client2_; |
180 std::string username_; | 176 std::string username_; |
181 std::string password_; | 177 std::string password_; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 TEST_F(RelayServerTest, TestSendRaw) { | 447 TEST_F(RelayServerTest, TestSendRaw) { |
452 Allocate(); | 448 Allocate(); |
453 Bind(); | 449 Bind(); |
454 | 450 |
455 for (int i = 0; i < 10; i++) { | 451 for (int i = 0; i < 10; i++) { |
456 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; | 452 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; |
457 AddMagicCookieAttr(req.get()); | 453 AddMagicCookieAttr(req.get()); |
458 AddUsernameAttr(req.get(), username_); | 454 AddUsernameAttr(req.get(), username_); |
459 AddDestinationAttr(req.get(), client2_addr); | 455 AddDestinationAttr(req.get(), client2_addr); |
460 | 456 |
461 StunByteStringAttribute* send_data = | 457 auto send_data = StunAttribute::CreateByteString(STUN_ATTR_DATA); |
462 StunAttribute::CreateByteString(STUN_ATTR_DATA); | |
463 send_data->CopyBytes(msg1); | 458 send_data->CopyBytes(msg1); |
464 req->AddAttribute(send_data); | 459 req->AddAttribute(std::move(send_data)); |
465 | 460 |
466 Send1(req.get()); | 461 Send1(req.get()); |
467 EXPECT_EQ(msg1, ReceiveRaw2()); | 462 EXPECT_EQ(msg1, ReceiveRaw2()); |
468 SendRaw2(msg2, static_cast<int>(strlen(msg2))); | 463 SendRaw2(msg2, static_cast<int>(strlen(msg2))); |
469 res.reset(Receive1()); | 464 res.reset(Receive1()); |
470 | 465 |
471 ASSERT_TRUE(res); | 466 ASSERT_TRUE(res); |
472 EXPECT_EQ(STUN_DATA_INDICATION, res->type()); | 467 EXPECT_EQ(STUN_DATA_INDICATION, res->type()); |
473 | 468 |
474 const StunAddressAttribute* src_addr = | 469 const StunAddressAttribute* src_addr = |
(...skipping 18 matching lines...) Expand all Loading... |
493 Bind(); | 488 Bind(); |
494 | 489 |
495 // Wait twice the lifetime to make sure the server has expired the binding. | 490 // Wait twice the lifetime to make sure the server has expired the binding. |
496 rtc::Thread::Current()->ProcessMessages((LIFETIME * 2) * 1000); | 491 rtc::Thread::Current()->ProcessMessages((LIFETIME * 2) * 1000); |
497 | 492 |
498 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; | 493 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; |
499 AddMagicCookieAttr(req.get()); | 494 AddMagicCookieAttr(req.get()); |
500 AddUsernameAttr(req.get(), username_); | 495 AddUsernameAttr(req.get(), username_); |
501 AddDestinationAttr(req.get(), client2_addr); | 496 AddDestinationAttr(req.get(), client2_addr); |
502 | 497 |
503 StunByteStringAttribute* data_attr = | 498 auto data_attr = StunAttribute::CreateByteString(STUN_ATTR_DATA); |
504 StunAttribute::CreateByteString(STUN_ATTR_DATA); | |
505 data_attr->CopyBytes(msg1); | 499 data_attr->CopyBytes(msg1); |
506 req->AddAttribute(data_attr); | 500 req->AddAttribute(std::move(data_attr)); |
507 | 501 |
508 Send1(req.get()); | 502 Send1(req.get()); |
509 res.reset(Receive1()); | 503 res.reset(Receive1()); |
510 | 504 |
511 ASSERT_TRUE(res.get() != NULL); | 505 ASSERT_TRUE(res.get() != NULL); |
512 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); | 506 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); |
513 | 507 |
514 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 508 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
515 ASSERT_TRUE(err != NULL); | 509 ASSERT_TRUE(err != NULL); |
516 EXPECT_EQ(6, err->eclass()); | 510 EXPECT_EQ(6, err->eclass()); |
517 EXPECT_EQ(0, err->number()); | 511 EXPECT_EQ(0, err->number()); |
518 EXPECT_EQ("Operation Not Supported", err->reason()); | 512 EXPECT_EQ("Operation Not Supported", err->reason()); |
519 | 513 |
520 // Also verify that traffic from the external client is ignored. | 514 // Also verify that traffic from the external client is ignored. |
521 SendRaw2(msg2, static_cast<int>(strlen(msg2))); | 515 SendRaw2(msg2, static_cast<int>(strlen(msg2))); |
522 EXPECT_TRUE(ReceiveRaw1().empty()); | 516 EXPECT_TRUE(ReceiveRaw1().empty()); |
523 } | 517 } |
OLD | NEW |