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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 void Bind() { | 70 void Bind() { |
71 rtc::scoped_ptr<StunMessage> req( | 71 rtc::scoped_ptr<StunMessage> req( |
72 CreateStunMessage(STUN_BINDING_REQUEST)); | 72 CreateStunMessage(STUN_BINDING_REQUEST)); |
73 AddUsernameAttr(req.get(), username_); | 73 AddUsernameAttr(req.get(), username_); |
74 Send2(req.get()); | 74 Send2(req.get()); |
75 delete Receive1(); | 75 delete Receive1(); |
76 } | 76 } |
77 | 77 |
78 void Send1(const StunMessage* msg) { | 78 void Send1(const StunMessage* msg) { |
79 rtc::ByteBuffer buf; | 79 rtc::ByteBufferWriter buf; |
80 msg->Write(&buf); | 80 msg->Write(&buf); |
81 SendRaw1(buf.Data(), static_cast<int>(buf.Length())); | 81 SendRaw1(buf.Data(), static_cast<int>(buf.Length())); |
82 } | 82 } |
83 void Send2(const StunMessage* msg) { | 83 void Send2(const StunMessage* msg) { |
84 rtc::ByteBuffer buf; | 84 rtc::ByteBufferWriter buf; |
85 msg->Write(&buf); | 85 msg->Write(&buf); |
86 SendRaw2(buf.Data(), static_cast<int>(buf.Length())); | 86 SendRaw2(buf.Data(), static_cast<int>(buf.Length())); |
87 } | 87 } |
88 void SendRaw1(const char* data, int len) { | 88 void SendRaw1(const char* data, int len) { |
89 return Send(client1_.get(), data, len, server_int_addr); | 89 return Send(client1_.get(), data, len, server_int_addr); |
90 } | 90 } |
91 void SendRaw2(const char* data, int len) { | 91 void SendRaw2(const char* data, int len) { |
92 return Send(client2_.get(), data, len, server_ext_addr); | 92 return Send(client2_.get(), data, len, server_ext_addr); |
93 } | 93 } |
94 void Send(rtc::TestClient* client, const char* data, | 94 void Send(rtc::TestClient* client, const char* data, |
(...skipping 18 matching lines...) Expand all Loading... |
113 return ReceiveRaw(client1_.get()); | 113 return ReceiveRaw(client1_.get()); |
114 } | 114 } |
115 std::string ReceiveRaw2() { | 115 std::string ReceiveRaw2() { |
116 return ReceiveRaw(client2_.get()); | 116 return ReceiveRaw(client2_.get()); |
117 } | 117 } |
118 StunMessage* Receive(rtc::TestClient* client) { | 118 StunMessage* Receive(rtc::TestClient* client) { |
119 StunMessage* msg = NULL; | 119 StunMessage* msg = NULL; |
120 rtc::TestClient::Packet* packet = | 120 rtc::TestClient::Packet* packet = |
121 client->NextPacket(rtc::TestClient::kTimeoutMs); | 121 client->NextPacket(rtc::TestClient::kTimeoutMs); |
122 if (packet) { | 122 if (packet) { |
123 rtc::ByteBuffer buf(packet->buf, packet->size); | 123 rtc::ByteBufferWriter buf(packet->buf, packet->size); |
| 124 rtc::ByteBufferReader read_buf(buf); |
124 msg = new RelayMessage(); | 125 msg = new RelayMessage(); |
125 msg->Read(&buf); | 126 msg->Read(&read_buf); |
126 delete packet; | 127 delete packet; |
127 } | 128 } |
128 return msg; | 129 return msg; |
129 } | 130 } |
130 std::string ReceiveRaw(rtc::TestClient* client) { | 131 std::string ReceiveRaw(rtc::TestClient* client) { |
131 std::string raw; | 132 std::string raw; |
132 rtc::TestClient::Packet* packet = | 133 rtc::TestClient::Packet* packet = |
133 client->NextPacket(rtc::TestClient::kTimeoutMs); | 134 client->NextPacket(rtc::TestClient::kTimeoutMs); |
134 if (packet) { | 135 if (packet) { |
135 raw = std::string(packet->buf, packet->size); | 136 raw = std::string(packet->buf, packet->size); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 Send2(req.get()); | 296 Send2(req.get()); |
296 res.reset(Receive1()); | 297 res.reset(Receive1()); |
297 | 298 |
298 ASSERT_TRUE(res); | 299 ASSERT_TRUE(res); |
299 EXPECT_EQ(STUN_DATA_INDICATION, res->type()); | 300 EXPECT_EQ(STUN_DATA_INDICATION, res->type()); |
300 | 301 |
301 const StunByteStringAttribute* recv_data = | 302 const StunByteStringAttribute* recv_data = |
302 res->GetByteString(STUN_ATTR_DATA); | 303 res->GetByteString(STUN_ATTR_DATA); |
303 ASSERT_TRUE(recv_data != NULL); | 304 ASSERT_TRUE(recv_data != NULL); |
304 | 305 |
305 rtc::ByteBuffer buf(recv_data->bytes(), recv_data->length()); | 306 rtc::ByteBufferReader buf(recv_data->bytes(), recv_data->length()); |
306 rtc::scoped_ptr<StunMessage> res2(new StunMessage()); | 307 rtc::scoped_ptr<StunMessage> res2(new StunMessage()); |
307 EXPECT_TRUE(res2->Read(&buf)); | 308 EXPECT_TRUE(res2->Read(&buf)); |
308 EXPECT_EQ(STUN_BINDING_REQUEST, res2->type()); | 309 EXPECT_EQ(STUN_BINDING_REQUEST, res2->type()); |
309 EXPECT_EQ(req->transaction_id(), res2->transaction_id()); | 310 EXPECT_EQ(req->transaction_id(), res2->transaction_id()); |
310 | 311 |
311 const StunAddressAttribute* src_addr = | 312 const StunAddressAttribute* src_addr = |
312 res->GetAddress(STUN_ATTR_SOURCE_ADDRESS2); | 313 res->GetAddress(STUN_ATTR_SOURCE_ADDRESS2); |
313 ASSERT_TRUE(src_addr != NULL); | 314 ASSERT_TRUE(src_addr != NULL); |
314 EXPECT_EQ(1, src_addr->family()); | 315 EXPECT_EQ(1, src_addr->family()); |
315 EXPECT_EQ(client2_addr.ipaddr(), src_addr->ipaddr()); | 316 EXPECT_EQ(client2_addr.ipaddr(), src_addr->ipaddr()); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 521 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
521 ASSERT_TRUE(err != NULL); | 522 ASSERT_TRUE(err != NULL); |
522 EXPECT_EQ(6, err->eclass()); | 523 EXPECT_EQ(6, err->eclass()); |
523 EXPECT_EQ(0, err->number()); | 524 EXPECT_EQ(0, err->number()); |
524 EXPECT_EQ("Operation Not Supported", err->reason()); | 525 EXPECT_EQ("Operation Not Supported", err->reason()); |
525 | 526 |
526 // Also verify that traffic from the external client is ignored. | 527 // Also verify that traffic from the external client is ignored. |
527 SendRaw2(msg2, static_cast<int>(strlen(msg2))); | 528 SendRaw2(msg2, static_cast<int>(strlen(msg2))); |
528 EXPECT_TRUE(ReceiveRaw1().empty()); | 529 EXPECT_TRUE(ReceiveRaw1().empty()); |
529 } | 530 } |
OLD | NEW |