manualpeering

package
Version: v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: Apache-2.0, BSD-2-Clause Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionDirection added in v0.6.2

type ConnectionDirection string

ConnectionDirection is an enum for the type of connection between local peer and the other peer in the gossip layer.

const (
	// ConnDirectionOutbound means that the local peer dials for the connection in the gossip layer.
	ConnDirectionOutbound ConnectionDirection = "outbound"
	// ConnDirectionInbound means that the local peer accepts for the connection in the gossip layer.
	ConnDirectionInbound ConnectionDirection = "inbound"
)

type ConnectionStatus added in v0.6.2

type ConnectionStatus string

ConnectionStatus is an enum for the peer connection status in the gossip layer.

const (
	// ConnStatusDisconnected means that there is no real connection established in the gossip layer for that peer.
	ConnStatusDisconnected ConnectionStatus = "disconnected"
	// ConnStatusConnected means that there is a real connection established in the gossip layer for that peer.
	ConnStatusConnected ConnectionStatus = "connected"
)

type GetPeersConfig added in v0.6.4

type GetPeersConfig struct {
	// If true, GetPeers returns peers that have actual connection established in the gossip layer.
	OnlyConnected bool `json:"onlyConnected"`
}

GetPeersConfig holds optional parameters for the GetPeers method.

func BuildGetPeersConfig added in v0.6.4

func BuildGetPeersConfig(opts []GetPeersOption) *GetPeersConfig

BuildGetPeersConfig builds GetPeersConfig struct from a list of options.

func (*GetPeersConfig) ToOptions added in v0.6.4

func (c *GetPeersConfig) ToOptions() (opts []GetPeersOption)

ToOptions translates config struct to a list of corresponding options.

type GetPeersOption added in v0.6.4

type GetPeersOption func(conf *GetPeersConfig)

GetPeersOption defines a single option for GetPeers method.

func WithOnlyConnectedPeers added in v0.6.2

func WithOnlyConnectedPeers() GetPeersOption

WithOnlyConnectedPeers returns a GetPeersOption that sets OnlyConnected field to true.

type KnownPeer added in v0.6.2

type KnownPeer struct {
	PublicKey     ed25519.PublicKey   `json:"publicKey"`
	Address       string              `json:"address"`
	ConnDirection ConnectionDirection `json:"connectionDirection"`
	ConnStatus    ConnectionStatus    `json:"connectionStatus"`
}

KnownPeer defines a peer record in the manualpeering layer.

type KnownPeerToAdd added in v0.6.4

type KnownPeerToAdd struct {
	PublicKey ed25519.PublicKey `json:"publicKey"`
	Address   string            `json:"address"`
}

KnownPeerToAdd defines a type that is used in .AddPeer() method.

type Manager

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

Manager is the core entity in the manualpeering package. It holds a list of known peers and constantly provisions it to the gossip layer. Its job is to keep in sync the list of known peers and the list of current manual neighbors connected in the gossip layer. If a new peer is added to known peers, manager will forward it to gossip and make sure it establishes a connection. And vice versa, if a peer is being removed from the list of known peers, manager will make sure gossip drops that connection. Manager also subscribes to the gossip events and in case the connection with a manual peer fails it will reconnect.

func NewManager

func NewManager(gm *gossip.Manager, local *peer.Local, log *logger.Logger) *Manager

NewManager initializes a new Manager instance.

func (*Manager) AddPeer

func (m *Manager) AddPeer(peers ...*KnownPeerToAdd) error

AddPeer adds multiple peers to the list of known peers.

func (*Manager) GetPeers added in v0.6.4

func (m *Manager) GetPeers(opts ...GetPeersOption) []*KnownPeer

GetPeers returns the list of known peers.

func (*Manager) RemovePeer

func (m *Manager) RemovePeer(keys ...ed25519.PublicKey) error

RemovePeer removes multiple peers from the list of known peers.

func (*Manager) Start

func (m *Manager) Start()

Start subscribes to the gossip layer events and starts internal background workers. Calling multiple times has no effect.

func (*Manager) Stop

func (m *Manager) Stop() (err error)

Stop terminates internal background workers. Calling multiple times has no effect.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL