]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Apply staticcheck
authorMatt Joiner <anacrolix@gmail.com>
Thu, 20 Feb 2020 00:09:57 +0000 (11:09 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 20 Feb 2020 00:09:57 +0000 (11:09 +1100)
bencode/decode_test.go
client.go
client_test.go
fs/torrentfs.go
metainfo/magnet_test.go
multiless.go
peer_protocol/decoder.go
piece.go
torrent.go
tracker/http_test.go

index f9876f5adaa7cfc45c5f1037b0c242ab8c44dceb..4b72edbb802376fc4389b0aefc29eaf12e581664 100644 (file)
@@ -108,26 +108,26 @@ func assert_equal(t *testing.T, x, y interface{}) {
        }
 }
 
-type unmarshaler_int struct {
+type unmarshalerInt struct {
        x int
 }
 
-func (this *unmarshaler_int) UnmarshalBencode(data []byte) error {
-       return Unmarshal(data, &this.x)
+func (me *unmarshalerInt) UnmarshalBencode(data []byte) error {
+       return Unmarshal(data, &me.x)
 }
 
-type unmarshaler_string struct {
+type unmarshalerString struct {
        x string
 }
 
-func (this *unmarshaler_string) UnmarshalBencode(data []byte) error {
-       this.x = string(data)
+func (me *unmarshalerString) UnmarshalBencode(data []byte) error {
+       me.x = string(data)
        return nil
 }
 
 func TestUnmarshalerBencode(t *testing.T) {
-       var i unmarshaler_int
-       var ss []unmarshaler_string
+       var i unmarshalerInt
+       var ss []unmarshalerString
        check_error(t, Unmarshal([]byte("i71e"), &i))
        assert_equal(t, i.x, 71)
        check_error(t, Unmarshal([]byte("l5:hello5:fruit3:waye"), &ss))
index 0990c6e0affb4534ba7357b0a23a4a0d1f523c49..8c1eb87f2a57413c3299d49c746fd4f0cc57d8ca 100644 (file)
--- a/client.go
+++ b/client.go
@@ -268,15 +268,6 @@ func (cl *Client) firewallCallback(net.Addr) bool {
        return block
 }
 
-func (cl *Client) enabledPeerNetworks() (ns []network) {
-       for _, n := range allPeerNetworks {
-               if peerNetworkEnabled(n, cl.config) {
-                       ns = append(ns, n)
-               }
-       }
-       return
-}
-
 func (cl *Client) listenOnNetwork(n network) bool {
        if n.Ipv4 && cl.config.DisableIPv4 {
                return false
@@ -863,10 +854,9 @@ func (cl *Client) runHandshookConn(c *connection, t *Torrent) {
                        addr := c.conn.RemoteAddr().String()
                        cl.dopplegangerAddrs[addr] = struct{}{}
                } else {
-                       // Because the remote address is not necessarily the same as its
-                       // client's torrent listen address, we won't record the remote address
-                       // as a doppleganger. Instead, the initiator can record *us* as the
-                       // doppleganger.
+                       // Because the remote address is not necessarily the same as its client's torrent listen
+                       // address, we won't record the remote address as a doppleganger. Instead, the initiator
+                       // can record *us* as the doppleganger.
                }
                return
        }
index 372f4bcdc09091a9fcb4a82f1f9b324dd9677e30..0278d42c41268051a6d7235ff691fcbec067f208 100644 (file)
@@ -5,7 +5,6 @@ import (
        "fmt"
        "io"
        "io/ioutil"
-       "log"
        "os"
        "path/filepath"
        "reflect"
@@ -317,16 +316,6 @@ type testClientTransferParams struct {
        LeecherDownloadRateLimiter *rate.Limiter
 }
 
-func logPieceStateChanges(t *Torrent) {
-       sub := t.SubscribePieceStateChanges()
-       go func() {
-               defer sub.Close()
-               for e := range sub.Values {
-                       log.Printf("%p %#v", t, e)
-               }
-       }()
-}
-
 // Creates a seeder and a leecher, and ensures the data transfers when a read
 // is attempted on the leecher.
 func testClientTransfer(t *testing.T, ps testClientTransferParams) {
@@ -1142,7 +1131,7 @@ func TestIssue335(t *testing.T) {
        assert.True(t, new)
        require.True(t, cl.WaitAll())
        tor.Drop()
-       tor, new, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
+       _, new, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
        require.NoError(t, err)
        assert.True(t, new)
        require.True(t, cl.WaitAll())
index 843e2f16eb0c3976f27374639bc355ffb6fa10b4..0b3b7a91f1421f3068f03e1d9dd34cb6bdf6602c 100644 (file)
@@ -19,9 +19,7 @@ const (
 )
 
 var (
-       torrentfsReadRequests        = expvar.NewInt("torrentfsReadRequests")
-       torrentfsDelayedReadRequests = expvar.NewInt("torrentfsDelayedReadRequests")
-       interruptedReads             = expvar.NewInt("interruptedReads")
+       torrentfsReadRequests = expvar.NewInt("torrentfsReadRequests")
 )
 
 type TorrentFS struct {
index 2cb590b9e10f4407b0f2d5b1a28e996a11a772a5..d75f367943cf988b0bfa87c96e6925d62c6a3292 100644 (file)
@@ -45,6 +45,7 @@ func TestParseMagnetURI(t *testing.T) {
        // Checking if the magnet instance struct is built correctly from parsing
        m, err = ParseMagnetURI(exampleMagnetURI)
        assert.EqualValues(t, exampleMagnet, m)
+       assert.NoError(t, err)
 
        // empty string URI case
        _, err = ParseMagnetURI("")
index 3f69a626b1aa9cae234fcfde21816548b26484e7..0d26c9270ccff2d7ea0039264f7a3beaab678ae7 100644 (file)
@@ -4,5 +4,4 @@ import "github.com/anacrolix/missinggo"
 
 type (
        multiLess = missinggo.MultiLess
-       cmper     = missinggo.SameLessFunc
 )
index b7ccab14c4ac500d9b2eaa333fda35ca0e533f2b..3b9d6e9cd3c378e5285d2b36bc8b0f0c57be62dd 100644 (file)
@@ -86,7 +86,8 @@ func (d *Decoder) Decode(msg *Message) (err error) {
                        return errors.Wrap(err, "reading piece data")
                }
        case Extended:
-               b, err := readByte(r)
+               var b byte
+               b, err = readByte(r)
                if err != nil {
                        break
                }
index 1c68d3edb5533c1c670a97a174434aeaa5eaefb8..28b87747ae57f06b718a4676694d77f9e5ed8932 100644 (file)
--- a/piece.go
+++ b/piece.go
@@ -105,12 +105,6 @@ func (p *Piece) numChunks() pp.Integer {
        return p.t.pieceNumChunks(p.index)
 }
 
-func (p *Piece) undirtiedChunkIndices() (ret bitmap.Bitmap) {
-       ret = p._dirtyChunks.Copy()
-       ret.FlipRange(0, bitmap.BitIndex(p.numChunks()))
-       return
-}
-
 func (p *Piece) incrementPendingWrites() {
        p.pendingWritesMutex.Lock()
        p.pendingWrites++
index 0f4a681024302451c2e7b247ea49324eb014f9f8..bb10264f78ecb0968c672c0e02b5231b774db323 100644 (file)
@@ -31,10 +31,6 @@ import (
        "github.com/anacrolix/torrent/tracker"
 )
 
-func (t *Torrent) chunkIndexSpec(chunkIndex pp.Integer, piece pieceIndex) chunkSpec {
-       return chunkIndexSpec(chunkIndex, t.pieceLength(piece), t.chunkSize)
-}
-
 // Maintains state of torrent within a Client. Many methods should not be called before the info is
 // available, see .Info and .GotInfo.
 type Torrent struct {
@@ -319,7 +315,7 @@ func infoPieceHashes(info *metainfo.Info) (ret [][]byte) {
 
 func (t *Torrent) makePieces() {
        hashes := infoPieceHashes(t.info)
-       t.pieces = make([]Piece, len(hashes), len(hashes))
+       t.pieces = make([]Piece, len(hashes))
        for i, hash := range hashes {
                piece := &t.pieces[i]
                piece.t = t
@@ -1107,12 +1103,6 @@ func (t *Torrent) readAt(b []byte, off int64) (n int, err error) {
        return p.Storage().ReadAt(b, off-p.Info().Offset())
 }
 
-func (t *Torrent) updateAllPieceCompletions() {
-       for i := pieceIndex(0); i < t.numPieces(); i++ {
-               t.updatePieceCompletion(i)
-       }
-}
-
 // Returns an error if the metadata was completed, but couldn't be set for
 // some reason. Blame it on the last peer to contribute.
 func (t *Torrent) maybeCompleteMetadata() error {
index a19677d59f75af7488189a35521af88e95c3613b..474c4aa4ec5572eb97d694260010134e99c129b8 100644 (file)
@@ -9,8 +9,6 @@ import (
        "github.com/anacrolix/torrent/bencode"
 )
 
-var defaultHTTPUserAgent = "Go-Torrent"
-
 func TestUnmarshalHTTPResponsePeerDicts(t *testing.T) {
        var hr HttpResponse
        require.NoError(t, bencode.Unmarshal(