]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix bugs in the new WriteSectionTo hashing implementation
authorMatt Joiner <anacrolix@gmail.com>
Mon, 7 Oct 2013 07:58:33 +0000 (18:58 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 7 Oct 2013 07:58:33 +0000 (18:58 +1100)
client.go
mmap_span.go

index 1eb15b9d8e0971a476403013034be39aeadc131d..af67137c9e092f6724ca2205a76efa15f3a9115c 100644 (file)
--- a/client.go
+++ b/client.go
@@ -8,6 +8,7 @@ import (
        "crypto/rand"
        "encoding"
        "errors"
+       "fmt"
        metainfo "github.com/nsf/libtorgo/torrent"
        "io"
        "launchpad.net/gommap"
@@ -231,12 +232,12 @@ func (t *Torrent) PieceSize(piece int) (size int64) {
 
 func (t *Torrent) HashPiece(piece int) (ps pieceSum) {
        hash := PieceHash.New()
-       n, err := t.Data.WriteSectionTo(hash, int64(piece)*t.MetaInfo.PieceLength, int64(piece)*t.MetaInfo.PieceLength)
+       n, err := t.Data.WriteSectionTo(hash, int64(piece)*t.MetaInfo.PieceLength, t.MetaInfo.PieceLength)
        if err != nil {
                panic(err)
        }
        if n != t.PieceSize(piece) {
-               panic("hashed wrong number of bytes")
+               panic(fmt.Sprintf("hashed wrong number of bytes: expected %d; did %d; piece %d", t.PieceSize(piece), n, piece))
        }
        copyHashSum(ps[:], hash.Sum(nil))
        return
index fcc5cd4e09368ced715b40d9cd76d604d9799096..37f97720e915341910d3bf4455bfa8cc8dfb39e7 100644 (file)
@@ -61,7 +61,7 @@ func (me MMapSpan) WriteSectionTo(w io.Writer, off, n int64) (written int64, err
                if err != nil {
                        return true
                }
-               return n != 0
+               return n == 0
        })
        return
 }