Skip to content

Commit

Permalink
[core] Refax: remove usage of LOGF/HLOGF (#2566).
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris committed Dec 2, 2022
1 parent 37d44f4 commit fc82eac
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 94 deletions.
4 changes: 2 additions & 2 deletions haicrypt/haicrypt_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ int HaiCrypt_SetLogLevel(int level, int logfa)
#define HAICRYPT_DEFINE_LOG_DISPATCHER(LOGLEVEL, dispatcher) \
int HaiCrypt_LogF_##LOGLEVEL ( const char* file, int line, const char* function, const char* format, ...) \
{ \
va_list ap; \
va_start(ap, format); \
srt_logging::LogDispatcher& lg = hclog.dispatcher; \
if (!lg.CheckEnabled()) return -1; \
va_list ap; \
va_start(ap, format); \
lg().setloc(file, line, function).vform(format, ap); \
va_end(ap); \
return 0; \
Expand Down
2 changes: 1 addition & 1 deletion haicrypt/haicrypt_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ HAICRYPT_DECLARE_LOG_DISPATCHER(LOG_EMERG);

#define HCRYPT_LOG_INIT()
#define HCRYPT_LOG_EXIT()
#define HCRYPT_LOG(lvl, fmt, ...) HaiCrypt_LogF_##lvl (__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
#define HCRYPT_LOG(lvl, ...) HaiCrypt_LogF_##lvl (__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)

#if ENABLE_HAICRYPT_LOGGING == 2
#define HCRYPT_DEV 1
Expand Down
12 changes: 7 additions & 5 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ int srt::CUDTUnited::newConnection(const SRTSOCKET listen,
}
catch (const CUDTException&)
{
LOGF(cnlog.Fatal, "newConnection: IPE: all sockets occupied? Last gen=%d", m_SocketIDGenerator);
LOGC(cnlog.Fatal, log << "newConnection: IPE: all sockets occupied? Last gen=" << m_SocketIDGenerator);
// generateSocketID throws exception, which can be naturally handled
// when the call is derived from the API call, but here it's called
// internally in response to receiving a handshake. It must be handled
Expand Down Expand Up @@ -600,7 +600,8 @@ int srt::CUDTUnited::newConnection(const SRTSOCKET listen,
// this call causes sending the SRT Handshake through this socket.
// Without this mapping the socket cannot be found and therefore
// the SRT Handshake message would fail.
HLOGF(cnlog.Debug, "newConnection: incoming %s, mapping socket %d", peer.str().c_str(), ns->m_SocketID);
HLOGC(cnlog.Debug, log <<
"newConnection: incoming " << peer.str() << ", mapping socket " << ns->m_SocketID);
{
ScopedLock cg(m_GlobControlLock);
m_Sockets[ns->m_SocketID] = ns;
Expand Down Expand Up @@ -647,7 +648,8 @@ int srt::CUDTUnited::newConnection(const SRTSOCKET listen,
ScopedLock glock(m_GlobControlLock);
try
{
HLOGF(cnlog.Debug, "newConnection: mapping peer %d to that socket (%d)\n", ns->m_PeerID, ns->m_SocketID);
HLOGC(cnlog.Debug, log << "newConnection: mapping peer " << ns->m_PeerID
<< " to that socket (" << ns->m_SocketID << ")");
m_PeerRec[ns->getPeerSpec()].insert(ns->m_SocketID);
}
catch (...)
Expand Down Expand Up @@ -2640,7 +2642,7 @@ void srt::CUDTUnited::checkBrokenSockets()

for (sockets_t::iterator j = m_ClosedSockets.begin(); j != m_ClosedSockets.end(); ++j)
{
// HLOGF(smlog.Debug, "checking CLOSED socket: %d\n", j->first);
// HLOGC(smlog.Debug, log << "checking CLOSED socket: " << j->first);
if (!is_zero(j->second->core().m_tsLingerExpiration))
{
// asynchronous close:
Expand All @@ -2667,7 +2669,7 @@ void srt::CUDTUnited::checkBrokenSockets()
log << "checkBrokenSockets: @" << j->second->m_SocketID << " closed "
<< FormatDuration(closed_ago) << " ago and removed from RcvQ - will remove");

// HLOGF(smlog.Debug, "will unref socket: %d\n", j->first);
// HLOGC(smlog.Debug, log << "will unref socket: " << j->first);
tbr.push_back(j->first);
}
}
Expand Down
138 changes: 53 additions & 85 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,14 +1175,14 @@ size_t srt::CUDT::fillSrtHandshake_HSRSP(uint32_t *aw_srtdata, size_t /* srtlen
{
// Request that the rexmit bit be used as a part of msgno.
aw_srtdata[SRT_HS_FLAGS] |= SRT_OPT_REXMITFLG;
HLOGF(cnlog.Debug, "HSRSP/snd: AGENT UNDERSTANDS REXMIT flag and PEER reported that it does, too.");
HLOGP(cnlog.Debug, "HSRSP/snd: AGENT UNDERSTANDS REXMIT flag and PEER reported that it does, too.");
}
}
else
{
// Since this is now in the code, it can occur only in case when you change the
// version specification in the build configuration.
HLOGF(cnlog.Debug, "HSRSP/snd: AGENT DOES NOT UNDERSTAND REXMIT flag");
HLOGP(cnlog.Debug, "HSRSP/snd: AGENT DOES NOT UNDERSTAND REXMIT flag");
}

HLOGC(cnlog.Debug,
Expand All @@ -1196,15 +1196,12 @@ size_t srt::CUDT::fillSrtHandshake_HSRSP(uint32_t *aw_srtdata, size_t /* srtlen
size_t srt::CUDT::prepareSrtHsMsg(int cmd, uint32_t *srtdata, size_t size)
{
size_t srtlen = fillSrtHandshake(srtdata, size, cmd, handshakeVersion());
HLOGF(cnlog.Debug,
"CMD:%s(%d) Len:%d Version: %s Flags: %08X (%s) sdelay:%d",
MessageTypeStr(UMSG_EXT, cmd).c_str(),
cmd,
(int)(srtlen * sizeof(int32_t)),
SrtVersionString(srtdata[SRT_HS_VERSION]).c_str(),
srtdata[SRT_HS_FLAGS],
SrtFlagString(srtdata[SRT_HS_FLAGS]).c_str(),
srtdata[SRT_HS_LATENCY]);
HLOGC(cnlog.Debug, log << "CMD:" << MessageTypeStr(UMSG_EXT, cmd) << "(" << cmd << ") Len:"
<< int(srtlen * sizeof(int32_t))
<< " Version: " << SrtVersionString(srtdata[SRT_HS_VERSION])
<< " Flags: " << srtdata[SRT_HS_FLAGS]
<< " (" << SrtFlagString(srtdata[SRT_HS_FLAGS]) << ") sdelay:"
<< srtdata[SRT_HS_LATENCY]);

return srtlen;
}
Expand Down Expand Up @@ -1248,7 +1245,7 @@ void srt::CUDT::sendSrtMsg(int cmd, uint32_t *srtdata_in, size_t srtlen_in)
break;

default:
LOGF(cnlog.Error, "sndSrtMsg: IPE: cmd=%d unsupported", cmd);
LOGC(cnlog.Error, log << "sndSrtMsg: IPE: cmd=" << cmd << " unsupported");
break;
}

Expand Down Expand Up @@ -2062,17 +2059,13 @@ int srt::CUDT::processSrtMsg_HSREQ(const uint32_t *srtdata, size_t bytelen, uint
{
m_RejectReason = SRT_REJ_ROGUE;
/* Packet smaller than minimum compatible packet size */
LOGF(cnlog.Error, "HSREQ/rcv: cmd=%d(HSREQ) len=%" PRIzu " invalid", SRT_CMD_HSREQ, bytelen);
LOGC(cnlog.Error, log << "HSREQ/rcv: cmd=" << SRT_CMD_HSREQ << "(HSREQ) len=" << bytelen << " invalid");
return SRT_CMD_NONE;
}

LOGF(cnlog.Note,
"HSREQ/rcv: cmd=%d(HSREQ) len=%" PRIzu " vers=0x%x opts=0x%x delay=%d",
SRT_CMD_HSREQ,
bytelen,
srtdata[SRT_HS_VERSION],
srtdata[SRT_HS_FLAGS],
SRT_HS_LATENCY_RCV::unwrap(srtdata[SRT_HS_LATENCY]));
LOGC(cnlog.Note, log << "HSREQ/rcv: cmd=" << SRT_CMD_HSREQ << "(HSREQ) len=" << bytelen
<< hex << " vers=0x" << srtdata[SRT_HS_VERSION] << " opts=0x" << srtdata[SRT_HS_FLAGS]
<< dec << " delay=" << SRT_HS_LATENCY_RCV::unwrap(srtdata[SRT_HS_LATENCY]));

m_uPeerSrtVersion = srtdata[SRT_HS_VERSION];
m_uPeerSrtFlags = srtdata[SRT_HS_FLAGS];
Expand Down Expand Up @@ -2117,7 +2110,7 @@ int srt::CUDT::processSrtMsg_HSREQ(const uint32_t *srtdata, size_t bytelen, uint
<< ") Min req version:" << SrtVersionString(m_config.uMinimumPeerSrtVersion));

m_bPeerRexmitFlag = IsSet(m_uPeerSrtFlags, SRT_OPT_REXMITFLG);
HLOGF(cnlog.Debug, "HSREQ/rcv: peer %s REXMIT flag", m_bPeerRexmitFlag ? "UNDERSTANDS" : "DOES NOT UNDERSTAND");
HLOGC(cnlog.Debug, log << CONID() << "HSREQ/rcv: peer " << (m_bPeerRexmitFlag ? "UNDERSTANDS" : "DOES NOT UNDERSTAND") << " REXMIT flag");

// Check if both use the same API type. Reject if not.
bool peer_message_api = !IsSet(m_uPeerSrtFlags, SRT_OPT_STREAM);
Expand Down Expand Up @@ -2271,7 +2264,7 @@ int srt::CUDT::processSrtMsg_HSRSP(const uint32_t *srtdata, size_t bytelen, uint
if (bytelen < SRT_CMD_HSRSP_MINSZ)
{
/* Packet smaller than minimum compatible packet size */
LOGF(cnlog.Error, "HSRSP/rcv: cmd=%d(HSRSP) len=%" PRIzu " invalid", SRT_CMD_HSRSP, bytelen);
LOGC(cnlog.Error, log << CONID() << "HSRSP/rcv: cmd=" << SRT_CMD_HSRSP << "(HSRSP) len=" << bytelen << " invalid");
return SRT_CMD_NONE;
}

Expand Down Expand Up @@ -2305,12 +2298,9 @@ int srt::CUDT::processSrtMsg_HSRSP(const uint32_t *srtdata, size_t bytelen, uint
m_uPeerSrtVersion = srtdata[SRT_HS_VERSION];
m_uPeerSrtFlags = srtdata[SRT_HS_FLAGS];

HLOGF(cnlog.Debug,
"HSRSP/rcv: Version: %s Flags: SND:%08X (%s)",
SrtVersionString(m_uPeerSrtVersion).c_str(),
m_uPeerSrtFlags,
SrtFlagString(m_uPeerSrtFlags).c_str());

HLOGC(cnlog.Debug, log << "HSRSP/rcv: Version: " << SrtVersionString(m_uPeerSrtVersion)
<< " Flags: SND:" << setw(8) << setfill('0') << hex << m_uPeerSrtFlags
<< setw(0) << " (" << SrtFlagString(m_uPeerSrtFlags) << ")");
// Basic version check
if (m_uPeerSrtVersion < m_config.uMinimumPeerSrtVersion)
{
Expand Down Expand Up @@ -2400,7 +2390,7 @@ int srt::CUDT::processSrtMsg_HSRSP(const uint32_t *srtdata, size_t bytelen, uint
}
else
{
HLOGF(cnlog.Debug, "HSRSP/rcv: <1.2.0 Agent DOESN'T understand REXMIT flag");
HLOGP(cnlog.Debug, "HSRSP/rcv: <1.2.0 Agent DOESN'T understand REXMIT flag");
}

handshakeDone();
Expand Down Expand Up @@ -3369,11 +3359,10 @@ void srt::CUDT::synchronizeWithGroup(CUDTGroup* gp)
m_pRcvBuffer->setPeerRexmitFlag(m_bPeerRexmitFlag);
leaveCS(m_RecvLock);

HLOGF(gmlog.Debug, "AFTER HS: Set Rcv TsbPd mode: delay=%u.%03us GROUP TIME BASE: %s%s",
m_iTsbPdDelay_ms/1000,
m_iTsbPdDelay_ms%1000,
FormatTime(rcv_buffer_time_base).c_str(),
rcv_buffer_wrap_period ? " (WRAP PERIOD)" : " (NOT WRAP PERIOD)");
HLOGC(gmlog.Debug, log << "AFTER HS: Set Rcv TsbPd mode: delay="
<< (m_iTsbPdDelay_ms/1000) << "." << (m_iTsbPdDelay_ms%1000)
<< "s GROUP TIME BASE: " << FormatTime(rcv_buffer_time_base)
<< " (" << (rcv_buffer_wrap_period ? "" : "NOT") << " WRAP PERIOD)");
}
else
{
Expand Down Expand Up @@ -8495,11 +8484,9 @@ void srt::CUDT::processCtrlLossReport(const CPacket& ctrlpkt)
// <lo, hi> specification means that the consecutive cell has been already interpreted.
++i;

HLOGF(inlog.Debug,
"%sreceived UMSG_LOSSREPORT: %d-%d (%d packets)...", CONID().c_str(),
losslist_lo,
losslist_hi,
CSeqNo::seqoff(losslist_lo, losslist_hi) + 1);
HLOGC(inlog.Debug, log << CONID() << "received UMSG_LOSSREPORT: "
<< losslist_lo << "-" << losslist_hi
<< " (" << (CSeqNo::seqoff(losslist_lo, losslist_hi) + 1) << " packets)...");

if ((CSeqNo::seqcmp(losslist_lo, losslist_hi) > 0) ||
(CSeqNo::seqcmp(losslist_hi, m_iSndCurrSeqNo) > 0))
Expand Down Expand Up @@ -8910,12 +8897,10 @@ void srt::CUDT::updateSrtRcvSettings()
{
m_pRcvBuffer->setTsbPdMode(m_tsRcvPeerStartTime, false, milliseconds_from(m_iTsbPdDelay_ms));

HLOGF(cnlog.Debug,
"AFTER HS: Set Rcv TsbPd mode%s: delay=%u.%03us RCV START: %s",
(m_bGroupTsbPd ? " (AS GROUP MEMBER)" : ""),
m_iTsbPdDelay_ms / 1000,
m_iTsbPdDelay_ms % 1000,
FormatTime(m_tsRcvPeerStartTime).c_str());
HLOGC(cnlog.Debug, log << "AFTER HS: Set Rcv TsbPd mode"
<< (m_bGroupTsbPd ? " (AS GROUP MEMBER)" : "")
<< ": delay=" << (m_iTsbPdDelay_ms / 1000) << "." << (m_iTsbPdDelay_ms % 1000)
<< "s RCV START: " << FormatTime(m_tsRcvPeerStartTime).c_str());
}
else
{
Expand All @@ -8934,11 +8919,10 @@ void srt::CUDT::updateSrtSndSettings()
* For sender to apply Too-Late Packet Drop
* option (m_bTLPktDrop) must be enabled and receiving peer shall support it
*/
HLOGF(cnlog.Debug,
"AFTER HS: Set Snd TsbPd mode %s TLPktDrop: delay=%d.%03ds START TIME: %s",
m_bPeerTLPktDrop ? "with" : "without",
m_iPeerTsbPdDelay_ms/1000, m_iPeerTsbPdDelay_ms%1000,
FormatTime(m_stats.tsStartTime).c_str());
HLOGC(cnlog.Debug, log << "AFTER HS: Set Snd TsbPd mode "
<< (m_bPeerTLPktDrop ? "with" : "without")
<< " TLPktDrop: delay=" << (m_iPeerTsbPdDelay_ms/1000) << "." << (m_iPeerTsbPdDelay_ms%1000)
<< "s START TIME: " << FormatTime(m_stats.tsStartTime).c_str());
}
else
{
Expand Down Expand Up @@ -9587,17 +9571,14 @@ void srt::CUDT::sendLossReport(const std::vector<std::pair<int32_t, int32_t> > &
if (i->first == i->second)
{
seqbuffer.push_back(i->first);
HLOGF(qrlog.Debug, "lost packet %d: sending LOSSREPORT", i->first);
HLOGC(qrlog.Debug, log << "lost packet " << i->first << ": sending LOSSREPORT");
}
else
{
seqbuffer.push_back(i->first | LOSSDATA_SEQNO_RANGE_FIRST);
seqbuffer.push_back(i->second);
HLOGF(qrlog.Debug,
"lost packets %d-%d (%d packets): sending LOSSREPORT",
i->first,
i->second,
1 + CSeqNo::seqcmp(i->second, i->first));
HLOGC(qrlog.Debug, log << "lost packets " << i->first << "-" << i->second
<< " (" << (1 + CSeqNo::seqcmp(i->second, i->first)) << " packets): sending LOSSREPORT");
}
}

Expand Down Expand Up @@ -10268,11 +10249,8 @@ int srt::CUDT::processData(CUnit* in_unit)
// into two records.
for (; i != m_FreshLoss.end() && i->ttl <= 0; ++i)
{
HLOGF(qrlog.Debug,
"Packet seq %d-%d (%d packets) considered lost - sending LOSSREPORT",
i->seq[0],
i->seq[1],
CSeqNo::seqoff(i->seq[0], i->seq[1]) + 1);
HLOGC(qrlog.Debug, log << "Packet seq " << i->seq[0] << "-" << i->seq[1]
<< " (" << (CSeqNo::seqoff(i->seq[0], i->seq[1]) + 1) << " packets) considered lost - sending LOSSREPORT");
addLossRecord(lossdata, i->seq[0], i->seq[1]);
}

Expand All @@ -10289,13 +10267,9 @@ int srt::CUDT::processData(CUnit* in_unit)
}
else
{
HLOGF(qrlog.Debug,
"STILL %" PRIzu " FRESH LOSS RECORDS, FIRST: %d-%d (%d) TTL: %d",
m_FreshLoss.size(),
i->seq[0],
i->seq[1],
1 + CSeqNo::seqoff(i->seq[0], i->seq[1]),
i->ttl);
HLOGC(qrlog.Debug, log << "STILL " << m_FreshLoss.size() << " FRESH LOSS RECORDS, FIRST: "
<< i->seq[0] << "-" << i->seq[1]
<< " (" << (1 + CSeqNo::seqoff(i->seq[0], i->seq[1])) << ") TTL: " << i->ttl);
}

// Phase 2: rest of the records should have TTL decreased.
Expand Down Expand Up @@ -10324,9 +10298,8 @@ int srt::CUDT::processData(CUnit* in_unit)
enterCS(m_StatsLock);
m_stats.traceReorderDistance--;
leaveCS(m_StatsLock);
HLOGF(qrlog.Debug,
"ORDERED DELIVERY of 50 packets in a row - decreasing tolerance to %d",
m_iReorderTolerance);
HLOGC(qrlog.Debug, log << "ORDERED DELIVERY of 50 packets in a row - decreasing tolerance to "
<< m_iReorderTolerance);
}
}
}
Expand Down Expand Up @@ -10423,7 +10396,7 @@ void srt::CUDT::unlose(const CPacket &packet)
was_reordered = !packet.getRexmitFlag();
if (was_reordered)
{
HLOGF(qrlog.Debug, "received out-of-band packet seq %d", sequence);
HLOGC(qrlog.Debug, log << "received out-of-band packet %" << sequence);

const int seqdiff = abs(CSeqNo::seqcmp(m_iRcvCurrSeqNo, packet.m_iSeqNo));
enterCS(m_StatsLock);
Expand All @@ -10432,11 +10405,8 @@ void srt::CUDT::unlose(const CPacket &packet)
if (seqdiff > m_iReorderTolerance)
{
const int new_tolerance = min(seqdiff, m_config.iMaxReorderTolerance);
HLOGF(qrlog.Debug,
"Belated by %d seqs - Reorder tolerance %s %d",
seqdiff,
(new_tolerance == m_iReorderTolerance) ? "REMAINS with" : "increased to",
new_tolerance);
HLOGC(qrlog.Debug, log << "Belated by " << seqdiff << " seqs - Reorder tolerance "
<< (new_tolerance == m_iReorderTolerance ? "REMAINS with " : "increased to ") << new_tolerance);
m_iReorderTolerance = new_tolerance;
has_increased_tolerance =
true; // Yes, even if reorder tolerance is already at maximum - this prevents decreasing tolerance.
Expand All @@ -10449,7 +10419,7 @@ void srt::CUDT::unlose(const CPacket &packet)
}
else
{
HLOGF(qrlog.Debug, "received reXmitted or belated packet seq %d (distinction not supported by peer)", sequence);
HLOGC(qrlog.Debug, log << "received reXmitted or belated packet seq " << sequence << " (distinction not supported by peer)");
}

// Don't do anything if "belated loss report" feature is not used.
Expand Down Expand Up @@ -10511,7 +10481,7 @@ breakbreak:;

if (i != m_FreshLoss.size())
{
HLOGF(qrlog.Debug, "sequence %d removed from belated lossreport record", sequence);
HLOGC(qrlog.Debug, log << "sequence " << sequence << " removed from belated lossreport record");
}

if (was_reordered)
Expand All @@ -10524,7 +10494,7 @@ breakbreak:;
else if (had_ttl > 2)
{
++m_iConsecEarlyDelivery; // otherwise, and if it arrived quite earlier, increase counter
HLOGF(qrlog.Debug, "... arrived at TTL %d case %d", had_ttl, m_iConsecEarlyDelivery);
HLOGC(qrlog.Debug, log << "... arrived at TTL " << had_ttl << " case " << m_iConsecEarlyDelivery);

// After 10 consecutive
if (m_iConsecEarlyDelivery >= 10)
Expand All @@ -10536,10 +10506,8 @@ breakbreak:;
enterCS(m_StatsLock);
m_stats.traceReorderDistance--;
leaveCS(m_StatsLock);
HLOGF(qrlog.Debug,
"... reached %d times - decreasing tolerance to %d",
m_iConsecEarlyDelivery,
m_iReorderTolerance);
HLOGC(qrlog.Debug, log << "... reached " << m_iConsecEarlyDelivery
<< " times - decreasing tolerance to " << m_iReorderTolerance);
}
}
}
Expand Down Expand Up @@ -10913,7 +10881,7 @@ int srt::CUDT::processConnectRequest(const sockaddr_any& addr, CPacket& packet)
if (result == -1)
{
hs.m_iReqType = URQFailure(error);
LOGF(cnlog.Warn, "processConnectRequest: rsp(REJECT): %d - %s", hs.m_iReqType, srt_rejectreason_str(error));
LOGC(cnlog.Warn, log << "processConnectRequest: rsp(REJECT): " << hs.m_iReqType << " - " << srt_rejectreason_str(error));
}

// The `acpu` not NULL means connection exists, the `result` should be 0. It is not checked here though.
Expand Down
Loading

0 comments on commit fc82eac

Please sign in to comment.