Documentation ¶
Index ¶
- Variables
- func New(ctx context.Context, opts ...Option) (*core.PeerNode, error)
- func NewWithoutDefaults(ctx context.Context, opts ...Option) (*core.PeerNode, error)
- type Config
- type Option
- func BootPeers(bootpeers []string) Option
- func BucketSize(size int) Option
- func ListenPort(port int) Option
- func MaxConnection(low, high int) Option
- func PrivatekeyFile(privatekey string) Option
- func ProtocolPrefix(protocolPrefix string) Option
- func PublicIpv4(ip string) Option
- func Version(ver string) Option
- func Workspace(workspace string) Option
Constants ¶
This section is empty.
Variables ¶
var DefaultBucketSize = func(cfg *Config) error { return cfg.Apply(BucketSize(100)) }
DefaultWorkSpace configures libp2p to use default work space.
var DefaultConnectionManager = func(cfg *Config) error { mgr, err := connmgr.NewConnManager(10, 100, connmgr.WithGracePeriod(time.Minute), connmgr.WithSilencePeriod(time.Minute)) if err != nil { return err } cfg.ConnManager = mgr return nil }
DefaultConnectionManager creates a default connection manager.
var DefaultListenPort = func(cfg *Config) error { port := 4001 return cfg.Apply(ListenPort(port)) }
DefaultListenPort configures libp2p to use default port.
var DefaultWorkSpace = func(cfg *Config) error { dir, err := os.Getwd() if err != nil { return err } return cfg.Apply(Workspace(dir)) }
DefaultWorkSpace configures libp2p to use default work space.
Functions ¶
func New ¶
New constructs a new libp2p node with the given options, falling back on reasonable defaults. The defaults are:
- If no listening port is provided, the host listens on the default port: 4001
- If no bootstrap nodes is provided, the host will run as a server
- If no protocol version is provided, The host uses the default protocol version: /kldr/1.0
- If no DHT protocol version is provided, The host uses the default DHT protocol version: /kldr/kad/1.0
To stop/shutdown the returned p2p node, the user needs to cancel the passed context and call `Close` on the returned Host.
func NewWithoutDefaults ¶
NewWithoutDefaults constructs a new libp2p node with the given options but *without* falling back on reasonable defaults.
Warning: This function should not be considered a stable interface. We may choose to add required services at any time and, by using this function, you opt-out of any defaults we may provide.
Types ¶
type Option ¶
Option is a p2p config option that can be given to the p2p constructor.
var FallbackDefaults Option = func(cfg *Config) error { for _, def := range defaults { if !def.fallback(cfg) { continue } if err := cfg.Apply(def.opt); err != nil { return err } } return nil }
FallbackDefaults applies default options to the libp2p node if and only if no other relevant options have been applied. will be appended to the options passed into New.
func BucketSize ¶ added in v0.3.4
BucketSize configuration bucket size
func ListenPort ¶ added in v0.0.24
ListenPort configuration listening port
func MaxConnection ¶ added in v0.3.4
MaxConnection configuration max connection
func PrivatekeyFile ¶ added in v0.0.32
PrivatekeyFile configuration privatekey file
func ProtocolPrefix ¶ added in v0.0.37
PrivatekeyFile configuration privatekey file
func PublicIpv4 ¶ added in v0.1.0
PrivatekeyFile configuration privatekey file