p2p

package
v1.6.0-rc0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2021 License: Apache-2.0 Imports: 24 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrAgentNotStarted is the error returned when p2p agent has not been started
	ErrAgentNotStarted = errors.New("p2p agent has not been started")
)

Functions

func WitContext

func WitContext(ctx context.Context, p2pCtx Context) context.Context

WitContext add Agent context into context.

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, genesisHash hash.Hash256, broadcastHandler HandleBroadcastInbound, unicastHandler HandleUnicastInboundAsync) *Agent

NewAgent instantiates a local P2P agent instance

func (*Agent) BroadcastOutbound

func (p *Agent) BroadcastOutbound(ctx context.Context, msg proto.Message) (err error)

BroadcastOutbound sends a broadcast message to the whole network

func (*Agent) Info

func (p *Agent) Info() (peerstore.PeerInfo, error)

Info returns agents' peer info.

func (*Agent) Neighbors

func (p *Agent) Neighbors(ctx context.Context) ([]peerstore.PeerInfo, error)

Neighbors returns the neighbors' peer info

func (*Agent) QosMetrics added in v1.3.0

func (p *Agent) QosMetrics() *Qos

QosMetrics returns the Qos metrics

func (*Agent) Self

func (p *Agent) Self() ([]multiaddr.Multiaddr, error)

Self returns the self network address

func (*Agent) Start

func (p *Agent) Start(ctx context.Context) error

Start connects into P2P network

func (*Agent) Stop

func (p *Agent) Stop(ctx context.Context) error

Stop disconnects from P2P network

func (*Agent) UnicastOutbound

func (p *Agent) UnicastOutbound(ctx context.Context, peer peerstore.PeerInfo, msg proto.Message) (err error)

UnicastOutbound sends a unicast message to the given address

type BlockList added in v1.1.1

type BlockList struct {
	// contains filtered or unexported fields
}

BlockList is the struct for blocklist

func NewBlockList added in v1.1.1

func NewBlockList(size int) *BlockList

NewBlockList creates an instance of blocklist

func (*BlockList) Add added in v1.1.1

func (bl *BlockList) Add(name string, t time.Time)

Add tries to add the name to blocklist

func (*BlockList) Blocked added in v1.1.1

func (bl *BlockList) Blocked(name string, t time.Time) bool

Blocked returns true if the name is blocked

func (*BlockList) Remove added in v1.1.1

func (bl *BlockList) Remove(name string)

Remove takes name off the blocklist

type Context

type Context struct {
	ChainID uint32
}

Context provides the auxiliary information Agent network operations

func GetContext

func GetContext(ctx context.Context) (Context, bool)

GetContext gets Agent context

type HandleBroadcastInbound

type HandleBroadcastInbound func(context.Context, uint32, string, proto.Message)

HandleBroadcastInbound handles broadcast message when agent listens it from the network

type HandleUnicastInboundAsync

type HandleUnicastInboundAsync func(context.Context, uint32, peerstore.PeerInfo, proto.Message)

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 NewQoS added in v1.3.0

func NewQoS(now time.Time, timeout time.Duration) *Qos

NewQoS returns the Qos metrics

func (*Qos) BroadcastRecvTotal added in v1.3.0

func (q *Qos) BroadcastRecvTotal() uint64

BroadcastRecvTotal returns the total amount of broadcast received

func (*Qos) BroadcastSendSuccessRate added in v1.3.0

func (q *Qos) BroadcastSendSuccessRate() float64

BroadcastSendSuccessRate returns the broadcast send success rate

func (*Qos) BroadcastSendTotal added in v1.3.0

func (q *Qos) BroadcastSendTotal() uint64

BroadcastSendTotal returns the total amount of broadcast sent

func (*Qos) UnicastRecvTotal added in v1.3.0

func (q *Qos) UnicastRecvTotal(peername string) (uint64, bool)

UnicastRecvTotal returns the total amount of unicast received from peer

func (*Qos) UnicastSendSuccessRate added in v1.3.0

func (q *Qos) UnicastSendSuccessRate(peername string) (float64, bool)

UnicastSendSuccessRate returns the unicast send success rate

func (*Qos) UnicastSendTotal added in v1.3.0

func (q *Qos) UnicastSendTotal(peername string) (uint64, bool)

UnicastSendTotal returns the total amount of unicast sent to peer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL