networking

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BootstrapPeers

func BootstrapPeers() []multiaddr.Multiaddr

BootstrapPeers - Returns addresses of bootstrap nodes, if none are given using default ones

func ConnectToBootstraps

func ConnectToBootstraps(ctx context.Context, _host host.Host) (int, int)

ConnectToBootstraps - Attempting to connect to bootstrap nodes concurrently Waiting for all of them to complete, after that returning back how many attempts went successful among total attempts, respectively

func CreateHost

func CreateHost(ctx context.Context) (host.Host, error)

CreateHost - Creates a libp2p host, to be used for communicating with other `harmony` peers

func HandleStream

func HandleStream(stream network.Stream)

HandleStream - Attepts new stream & handles it through out its life time

func InitMemPool

func InitMemPool(pool *data.MemPool) error

InitMemPool - Initializing mempool handle, in this module so that it can be used updating local mempool state, when new deserialisable tx chunk is received from any peer, over p2p network

func InitRedisClient

func InitRedisClient(client *redis.Client) error

InitRedisClient - Initializing redis client handle, so that all subscriptions can be done using this client

func Listen

func Listen(_host host.Host)

Listen - Handle incoming connection of other harmony peer for certain supported protocol(s)

func LookForPeers

func LookForPeers(ctx context.Context, _host host.Host, _dht *dht.IpfsDHT, routing *discovery.RoutingDiscovery, comm chan struct{})

LookForPeers - Asks this node to start looking for peers, does for some time & attempts to connect to them, while setting up stream for further chit-chat

func ReadFrom

func ReadFrom(ctx context.Context, cancel context.CancelFunc, rw *bufio.ReadWriter, peerId string, remote multiaddr.Multiaddr)

ReadFrom - Read from stream & attempt to deserialize length prefixed tx data received from peer, which will be acted upon

func SetUpPeerDiscovery

func SetUpPeerDiscovery(ctx context.Context, _host host.Host, comm chan struct{})

SetUpPeerDiscovery - Setting up peer discovery mechanism, by connecting to bootstrap nodes first, then advertises self with rendezvous & attempts to discover peers with same rendezvous, which are to be eventually connected with

func Setup

func Setup(ctx context.Context, comm chan struct{}) error

Setup - Bootstraps `harmony`'s p2p networking stack

func ShowHost

func ShowHost(_host host.Host)

ShowHost - Showing on which multi addresses given host is listening on

func WriteTo

func WriteTo(ctx context.Context, cancel context.CancelFunc, rw *bufio.ReadWriter, peerId string, remote multiaddr.Multiaddr)

WriteTo - Write to mempool changes into stream i.e. connection with some remote peer

Types

type ConnectionManager

type ConnectionManager struct {
	Peers           map[peer.ID]bool
	NewPeerChan     chan peer.ID
	DroppedPeerChan chan peer.ID
	IsConnectedChan chan IsConnected
}

ConnectionManager - All connected peers to be kept track of, so that we don't attempt to reconnect to same peer again

func NewConnectionManager

func NewConnectionManager() *ConnectionManager

func (*ConnectionManager) Added

func (c *ConnectionManager) Added(peerId peer.ID)

Added - When new connection is established

func (*ConnectionManager) Dropped

func (c *ConnectionManager) Dropped(peerId peer.ID)

Dropped - When connection with some peer is dropped

func (*ConnectionManager) IsConnected

func (c *ConnectionManager) IsConnected(peerId peer.ID) bool

IsConnected - Before attempting to (re-)establish connection with peer, check whether already connected or not

func (*ConnectionManager) Start

func (c *ConnectionManager) Start(ctx context.Context)

Start - Listen for new peer we're getting connected to/ dropped

Also clean up list of dropped peers after every `n` time unit, to avoid lock contention as much as possible

type IsConnected

type IsConnected struct {
	Peer     peer.ID
	Response chan bool
}

IsConnected - Queries can be sent to connection manager by worker go routines over channel & response to be sent back to them over `response` channel

Jump to

Keyboard shortcuts

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