OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/p2p/ipc_socket_factory.h" | 5 #include "content/renderer/p2p/ipc_socket_factory.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 } | 391 } |
392 | 392 |
393 error_ = EWOULDBLOCK; | 393 error_ = EWOULDBLOCK; |
394 IncrementDiscardCounters(data_size); | 394 IncrementDiscardCounters(data_size); |
395 return -1; | 395 return -1; |
396 } else { | 396 } else { |
397 current_discard_bytes_sequence_ = 0; | 397 current_discard_bytes_sequence_ = 0; |
398 } | 398 } |
399 | 399 |
400 net::IPEndPoint address_chrome; | 400 net::IPEndPoint address_chrome; |
401 if (!jingle_glue::SocketAddressToIPEndPoint(address, &address_chrome)) { | 401 if (address.IsUnresolvedIP()) { |
402 LOG(WARNING) << "Failed to convert remote address to IPEndPoint: address = " | 402 address_chrome = net::IPEndPoint(net::IPAddressNumber(), address.port()); |
juberti2
2014/12/11 19:23:50
I think we should check that address == remote_add
| |
403 << address.ipaddr().ToSensitiveString() | 403 } else { |
404 << ", remote_address_ = " | 404 if (!jingle_glue::SocketAddressToIPEndPoint(address, &address_chrome)) { |
405 << remote_address_.ipaddr().ToSensitiveString(); | 405 LOG(WARNING) << "Failed to convert remote address to IPEndPoint: address=" |
406 NOTREACHED(); | 406 << address.ipaddr().ToSensitiveString() |
407 error_ = EINVAL; | 407 << ", remote_address_=" |
408 return -1; | 408 << remote_address_.ipaddr().ToSensitiveString(); |
409 NOTREACHED(); | |
410 error_ = EINVAL; | |
411 return -1; | |
412 } | |
409 } | 413 } |
410 | 414 |
411 send_bytes_available_ -= data_size; | 415 send_bytes_available_ -= data_size; |
412 in_flight_packet_sizes_.push_back(data_size); | 416 in_flight_packet_sizes_.push_back(data_size); |
413 TraceSendThrottlingState(); | 417 TraceSendThrottlingState(); |
414 | 418 |
415 const char* data_char = reinterpret_cast<const char*>(data); | 419 const char* data_char = reinterpret_cast<const char*>(data); |
416 std::vector<char> data_vector(data_char, data_char + data_size); | 420 std::vector<char> data_vector(data_char, data_char + data_size); |
417 client_->SendWithDscp(address_chrome, data_vector, options); | 421 client_->SendWithDscp(address_chrome, data_vector, options); |
418 | 422 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 DoSetOption(static_cast<P2PSocketOption> (i), options_[i]); | 527 DoSetOption(static_cast<P2PSocketOption> (i), options_[i]); |
524 } | 528 } |
525 | 529 |
526 SignalAddressReady(this, local_address_); | 530 SignalAddressReady(this, local_address_); |
527 if (IsTcpClientSocket(type_)) { | 531 if (IsTcpClientSocket(type_)) { |
528 // If remote address is unresolved, set resolved remote IP address received | 532 // If remote address is unresolved, set resolved remote IP address received |
529 // in the callback. This address will be used while sending the packets | 533 // in the callback. This address will be used while sending the packets |
530 // over the network. | 534 // over the network. |
531 if (remote_address_.IsUnresolvedIP()) { | 535 if (remote_address_.IsUnresolvedIP()) { |
532 rtc::SocketAddress jingle_socket_address; | 536 rtc::SocketAddress jingle_socket_address; |
533 if (!jingle_glue::IPEndPointToSocketAddress( | 537 if (jingle_glue::IPEndPointToSocketAddress( |
534 remote_address, &jingle_socket_address)) { | 538 remote_address, &jingle_socket_address)) { |
535 LOG(WARNING) << "Failed to convert remote IPEndPoint to SocketAddress: " | 539 // Set only the IP address. |
536 << remote_address.ToString(); | 540 remote_address_.SetResolvedIP(jingle_socket_address.ipaddr()); |
537 NOTREACHED(); | 541 } else { |
542 // This could happen if the socket is connected through a proxy. | |
543 VLOG(3) << "Failed to convert remote IPEndPoint to SocketAddress: " | |
Sergey Ulanov
2014/12/11 19:09:17
Do we need to log it at all if it's expected?
juberti2
2014/12/11 19:23:50
agree, we should probably not even try this step i
| |
544 << remote_address.ToString(); | |
538 } | 545 } |
539 // Set only the IP address. | |
540 remote_address_.SetResolvedIP(jingle_socket_address.ipaddr()); | |
541 } | 546 } |
542 | 547 |
543 // SignalConnect after updating the |remote_address_| so that the listener | 548 // SignalConnect after updating the |remote_address_| so that the listener |
544 // can get the resolved remote address. | 549 // can get the resolved remote address. |
545 SignalConnect(this); | 550 SignalConnect(this); |
546 } | 551 } |
547 } | 552 } |
548 | 553 |
549 void IpcPacketSocket::OnIncomingTcpConnection( | 554 void IpcPacketSocket::OnIncomingTcpConnection( |
550 const net::IPEndPoint& address, | 555 const net::IPEndPoint& address, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 SignalClose(this, 0); | 597 SignalClose(this, 0); |
593 } | 598 } |
594 } | 599 } |
595 | 600 |
596 void IpcPacketSocket::OnDataReceived(const net::IPEndPoint& address, | 601 void IpcPacketSocket::OnDataReceived(const net::IPEndPoint& address, |
597 const std::vector<char>& data, | 602 const std::vector<char>& data, |
598 const base::TimeTicks& timestamp) { | 603 const base::TimeTicks& timestamp) { |
599 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 604 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
600 | 605 |
601 rtc::SocketAddress address_lj; | 606 rtc::SocketAddress address_lj; |
602 if (!jingle_glue::IPEndPointToSocketAddress(address, &address_lj)) { | 607 |
603 // We should always be able to convert address here because we | 608 if (address.address().empty()) { |
juberti2
2014/12/11 19:23:50
check that this only happens for TCP connections?
| |
604 // don't expect IPv6 address on IPv4 connections. | 609 // |address| could be empty for TCP connections behind a proxy. |
605 NOTREACHED(); | 610 address_lj = remote_address_; |
606 return; | 611 } else { |
612 if (!jingle_glue::IPEndPointToSocketAddress(address, &address_lj)) { | |
613 // We should always be able to convert address here because we | |
614 // don't expect IPv6 address on IPv4 connections. | |
615 NOTREACHED(); | |
616 return; | |
617 } | |
607 } | 618 } |
608 | 619 |
609 rtc::PacketTime packet_time(timestamp.ToInternalValue(), 0); | 620 rtc::PacketTime packet_time(timestamp.ToInternalValue(), 0); |
610 SignalReadPacket(this, &data[0], data.size(), address_lj, | 621 SignalReadPacket(this, &data[0], data.size(), address_lj, |
611 packet_time); | 622 packet_time); |
612 } | 623 } |
613 | 624 |
614 AsyncAddressResolverImpl::AsyncAddressResolverImpl( | 625 AsyncAddressResolverImpl::AsyncAddressResolverImpl( |
615 P2PSocketDispatcher* dispatcher) | 626 P2PSocketDispatcher* dispatcher) |
616 : resolver_(new P2PAsyncAddressResolver(dispatcher)) { | 627 : resolver_(new P2PAsyncAddressResolver(dispatcher)) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 } | 754 } |
744 | 755 |
745 rtc::AsyncResolverInterface* | 756 rtc::AsyncResolverInterface* |
746 IpcPacketSocketFactory::CreateAsyncResolver() { | 757 IpcPacketSocketFactory::CreateAsyncResolver() { |
747 scoped_ptr<AsyncAddressResolverImpl> resolver( | 758 scoped_ptr<AsyncAddressResolverImpl> resolver( |
748 new AsyncAddressResolverImpl(socket_dispatcher_)); | 759 new AsyncAddressResolverImpl(socket_dispatcher_)); |
749 return resolver.release(); | 760 return resolver.release(); |
750 } | 761 } |
751 | 762 |
752 } // namespace content | 763 } // namespace content |
OLD | NEW |