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

     1  package unicast
     2  
     3  import (
     4  	"github.com/libp2p/go-libp2p/core/peer"
     5  )
     6  
     7  // ConfigCache is a thread-safe cache for dial configs. It is used by the unicast service to store
     8  // the dial configs for peers.
     9  type ConfigCache interface {
    10  	// GetWithInit returns the dial config for the given peer id. If the config does not exist, it creates a new config
    11  	// using the factory function and stores it in the cache.
    12  	// Args:
    13  	// - peerID: the peer id of the dial config.
    14  	// Returns:
    15  	//   - *Config, the dial config for the given peer id.
    16  	//   - error if the factory function returns an error. Any error should be treated as an irrecoverable error and indicates a bug.
    17  	GetWithInit(peerID peer.ID) (*Config, error)
    18  
    19  	// Adjust adjusts the dial config for the given peer id using the given adjustFunc.
    20  	// It returns an error if the adjustFunc returns an error.
    21  	// Args:
    22  	// - peerID: the peer id of the dial config.
    23  	// - adjustFunc: the function that adjusts the dial config.
    24  	// Returns:
    25  	//   - error if the adjustFunc returns an error. Any error should be treated as an irrecoverable error and indicates a bug.
    26  	AdjustWithInit(peerID peer.ID, adjustFunc UnicastConfigAdjustFunc) (*Config, error)
    27  
    28  	// Size returns the number of dial configs in the cache.
    29  	Size() uint
    30  }