]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix error in bitfield correction expression and off by one condition when metadata...
authorMatt Joiner <anacrolix@gmail.com>
Thu, 21 Aug 2014 15:26:41 +0000 (01:26 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 21 Aug 2014 15:26:41 +0000 (01:26 +1000)
connection.go

index 4a7104d958740ba83c7e5e0c3d27a50a48bc8711..e79b5d665839e6a15de8ec99b28a9f3fb513c2c1 100644 (file)
@@ -100,7 +100,7 @@ func (cn *connection) setNumPieces(num int) error {
        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 @@ func (cn *connection) setNumPieces(num int) error {
                }
                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")