Skip to content

Commit 70dbacb

Browse files
optimisation
1 parent 4e3746b commit 70dbacb

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

dht_net.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ func (dht *IpfsDHT) handleNewMessage(s network.Stream) bool {
100100
metrics.ReceivedBytes.M(int64(msgLen)),
101101
)
102102

103-
dht.onRequestHook(ctx, s, req)
103+
if dht.onRequestHook != nil {
104+
dht.onRequestHook(ctx, s, req)
105+
}
104106

105107
handler := dht.handlerForMsgType(req.GetType())
106108
if handler == nil {

dht_options.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,10 @@ func WithCustomMessageSender(messageSenderBuilder func(h host.Host, protos []pro
371371
}
372372
}
373373

374-
// OnRequestHook registers a callback function that will be invoked
375-
// for every incoming DHT protocol message. Note: Ensure that the
376-
// callback executes efficiently, as it can block the entire message handler.
374+
// OnRequestHook registers a callback function that will be invoked for every
375+
// incoming DHT protocol message.
376+
// Note: Ensure that the callback executes efficiently, as it will block the
377+
// entire message handler.
377378
func OnRequestHook(f func(ctx context.Context, s network.Stream, req pb.Message)) Option {
378379
return func(c *dhtcfg.Config) error {
379380
c.OnRequestHook = f

internal/config/config.go

-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ var Defaults = func(o *Config) error {
137137
// MAGIC: It makes sense to set it to a multiple of OptProvReturnRatio * BucketSize. We chose a multiple of 4.
138138
o.OptimisticProvideJobsPoolSize = 60
139139

140-
o.OnRequestHook = func(ctx context.Context, s network.Stream, req pb.Message) {}
141-
142140
return nil
143141
}
144142

0 commit comments

Comments
 (0)