Invalidating metadata would cause a crash when metadata pieces kept arriving

This commit is contained in:
Matt Joiner 2014-07-14 23:12:52 +10:00
parent 61b87222d4
commit 9e8a72ff1d
2 changed files with 8 additions and 3 deletions

View File

@ -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)

View File

@ -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
}