Skip to content

Commit

Permalink
Cleanup logging and move some to LogDebug
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonrakena committed Dec 12, 2023
1 parent a007b28 commit 9dd4643
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/Promul/Channels/ReliableChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ private async ValueTask ProcessAckAsync(NetworkPacket packet)
{
if (packet.Data.Count != _outgoingAcks.Data.Count)
{
NetDebug.Write("[PA]Invalid acks packet size");
Peer.LogDebug("[PA]Invalid acks packet size");
return;
}

var ackWindowStart = packet.Sequence;
var windowRel = NetUtils.RelativeSequenceNumber(_localWindowStart, ackWindowStart);
if (ackWindowStart >= NetConstants.MaxSequence || windowRel < 0)
{
NetDebug.Write("[PA]Bad window start");
Peer.LogDebug("[PA]Bad window start");
return;
}

//check relevance
if (windowRel >= _windowSize)
{
NetDebug.Write("[PA]Old acks");
Peer.LogDebug("[PA]Old acks");
return;
}

Expand Down Expand Up @@ -352,7 +352,7 @@ public async Task TrySendAsync(long utcNowTicks, PeerBase peer)
var resendDelay = peer.ResendDelay * TimeSpan.TicksPerMillisecond;
double packetHoldTime = utcNowTicks - _timeStamp!.Value;
if (packetHoldTime < resendDelay) return;
NetDebug.Write($"[RC]Resend: {packetHoldTime} > {resendDelay}");
peer.LogDebug($"[RC] Resend: {packetHoldTime} > {resendDelay}");
}

_timeStamp = utcNowTicks;
Expand Down
2 changes: 1 addition & 1 deletion src/Promul/ConnectionRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private bool TryActivate()
}
catch
{
NetDebug.WriteError("[AC] Invalid incoming data");
NetDebug.Write($"{nameof(AcceptIfMatchesKeyAsync)} - {this.RemoteEndPoint} sent invalid incoming data, rejecting");
}

if (Result == ConnectionRequestResult.Accept)
Expand Down
1 change: 0 additions & 1 deletion src/Promul/Core/PromulManager.Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ private async Task<bool> ProcessError(SocketException ex)
case SocketError.MessageSize:
case SocketError.TimedOut:
case SocketError.NetworkReset:
//NetDebug.Write($"[R]Ignored error: {(int)ex.SocketErrorCode} - {ex}");
break;
default:
NetDebug.WriteError($"[R]Error code: {(int)ex.SocketErrorCode} - {ex}");
Expand Down
1 change: 0 additions & 1 deletion src/Promul/Core/PromulManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ private void ProcessNtpRequests(long elapsedMilliseconds)

