From 376ff763fe13c9028d2673a36e41ed3d22ae1dde Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 20 Feb 2020 11:09:57 +1100 Subject: [PATCH] Apply staticcheck --- bencode/decode_test.go | 16 ++++++++-------- client.go | 16 +++------------- client_test.go | 13 +------------ fs/torrentfs.go | 4 +--- metainfo/magnet_test.go | 1 + multiless.go | 1 - peer_protocol/decoder.go | 3 ++- piece.go | 6 ------ torrent.go | 12 +----------- tracker/http_test.go | 2 -- 10 files changed, 17 insertions(+), 57 deletions(-) diff --git a/bencode/decode_test.go b/bencode/decode_test.go index f9876f5a..4b72edbb 100644 --- a/bencode/decode_test.go +++ b/bencode/decode_test.go @@ -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)) diff --git a/client.go b/client.go index 0990c6e0..8c1eb87f 100644 --- 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 } diff --git a/client_test.go b/client_test.go index 372f4bcd..0278d42c 100644 --- a/client_test.go +++ b/client_test.go @@ -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()) diff --git a/fs/torrentfs.go b/fs/torrentfs.go index 843e2f16..0b3b7a91 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -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 { diff --git a/metainfo/magnet_test.go b/metainfo/magnet_test.go index 2cb590b9..d75f3679 100644 --- a/metainfo/magnet_test.go +++ b/metainfo/magnet_test.go @@ -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("") diff --git a/multiless.go b/multiless.go index 3f69a626..0d26c927 100644 --- a/multiless.go +++ b/multiless.go @@ -4,5 +4,4 @@ import "github.com/anacrolix/missinggo" type ( multiLess = missinggo.MultiLess - cmper = missinggo.SameLessFunc ) diff --git a/peer_protocol/decoder.go b/peer_protocol/decoder.go index b7ccab14..3b9d6e9c 100644 --- a/peer_protocol/decoder.go +++ b/peer_protocol/decoder.go @@ -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 } diff --git a/piece.go b/piece.go index 1c68d3ed..28b87747 100644 --- 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++ diff --git a/torrent.go b/torrent.go index 0f4a6810..bb10264f 100644 --- a/torrent.go +++ b/torrent.go @@ -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 { diff --git a/tracker/http_test.go b/tracker/http_test.go index a19677d5..474c4aa4 100644 --- a/tracker/http_test.go +++ b/tracker/http_test.go @@ -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( -- 2.44.0