node

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMultiAddrFromString

func GetMultiAddrFromString(addr string) (multiaddr.Multiaddr, error)

GetMultiAddrFromString gets the multiaddress from the string encoded address.

Types

type Interface

type Interface interface {
	GetSyncing() bool
	Sync(ctx context.Context) error
	ConnectToPeerWithMultiaddr(ctx context.Context, addr multiaddr.Multiaddr) (*peer.AddrInfo, error)
	Advertise(ctx context.Context, ns string)
	DiscoverPeers(ctx context.Context, ns string) error
	PublishMessageToNetwork(ctx context.Context, topicName string, data []byte) error
	HandleIncomingMessages(ctx context.Context, topicName string) error
	GetMultiaddr() ([]multiaddr.Multiaddr, error)
	Peers() peer.IDSlice
	GetID() string
	GetPeerID() peer.ID
	Bootstrap(ctx context.Context, bootstrapPeers []string) error
	FindPeers(ctx context.Context, peerIDs []peer.ID) []peer.AddrInfo
	JoinPubSubNetwork(topicName string) error
	HeighestBlockNumberDiscovered() uint64
	Uptime() int64
}

Interface defines a node's functionalities.

type Node

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

Node represents all the node functionalities

func New

func New(cfg *ffgconfig.Config, host host.Host, dht PeerFinderBootstrapper, discovery libp2pdiscovery.Discovery, pubSub PublishSubscriber, search search.IndexSearcher, storage storage.Interface, blockchain blockchain.Interface, dataQuery dataquery.Interface, blockDownloaderProtocol blockdownloader.Interface, storageProtocol storageprotocol.Interface, uptime int64) (*Node, error)

New creates a new node.

func (*Node) Advertise

func (n *Node) Advertise(ctx context.Context, ns string)

Advertise randevouz point.

func (*Node) Bootstrap

func (n *Node) Bootstrap(ctx context.Context, bootstrapPeers []string) error

Bootstrap connects to bootstrap nodes.

func (*Node) ConnectToPeerWithMultiaddr

func (n *Node) ConnectToPeerWithMultiaddr(ctx context.Context, addr multiaddr.Multiaddr) (*peer.AddrInfo, error)

ConnectToPeerWithMultiaddr connects to a node given its full address.

func (*Node) DiscoverPeers

func (n *Node) DiscoverPeers(ctx context.Context, ns string) error

DiscoverPeers discovers peers from randevouz point.

func (*Node) FindPeers

func (n *Node) FindPeers(ctx context.Context, peerIDs []peer.ID) []peer.AddrInfo

FindPeers returns the list of peer addresses.

func (*Node) GetID

func (n *Node) GetID() string

GetID returns the node id.

func (*Node) GetMultiaddr

func (n *Node) GetMultiaddr() ([]multiaddr.Multiaddr, error)

GetMultiaddr returns the peers multiaddr.

func (*Node) GetPeerID

func (n *Node) GetPeerID() peer.ID

GetPeerID returns the peer id struct.

func (*Node) GetSyncing

func (n *Node) GetSyncing() bool

GetSyncing returns true if node is syncing.

func (*Node) HandleIncomingMessages

func (n *Node) HandleIncomingMessages(ctx context.Context, topicName string) error

HandleIncomingMessages gets the messages from gossip network.

func (*Node) HeighestBlockNumberDiscovered added in v1.1.16

func (n *Node) HeighestBlockNumberDiscovered() uint64

nolint:misspell HeighestBlockNumberDiscovered gets the heighest block discovered from other peers in the network.

func (*Node) JoinPubSubNetwork

func (n *Node) JoinPubSubNetwork(topicName string) error

JoinPubSubNetwork joins the gossip network.

func (*Node) Peers

func (n *Node) Peers() peer.IDSlice

Peers returns a list of peers in the peer store.

func (*Node) PublishMessageToNetwork

func (n *Node) PublishMessageToNetwork(ctx context.Context, topicName string, data []byte) error

PublishMessageToNetwork publish a message to the network.

func (*Node) Sync

func (n *Node) Sync(ctx context.Context) error

Sync the node with other peers in the network.

func (*Node) Uptime added in v1.3.0

func (n *Node) Uptime() int64

Uptime returns the uptime of the node.

type PeerFinderBootstrapper

type PeerFinderBootstrapper interface {
	FindPeer(ctx context.Context, id peer.ID) (_ peer.AddrInfo, err error)
	Bootstrap(ctx context.Context) error
}

PeerFinderBootstrapper is a dht interface.

type PublishSubscriber

type PublishSubscriber interface {
	// Publish to a topic.
	Publish(topic string, data []byte, opts ...pubsub.PubOpt) error
	// Join a topic.
	Join(topic string, opts ...pubsub.TopicOpt) (*pubsub.Topic, error)
	// Subscribe to a topic.
	Subscribe(topic string, opts ...pubsub.SubOpt) (*pubsub.Subscription, error)
}

PublishSubscriber is a pub sub interface.

Directories

Path Synopsis
protocols

Jump to

Keyboard shortcuts

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