Skip to content

Commit

Permalink
[core] Add improved logging for unexpected peer_ids
Browse files Browse the repository at this point in the history
If a peer sends a HandshakeMessage with a 'peer_id' that *does not*
match the 'peer_id' it sent to the tracker - log both the expected
and actual peer_ids.

Helps diagnose #614

It's probably a normal bittorrent client which is just randomising
the peer id on every connection attempt.
  • Loading branch information
alanmcgovern committed Feb 1, 2023
1 parent a8c7a6c commit 735f412
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MonoTorrent.Client/MonoTorrent.Client.Modes/Mode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected virtual void HandleHandshakeMessage (PeerId id, HandshakeMessage messa
// match we should close the connection. I *think* uTorrent doesn't randomise peerids
// for private torrents. It's not documented very well. We may need to relax this check
// if other clients randomize for private torrents.
logger.Info (id.Connection, "HandShake.Handle - Invalid peerid");
logger.InfoFormatted (id.Connection, "HandShake.Handle - Invalid peerid. Expected '{0}' but received '{1}'", id.Peer.Info.PeerId, message.PeerId);
throw new TorrentException ("Supplied PeerID didn't match the one the tracker gave us");
} else {
// We don't care about the mismatch for public torrents. uTorrent randomizes its PeerId, as do other clients.
Expand Down
6 changes: 6 additions & 0 deletions src/MonoTorrent.Client/MonoTorrent.Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ internal void InfoFormatted (IPeerConnection connection, string formatString, ob
Writer.Info ($"{connection.Uri}: {string.Format (formatString, p1)}");
}

internal void InfoFormatted (IPeerConnection connection, string formatString, object p1, object p2)
{
if (Writer != null)
Writer.Info ($"{connection.Uri}: {string.Format (formatString, p1, p2)}");
}

internal void Error (string message)
{
if (Writer != null)
Expand Down

0 comments on commit 735f412

Please sign in to comment.