Skip to content

Commit

Permalink
[core] Add extra logging around incoming/outgoing connections
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmcgovern committed Feb 1, 2023
1 parent 2a2243c commit 0c919b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ internal async void ProcessNewOutgoingConnection (TorrentManager manager, PeerId
try {
// Create a handshake message to send to the peer
var handshake = new HandshakeMessage (id.ExpectedInfoHash.Truncate (), LocalPeerId, Constants.ProtocolStringV100);
logger.InfoFormatted (id.Connection, "[outgoing] Sending handshake message with peer id '{0}'", LocalPeerId);

var preferredEncryption = EncryptionTypes.GetPreferredEncryption (id.Peer.AllowedEncryption, Settings.AllowedEncryption);
if (preferredEncryption.Count == 0)
throw new NotSupportedException ("The peer and the engine do not agree on any encryption methods");
Expand Down Expand Up @@ -226,6 +228,7 @@ internal async void ProcessNewOutgoingConnection (TorrentManager manager, PeerId
try {
// Receive their handshake
HandshakeMessage handshake = await PeerIO.ReceiveHandshakeAsync (id.Connection, id.Decryptor);
logger.InfoFormatted (id.Connection, "[outgoing] Received handshake message with peer id '{0}'", handshake.PeerId);
manager.Mode.HandleMessage (id, handshake, default);
} catch {
// If we choose plaintext and it resulted in the connection being closed, remove it from the list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ async ReusableTask<bool> HandleHandshake (PeerInfo peerInfo, IPeerConnection con

var peer = new Peer (peerInfo, man.InfoHashes.Expand (message.InfoHash));
peer.UpdatePeerId (message.PeerId);

logger.InfoFormatted (connection, "[incoming] Received handshake with peer_id '{0}'", message.PeerId);

var id = new PeerId (peer, connection, new BitField (man.Bitfield.Length).SetAll (false)) {
Decryptor = decryptor,
Encryptor = encryptor
Expand Down

0 comments on commit 0c919b2

Please sign in to comment.