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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 // If the user has enabled port packets, just hand this over. | 281 // If the user has enabled port packets, just hand this over. |
282 if (enable_port_packets_) { | 282 if (enable_port_packets_) { |
283 SignalReadPacket(this, data, size, addr); | 283 SignalReadPacket(this, data, size, addr); |
284 return; | 284 return; |
285 } | 285 } |
286 | 286 |
287 // If this is an authenticated STUN request, then signal unknown address and | 287 // If this is an authenticated STUN request, then signal unknown address and |
288 // send back a proper binding response. | 288 // send back a proper binding response. |
289 rtc::scoped_ptr<IceMessage> msg; | 289 rtc::scoped_ptr<IceMessage> msg; |
290 std::string remote_username; | 290 std::string remote_username; |
291 if (!GetStunMessage(data, size, addr, msg.accept(), &remote_username)) { | 291 if (!GetStunMessage(data, size, addr, &msg, &remote_username)) { |
292 LOG_J(LS_ERROR, this) << "Received non-STUN packet from unknown address (" | 292 LOG_J(LS_ERROR, this) << "Received non-STUN packet from unknown address (" |
293 << addr.ToSensitiveString() << ")"; | 293 << addr.ToSensitiveString() << ")"; |
294 } else if (!msg) { | 294 } else if (!msg) { |
295 // STUN message handled already | 295 // STUN message handled already |
296 } else if (msg->type() == STUN_BINDING_REQUEST) { | 296 } else if (msg->type() == STUN_BINDING_REQUEST) { |
297 LOG(LS_INFO) << "Received STUN ping " | 297 LOG(LS_INFO) << "Received STUN ping " |
298 << " id=" << rtc::hex_encode(msg->transaction_id()) | 298 << " id=" << rtc::hex_encode(msg->transaction_id()) |
299 << " from unknown address " << addr.ToSensitiveString(); | 299 << " from unknown address " << addr.ToSensitiveString(); |
300 | 300 |
301 // Check for role conflicts. | 301 // Check for role conflicts. |
(...skipping 21 matching lines...) Expand all Loading... | |
323 for (; iter != connections_.end(); ++iter) { | 323 for (; iter != connections_.end(); ++iter) { |
324 iter->second->OnReadyToSend(); | 324 iter->second->OnReadyToSend(); |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 size_t Port::AddPrflxCandidate(const Candidate& local) { | 328 size_t Port::AddPrflxCandidate(const Candidate& local) { |
329 candidates_.push_back(local); | 329 candidates_.push_back(local); |
330 return (candidates_.size() - 1); | 330 return (candidates_.size() - 1); |
331 } | 331 } |
332 | 332 |
333 bool Port::GetStunMessage(const char* data, size_t size, | 333 bool Port::GetStunMessage(const char* data, |
334 size_t size, | |
334 const rtc::SocketAddress& addr, | 335 const rtc::SocketAddress& addr, |
335 IceMessage** out_msg, std::string* out_username) { | 336 rtc::scoped_ptr<IceMessage>* out_msg, |
337 std::string* out_username) { | |
336 // NOTE: This could clearly be optimized to avoid allocating any memory. | 338 // NOTE: This could clearly be optimized to avoid allocating any memory. |
337 // However, at the data rates we'll be looking at on the client side, | 339 // However, at the data rates we'll be looking at on the client side, |
338 // this probably isn't worth worrying about. | 340 // this probably isn't worth worrying about. |
339 ASSERT(out_msg != NULL); | 341 ASSERT(out_msg != NULL); |
340 ASSERT(out_username != NULL); | 342 ASSERT(out_username != NULL); |
341 *out_msg = NULL; | 343 out_msg->reset(); |
tommi
2016/03/15 09:30:16
Prefer to have this be the caller's responsibility
kwiberg-webrtc
2016/03/15 10:16:01
Sure. I just left it in because I wanted to make a
| |
342 out_username->clear(); | 344 out_username->clear(); |
343 | 345 |
344 // Don't bother parsing the packet if we can tell it's not STUN. | 346 // Don't bother parsing the packet if we can tell it's not STUN. |
345 // In ICE mode, all STUN packets will have a valid fingerprint. | 347 // In ICE mode, all STUN packets will have a valid fingerprint. |
346 if (!StunMessage::ValidateFingerprint(data, size)) { | 348 if (!StunMessage::ValidateFingerprint(data, size)) { |
347 return false; | 349 return false; |
348 } | 350 } |
349 | 351 |
350 // Parse the request message. If the packet is not a complete and correct | 352 // Parse the request message. If the packet is not a complete and correct |
351 // STUN message, then ignore it. | 353 // STUN message, then ignore it. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 // No stun attributes will be verified, if it's stun indication message. | 417 // No stun attributes will be verified, if it's stun indication message. |
416 // Returning from end of the this method. | 418 // Returning from end of the this method. |
417 } else { | 419 } else { |
418 LOG_J(LS_ERROR, this) << "Received STUN packet with invalid type (" | 420 LOG_J(LS_ERROR, this) << "Received STUN packet with invalid type (" |
419 << stun_msg->type() << ") from " | 421 << stun_msg->type() << ") from " |
420 << addr.ToSensitiveString(); | 422 << addr.ToSensitiveString(); |
421 return true; | 423 return true; |
422 } | 424 } |
423 | 425 |
424 // Return the STUN message found. | 426 // Return the STUN message found. |
425 *out_msg = stun_msg.release(); | 427 *out_msg = std::move(stun_msg); |
426 return true; | 428 return true; |
427 } | 429 } |
428 | 430 |
429 bool Port::IsCompatibleAddress(const rtc::SocketAddress& addr) { | 431 bool Port::IsCompatibleAddress(const rtc::SocketAddress& addr) { |
430 int family = ip().family(); | 432 int family = ip().family(); |
431 // We use single-stack sockets, so families must match. | 433 // We use single-stack sockets, so families must match. |
432 if (addr.family() != family) { | 434 if (addr.family() != family) { |
433 return false; | 435 return false; |
434 } | 436 } |
435 // Link-local IPv6 ports can only connect to other link-local IPv6 ports. | 437 // Link-local IPv6 ports can only connect to other link-local IPv6 ports. |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
895 << " err=" << err | 897 << " err=" << err |
896 << " id=" << rtc::hex_encode(req->id()); | 898 << " id=" << rtc::hex_encode(req->id()); |
897 } | 899 } |
898 } | 900 } |
899 | 901 |
900 void Connection::OnReadPacket( | 902 void Connection::OnReadPacket( |
901 const char* data, size_t size, const rtc::PacketTime& packet_time) { | 903 const char* data, size_t size, const rtc::PacketTime& packet_time) { |
902 rtc::scoped_ptr<IceMessage> msg; | 904 rtc::scoped_ptr<IceMessage> msg; |
903 std::string remote_ufrag; | 905 std::string remote_ufrag; |
904 const rtc::SocketAddress& addr(remote_candidate_.address()); | 906 const rtc::SocketAddress& addr(remote_candidate_.address()); |
905 if (!port_->GetStunMessage(data, size, addr, msg.accept(), &remote_ufrag)) { | 907 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { |
906 // The packet did not parse as a valid STUN message | 908 // The packet did not parse as a valid STUN message |
907 // This is a data packet, pass it along. | 909 // This is a data packet, pass it along. |
908 set_receiving(true); | 910 set_receiving(true); |
909 last_data_received_ = rtc::Time(); | 911 last_data_received_ = rtc::Time(); |
910 recv_rate_tracker_.AddSamples(size); | 912 recv_rate_tracker_.AddSamples(size); |
911 SignalReadPacket(this, data, size, packet_time); | 913 SignalReadPacket(this, data, size, packet_time); |
912 | 914 |
913 // If timed out sending writability checks, start up again | 915 // If timed out sending writability checks, start up again |
914 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { | 916 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { |
915 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " | 917 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1443 ASSERT(sent < 0); | 1445 ASSERT(sent < 0); |
1444 error_ = port_->GetError(); | 1446 error_ = port_->GetError(); |
1445 sent_packets_discarded_++; | 1447 sent_packets_discarded_++; |
1446 } else { | 1448 } else { |
1447 send_rate_tracker_.AddSamples(sent); | 1449 send_rate_tracker_.AddSamples(sent); |
1448 } | 1450 } |
1449 return sent; | 1451 return sent; |
1450 } | 1452 } |
1451 | 1453 |
1452 } // namespace cricket | 1454 } // namespace cricket |
OLD | NEW |