#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"
#define _DBG_NONE …
#define _DBG_NORMAL …
#define _DBG_VERBOSE …
#define _DEBUGMSG …
namespace cricket {
const uint16_t PACKET_MAXIMUMS[] = …;
const uint32_t MAX_PACKET = …;
const uint32_t MIN_PACKET = …;
const uint32_t IP_HEADER_SIZE = …;
const uint32_t UDP_HEADER_SIZE = …;
const uint32_t JINGLE_HEADER_SIZE = …;
const uint32_t DEFAULT_RCV_BUF_SIZE = …;
const uint32_t DEFAULT_SND_BUF_SIZE = …;
#define PSEUDO_KEEPALIVE …
const uint32_t HEADER_SIZE = …;
const uint32_t PACKET_OVERHEAD = …;
const uint32_t MIN_RTO = …;
const uint32_t DEF_RTO = …;
const uint32_t MAX_RTO = …;
const uint32_t DEF_ACK_DELAY = …;
const uint8_t FLAG_CTL = …;
const uint8_t FLAG_RST = …;
const uint8_t CTL_CONNECT = …;
const uint8_t TCP_OPT_EOL = …;
const uint8_t TCP_OPT_NOOP = …;
const uint8_t TCP_OPT_MSS = …;
const uint8_t TCP_OPT_WND_SCALE = …;
const long DEFAULT_TIMEOUT = …;
const long CLOSED_TIMEOUT = …;
#if PSEUDO_KEEPALIVE
const uint32_t IDLE_PING =
20 *
1000;
const uint32_t IDLE_TIMEOUT = 90 * 1000;
#endif
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) { … }
#if 0
enum Stat {
S_SENT_PACKET,
S_RESENT_PACKET,
S_RECV_PACKET,
S_RECV_NEW,
S_RECV_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
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 { … }
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() { … }
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) { … }
}