github.com/onflow/flow-go@v0.33.17/network/p2p/builder/inspector/aggregate.go (about)

     1  package inspector
     2  
     3  import (
     4  	"github.com/hashicorp/go-multierror"
     5  	pubsub "github.com/libp2p/go-libp2p-pubsub"
     6  	"github.com/libp2p/go-libp2p/core/peer"
     7  
     8  	"github.com/onflow/flow-go/network/p2p"
     9  )
    10  
    11  // AggregateRPCInspector gossip sub RPC inspector that combines multiple RPC inspectors into a single inspector. Each
    12  // individual inspector will be invoked synchronously.
    13  type AggregateRPCInspector struct {
    14  	inspectors []p2p.GossipSubRPCInspector
    15  }
    16  
    17  // NewAggregateRPCInspector returns new aggregate RPC inspector.
    18  func NewAggregateRPCInspector(inspectors ...p2p.GossipSubRPCInspector) *AggregateRPCInspector {
    19  	return &AggregateRPCInspector{
    20  		inspectors: inspectors,
    21  	}
    22  }
    23  
    24  // Inspect func with the p2p.GossipSubAppSpecificRpcInspector func signature that will invoke all the configured inspectors.
    25  func (a *AggregateRPCInspector) Inspect(peerID peer.ID, rpc *pubsub.RPC) error {
    26  	var errs *multierror.Error
    27  	for _, inspector := range a.inspectors {
    28  		err := inspector.Inspect(peerID, rpc)
    29  		if err != nil {
    30  			errs = multierror.Append(errs, err)
    31  		}
    32  	}
    33  	return errs.ErrorOrNil()
    34  }
    35  
    36  func (a *AggregateRPCInspector) Inspectors() []p2p.GossipSubRPCInspector {
    37  	return a.inspectors
    38  }