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 "webrtc/base/natsocketfactory.h" | 11 #include "webrtc/base/natsocketfactory.h" |
12 | 12 |
| 13 #include "webrtc/base/arraysize.h" |
13 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
14 #include "webrtc/base/natserver.h" | 15 #include "webrtc/base/natserver.h" |
15 #include "webrtc/base/virtualsocketserver.h" | 16 #include "webrtc/base/virtualsocketserver.h" |
16 | 17 |
17 namespace rtc { | 18 namespace rtc { |
18 | 19 |
19 // Packs the given socketaddress into the buffer in buf, in the quasi-STUN | 20 // Packs the given socketaddress into the buffer in buf, in the quasi-STUN |
20 // format that the natserver uses. | 21 // format that the natserver uses. |
21 // Returns 0 if an invalid address is passed. | 22 // Returns 0 if an invalid address is passed. |
22 size_t PackAddressForNAT(char* buf, size_t buf_size, | 23 size_t PackAddressForNAT(char* buf, size_t buf_size, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 if (size_ < new_size) { | 264 if (size_ < new_size) { |
264 delete[] buf_; | 265 delete[] buf_; |
265 size_ = new_size; | 266 size_ = new_size; |
266 buf_ = new char[size_]; | 267 buf_ = new char[size_]; |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 // Sends the destination address to the server to tell it to connect. | 271 // Sends the destination address to the server to tell it to connect. |
271 void SendConnectRequest() { | 272 void SendConnectRequest() { |
272 char buf[kNATEncodedIPv6AddressSize]; | 273 char buf[kNATEncodedIPv6AddressSize]; |
273 size_t length = PackAddressForNAT(buf, ARRAY_SIZE(buf), remote_addr_); | 274 size_t length = PackAddressForNAT(buf, arraysize(buf), remote_addr_); |
274 socket_->Send(buf, length); | 275 socket_->Send(buf, length); |
275 } | 276 } |
276 | 277 |
277 // Handles the byte sent back from the server and fires the appropriate event. | 278 // Handles the byte sent back from the server and fires the appropriate event. |
278 void HandleConnectReply() { | 279 void HandleConnectReply() { |
279 char code; | 280 char code; |
280 socket_->Recv(&code, sizeof(code)); | 281 socket_->Recv(&code, sizeof(code)); |
281 if (code == 0) { | 282 if (code == 0) { |
282 connected_ = true; | 283 connected_ = true; |
283 SignalConnectEvent(this); | 284 SignalConnectEvent(this); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 NATSocketServer::Translator* NATSocketServer::TranslatorMap::FindClient( | 494 NATSocketServer::Translator* NATSocketServer::TranslatorMap::FindClient( |
494 const SocketAddress& int_ip) { | 495 const SocketAddress& int_ip) { |
495 Translator* nat = NULL; | 496 Translator* nat = NULL; |
496 for (TranslatorMap::iterator it = begin(); it != end() && !nat; ++it) { | 497 for (TranslatorMap::iterator it = begin(); it != end() && !nat; ++it) { |
497 nat = it->second->FindClient(int_ip); | 498 nat = it->second->FindClient(int_ip); |
498 } | 499 } |
499 return nat; | 500 return nat; |
500 } | 501 } |
501 | 502 |
502 } // namespace rtc | 503 } // namespace rtc |
OLD | NEW |