p2p

package
v0.3.4-beta.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 25 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureIdentity added in v1.0.0

func EnsureIdentity(dir string) (crypto.PrivKey, error)

EnsureIdentity generates an identity key file in given directory.

func IsNoPeer added in v1.0.0

func IsNoPeer(p Peer) bool

IsNoPeer checks if it's any peer.

func PrettyIdentityInfoFromDir added in v1.0.0

func PrettyIdentityInfoFromDir(dir string) (string, error)

PrettyIdentityInfoFromDir returns a printable ID from a given identity directory.

Types

type Config added in v1.0.0

type Config struct {
	DataDir            string
	LogLevel           log.Level
	GracePeersShutdown time.Duration
	MaxMessageSize     int

	DisableNatPort   bool     `mapstructure:"disable-natport"`
	Flood            bool     `mapstructure:"flood"`
	Listen           string   `mapstructure:"listen"`
	Bootnodes        []string `mapstructure:"bootnodes"`
	MinPeers         int      `mapstructure:"min-peers"`
	LowPeers         int      `mapstructure:"low-peers"`
	HighPeers        int      `mapstructure:"high-peers"`
	AdvertiseAddress string   `mapstructure:"advertise-address"`
}

Config for all things related to p2p layer.

func DefaultConfig added in v1.0.0

func DefaultConfig() Config

DefaultConfig config.

type Host added in v1.0.0

type Host struct {
	host.Host
	*pubsub.PubSub
	// contains filtered or unexported fields
}

Host is a conveniency wrapper for all p2p related functionality required to run a full spacemesh node.

func New

func New(_ context.Context, logger log.Log, cfg Config, genesisID types.Hash20, opts ...Opt) (*Host, error)

New initializes libp2p host configured for spacemesh.

func Upgrade added in v1.0.0

func Upgrade(h host.Host, genesisID types.Hash20, opts ...Opt) (*Host, error)

Upgrade creates Host instance from host.Host.

func (*Host) GetPeers added in v1.0.0

func (fh *Host) GetPeers() []Peer

GetPeers returns connected peers.

func (*Host) PeerCount added in v1.0.0

func (fh *Host) PeerCount() uint64

PeerCount returns number of connected peers.

func (*Host) Stop added in v1.0.0

func (fh *Host) Stop() error

Stop background workers and release external resources.

type Opt added in v1.0.0

type Opt func(fh *Host)

Opt is for configuring Host.

func WithConfig added in v1.0.0

func WithConfig(cfg Config) Opt

WithConfig sets Config for Host.

func WithContext added in v1.0.0

func WithContext(ctx context.Context) Opt

WithContext set context for Host.

func WithLog added in v1.0.0

func WithLog(logger log.Log) Opt

WithLog configures logger for Host.

func WithNodeReporter added in v1.0.0

func WithNodeReporter(reporter func()) Opt

WithNodeReporter updates reporter that is notified every time when node added or removed a peer.

type Peer

type Peer = peer.ID

Peer is an alias to libp2p's peer.ID.

const NoPeer Peer = ""

NoPeer is used when peer doesn't matter.

Directories

Path Synopsis
nolint
nolint
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
nolint
nolint
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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