From: Matt Joiner Date: Mon, 30 Aug 2021 01:48:34 +0000 (+1000) Subject: Fix some DeepSource lints X-Git-Tag: v1.31.0~7 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=bf6e64a652d7d6c48328558794d23010cefd55f9;p=btrtrc.git Fix some DeepSource lints --- diff --git a/client_test.go b/client_test.go index df0aeaaa..a8192eb1 100644 --- a/client_test.go +++ b/client_test.go @@ -86,7 +86,7 @@ func TestTorrentInitialState(t *testing.T) { ) 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) diff --git a/torrent.go b/torrent.go index 7fbcd278..8e2b3917 100644 --- a/torrent.go +++ b/torrent.go @@ -449,7 +449,7 @@ func (t *Torrent) onSetInfo() { } // 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") } @@ -1280,7 +1280,7 @@ func (t *Torrent) maybeCompleteMetadata() error { // 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) @@ -1355,7 +1355,7 @@ func (t *Torrent) bytesCompleted() int64 { 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. @@ -1658,7 +1658,7 @@ func (t *Torrent) AnnounceToDht(s DhtServer) (done <-chan struct{}, stop func(), 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 @@ -1695,7 +1695,7 @@ func (t *Torrent) dhtAnnouncer(s DhtServer) { 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) } diff --git a/torrent_test.go b/torrent_test.go index b413a39e..053ed5d1 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -147,7 +147,7 @@ func TestPieceHashFailed(t *testing.T) { 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))