Documentation ¶
Index ¶
- func Fuzz(data []byte) int
- type AddrBook
- func (a *AddrBook) AddAddress(addr *nu.NetAddress, src *nu.NetAddress)
- func (a *AddrBook) AddOurAddress(addr *nu.NetAddress)
- func (a *AddrBook) GetSelection() []*nu.NetAddress
- func (a *AddrBook) MarkAttempt(addr *nu.NetAddress)
- func (a *AddrBook) MarkBad(addr *nu.NetAddress)
- func (a *AddrBook) MarkGood(addr *nu.NetAddress)
- func (a *AddrBook) NeedMoreAddrs() bool
- func (a *AddrBook) OnStart() error
- func (a *AddrBook) OnStop()
- func (a *AddrBook) OurAddresses() []*nu.NetAddress
- func (a *AddrBook) PickAddress(newBias int) *nu.NetAddress
- func (a *AddrBook) RemoveAddress(addr *nu.NetAddress)
- func (a *AddrBook) Save()
- func (a *AddrBook) Size() int
- func (a *AddrBook) Wait()
- type InboundCallback
- type InboundPeerListener
- func (ipl *InboundPeerListener) ExternalAddress() *netutil.NetAddress
- func (ipl *InboundPeerListener) InternalAddress() *netutil.NetAddress
- func (ipl *InboundPeerListener) NetListener() net.Listener
- func (ipl *InboundPeerListener) SetInboundCallback(incb InboundCallback)
- func (ipl *InboundPeerListener) Start(ctx context.Context) error
- func (ipl *InboundPeerListener) Stop()
- func (ipl *InboundPeerListener) String() string
- func (ipl *InboundPeerListener) Wait()
- type InboundPeerListenerConfig
- type Messenger
- func (msgr *Messenger) AttachMessageHandlersToPeer(peer *pr.Peer)
- func (msgr *Messenger) Broadcast(message p2ptypes.Message) (successes chan bool)
- func (msgr *Messenger) BroadcastToNeighbors(message p2ptypes.Message, maxNumPeersToBroadcast int) (successes chan bool)
- func (msgr *Messenger) ID() string
- func (msgr *Messenger) PeerExists(peerID string) bool
- func (msgr *Messenger) Peers() []string
- func (msgr *Messenger) RegisterMessageHandler(msgHandler p2p.MessageHandler)
- func (msgr *Messenger) Send(peerID string, message p2ptypes.Message) bool
- func (msgr *Messenger) SetNATManager(natMgr *NATManager)
- func (msgr *Messenger) SetPeerDiscoveryManager(discMgr *PeerDiscoveryManager)
- func (msgr *Messenger) Start(ctx context.Context) error
- func (msgr *Messenger) Stop()
- func (msgr *Messenger) Wait()
- type MessengerConfig
- type NATManager
- func (nmgr *NATManager) DiscoverGateway() error
- func (nmgr *NATManager) EncodeMessage(message interface{}) (common.Bytes, error)
- func (nmgr *NATManager) GetChannelIDs() []common.ChannelIDEnum
- func (nmgr *NATManager) HandleMessage(msg types.Message) error
- func (nmgr *NATManager) NatMapping(port int) (eport int, err error)
- func (nmgr *NATManager) ParseMessage(peerID string, channelID common.ChannelIDEnum, rawMessageBytes common.Bytes) (types.Message, error)
- func (nmgr *NATManager) SetMessenger(msgr *Messenger)
- func (nmgr *NATManager) Start(ctx context.Context) error
- func (nmgr *NATManager) Stop()
- func (nmgr *NATManager) Wait()
- type NATMappingMessage
- type PeerDiscoveryManager
- type PeerDiscoveryManagerConfig
- type PeerDiscoveryMessage
- type PeerDiscoveryMessageHandler
- func (pdmh *PeerDiscoveryMessageHandler) EncodeMessage(message interface{}) (common.Bytes, error)
- func (pdmh *PeerDiscoveryMessageHandler) GetChannelIDs() []common.ChannelIDEnum
- func (pdmh *PeerDiscoveryMessageHandler) HandleMessage(msg types.Message) error
- func (pdmh *PeerDiscoveryMessageHandler) ParseMessage(peerID string, channelID common.ChannelIDEnum, rawMessageBytes common.Bytes) (types.Message, error)
- func (pdmh *PeerDiscoveryMessageHandler) SetDiscoveryCallback(disccb InboundCallback)
- func (pdmh *PeerDiscoveryMessageHandler) Start(ctx context.Context) error
- func (pdmh *PeerDiscoveryMessageHandler) Stop()
- func (pdmh *PeerDiscoveryMessageHandler) Wait()
- type PeerDiscoveryMessageType
- type SeedPeerConnector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AddrBook ¶
type AddrBook struct {
// contains filtered or unexported fields
}
AddrBook - concurrency safe peer address manager.
func NewAddrBook ¶
NewAddrBook creates a new address book. Use Start to begin processing asynchronous address updates.
func (*AddrBook) AddAddress ¶
func (a *AddrBook) AddAddress(addr *nu.NetAddress, src *nu.NetAddress)
NOTE: addr must not be nil
func (*AddrBook) AddOurAddress ¶
func (a *AddrBook) AddOurAddress(addr *nu.NetAddress)
func (*AddrBook) GetSelection ¶
func (a *AddrBook) GetSelection() []*nu.NetAddress
GetSelection randomly selects some addresses (old & new). Suitable for peer-exchange protocols.
func (*AddrBook) MarkAttempt ¶
func (a *AddrBook) MarkAttempt(addr *nu.NetAddress)
func (*AddrBook) MarkBad ¶
func (a *AddrBook) MarkBad(addr *nu.NetAddress)
MarkBad currently just ejects the address. In the future, consider blacklisting.
func (*AddrBook) MarkGood ¶
func (a *AddrBook) MarkGood(addr *nu.NetAddress)
func (*AddrBook) NeedMoreAddrs ¶
func (*AddrBook) OurAddresses ¶
func (a *AddrBook) OurAddresses() []*nu.NetAddress
func (*AddrBook) PickAddress ¶
func (a *AddrBook) PickAddress(newBias int) *nu.NetAddress
Pick an address to connect to with new/old bias.
func (*AddrBook) RemoveAddress ¶
func (a *AddrBook) RemoveAddress(addr *nu.NetAddress)
RemoveAddress removes the address from the book.
type InboundCallback ¶
InboundCallback is called when an inbound peer is created
type InboundPeerListener ¶
type InboundPeerListener struct {
// contains filtered or unexported fields
}
InboundPeerListener models a listener for inbound peer connections
func (*InboundPeerListener) ExternalAddress ¶
func (ipl *InboundPeerListener) ExternalAddress() *netutil.NetAddress
ExternalAddress returns the external address of the current node
func (*InboundPeerListener) InternalAddress ¶
func (ipl *InboundPeerListener) InternalAddress() *netutil.NetAddress
InternalAddress returns the internal address of the current node
func (*InboundPeerListener) NetListener ¶
func (ipl *InboundPeerListener) NetListener() net.Listener
NetListener returns the attached network listener
func (*InboundPeerListener) SetInboundCallback ¶
func (ipl *InboundPeerListener) SetInboundCallback(incb InboundCallback)
SetInboundCallback sets the inbound callback function
func (*InboundPeerListener) Start ¶
func (ipl *InboundPeerListener) Start(ctx context.Context) error
Start is called when the InboundPeerListener instance starts
func (*InboundPeerListener) Stop ¶
func (ipl *InboundPeerListener) Stop()
Stop is called when the InboundPeerListener instance stops
func (*InboundPeerListener) String ¶
func (ipl *InboundPeerListener) String() string
func (*InboundPeerListener) Wait ¶
func (ipl *InboundPeerListener) Wait()
Wait suspends the caller goroutine
type InboundPeerListenerConfig ¶
type InboundPeerListenerConfig struct {
// contains filtered or unexported fields
}
InboundPeerListenerConfig specifies the configuration for the PeerListener instance
func GetDefaultInboundPeerListenerConfig ¶
func GetDefaultInboundPeerListenerConfig() InboundPeerListenerConfig
GetDefaultInboundPeerListenerConfig returns the default configuration for the listeners
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
func CreateMessenger ¶
func CreateMessenger(privKey *crypto.PrivateKey, seedPeerNetAddresses []string, port int, msgrConfig MessengerConfig) (*Messenger, error)
CreateMessenger creates an instance of Messenger
func (*Messenger) AttachMessageHandlersToPeer ¶
AttachMessageHandlersToPeer attaches the registered message handlers to the given peer
func (*Messenger) BroadcastToNeighbors ¶
func (msgr *Messenger) BroadcastToNeighbors(message p2ptypes.Message, maxNumPeersToBroadcast int) (successes chan bool)
BroadcastToNeighbors broadcasts the given message to neighbors
func (*Messenger) PeerExists ¶
PeerExists indicates if the given peerID is a neighboring peer
func (*Messenger) RegisterMessageHandler ¶
func (msgr *Messenger) RegisterMessageHandler(msgHandler p2p.MessageHandler)
RegisterMessageHandler registers the message handler
func (*Messenger) SetNATManager ¶
func (msgr *Messenger) SetNATManager(natMgr *NATManager)
SetPeerDiscoveryManager sets the PeerDiscoveryManager for the Messenger
func (*Messenger) SetPeerDiscoveryManager ¶
func (msgr *Messenger) SetPeerDiscoveryManager(discMgr *PeerDiscoveryManager)
SetPeerDiscoveryManager sets the PeerDiscoveryManager for the Messenger
type MessengerConfig ¶
type MessengerConfig struct {
// contains filtered or unexported fields
}
MessengerConfig specifies the configuration for Messenger
func GetDefaultMessengerConfig ¶
func GetDefaultMessengerConfig() MessengerConfig
GetDefaultMessengerConfig returns the default config for messenger
func (*MessengerConfig) SetAddressBookFilePath ¶
func (msgrConfig *MessengerConfig) SetAddressBookFilePath(filePath string)
SetAddressBookFilePath sets the address book file path
type NATManager ¶
type NATManager struct {
// contains filtered or unexported fields
}
func CreateNATManager ¶
func CreateNATManager(port int) *NATManager
func (*NATManager) DiscoverGateway ¶
func (nmgr *NATManager) DiscoverGateway() error
DiscoverGateway discovers the gateway for the NAT mapping
func (*NATManager) EncodeMessage ¶
func (nmgr *NATManager) EncodeMessage(message interface{}) (common.Bytes, error)
EncodeMessage implements the p2p.MessageHandler interface
func (*NATManager) GetChannelIDs ¶
func (nmgr *NATManager) GetChannelIDs() []common.ChannelIDEnum
GetChannelIDs implements the p2p.MessageHandler interface
func (*NATManager) HandleMessage ¶
func (nmgr *NATManager) HandleMessage(msg types.Message) error
HandleMessage implements the p2p.MessageHandler interface
func (*NATManager) NatMapping ¶
func (nmgr *NATManager) NatMapping(port int) (eport int, err error)
func (*NATManager) ParseMessage ¶
func (nmgr *NATManager) ParseMessage(peerID string, channelID common.ChannelIDEnum, rawMessageBytes common.Bytes) (types.Message, error)
ParseMessage implements the p2p.MessageHandler interface
func (*NATManager) SetMessenger ¶
func (nmgr *NATManager) SetMessenger(msgr *Messenger)
SetMessenger sets the Messenger for the NATManager
func (*NATManager) Start ¶
func (nmgr *NATManager) Start(ctx context.Context) error
Start is called when the NATManager instance starts
func (*NATManager) Stop ¶
func (nmgr *NATManager) Stop()
Stop is called when the NATManager instance stops
type NATMappingMessage ¶
type NATMappingMessage struct {
EPort uint16
}
NatMappingMessage defines the structure of the NAT mapping message
type PeerDiscoveryManager ¶
type PeerDiscoveryManager struct {
// contains filtered or unexported fields
}
PeerDiscoveryManager manages the peer discovery process
func CreatePeerDiscoveryManager ¶
func CreatePeerDiscoveryManager(msgr *Messenger, nodeInfo *p2ptypes.NodeInfo, addrBookFilePath string, routabilityRestrict bool, seedPeerNetAddresses []string, networkProtocol string, localNetworkAddr string, externalPort int, skipUPNP bool, peerTable *pr.PeerTable, config PeerDiscoveryManagerConfig) (*PeerDiscoveryManager, error)
CreatePeerDiscoveryManager creates an instance of the PeerDiscoveryManager
func (*PeerDiscoveryManager) HandlePeerWithErrors ¶
func (discMgr *PeerDiscoveryManager) HandlePeerWithErrors(peer *pr.Peer)
HandlePeerWithErrors handles peers that are in the error state. If the peer is persistent, it will attempt to reconnect to the peer. Otherwise, it disconnects from that peer
func (*PeerDiscoveryManager) SetMessenger ¶
func (discMgr *PeerDiscoveryManager) SetMessenger(msgr *Messenger)
SetMessenger sets the Messenger for the PeerDiscoveryManager
func (*PeerDiscoveryManager) Start ¶
func (discMgr *PeerDiscoveryManager) Start(ctx context.Context) error
Start is called when the PeerDiscoveryManager starts
func (*PeerDiscoveryManager) Stop ¶
func (discMgr *PeerDiscoveryManager) Stop()
Stop is called when the PeerDiscoveryManager stops
func (*PeerDiscoveryManager) Wait ¶
func (discMgr *PeerDiscoveryManager) Wait()
Wait suspends the caller goroutine
type PeerDiscoveryManagerConfig ¶
PeerDiscoveryManagerConfig specifies the configuration for PeerDiscoveryManager
func GetDefaultPeerDiscoveryManagerConfig ¶
func GetDefaultPeerDiscoveryManagerConfig() PeerDiscoveryManagerConfig
GetDefaultPeerDiscoveryManagerConfig returns the default config for the PeerDiscoveryManager
type PeerDiscoveryMessage ¶
type PeerDiscoveryMessage struct { Type PeerDiscoveryMessageType SourcePeerID string Addresses []pr.PeerIDAddress }
PeerDiscoveryMessage defines the structure of the peer discovery message
type PeerDiscoveryMessageHandler ¶
type PeerDiscoveryMessageHandler struct {
// contains filtered or unexported fields
}
PeerDiscoveryMessageHandler implements the MessageHandler interface
func (*PeerDiscoveryMessageHandler) EncodeMessage ¶
func (pdmh *PeerDiscoveryMessageHandler) EncodeMessage(message interface{}) (common.Bytes, error)
EncodeMessage implements the p2p.MessageHandler interface
func (*PeerDiscoveryMessageHandler) GetChannelIDs ¶
func (pdmh *PeerDiscoveryMessageHandler) GetChannelIDs() []common.ChannelIDEnum
GetChannelIDs implements the p2p.MessageHandler interface
func (*PeerDiscoveryMessageHandler) HandleMessage ¶
func (pdmh *PeerDiscoveryMessageHandler) HandleMessage(msg types.Message) error
HandleMessage implements the p2p.MessageHandler interface
func (*PeerDiscoveryMessageHandler) ParseMessage ¶
func (pdmh *PeerDiscoveryMessageHandler) ParseMessage(peerID string, channelID common.ChannelIDEnum, rawMessageBytes common.Bytes) (types.Message, error)
ParseMessage implements the p2p.MessageHandler interface
func (*PeerDiscoveryMessageHandler) SetDiscoveryCallback ¶
func (pdmh *PeerDiscoveryMessageHandler) SetDiscoveryCallback(disccb InboundCallback)
SetDiscoveryCallback sets the discovery callback function
func (*PeerDiscoveryMessageHandler) Start ¶
func (pdmh *PeerDiscoveryMessageHandler) Start(ctx context.Context) error
Start is called when the message handler starts
func (*PeerDiscoveryMessageHandler) Stop ¶
func (pdmh *PeerDiscoveryMessageHandler) Stop()
Stop is called when the message handler stops
func (*PeerDiscoveryMessageHandler) Wait ¶
func (pdmh *PeerDiscoveryMessageHandler) Wait()
Wait suspends the caller goroutine
type PeerDiscoveryMessageType ¶
type PeerDiscoveryMessageType byte
PeerDiscoveryMessageType defines the types of peer discovery message
type SeedPeerConnector ¶
type SeedPeerConnector struct { Connected chan bool // contains filtered or unexported fields }
SeedPeerConnector proactively connects to seed peers
func (*SeedPeerConnector) Start ¶
func (spc *SeedPeerConnector) Start(ctx context.Context) error
Start is called when the SeedPeerConnector starts
func (*SeedPeerConnector) Stop ¶
func (spc *SeedPeerConnector) Stop()
Stop is called when the SeedPeerConnector stops
func (*SeedPeerConnector) Wait ¶
func (spc *SeedPeerConnector) Wait()
Wait suspends the caller goroutine