await peer.ShutdownAsync(data, false);
AddPeer(peer);
NetDebug.Write(NetLogLevel.Trace, "[NM] Peer connect reject.");
}
else // Accept
{
Expand Down
5 changes: 2 additions & 3 deletions src/Promul/Peers/OutgoingPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ internal bool ProcessConnectionAccepted(NetConnectAcceptPacket packet)
//check connection id
if (packet.ConnectionTime != ConnectTime)
{
NetDebug.Write(NetLogLevel.Trace,
$"[NC] Invalid connectId: {packet.ConnectionTime} != our({ConnectTime})");
LogDebug($"[NC] Invalid connectId: {packet.ConnectionTime} != our({ConnectTime})");
return false;
}

Expand Down Expand Up @@ -74,7 +73,7 @@ internal override async Task<ConnectRequestResult> ProcessReconnectionRequestAsy
case ConnectionState.Connected:
// Old connect request
if (connRequest.ConnectionTime == ConnectTime)
NetDebug.Write($"Received connection request while in Connected state from {Id}");
LogDebug($"Received connection request while in Connected state");
//just reply accept
//await PromulManager.SendRaw(_connectAcceptPacket, EndPoint);
// New connect request
Expand Down
11 changes: 5 additions & 6 deletions src/Promul/Peers/PeerBase.Mtu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ private async Task ProcessMtuPacketAsync(NetworkPacket packet)
// Ignore MTU values below our configured minimum.
if (packet.Data.Count < NetConstants.PossibleMtu[0])
{
NetDebug.WriteError(
$"[MTU] Peer requested an MTU ({packet.Data.Count}) lower than minimum ({NetConstants.PossibleMtu[0]}.");
LogDebug($"[MTU] Peer requested an MTU ({packet.Data.Count}) lower than minimum ({NetConstants.PossibleMtu[0]}.");
return;
}
// Validate the following:
Expand All @@ -32,21 +31,21 @@ private async Task ProcessMtuPacketAsync(NetworkPacket packet)

if (frontCheck != packet.Data.Count)
{
NetDebug.WriteError("[MTU] MTU negotiation resulted in a broken packet. " +
LogDebug("[MTU] MTU negotiation resulted in a broken packet. " +
$"Peer requested {frontCheck} while packet was only {packet.Data.Count} bytes.");
return;
}

if (frontCheck != backCheck)
{
NetDebug.WriteError(
LogDebug(
$"[MTU] MTU negotiation resulted in a broken end MTU check. Received {backCheck}, expected to be same as packet size of {packet.Data.Count} bytes.");
return;
}

if (frontCheck > NetConstants.MaxPacketSize)
{
NetDebug.WriteError(
LogDebug(
$"[MTU] Peer requested an MTU ({frontCheck}) higher than permitted by policy ({NetConstants.MaxPacketSize}).");
return;
}
Expand Down Expand Up @@ -79,7 +78,7 @@ private async Task ProcessMtuPacketAsync(NetworkPacket packet)
if (_currentMtuIndex == NetConstants.PossibleMtu.Length - 1)
{
_mtuNegotiationComplete = true;
NetDebug.Write($"[MTU] Negotiation complete. MTU for this session: {MaximumTransferUnit}.");
LogDebug($"[MTU] Negotiation complete. MTU for this session: {MaximumTransferUnit}.");
}

break;
Expand Down
12 changes: 6 additions & 6 deletions src/Promul/Peers/PeerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ internal async Task<ShutdownResult> ShutdownAsync(ArraySegment<byte> data, bool
FastBitConverter.GetBytes(_shutdownPacket.Value.Data.Array, _shutdownPacket.Value.Data.Offset + 1, ConnectTime);
if (_shutdownPacket.Value.Data.Count >= MaximumTransferUnit)
//Drop additional data
NetDebug.WriteError("[Peer] Disconnect additional data size more than MTU - 8!");
LogDebug("Disconnect additional data size more than MTU - 8!");
else if (data != null && data.Count > 0)
data.CopyTo(_shutdownPacket.Value.Data.Array, _shutdownPacket.Value.Data.Offset + 9);
ConnectionState = ConnectionState.ShutdownRequested;
Expand Down Expand Up @@ -492,7 +492,7 @@ internal async ValueTask AddReliablePacket(DeliveryMethod method, NetworkPacket
fragments[p.FragmentPart] != null ||
p.ChannelId != incomingFragments.ChannelId)
{
NetDebug.WriteError(
LogDebug(
$"Fragmented packet {p.FragmentId} (channel {incomingFragments.ChannelId}): received invalid fragment part {p.FragmentId + 1} (channel {p.ChannelId})");
return;
}
Expand Down Expand Up @@ -526,15 +526,15 @@ internal async ValueTask AddReliablePacket(DeliveryMethod method, NetworkPacket
if (pos + writtenSize > resultingPacket.Data.Count)
{
_holdedFragments.Remove(packetFragId);
NetDebug.WriteError(
LogDebug(
$"Fragment error pos: {pos + writtenSize} >= resultPacketSize: {resultingPacket.Data.Count} , totalSize: {incomingFragments.TotalSize}");
return;
}

if (fragment.Value.Data.Count > fragment.Value.Data.Count)
{
_holdedFragments.Remove(packetFragId);
NetDebug.WriteError(
LogDebug(
$"Fragment error size: {fragment.Value.Data.Count} > fragment.RawData.Length: {fragment.Value.Data.Count}");
return;
}
Expand Down Expand Up @@ -581,7 +581,7 @@ internal async ValueTask ProcessPacket(NetworkPacket packet)

if (packet.ConnectionNumber != _connectNumber)
{
NetDebug.Write(NetLogLevel.Trace,
LogDebug(
$"Received a packet with invalid connection number ({packet.ConnectionNumber}), expected {_connectNumber}. Ignoring.");
return;
}
Expand Down Expand Up @@ -659,7 +659,7 @@ await PromulManager.CreateReceiveEvent(packet, DeliveryMethod.Unreliable, 0,
break;

default:
NetDebug.WriteError("Error! Unexpected packet type: " + packet.Property);
LogDebug("Error! Unexpected packet type: " + packet.Property);
break;
}
}
Expand Down

0 comments on commit 9dd4643

Please sign in to comment.