 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Variables
- type Agent
- type Config
- type HandleBroadcastInbound
- type HandleUnicastInboundAsync
- type Qos
- func (q *Qos) BroadcastRecvTotal() uint64
- func (q *Qos) BroadcastSendSuccessRate() float64
- func (q *Qos) BroadcastSendTotal() uint64
- func (q *Qos) UnicastRecvTotal(peername string) (uint64, bool)
- func (q *Qos) UnicastSendSuccessRate(peername string) (float64, bool)
- func (q *Qos) UnicastSendTotal(peername string) (uint64, bool)
 
- type ValidateBroadcastInbound
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{ Host: "0.0.0.0", Port: 4689, ExternalHost: "", ExternalPort: 4689, BootstrapNodes: []string{}, MasterKey: "", RateLimit: p2p.DefaultRatelimitConfig, ReconnectInterval: 150 * time.Second, EnableRateLimit: true, PrivateNetworkPSK: "", MaxPeers: 30, MaxMessageSize: p2p.DefaultConfig.MaxMessageSize, RpcMsgCacheSize: 10000, RpcDedupCacheSize: 40000, }
DefaultConfig is the default config of p2p
var ( // ErrAgentNotStarted is the error returned when p2p agent has not been started ErrAgentNotStarted = errors.New("p2p agent has not been started") )
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface {
	lifecycle.StartStopper
	nodestats.StatsReporter
	// BroadcastOutbound sends a broadcast message to the whole network
	BroadcastOutbound(ctx context.Context, msg proto.Message) (err error)
	// UnicastOutbound sends a unicast message to the given address
	UnicastOutbound(_ context.Context, peer peer.AddrInfo, msg proto.Message) (err error)
	// Info returns agents' peer info.
	Info() (peer.AddrInfo, error)
	// Self returns the self network address
	Self() ([]multiaddr.Multiaddr, error)
	// ConnectedPeers returns the connected peers' info
	ConnectedPeers() ([]peer.AddrInfo, error)
	// BlockPeer blocks the peer in p2p layer
	BlockPeer(string)
}
    Agent is the agent to help the blockchain node connect into the P2P networks and send/receive messages
func NewAgent ¶
func NewAgent( cfg Config, chainID uint32, genesisHash hash.Hash256, validateBroadcastInbound ValidateBroadcastInbound, broadcastHandler HandleBroadcastInbound, unicastHandler HandleUnicastInboundAsync, ) Agent
NewAgent instantiates a local P2P agent instance
type Config ¶
type Config struct {
	Host           string   `yaml:"host"`
	Port           int      `yaml:"port"`
	ExternalHost   string   `yaml:"externalHost"`
	ExternalPort   int      `yaml:"externalPort"`
	BootstrapNodes []string `yaml:"bootstrapNodes"`
	MasterKey      string   `yaml:"masterKey"` // master key will be PrivateKey if not set.
	// RelayType is the type of P2P network relay. By default, the value is empty, meaning disabled. Two relay types
	// are supported: active, nat.
	RelayType         string              `yaml:"relayType"`
	ReconnectInterval time.Duration       `yaml:"reconnectInterval"`
	RateLimit         p2p.RateLimitConfig `yaml:"rateLimit"`
	EnableRateLimit   bool                `yaml:"enableRateLimit"`
	PrivateNetworkPSK string              `yaml:"privateNetworkPSK"`
	MaxPeers          int                 `yaml:"maxPeers"`
	MaxMessageSize    int                 `yaml:"maxMessageSize"`
	RpcMsgCacheSize   int                 `yaml:"rpcMsgCacheSize"`
	RpcDedupCacheSize int                 `yaml:"rpcDedupCacheSize"`
}
    Config is the config of p2p
type HandleBroadcastInbound ¶
HandleBroadcastInbound handles broadcast message when agent listens it from the network
type HandleUnicastInboundAsync ¶
HandleUnicastInboundAsync handles unicast message when agent listens it from the network
type Qos ¶
type Qos struct {
	// contains filtered or unexported fields
}
    Qos metrics
func (*Qos) BroadcastRecvTotal ¶
BroadcastRecvTotal returns the total amount of broadcast received
func (*Qos) BroadcastSendSuccessRate ¶
BroadcastSendSuccessRate returns the broadcast send success rate
func (*Qos) BroadcastSendTotal ¶
BroadcastSendTotal returns the total amount of broadcast sent
func (*Qos) UnicastRecvTotal ¶
UnicastRecvTotal returns the total amount of unicast received from peer
func (*Qos) UnicastSendSuccessRate ¶
UnicastSendSuccessRate returns the unicast send success rate