@@ -3,6 +3,7 @@ package p2p
33import (
44 "context"
55 "reflect"
6+ "time"
67
78 "github.com/hashicorp/go-multierror"
89 pubsub "github.com/libp2p/go-libp2p-pubsub"
@@ -30,6 +31,15 @@ type (
3031
3132func (r * ValidatorRegistry ) GetCombinedValidator (topic string ) pubsub.ValidatorEx {
3233 validate := func (ctx context.Context , sender peer.ID , message * pubsub.Message ) pubsub.ValidationResult {
34+ startTime := time .Now ()
35+ defer func () {
36+ elapsedTime := time .Since (startTime )
37+ log .Debug ().
38+ Str ("topic" , topic ).
39+ Dur ("duration" , elapsedTime ).
40+ Msg ("validated message" )
41+ }()
42+
3343 ignored := false
3444 for _ , valFunc := range (* r )[topic ] {
3545 res := valFunc (ctx , sender , message )
@@ -284,11 +294,21 @@ var (
284294)
285295
286296func (m * P2PMessaging ) Handle (ctx context.Context , msg p2pmsg.Message ) ([]p2pmsg.Message , error ) {
297+ startTime := time .Now ()
298+ messageName := proto .MessageName (msg )
299+ defer func () {
300+ elapsedTime := time .Since (startTime )
301+ log .Debug ().
302+ Str ("message-name" , string (messageName )).
303+ Dur ("duration" , elapsedTime ).
304+ Msg ("handled message" )
305+ }()
306+
287307 var (
288308 msgsOut []p2pmsg.Message
289309 errResult error
290310 )
291- fns , exists := m .handlerRegistry [proto . MessageName ( msg ) ]
311+ fns , exists := m .handlerRegistry [messageName ]
292312 if ! exists {
293313 return nil , ErrNoMessageHandler
294314 }
0 commit comments