From e8b04c7181588c362cf11d48ba88170742cb48e7 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 18 Feb 2023 18:35:22 +1100 Subject: [PATCH] gofumpt --- 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 ++- 9 files changed, 27 insertions(+), 19 deletions(-) diff --git a/client_test.go b/client_test.go index 65182d58..03851ae8 100644 --- a/client_test.go +++ b/client_test.go @@ -808,7 +808,7 @@ func TestBadPeerIpPort(t *testing.T) { 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 @@ func TestBadPeerIpPort(t *testing.T) { require.Equal(t, tc.expectedOk, cl.badPeerIPPort(tc.ip, tc.port)) }) } - } diff --git a/cmd/torrent/download.go b/cmd/torrent/download.go index 1f2fbc89..0ec4b990 100644 --- a/cmd/torrent/download.go +++ b/cmd/torrent/download.go @@ -221,7 +221,7 @@ func waitForPieces(ctx context.Context, t *torrent.Torrent, beginIndex, endIndex } 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 9835dc5b..183b4d86 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 99345fe7..7d3007ec 100644 --- a/misc.go +++ b/misc.go @@ -115,7 +115,8 @@ func connLessTrusted(l, r *Peer) bool { 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 b009a108..6c134be1 100644 --- a/request-strategy/order.go +++ b/request-strategy/order.go @@ -66,7 +66,7 @@ func GetRequestablePieces( 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 a9d922ac..00b2721c 100644 --- a/storage/mmap.go +++ b/storage/mmap.go @@ -71,6 +71,7 @@ func (ts *mmapTorrentStorage) Close() error { } 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 1716b44c..c6b06fc1 100644 --- a/tracker/http/client.go +++ b/tracker/http/client.go @@ -13,8 +13,10 @@ type Client struct { 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 60cd8527..97b9b621 100644 --- a/webtorrent/tracker-client.go +++ b/webtorrent/tracker-client.go @@ -233,14 +233,16 @@ func (tc *TrackerClient) Announce(event tracker.AnnounceEvent, infoHash [20]byte 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 b993487d..c17328e8 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) {