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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 pretending_to_be_writable_ = false; | 380 pretending_to_be_writable_ = false; |
381 ASSERT(write_state() == STATE_WRITABLE); | 381 ASSERT(write_state() == STATE_WRITABLE); |
382 } | 382 } |
383 | 383 |
384 void TCPConnection::OnConnect(rtc::AsyncPacketSocket* socket) { | 384 void TCPConnection::OnConnect(rtc::AsyncPacketSocket* socket) { |
385 ASSERT(socket == socket_.get()); | 385 ASSERT(socket == socket_.get()); |
386 // Do not use this connection if the socket bound to a different address than | 386 // Do not use this connection if the socket bound to a different address than |
387 // the one we asked for. This is seen in Chrome, where TCP sockets cannot be | 387 // the one we asked for. This is seen in Chrome, where TCP sockets cannot be |
388 // given a binding address, and the platform is expected to pick the | 388 // given a binding address, and the platform is expected to pick the |
389 // correct local address. | 389 // correct local address. |
390 const rtc::IPAddress& socket_ip = socket->GetLocalAddress().ipaddr(); | 390 const rtc::SocketAddress& socket_addr = socket->GetLocalAddress(); |
391 if (socket_ip == port()->ip() || IPIsAny(port()->ip())) { | 391 if (socket_addr.ipaddr() == port()->ip()) { |
392 if (socket_ip == port()->ip()) { | 392 LOG_J(LS_VERBOSE, this) << "Connection established to " |
393 LOG_J(LS_VERBOSE, this) << "Connection established to " | 393 << socket->GetRemoteAddress().ToSensitiveString(); |
394 << socket->GetRemoteAddress().ToSensitiveString(); | 394 } else if (IPIsAny(port()->ip())) { |
395 } else { | 395 LOG(LS_WARNING) << "Socket is bound to a different address:" |
396 LOG(LS_WARNING) << "Socket is bound to a different address:" | 396 << socket_addr.ipaddr().ToString() |
397 << socket->GetLocalAddress().ipaddr().ToString() | 397 << ", rather then the local port:" |
398 << ", rather then the local port:" | 398 << port()->ip().ToString() |
399 << port()->ip().ToString() | 399 << ". Still allowing it since it's any address" |
400 << ". Still allowing it since it's any address" | 400 << ", possibly caused by multi-routes being disabled."; |
401 << ", possibly caused by multi-routes being disabled."; | 401 } else if (socket_addr.IsLoopbackIP()) { |
402 } | 402 LOG(LS_WARNING) << "Socket is bound to a different address:" |
403 set_connected(true); | 403 << socket_addr.ipaddr().ToString() |
404 connection_pending_ = false; | 404 << ", rather then the local port:" |
| 405 << port()->ip().ToString() |
| 406 << ". Still allowing it since it's localhost."; |
405 } else { | 407 } else { |
406 LOG_J(LS_WARNING, this) << "Dropping connection as TCP socket bound to IP " | 408 LOG_J(LS_WARNING, this) << "Dropping connection as TCP socket bound to IP " |
407 << socket_ip.ToSensitiveString() | 409 << socket_addr.ipaddr().ToSensitiveString() |
408 << ", different from the local candidate IP " | 410 << ", different from the local candidate IP " |
409 << port()->ip().ToSensitiveString(); | 411 << port()->ip().ToSensitiveString(); |
410 OnClose(socket, 0); | 412 OnClose(socket, 0); |
| 413 return; |
411 } | 414 } |
| 415 |
| 416 // Connection is established successfully. |
| 417 set_connected(true); |
| 418 connection_pending_ = false; |
412 } | 419 } |
413 | 420 |
414 void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) { | 421 void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) { |
415 ASSERT(socket == socket_.get()); | 422 ASSERT(socket == socket_.get()); |
416 LOG_J(LS_INFO, this) << "Connection closed with error " << error; | 423 LOG_J(LS_INFO, this) << "Connection closed with error " << error; |
417 | 424 |
418 // Guard against the condition where IPC socket will call OnClose for every | 425 // Guard against the condition where IPC socket will call OnClose for every |
419 // packet it can't send. | 426 // packet it can't send. |
420 if (connected()) { | 427 if (connected()) { |
421 set_connected(false); | 428 set_connected(false); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { | 512 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { |
506 if (outgoing_) { | 513 if (outgoing_) { |
507 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); | 514 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); |
508 } | 515 } |
509 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); | 516 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); |
510 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); | 517 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); |
511 socket->SignalClose.connect(this, &TCPConnection::OnClose); | 518 socket->SignalClose.connect(this, &TCPConnection::OnClose); |
512 } | 519 } |
513 | 520 |
514 } // namespace cricket | 521 } // namespace cricket |
OLD | NEW |