Skip to content

Commit

Permalink
[core] Added Drift Tracer socket option
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Aug 6, 2020
1 parent a043ba4 commit 4dcfa5d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions apps/socketoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ const SocketOption srt_options [] {
{ "snddropdelay", 0, SRTO_SNDDROPDELAY, SocketOption::POST, SocketOption::INT, nullptr},
{ "nakreport", 0, SRTO_NAKREPORT, SocketOption::PRE, SocketOption::BOOL, nullptr},
{ "conntimeo", 0, SRTO_CONNTIMEO, SocketOption::PRE, SocketOption::INT, nullptr},
{ "drifttracer", 0, SRTO_DRIFTTRACER, SocketOption::POST, SocketOption::BOOL, nullptr},
{ "lossmaxttl", 0, SRTO_LOSSMAXTTL, SocketOption::PRE, SocketOption::INT, nullptr},
{ "rcvlatency", 0, SRTO_RCVLATENCY, SocketOption::PRE, SocketOption::INT, nullptr},
{ "peerlatency", 0, SRTO_PEERLATENCY, SocketOption::PRE, SocketOption::INT, nullptr},
Expand Down
44 changes: 24 additions & 20 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ CUDT::CUDT(CUDTSocket* parent): m_parent(parent)
m_Linger.l_linger = 0;
m_bRendezvous = false;
m_tdConnTimeOut = seconds_from(DEF_CONNTIMEO_S);
m_bDriftTracer = true;
m_iSndTimeOut = -1;
m_iRcvTimeOut = -1;
m_bReuseAddr = true;
Expand Down Expand Up @@ -294,6 +295,7 @@ CUDT::CUDT(CUDTSocket* parent, const CUDT& ancestor): m_parent(parent)
m_iSndBufSize = ancestor.m_iSndBufSize;
m_iRcvBufSize = ancestor.m_iRcvBufSize;
m_Linger = ancestor.m_Linger;
m_bDriftTracer = ancestor.m_bDriftTracer;
m_iUDPSndBufSize = ancestor.m_iUDPSndBufSize;
m_iUDPRcvBufSize = ancestor.m_iUDPRcvBufSize;
m_bRendezvous = ancestor.m_bRendezvous;
Expand Down Expand Up @@ -405,6 +407,7 @@ extern const SRT_SOCKOPT srt_post_opt_list [SRT_SOCKOPT_NPOST] = {
SRTO_OHEADBW,
SRTO_SNDDROPDELAY,
SRTO_CONNTIMEO,
SRTO_DRIFTTRACER,
SRTO_LOSSMAXTTL
};

Expand Down Expand Up @@ -731,6 +734,10 @@ void CUDT::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)
m_tdConnTimeOut = milliseconds_from(cast_optval<int>(optval, optlen));
break;

case SRTO_DRIFTTRACER:
m_bDriftTracer = cast_optval<bool>(optval, optlen);
break;

case SRTO_LOSSMAXTTL:
m_iMaxReorderTolerance = cast_optval<int>(optval, optlen);
if (!m_bConnected)
Expand Down Expand Up @@ -1242,6 +1249,11 @@ void CUDT::getOpt(SRT_SOCKOPT optName, void *optval, int &optlen)
optlen = sizeof(int);
break;

case SRTO_DRIFTTRACER:
*(int*)optval = m_bDriftTracer;
optlen = sizeof(int);
break;

case SRTO_MINVERSION:
*(uint32_t *)optval = m_lMinimumPeerSrtVersion;
optlen = sizeof(uint32_t);
Expand Down Expand Up @@ -7487,15 +7499,13 @@ void CUDT::bstats(CBytePerfMon *perf, bool clear, bool instantaneous)
perf->pktCongestionWindow = (int)m_dCongestionWindow;
perf->pktFlightSize = getFlightSpan();
perf->msRTT = (double)m_iRTT / 1000.0;
//>new
perf->msSndTsbPdDelay = m_bPeerTsbPd ? m_iPeerTsbPdDelay_ms : 0;
perf->msRcvTsbPdDelay = isOPT_TsbPd() ? m_iTsbPdDelay_ms : 0;
perf->byteMSS = m_iMSS;

perf->mbpsMaxBW = m_llMaxBW > 0 ? Bps2Mbps(m_llMaxBW) : m_CongCtl.ready() ? Bps2Mbps(m_CongCtl->sndBandwidth()) : 0;

//<
uint32_t availbw = (uint64_t)(m_iBandwidth == 1 ? m_RcvTimeWindow.getBandwidth() : m_iBandwidth);
const uint32_t availbw = (uint64_t)(m_iBandwidth == 1 ? m_RcvTimeWindow.getBandwidth() : m_iBandwidth);

perf->mbpsBandwidth = Bps2Mbps(availbw * (m_iMaxSRTPayloadSize + pktHdrSize));

Expand All @@ -7520,17 +7530,14 @@ void CUDT::bstats(CBytePerfMon *perf, bool clear, bool instantaneous)
else
{
perf->byteAvailSndBuf = 0;
// new>
perf->pktSndBuf = 0;
perf->byteSndBuf = 0;
perf->msSndBuf = 0;
//<
}

