Documentation
¶
Index ¶
- Constants
- Variables
- func AddrIP(addr net.Addr) net.IP
- func Body2EventLoad(eventType models.EventType, body []byte) (eventLoad []byte)
- func GetEventTypeFromMsgLoad(msgLoad []byte) (models.EventType, error)
- func GetEventTypeFromPayLoad(payLoad []byte) (models.EventType, error)
- func NewP2PServer(con map[string]common.NodeID, bootport uint16, localport uint16, ...) (models.P2PServer, error)
- func PayLoad2Body(payLoad []byte) (eventType models.EventType, body []byte, pub []byte, sig []byte, err error)
- func ReadP2PMsg(msg *Msg) (models.EventType, interface{}, error)
- func SendReasonAndClose(conn net.Conn, enc cipher.Stream, erro error)
- func UnpackP2PMsg(msg *Msg) (eventLoad []byte, eventType models.EventType, body []byte, pub, sig []byte, ...)
- func WriteEventLoad(v interface{}, needSign bool) (eventType models.EventType, eventLoad, pub, sig []byte, err error)
- type CallbackFun
- type CheckPermissionFunc
- type Dialer
- type DiscReason
- type HandShakeReq
- type HandShakeRsp
- type HandShaker
- type HandleMsgFunc
- type Listener
- type Manager
- func (m *Manager) BroadcastFull(info string, skip *common.NodeID, cid common.ChainID, ntp common.NetType, ...) error
- func (m *Manager) BroadcastFullSync(info string, skip *common.NodeID, cid common.ChainID, ntp common.NetType, ...) error
- func (m *Manager) ClearNetWorker(id common.ChainID)
- func (m *Manager) Closer() error
- func (m *Manager) ConnectNet(chaininfo *common.ChainInfos) error
- func (m *Manager) CreateOneNet(cid common.ChainID, ntp common.NetType) error
- func (m *Manager) CreateOrConnectNet(ntp common.NetType, bootChainID, localChandID common.ChainID) error
- func (m *Manager) GetAllNetInfomap() map[common.ChainID]map[common.NodeID]common.NetInfo
- func (m *Manager) GetBootMap() map[string]common.NodeID
- func (m *Manager) GetChainNet(id common.ChainID, netType common.NetType) (map[common.NodeID]net.Addr, bool)
- func (m *Manager) GetDataServer(chainId common.ChainID) *[]common.Dataserver
- func (m *Manager) GetNetInfomap(chainid common.ChainID) (map[common.NodeID]common.NetInfo, bool)
- func (m *Manager) GetNetworker(id common.ChainID) models.Networker
- func (m *Manager) InitChain(id common.ChainID) error
- func (m *Manager) InitNet(chaininfo *common.ChainInfos) error
- func (m *Manager) Initializer() error
- func (m *Manager) IsBootNode(id common.ChainID) bool
- func (m *Manager) Rand(size int, info string, chainId common.ChainID, ntp common.NetType, ...) error
- func (m *Manager) ResetConNet(networker models.Networker, chainid common.ChainID, netType common.NetType) (common.NodeID, error)
- func (m *Manager) ResetNet(chainid common.ChainID, ntp common.NetType) error
- func (m *Manager) ResetOneNet(cid common.ChainID, ntp common.NetType) error
- func (m *Manager) SendToChain(info string, ntp common.NetType, fromChain common.ChainID, ...) error
- func (m *Manager) SendToNode(info string, ntp common.NetType, chainId common.ChainID, ...) error
- func (m *Manager) SendToPeer(info string, ntp common.NetType, chainId common.ChainID, ...) error
- func (m *Manager) SetDataManager(dmanager models.DataManager)
- func (m *Manager) StartConNet(networker models.Networker, chainid common.ChainID, netType common.NetType) (common.NodeID, error)
- func (m *Manager) Starter() error
- func (m *Manager) Status()
- func (m *Manager) StopOneChain(id *common.ChainID) error
- func (m *Manager) StopOneNet(cid common.ChainID, ntp common.NetType) (int, error)
- func (m *Manager) String() string
- type Msg
- type MsgHandler
- type MsgType
- type NetWorker
- func (n *NetWorker) AbandonUselessPeers(nt common.NetType)
- func (n *NetWorker) Broadcast(info string, typ common.NetType, msg interface{}, pub, sig []byte, ...) ([]byte, []byte, error)
- func (n *NetWorker) BroadcastSync(info string, typ common.NetType, msg interface{}, pub, sig []byte, ...) ([]byte, []byte, error)
- func (n *NetWorker) Close() error
- func (n *NetWorker) Connect(typ common.NetType, bootId common.ChainID, boots map[common.NodeID]net.Addr, ...) (err error)
- func (n *NetWorker) Create(typ common.NetType, address net.Addr, boots map[common.NodeID]net.Addr, ...) error
- func (n *NetWorker) Exit(typ common.NetType) (int, error)
- func (n *NetWorker) GetChainID() common.ChainID
- func (n *NetWorker) IsIn(netType common.NetType) bool
- func (n *NetWorker) NetTypes() (types []common.NetType)
- func (n *NetWorker) Rand(size int, info string, typ common.NetType, msg interface{}, pub, sig []byte, ...) ([]byte, []byte, error)
- func (n *NetWorker) ReplaceDataNodes(nt common.NetType)
- func (n *NetWorker) Reset(typ common.NetType, addr net.Addr, callback models.ConnectedCallBackFunc) error
- func (n *NetWorker) SendToChain(info string, typ common.NetType, chainid common.ChainID, msg interface{}, ...) ([]byte, []byte, error)
- func (n *NetWorker) SendToNode(info string, typ common.NetType, nodeids common.NodeIDs, msg interface{}, ...) ([]byte, []byte, error)
- func (n *NetWorker) SendToPeer(info string, typ common.NetType, nodeids common.NodeIDs, msg interface{}, ...) ([]byte, []byte, error)
- func (n *NetWorker) SetTmpDataNodes(nt common.NetType)
- type Peer
- func (p *Peer) Disconnect(reason DiscReason)
- func (p *Peer) Ping() error
- func (p *Peer) PingLoop()
- func (p *Peer) Pong() error
- func (p *Peer) ReadLoop(readErrChan chan<- error)
- func (p *Peer) ReadMsg() (*Msg, error)
- func (p *Peer) Run() (err error)
- func (p *Peer) WriteMsg(msg *Msg) error
- func (p *Peer) WriteMsgLoad(msgLoad []byte) error
- type PortPool
- type RecentMsgPool
- func (rm *RecentMsgPool) Clear()
- func (rm *RecentMsgPool) GetLoad(loadHash common.Hash) (load []byte, exist bool)
- func (rm *RecentMsgPool) IsExist(loadHash common.Hash) bool
- func (rm *RecentMsgPool) PutLoad(key common.Hash, load []byte) error
- func (rm *RecentMsgPool) Start()
- func (rm *RecentMsgPool) Stop()
- type RecentReceivePool
- type Secrets
- type Server
- func (s *Server) AbandonUselessPeers()
- func (s *Server) BootChain() common.ChainID
- func (s *Server) BroadcastAsync(info string, msgv interface{}, pub, sig []byte, skips ...*common.NodeID) ([]byte, []byte, error)
- func (s *Server) BroadcastFull(info string, msgv interface{}, pub, sig []byte, skips ...*common.NodeID) error
- func (s *Server) BroadcastFullPayLoad(info string, eventType models.EventType, eventLoad, pub, sig []byte, ...) error
- func (s *Server) BroadcastPartPayLoad(info string, eventType models.EventType, eventLoad, pub, sig []byte, ...) error
- func (s *Server) BroadcastSync(info string, msgv interface{}, pub, sig []byte, skips ...*common.NodeID) ([]byte, []byte, error)
- func (s *Server) DiscoverTypeIsSRT() bool
- func (s *Server) HandPeerInfo(p *Peer, flag int, peerCount int, inboundCount int) error
- func (s *Server) HandleMsg(peer *Peer, msg *Msg) error
- func (s *Server) LocalPort() uint16
- func (s *Server) NewPeerLogger(nid common.NodeID) logrus.FieldLogger
- func (s *Server) NodeID() *common.NodeID
- func (s *Server) PeerCount() int
- func (s *Server) PeerIDs() []common.NodeID
- func (s *Server) RandBroadcast(size int, info string, msgv interface{}, pub, sig []byte, ...) ([]byte, []byte, error)
- func (s *Server) ReplaceDataNodes()
- func (s *Server) SendToChain(info string, chainid common.ChainID, pb interface{}, pub, sig []byte) ([]byte, []byte, error)
- func (s *Server) SendToNode(info string, toNodes common.NodeIDs, pb interface{}, pub, sig []byte) ([]byte, []byte, error)
- func (s *Server) SendToPeer(info string, toNodes common.NodeIDs, pb interface{}, pub, sig []byte) ([]byte, []byte, error)
- func (s *Server) SetTmpDataNodes(infos []*common.ChainInfos)
- func (s *Server) Start() error
- func (s *Server) Stop()
- type TcpDialer
- type TcpHandShaker
- type TcpListener
- type WantDetailLock
Constants ¶
View Source
const ( TimesToRetryConnect = 10 // connect retry times MaxBytesCanBroadcast = 65536 // the max length of a full broadcast msg NumOfFullBroadcast = 1 // full msg count to broadcast when msg was too large RecentReceivePoolSize = 5000 // recent receive msg pool size RecentMsgPoolSize = 200 // recent send msg pool size NewWantDetailLockSize = 500 // recent WantDetail msg pool size SECLen = 16 MACLen = 16 )
View Source
const ( // max peer count MaxPeerCount = 21 // max count for dialing in nodes MaxPendCount = 21 // Tcp handshake version TcpHandShakerVersion = 2000000 // nopos )
View Source
const MsgTypeLength int = 2
Variables ¶
View Source
var ( HandProofMsgType MsgType = [MsgTypeLength]byte{0, 0} PingMsgType MsgType = [MsgTypeLength]byte{0, 1} PongMsgType MsgType = [MsgTypeLength]byte{0, 2} DiscMsgType MsgType = [MsgTypeLength]byte{0, 3} EventMsgType MsgType = [MsgTypeLength]byte{0, 255} PingMsg = &Msg{ MsgType: &PingMsgType, Payload: []byte{1}, } PongMsg = &Msg{ MsgType: &PongMsgType, Payload: []byte{2}, } DiscMsg = &Msg{ MsgType: &DiscMsgType, Payload: []byte{3}, } )
View Source
var ( ErrInsertSameMsg = errors.New("insert the same msg") ErrAlreadyConnected = errors.New("already connect to net") )
View Source
var ( SystemRecentRecPool = RecentReceivePool{ // contains filtered or unexported fields } )
Functions ¶
func Body2EventLoad ¶
func GetEventTypeFromMsgLoad ¶
func GetEventTypeFromPayLoad ¶
func NewP2PServer ¶
func PayLoad2Body ¶
func ReadP2PMsg ¶
p2p.Msg to MsgEvent
Types ¶
type CallbackFun ¶
type CheckPermissionFunc ¶
type DiscReason ¶
type DiscReason uint
const ( DiscRequested DiscReason = iota DiscNetworkError DiscProtocolError DiscUselessPeer DiscTooManyPeers DiscTooManyInboundPeers DiscAlreadyConnected DiscIncompatibleVersion DiscInvalidIdentity DiscQuitting DiscUnexpectedIdentity DiscSelf DiscReadTimeout DiscDifferentChain DiscDifferentNet DiscInvalidIP DiscTryTooOften DiscTooManyChildToChildPeers DiscMsgTooLarge DiscSubprotocolError = 0x13 )
func (DiscReason) Error ¶
func (d DiscReason) Error() string
func (DiscReason) String ¶
func (d DiscReason) String() string
type HandShakeReq ¶
type HandShakeReq struct {
// contains filtered or unexported fields
}
type HandShakeRsp ¶
type HandShakeRsp struct {
// contains filtered or unexported fields
}
type HandShaker ¶
type HandleMsgFunc ¶
type Manager ¶
type Manager struct { common.AbstractService // contains filtered or unexported fields }
func (*Manager) BroadcastFull ¶
func (*Manager) BroadcastFullSync ¶
func (*Manager) ClearNetWorker ¶
func (m *Manager) ClearNetWorker(id common.ChainID)
func (*Manager) ConnectNet ¶
func (*Manager) CreateOneNet ¶
func (*Manager) CreateOrConnectNet ¶
func (*Manager) GetAllNetInfomap ¶
func (m *Manager) GetAllNetInfomap() map[common.ChainID]map[common.NodeID]common.NetInfo
func (*Manager) GetBootMap ¶
func (*Manager) GetChainNet ¶
func (*Manager) GetDataServer ¶
func (m *Manager) GetDataServer(chainId common.ChainID) *[]common.Dataserver
func (*Manager) GetNetInfomap ¶
func (*Manager) GetNetworker ¶
func (*Manager) IsBootNode ¶
func (*Manager) ResetConNet ¶
func (*Manager) ResetOneNet ¶
func (*Manager) SendToChain ¶
func (*Manager) SendToNode ¶
func (*Manager) SendToPeer ¶
func (*Manager) SetDataManager ¶
func (m *Manager) SetDataManager(dmanager models.DataManager)
func (*Manager) StartConNet ¶
func (*Manager) StopOneChain ¶
stop manager's one networker
func (*Manager) StopOneNet ¶
stop manager's one net of a networker
type MsgHandler ¶
type MsgType ¶
type MsgType [MsgTypeLength]byte
func (*MsgType) Bytes ¶
func (t *MsgType) Bytes() [MsgTypeLength]byte
type NetWorker ¶
type NetWorker struct {
// contains filtered or unexported fields
}
func NewNetWorker ¶
func (*NetWorker) AbandonUselessPeers ¶
func (n *NetWorker) AbandonUselessPeers(nt common.NetType)
func (*NetWorker) BroadcastSync ¶
func (*NetWorker) Connect ¶
func (n *NetWorker) Connect(typ common.NetType, bootId common.ChainID, boots map[common.NodeID]net.Addr, infos []*common.ChainInfos, permission []byte, callback models.ConnectedCallBackFunc) (err error)
connect to a boot node
func (*NetWorker) Create ¶
func (n *NetWorker) Create(typ common.NetType, address net.Addr, boots map[common.NodeID]net.Addr, infos []*common.ChainInfos, callback models.ConnectedCallBackFunc) error
start a boot node
func (*NetWorker) GetChainID ¶
func (n *NetWorker) GetChainID() common.ChainID
func (*NetWorker) ReplaceDataNodes ¶
func (n *NetWorker) ReplaceDataNodes(nt common.NetType)
func (*NetWorker) SendToChain ¶
func (*NetWorker) SendToNode ¶
func (*NetWorker) SendToPeer ¶
func (*NetWorker) SetTmpDataNodes ¶
func (n *NetWorker) SetTmpDataNodes(nt common.NetType)
type Peer ¶
type Peer struct { discover.Node RW net.Conn MC chan *Msg // contains filtered or unexported fields }
func NewPeer ¶
func NewPeer(n discover.Node, chainId common.ChainID, con net.Conn, flag connFlag, sec *Secrets, logger logrus.FieldLogger, handleFunc HandleMsgFunc, callbackFun CallbackFun) *Peer
func (*Peer) Disconnect ¶
func (p *Peer) Disconnect(reason DiscReason)
func (*Peer) WriteMsgLoad ¶
type PortPool ¶
type PortPool struct {
// contains filtered or unexported fields
}
func NewPortPool ¶
type RecentMsgPool ¶
type RecentMsgPool struct {
// contains filtered or unexported fields
}
func NewRecentMsgPool ¶
func NewRecentMsgPool(size int) *RecentMsgPool
func (*RecentMsgPool) Clear ¶
func (rm *RecentMsgPool) Clear()
func (*RecentMsgPool) GetLoad ¶
func (rm *RecentMsgPool) GetLoad(loadHash common.Hash) (load []byte, exist bool)
func (*RecentMsgPool) IsExist ¶
func (rm *RecentMsgPool) IsExist(loadHash common.Hash) bool
func (*RecentMsgPool) PutLoad ¶
func (rm *RecentMsgPool) PutLoad(key common.Hash, load []byte) error
func (*RecentMsgPool) Start ¶
func (rm *RecentMsgPool) Start()
func (*RecentMsgPool) Stop ¶
func (rm *RecentMsgPool) Stop()
type RecentReceivePool ¶
type RecentReceivePool struct {
// contains filtered or unexported fields
}
func (*RecentReceivePool) Add ¶
func (p *RecentReceivePool) Add(hashOfLoad common.Hash, fromid *common.NodeID) bool
func (*RecentReceivePool) IsExist ¶
func (p *RecentReceivePool) IsExist(hashOfLoad common.Hash, fromid *common.NodeID) (exist bool, inNodes bool)
type Server ¶
type Server struct { SID uint64 discover.Node discover.P2PConfig Peers sync.Map ChainToPeers sync.Map Eventer models.Eventer // contains filtered or unexported fields }
func (*Server) BroadcastAsync ¶
func (*Server) BroadcastFull ¶
func (*Server) BroadcastFullPayLoad ¶
func (*Server) BroadcastPartPayLoad ¶
func (*Server) BroadcastSync ¶
func (*Server) DiscoverTypeIsSRT ¶
func (*Server) HandPeerInfo ¶
func (*Server) NewPeerLogger ¶
func (s *Server) NewPeerLogger(nid common.NodeID) logrus.FieldLogger
func (*Server) RandBroadcast ¶
func (*Server) ReplaceDataNodes ¶
func (s *Server) ReplaceDataNodes()
change the current chain structure with tmp and clear tmp
func (*Server) SendToChain ¶
func (*Server) SendToNode ¶
func (*Server) SendToPeer ¶
func (*Server) SetTmpDataNodes ¶
func (s *Server) SetTmpDataNodes(infos []*common.ChainInfos)
set the new chain structure to tmp
type TcpDialer ¶
type TcpDialer struct {
// contains filtered or unexported fields
}
func NewTcpDialer ¶
func NewTcpDialer() *TcpDialer
type TcpHandShaker ¶
type TcpHandShaker struct {
// contains filtered or unexported fields
}
func (*TcpHandShaker) GetChainID ¶
func (s *TcpHandShaker) GetChainID() (common.ChainID, error)
func (*TcpHandShaker) ShakeHandWith ¶
func (*TcpHandShaker) VerifyPeerProof ¶
type TcpListener ¶
type TcpListener struct {
// contains filtered or unexported fields
}
func (*TcpListener) Accept ¶
func (t *TcpListener) Accept() (net.Conn, error)
Accept waits for and returns the next connection to the listener.
func (*TcpListener) Addr ¶
func (t *TcpListener) Addr() net.Addr
Addr returns the listener's network address.
func (*TcpListener) Close ¶
func (t *TcpListener) Close() error
Close closes the listener. Any blocked Accept operations will be unblocked and return errors.
type WantDetailLock ¶
type WantDetailLock struct {
// contains filtered or unexported fields
}
lock for WantDetailEvent
func NewWantDetailLock ¶
func NewWantDetailLock(size int) *WantDetailLock
func (*WantDetailLock) Lock ¶
func (w *WantDetailLock) Lock(h common.Hash) bool
func (*WantDetailLock) Unlock ¶
func (w *WantDetailLock) Unlock(h common.Hash)
func (*WantDetailLock) UnlockAll ¶
func (w *WantDetailLock) UnlockAll()
Source Files
¶
Click to show internal directories.
Click to hide internal directories.