github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/inspector/validation/inspect_message_request.go (about)

     1  package validation
     2  
     3  import (
     4  	"fmt"
     5  
     6  	pubsub "github.com/libp2p/go-libp2p-pubsub"
     7  	"github.com/libp2p/go-libp2p/core/peer"
     8  
     9  	"github.com/onflow/flow-go/network/p2p/inspector/internal"
    10  )
    11  
    12  // InspectRPCRequest represents a short digest of an RPC control message. It is used for further message inspection by component workers.
    13  type InspectRPCRequest struct {
    14  	// Nonce adds random value so that when msg req is stored on hero store a unique ID can be created from the struct fields.
    15  	Nonce []byte
    16  	// Peer sender of the message.
    17  	Peer peer.ID
    18  	rpc  *pubsub.RPC
    19  }
    20  
    21  // NewInspectRPCRequest returns a new *InspectRPCRequest.
    22  func NewInspectRPCRequest(from peer.ID, rpc *pubsub.RPC) (*InspectRPCRequest, error) {
    23  	nonce, err := internal.Nonce()
    24  	if err != nil {
    25  		return nil, fmt.Errorf("failed to get inspect message request nonce: %w", err)
    26  	}
    27  	return &InspectRPCRequest{Nonce: nonce, Peer: from, rpc: rpc}, nil
    28  }