Clarify maximum value of "metadata_size" (#609)
This commit is contained in:
parent
57b4e78b0f
commit
e80b989f8e
@ -10,6 +10,10 @@ import (
|
|||||||
const (
|
const (
|
||||||
pieceHash = crypto.SHA1
|
pieceHash = crypto.SHA1
|
||||||
defaultChunkSize = 0x4000 // 16KiB
|
defaultChunkSize = 0x4000 // 16KiB
|
||||||
|
|
||||||
|
// Arbitrary maximum of "metadata_size" (see https://www.bittorrent.org/beps/bep_0009.html)
|
||||||
|
// This value is 2x what libtorrent-rasterbar uses, which should be plenty
|
||||||
|
maxMetadataSize uint32 = 8*1024*1024
|
||||||
)
|
)
|
||||||
|
|
||||||
// These are our extended message IDs. Peers will use these values to
|
// These are our extended message IDs. Peers will use these values to
|
||||||
|
10
torrent.go
10
torrent.go
@ -481,19 +481,19 @@ func (t *Torrent) haveAllMetadataPieces() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Propagate errors to disconnect peer.
|
// TODO: Propagate errors to disconnect peer.
|
||||||
func (t *Torrent) setMetadataSize(bytes int) (err error) {
|
func (t *Torrent) setMetadataSize(size int) (err error) {
|
||||||
if t.haveInfo() {
|
if t.haveInfo() {
|
||||||
// We already know the correct metadata size.
|
// We already know the correct metadata size.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes <= 0 || bytes > 10000000 { // 10MB, pulled from my ass.
|
if uint32(size) > maxMetadataSize {
|
||||||
return errors.New("bad size")
|
return errors.New("bad size")
|
||||||
}
|
}
|
||||||
if t.metadataBytes != nil && len(t.metadataBytes) == int(bytes) {
|
if len(t.metadataBytes) == size {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.metadataBytes = make([]byte, bytes)
|
t.metadataBytes = make([]byte, size)
|
||||||
t.metadataCompletedChunks = make([]bool, (bytes+(1<<14)-1)/(1<<14))
|
t.metadataCompletedChunks = make([]bool, (size+(1<<14)-1)/(1<<14))
|
||||||
t.metadataChanged.Broadcast()
|
t.metadataChanged.Broadcast()
|
||||||
for c := range t.conns {
|
for c := range t.conns {
|
||||||
c.requestPendingMetadata()
|
c.requestPendingMetadata()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user