From: Matt Joiner Date: Thu, 21 Aug 2014 15:26:41 +0000 (+1000) Subject: Fix error in bitfield correction expression and off by one condition when metadata... X-Git-Tag: v1.0.0~1627 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=848636f830ec820a0290c4001d220fa93d139ff7;p=btrtrc.git Fix error in bitfield correction expression and off by one condition when metadata is completed --- diff --git a/connection.go b/connection.go index 4a7104d9..e79b5d66 100644 --- a/connection.go +++ b/connection.go @@ -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")