aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-07-18 13:56:25 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-07-18 13:56:25 +0200
commit177af7984086849da2ab3b324509df5d1932417f (patch)
tree7cff78013349f29af28c68c1863c29f7427e4ce7
parentad55cd39c9ca982b8cbc40712885d3ad8a5bea52 (diff)
Cleanup
-rw-r--r--cmd/btcheck/main.go2
-rw-r--r--meta/info.go11
-rw-r--r--meta/piece.go19
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)
-}