connection.go | 4 ++-- diff --git a/connection.go b/connection.go index 4a7104d958740ba83c7e5e0c3d27a50a48bc8711..e79b5d665839e6a15de8ec99b28a9f3fb513c2c1 100644 --- a/connection.go +++ b/connection.go @@ -100,7 +100,7 @@ } if len(cn.PeerPieces) == num { } else if len(cn.PeerPieces) < num { cn.PeerPieces = append(cn.PeerPieces, make([]bool, num-len(cn.PeerPieces))...) - } else if len(cn.PeerPieces) < 8*(num+7)/8 { + } else if len(cn.PeerPieces) <= (num+7)/8*8 { for _, have := range cn.PeerPieces[num:] { if have { return errors.New("peer has invalid piece") @@ -108,7 +108,7 @@ } } cn.PeerPieces = cn.PeerPieces[:num] } else { - return errors.New("peer bitfield is excessively long") + return fmt.Errorf("peer bitfield is excessively long: expected %d, have %d", num, len(cn.PeerPieces)) } if len(cn.PeerPieces) != num { panic("wat")