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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 size_t encoded_size = size + addrlength; | 148 size_t encoded_size = size + addrlength; |
149 memcpy(buf.get() + addrlength, data, size); | 149 memcpy(buf.get() + addrlength, data, size); |
150 int result = socket_->SendTo(buf.get(), encoded_size, server_addr_); | 150 int result = socket_->SendTo(buf.get(), encoded_size, server_addr_); |
151 if (result >= 0) { | 151 if (result >= 0) { |
152 ASSERT(result == static_cast<int>(encoded_size)); | 152 ASSERT(result == static_cast<int>(encoded_size)); |
153 result = result - static_cast<int>(addrlength); | 153 result = result - static_cast<int>(addrlength); |
154 } | 154 } |
155 return result; | 155 return result; |
156 } | 156 } |
157 | 157 |
158 int Recv(void* data, size_t size) override { | 158 int Recv(void* data, size_t size, int64_t* timestamp) override { |
159 SocketAddress addr; | 159 SocketAddress addr; |
160 return RecvFrom(data, size, &addr); | 160 return RecvFrom(data, size, &addr, timestamp); |
161 } | 161 } |
162 | 162 |
163 int RecvFrom(void* data, size_t size, SocketAddress* out_addr) override { | 163 int RecvFrom(void* data, |
| 164 size_t size, |
| 165 SocketAddress* out_addr, |
| 166 int64_t* timestamp) override { |
164 if (server_addr_.IsNil() || type_ == SOCK_STREAM) { | 167 if (server_addr_.IsNil() || type_ == SOCK_STREAM) { |
165 return socket_->RecvFrom(data, size, out_addr); | 168 return socket_->RecvFrom(data, size, out_addr, timestamp); |
166 } | 169 } |
167 // Make sure we have enough room to read the requested amount plus the | 170 // Make sure we have enough room to read the requested amount plus the |
168 // largest possible header address. | 171 // largest possible header address. |
169 SocketAddress remote_addr; | 172 SocketAddress remote_addr; |
170 Grow(size + kNATEncodedIPv6AddressSize); | 173 Grow(size + kNATEncodedIPv6AddressSize); |
171 | 174 |
172 // Read the packet from the socket. | 175 // Read the packet from the socket. |
173 int result = socket_->RecvFrom(buf_, size_, &remote_addr); | 176 int result = socket_->RecvFrom(buf_, size_, &remote_addr, timestamp); |
174 if (result >= 0) { | 177 if (result >= 0) { |
175 ASSERT(remote_addr == server_addr_); | 178 ASSERT(remote_addr == server_addr_); |
176 | 179 |
177 // TODO: we need better framing so we know how many bytes we can | 180 // TODO: we need better framing so we know how many bytes we can |
178 // return before we need to read the next address. For UDP, this will be | 181 // return before we need to read the next address. For UDP, this will be |
179 // fine as long as the reader always reads everything in the packet. | 182 // fine as long as the reader always reads everything in the packet. |
180 ASSERT((size_t)result < size_); | 183 ASSERT((size_t)result < size_); |
181 | 184 |
182 // Decode the wire packet into the actual results. | 185 // Decode the wire packet into the actual results. |
183 SocketAddress real_remote_addr; | 186 SocketAddress real_remote_addr; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 // Sends the destination address to the server to tell it to connect. | 274 // Sends the destination address to the server to tell it to connect. |
272 void SendConnectRequest() { | 275 void SendConnectRequest() { |
273 char buf[kNATEncodedIPv6AddressSize]; | 276 char buf[kNATEncodedIPv6AddressSize]; |
274 size_t length = PackAddressForNAT(buf, arraysize(buf), remote_addr_); | 277 size_t length = PackAddressForNAT(buf, arraysize(buf), remote_addr_); |
275 socket_->Send(buf, length); | 278 socket_->Send(buf, length); |
276 } | 279 } |
277 | 280 |
278 // Handles the byte sent back from the server and fires the appropriate event. | 281 // Handles the byte sent back from the server and fires the appropriate event. |
279 void HandleConnectReply() { | 282 void HandleConnectReply() { |
280 char code; | 283 char code; |
281 socket_->Recv(&code, sizeof(code)); | 284 socket_->Recv(&code, sizeof(code), nullptr); |
282 if (code == 0) { | 285 if (code == 0) { |
283 connected_ = true; | 286 connected_ = true; |
284 SignalConnectEvent(this); | 287 SignalConnectEvent(this); |
285 } else { | 288 } else { |
286 Close(); | 289 Close(); |
287 SignalCloseEvent(this, code); | 290 SignalCloseEvent(this, code); |
288 } | 291 } |
289 } | 292 } |
290 | 293 |
291 NATInternalSocketFactory* sf_; | 294 NATInternalSocketFactory* sf_; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 NATSocketServer::Translator* NATSocketServer::TranslatorMap::FindClient( | 497 NATSocketServer::Translator* NATSocketServer::TranslatorMap::FindClient( |
495 const SocketAddress& int_ip) { | 498 const SocketAddress& int_ip) { |
496 Translator* nat = NULL; | 499 Translator* nat = NULL; |
497 for (TranslatorMap::iterator it = begin(); it != end() && !nat; ++it) { | 500 for (TranslatorMap::iterator it = begin(); it != end() && !nat; ++it) { |
498 nat = it->second->FindClient(int_ip); | 501 nat = it->second->FindClient(int_ip); |
499 } | 502 } |
500 return nat; | 503 return nat; |
501 } | 504 } |
502 | 505 |
503 } // namespace rtc | 506 } // namespace rtc |
OLD | NEW |