Documentation ¶
Index ¶
- Constants
- func AutoClose(ctx context.Context, c Closeable)
- func BootstrapLibP2P(ctx context.Context, cfg *Config, opts ...libp2p.Option) (host.Host, *kaddht.IpfsDHT, *pubsub.PubSub, error)
- func CircuitRelayAddr(relay, target peer.ID) multiaddr.Multiaddr
- func CircuitRelayAddrInfo(relay, target peer.ID) peer.AddrInfo
- func Close(node LibP2PPeer) []error
- func ConfigureDiscovery(ctx context.Context, h host.Host, opts *DiscoveryConfig, ...) error
- func Connect(node LibP2PPeer, peers []peer.AddrInfo, bootDht bool) chan PeerConnection
- func MAddrs(addrs []string) []multiaddr.Multiaddr
- func PNetSecret() pnet.PSK
- func Peers(addrs []string) []peer.AddrInfo
- func PrivKey(keyPath string) crypto.PrivKey
- func Publish(node PubSuber, ctx context.Context, topic string, data []byte) error
- func SerializeAddrInfo(info peer.AddrInfo) string
- func SerializePeer(h host.Host) string
- func Subscribe(node PubSuber, topic string) (*pubsub.Subscription, error)
- func Topic(node PubSuber, name string) (*pubsub.Topic, error)
- type BasePeer
- func (p *BasePeer) Close() error
- func (p *BasePeer) Context() context.Context
- func (p *BasePeer) DHT() *kaddht.IpfsDHT
- func (p *BasePeer) Host() host.Host
- func (p *BasePeer) Logger() logging.EventLogger
- func (p *BasePeer) PrivKey() crypto.PrivKey
- func (p *BasePeer) Psk() pnet.PSK
- func (p *BasePeer) PubSub() *pubsub.PubSub
- func (p *BasePeer) Store() datastore.Batching
- func (p *BasePeer) Topics() map[string]*pubsub.Topic
- type Closeable
- type Config
- type ConnManagerConfig
- type DiscoveryConfig
- type GroupNodeFactory
- type LibP2PPeer
- type OnPeerFound
- type PeerConnection
- type PubSuber
Constants ¶
const DefaultDiscoveryInterval = time.Minute * 10
DiscoveryInterval is how often we re-publish our mDNS records.
const DefaultDiscoveryServiceTag = "pnet:pubsub"
DiscoveryServiceTag is used in our mDNS advertisements to discover other chat peers.
Variables ¶
This section is empty.
Functions ¶
func BootstrapLibP2P ¶
func BootstrapLibP2P(ctx context.Context, cfg *Config, opts ...libp2p.Option) (host.Host, *kaddht.IpfsDHT, *pubsub.PubSub, error)
BootstrapLibP2P creates an instance of libp2p host + DHT and peer discovery / pubsub (if configured)
func CircuitRelayAddr ¶
CircuitRelayAddr construct a circuit relay address of the given relay and target peer
func Close ¶
func Close(node LibP2PPeer) []error
Close closes the underlying host, dht and possibly other services (e.g. store, pubsub) returns an array to be compatible with multiple closes
func ConfigureDiscovery ¶
func ConfigureDiscovery(ctx context.Context, h host.Host, opts *DiscoveryConfig, logger logging.EventLogger) error
ConfigureDiscovery binds mDNS discovery services
func Connect ¶
func Connect(node LibP2PPeer, peers []peer.AddrInfo, bootDht bool) chan PeerConnection
Connect will try to connect to each of the given peer a channel is used to publish connection result. the dht should be bootstrapped if the is the first connect of a node
func MAddrs ¶
func MAddrs(addrs []string) []multiaddr.Multiaddr
MAddrs takes []string and creates the corresponding []multiaddrs
func SerializeAddrInfo ¶
SerializeAddrInfo marshals (json) the given peer
func SerializePeer ¶
SerializePeer marshals (json) the given host's info
Types ¶
type BasePeer ¶
type BasePeer struct {
// contains filtered or unexported fields
}
func NewBasePeer ¶
func (*BasePeer) Logger ¶
func (p *BasePeer) Logger() logging.EventLogger
type Closeable ¶
type Closeable interface {
Close() error
}
Closeable represent an object the can be closed
type Config ¶
type Config struct { // PrivKey of the current node PrivKey crypto.PrivKey // Secret is the private network secret ([32]byte) Secret pnet.PSK // Addrs are Multiaddrs for the current node, will fallback to libp2p defaults Addrs []multiaddr.Multiaddr // Logger to use (see github.com/ipfs/go-log/v2) Logger logging.EventLogger // DS is the main data store used by DHT, BlockStore, etc... DS datastore.Batching // Peers are nodes that we want to connect on bootstrap Peers []peer.AddrInfo // ConnManagerConfig is used to configure the conn management of current peer ConnManagerConfig *ConnManagerConfig // Discovery is used to configure discovery (+pubsub) Discovery *DiscoveryConfig }
Config holds the needed configuration for creating a private node instance
func (*Config) ToLibP2pOpts ¶
ToLibP2pOpts converts Config into the corresponding []libp2p.Option
type ConnManagerConfig ¶
ConnManagerConfig used to configure a connection manager (github.com/libp2p/go-libp2p-connmgr)
type DiscoveryConfig ¶
type DiscoveryConfig struct { OnPeerFound OnPeerFound ServiceTag string Interval time.Duration Services []discovery.Service }
DiscoveryConfig
func NewDiscoveryConfig ¶
func NewDiscoveryConfig(onPeerFound OnPeerFound) *DiscoveryConfig
NewDiscoveryConfig creates a new discovery config object with defaults
type GroupNodeFactory ¶
type GroupNodeFactory func(OnPeerFound) LibP2PPeer
type LibP2PPeer ¶
type LibP2PPeer interface { Context() context.Context Closeable PrivKey() crypto.PrivKey Psk() pnet.PSK Host() host.Host DHT() *kaddht.IpfsDHT Store() datastore.Batching PubSuber Logger() logging.EventLogger }
LibP2PPeer is the base interface
func NewRelayer ¶
func NewRelayer(ctx context.Context, cfg *Config, opts ...libp2p.Option) LibP2PPeer
NewRelayer creates an instance of BasePeer with the needed configuration to be a circuit-relay node
func SetupGroup ¶
func SetupGroup(n int, nodeFactory GroupNodeFactory) ([]LibP2PPeer, error)
SetupGroup will create a group of n local nodes that are connected to each other used in tests
type OnPeerFound ¶
OnPeerFound will be triggered on new peer discovery in case it returns false, this node won't connect to the given peer
func OnPeerFoundWaitGroup ¶
func OnPeerFoundWaitGroup(wg *sync.WaitGroup) OnPeerFound
OnPeerFoundWaitGroup creates an OnPeerFound that triggers a WaitGroup
type PeerConnection ¶
ConnectionResult is the used to abstract connection try