Skip to content

Commit

Permalink
Minor refactoring during the code studying
Browse files Browse the repository at this point in the history
  • Loading branch information
mbakholdina committed Apr 9, 2021
1 parent f1f2dd4 commit 7da9425
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
24 changes: 14 additions & 10 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,18 @@ void CUDT::construct()
m_pSndLossList = NULL;
m_pRcvLossList = NULL;
m_iReorderTolerance = 0;
m_iConsecEarlyDelivery = 0; // how many times so far the packet considered lost has been received before TTL expires
// How many times so far the packet considered lost has been received
// before TTL expires.
m_iConsecEarlyDelivery = 0;
m_iConsecOrderedDelivery = 0;

m_pSndQueue = NULL;
m_pRcvQueue = NULL;
m_pSNode = NULL;
m_pRNode = NULL;

m_iSndHsRetryCnt = SRT_MAX_HSRETRY + 1; // Will be reset to 0 for HSv5, this value is important for HSv4
// Will be reset to 0 for HSv5, this value is important for HSv4.
m_iSndHsRetryCnt = SRT_MAX_HSRETRY + 1;

// Initial status
m_bOpened = false;
Expand All @@ -239,12 +242,12 @@ void CUDT::construct()
m_bClosing = false;
m_bShutdown = false;
m_bBroken = false;
// XXX m_iBrokenCounter should be still set to some default!
// TODO: m_iBrokenCounter should be still set to some default.
m_bPeerHealth = true;
m_RejectReason = SRT_REJ_UNKNOWN;
m_tsLastReqTime = steady_clock::time_point();
m_SrtHsSide = HSD_DRAW;
m_uPeerSrtVersion = 0; // not defined until connected.
m_uPeerSrtVersion = 0; // Not defined until connected.
m_iTsbPdDelay_ms = 0;
m_iPeerTsbPdDelay_ms = 0;
m_bPeerTsbPd = false;
Expand All @@ -254,10 +257,10 @@ void CUDT::construct()
m_bGroupTsbPd = false;
m_bPeerTLPktDrop = false;

// Initilize mutex and condition variables
// Initilize mutex and condition variables.
initSynch();

// XXX: Unblock, when the callback is implemented
// TODO: Uncomment when the callback is implemented.
// m_cbPacketArrival.set(this, &CUDT::defaultPacketArrival);
}

Expand Down Expand Up @@ -5423,17 +5426,18 @@ void CUDT::acceptAndRespond(const sockaddr_any& agent, const sockaddr_any& peer,
// And of course, it is connected.
m_bConnected = true;

// register this socket for receiving data packets
// Register this socket for receiving data packets.
m_pRNode->m_bOnList = true;
m_pRcvQueue->setNewEntry(this);

// Save the handshake in m_ConnRes in case when needs repeating.
m_ConnRes = w_hs;

// send the response to the peer, see listen() for more discussions about this
// XXX Here create CONCLUSION RESPONSE with:
// Send the response to the peer, see listen() for more discussions
// about this.
// TODO: Here create CONCLUSION RESPONSE with:
// - just the UDT handshake, if HS_VERSION_UDT4,
// - if higher, the UDT handshake, the SRT HSRSP, the SRT KMRSP
// - if higher, the UDT handshake, the SRT HSRSP, the SRT KMRSP.
size_t size = m_iMaxSRTPayloadSize;
// Allocate the maximum possible memory for an SRT payload.
// This is a maximum you can send once.
Expand Down
49 changes: 25 additions & 24 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ inline T CountIIR(T base, T newval, double factor)
return base+T(diff*factor);
}

