p2p

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: GPL-3.0 Imports: 22 Imported by: 1

README

p2p

This subpackage contains helper functions for use with go-ma. They MUST NOT be required by any other subpackage. It's an aid for simple p2p communication, but users should be able to use go-ma without it.

2023-11-19: bahner

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToCreateRoutingDiscovery = fmt.Errorf("failed to create routing discovery")
)

Functions

This section is empty.

Types

type DHT added in v0.3.0

type DHT struct {
	*p2pDHT.IpfsDHT
	Host            host.Host
	ConnectionGater *connmgr.ConnectionGater
}

func NewDHT added in v0.3.0

func NewDHT(h host.Host, cg *connmgr.ConnectionGater, dhtOpts ...p2pDHT.Option) (*DHT, error)

func (*DHT) Bootstrap added in v0.3.0

func (d *DHT) Bootstrap(ctx context.Context) error

You should only call this once. It bootstraps the DHT to the network.

type MDNS added in v0.3.0

type MDNS struct {
	PeerChan chan p2peer.AddrInfo
	// contains filtered or unexported fields
}

type Options added in v0.4.0

type Options struct {
	DHT     []p2pDHT.Option
	P2P     []libp2p.Option
	Connmgr []connmgr.Option
}

func DefaultOptions added in v0.4.0

func DefaultOptions() Options

type P2P added in v0.0.2

type P2P struct {
	PubSub   *p2ppubsub.PubSub
	DHT      *DHT
	MDNS     *MDNS
	Host     host.Host
	AddrInfo p2peer.AddrInfo
}

This is not a normal libp2p node, it's a wrapper around it. And it is specific to this project. It contains a libp2p node, a pubsub service and a DHT instance. It also contains a list of connected peers.

func Get added in v0.3.0

func Get() *P2P

Get the P2P instance. This is a singleton.

func Init

func Init(opts Options) (*P2P, error)

Initialise everything needed for p2p communication. The function forces use of a specific IPNS key. Taken from the config package. It would be an error to initialise the node with a different key. The input is derived from Config() in the config package.

func (*P2P) AllConnectedPeers added in v0.3.0

func (p *P2P) AllConnectedPeers() p2peer.IDSlice

AllConnectedPeers returns a slice of p2peer.ID for all connected peers of the given host.

func (*P2P) ConnectedProctectedPeersNickList added in v0.3.0

func (p *P2P) ConnectedProctectedPeersNickList() []string

func (*P2P) ConnectedProtectedPeers added in v0.3.0

func (p *P2P) ConnectedProtectedPeers() p2peer.IDSlice

ConnectedProtectedPeers returns a slice of p2peer.ID for all protected connected peers.

func (*P2P) ConnectedProtectedPeersAddrInfo added in v0.3.0

func (p *P2P) ConnectedProtectedPeersAddrInfo() map[string]p2peer.AddrInfo

ConnectedProtectedPeersAddrInfo returns a map of p2peer.ID to AddrInfo for all protected connected peers.

func (*P2P) ConnectedUnprotectedPeers added in v0.3.0

func (p *P2P) ConnectedUnprotectedPeers() p2peer.IDSlice

ConnectedUnprotectedPeers returns a slice of p2peer.ID for all unprotected connected peers.

func (*P2P) StartDiscoveryLoop added in v0.3.0

func (p *P2P) StartDiscoveryLoop(ctx context.Context) error

Directories

Path Synopsis
key

Jump to

Keyboard shortcuts

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