client.go | 1 + peer-impl.go | 3 +++ peerconn.go | 4 ++++ torrent.go | 3 +-- webseed-peer.go | 7 +++++-- diff --git a/client.go b/client.go index 86c83e20e91b3412d9a95469b083a4a4b4ba223c..0d158395f96310bfe0ae06e98a93aeefec85c2de 100644 --- a/client.go +++ b/client.go @@ -1493,6 +1493,7 @@ for _, t := range cl.torrents { t.iterPeers(func(p *Peer) { if p.remoteIp().Equal(ip) { t.logger.Levelf(log.Warning, "dropping peer %v with banned ip %v", p, ip) + // Should this be a close? p.drop() } }) diff --git a/peer-impl.go b/peer-impl.go index e29fb43967cb255086dc3fa73dead6b077749df4..1b9cf978205506a598fbfbad1812a31cf5cafb40 100644 --- a/peer-impl.go +++ b/peer-impl.go @@ -20,7 +20,10 @@ _request(Request) bool connectionFlags() string onClose() onGotInfo(*metainfo.Info) + // Drop connection. This may be a no-op if there is no connection. drop() + // Rebuke the peer + ban() String() string connStatusString() string diff --git a/peerconn.go b/peerconn.go index bc16ae6c63cabad8a18680e5ac9da3cb280c4574..6615d79c5a4573bab13a3561b5be4d95463fe170 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1590,6 +1590,10 @@ func (cn *PeerConn) drop() { cn.t.dropConnection(cn) } +func (cn *PeerConn) ban() { + cn.t.cl.banPeerIP(cn.remoteIp()) +} + func (cn *Peer) netGoodPiecesDirtied() int64 { return cn._stats.PiecesDirtiedGood.Int64() - cn._stats.PiecesDirtiedBad.Int64() } diff --git a/torrent.go b/torrent.go index e148d38bd98de87ccdccf2ad53e57b79bf780c63..1c197f9b66bbf351ac1c010ad24a71e294195316 100644 --- a/torrent.go +++ b/torrent.go @@ -2020,8 +2020,7 @@ } if len(bannableTouchers) >= 1 { c := bannableTouchers[0] - t.cl.banPeerIP(c.remoteIp()) - c.drop() + c.ban() } } t.onIncompletePiece(piece) diff --git a/webseed-peer.go b/webseed-peer.go index 9b1cba2233ec82f05d09a94b4a5177d3d592b138..0cdf4cacd4950300d27b2c4625fc92d10229f712 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -114,9 +114,12 @@ func (ws *webseedPeer) connectionFlags() string { return "WS" } -// TODO: This is called when banning peers. Perhaps we want to be able to ban webseeds too. We could -// return bool if this is even possible, and if it isn't, skip to the next drop candidate. +// Maybe this should drop all existing connections, or something like that. func (ws *webseedPeer) drop() {} + +func (cn *webseedPeer) ban() { + cn.peer.close() +} func (ws *webseedPeer) handleUpdateRequests() { // Because this is synchronous, webseed peers seem to get first dibs on newly prioritized