1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 15:53:55 +00:00

1. Updated Helper method for console.log to implement info1 & info2

2. Added more logging to WebRTC
3. Fix edge case when piping RTC DataChannel could result in 100% CPU utilization
This commit is contained in:
Bryan Roe
2022-03-07 19:09:44 -08:00
parent c2bafce024
commit 6030154d94
4 changed files with 26 additions and 5 deletions

View File

@@ -1155,6 +1155,12 @@ void Duktape_Console_Log_ChainEx(duk_context *ctx, ILibDuktape_LogTypes logType,
case ILibDuktape_LogType_Warn:
duk_get_prop_string(ctx, -1, "warn"); // [g][console][warn]
break;
case ILibDuktape_LogType_Info1:
duk_get_prop_string(ctx, -1, "info1"); // [g][console][warn]
break;
case ILibDuktape_LogType_Info2:
duk_get_prop_string(ctx, -1, "info2"); // [g][console][warn]
break;
default:
duk_get_prop_string(ctx, -1, "log"); // [g][console][log]
break;

View File

@@ -632,13 +632,16 @@ duk_ret_t ILibDuktape_readableStream_pipe(duk_context *ctx)
int nargs = duk_get_top(ctx);
duk_push_this(ctx); // [readable]
char *ID = Duktape_GetStringPropertyValue(ctx, -1, ILibDuktape_OBJID, "UNKNOWN");
duk_get_prop_string(ctx, -1, ILibDuktape_readableStream_RSPTRS); // [readable][ptrs]
rstream = (ILibDuktape_readableStream*)Duktape_GetBuffer(ctx, -1, NULL);
duk_pop_2(ctx); // ...
ILibSpinLock_Lock(&(rstream->pipeLock));
if (rstream->pipeInProgress != 0)
if (rstream->pipeInProgress != 0 && rstream->pipeInProgress_counter < 10)
{
++rstream->pipeInProgress_counter;
// We must YIELD and try again later, becuase there is an active dispatch going on
rstream->pipeImmediate = ILibDuktape_Immediate(ctx, (void*[]) { rstream, duk_get_heapptr(ctx, 0), nargs > 1 ? duk_get_heapptr(ctx, 1) : NULL }, 1 + nargs, ILibDuktape_readableStream_pipe_later);
duk_push_heapptr(ctx, rstream->pipeImmediate); // [immediate]
@@ -655,6 +658,11 @@ duk_ret_t ILibDuktape_readableStream_pipe(duk_context *ctx)
}
else
{
char tmpbuf[512];
int len = sprintf_s(tmpbuf, sizeof(tmpbuf), "PIPE:%s [%d]", ID, rstream->pipeInProgress_counter);
if (len > 0) { Duktape_Console_Log(ctx, duk_ctx_chain(ctx), ILibDuktape_LogType_Info1, tmpbuf, len); }
rstream->pipeInProgress_counter = 0;
// No Active Dispatch, so while we hold this lock, we can setup/add the pipe
duk_push_heapptr(ctx, rstream->pipeArray); // [pipeArray]
duk_get_prop_string(ctx, -1, "push"); // [pipeArray][push]
@@ -704,6 +712,8 @@ duk_ret_t ILibDuktape_readableStream_pipe(duk_context *ctx)
duk_push_string(ctx, "pipe"); // [emit][this][pipe]
duk_push_this(ctx); // [emit][this][pipe][readable]
duk_call_method(ctx, 2); duk_pop(ctx); // ...
if (rstream->paused != 0)
{
rstream->paused = 0; // Set state now, so nobody tries to resume before we can finish piping

View File

@@ -54,6 +54,7 @@ typedef struct ILibDuktape_readableStream
#endif
int endRelayed;
int pipeInProgress;
int pipeInProgress_counter;
#ifdef WIN32
DWORD pipedThreadID;
#else

View File

@@ -3865,7 +3865,7 @@ void ILibStun_SctpResent(struct ILibStun_dTlsSession *obj)
#ifdef _WEBRTCDEBUG
if (obj->onT3RTX != NULL) { obj->onT3RTX(obj, "OnT3RTX", -1); } // Debug event informing of the T3RTX timer expiration
#endif
ILibRemoteLogging_printf(ILibChainGetLogger(obj->parent->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_3, "SCTP[%d]: T3TX Timer Expired", obj->sessionId);
obj->senderCredits = ILibRUDP_StartMTU; // Set CWND to 1 MTU
obj->SSTHRESH = MAX(obj->congestionWindowSize / 2, 4 * ILibRUDP_StartMTU); // Update Slow Start Threshold
obj->congestionWindowSize = ILibRUDP_StartMTU; // Reset the size of the Congestion Window, so that we'll initialy only have one SCTP packet in flight
@@ -3921,6 +3921,7 @@ void ILibStun_SctpResent(struct ILibStun_dTlsSession *obj)
if (obj->onT3RTX != NULL) { obj->onT3RTX(obj, "OnT3RTX", obj->RTO); } // Debug event informing of the T3RTX timer expiration
#endif
}
ILibRemoteLogging_printf(ILibChainGetLogger(obj->parent->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_3, "SCTP[%d]: RESEND", obj->sessionId);
ILibStun_SendSctpPacket(obj->parent, obj->sessionId, rpacket->Data - 12, rpacket->PacketSize);
#ifdef _WEBRTCDEBUG
//if (obj->onSendRetry != NULL) { obj->onSendRetry(obj, "OnSendRetry", ((unsigned short*)(rpacket->Data + sizeof(char*)))[0]); }
@@ -3937,6 +3938,7 @@ void ILibStun_SctpResent(struct ILibStun_dTlsSession *obj)
else
{
rpacket->PacketGAPCounter = 0xFF; // Mark for retransmit later (when CWND allows)
ILibRemoteLogging_printf(ILibChainGetLogger(obj->parent->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_3, "SCTP[%d]: MARK FOR RESEND", obj->sessionId);
}
}
rpacket = rpacket->NextPacket; // Move to the next packet
@@ -4632,6 +4634,8 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char*
ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "SCTP: %d received [INIT]", session);
ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "...TSN/IN = %u", o->intsn);
ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "...TSN/OUT = %u", o->outtsn);
ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_1, "...SenderCredits = %u", o->senderCredits);
// Optional/Variable Fields
{
int varLen = 0;
@@ -5031,7 +5035,7 @@ void ILibStun_ProcessSctpPacket(struct ILibStun_Module *obj, int session, char*
// Update the packet retry data
rpacket->LastSentTimeStamp = o->lastSackTime; // Last time the packet was sent (Used for retry)
ILibRemoteLogging_printf(ILibChainGetLogger(obj->ChainLink.ParentChain), ILibRemoteLogging_Modules_WebRTC_SCTP, ILibRemoteLogging_Flags_VerbosityLevel_2, "Sending %u/%u bytes from Holding Queue", (rpacket->PacketSize - (12 + 16)), o->holdingByteCount);
// Send the packet
ILibStun_SendSctpPacket(obj, session, rpacket->Data - 12, rpacket->PacketSize); // Send the packet