8000 Peers trying to connect to themselves · Issue #711 · alanmcgovern/monotorrent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Peers trying to connect to themselves #711
Open
@MarkPreschern

Description

@MarkPreschern

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 );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0