29 lines
517 B
Go
29 lines
517 B
Go
|
package torrent
|
||
|
|
||
|
import (
|
||
|
"crypto/sha1"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
TORRENT_PIECE_LENGTH = 262144
|
||
|
)
|
||
|
|
||
|
type TorrentInfo struct {
|
||
|
PieceLength int `bencode:"piece length"`
|
||
|
Pieces string `bencode:"pieces"`
|
||
|
Name string `bencode:"name"`
|
||
|
Length int `bencode:"length"`
|
||
|
}
|
||
|
|
||
|
type Torrent struct {
|
||
|
Encoding string `bencode:"encoding"`
|
||
|
Info TorrentInfo `bencode:"info"`
|
||
|
UrlList []string `bencode:"url-list"`
|
||
|
}
|
||
|
|
||
|
func HashPiece(piece []byte) []byte {
|
||
|
h := sha1.New()
|
||
|
h.Write(piece)
|
||
|
return h.Sum(nil)
|
||
|
}
|