client.go | 14 ++++++++++++++ connection.go | 5 ++++- dht/dht.go | 4 ++++ diff --git a/client.go b/client.go index 13b67cfae2dedd3a7a169f63b58ef1dedb953817..f5a52449b3d0ac5760c0d94bc6d605d911ca4439 100644 --- a/client.go +++ b/client.go @@ -2527,6 +2527,10 @@ return } tr.Stop("write chunk") }() + if c.peerTouchedPieces == nil { + c.peerTouchedPieces = make(map[int]struct{}) + } + c.peerTouchedPieces[int(req.Index)] = struct{}{} // log.Println("got chunk", req) piece.Event.Broadcast() @@ -2562,6 +2566,16 @@ pieceHashedCorrect.Add(1) } else { log.Printf("%s: piece %d failed hash", t, piece) pieceHashedNotCorrect.Add(1) + var touched []*connection + for _, c := range t.Conns { + if _, ok := c.peerTouchedPieces[int(piece)]; ok { + touched = append(touched, c) + } + } + log.Printf("dropping %d conns that touched piece", len(touched)) + for _, c := range touched { + me.dropConnection(t, c) + } } } p.EverHashed = true diff --git a/connection.go b/connection.go index ba0d124a8f85077dc1b1b1262c94450c6c49a735..85df7eb47039228c6144fd0043c2859d8578c26f 100644 --- a/connection.go +++ b/connection.go @@ -74,6 +74,8 @@ // Whether the peer has the given piece. nil if they've not sent any // related messages yet. PeerPieces []bool peerHasAll bool + // Pieces we've accepted chunks for from the peer. + peerTouchedPieces map[int]struct{} PeerMaxRequests int // Maximum pending requests the peer allows. PeerExtensionIDs map[string]byte @@ -257,8 +259,9 @@ eventAgeString(cn.lastMessageReceived), eventAgeString(cn.completedHandshake), eventAgeString(cn.lastUsefulChunkReceived)) fmt.Fprintf(w, - " %s completed, good chunks: %d/%d-%d reqq: %d-%d, flags: %s\n", + " %s completed, %d pieces touched, good chunks: %d/%d-%d reqq: %d-%d, flags: %s\n", cn.completedString(t), + len(cn.peerTouchedPieces), cn.UsefulChunksReceived, cn.UnwantedChunksReceived+cn.UsefulChunksReceived, cn.chunksSent, diff --git a/dht/dht.go b/dht/dht.go index e269350f24ad662fe43a868c601aeb68a0bbdd00..599522f80a44f8f47a483b5c2a1198703a66c080 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -587,6 +587,10 @@ defer s.mu.Unlock() s.ipBlockList = list } +func (s *Server) IPBlocklist() *iplist.IPList { + return s.ipBlockList +} + func (s *Server) init() (err error) { err = s.setDefaults() if err != nil {