Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(logging): additional trace level diagnostic logs #3

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions LiteNetLib/ConnectionRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ public NetPeer AcceptIfKey(string key)
{
NetDebug.WriteError("[AC] Invalid incoming data");
}

if (Result == ConnectionRequestResult.Accept)
{
NetDebug.Write("[AC] Accepting incoming connection.");
return _listener.OnConnectionSolved(this, null, 0, 0);
}

NetDebug.Write($"[AC] Invalid key for: {RemoteEndPoint}.");
Result = ConnectionRequestResult.Reject;
_listener.OnConnectionSolved(this, null, 0, 0);
return null;
Expand Down
9 changes: 8 additions & 1 deletion LiteNetLib/NetManager.Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,10 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd
{
socket = _udpSocketv6;
if (socket == null)
{
NetDebug.Write($"[S] No Socket for: {remoteEndPoint}");
return 0;
}
}

int result;
Expand All @@ -554,21 +557,23 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd
result = socket.SendTo(message, start, length, SocketFlags.None, remoteEndPoint);
#endif
}
//NetDebug.WriteForce("[S]Send packet to {0}, result: {1}", remoteEndPoint, result);
NetDebug.Write($"[S]Send packet to {remoteEndPoint}, result: {result}");
}
catch (SocketException ex)
{
switch (ex.SocketErrorCode)
{
case SocketError.NoBufferSpaceAvailable:
case SocketError.Interrupted:
NetDebug.Write($"[S] Interrupted {ex}");
return 0;
case SocketError.MessageSize:
NetDebug.Write(NetLogLevel.Trace, $"[SRD] 10040, datalen: {length}");
return 0;

case SocketError.HostUnreachable:
case SocketError.NetworkUnreachable:
NetDebug.Write($"[S] Network/Host Unreachable {ex}");
if (DisconnectOnUnreachable && remoteEndPoint is NetPeer peer)
{
DisconnectPeerForce(
Expand All @@ -584,6 +589,7 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd
return -1;

case SocketError.Shutdown:
NetDebug.Write($"[S] Shutdown {ex}");
CreateEvent(NetEvent.EType.Error, remoteEndPoint: remoteEndPoint, errorCode: ex.SocketErrorCode);
return -1;

Expand All @@ -603,6 +609,7 @@ internal int SendRaw(byte[] message, int start, int length, IPEndPoint remoteEnd
PoolRecycle(expandedPacket);
}

// TODO: Why are we hiding failure?
if (result <= 0)
return 0;

Expand Down
1 change: 1 addition & 0 deletions LiteNetLib/NetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ internal NetPeer OnConnectionSolved(ConnectionRequest request, byte[] rejectData
if (TryGetPeer(request.RemoteEndPoint, out netPeer))
{
//already have peer
NetDebug.Write($"[NM] Duplicate peer for {request.RemoteEndPoint}, ignoring.");
}
else if (request.Result == ConnectionRequestResult.Reject)
{
Expand Down
Loading