1
1
package crawler
2
2
3
3
import (
4
+ "slices"
4
5
"time"
5
6
6
7
"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"
7
10
"github.com/libp2p/go-libp2p/core/protocol"
8
11
)
9
12
10
13
// Option DHT Crawler option type.
11
14
type Option func (* options ) error
12
15
13
16
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
18
22
}
19
23
20
24
// defaults are the default crawler options. This option will be automatically
@@ -31,7 +35,7 @@ var defaults = func(o *options) error {
31
35
// WithProtocols defines the ordered set of protocols the crawler will use to talk to other nodes
32
36
func WithProtocols (protocols []protocol.ID ) Option {
33
37
return func (o * options ) error {
34
- o .protocols = append ([]protocol. ID {}, protocols ... )
38
+ o .protocols = slices . Clone ( protocols )
35
39
return nil
36
40
}
37
41
}
@@ -59,3 +63,12 @@ func WithConnectTimeout(timeout time.Duration) Option {
59
63
return nil
60
64
}
61
65
}
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
+ }
0 commit comments