messenger

package
v0.0.0-...-4d9f4f2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fuzz

func Fuzz(data []byte) int

Types

type AddrBook

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

AddrBook - concurrency safe peer address manager.

func NewAddrBook

func NewAddrBook(filePath string, routabilityStrict bool) *AddrBook

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 (a *AddrBook) NeedMoreAddrs() bool

func (*AddrBook) OnStart

func (a *AddrBook) OnStart() error

OnStart implements Service.

func (*AddrBook) OnStop

func (a *AddrBook) OnStop()

OnStop implements Service.

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.

func (*AddrBook) Save

func (a *AddrBook) Save()

Save saves the book.

func (*AddrBook) Size

func (a *AddrBook) Size() int

func (*AddrBook) Wait

func (a *AddrBook) Wait()

type InboundCallback

type InboundCallback func(peer *pr.Peer, err error)

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

func (msgr *Messenger) AttachMessageHandlersToPeer(peer *pr.Peer)

AttachMessageHandlersToPeer attaches the registered message handlers to the given peer

func (*Messenger) Broadcast

func (msgr *Messenger) Broadcast(message p2ptypes.Message) (successes chan bool)

Broadcast broadcasts the given message to all the connected peers

func (*Messenger) BroadcastToNeighbors

func (msgr *Messenger) BroadcastToNeighbors(message p2ptypes.Message, maxNumPeersToBroadcast int) (successes chan bool)

BroadcastToNeighbors broadcasts the given message to neighbors

func (*Messenger) ID

func (msgr *Messenger) ID() string

ID returns the ID of the current node

func (*Messenger) PeerExists

func (msgr *Messenger) PeerExists(peerID string) bool

PeerExists indicates if the given peerID is a neighboring peer

func (*Messenger) Peers

func (msgr *Messenger) Peers() []string

Peers returns the IDs of all peers

func (*Messenger) RegisterMessageHandler

func (msgr *Messenger) RegisterMessageHandler(msgHandler p2p.MessageHandler)

RegisterMessageHandler registers the message handler

func (*Messenger) Send

func (msgr *Messenger) Send(peerID string, message p2ptypes.Message) bool

Send sends the given message to the specified peer

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

func (*Messenger) Start

func (msgr *Messenger) Start(ctx context.Context) error

Start is called when the Messenger starts

func (*Messenger) Stop

func (msgr *Messenger) Stop()

Stop is called when the Messenger stops

func (*Messenger) Wait

func (msgr *Messenger) Wait()

Wait suspends the caller goroutine

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

func (*NATManager) Wait

func (nmgr *NATManager) Wait()

Wait suspends the caller goroutine

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

type PeerDiscoveryManagerConfig struct {
	MaxNumPeers        int
	SufficientNumPeers uint
}

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

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

Jump to

Keyboard shortcuts

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