]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix some DeepSource lints
authorMatt Joiner <anacrolix@gmail.com>
Mon, 30 Aug 2021 01:48:34 +0000 (11:48 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 30 Aug 2021 01:48:34 +0000 (11:48 +1000)
client_test.go
torrent.go
torrent_test.go

index df0aeaaa07d9b197b5bcbf1ef8d3637511ae92a6..a8192eb1dd5d89df05f2925ab792bc71359aa8a9 100644 (file)
@@ -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)
index 7fbcd2781f7589b5d437e5d1a85cdccae436bdd7..8e2b39174a7be8e2980c9ce3c6412ec12e7b5c97 100644 (file)
@@ -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)
                        }
index b413a39e8c928926cb6c0dfa60a6872540c9d25c..053ed5d1a444b8b8d9c9461e865ed5ca03343b73 100644 (file)
@@ -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))