// XXX Probably a better rework for that can be done - this can be
// TODO: Probably a better rework for that can be done - this can be
// turned into a serializable structure, just like it's for CHandShake.
enum AckDataItem
{
Expand All @@ -97,22 +97,23 @@ enum AckDataItem
ACKD_BUFFERLEFT = 3,
ACKD_TOTAL_SIZE_SMALL = 4,

// Extra fields existing in UDT (not always sent)

ACKD_RCVSPEED = 4, // length would be 16
// Extra fields existing in UDT (not always sent).
ACKD_RCVSPEED = 4, // length = 16
ACKD_BANDWIDTH = 5,
ACKD_TOTAL_SIZE_UDTBASE = 6, // length = 24
// Extra stats for SRT

ACKD_TOTAL_SIZE_UDTBASE = 6, // length = 24

// Extra stats for SRT.
ACKD_RCVRATE = 6,
ACKD_TOTAL_SIZE_VER101 = 7, // length = 28
ACKD_XMRATE = 7, // XXX This is a weird compat stuff. Version 1.1.3 defines it as ACKD_BANDWIDTH*m_iMaxSRTPayloadSize when set. Never got.
// XXX NOTE: field number 7 may be used for something in future, need to confirm destruction of all !compat 1.0.2 version

ACKD_TOTAL_SIZE_VER102 = 8, // 32
// FEATURE BLOCKED. Probably not to be restored.
// ACKD_ACKBITMAP = 8,
ACKD_TOTAL_SIZE = ACKD_TOTAL_SIZE_VER102 // length = 32 (or more)
ACKD_TOTAL_SIZE_VER101 = 7, // length = 28
// XXX This is a weird compat stuff. Version 1.1.3 defines it as
// ACKD_BANDWIDTH*m_iMaxSRTPayloadSize when set. Never got.
// XXX NOTE: field number 7 may be used for something in future,
// need to confirm destruction of all !compat 1.0.2 version.
ACKD_XMRATE = 7,

ACKD_TOTAL_SIZE_VER102 = 8, // length = 32
// ACKD_ACKBITMAP = 8, // Feature blocked, probably not to be restored.
ACKD_TOTAL_SIZE = ACKD_TOTAL_SIZE_VER102 // length = 32 (or more)
};
const size_t ACKD_FIELD_SIZE = sizeof(int32_t);

Expand Down Expand Up @@ -267,14 +268,15 @@ class CUDT

// Parameters
//
// Note: use notation with X*1000*1000*... instead of million zeros in a row
static const int COMM_RESPONSE_MAX_EXP = 16;
static const int SRT_TLPKTDROP_MINTHRESHOLD_MS = 1000;
static const uint64_t COMM_KEEPALIVE_PERIOD_US = 1*1000*1000;
static const int32_t COMM_SYN_INTERVAL_US = 10*1000;
static const int COMM_CLOSE_BROKEN_LISTENER_TIMEOUT_MS = 3000;
static const uint16_t MAX_WEIGHT = 32767;
static const size_t ACK_WND_SIZE = 1024;
// NOTE: Use notation with X*1000*1000*... instead of
// million zeros in a row.
static const int COMM_RESPONSE_MAX_EXP = 16;
static const int SRT_TLPKTDROP_MINTHRESHOLD_MS = 1000;
static const uint64_t COMM_KEEPALIVE_PERIOD_US = 1*1000*1000;
static const int32_t COMM_SYN_INTERVAL_US = 10*1000;
static const int COMM_CLOSE_BROKEN_LISTENER_TIMEOUT_MS = 3000;
static const uint16_t MAX_WEIGHT = 32767;
static const size_t ACK_WND_SIZE = 1024;

int handshakeVersion()
{
Expand Down Expand Up @@ -745,7 +747,6 @@ class CUDT
int m_iDeliveryRate; // Packet arrival rate at the receiver side
int m_iByteDeliveryRate; // Byte arrival rate at the receiver side


CHandShake m_ConnReq; // Connection request
CHandShake m_ConnRes; // Connection response
CHandShake::RendezvousState m_RdvState; // HSv5 rendezvous state
Expand Down

0 comments on commit 7da9425

Please sign in to comment.