chromium/third_party/webrtc/p2p/base/tcp_port.cc

/*
 *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

/*
 *  This is a diagram of how TCP reconnect works for the active side. The
 *  passive side just waits for an incoming connection.
 *
 *  - Connected: Indicate whether the TCP socket is connected.
 *
 *  - Writable: Whether the stun binding is completed. Sending a data packet
 *    before stun binding completed will trigger IPC socket layer to shutdown
 *    the connection.
 *
 *  - PendingTCP: `connection_pending_` indicates whether there is an
 *    outstanding TCP connection in progress.
 *
 *  - PretendWri: Tracked by `pretending_to_be_writable_`. Marking connection as
 *    WRITE_TIMEOUT will cause the connection be deleted. Instead, we're
 *    "pretending" we're still writable for a period of time such that reconnect
 *    could work.
 *
 *  Data could only be sent in state 3. Sening data during state 2 & 6 will get
 *  EWOULDBLOCK, 4 & 5 EPIPE.
 *
 *         OS Timeout         7 -------------+
 *   +----------------------->|Connected: N  |
 *   |                        |Writable:  N  |     Timeout
 *   |       Timeout          |Connection is |<----------------+
 *   |   +------------------->|Dead          |                 |
 *   |   |                    +--------------+                 |
 *   |   |                               ^                     |
 *   |   |            OnClose            |                     |
 *   |   |    +-----------------------+  |                     |
 *   |   |    |                       |  |Timeout              |
 *   |   |    v                       |  |                     |
 *   | 4 +----------+          5 -----+--+--+           6 -----+-----+
 *   | |Connected: N|Send() or |Connected: N|           |Connected: Y|
 *   | |Writable:  Y|Ping()    |Writable:  Y|OnConnect  |Writable:  Y|
 *   | |PendingTCP:N+--------> |PendingTCP:Y+---------> |PendingTCP:N|
 *   | |PretendWri:Y|          |PretendWri:Y|           |PretendWri:Y|
 *   | +-----+------+          +------------+           +---+--+-----+
 *   |   ^   ^                                              |  |
 *   |   |   |                     OnClose                  |  |
 *   |   |   +----------------------------------------------+  |
 *   |   |                                                     |
 *   |   |                              Stun Binding Completed |
 *   |   |                                                     |
 *   |   |                    OnClose                          |
 *   |   +------------------------------------------------+    |
 *   |                                                    |    v
 *  1 -----------+           2 -----------+Stun      3 -----------+
 *  |Connected: N|           |Connected: Y|Binding   |Connected: Y|
 *  |Writable:  N|OnConnect  |Writable:  N|Completed |Writable:  Y|
 *  |PendingTCP:Y+---------> |PendingTCP:N+--------> |PendingTCP:N|
 *  |PretendWri:N|           |PretendWri:N|          |PretendWri:N|
 *  +------------+           +------------+          +------------+
 *
 */

#include "p2p/base/tcp_port.h"

#include <errno.h>

#include <utility>
#include <vector>

#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "api/task_queue/pending_task_safety_flag.h"
#include "api/units/time_delta.h"
#include "p2p/base/p2p_constants.h"
#include "rtc_base/checks.h"
#include "rtc_base/ip_address.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helper.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/rate_tracker.h"
#include "rtc_base/thread.h"

namespace cricket {
IceCandidateType;
SafeTask;
TimeDelta;

TCPPort::TCPPort(const PortParametersRef& args,
                 uint16_t min_port,
                 uint16_t max_port,
                 bool allow_listen)
    :{}

TCPPort::~TCPPort() {}

Connection* TCPPort::CreateConnection(const Candidate& address,
                                      CandidateOrigin origin) {}

void TCPPort::PrepareAddress() {}

int TCPPort::SendTo(const void* data,
                    size_t size,
                    const rtc::SocketAddress& addr,
                    const rtc::PacketOptions& options,
                    bool payload) {}

int TCPPort::GetOption(rtc::Socket::Option opt, int* value) {}

int TCPPort::SetOption(rtc::Socket::Option opt, int value) {}

int TCPPort::GetError() {}

bool TCPPort::SupportsProtocol(absl::string_view protocol) const {}

ProtocolType TCPPort::GetProtocol() const {}

void TCPPort::OnNewConnection(rtc::AsyncListenSocket* socket,
                              rtc::AsyncPacketSocket* new_socket) {}

void TCPPort::TryCreateServerSocket() {}

rtc::AsyncPacketSocket* TCPPort::GetIncoming(const rtc::SocketAddress& addr,
                                             bool remove) {}

void TCPPort::OnReadPacket(rtc::AsyncPacketSocket* socket,
                           const rtc::ReceivedPacket& packet) {}

void TCPPort::OnSentPacket(rtc::AsyncPacketSocket* socket,
                           const rtc::SentPacket& sent_packet) {}

void TCPPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) {}

// TODO(qingsi): `CONNECTION_WRITE_CONNECT_TIMEOUT` is overriden by
// `ice_unwritable_timeout` in IceConfig when determining the writability state.
// Replace this constant with the config parameter assuming the default value if
// we decide it is also applicable here.
TCPConnection::TCPConnection(rtc::WeakPtr<Port> tcp_port,
                             const Candidate& candidate,
                             rtc::AsyncPacketSocket* socket)
    :{}

TCPConnection::~TCPConnection() {}

int TCPConnection::Send(const void* data,
                        size_t size,
                        const rtc::PacketOptions& options) {}

int TCPConnection::GetError() {}

void TCPConnection::OnSentPacket(rtc::AsyncPacketSocket* socket,
                                 const rtc::SentPacket& sent_packet) {}

void TCPConnection::OnConnectionRequestResponse(StunRequest* req,
                                                StunMessage* response) {}

void TCPConnection::OnConnect(rtc::AsyncPacketSocket* socket) {}

void TCPConnection::OnClose(rtc::AsyncPacketSocket* socket, int error) {}

void TCPConnection::MaybeReconnect() {}

void TCPConnection::OnReadPacket(rtc::AsyncPacketSocket* socket,
                                 const rtc::ReceivedPacket& packet) {}

void TCPConnection::OnReadyToSend(rtc::AsyncPacketSocket* socket) {}

void TCPConnection::OnDestroyed(Connection* c) {}

void TCPConnection::CreateOutgoingTcpSocket() {}

void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) {}

void TCPConnection::DisconnectSocketSignals(rtc::AsyncPacketSocket* socket) {}

}  // namespace cricket