Skip to content

Commit

Permalink
Log message validation and handle durations
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikluhn committed Jun 11, 2024
1 parent c86a09a commit d8b6751
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion rolling-shutter/p2p/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package p2p
import (
"context"
"reflect"
"time"

"github.com/hashicorp/go-multierror"
pubsub "github.com/libp2p/go-libp2p-pubsub"
Expand Down Expand Up @@ -30,6 +31,15 @@ type (

func (r *ValidatorRegistry) GetCombinedValidator(topic string) pubsub.ValidatorEx {
validate := func(ctx context.Context, sender peer.ID, message *pubsub.Message) pubsub.ValidationResult {
startTime := time.Now()
defer func() {
elapsedTime := time.Since(startTime)
log.Debug().
Str("topic", topic).
Str("duration", elapsedTime.String()).
Msg("validated message")
}()

ignored := false
for _, valFunc := range (*r)[topic] {
res := valFunc(ctx, sender, message)
Expand Down Expand Up @@ -284,11 +294,21 @@ var (
)

func (m *P2PMessaging) Handle(ctx context.Context, msg p2pmsg.Message) ([]p2pmsg.Message, error) {
startTime := time.Now()
messageName := proto.MessageName(msg)
defer func() {
elapsedTime := time.Since(startTime)
log.Debug().
Str("message-name", string(messageName)).
Str("duration", elapsedTime.String()).
Msg("handled message")
}()

var (
msgsOut []p2pmsg.Message
errResult error
)
fns, exists := m.handlerRegistry[proto.MessageName(msg)]
fns, exists := m.handlerRegistry[messageName]
if !exists {
return nil, ErrNoMessageHandler
}
Expand Down

0 comments on commit d8b6751

Please sign in to comment.