commons

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMultiAddress

func BuildMultiAddress(ipAddr, protocol string, port uint, id peer.ID) (ma.Multiaddr, error)

BuildMultiAddress creates a multiaddr from the given peer data

func CheckAddress

func CheckAddress(addr string) error

CheckAddress checks that some address is accessible and returns error accordingly

func EnsureConnectedPeers

func EnsureConnectedPeers(pctx context.Context, h host.Host, n int, timeout time.Duration) error

EnsureConnectedPeers ensures that the host has at least {n} connected peers under the given timeout

Types

type Config

type Config struct {
	StaticConfig
	// PrivateKey is used as the private key of the peer
	PrivateKey crypto.PrivKey
	// Reporter to use to collect metrics
	Reporter        metrics.Reporter
	AddrsFactory    bhost.AddrsFactory
	ConnectionGater connmgr.ConnectionGater
	ConnManager     connmgr.ConnManager
	ResourceManager network.ResourceManager
	Peerstore       peerstore.Peerstore

	Routing func(h host.Host) (routing.Routing, error)

	Pubsub *PubsubConfig
}

Config contains both dynamic (libp2p components) and static information (json/yaml). TODO: complete more fields from https://pkg.go.dev/github.com/libp2p/go-libp2p/config#Config

func (*Config) Init

func (cfg *Config) Init() error

func (*Config) Libp2pOptions

func (cfg *Config) Libp2pOptions() ([]libp2p.Option, error)

Libp2pOptions returns a list of libp2p options for the given config

type PubsubConfig

type PubsubConfig struct {
	// Config is the general configuration in the pubsub router level
	Config *PubsubTopicConfig `json:"config" yaml:"config"`
	// Topics is the configuration for topics
	Topics []PubsubTopicConfig `json:"topics" yaml:"topics"`
}

func (*PubsubConfig) GetTopicCfg

func (pcfg *PubsubConfig) GetTopicCfg(topicName string) []PubsubTopicConfig

GetTopicCfg returns all the relevant configs (including regex) for the given topic name

type PubsubTopicConfig

type PubsubTopicConfig struct {
	Name       string `json:"name" yaml:"name"`
	BufferSize int    `json:"bufferSize" yaml:"bufferSize"`
}

type StaticConfig

type StaticConfig struct {
	// ListenAddrs addrs to listen, this allows to specify also the transports that are supported
	ListenAddrs []string `json:"listenAddrs" yaml:"listenAddrs"`
	// Relayers are possible circuit relay end-points
	Relayers []string `json:"relayers,omitempty" yaml:"relayers,omitempty"`
	// DialTimeout is the timeout to use when dialing peers
	DialTimeout time.Duration `json:"dialTimeout,omitempty" yaml:"dialTimeout,omitempty"`
	// Muxers the supported muxers
	Muxers []string `json:"muxers,omitempty" yaml:"muxers,omitempty"`
	// Security the supported security protocols
	Security []string `json:"security,omitempty" yaml:"security,omitempty"`
	// NetworkSecret is a secret to use for a private network
	NetworkSecret string `json:"networkSecret,omitempty" yaml:"networkSecret,omitempty"`
	// DisablePing is a negative flag to turn off libp2p Ping
	DisablePing bool `json:"disablePing,omitempty" yaml:"disablePing,omitempty"`
	// EnableAutoRelay whether to enable auto relay
	EnableAutoRelay bool `json:"enableAutoRelay,omitempty" yaml:"enableAutoRelay,omitempty"`
	// MdnsServiceTag is the service tag used by mdns service. mdns is disabled if service tag is empty
	MdnsServiceTag string `json:"mdnsServiceTag,omitempty" yaml:"mdnsServiceTag,omitempty"`
	// UserAgent is the user agent string used by identify protocol
	UserAgent string `json:"userAgent,omitempty" yaml:"userAgent,omitempty"`
}

StaticConfig contains static configuration for the p2p node

Jump to

Keyboard shortcuts

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