Invalidating metadata would cause a crash when metadata pieces kept arriving
This commit is contained in:
parent
61b87222d4
commit
9e8a72ff1d
|
@ -494,6 +494,8 @@ func (cl *Client) completedMetadata(t *torrent) {
|
|||
t.InvalidateMetadata()
|
||||
return
|
||||
}
|
||||
// TODO(anacrolix): If this fails, I think something harsher should be
|
||||
// done.
|
||||
err = cl.setMetaData(t, info, t.MetaData)
|
||||
if err != nil {
|
||||
log.Printf("error setting metadata: %s", err)
|
||||
|
|
|
@ -53,9 +53,8 @@ type torrent struct {
|
|||
}
|
||||
|
||||
func (t *torrent) InvalidateMetadata() {
|
||||
for i := range t.metadataHave {
|
||||
t.metadataHave[i] = false
|
||||
}
|
||||
t.MetaData = nil
|
||||
t.metadataHave = nil
|
||||
t.Info = nil
|
||||
}
|
||||
|
||||
|
@ -63,6 +62,10 @@ func (t *torrent) SaveMetadataPiece(index int, data []byte) {
|
|||
if t.haveInfo() {
|
||||
return
|
||||
}
|
||||
if index >= len(t.metadataHave) {
|
||||
log.Printf("%s: ignoring metadata piece %d", t, index)
|
||||
return
|
||||
}
|
||||
copy(t.MetaData[(1<<14)*index:], data)
|
||||
t.metadataHave[index] = true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue