Documentation
¶
Index ¶
- Constants
- func ConnectAsync(ctx context.Context, h lp2phost.Host, addrInfo lp2ppeer.AddrInfo, ...)
- func ConnectSync(ctx context.Context, h lp2phost.Host, addrInfo lp2ppeer.AddrInfo) error
- func HasPID(pids []lp2ppeer.ID, pid lp2ppeer.ID) bool
- func IPToMultiAddr(ip string, port int) (multiaddr.Multiaddr, error)
- func MakeAddrInfos(addrs []string) ([]lp2ppeer.AddrInfo, error)
- func MakeMultiAddrs(addrs []string) ([]multiaddr.Multiaddr, error)
- func MessageIDFunc(m *lp2pspb.Message) string
- func PrivateSubnets() []*net.IPNet
- func SubnetsToFilters(subnets []*net.IPNet, action multiaddr.Action) *multiaddr.Filters
- type Config
- func (conf *Config) BasicCheck() error
- func (conf *Config) BootstrapAddrInfos() []lp2ppeer.AddrInfo
- func (conf *Config) CheckIsBootstrapper(pid lp2pcore.PeerID)
- func (conf *Config) ListenAddrs() []multiaddr.Multiaddr
- func (conf *Config) MinConns() int
- func (conf *Config) PublicAddr() multiaddr.Multiaddr
- type ConfigError
- type ConnectEvent
- type ConnectionGater
- func (g *ConnectionGater) InterceptAccept(cma lp2pnetwork.ConnMultiaddrs) bool
- func (g *ConnectionGater) InterceptAddrDial(pid lp2ppeer.ID, ma multiaddr.Multiaddr) bool
- func (g *ConnectionGater) InterceptPeerDial(pid lp2ppeer.ID) bool
- func (*ConnectionGater) InterceptSecured(_ lp2pnetwork.Direction, _ lp2ppeer.ID, _ lp2pnetwork.ConnMultiaddrs) bool
- func (*ConnectionGater) InterceptUpgraded(_ lp2pnetwork.Conn) (bool, lp2pcontrol.DisconnectReason)
- func (g *ConnectionGater) SetPeerManager(peerMgr *peerMgr)
- type DisconnectEvent
- type Event
- type EventType
- type GossipMessage
- type InvalidTopicError
- type LibP2PError
- type MockNetwork
- func (m *MockNetwork) AddAnotherNetwork(otherNet *MockNetwork, direction lp2pnetwork.Direction)
- func (m *MockNetwork) Broadcast(data []byte, _ TopicID)
- func (m *MockNetwork) CloseConnection(pid lp2ppeer.ID)
- func (*MockNetwork) HostAddrs() []string
- func (m *MockNetwork) IsClosed(pid lp2ppeer.ID) bool
- func (*MockNetwork) JoinTopic(_ TopicID, _ PropagationEvaluator) error
- func (*MockNetwork) Name() string
- func (m *MockNetwork) NumConnectedPeers() int
- func (m *MockNetwork) NumInbound() int
- func (m *MockNetwork) NumOutbound() int
- func (*MockNetwork) Protect(_ lp2pcore.PeerID, _ string)
- func (*MockNetwork) Protocols() []string
- func (*MockNetwork) ReachabilityStatus() string
- func (m *MockNetwork) SelfID() lp2ppeer.ID
- func (m *MockNetwork) SendTo(data []byte, pid lp2pcore.PeerID)
- func (*MockNetwork) Start() error
- func (*MockNetwork) Stop()
- type Network
- type NotSubscribedError
- type NotifeeService
- func (s *NotifeeService) Connected(_ lp2pnetwork.Network, conn lp2pnetwork.Conn)
- func (s *NotifeeService) Disconnected(_ lp2pnetwork.Network, conn lp2pnetwork.Conn)
- func (s *NotifeeService) Listen(_ lp2pnetwork.Network, ma multiaddr.Multiaddr)
- func (s *NotifeeService) ListenClose(_ lp2pnetwork.Network, ma multiaddr.Multiaddr)
- func (s *NotifeeService) Reachability() lp2pnetwork.Reachability
- func (s *NotifeeService) Start()
- func (s *NotifeeService) Stop()
- type PropagationEvaluator
- type PropagationPolicy
- type ProtocolsEvents
- type PublishData
- type StreamMessage
- type TopicID
Constants ¶
const ( // Propagate means the message should be forwarded to other peers in the network. Propagate = PropagationPolicy(0) // DropButConsume means the message should not be forwarded but should be processed locally. DropButConsume = PropagationPolicy(1) // Drop means the message should be discarded without any further processing. Drop = PropagationPolicy(2) )
Variables ¶
This section is empty.
Functions ¶
func ConnectAsync ¶
func ConnectSync ¶
func MakeAddrInfos ¶
MakeAddrInfos converts a slice of string peer addresses to AddrInfo.
func MakeMultiAddrs ¶
MakeMultiAddrs converts a slice of string peer addresses to MultiAddress.
func MessageIDFunc ¶
func PrivateSubnets ¶
Types ¶
type Config ¶
type Config struct {
NetworkKey string `toml:"network_key"`
PublicAddrString string `toml:"public_addr"`
ListenAddrStrings []string `toml:"listen_addrs"`
BootstrapAddrStrings []string `toml:"bootstrap_addrs"`
MaxConns int `toml:"max_connections"`
EnableUDP bool `toml:"enable_udp"`
EnableNATService bool `toml:"enable_nat_service"`
EnableUPnP bool `toml:"enable_upnp"`
EnableRelay bool `toml:"enable_relay"`
EnableRelayService bool `toml:"enable_relay_service"`
EnableMdns bool `toml:"enable_mdns"`
EnableMetrics bool `toml:"enable_metrics"`
ForcePrivateNetwork bool `toml:"force_private_network"`
// Private configs
NetworkName string `toml:"-"`
DefaultPort int `toml:"-"`
DefaultBootstrapAddrStrings []string `toml:"-"`
IsBootstrapper bool `toml:"-"`
PeerStorePath string `toml:"-"`
StreamTimeout time.Duration `toml:"-"`
CheckConnectivityInterval time.Duration `toml:"-"`
MaxGossipMessageSize int `toml:"-"`
MaxStreamMessageSize int `toml:"-"`
}
func DefaultConfig ¶
func DefaultConfig() *Config
func (*Config) BasicCheck ¶
BasicCheck performs basic checks on the configuration.
func (*Config) BootstrapAddrInfos ¶
func (*Config) CheckIsBootstrapper ¶
func (*Config) ListenAddrs ¶
func (*Config) PublicAddr ¶
type ConfigError ¶
type ConfigError struct {
Reason string
}
ConfigError is returned when the config is not valid with a descriptive Reason message.
func (ConfigError) Error ¶
func (e ConfigError) Error() string
type ConnectEvent ¶
type ConnectEvent struct {
PeerID lp2pcore.PeerID
RemoteAddress string
Direction lp2pnetwork.Direction
}
ConnectEvent represents a peer connection event.
func (*ConnectEvent) Type ¶
func (*ConnectEvent) Type() EventType
type ConnectionGater ¶
type ConnectionGater struct {
// contains filtered or unexported fields
}
func NewConnectionGater ¶
func NewConnectionGater(conf *Config, log *logger.SubLogger) (*ConnectionGater, error)
func (*ConnectionGater) InterceptAccept ¶
func (g *ConnectionGater) InterceptAccept(cma lp2pnetwork.ConnMultiaddrs) bool
func (*ConnectionGater) InterceptAddrDial ¶
func (*ConnectionGater) InterceptPeerDial ¶
func (g *ConnectionGater) InterceptPeerDial(pid lp2ppeer.ID) bool
func (*ConnectionGater) InterceptSecured ¶
func (*ConnectionGater) InterceptSecured(_ lp2pnetwork.Direction, _ lp2ppeer.ID, _ lp2pnetwork.ConnMultiaddrs) bool
func (*ConnectionGater) InterceptUpgraded ¶
func (*ConnectionGater) InterceptUpgraded(_ lp2pnetwork.Conn) (bool, lp2pcontrol.DisconnectReason)
func (*ConnectionGater) SetPeerManager ¶
func (g *ConnectionGater) SetPeerManager(peerMgr *peerMgr)
type DisconnectEvent ¶
DisconnectEvent represents a peer disconnection event.
func (*DisconnectEvent) Type ¶
func (*DisconnectEvent) Type() EventType
type GossipMessage ¶
GossipMessage represents message from PubSub module. `From` is the ID of the peer that we received a message from.
func (*GossipMessage) Type ¶
func (*GossipMessage) Type() EventType
type InvalidTopicError ¶
type InvalidTopicError struct {
TopicID TopicID
}
InvalidTopicError is returned when the Pub-Sub topic is invalid.
func (InvalidTopicError) Error ¶
func (e InvalidTopicError) Error() string
type LibP2PError ¶
type LibP2PError struct {
Err error
}
LibP2PError is returned when an underlying libp2p operation encounters an error.
func (LibP2PError) Error ¶
func (e LibP2PError) Error() string
type MockNetwork ¶
type MockNetwork struct {
*testsuite.TestSuite
ID lp2ppeer.ID
PublishCh chan PublishData
EventPipe pipeline.Pipeline[Event]
OtherNets map[lp2ppeer.ID]*MockNetwork
// contains filtered or unexported fields
}
func MockingNetwork ¶
func MockingNetwork(ts *testsuite.TestSuite, pid lp2ppeer.ID) *MockNetwork
func (*MockNetwork) AddAnotherNetwork ¶
func (m *MockNetwork) AddAnotherNetwork(otherNet *MockNetwork, direction lp2pnetwork.Direction)
func (*MockNetwork) Broadcast ¶
func (m *MockNetwork) Broadcast(data []byte, _ TopicID)
func (*MockNetwork) CloseConnection ¶
func (m *MockNetwork) CloseConnection(pid lp2ppeer.ID)
func (*MockNetwork) HostAddrs ¶
func (*MockNetwork) HostAddrs() []string
func (*MockNetwork) JoinTopic ¶
func (*MockNetwork) JoinTopic(_ TopicID, _ PropagationEvaluator) error
func (*MockNetwork) Name ¶
func (*MockNetwork) Name() string
func (*MockNetwork) NumConnectedPeers ¶
func (m *MockNetwork) NumConnectedPeers() int
func (*MockNetwork) NumInbound ¶
func (m *MockNetwork) NumInbound() int
func (*MockNetwork) NumOutbound ¶
func (m *MockNetwork) NumOutbound() int
func (*MockNetwork) Protocols ¶
func (*MockNetwork) Protocols() []string
func (*MockNetwork) ReachabilityStatus ¶
func (*MockNetwork) ReachabilityStatus() string
func (*MockNetwork) SelfID ¶
func (m *MockNetwork) SelfID() lp2ppeer.ID
func (*MockNetwork) Start ¶
func (*MockNetwork) Start() error
func (*MockNetwork) Stop ¶
func (*MockNetwork) Stop()
type Network ¶
type Network interface {
Start() error
Stop()
Protect(lp2pcore.PeerID, string)
Broadcast([]byte, TopicID)
SendTo([]byte, lp2pcore.PeerID)
JoinTopic(TopicID, PropagationEvaluator) error
CloseConnection(lp2pcore.PeerID)
SelfID() lp2pcore.PeerID
NumConnectedPeers() int
NumInbound() int
NumOutbound() int
ReachabilityStatus() string
HostAddrs() []string
Name() string
Protocols() []string
}
type NotSubscribedError ¶
type NotSubscribedError struct {
TopicID TopicID
}
NotSubscribedError is returned when the peer is not subscribed to a specific topic.
func (NotSubscribedError) Error ¶
func (e NotSubscribedError) Error() string
type NotifeeService ¶
type NotifeeService struct {
// contains filtered or unexported fields
}
func (*NotifeeService) Connected ¶
func (s *NotifeeService) Connected(_ lp2pnetwork.Network, conn lp2pnetwork.Conn)
func (*NotifeeService) Disconnected ¶
func (s *NotifeeService) Disconnected(_ lp2pnetwork.Network, conn lp2pnetwork.Conn)
func (*NotifeeService) Listen ¶
func (s *NotifeeService) Listen(_ lp2pnetwork.Network, ma multiaddr.Multiaddr)
func (*NotifeeService) ListenClose ¶
func (s *NotifeeService) ListenClose(_ lp2pnetwork.Network, ma multiaddr.Multiaddr)
ListenClose is called when the peer stops listening on an address.
func (*NotifeeService) Reachability ¶
func (s *NotifeeService) Reachability() lp2pnetwork.Reachability
func (*NotifeeService) Start ¶
func (s *NotifeeService) Start()
func (*NotifeeService) Stop ¶
func (s *NotifeeService) Stop()
type PropagationEvaluator ¶
type PropagationEvaluator func(*GossipMessage) PropagationPolicy
PropagationEvaluator is a function that evaluates how a gossip message should propagate.
type PropagationPolicy ¶
type PropagationPolicy int
PropagationPolicy defines the possible actions for how a gossip message should propagate.
type ProtocolsEvents ¶
ProtocolsEvents represents updating protocols event.
func (*ProtocolsEvents) Type ¶
func (*ProtocolsEvents) Type() EventType
type PublishData ¶
type StreamMessage ¶
type StreamMessage struct {
From lp2pcore.PeerID
Reader io.ReadCloser
}
StreamMessage represents message from Stream module. `From` is the ID of the peer that we received a message from.
func (*StreamMessage) Type ¶
func (*StreamMessage) Type() EventType