p2p

package
v1.2.10-rc.5 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 37 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientNode

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

ClientNode is a peer to peer node. ClientNode acts as a client, routing messages to its peers, and as a server that can register services to the network.

func NewClient

func NewClient(opts Options) (*ClientNode, error)

NewClient creates a new node. NewClient waits for the Network service of the Directory network to be available and queries it to determine the routing table. Thus NewClient must not be used by the core nodes themselves.

func NewClientWith

func NewClientWith(node *Node) (*ClientNode, error)

NewClientWith creates a new client for the given node. NewClientWith waits for the Network service of the Directory network to be available and queries it to determine the routing table. Thus NewClientWith must not be used by the core nodes themselves.

func (*ClientNode) ConsensusStatus

func (n *ClientNode) ConsensusStatus(ctx context.Context, opts api.ConsensusStatusOptions) (*api.ConsensusStatus, error)

ConsensusStatus implements api.ConsensusService.ConsensusStatus.

func (*ClientNode) Faucet

func (n *ClientNode) Faucet(ctx context.Context, account *url.URL, opts api.FaucetOptions) (*api.Submission, error)

Faucet implements api.Faucet.Faucet.

func (*ClientNode) FindService

func (n *ClientNode) FindService(ctx context.Context, opts api.FindServiceOptions) ([]*api.FindServiceResult, error)

FindService implements api.NodeService.FindService.

func (*ClientNode) Metrics

func (n *ClientNode) Metrics(ctx context.Context, opts api.MetricsOptions) (*api.Metrics, error)

Metrics implements api.MetricsService.Metrics.

func (*ClientNode) NetworkStatus

func (n *ClientNode) NetworkStatus(ctx context.Context, opts api.NetworkStatusOptions) (*api.NetworkStatus, error)

NetworkStatus implements api.NetworkService.NetworkStatus.

func (*ClientNode) NodeInfo

func (n *ClientNode) NodeInfo(ctx context.Context, opts api.NodeInfoOptions) (*api.NodeInfo, error)

NodeInfo implements api.NodeService.NodeInfo.

func (*ClientNode) Query

func (n *ClientNode) Query(ctx context.Context, scope *url.URL, query api.Query) (api.Record, error)

Query implements api.Querier.Query.

func (*ClientNode) Submit

func (n *ClientNode) Submit(ctx context.Context, envelope *messaging.Envelope, opts api.SubmitOptions) ([]*api.Submission, error)

Submit implements api.Submitter.Submit.

func (*ClientNode) Subscribe

func (n *ClientNode) Subscribe(ctx context.Context, opts api.SubscribeOptions) (<-chan api.Event, error)

Subscribe implements api.EventService.Subscribe.

func (*ClientNode) Validate

func (n *ClientNode) Validate(ctx context.Context, envelope *messaging.Envelope, opts api.ValidateOptions) ([]*api.Submission, error)

Validate implements api.Validator.Validate.

type MessageStreamHandler

type MessageStreamHandler func(message.Stream)

A MessageStreamHandler handles an incoming message.Stream.

type Node

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

Node implements peer-to-peer routing of API v3 messages over via binary message transport.

func New

func New(opts Options) (_ *Node, err error)

New creates a node with the given Options.

func (*Node) Addresses

func (n *Node) Addresses() []multiaddr.Multiaddr

Addresses lists the node's addresses.

func (*Node) Close

func (n *Node) Close() error

Close shuts down the host and topics.

func (*Node) ConnectDirectly

func (n *Node) ConnectDirectly(m *Node) error

ConnectDirectly connects this node directly to another node.

func (*Node) Connector added in v1.2.10

func (n *Node) Connector() dial.Connector

func (*Node) DialNetwork

func (n *Node) DialNetwork() message.Dialer

DialNetwork returns a message.MultiDialer that opens a stream to a node that can provides a given service.

func (*Node) DialSelf

func (n *Node) DialSelf() message.Dialer

DialSelf returns a message.Dialer that always returns a stream for the current node.

func (*Node) ID

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

func (*Node) RegisterService

func (n *Node) RegisterService(sa *api.ServiceAddress, handler MessageStreamHandler) bool

RegisterService registers a service handler and registers the service with the network.

func (*Node) Tracker added in v1.2.10

func (n *Node) Tracker() dial.Tracker

func (*Node) WaitForService

func (s *Node) WaitForService(ctx context.Context, addr multiaddr.Multiaddr) error

WaitForService IS NOT RELIABLE.

WaitForService blocks until the given service is available. WaitForService will return once the service is registered on the current node or until the node is informed of a peer with the given service. WaitForService will return immediately if the service is already registered or known.

type Options

type Options struct {
	// Network is the network the node is a part of. An empty Network indicates
	// the node is not part of any network.
	Network string

	// Listen is an array of addresses to listen on.
	Listen []multiaddr.Multiaddr

	// BootstrapPeers is an array of addresses of the bootstrap peers to connect
	// to on bootup.
	BootstrapPeers []multiaddr.Multiaddr

	// Key is the node's private key. If Key is omitted, the node will
	// generate a new key.
	Key ed25519.PrivateKey

	// DiscoveryMode determines how the node responds to peer discovery
	// requests.
	DiscoveryMode dht.ModeOpt

	// External is the node's external address
	External multiaddr.Multiaddr

	// EnablePeerTracker enables the peer tracker to reduce the impact of
	// mis-configured peers. This is currently experimental.
	EnablePeerTracker bool

	PeerDatabase string
}

Options are options for creating a Node.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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