| 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 28 matching lines...) Expand all Loading... |
| 39 << " bytes"; | 39 << " bytes"; |
| 40 } else if (result < 0) { | 40 } else if (result < 0) { |
| 41 LOG_ERR(LS_ERROR) << "SendTo"; | 41 LOG_ERR(LS_ERROR) << "SendTo"; |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Sends the given STUN message on the given socket. | 45 // Sends the given STUN message on the given socket. |
| 46 void SendStun(const StunMessage& msg, | 46 void SendStun(const StunMessage& msg, |
| 47 rtc::AsyncPacketSocket* socket, | 47 rtc::AsyncPacketSocket* socket, |
| 48 const rtc::SocketAddress& addr) { | 48 const rtc::SocketAddress& addr) { |
| 49 rtc::ByteBuffer buf; | 49 rtc::ByteBufferWriter buf; |
| 50 msg.Write(&buf); | 50 msg.Write(&buf); |
| 51 Send(socket, buf.Data(), buf.Length(), addr); | 51 Send(socket, buf.Data(), buf.Length(), addr); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Constructs a STUN error response and sends it on the given socket. | 54 // Constructs a STUN error response and sends it on the given socket. |
| 55 void SendStunError(const StunMessage& msg, rtc::AsyncPacketSocket* socket, | 55 void SendStunError(const StunMessage& msg, rtc::AsyncPacketSocket* socket, |
| 56 const rtc::SocketAddress& remote_addr, int error_code, | 56 const rtc::SocketAddress& remote_addr, int error_code, |
| 57 const char* error_desc, const std::string& magic_cookie) { | 57 const char* error_desc, const std::string& magic_cookie) { |
| 58 RelayMessage err_msg; | 58 RelayMessage err_msg; |
| 59 err_msg.SetType(GetStunErrorResponseType(msg.type())); | 59 err_msg.SetType(GetStunErrorResponseType(msg.type())); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 ext_conn->addr_pair().source()); | 242 ext_conn->addr_pair().source()); |
| 243 ASSERT(int_conn != NULL); | 243 ASSERT(int_conn != NULL); |
| 244 int_conn->Send(bytes, size, ext_conn->addr_pair().source()); | 244 int_conn->Send(bytes, size, ext_conn->addr_pair().source()); |
| 245 ext_conn->Lock(); // allow outgoing packets | 245 ext_conn->Lock(); // allow outgoing packets |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 | 248 |
| 249 // The first packet should always be a STUN / TURN packet. If it isn't, then | 249 // The first packet should always be a STUN / TURN packet. If it isn't, then |
| 250 // we should just ignore this packet. | 250 // we should just ignore this packet. |
| 251 RelayMessage msg; | 251 RelayMessage msg; |
| 252 rtc::ByteBuffer buf(bytes, size); | 252 rtc::ByteBufferReader buf(bytes, size); |
| 253 if (!msg.Read(&buf)) { | 253 if (!msg.Read(&buf)) { |
| 254 LOG(LS_WARNING) << "Dropping packet: first packet not STUN"; | 254 LOG(LS_WARNING) << "Dropping packet: first packet not STUN"; |
| 255 return; | 255 return; |
| 256 } | 256 } |
| 257 | 257 |
| 258 // The initial packet should have a username (which identifies the binding). | 258 // The initial packet should have a username (which identifies the binding). |
| 259 const StunByteStringAttribute* username_attr = | 259 const StunByteStringAttribute* username_attr = |
| 260 msg.GetByteString(STUN_ATTR_USERNAME); | 260 msg.GetByteString(STUN_ATTR_USERNAME); |
| 261 if (!username_attr) { | 261 if (!username_attr) { |
| 262 LOG(LS_WARNING) << "Dropping packet: no username"; | 262 LOG(LS_WARNING) << "Dropping packet: no username"; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 291 ASSERT(int_conn != NULL); | 291 ASSERT(int_conn != NULL); |
| 292 int_conn->Send(bytes, size, ext_conn->addr_pair().source()); | 292 int_conn->Send(bytes, size, ext_conn->addr_pair().source()); |
| 293 } | 293 } |
| 294 | 294 |
| 295 bool RelayServer::HandleStun( | 295 bool RelayServer::HandleStun( |
| 296 const char* bytes, size_t size, const rtc::SocketAddress& remote_addr, | 296 const char* bytes, size_t size, const rtc::SocketAddress& remote_addr, |
| 297 rtc::AsyncPacketSocket* socket, std::string* username, | 297 rtc::AsyncPacketSocket* socket, std::string* username, |
| 298 StunMessage* msg) { | 298 StunMessage* msg) { |
| 299 | 299 |
| 300 // Parse this into a stun message. Eat the message if this fails. | 300 // Parse this into a stun message. Eat the message if this fails. |
| 301 rtc::ByteBuffer buf(bytes, size); | 301 rtc::ByteBufferReader buf(bytes, size); |
| 302 if (!msg->Read(&buf)) { | 302 if (!msg->Read(&buf)) { |
| 303 return false; | 303 return false; |
| 304 } | 304 } |
| 305 | 305 |
| 306 // The initial packet should have a username (which identifies the binding). | 306 // The initial packet should have a username (which identifies the binding). |
| 307 const StunByteStringAttribute* username_attr = | 307 const StunByteStringAttribute* username_attr = |
| 308 msg->GetByteString(STUN_ATTR_USERNAME); | 308 msg->GetByteString(STUN_ATTR_USERNAME); |
| 309 if (!username_attr) { | 309 if (!username_attr) { |
| 310 SendStunError(*msg, socket, remote_addr, 432, "Missing Username", ""); | 310 SendStunError(*msg, socket, remote_addr, 432, "Missing Username", ""); |
| 311 return false; | 311 return false; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 } else { | 741 } else { |
| 742 server_->thread()->PostDelayed(lifetime_, this, MSG_LIFETIME_TIMER); | 742 server_->thread()->PostDelayed(lifetime_, this, MSG_LIFETIME_TIMER); |
| 743 } | 743 } |
| 744 | 744 |
| 745 } else { | 745 } else { |
| 746 ASSERT(false); | 746 ASSERT(false); |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 | 749 |
| 750 } // namespace cricket | 750 } // namespace cricket |
| OLD | NEW |