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

Peers trying to connect to themselves #711

Open
MarkPreschern opened this issue Jan 3, 2025 · 0 comments
Open

Peers trying to connect to themselves #711

MarkPreschern opened this issue Jan 3, 2025 · 0 comments

Comments

@MarkPreschern
Copy link

MarkPreschern commented Jan 3, 2025

I'm setting up a local test based on StressTest.cs. I subscribed to event handlers, and noticed that each peer was trying and failing to connect to themself. Example output -

Connection failed: ipv4://127.0.0.1:37001/, HandshakeFailed
Peer Disconnected: ipv4://127.0.0.1:37001/
Connection failed: ipv4://127.0.0.1:37001/, EncryptionNegiotiationFailed
Peer Disconnected: ipv4://127.0.0.1:37001/

After some debugging, I realized that AnnounceResponse's peers PeerInfo.PeerId is empty. When created on the Tracker at SimpleTorrentManager.GetPeers, with compact=1 the PeerId isn't included. In TorrentManager.AddPeer, this check then doesn't get hit -

if (Engine!.PeerId.Equals (peer.Info.PeerId))
    return false;

Which results in the torrent manager adding itself as a peer.

I think a proper fix would be to include the PeerId in the compact byte[].

For a workaround I extended HttpTrackerListener, turning off "compact"

private class NonCompactHttpTrackerListener : HttpTrackerListener
{
    public NonCompactHttpTrackerListener( string httpPrefix ) : base( httpPrefix )
    {
    }

    public override BEncodedDictionary Handle( NameValueCollection collection, IPAddress remoteAddress, bool isScrape )
    {
        collection[ "compact" ] = "0"; // don't compact the peers, it results in missing data which causes peers to try to connect to themself (and fail)
        return base.Handle( collection, remoteAddress, isScrape );
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant