host

package
v0.2.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const MinPeersForSyncStart = 3

Variables

View Source
var (
	// ErrorBlockAlreadyKnown returns when received a block already known
	ErrorBlockAlreadyKnown = errors.New("block already known")

	// ErrorBlockParentUnknown returns when received a block with an unknown parent
	ErrorBlockParentUnknown = errors.New("unknown block parent")
)

Functions

func ExternalIP

func ExternalIP() (string, error)

ExternalIP returns the first IPv4/IPv6 available.

func ExternalIPv4

func ExternalIPv4() (string, error)

ExternalIPv4 returns the first IPv4 available.

func ExternalIPv6

func ExternalIPv6() (string, error)

ExternalIPv6 retrieves any allocated IPv6 addresses from the accessible network interfaces.

func NewDiscovery

func NewDiscovery(ctx context.Context, h Host, lh libhost.Host) (*discovery, error)

func NewNotify

func NewNotify(h Host, s *stats) *notify

func NewStatsService

func NewStatsService(h Host) (*stats, error)

func NewSynchronizer

func NewSynchronizer(host Host, chain chain.Blockchain) (*synchronizer, error)

NewSynchronizer constructs a new sync protocol with a given host and chain.

func SortAddresses

func SortAddresses(ipAddrs []net.IP) []net.IP

SortAddresses sorts a set of addresses in the order of ipv4 -> ipv6.

Types

type Host

type Host interface {
	ID() peer.ID
	Version() *p2p.MsgVersion
	Synced() bool
	ConnectedPeers() int
	GetPeersInfo() []*peerStats
	GetPeerDirection(p peer.ID) network.Direction
	SendMessage(id peer.ID, msg p2p.Message) error

	Notify(n *notify)
	Unnotify(n *notify)

	Disconnect(p peer.ID) error
	Connect(p peer.AddrInfo) error
	HandleConnection(net network.Network, conn network.Conn)

	RegisterTopicHandler(messageName string, handler MessageHandler)
	Broadcast(msg p2p.Message) error

	Stop()

	SetStreamHandler(pid protocol.ID, s network.StreamHandler)

	TrackedPeers() int
	FindBestPeer() (peer.ID, bool)
	GetPeerStats(p peer.ID) (*peerStats, bool)
	RemovePeerStats(id peer.ID)
	AddPeerStats(id peer.ID, msg *p2p.MsgVersion, dir network.Direction)
	IncreasePeerReceivedBytes(p peer.ID, amount uint64)
}

func NewHostNode

func NewHostNode(ch chain.Blockchain) (Host, error)

type MessageHandler

type MessageHandler func(id peer.ID, msg p2p.Message) error

MessageHandler is a handler for a specific message.

Jump to

Keyboard shortcuts

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