Skip to content

Commit

Permalink
[core] Placed CHandshake inside the srt namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed May 2, 2022
1 parent 9ba7e64 commit 3fbb917
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 46 deletions.
35 changes: 0 additions & 35 deletions srtcore/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,38 +856,3 @@ srt::CCryptoControl::~CCryptoControl()
}
#endif
}


std::string SrtFlagString(int32_t flags)
{
#define LEN(arr) (sizeof (arr)/(sizeof ((arr)[0])))

std::string output;
static std::string namera[] = { "TSBPD-snd", "TSBPD-rcv", "haicrypt", "TLPktDrop", "NAKReport", "ReXmitFlag", "StreamAPI" };

size_t i = 0;
for ( ; i < LEN(namera); ++i )
{
if ( (flags & 1) == 1 )
{
output += "+" + namera[i] + " ";
}
else
{
output += "-" + namera[i] + " ";
}

flags >>= 1;
//if ( flags == 0 )
// break;
}

#undef LEN

if ( flags != 0 )
{
output += "+unknown";
}

return output;
}
55 changes: 45 additions & 10 deletions srtcore/handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ using namespace std;
using namespace srt;


CHandShake::CHandShake()
srt::CHandShake::CHandShake()
: m_iVersion(0)
, m_iType(0) // Universal: UDT_UNDEFINED or no flags
, m_iISN(0)
Expand All @@ -76,7 +76,7 @@ CHandShake::CHandShake()
m_piPeerIP[i] = 0;
}

int CHandShake::store_to(char* buf, size_t& w_size)
int srt::CHandShake::store_to(char* buf, size_t& w_size)
{
if (w_size < m_iContentSize)
return -1;
Expand All @@ -98,7 +98,7 @@ int CHandShake::store_to(char* buf, size_t& w_size)
return 0;
}

int CHandShake::load_from(const char* buf, size_t size)
int srt::CHandShake::load_from(const char* buf, size_t size)
{
if (size < m_iContentSize)
return -1;
Expand All @@ -121,6 +121,8 @@ int CHandShake::load_from(const char* buf, size_t size)

#ifdef ENABLE_LOGGING

namespace srt
{
const char* srt_rejectreason_name [] = {
"UNKNOWN",
"SYSTEM",
Expand All @@ -138,8 +140,9 @@ const char* srt_rejectreason_name [] = {
"CONGESTION",
"FILTER",
};
}

std::string RequestTypeStr(UDTRequestType rq)
std::string srt::RequestTypeStr(UDTRequestType rq)
{
if (rq >= URQ_FAILURE_TYPES)
{
Expand Down Expand Up @@ -172,7 +175,7 @@ std::string RequestTypeStr(UDTRequestType rq)
}
}

string CHandShake::RdvStateStr(CHandShake::RendezvousState s)
string srt::CHandShake::RdvStateStr(CHandShake::RendezvousState s)
{
switch (s)
{
Expand All @@ -188,7 +191,7 @@ string CHandShake::RdvStateStr(CHandShake::RendezvousState s)
}
#endif

bool CHandShake::valid()
bool srt::CHandShake::valid()
{
if (m_iVersion < CUDT::HS_VERSION_UDT4
|| m_iISN < 0 || m_iISN >= CSeqNo::m_iMaxSeqNo
Expand All @@ -199,7 +202,7 @@ bool CHandShake::valid()
return true;
}

string CHandShake::show()
string srt::CHandShake::show()
{
ostringstream so;

Expand Down Expand Up @@ -231,7 +234,7 @@ string CHandShake::show()
return so.str();
}

string CHandShake::ExtensionFlagStr(int32_t fl)
string srt::CHandShake::ExtensionFlagStr(int32_t fl)
{
std::ostringstream out;
if ( fl & HS_EXT_HSREQ )
Expand All @@ -258,7 +261,7 @@ string CHandShake::ExtensionFlagStr(int32_t fl)
// XXX This code isn't currently used. Left here because it can
// be used in future, should any refactoring for the "manual word placement"
// code be done.
bool SrtHSRequest::serialize(char* buf, size_t size) const
bool srt::SrtHSRequest::serialize(char* buf, size_t size) const
{
if (size < SRT_HS_SIZE)
return false;
Expand All @@ -273,7 +276,7 @@ bool SrtHSRequest::serialize(char* buf, size_t size) const
}


bool SrtHSRequest::deserialize(const char* buf, size_t size)
bool srt::SrtHSRequest::deserialize(const char* buf, size_t size)
{
m_iSrtVersion = 0; // just to let users recognize if it succeeded or not.

Expand All @@ -288,3 +291,35 @@ bool SrtHSRequest::deserialize(const char* buf, size_t size)
m_iSrtReserved = (*p++);
return true;
}

std::string srt::SrtFlagString(int32_t flags)
{
#define LEN(arr) (sizeof (arr)/(sizeof ((arr)[0])))

std::string output;
static std::string namera[] = { "TSBPD-snd", "TSBPD-rcv", "haicrypt", "TLPktDrop", "NAKReport", "ReXmitFlag", "StreamAPI" };

size_t i = 0;
for (; i < LEN(namera); ++i)
{
if ((flags & 1) == 1)
{
output += "+" + namera[i] + " ";
}
else
{
output += "-" + namera[i] + " ";
}

flags >>= 1;
}

#undef LEN

if (flags != 0)
{
output += "+unknown";
}

return output;
}
5 changes: 4 additions & 1 deletion srtcore/handshake.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "crypto.h"
#include "utilities.h"

namespace srt
{

typedef Bits<31, 16> HS_CMDSPEC_CMD;
typedef Bits<15, 0> HS_CMDSPEC_SIZE;

Expand Down Expand Up @@ -128,7 +131,6 @@ void SrtExtractHandshakeExtensions(const char* bufbegin, size_t size,
std::vector<SrtHandshakeExtension>& w_output);



struct SrtHSRequest: public SrtHandshakeExtension
{
typedef Bits<31, 16> SRT_HSTYPE_ENCFLAGS;
Expand Down Expand Up @@ -359,5 +361,6 @@ class CHandShake

};

} // namespace srt

#endif

0 comments on commit 3fbb917

Please sign in to comment.