chromium/third_party/webrtc/p2p/base/pseudo_tcp.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.
 */

#include "p2p/base/pseudo_tcp.h"

#include <errno.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <cstdint>
#include <memory>
#include <set>

#include "rtc_base/byte_buffer.h"
#include "rtc_base/byte_order.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_minmax.h"
#include "rtc_base/socket.h"
#include "rtc_base/time_utils.h"

// The following logging is for detailed (packet-level) analysis only.
#define _DBG_NONE
#define _DBG_NORMAL
#define _DBG_VERBOSE
#define _DEBUGMSG

namespace cricket {

//////////////////////////////////////////////////////////////////////
// Network Constants
//////////////////////////////////////////////////////////////////////

// Standard MTUs
const uint16_t PACKET_MAXIMUMS[] =;

const uint32_t MAX_PACKET =;
// Note: we removed lowest level because packet overhead was larger!
const uint32_t MIN_PACKET =;

const uint32_t IP_HEADER_SIZE =;  // (+ up to 40 bytes of options?)
const uint32_t UDP_HEADER_SIZE =;
// TODO(?): Make JINGLE_HEADER_SIZE transparent to this code?
const uint32_t JINGLE_HEADER_SIZE =;  // when relay framing is in use

// Default size for receive and send buffer.
const uint32_t DEFAULT_RCV_BUF_SIZE =;
const uint32_t DEFAULT_SND_BUF_SIZE =;

//////////////////////////////////////////////////////////////////////
// Global Constants and Functions
//////////////////////////////////////////////////////////////////////
//
//    0                   1                   2                   3
//    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
//    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//  0 |                      Conversation Number                      |
//    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//  4 |                        Sequence Number                        |
//    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//  8 |                     Acknowledgment Number                     |
//    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//    |               |   |U|A|P|R|S|F|                               |
// 12 |    Control    |   |R|C|S|S|Y|I|            Window             |
//    |               |   |G|K|H|T|N|N|                               |
//    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// 16 |                       Timestamp sending                       |
//    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// 20 |                      Timestamp receiving                      |
//    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// 24 |                             data                              |
//    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
//////////////////////////////////////////////////////////////////////

#define PSEUDO_KEEPALIVE

const uint32_t HEADER_SIZE =;
const uint32_t PACKET_OVERHEAD =;

const uint32_t MIN_RTO =;  // 250 ms (RFC1122, Sec 4.2.3.1 "fractions of a second")
const uint32_t DEF_RTO =;       // 3 seconds (RFC1122, Sec 4.2.3.1)
const uint32_t MAX_RTO =;      // 60 seconds
const uint32_t DEF_ACK_DELAY =;  // 100 milliseconds

const uint8_t FLAG_CTL =;
const uint8_t FLAG_RST =;

const uint8_t CTL_CONNECT =;

// TCP options.
const uint8_t TCP_OPT_EOL =;        // End of list.
const uint8_t TCP_OPT_NOOP =;       // No-op.
const uint8_t TCP_OPT_MSS =;        // Maximum segment size.
const uint8_t TCP_OPT_WND_SCALE =;  // Window scale factor.

const long DEFAULT_TIMEOUT =;  // If there are no pending clocks, wake up every 4 seconds
const long CLOSED_TIMEOUT =;  // If the connection is closed, once per minute

#if PSEUDO_KEEPALIVE
// !?! Rethink these times
const uint32_t IDLE_PING =
    20 *
    1000;  // 20 seconds (note: WinXP SP2 firewall udp timeout is 90 seconds)
const uint32_t IDLE_TIMEOUT = 90 * 1000;  // 90 seconds;
#endif                                    // PSEUDO_KEEPALIVE

//////////////////////////////////////////////////////////////////////
// Helper Functions
//////////////////////////////////////////////////////////////////////

inline void long_to_bytes(uint32_t val, void* buf) {}

inline void short_to_bytes(uint16_t val, void* buf) {}

inline uint32_t bytes_to_long(const void* buf) {}

inline uint16_t bytes_to_short(const void* buf) {}

//////////////////////////////////////////////////////////////////////
// Debugging Statistics
//////////////////////////////////////////////////////////////////////

#if 0  // Not used yet

enum Stat {
  S_SENT_PACKET,    // All packet sends
  S_RESENT_PACKET,  // All packet sends that are retransmits
  S_RECV_PACKET,    // All packet receives
  S_RECV_NEW,       // All packet receives that are too new
  S_RECV_OLD,       // All packet receives that are too old
  S_NUM_STATS
};

const char* const STAT_NAMES[S_NUM_STATS] = {
  "snt",
  "snt-r",
  "rcv"
  "rcv-n",
  "rcv-o"
};

int g_stats[S_NUM_STATS];
inline void Incr(Stat s) { ++g_stats[s]; }
void ReportStats() {
  char buffer[256];
  size_t len = 0;
  for (int i = 0; i < S_NUM_STATS; ++i) {
    len += snprintf(buffer, arraysize(buffer), "%s%s:%d",
                          (i == 0) ? "" : ",", STAT_NAMES[i], g_stats[i]);
    g_stats[i] = 0;
  }
  RTC_LOG(LS_INFO) << "Stats[" << buffer << "]";
}

#endif

//////////////////////////////////////////////////////////////////////
// PseudoTcp
//////////////////////////////////////////////////////////////////////

uint32_t PseudoTcp::Now() {}

PseudoTcp::PseudoTcp(IPseudoTcpNotify* notify, uint32_t conv)
    :{}

PseudoTcp::~PseudoTcp() {}

int PseudoTcp::Connect() {}

void PseudoTcp::NotifyMTU(uint16_t mtu) {}

void PseudoTcp::NotifyClock(uint32_t now) {}

bool PseudoTcp::NotifyPacket(const char* buffer, size_t len) {}

bool PseudoTcp::GetNextClock(uint32_t now, long& timeout) {}

void PseudoTcp::GetOption(Option opt, int* value) {}
void PseudoTcp::SetOption(Option opt, int value) {}

uint32_t PseudoTcp::GetCongestionWindow() const {}

uint32_t PseudoTcp::GetBytesInFlight() const {}

uint32_t PseudoTcp::GetBytesBufferedNotSent() const {}

uint32_t PseudoTcp::GetRoundTripTimeEstimateMs() const {}

//
// IPStream Implementation
//

int PseudoTcp::Recv(char* buffer, size_t len) {}

int PseudoTcp::Send(const char* buffer, size_t len) {}

void PseudoTcp::Close(bool force) {}

int PseudoTcp::GetError() {}

//
// Internal Implementation
//

uint32_t PseudoTcp::queue(const char* data, uint32_t len, bool bCtrl) {}

IPseudoTcpNotify::WriteResult PseudoTcp::packet(uint32_t seq,
                                                uint8_t flags,
                                                uint32_t offset,
                                                uint32_t len) {}

bool PseudoTcp::parse(const uint8_t* buffer, uint32_t size) {}

bool PseudoTcp::clock_check(uint32_t now, long& nTimeout) {}

bool PseudoTcp::process(Segment& seg) {}

bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {}

void PseudoTcp::attemptSend(SendFlags sflags) {}

void PseudoTcp::closedown(uint32_t err) {}

void PseudoTcp::adjustMTU() {}

bool PseudoTcp::isReceiveBufferFull() const {}

void PseudoTcp::disableWindowScale() {}

void PseudoTcp::queueConnectMessage() {}

void PseudoTcp::parseOptions(const char* data, uint32_t len) {}

void PseudoTcp::applyOption(char kind, const char* data, uint32_t len) {}

void PseudoTcp::applyWindowScaleOption(uint8_t scale_factor) {}

void PseudoTcp::resizeSendBuffer(uint32_t new_size) {}

void PseudoTcp::resizeReceiveBuffer(uint32_t new_size) {}

PseudoTcp::LockedFifoBuffer::LockedFifoBuffer(size_t size)
    :{}

PseudoTcp::LockedFifoBuffer::~LockedFifoBuffer() {}

size_t PseudoTcp::LockedFifoBuffer::GetBuffered() const {}

bool PseudoTcp::LockedFifoBuffer::SetCapacity(size_t size) {}

bool PseudoTcp::LockedFifoBuffer::ReadOffset(void* buffer,
                                             size_t bytes,
                                             size_t offset,
                                             size_t* bytes_read) {}

bool PseudoTcp::LockedFifoBuffer::WriteOffset(const void* buffer,
                                              size_t bytes,
                                              size_t offset,
                                              size_t* bytes_written) {}

bool PseudoTcp::LockedFifoBuffer::Read(void* buffer,
                                       size_t bytes,
                                       size_t* bytes_read) {}

bool PseudoTcp::LockedFifoBuffer::Write(const void* buffer,
                                        size_t bytes,
                                        size_t* bytes_written) {}

void PseudoTcp::LockedFifoBuffer::ConsumeReadData(size_t size) {}

void PseudoTcp::LockedFifoBuffer::ConsumeWriteBuffer(size_t size) {}

bool PseudoTcp::LockedFifoBuffer::GetWriteRemaining(size_t* size) const {}

bool PseudoTcp::LockedFifoBuffer::ReadOffsetLocked(void* buffer,
                                                   size_t bytes,
                                                   size_t offset,
                                                   size_t* bytes_read) {}

bool PseudoTcp::LockedFifoBuffer::WriteOffsetLocked(const void* buffer,
                                                    size_t bytes,
                                                    size_t offset,
                                                    size_t* bytes_written) {}

}  // namespace cricket