network

package
v1.1.1-0...-7cefdf7 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBootstrapTimeout is the default timeout for bootstrapping with each peer.
	DefaultBootstrapTimeout = time.Second * 10
	// DefaultPeerThreshold is the default threshold above which bootstrapping is considered successful
	DefaultPeerThreshold = 8
)

Variables

This section is empty.

Functions

func AddrToHostPort

func AddrToHostPort(addr string) (string, uint16, error)

AddrToHostPort splits an address-colon-host string into host and port.

func CreatePeers

func CreatePeers(host string, minPort uint16, numPeers int) ([]kad.ID, []*kad.Keypair, error)

CreatePeers creates a number of peer identities starting at the minimum port number.

func RandBootstrapAddrs

func RandBootstrapAddrs(peers []kad.ID, n int) []string

RandBootstrapAddrs returns up to n random addresses from peers.

func RandPeer

func RandPeer(peers []kad.ID) kad.ID

RandPeer returns a random peer from peers.

func RunPeers

func RunPeers(peers []kad.ID, keypairs []*kad.Keypair, numBootstrapPeers int) (chan relay.Message, chan broadcast.Message)

RunPeers runs the specified peers, bootstrap them with each other, and returns two channels that aggregate all relay and broadcast messages.

Types

type Network

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

Network encapsulates the communication in a noise p2p network.

func New

func New(host string, port uint16, keys *kad.Keypair) (*Network, error)

New creates and returns a new network instance.

func (*Network) AddressFromPK

func (ntw *Network) AddressFromPK(publicKey []byte) string

AddressFromPK returns the address associated with the public key

func (*Network) Bootstrap

func (ntw *Network) Bootstrap(peerAddrs []string, timeout time.Duration, peerThreshold int) bool

Bootstrap bootstraps a network using a list of peer addresses and returns whether bootstrap finished before timeout.

func (*Network) BootstrapDefault

func (ntw *Network) BootstrapDefault(peerAddrs []string) bool

BootstrapDefault runs Bootstrap with default parameters.

func (*Network) Broadcast

func (ntw *Network) Broadcast(code byte, data []byte)

Broadcast broadcasts data to the entire p2p network.

func (*Network) GetBroadcastChan

func (ntw *Network) GetBroadcastChan() chan broadcast.Message

GetBroadcastChan returns the channel for broadcast messages.

func (*Network) GetNodeID

func (ntw *Network) GetNodeID() kad.ID

GetNodeID returns the network node's skademlia ID.

func (*Network) GetNumPeers

func (ntw *Network) GetNumPeers() int

GetNumPeers returns the number of peers the network node has.

func (*Network) GetPeerAddrs

func (ntw *Network) GetPeerAddrs() []string

GetPeerAddrs returns the peer addresses in the network node's kademlia table.

func (*Network) GetPeerKadID

func (ntw *Network) GetPeerKadID(address string) kad.ID

GetPeerKadID returns the KadID of the peer since it is randomly initialized sometimes

func (*Network) GetRelayChan

func (ntw *Network) GetRelayChan() chan relay.Message

GetRelayChan returns the channel for relay messages.

func (*Network) HandlePeerDisconnection

func (ntw *Network) HandlePeerDisconnection(peerCleanup disconCleanInterface)

HandlePeerDisconnection registers the dinconnection callback with the interface

func (*Network) Relay

func (ntw *Network) Relay(peerID kad.ID, code byte, data []byte) error

Relay relays data to peer with given ID.

Jump to

Keyboard shortcuts

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