Skip to content

Commit 0ff3247

Browse files
Merge branch 'master' into provider
2 parents 5b3de2c + 79c3c1b commit 0ff3247

File tree

6 files changed

+127
-109
lines changed

6 files changed

+127
-109
lines changed

crawler/crawler.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ func NewDefaultCrawler(host host.Host, opts ...Option) (*DefaultCrawler, error)
5252
}
5353
}
5454

55-
pm, err := pb.NewProtocolMessenger(&messageSender{h: host, protocols: o.protocols, timeout: o.perMsgTimeout})
55+
var err error
56+
var pm *pb.ProtocolMessenger
57+
if o.msgSenderBuilder != nil {
58+
pm, err = pb.NewProtocolMessenger(o.msgSenderBuilder(host, o.protocols))
59+
} else {
60+
pm, err = pb.NewProtocolMessenger(&messageSender{h: host, protocols: o.protocols, timeout: o.perMsgTimeout})
61+
}
5662
if err != nil {
5763
return nil, err
5864
}
@@ -192,7 +198,7 @@ func (c *DefaultCrawler) Run(ctx context.Context, startingPeers []*peer.AddrInfo
192198
// Start worker goroutines
193199
var wg sync.WaitGroup
194200
wg.Add(c.parallelism)
195-
for i := 0; i < c.parallelism; i++ {
201+
for range c.parallelism {
196202
go func() {
197203
defer wg.Done()
198204
for p := range jobs {

crawler/options.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package crawler
22

33
import (
4+
"slices"
45
"time"
56

67
"github.com/libp2p/go-libp2p-kad-dht/amino"
8+
pb "github.com/libp2p/go-libp2p-kad-dht/pb"
9+
"github.com/libp2p/go-libp2p/core/host"
710
"github.com/libp2p/go-libp2p/core/protocol"
811
)
912

1013
// Option DHT Crawler option type.
1114
type Option func(*options) error
1215

1316
type options struct {
14-
protocols []protocol.ID
15-
parallelism int
16-
connectTimeout time.Duration
17-
perMsgTimeout time.Duration
17+
protocols []protocol.ID
18+
parallelism int
19+
connectTimeout time.Duration
20+
perMsgTimeout time.Duration
21+
msgSenderBuilder func(h host.Host, protos []protocol.ID) pb.MessageSenderWithDisconnect
1822
}
1923

2024
// defaults are the default crawler options. This option will be automatically
@@ -31,7 +35,7 @@ var defaults = func(o *options) error {
3135
// WithProtocols defines the ordered set of protocols the crawler will use to talk to other nodes
3236
func WithProtocols(protocols []protocol.ID) Option {
3337
return func(o *options) error {
34-
o.protocols = append([]protocol.ID{}, protocols...)
38+
o.protocols = slices.Clone(protocols)
3539
return nil
3640
}
3741
}
@@ -59,3 +63,12 @@ func WithConnectTimeout(timeout time.Duration) Option {
5963
return nil
6064
}
6165
}
66+
67+
// WithCustomMessageSender configures the pb.MessageSender of the IpfsDHT to use the
68+
// custom implementation of the pb.MessageSender
69+
func WithCustomMessageSender(messageSenderBuilder func(h host.Host, protos []protocol.ID) pb.MessageSenderWithDisconnect) Option {
70+
return func(o *options) error {
71+
o.msgSenderBuilder = messageSenderBuilder
72+
return nil
73+
}
74+
}

go.mod

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/libp2p/go-libp2p-kad-dht
22

3-
go 1.23.8
3+
go 1.23.10
44

55
require (
66
github.com/filecoin-project/go-clock v0.1.0
@@ -9,35 +9,35 @@ require (
99
github.com/google/uuid v1.6.0
1010
github.com/guillaumemichel/reservedpool v0.2.0
1111
github.com/hashicorp/golang-lru v1.0.2
12-
github.com/ipfs/boxo v0.31.0
12+
github.com/ipfs/boxo v0.33.1
1313
github.com/ipfs/go-cid v0.5.0
1414
github.com/ipfs/go-datastore v0.8.2
1515
github.com/ipfs/go-detect-race v0.0.1
16-
github.com/ipfs/go-log/v2 v2.6.0
16+
github.com/ipfs/go-log/v2 v2.8.0
1717
github.com/ipfs/go-test v0.2.2
1818
github.com/libp2p/go-libp2p v0.43.0
19-
github.com/libp2p/go-libp2p-kbucket v0.7.1-0.20250718125122-f77e735b68e8
19+
github.com/libp2p/go-libp2p-kbucket v0.8.0
2020
github.com/libp2p/go-libp2p-record v0.3.1
2121
github.com/libp2p/go-libp2p-routing-helpers v0.7.5
2222
github.com/libp2p/go-libp2p-testing v0.12.0
2323
github.com/libp2p/go-libp2p-xor v0.1.0
2424
github.com/libp2p/go-msgio v0.3.0
2525
github.com/libp2p/go-netroute v0.2.2
2626
github.com/multiformats/go-base32 v0.1.0
27-
github.com/multiformats/go-multiaddr v0.16.0
27+
github.com/multiformats/go-multiaddr v0.16.1
2828
github.com/multiformats/go-multibase v0.2.0
2929
github.com/multiformats/go-multihash v0.2.3
3030
github.com/multiformats/go-multistream v0.6.1
3131
github.com/probe-lab/go-libdht v0.2.1
3232
github.com/stretchr/testify v1.10.0
3333
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1
34-
go.opentelemetry.io/otel v1.35.0
35-
go.opentelemetry.io/otel/metric v1.35.0
36-
go.opentelemetry.io/otel/trace v1.35.0
34+
go.opentelemetry.io/otel v1.37.0
35+
go.opentelemetry.io/otel/metric v1.37.0
36+
go.opentelemetry.io/otel/trace v1.37.0
3737
go.uber.org/multierr v1.11.0
3838
go.uber.org/zap v1.27.0
3939
gonum.org/v1/gonum v0.16.0
40-
google.golang.org/protobuf v1.36.6
40+
google.golang.org/protobuf v1.36.7
4141
)
4242

4343
require (
@@ -50,34 +50,34 @@ require (
5050
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
5151
github.com/flynn/noise v1.1.0 // indirect
5252
github.com/francoispqt/gojay v1.2.13 // indirect
53-
github.com/go-logr/logr v1.4.2 // indirect
53+
github.com/go-logr/logr v1.4.3 // indirect
5454
github.com/go-logr/stdr v1.2.2 // indirect
5555
github.com/gorilla/websocket v1.5.3 // indirect
5656
github.com/huin/goupnp v1.3.0 // indirect
57-
github.com/ipfs/go-block-format v0.2.1 // indirect
57+
github.com/ipfs/go-block-format v0.2.2 // indirect
5858
github.com/ipld/go-ipld-prime v0.21.0 // indirect
5959
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
6060
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
6161
github.com/klauspost/compress v1.18.0 // indirect
62-
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
62+
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
6363
github.com/koron/go-ssdp v0.0.6 // indirect
6464
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
6565
github.com/libp2p/go-cidranger v1.1.0 // indirect
66-
github.com/libp2p/go-flow-metrics v0.2.0 // indirect
66+
github.com/libp2p/go-flow-metrics v0.3.0 // indirect
6767
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
6868
github.com/libp2p/go-reuseport v0.4.0 // indirect
6969
github.com/libp2p/go-yamux/v5 v5.0.1 // indirect
7070
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
7171
github.com/mattn/go-isatty v0.0.20 // indirect
72-
github.com/miekg/dns v1.1.66 // indirect
72+
github.com/miekg/dns v1.1.68 // indirect
7373
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
7474
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
7575
github.com/minio/sha256-simd v1.0.1 // indirect
7676
github.com/mr-tron/base58 v1.2.0 // indirect
7777
github.com/multiformats/go-base36 v0.2.0 // indirect
7878
github.com/multiformats/go-multiaddr-dns v0.4.1 // indirect
7979
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
80-
github.com/multiformats/go-multicodec v0.9.1 // indirect
80+
github.com/multiformats/go-multicodec v0.9.2 // indirect
8181
github.com/multiformats/go-varint v0.0.7 // indirect
8282
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
8383
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
@@ -102,10 +102,10 @@ require (
102102
github.com/pion/webrtc/v4 v4.1.2 // indirect
103103
github.com/pmezard/go-difflib v1.0.0 // indirect
104104
github.com/polydawn/refmt v0.89.0 // indirect
105-
github.com/prometheus/client_golang v1.22.0 // indirect
105+
github.com/prometheus/client_golang v1.23.0 // indirect
106106
github.com/prometheus/client_model v0.6.2 // indirect
107-
github.com/prometheus/common v0.64.0 // indirect
108-
github.com/prometheus/procfs v0.16.1 // indirect
107+
github.com/prometheus/common v0.65.0 // indirect
108+
github.com/prometheus/procfs v0.17.0 // indirect
109109
github.com/quic-go/qpack v0.5.1 // indirect
110110
github.com/quic-go/quic-go v0.54.0 // indirect
111111
github.com/quic-go/webtransport-go v0.9.0 // indirect
@@ -115,15 +115,15 @@ require (
115115
go.uber.org/dig v1.19.0 // indirect
116116
go.uber.org/fx v1.24.0 // indirect
117117
go.uber.org/mock v0.5.2 // indirect
118-
golang.org/x/crypto v0.39.0 // indirect
119-
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
120-
golang.org/x/mod v0.25.0 // indirect
121-
golang.org/x/net v0.41.0 // indirect
122-
golang.org/x/sync v0.15.0 // indirect
123-
golang.org/x/sys v0.33.0 // indirect
124-
golang.org/x/text v0.26.0 // indirect
118+
golang.org/x/crypto v0.41.0 // indirect
119+
golang.org/x/exp v0.0.0-20250811191247-51f88131bc50 // indirect
120+
golang.org/x/mod v0.27.0 // indirect
121+
golang.org/x/net v0.43.0 // indirect
122+
golang.org/x/sync v0.16.0 // indirect
123+
golang.org/x/sys v0.35.0 // indirect
124+
golang.org/x/text v0.28.0 // indirect
125125
golang.org/x/time v0.12.0 // indirect
126-
golang.org/x/tools v0.34.0 // indirect
126+
golang.org/x/tools v0.36.0 // indirect
127127
gopkg.in/yaml.v3 v3.0.1 // indirect
128128
lukechampine.com/blake3 v1.4.1 // indirect
129129
)

0 commit comments

Comments
 (0)