p2p

package
v0.0.0-...-28b05a4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HostToString

func HostToString(h host.Host) string

func NewDefaultP2PHost

func NewDefaultP2PHost() (*host.Host, error)

NewDefaultP2PHost initialise a new libp2p host

Types

type DHTValidator

type DHTValidator struct{}

DHTValidator is used to validate the record in the DHT

func NewDHTValidator

func NewDHTValidator() *DHTValidator

NewDHTValidator initialise a new DHT validator

func (*DHTValidator) Select

func (v *DHTValidator) Select(key string, values [][]byte) (int, error)

Select returns the index of the best value and nil, or -1 and an error if none are valid

func (*DHTValidator) Validate

func (v *DHTValidator) Validate(key string, value []byte) error

Validate is to validate a key in the DHT TODO It always returns nil (i.e. valid) by now. Please add validation mechanism if needed.

type Instance

type Instance struct {
	Host      *host.Host     // Host for libp2p.
	DHT       *dht.IpfsDHT   // Kademlia DHT for resource locating.
	Discovery *PeerDiscovery // mDNS peer discovery instance.

	PubSub *pubsub.PubSub // Gossip pub-sub service.
	// contains filtered or unexported fields
}

Instance is the libp2p instance for networking usage.

func NewInstance

func NewInstance(c context.Context, p2pconfig config.P2pConfig) *Instance

NewInstance initialises a blank libp2p instance.

func (*Instance) Build

func (i *Instance) Build() (*Instance, error)

Build constructs the P2P instance using the given configuration.

func (*Instance) ConnectFromMultiaddr

func (i *Instance) ConnectFromMultiaddr(ctx context.Context, str string)

func (*Instance) JoinTopic

func (i *Instance) JoinTopic(topic string) error

JoinTopic join this instance to the specific pub-sub topic

func (*Instance) Publish

func (i *Instance) Publish(topic string, message []byte) error

Publish a message to the specific topic

func (*Instance) SetP2PHost

func (i *Instance) SetP2PHost(existingHost *host.Host) *Instance

SetP2PHost uses an existing libp2p host to initialise the instance.

func (*Instance) Start

func (i *Instance) Start() error

Start using mDNS to join this client to the existing cluster

func (*Instance) Stop

func (i *Instance) Stop() error

Stop shutdown the libp2p instance and close this dht client It does not destroy the whole DHT itself

func (*Instance) Subscribe

func (i *Instance) Subscribe(topic string) (<-chan *pubsub.Message, error)

Subscribe to a specific topic

type PeerDiscovery

type PeerDiscovery struct {
	NewPeers chan peer.AddrInfo
}

PeerDiscovery is the mDNS peer discovery notify instance

func NewPeerDiscovery

func NewPeerDiscovery() *PeerDiscovery

NewPeerDiscovery initialise a new peer discovery instance

func (*PeerDiscovery) HandlePeerFound

func (d *PeerDiscovery) HandlePeerFound(p peer.AddrInfo)

HandlePeerFound will be called when a new peer is discovered

Jump to

Keyboard shortcuts

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