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

fix: don't copy message to OnRequestHook #1012

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ import (
"go.uber.org/zap"
)

const tracer = tracing.Tracer("go-libp2p-kad-dht")
const dhtName = "IpfsDHT"
const (
tracer = tracing.Tracer("go-libp2p-kad-dht")
dhtName = "IpfsDHT"
)

var (
logger = logging.Logger("dht")
Expand Down Expand Up @@ -164,7 +166,7 @@ type IpfsDHT struct {
// Mostly used to filter out localhost and local addresses.
addrFilter func([]ma.Multiaddr) []ma.Multiaddr

onRequestHook func(ctx context.Context, s network.Stream, req pb.Message)
onRequestHook func(ctx context.Context, s network.Stream, req *pb.Message)
}

// Assert that IPFS assumptions about interfaces aren't broken. These aren't a
Expand Down Expand Up @@ -420,7 +422,6 @@ func makeRoutingTable(dht *IpfsDHT, cfg dhtcfg.Config, maxLastSuccessfulOutbound
df, err := peerdiversity.NewFilter(dht.rtPeerDiversityFilter, "rt/diversity", func(p peer.ID) int {
return kb.CommonPrefixLen(dht.selfKey, kb.ConvertPeerID(p))
})

if err != nil {
return nil, fmt.Errorf("failed to construct peer diversity filter: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dht_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
)

if dht.onRequestHook != nil {
dht.onRequestHook(ctx, s, req)
dht.onRequestHook(ctx, s, &req)

Check warning on line 104 in dht_net.go

View check run for this annotation

Codecov / codecov/patch

dht_net.go#L104

Added line #L104 was not covered by tests
}

handler := dht.handlerForMsgType(req.GetType())
Expand Down
2 changes: 1 addition & 1 deletion dht_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
// incoming DHT protocol message.
// Note: Ensure that the callback executes efficiently, as it will block the
// entire message handler.
func OnRequestHook(f func(ctx context.Context, s network.Stream, req pb.Message)) Option {
func OnRequestHook(f func(ctx context.Context, s network.Stream, req *pb.Message)) Option {

Check warning on line 378 in dht_options.go

View check run for this annotation

Codecov / codecov/patch

dht_options.go#L378

Added line #L378 was not covered by tests
return func(c *dhtcfg.Config) error {
c.OnRequestHook = f
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Config struct {

BootstrapPeers func() []peer.AddrInfo
AddressFilter func([]ma.Multiaddr) []ma.Multiaddr
OnRequestHook func(ctx context.Context, s network.Stream, req pb.Message)
OnRequestHook func(ctx context.Context, s network.Stream, req *pb.Message)

// test specific Config options
DisableFixLowPeers bool
Expand Down
Loading