You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
517 B
28 lines
517 B
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)
|
|
}
|