hostnode

package
v0.2.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 42 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")
)
View Source
var BadPeersCache, _ = ristretto.NewCache(&ristretto.Config{
	NumCounters: maxPeers,
	MaxCost:     1 << 22,
	BufferItems: 64,
})

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 NewDiscover

func NewDiscover(host HostNode) (*discover, error)

NewDiscover creates a new discovery service.

func NewSyncronizer

func NewSyncronizer(host HostNode, chain chain.Blockchain) (*synchronizer, error)

NewSyncronizerl 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 HostNode

type HostNode interface {
	Syncing() bool
	GetHost() host.Host
	GetNetMagic() uint32
	DisconnectPeer(p peer.ID) error
	GetPeerInfos() []peer.AddrInfo
	GetPeerDirection(id peer.ID) network.Direction
	GetPeerInfo(id peer.ID) *peer.AddrInfo
	GetPeersStats() []*peerInfo
	RegisterHandler(message string, handler MessageHandler) error
	RegisterTopicHandler(message string, handler MessageHandler) error
	HandleStream(s network.Stream)
	SendMessage(id peer.ID, msg p2p.Message) error
	Broadcast(msg p2p.Message) error
}

HostNode is an interface for hostNode

func NewHostNode

func NewHostNode(blockchain chain.Blockchain) (HostNode, error)

NewHostNode creates a host node

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