)
tor.setChunkSize(2)
tor.cl.lock()
- err := tor.setInfoBytes(mi.InfoBytes)
+ err := tor.setInfoBytesLocked(mi.InfoBytes)
tor.cl.unlock()
require.NoError(t, err)
require.Len(t, tor.pieces, 3)
}
// Called when metadata for a torrent becomes available.
-func (t *Torrent) setInfoBytes(b []byte) error {
+func (t *Torrent) setInfoBytesLocked(b []byte) error {
if metainfo.HashBytes(b) != t.infoHash {
return errors.New("info bytes have wrong hash")
}
// Don't have enough metadata pieces.
return nil
}
- err := t.setInfoBytes(t.metadataBytes)
+ err := t.setInfoBytesLocked(t.metadataBytes)
if err != nil {
t.invalidateMetadata()
return fmt.Errorf("error setting info bytes: %s", err)
func (t *Torrent) SetInfoBytes(b []byte) (err error) {
t.cl.lock()
defer t.cl.unlock()
- return t.setInfoBytes(b)
+ return t.setInfoBytesLocked(b)
}
// Returns true if connection is removed from torrent.Conns.
return
}
-func (t *Torrent) announceToDht(s DhtServer) error {
+func (t *Torrent) timeboxedAnnounceToDht(s DhtServer) error {
_, stop, err := t.AnnounceToDht(s)
if err != nil {
return err
t.numDHTAnnounces++
cl.unlock()
defer cl.lock()
- err := t.announceToDht(s)
+ err := t.timeboxedAnnounceToDht(s)
if err != nil {
t.logger.WithDefaultLevel(log.Warning).Printf("error announcing %q to DHT: %s", t, err)
}
cl.initLogger()
tt := cl.newTorrent(mi.HashInfoBytes(), badStorage{})
tt.setChunkSize(2)
- require.NoError(t, tt.setInfoBytes(mi.InfoBytes))
+ require.NoError(t, tt.setInfoBytesLocked(mi.InfoBytes))
tt.cl.lock()
tt.pieces[1]._dirtyChunks.AddRange(0, 3)
require.True(t, tt.pieceAllDirty(1))