connmanager

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnexpectedError = iota
	GetPeerIdError
	ConnectError
	StartError
	StopError
	NotAcceptConnectionError
)

Variables

View Source
var ErrCodeMessage = map[int]struct {
	Code    int
	Message string
}{
	UnexpectedError:          {-1, "Unexpected error"},
	GetPeerIdError:           {-2, "Get peer id fail"},
	ConnectError:             {-3, "Connect error"},
	StartError:               {-4, "Start error"},
	StopError:                {-5, "Stop errior"},
	NotAcceptConnectionError: {-6, "Not accept connection"},
}

Global instant to use

Functions

This section is empty.

Types

type Config

type Config struct {
	ExternalAddress    string
	MaxPeersSameShard  int
	MaxPeersOtherShard int
	MaxPeersOther      int
	MaxPeersNoShard    int
	MaxPeersBeacon     int
	// ListenerPeers defines a slice of listeners for which the connection
	// manager will take ownership of and accept connections.  When a
	// connection is accepted, the OnAccept handler will be invoked with the
	// connection.  Since the connection manager takes ownership of these
	// listeners, they will be closed when the connection manager is
	// stopped.
	//
	// This field will not have any effect if the OnAccept field is not
	// also specified.  It may be nil if the caller does not wish to listen
	// for incoming connections.
	ListenerPeer *peer.Peer

	// OnInboundAccept is a callback that is fired when an inbound connection is accepted
	OnInboundAccept func(peerConn *peer.PeerConn)

	//OnOutboundConnection is a callback that is fired when an outbound connection is established
	OnOutboundConnection func(peerConn *peer.PeerConn)

	//OnOutboundDisconnection is a callback that is fired when an outbound connection is disconnected
	OnOutboundDisconnection func(peerConn *peer.PeerConn)

	DiscoverPeers        bool
	DiscoverPeersAddress string
	ConsensusState       *ConsensusState
}

type ConnManager

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

func New

func New(cfg *Config) *ConnManager

New - init an object connManager and return pointer to object

func (*ConnManager) CheckForAcceptConn

func (connManager *ConnManager) CheckForAcceptConn(peerConn *peer.PeerConn) (bool, error)

CheckForAcceptConn - return true if our connection manager can accept a new connection from new peer

func (*ConnManager) Connect

func (connManager *ConnManager) Connect(addr string, publicKey string, publicKeyType string, cConn chan *peer.PeerConn) error

Connect assigns an id and dials a connection to the address of the connection request.

func (*ConnManager) DropAllConnections

func (connManager *ConnManager) DropAllConnections()

func (ConnManager) GetConfig

func (connManager ConnManager) GetConfig() *Config

func (*ConnManager) GetConnOfRelayNode

func (connManager *ConnManager) GetConnOfRelayNode() []*peer.PeerConn

GetConnOfRelayNode - return connection of relay nodes

func (*ConnManager) GetCurrentRoleShard

func (connManager *ConnManager) GetCurrentRoleShard() (string, *byte)

GetCurrentRoleShard - return current role in shard of connected peer

func (ConnManager) GetListeningPeer

func (connManager ConnManager) GetListeningPeer() *peer.Peer

func (*ConnManager) GetPeerConnOfAll

func (connManager *ConnManager) GetPeerConnOfAll() []*peer.PeerConn

GetPeerConnOfAll - return all Peer connection of node

func (*ConnManager) GetPeerConnOfBeacon

func (connManager *ConnManager) GetPeerConnOfBeacon() []*peer.PeerConn

GetPeerConnOfBeacon - return peer connection of nodes which are beacon committee

func (*ConnManager) GetPeerConnOfPublicKey

func (connManager *ConnManager) GetPeerConnOfPublicKey(publicKey string) []*peer.PeerConn

GetPeerConnOfPublicKey - return PeerConn from public key

func (*ConnManager) GetPeerConnOfShard

func (connManager *ConnManager) GetPeerConnOfShard(shard byte) []*peer.PeerConn

GetPeerConnOfShard - return peer connection of shard

func (*ConnManager) GetPeerId

func (connManager *ConnManager) GetPeerId(addr string) (string, error)

GetPeerId return peer id from connection address

func (*ConnManager) Start

func (connManager *ConnManager) Start(discoverPeerAddress string) error

func (*ConnManager) Stop

func (connManager *ConnManager) Stop() error

Stop gracefully shuts down the connection manager.

func (*ConnManager) UpdateConsensusState

func (connManager *ConnManager) UpdateConsensusState(role string, userPbk string, currentShard *byte, beaconCommittee []string, shardCommittee map[byte][]string) bool

type ConnManagerError

type ConnManagerError struct {
	Code    int
	Message string
	// contains filtered or unexported fields
}

func NewConnManagerError

func NewConnManagerError(key int, err error) *ConnManagerError

func (ConnManagerError) Error

func (e ConnManagerError) Error() string

type ConnManagerLogger

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

func (*ConnManagerLogger) Init

func (connManagerLogger *ConnManagerLogger) Init(inst common.Logger)

type ConsensusState

type ConsensusState struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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