network

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const DiscoveryInterval = time.Hour

DiscoveryInterval is how often we re-publish our mDNS records.

View Source
const DiscoveryServiceTag = "pubsub-zarb"

DiscoveryServiceTag is used in our mDNS advertisements to discover other peers.

Variables

This section is empty.

Functions

func PeerAddrsToAddrInfo

func PeerAddrsToAddrInfo(addrs []string) ([]lp2ppeer.AddrInfo, error)

PeerAddrsToAddrInfo converts a slice of string peer addresses to AddrInfo.

Types

type BootstrapConfig

type BootstrapConfig struct {
	// Peers to connect to if we fall below the threshold.
	Addresses []string
	// MinPeerThreshold is the number of connections it attempts to maintain.
	MinThreshold int
	// MaxThreshold is the threshold of maximum number of connections.
	MaxThreshold int
	// Period is the interval at which it periodically checks to see
	// if the threshold is maintained.
	Period time.Duration
}

BootstrapConfig holds all configuration options related to bootstrap nodes

type Bootstrapper added in v1.0.0

type Bootstrapper struct {
	// contains filtered or unexported fields
}

Bootstrapper attempts to keep the p2p host connected to the network by keeping a minimum threshold of connections. If the threshold isn't met it connects to a random subset of the bootstrap peers. It does not use peer routing to discover new peers. To stop a Bootstrapper cancel the context passed in Start() or call Stop().

func NewBootstrapper added in v1.0.0

func NewBootstrapper(ctx context.Context, h lp2phost.Host, d lp2pnet.Dialer, r lp2prouting.Routing, conf *BootstrapConfig, logger *logger.Logger) *Bootstrapper

NewBootstrapper returns a new Bootstrapper that will attempt to keep connected to the network by connecting to the given bootstrap peers.

func (*Bootstrapper) Start added in v1.0.0

func (b *Bootstrapper) Start()

Start starts the Bootstrapper bootstrapping. Cancel `ctx` or call Stop() to stop it.

func (*Bootstrapper) Stop added in v1.0.0

func (b *Bootstrapper) Stop()

Stop stops the Bootstrapper.

type CallbackFn added in v1.0.0

type CallbackFn func([]byte, peer.ID)

type Config

type Config struct {
	Name             string
	ListenAddress    []string
	NodeKeyFile      string
	EnableNATService bool
	EnableRelay      bool
	EnableMDNS       bool
	EnableKademlia   bool
	Bootstrap        *BootstrapConfig
}

func DefaultConfig

func DefaultConfig() *Config

func TestConfig

func TestConfig() *Config

func (*Config) SanityCheck

func (conf *Config) SanityCheck() error

SanityCheck is a basic checks for config

type MockNetwork

type MockNetwork struct {
	BroadcastCh chan *message.Message

	CallbackFn CallbackFn
	OtherNet   *MockNetwork
	Closed     bool
	// contains filtered or unexported fields
}

func MockingNetwork

func MockingNetwork(id peer.ID) *MockNetwork

func (*MockNetwork) CloseConnection

func (mock *MockNetwork) CloseConnection(pid peer.ID)

func (*MockNetwork) JoinDownloadTopic added in v1.0.0

func (mock *MockNetwork) JoinDownloadTopic() error

func (*MockNetwork) JoinTopics added in v1.0.0

func (mock *MockNetwork) JoinTopics(callbackFn CallbackFn) error

func (*MockNetwork) LeaveDownloadTopic added in v1.0.0

func (mock *MockNetwork) LeaveDownloadTopic()

func (*MockNetwork) PublishMessage added in v1.0.0

func (mock *MockNetwork) PublishMessage(msg *message.Message) error

func (*MockNetwork) ReceivingMessageFromOtherPeer added in v1.0.0

func (mock *MockNetwork) ReceivingMessageFromOtherPeer(initiator peer.ID, pld payload.Payload)

func (*MockNetwork) SelfID

func (mock *MockNetwork) SelfID() peer.ID

func (*MockNetwork) SendMessageToOthePeer added in v1.0.0

func (mock *MockNetwork) SendMessageToOthePeer(msg *message.Message)

func (*MockNetwork) Start

func (mock *MockNetwork) Start() error

func (*MockNetwork) Stop

func (mock *MockNetwork) Stop()

type Network

type Network interface {
	Start() error
	Stop()
	PublishMessage(msg *message.Message) error
	JoinTopics(CallbackFn) error
	JoinDownloadTopic() error
	LeaveDownloadTopic()
	CloseConnection(pid peer.ID)
	SelfID() peer.ID
}

func NewNetwork

func NewNetwork(conf *Config) (Network, error)

Jump to

Keyboard shortcuts

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