1
0
mirror of https://github.com/veggiedefender/torrent-client.git synced 2025-11-06 09:29:16 +02:00

Change Torrent.PieceHashes to [][20]byte

This commit is contained in:
Jesse
2019-12-22 21:56:45 -05:00
parent 2810320046
commit b7cccc4662
2 changed files with 5 additions and 5 deletions

View File

@@ -19,7 +19,7 @@ const Port uint16 = 6881
type Torrent struct {
Announce string
InfoHash [20]byte
PieceHashes [][]byte
PieceHashes [][20]byte
PieceLength int
Length int
Name string
@@ -83,7 +83,7 @@ func (i *bencodeInfo) hash() ([20]byte, error) {
return h, nil
}
func (i *bencodeInfo) splitPieceHashes() ([][]byte, error) {
func (i *bencodeInfo) splitPieceHashes() ([][20]byte, error) {
hashLen := 20 // Length of SHA-1 hash
buf := []byte(i.Pieces)
if len(buf)%hashLen != 0 {
@@ -91,10 +91,10 @@ func (i *bencodeInfo) splitPieceHashes() ([][]byte, error) {
return nil, err
}
numHashes := len(buf) / hashLen
hashes := make([][]byte, numHashes)
hashes := make([][20]byte, numHashes)
for i := 0; i < numHashes; i++ {
hashes[i] = buf[i*hashLen : (i+1)*hashLen]
copy(hashes[i][:], buf[i*hashLen:(i+1)*hashLen])
}
return hashes, nil
}