Documentation ¶
Index ¶
- Constants
- Variables
- func GetInboundMessagesByPeer() map[string]int
- func GetInboundPeerMessages() map[string][]PeerMessageInOut
- func GetOutboundMessagesByPeer() map[string]int
- func GetOutboundPeerMessages() map[string][]PeerMessageInOut
- type Config
- type ConnState
- type MessageListeners
- type Peer
- func (peerObj *Peer) CheckHashPool(hash string) bool
- func (peerObj Peer) GetConfig() Config
- func (peerObj Peer) GetHost() host.Host
- func (peerObj Peer) GetListeningAddress() common.SimpleAddr
- func (peerObj *Peer) GetPeerConnByPeerID(peerID string) *PeerConn
- func (peerObj *Peer) GetPeerConnOfAll() []*PeerConn
- func (peerObj Peer) GetPeerConns() map[string]*PeerConn
- func (peerObj Peer) GetPeerConnsMtx() *sync.Mutex
- func (peerObj Peer) GetPeerID() peer.ID
- func (peerObj Peer) GetPendingPeers() map[string]*Peer
- func (peerObj Peer) GetPort() string
- func (peerObj Peer) GetPublicKey() (string, string)
- func (peerObj Peer) GetRawAddress() string
- func (peerObj Peer) GetTargetAddress() ma.Multiaddr
- func (peerObj *Peer) HashToPool(hash string) error
- func (peerObj *Peer) Init(protocolIDStr string) error
- func (peerObj *Peer) PushConn(peer *Peer, cConn chan *PeerConn)
- func (peerObj *Peer) QueueMessageWithEncoding(msg wire.Message, doneChan chan<- struct{}, msgType byte, msgShard *byte)
- func (peerObj *Peer) SetConfig(config Config)
- func (peerObj *Peer) SetListeningAddress(v common.SimpleAddr)
- func (peerObj *Peer) SetPeerConns(data map[string]*PeerConn)
- func (peerObj *Peer) SetPeerConnsMtx(v *sync.Mutex)
- func (peerObj *Peer) SetPeerID(peerID peer.ID)
- func (peerObj *Peer) SetPendingPeers(data map[string]*Peer)
- func (peerObj *Peer) SetPublicKey(publicKey string, keyType string)
- func (peerObj *Peer) SetRawAddress(rawAddress string)
- func (peerObj *Peer) SetSeed(v int64)
- func (peerObj *Peer) SetTargetAddress(targetAddress ma.Multiaddr)
- func (peerObj *Peer) Start()
- func (peerObj *Peer) Stop()
- type PeerConn
- func (p *PeerConn) ForceClose()
- func (peerConn *PeerConn) GetIsOutbound() bool
- func (p PeerConn) GetListenerPeer() *Peer
- func (p PeerConn) GetRemotePeer() *Peer
- func (p PeerConn) GetRemotePeerID() peer.ID
- func (p PeerConn) GetRemoteRawAddress() string
- func (peerConn *PeerConn) QueueMessageWithBytes(msgBytes *[]byte, doneChan chan<- struct{})
- func (peerConn *PeerConn) QueueMessageWithEncoding(msg wire.Message, doneChan chan<- struct{}, forwardType byte, ...)
- func (p *PeerConn) SetListenerPeer(v *Peer)
- func (p *PeerConn) SetRemotePeer(v *Peer)
- func (p *PeerConn) SetRemotePeerID(v peer.ID)
- func (p *PeerConn) SetVerValid(v bool)
- func (p *PeerConn) VerAckReceived() bool
- type PeerError
- type PeerLoger
- type PeerMessageInOut
Constants ¶
const ( MessageToAll = byte('a') MessageToShard = byte('s') MessageToPeer = byte('p') MessageToBeacon = byte('b') )
const ( // RemotePeer err UnexpectedError = iota PeerGenerateKeyPairError CreateP2PNodeError CreateP2PAddressError GetPeerIdFromProtocolError OpeningStreamP2PError HandleNewStreamError // PeerConn err HandleMessageCheckResponse HandleMessageCheck LimitByteForMessageError ReadStringMessageError HexDecodeMessageError UnzipMessageError HashToPoolError MessageTypeError CheckForwardError ParseJsonMessageError CacheMessageHashError UnhandleMessageTypeError )
const (
PrefixProtocolID = "/incognito/"
)
Variables ¶
var ErrCodeMessage = map[int]struct { Code int Message string }{ UnexpectedError: {-1001, "Unexpected"}, PeerGenerateKeyPairError: {-1001, "Can not generate key pair with reader"}, CreateP2PNodeError: {-1002, "Can not create libp2p node"}, CreateP2PAddressError: {-1003, "Can not create libp2p address for node"}, GetPeerIdFromProtocolError: {-1004, "Can not get peer id from protocol"}, OpeningStreamP2PError: {-1005, "Fail in opening stream "}, HandleNewStreamError: {-1006, "Handle new stream error"}, HandleMessageCheckResponse: {-2001, "Handle message check response error"}, HandleMessageCheck: {-2002, "Handle message check error"}, LimitByteForMessageError: {-2003, "Limit byte for message"}, ReadStringMessageError: {-2004, "Read message error"}, HexDecodeMessageError: {-2005, "Hex decode message error"}, UnzipMessageError: {-2006, "Unzip message error"}, HashToPoolError: {-2007, "Insert hash of message to pool error"}, MessageTypeError: {-2008, "Can not find particular message for message cmd type"}, CheckForwardError: {-2009, "Check forward error"}, ParseJsonMessageError: {-2010, "Can not parse struct from json message"}, CacheMessageHashError: {-2011, "Cache messagse hash error"}, UnhandleMessageTypeError: {-2012, "Received unhandled message of type"}, }
var Logger = PeerLoger{}
Global instant to use
Functions ¶
func GetInboundPeerMessages ¶
func GetInboundPeerMessages() map[string][]PeerMessageInOut
func GetOutboundPeerMessages ¶
func GetOutboundPeerMessages() map[string][]PeerMessageInOut
Types ¶
type Config ¶
type Config struct { MessageListeners MessageListeners // UserKeySet *incognitokey.KeySet MaxOutPeers int MaxInPeers int MaxPeers int ConsensusEngine interface { GetCurrentMiningPublicKey() (publickey string, keyType string) VerifyData(data []byte, sig string, publicKey string, consensusType string) error SignDataWithCurrentMiningKey(data []byte) (string, string, string, error) } }
config is the struct to hold configuration options useful to RemotePeer.
type MessageListeners ¶
type MessageListeners struct { OnTx func(p *PeerConn, msg *wire.MessageTx) OnTxPrivacyToken func(p *PeerConn, msg *wire.MessageTxPrivacyToken) OnBlockShard func(p *PeerConn, msg *wire.MessageBlockShard) OnBlockBeacon func(p *PeerConn, msg *wire.MessageBlockBeacon) OnCrossShard func(p *PeerConn, msg *wire.MessageCrossShard) OnGetBlockBeacon func(p *PeerConn, msg *wire.MessageGetBlockBeacon) OnGetBlockShard func(p *PeerConn, msg *wire.MessageGetBlockShard) OnGetCrossShard func(p *PeerConn, msg *wire.MessageGetCrossShard) OnVersion func(p *PeerConn, msg *wire.MessageVersion) OnVerAck func(p *PeerConn, msg *wire.MessageVerAck) OnGetAddr func(p *PeerConn, msg *wire.MessageGetAddr) OnAddr func(p *PeerConn, msg *wire.MessageAddr) //PBFT OnBFTMsg func(p *PeerConn, msg wire.Message) OnPeerState func(p *PeerConn, msg *wire.MessagePeerState) OnFinishSync func(p *PeerConn, msg *wire.MessageFinishSync) OnFeatureMsg func(p *PeerConn, msg *wire.MessageFeature) PushRawBytesToShard func(p *PeerConn, msgBytes *[]byte, shard byte) error PushRawBytesToBeacon func(p *PeerConn, msgBytes *[]byte) error GetCurrentRoleShard func() (string, *byte) }
// MessageListeners defines callback function pointers to invoke with message // listeners for a peer. Any listener which is not set to a concrete callback // during peer initialization is ignored. Execution of multiple message // listeners occurs serially, so one callback blocks the execution of the next. // // NOTE: Unless otherwise documented, these listeners must NOT directly call any // blocking calls (such as WaitForShutdown) on the peer instance since the input // handler goroutine blocks until the callback has completed. Doing so will // result in a deadlock.
type Peer ¶
type Peer struct { // public field HandleConnected func(peerConn *PeerConn) HandleDisconnected func(peerConn *PeerConn) HandleFailed func(peerConn *PeerConn) // contains filtered or unexported fields }
RemotePeer is present for libp2p node data
func (*Peer) CheckHashPool ¶
func (Peer) GetListeningAddress ¶
func (peerObj Peer) GetListeningAddress() common.SimpleAddr
func (*Peer) GetPeerConnByPeerID ¶
func (*Peer) GetPeerConnOfAll ¶
GetPeerConnOfAll - return all Peer connection to other peers
func (Peer) GetPeerConns ¶
func (Peer) GetPeerConnsMtx ¶
func (Peer) GetPendingPeers ¶
func (Peer) GetPublicKey ¶
GetPublicKey return publicKey and keyType
func (Peer) GetRawAddress ¶
func (Peer) GetTargetAddress ¶
func (*Peer) HashToPool ¶
func (*Peer) QueueMessageWithEncoding ¶
func (peerObj *Peer) QueueMessageWithEncoding(msg wire.Message, doneChan chan<- struct{}, msgType byte, msgShard *byte)
QueueMessageWithEncoding adds the passed Incognito message to the peer send queue. This function is identical to QueueMessage, however it allows the caller to specify the wire encoding type that should be used when encoding/decoding blocks and transactions.
This function is safe for concurrent access.
func (*Peer) SetListeningAddress ¶
func (peerObj *Peer) SetListeningAddress(v common.SimpleAddr)
func (*Peer) SetPeerConns ¶
func (*Peer) SetPeerConnsMtx ¶
func (*Peer) SetPendingPeers ¶
func (*Peer) SetPublicKey ¶
func (*Peer) SetRawAddress ¶
func (*Peer) SetTargetAddress ¶
type PeerConn ¶
type PeerConn struct { HandleConnected func(peerConn *PeerConn) HandleDisconnected func(peerConn *PeerConn) HandleFailed func(peerConn *PeerConn) // contains filtered or unexported fields }
func (*PeerConn) ForceClose ¶
func (p *PeerConn) ForceClose()
ForceClose - set flag and close channel
func (PeerConn) GetListenerPeer ¶
func (PeerConn) GetRemotePeer ¶
func (PeerConn) GetRemotePeerID ¶
func (PeerConn) GetRemoteRawAddress ¶
func (*PeerConn) QueueMessageWithBytes ¶
QueueMessageWithBytes -
func (*PeerConn) QueueMessageWithEncoding ¶
func (peerConn *PeerConn) QueueMessageWithEncoding(msg wire.Message, doneChan chan<- struct{}, forwardType byte, forwardValue *byte)
QueueMessageWithEncoding adds the passed Incognito message to the peer send queue. This function is identical to QueueMessage, however it allows the caller to specify the wire encoding type that should be used when encoding/decoding blocks and transactions.
This function is safe for concurrent access.