Skip to content

Commit

Permalink
optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel committed Jan 15, 2025
1 parent 4e3746b commit 70dbacb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion dht_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func (dht *IpfsDHT) handleNewMessage(s network.Stream) bool {
metrics.ReceivedBytes.M(int64(msgLen)),
)

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

Check warning on line 105 in dht_net.go

View check run for this annotation

Codecov / codecov/patch

dht_net.go#L104-L105

Added lines #L104 - L105 were not covered by tests

handler := dht.handlerForMsgType(req.GetType())
if handler == nil {
Expand Down
7 changes: 4 additions & 3 deletions dht_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,10 @@ func WithCustomMessageSender(messageSenderBuilder func(h host.Host, protos []pro
}
}

// OnRequestHook registers a callback function that will be invoked
// for every incoming DHT protocol message. Note: Ensure that the
// callback executes efficiently, as it can block the entire message handler.
// OnRequestHook registers a callback function that will be invoked for every
// 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 {
return func(c *dhtcfg.Config) error {
c.OnRequestHook = f
Expand Down
2 changes: 0 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ var Defaults = func(o *Config) error {
// MAGIC: It makes sense to set it to a multiple of OptProvReturnRatio * BucketSize. We chose a multiple of 4.
o.OptimisticProvideJobsPoolSize = 60

o.OnRequestHook = func(ctx context.Context, s network.Stream, req pb.Message) {}

return nil
}

Expand Down

0 comments on commit 70dbacb

Please sign in to comment.