From 177af7984086849da2ab3b324509df5d1932417f Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 18 Jul 2016 13:56:25 +0200 Subject: Cleanup --- cmd/btcheck/main.go | 2 +- meta/info.go | 11 +---------- meta/piece.go | 19 ++++++------------- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/cmd/btcheck/main.go b/cmd/btcheck/main.go index 2fc1b1c..d4c30b0 100644 --- a/cmd/btcheck/main.go +++ b/cmd/btcheck/main.go @@ -20,7 +20,7 @@ func main() { } buf := make([]byte, tor.Info.PieceLength) for i, p := range tor.Info.Pieces { - off := tor.Info.PieceLength * i + off := tor.Info.Offset(i) n, err := tor.Info.ReadAt(buf, int64(off)) if err != nil { log.Fatal(err) diff --git a/meta/info.go b/meta/info.go index 51378ed..778c394 100644 --- a/meta/info.go +++ b/meta/info.go @@ -19,22 +19,13 @@ type Info struct { Pieces Pieces `bencode:"pieces"` Private bool `bencode:"private"` // BEP-0027 RootHash []byte `bencode:"root hash"` // BEP-0030 - Raw []byte `bencode:"-"` + Raw []byte `bencode:"-"` // raw representation of bencoded structure } func (i Info) Hash() [sha1.Size]byte { return sha1.Sum(i.Raw) } -// NPieces returns number of all pieces -func (i Info) NPieces() int { - full, last := i.Full(), i.Last() - if last > 0 { - return full + 1 - } - return full -} - // Full returns count of full pieces func (i Info) Full() int { return int(i.TotalLength() / int64(i.PieceLength)) diff --git a/meta/piece.go b/meta/piece.go index ee39d36..3878818 100644 --- a/meta/piece.go +++ b/meta/piece.go @@ -2,11 +2,16 @@ package meta import ( "crypto/sha1" - "fmt" "dim13.org/btget/bencode" ) +type Piece [sha1.Size]byte + +func (p Piece) Check(b []byte) bool { + return sha1.Sum(b) == p +} + type Pieces []Piece func (p *Pieces) UnmarshalBencode(b []byte) (int, error) { @@ -23,15 +28,3 @@ func (p *Pieces) UnmarshalBencode(b []byte) (int, error) { } return n, nil } - -type Piece [sha1.Size]byte - -func (p Piece) Check(b []byte) bool { - return sha1.Sum(b) == p -} - -type Percent float64 - -func (p Percent) String() string { - return fmt.Sprintf("%6.2f%%", p) -} -- cgit v1.2.3