Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up missinggo dependencies and formatting #976

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bencode/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"reflect"

"github.com/anacrolix/missinggo/expect"
"github.com/anacrolix/missinggo/v2/expect"
)

//----------------------------------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions bencode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ import (
"sort"
"strconv"
"sync"

"github.com/anacrolix/missinggo"
)

func isEmptyValue(v reflect.Value) bool {
return missinggo.IsEmptyValue(v)
}

type Encoder struct {
w io.Writer
scratch [64]byte
Expand Down Expand Up @@ -139,7 +133,7 @@ func (e *Encoder) reflectValue(v reflect.Value) {
if !fieldValue.IsValid() {
continue
}
if ef.omitEmpty && isEmptyValue(fieldValue) {
if ef.omitEmpty && fieldValue.IsZero() {
continue
}
e.reflectString(ef.tag)
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ require (
github.com/anacrolix/go-libutp v1.3.1
github.com/anacrolix/gostdapp v0.1.0
github.com/anacrolix/log v0.15.3-0.20240627045001-cd912c641d83
github.com/anacrolix/missinggo v1.3.0
github.com/anacrolix/missinggo/v2/perf v1.0.0
github.com/anacrolix/missinggo/v2 v2.7.3
github.com/anacrolix/missinggo/v2 v2.7.4
github.com/anacrolix/multiless v0.3.0
github.com/anacrolix/possum/go v0.1.1-0.20240321122240-a01f3a22f2d1
github.com/anacrolix/squirrel v0.6.4
Expand Down Expand Up @@ -53,8 +51,8 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1
go.opentelemetry.io/otel/sdk v1.11.1
go.opentelemetry.io/otel/trace v1.11.1
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/sync v0.7.0
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948
golang.org/x/sync v0.8.0
golang.org/x/sys v0.18.0
golang.org/x/time v0.0.0-20220609170525-579cf78fd858
)
Expand All @@ -63,6 +61,8 @@ require (
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/anacrolix/backtrace v0.0.0-20221205112523-22a61db8f82e // indirect
github.com/anacrolix/missinggo v1.3.0 // indirect
github.com/anacrolix/missinggo/perf v1.0.0 // indirect
github.com/anacrolix/mmsg v1.0.0 // indirect
github.com/anacrolix/stm v0.4.0 // indirect
github.com/benbjohnson/immutable v0.3.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ github.com/anacrolix/missinggo/v2/perf v1.0.0 h1:7ZOGYziGEBytW49+KmYGTaNfnwUqP1H
github.com/anacrolix/missinggo/v2/perf v1.0.0/go.mod h1:ljAFWkBuzkO12MQclXzZrosP5urunoLS0Cbvb4V0uMQ=
github.com/anacrolix/missinggo/v2 v2.2.0/go.mod h1:o0jgJoYOyaoYQ4E2ZMISVa9c88BbUBVQQW4QeRkNCGY=
github.com/anacrolix/missinggo/v2 v2.5.1/go.mod h1:WEjqh2rmKECd0t1VhQkLGTdIWXO6f6NLjp5GlMZ+6FA=
github.com/anacrolix/missinggo/v2 v2.7.3 h1:Ee//CmZBMadeNiYB/hHo9ly2PFOEZ4Fhsbnug3rDAIE=
github.com/anacrolix/missinggo/v2 v2.7.3/go.mod h1:mIEtp9pgaXqt8VQ3NQxFOod/eQ1H0D1XsZzKUQfwtac=
github.com/anacrolix/missinggo/v2 v2.7.4 h1:47h5OXoPV8JbA/ACA+FLwKdYbAinuDO8osc2Cu9xkxg=
github.com/anacrolix/missinggo/v2 v2.7.4/go.mod h1:vVO5FEziQm+NFmJesc7StpkquZk+WJFCaL0Wp//2sa0=
github.com/anacrolix/mmsg v0.0.0-20180515031531-a4a3ba1fc8bb/go.mod h1:x2/ErsYUmT77kezS63+wzZp8E3byYB0gzirM/WMBLfw=
github.com/anacrolix/mmsg v1.0.0 h1:btC7YLjOn29aTUAExJiVUhQOuf/8rhm+/nWCMAnL3Hg=
github.com/anacrolix/mmsg v1.0.0/go.mod h1:x8kRaJY/dCrY9Al0PEcj1mb/uFHwP6GCJ9fLl4thEPc=
Expand Down Expand Up @@ -633,8 +633,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA=
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -730,8 +730,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io"
"strings"

"github.com/anacrolix/missinggo/expect"
"github.com/anacrolix/missinggo/v2/expect"

"github.com/anacrolix/torrent/bencode"
"github.com/anacrolix/torrent/metainfo"
Expand Down
2 changes: 1 addition & 1 deletion misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
)

func newRequest(index, begin, length pp.Integer) Request {
return Request{index, ChunkSpec{begin, length}}
return Request{Index: index, ChunkSpec: ChunkSpec{Begin: begin, Length: length}}
}

func newRequestFromMessage(msg *pp.Message) Request {
Expand Down
2 changes: 1 addition & 1 deletion misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"
"testing"

"github.com/anacrolix/missinggo/iter"
"github.com/anacrolix/missinggo/v2/bitmap"
"github.com/anacrolix/missinggo/v2/iter"
"github.com/davecgh/go-spew/spew"
"github.com/stretchr/testify/assert"
)
Expand Down
30 changes: 13 additions & 17 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/anacrolix/chansync"
. "github.com/anacrolix/generics"
"github.com/anacrolix/log"
"github.com/anacrolix/missinggo/iter"
"github.com/anacrolix/missinggo/v2/bitmap"
"github.com/anacrolix/missinggo/v2/iter"
"github.com/anacrolix/multiless"

"github.com/anacrolix/torrent/internal/alloclim"
Expand Down Expand Up @@ -504,25 +504,21 @@ func (cn *Peer) updateRequests(reason updateRequestReason) {
cn.handleUpdateRequests()
}

// Emits the indices in the Bitmaps bms in order, never repeating any index.
// skip is mutated during execution, and its initial values will never be
// emitted.
// iterBitmapsDistinct emits the indices in the Bitmaps bms in order, never repeating any index.
// skip is mutated during execution, and its initial values will never be emitted.
func iterBitmapsDistinct(skip *bitmap.Bitmap, bms ...bitmap.Bitmap) iter.Func {
return func(cb iter.Callback) {
for _, bm := range bms {
if !iter.All(
func(_i interface{}) bool {
i := _i.(int)
if skip.Contains(bitmap.BitIndex(i)) {
return true
bm.Iter(func(value interface{}) bool {
index := value.(int)
if !skip.Contains(bitmap.BitIndex(index)) {
skip.Add(bitmap.BitIndex(index))
if !cb(index) {
return false
}
skip.Add(bitmap.BitIndex(i))
return cb(i)
},
bm.Iter,
) {
return
}
}
return true
})
}
}
}
Expand Down Expand Up @@ -842,7 +838,7 @@ func (c *Peer) remoteIp() net.IP {

func (c *Peer) remoteIpPort() IpPort {
ipa, _ := tryIpPortFromNetAddr(c.RemoteAddr)
return IpPort{ipa.IP, uint16(ipa.Port)}
return IpPort{IP: ipa.IP, Port: uint16(ipa.Port)}
}

func (c *Peer) trust() connectionTrust {
Expand Down
2 changes: 1 addition & 1 deletion peer_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ func (me *PeerInfo) FromPex(na krpc.NodeAddr, fs peer_protocol.PexPeerFlags) {

func (me PeerInfo) addr() IpPort {
ipPort, _ := tryIpPortFromNetAddr(me.Addr)
return IpPort{ipPort.IP, uint16(ipPort.Port)}
return IpPort{IP: ipPort.IP, Port: uint16(ipPort.Port)}
}
3 changes: 2 additions & 1 deletion peer_protocol/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/anacrolix/torrent/internal/ctxrw"
"io"
"math/bits"
"strconv"
"strings"
"unsafe"

"github.com/anacrolix/torrent/internal/ctxrw"

"github.com/anacrolix/torrent/metainfo"
)

Expand Down
2 changes: 1 addition & 1 deletion peerconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (cn *PeerConn) postBitfield() {
Type: pp.Bitfield,
Bitfield: cn.t.bitfield(),
})
cn.sentHaves = bitmap.Bitmap{cn.t._completedPieces.Clone()}
cn.sentHaves = bitmap.Bitmap{RB: cn.t._completedPieces.Clone()}
}

func (cn *PeerConn) handleUpdateRequests() {
Expand Down
2 changes: 1 addition & 1 deletion peerconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func TestReceiveLargeRequest(t *testing.T) {
func TestChunkOverflowsPiece(t *testing.T) {
c := qt.New(t)
check := func(begin, length, limit pp.Integer, expected bool) {
c.Check(chunkOverflowsPiece(ChunkSpec{begin, length}, limit), qt.Equals, expected)
c.Check(chunkOverflowsPiece(ChunkSpec{Begin: begin, Length: length}, limit), qt.Equals, expected)
}
check(2, 3, 1, true)
check(2, pp.IntegerMax, 1, true)
Expand Down
2 changes: 1 addition & 1 deletion requesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func makeTypicalRequests() map[Request]struct{} {
m := make(map[Request]struct{})
for p := pp.Integer(0); p < 4; p++ {
for c := pp.Integer(0); c < 16; c++ {
m[Request{p, ChunkSpec{c * defaultChunkSize, defaultChunkSize}}] = struct{}{}
m[Request{Index: p, ChunkSpec: ChunkSpec{c * defaultChunkSize, defaultChunkSize}}] = struct{}{}
}
}
return m
Expand Down
2 changes: 1 addition & 1 deletion storage/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"time"

"github.com/anacrolix/missinggo/expect"
"github.com/anacrolix/missinggo/v2/expect"
"go.etcd.io/bbolt"

"github.com/anacrolix/torrent/metainfo"
Expand Down
6 changes: 3 additions & 3 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
. "github.com/anacrolix/generics"
g "github.com/anacrolix/generics"
"github.com/anacrolix/log"
"github.com/anacrolix/missinggo/slices"
"github.com/anacrolix/missinggo/v2"
"github.com/anacrolix/missinggo/v2/bitmap"
"github.com/anacrolix/missinggo/v2/pubsub"
"github.com/anacrolix/missinggo/v2/slices"
"github.com/anacrolix/multiless"
"github.com/anacrolix/sync"
"github.com/pion/datachannel"
Expand Down Expand Up @@ -2919,8 +2919,8 @@ func (t *Torrent) peerIsActive(p *Peer) (active bool) {
func (t *Torrent) requestIndexToRequest(ri RequestIndex) Request {
index := t.pieceIndexOfRequestIndex(ri)
return Request{
pp.Integer(index),
t.piece(index).chunkIndexSpec(ri % t.chunksPerRegularPiece()),
Index: pp.Integer(index),
ChunkSpec: t.piece(index).chunkIndexSpec(ri % t.chunksPerRegularPiece()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion torrent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func r(i, b, l pp.Integer) Request {
return Request{i, ChunkSpec{b, l}}
return Request{Index: i, ChunkSpec: ChunkSpec{Begin: b, Length: l}}
}

// Check the given request is correct for various torrent offsets.
Expand Down
2 changes: 1 addition & 1 deletion tracker/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strconv"
"strings"

"github.com/anacrolix/missinggo/httptoo"
"github.com/anacrolix/missinggo/v2/httptoo"

"github.com/anacrolix/torrent/bencode"
"github.com/anacrolix/torrent/tracker/shared"
Expand Down
2 changes: 1 addition & 1 deletion webseed-peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (ws *webseedPeer) _cancel(r RequestIndex) bool {
}

func (ws *webseedPeer) intoSpec(r Request) webseed.RequestSpec {
return webseed.RequestSpec{ws.peer.t.requestOffset(r), int64(r.Length)}
return webseed.RequestSpec{Start: ws.peer.t.requestOffset(r), Length: int64(r.Length)}
}

func (ws *webseedPeer) _request(r Request) bool {
Expand Down
Loading