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 -- diff --git a/bencode/decode_test.go b/bencode/decode_test.go index f9876f5adaa7cfc45c5f1037b0c242ab8c44dceb..4b72edbb802376fc4389b0aefc29eaf12e581664 100644 --- a/bencode/decode_test.go +++ b/bencode/decode_test.go @@ -108,26 +108,26 @@ t.Errorf("got: %v (%T), expected: %v (%T)\n", x, x, y, y) } } -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 0990c6e0affb4534ba7357b0a23a4a0d1f523c49..8c1eb87f2a57413c3299d49c746fd4f0cc57d8ca 100644 --- a/client.go +++ b/client.go @@ -268,15 +268,6 @@ } 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 @@ connsToSelf.Add(1) 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 372f4bcdc09091a9fcb4a82f1f9b324dd9677e30..0278d42c41268051a6d7235ff691fcbec067f208 100644 --- a/client_test.go +++ b/client_test.go @@ -5,7 +5,6 @@ "encoding/binary" "fmt" "io" "io/ioutil" - "log" "os" "path/filepath" "reflect" @@ -315,16 +314,6 @@ LeecherStorage func(string) storage.ClientImpl SeederStorage func(string) storage.ClientImpl SeederUploadRateLimiter *rate.Limiter 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 @@ -1142,7 +1131,7 @@ require.NoError(t, err) 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 843e2f16eb0c3976f27374639bc355ffb6fa10b4..0b3b7a91f1421f3068f03e1d9dd34cb6bdf6602c 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -19,9 +19,7 @@ defaultMode = 0555 ) 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 2cb590b9e10f4407b0f2d5b1a28e996a11a772a5..d75f367943cf988b0bfa87c96e6925d62c6a3292 100644 --- a/metainfo/magnet_test.go +++ b/metainfo/magnet_test.go @@ -45,6 +45,7 @@ // 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 3f69a626b1aa9cae234fcfde21816548b26484e7..0d26c9270ccff2d7ea0039264f7a3beaab678ae7 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 b7ccab14c4ac500d9b2eaa333fda35ca0e533f2b..3b9d6e9cd3c378e5285d2b36bc8b0f0c57be62dd 100644 --- a/peer_protocol/decoder.go +++ b/peer_protocol/decoder.go @@ -86,7 +86,8 @@ if err != nil { 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 1c68d3edb5533c1c670a97a174434aeaa5eaefb8..28b87747ae57f06b718a4676694d77f9e5ed8932 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 0f4a681024302451c2e7b247ea49324eb014f9f8..bb10264f78ecb0968c672c0e02b5231b774db323 100644 --- a/torrent.go +++ b/torrent.go @@ -31,10 +31,6 @@ "github.com/anacrolix/torrent/storage" "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 (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 @@ -1105,12 +1101,6 @@ func (t *Torrent) readAt(b []byte, off int64) (n int, err error) { p := &t.pieces[off/t.info.PieceLength] p.waitNoPendingWrites() 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 diff --git a/tracker/http_test.go b/tracker/http_test.go index a19677d59f75af7488189a35521af88e95c3613b..474c4aa4ec5572eb97d694260010134e99c129b8 100644 --- a/tracker/http_test.go +++ b/tracker/http_test.go @@ -9,8 +9,6 @@ "github.com/anacrolix/torrent/bencode" ) -var defaultHTTPUserAgent = "Go-Torrent" - func TestUnmarshalHTTPResponsePeerDicts(t *testing.T) { var hr HttpResponse require.NoError(t, bencode.Unmarshal(