client_test.go | 3 +-- cmd/torrent/download.go | 2 +- metainfo/piece-length.go | 8 +++++--- misc.go | 3 ++- request-strategy/order.go | 2 +- storage/mmap.go | 1 + tracker/http/client.go | 6 ++++-- webtorrent/tracker-client.go | 18 ++++++++++-------- webtorrent/transport_test.go | 3 ++- diff --git a/client_test.go b/client_test.go index 65182d58be84bfe5a880ab2071f2525e5dfee851..03851ae88d8712c4293545604ab97e7935f273e3 100644 --- a/client_test.go +++ b/client_test.go @@ -808,7 +808,7 @@ 2322, true, func(cl *Client) { cl.ipBlockList = iplist.New([]iplist.Range{ - iplist.Range{First: net.ParseIP("10.0.0.1"), Last: net.ParseIP("10.0.0.255")}, + {First: net.ParseIP("10.0.0.1"), Last: net.ParseIP("10.0.0.255")}, }) }, }, @@ -845,5 +845,4 @@ tc.setup(cl) require.Equal(t, tc.expectedOk, cl.badPeerIPPort(tc.ip, tc.port)) }) } - } diff --git a/cmd/torrent/download.go b/cmd/torrent/download.go index 1f2fbc89ff7c1ae57004afb595908c07509d9a13..0ec4b99088250bc37cae52daf60c9791155519bc 100644 --- a/cmd/torrent/download.go +++ b/cmd/torrent/download.go @@ -221,7 +221,7 @@ } } func writeMetainfoToFile(mi metainfo.MetaInfo, path string) error { - f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0640) + f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o640) if err != nil { return err } diff --git a/metainfo/piece-length.go b/metainfo/piece-length.go index 9835dc5b2fbeae4c287abe5803fccd5b932ba8f3..183b4d86ff4196626c75cff62b3c878f98c1871c 100644 --- a/metainfo/piece-length.go +++ b/metainfo/piece-length.go @@ -31,9 +31,11 @@ package metainfo // For more context on why these numbers, see http://wiki.vuze.com/w/Torrent_Piece_Size -const minimumPieceLength = 16 * 1024 -const targetPieceCountLog2 = 10 -const targetPieceCountMin = 1 << targetPieceCountLog2 +const ( + minimumPieceLength = 16 * 1024 + targetPieceCountLog2 = 10 + targetPieceCountMin = 1 << targetPieceCountLog2 +) // Target piece count should be < targetPieceCountMax const targetPieceCountMax = targetPieceCountMin << 1 diff --git a/misc.go b/misc.go index 99345fe70f5fdf26f8c00494ed31055a0df1faff..7d3007ecee74eb92f58eee434dfb9431a86f9098 100644 --- a/misc.go +++ b/misc.go @@ -115,7 +115,8 @@ } func connIsIpv6(nc interface { LocalAddr() net.Addr -}) bool { +}, +) bool { ra := nc.LocalAddr() rip := addrIpOrNil(ra) return rip.To4() == nil && rip.To16() != nil diff --git a/request-strategy/order.go b/request-strategy/order.go index b009a10882e84eb9a235345b64f70cd2f2631f15..6c134be1d333e19ff43f523da1c4d485dde5bbed 100644 --- a/request-strategy/order.go +++ b/request-strategy/order.go @@ -66,7 +66,7 @@ } lastItem.Set(_i) ih := _i.key.InfoHash - var t = input.Torrent(ih) + t := input.Torrent(ih) pieceLength := t.PieceLength() if storageLeft != nil { if *storageLeft < pieceLength { diff --git a/storage/mmap.go b/storage/mmap.go index a9d922ac20146b2fa11db8c4ea2497f210e7d73a..00b2721c1199767d5f9982d2f243820a6fb325a4 100644 --- a/storage/mmap.go +++ b/storage/mmap.go @@ -71,6 +71,7 @@ return errs[0] } return nil } + func (ts *mmapTorrentStorage) Flush() error { errs := ts.span.Flush() if len(errs) > 0 { diff --git a/tracker/http/client.go b/tracker/http/client.go index 1716b44c8a80781540ee1f0ecf827ebbb84c6216..c6b06fc10dcc5a3f47c89d27a2a84c5a75229d01 100644 --- a/tracker/http/client.go +++ b/tracker/http/client.go @@ -13,8 +13,10 @@ hc *http.Client url_ *url.URL } -type ProxyFunc func(*http.Request) (*url.URL, error) -type DialContextFunc func(ctx context.Context, network, addr string) (net.Conn, error) +type ( + ProxyFunc func(*http.Request) (*url.URL, error) + DialContextFunc func(ctx context.Context, network, addr string) (net.Conn, error) +) type NewClientOpts struct { Proxy ProxyFunc diff --git a/webtorrent/tracker-client.go b/webtorrent/tracker-client.go index 60cd852773e524c8d9d130b16c9fc5005e43c32c..97b9b6211aa744bd09a19d8cc5527ee671f2f578 100644 --- a/webtorrent/tracker-client.go +++ b/webtorrent/tracker-client.go @@ -233,14 +233,16 @@ if err != nil { return fmt.Errorf("creating offer: %w", err) } - err = tc.announce(event, infoHash, []outboundOffer{{ - offerId: offerIDBinary, - outboundOfferValue: outboundOfferValue{ - originalOffer: offer, - peerConnection: pc, - infoHash: infoHash, - dataChannel: dc, - }}, + err = tc.announce(event, infoHash, []outboundOffer{ + { + offerId: offerIDBinary, + outboundOfferValue: outboundOfferValue{ + originalOffer: offer, + peerConnection: pc, + infoHash: infoHash, + dataChannel: dc, + }, + }, }) if err != nil { dc.Close() diff --git a/webtorrent/transport_test.go b/webtorrent/transport_test.go index b993487dd5d6373775b1ef2617bb49b4d03b47aa..c17328e8dd410a352436a014d19175f8d52be6a1 100644 --- a/webtorrent/transport_test.go +++ b/webtorrent/transport_test.go @@ -1,10 +1,11 @@ package webtorrent import ( + "testing" + "github.com/anacrolix/log" qt "github.com/frankban/quicktest" "github.com/pion/webrtc/v3" - "testing" ) func TestClosingPeerConnectionDoesNotCloseUnopenedDataChannel(t *testing.T) {