Skip to content

Commit

Permalink
add new option to set custom
Browse files Browse the repository at this point in the history
msgSenderBuilder
  • Loading branch information
cortze committed Oct 2, 2024
1 parent 3989875 commit 53ef5be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dht_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"time"

dhtcfg "github.com/libp2p/go-libp2p-kad-dht/internal/config"
pb "github.com/libp2p/go-libp2p-kad-dht/pb"
"github.com/libp2p/go-libp2p-kad-dht/providers"
"github.com/libp2p/go-libp2p-kbucket/peerdiversity"
record "github.com/libp2p/go-libp2p-record"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"

Expand Down Expand Up @@ -356,3 +358,13 @@ func AddressFilter(f func([]ma.Multiaddr) []ma.Multiaddr) Option {
return nil
}
}

// --- NEW FEATURE ---
// WithCustomMessageSender configures the pb.MessageSender of the IpfsDHT to use the
// custom implementation of the pb.MessageSender
func WithCustomMessageSender(messageSenderBuilder func(h host.Host, protos []protocol.ID) pb.MessageSenderWithDisconnect) Option {
return func(c *dhtcfg.Config) error {
c.MsgSenderBuilder = messageSenderBuilder
return nil
}
}
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/ipfs/boxo/ipns"
ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
"github.com/libp2p/go-libp2p-kad-dht/internal/net"
pb "github.com/libp2p/go-libp2p-kad-dht/pb"
"github.com/libp2p/go-libp2p-kad-dht/providers"
"github.com/libp2p/go-libp2p-kbucket/peerdiversity"
record "github.com/libp2p/go-libp2p-record"
Expand Down Expand Up @@ -48,6 +50,7 @@ type Config struct {
ProviderStore providers.ProviderStore
QueryPeerFilter QueryFilterFunc
LookupCheckConcurrency int
MsgSenderBuilder func(h host.Host, protos []protocol.ID) pb.MessageSenderWithDisconnect

RoutingTable struct {
RefreshQueryTimeout time.Duration
Expand Down Expand Up @@ -114,6 +117,7 @@ var Defaults = func(o *Config) error {
o.EnableProviders = true
o.EnableValues = true
o.QueryPeerFilter = EmptyQueryFilter
o.MsgSenderBuilder = net.NewMessageSenderImpl

o.RoutingTable.LatencyTolerance = 10 * time.Second
o.RoutingTable.RefreshQueryTimeout = 10 * time.Second
Expand Down

0 comments on commit 53ef5be

Please sign in to comment.