Documentation ¶
Index ¶
- Constants
- func PeerAddrsToAddrInfo(addrs []string) ([]lp2ppeer.AddrInfo, error)
- type BootstrapConfig
- type Bootstrapper
- type CallbackFn
- type Config
- type MockNetwork
- func (mock *MockNetwork) CloseConnection(pid peer.ID)
- func (mock *MockNetwork) JoinDownloadTopic() error
- func (mock *MockNetwork) JoinTopics(callbackFn CallbackFn) error
- func (mock *MockNetwork) LeaveDownloadTopic()
- func (mock *MockNetwork) PublishMessage(msg *message.Message) error
- func (mock *MockNetwork) ReceivingMessageFromOtherPeer(initiator peer.ID, pld payload.Payload)
- func (mock *MockNetwork) SelfID() peer.ID
- func (mock *MockNetwork) SendMessageToOthePeer(msg *message.Message)
- func (mock *MockNetwork) Start() error
- func (mock *MockNetwork) Stop()
- type Network
Constants ¶
const DiscoveryInterval = time.Hour
DiscoveryInterval is how often we re-publish our mDNS records.
const DiscoveryServiceTag = "pubsub-zarb"
DiscoveryServiceTag is used in our mDNS advertisements to discover other peers.
Variables ¶
This section is empty.
Functions ¶
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 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 ¶
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()