host

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithBootNodes

func WithBootNodes(nodes []multiaddr.Multiaddr) func(*Config)

WithBootNodes specifies boot nodes that the host initially tries to connect to.

func WithConnectionThreshold

func WithConnectionThreshold(n uint) func(*Config)

WithConnectionThreshold specifies how many connections should the host wait for on peer discovery.

func WithDialBackAddress

func WithDialBackAddress(a string) func(*Config)

func WithDialBackPeers

func WithDialBackPeers(peers []blockless.Peer) func(*Config)

WithDialBackPeers specifies dial-back peers that the host initially tries to connect to.

func WithDialBackPeersLimit

func WithDialBackPeersLimit(n uint) func(*Config)

WithDialBackPeersLimit specifies the maximum number of dial-back peers to use.

func WithDialBackPort

func WithDialBackPort(n uint) func(*Config)

func WithDialBackWebsocketPort

func WithDialBackWebsocketPort(n uint) func(*Config)

func WithDiscoveryInterval

func WithDiscoveryInterval(d time.Duration) func(*Config)

WithDiscoveryInterval specifies how often we should try to discover new peers during the discovery phase.

func WithPrivateKey

func WithPrivateKey(filepath string) func(*Config)

WithPrivateKey specifies the private key for the Host.

func WithWebsocket

func WithWebsocket(b bool) func(*Config)

WithWebsocket specifies whether libp2p host should use websocket protocol.

func WithWebsocketPort

func WithWebsocketPort(port uint) func(*Config)

WithWebsocketPort specifies on which port the host should listen for websocket connections.

Types

type Config

type Config struct {
	PrivateKey string

	ConnectionThreshold uint
	BootNodes           []multiaddr.Multiaddr
	DialBackPeers       []blockless.Peer
	DialBackPeersLimit  uint
	DiscoveryInterval   time.Duration

	Websocket     bool
	WebsocketPort uint

	DialBackAddress       string
	DialBackPort          uint
	DialBackWebsocketPort uint
}

Config represents the Host configuration.

type Host

type Host struct {
	host.Host
	// contains filtered or unexported fields
}

Host represents a new libp2p host.

func New

func New(log zerolog.Logger, address string, port uint, options ...func(*Config)) (*Host, error)

New creates a new Host.

func (*Host) Addresses

func (h *Host) Addresses() []string

Addresses returns the list of p2p addresses of the host.

func (*Host) DiscoverPeers

func (h *Host) DiscoverPeers(ctx context.Context, topic string) error

func (*Host) InitPubSub

func (h *Host) InitPubSub(ctx context.Context) error

func (*Host) JoinTopic

func (h *Host) JoinTopic(topic string) (*pubsub.Topic, error)

func (*Host) PrivateKey

func (h *Host) PrivateKey() crypto.PrivKey

PrivateKey returns the private key of the libp2p host.

func (*Host) PublicKey

func (h *Host) PublicKey() crypto.PubKey

PublicKey returns the public key of the libp2p host.

func (*Host) Publish

func (h *Host) Publish(ctx context.Context, topic *pubsub.Topic, payload []byte) error

Publish will publish the message on the provided gossipsub topic.

func (*Host) SendMessage

func (h *Host) SendMessage(ctx context.Context, to peer.ID, payload []byte) error

SendMessage sends a message directly to the specified peer, on the standard blockless protocol.

func (*Host) SendMessageOnProtocol

func (h *Host) SendMessageOnProtocol(ctx context.Context, to peer.ID, payload []byte, protocol protocol.ID) error

SendMessageOnProtocol sends a message directly to the specified peer, using the specified protocol.

func (*Host) Subscribe

func (h *Host) Subscribe(topic string) (*pubsub.Topic, *pubsub.Subscription, error)

Subscribe will have the host start listening to a specified gossipsub topic.

Jump to

Keyboard shortcuts

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