Documentation ¶
Index ¶
- Variables
- type Agent
- func (p *Agent) BroadcastOutbound(ctx context.Context, msg proto.Message) (err error)
- func (p *Agent) Info() (peer.AddrInfo, error)
- func (p *Agent) Neighbors(ctx context.Context) ([]peer.AddrInfo, error)
- func (p *Agent) QosMetrics() *Qos
- func (p *Agent) Self() ([]multiaddr.Multiaddr, error)
- func (p *Agent) Start(ctx context.Context) error
- func (p *Agent) Stop(ctx context.Context) error
- func (p *Agent) UnicastOutbound(_ context.Context, peer peer.AddrInfo, msg proto.Message) (err error)
- type HandleBroadcastInbound
- type HandleUnicastInboundAsync
- type Network
- 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)
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Network{ Host: "0.0.0.0", Port: 4689, ExternalHost: "", ExternalPort: 4689, BootstrapNodes: []string{}, MasterKey: "", RateLimit: p2p.DefaultRatelimitConfig, ReconnectInterval: 150 * time.Second, EnableRateLimit: true, PrivateNetworkPSK: "", }
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 struct {
// contains filtered or unexported fields
}
Agent is the agent to help the blockchain node connect into the P2P networks and send/receive messages
func NewAgent ¶
func NewAgent(cfg Network, chainID uint32, genesisHash hash.Hash256, broadcastHandler HandleBroadcastInbound, unicastHandler HandleUnicastInboundAsync) *Agent
NewAgent instantiates a local P2P agent instance
func (*Agent) BroadcastOutbound ¶
BroadcastOutbound sends a broadcast message to the whole network
func (*Agent) QosMetrics ¶ added in v1.3.0
QosMetrics returns the Qos metrics
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 Network ¶ added in v1.3.0
type Network 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"` }
Network is the config of p2p
type Qos ¶ added in v1.3.0
type Qos struct {
// contains filtered or unexported fields
}
Qos metrics
func (*Qos) BroadcastRecvTotal ¶ added in v1.3.0
BroadcastRecvTotal returns the total amount of broadcast received
func (*Qos) BroadcastSendSuccessRate ¶ added in v1.3.0
BroadcastSendSuccessRate returns the broadcast send success rate
func (*Qos) BroadcastSendTotal ¶ added in v1.3.0
BroadcastSendTotal returns the total amount of broadcast sent
func (*Qos) UnicastRecvTotal ¶ added in v1.3.0
UnicastRecvTotal returns the total amount of unicast received from peer
func (*Qos) UnicastSendSuccessRate ¶ added in v1.3.0
UnicastSendSuccessRate returns the unicast send success rate