if (m_pRcvBuffer)
{
perf->byteAvailRcvBuf = m_pRcvBuffer->getAvailBufSize() * m_iMSS;
// new>
if (instantaneous) // no need for historical API for Rcv side
{
perf->pktRcvBuf = m_pRcvBuffer->getRcvDataSize(perf->byteRcvBuf, perf->msRcvBuf);
Expand All @@ -7539,16 +7546,13 @@ void CUDT::bstats(CBytePerfMon *perf, bool clear, bool instantaneous)
{
perf->pktRcvBuf = m_pRcvBuffer->getRcvAvgDataSize(perf->byteRcvBuf, perf->msRcvBuf);
}
//<
}
else
{
perf->byteAvailRcvBuf = 0;
// new>
perf->pktRcvBuf = 0;
perf->byteRcvBuf = 0;
perf->msRcvBuf = 0;
//<
}

leaveCS(m_ConnectionLock);
Expand All @@ -7557,14 +7561,11 @@ void CUDT::bstats(CBytePerfMon *perf, bool clear, bool instantaneous)
{
perf->byteAvailSndBuf = 0;
perf->byteAvailRcvBuf = 0;
// new>
perf->pktSndBuf = 0;
perf->byteSndBuf = 0;
perf->msSndBuf = 0;

perf->byteRcvBuf = 0;
perf->msRcvBuf = 0;
//<
}

if (clear)
Expand All @@ -7575,10 +7576,8 @@ void CUDT::bstats(CBytePerfMon *perf, bool clear, bool instantaneous)
m_stats.traceRcvBytesDrop = 0;
m_stats.traceRcvUndecrypt = 0;
m_stats.traceRcvBytesUndecrypt = 0;
// new>
m_stats.traceBytesSent = m_stats.traceBytesRecv = m_stats.traceBytesRetrans = 0;
m_stats.traceBytesSentUniq = m_stats.traceBytesRecvUniq = 0;
//<
m_stats.traceSent = m_stats.traceRecv
= m_stats.traceSentUniq = m_stats.traceRecvUniq
= m_stats.traceSndLoss = m_stats.traceRcvLoss = m_stats.traceRetrans
Expand Down Expand Up @@ -8595,13 +8594,16 @@ void CUDT::processCtrl(const CPacket &ctrlpkt)
// inaccurate. Additionally it won't lock if TSBPD mode is off, and
// won't update anything. Note that if you set TSBPD mode and use
// srt_recvfile (which doesn't make any sense), you'll have a deadlock.
steady_clock::duration udrift(0);
steady_clock::time_point newtimebase;
const bool drift_updated = m_pRcvBuffer->addRcvTsbPdDriftSample(ctrlpkt.getMsgTimeStamp(), m_RecvLock,
(udrift), (newtimebase));
if (drift_updated && m_parent->m_IncludedGroup)
if (m_bDriftTracer)
{
m_parent->m_IncludedGroup->synchronizeDrift(this, udrift, newtimebase);
steady_clock::duration udrift(0);
steady_clock::time_point newtimebase;
const bool drift_updated = m_pRcvBuffer->addRcvTsbPdDriftSample(ctrlpkt.getMsgTimeStamp(), m_RecvLock,
(udrift), (newtimebase));
if (drift_updated && m_parent->m_IncludedGroup)
{
m_parent->m_IncludedGroup->synchronizeDrift(this, udrift, newtimebase);
}
}

// update last ACK that has been received by the sender
Expand Down Expand Up @@ -11638,6 +11640,7 @@ void CUDTGroup::deriveSettings(CUDT* u)
// SRTO_RENDEZVOUS: impossible to have it set on a listener socket.
// SRTO_SNDTIMEO/RCVTIMEO: groupwise setting
IM(SRTO_CONNTIMEO, m_tdConnTimeOut);
IM(SRTO_DRIFTTRACER, m_bDriftTracer);
// Reuseaddr: true by default and should only be true.
IM(SRTO_MAXBW, m_llMaxBW);
IM(SRTO_INPUTBW, m_llInputBW);
Expand Down Expand Up @@ -11805,6 +11808,7 @@ static bool getOptDefault(SRT_SOCKOPT optname, void* pw_optval, int& w_optlen)
case SRTO_PEERVERSION: RD(0);

case SRTO_CONNTIMEO: RD(-1);
case SRTO_DRIFTTRACER: RD(true);

case SRTO_MINVERSION: RD(0);
case SRTO_STREAMID: RD(std::string());
Expand Down
3 changes: 2 additions & 1 deletion srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ enum AckDataItem
};
const size_t ACKD_FIELD_SIZE = sizeof(int32_t);

static const size_t SRT_SOCKOPT_NPOST = 11;
static const size_t SRT_SOCKOPT_NPOST = 12;
extern const SRT_SOCKOPT srt_post_opt_list [];

enum GroupDataItem
Expand Down Expand Up @@ -1406,6 +1406,7 @@ class CUDT
bool m_bRendezvous; // Rendezvous connection mode

duration m_tdConnTimeOut; // connect timeout in milliseconds
bool m_bDriftTracer;
int m_iSndTimeOut; // sending timeout in milliseconds
int m_iRcvTimeOut; // receiving timeout in milliseconds
bool m_bReuseAddr; // reuse an exiting port or not, for UDP multiplexer
Expand Down
1 change: 1 addition & 0 deletions srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ typedef enum SRT_SOCKOPT {
SRTO_VERSION = 34, // Local SRT Version
SRTO_PEERVERSION, // Peer SRT Version (from SRT Handshake)
SRTO_CONNTIMEO = 36, // Connect timeout in msec. Caller default: 3000, rendezvous (x 10)
SRTO_DRIFTTRACER = 37, // Enable or disable drift tracer
// (some space left)
SRTO_SNDKMSTATE = 40, // (GET) the current state of the encryption at the peer side
SRTO_RCVKMSTATE, // (GET) the current state of the encryption at the agent side
Expand Down

0 comments on commit 4dcfa5d

Please sign in to comment.