Documentation ¶
Index ¶
- Constants
- Variables
- func LsnMgrProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno
- func PauseAccept() bool
- func PeerAcceptProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno
- func PeerInstProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno
- func PeerMgrProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno
- func ResumeAccept() bool
- func SendPackage(pkg *P2pPackage2Peer) (PeMgrErrno, []*PeerId)
- type Handshake
- type MsgCloseCfm
- type MsgCloseInd
- type MsgPingpongReq
- type P2pIndConnStatusPara
- type P2pIndPeerActivatedPara
- type P2pIndPeerClosedPara
- type P2pInfIndCallback
- type P2pInfPkgCallback
- type P2pMessage
- type P2pPackage
- type P2pPackage2Peer
- type P2pPackage4Callback
- type PeMgrErrno
- type PeerId
- type PeerInfo
- type Pingpong
- type Protocol
Constants ¶
const ( PeMgrEnoNone = iota PeMgrEnoParameter PeMgrEnoScheduler PeMgrEnoConfig PeMgrEnoResource PeMgrEnoOs PeMgrEnoMessage PeMgrEnoDuplicaated PeMgrEnoNotfound PeMgrEnoInternal PeMgrEnoPingpongTh PeMgrEnoUnknown )
Peer manager errno
const ( P2pInfIndCb = iota P2pInfPkgCb )
callback type
const ( P2pIndPeerActivated = iota // peer activated P2pIndConnStatus // connection status changed P2pIndPeerClosed // connection closed )
P2p peer status indication callback type
const ( PID_P2P = pb.ProtocolId_PID_P2P PID_EXT = pb.ProtocolId_PID_EXT )
Protocol identities
const ( MID_HANDSHAKE = pb.MessageId_MID_HANDSHAKE MID_PING = pb.MessageId_MID_PING MID_PONG = pb.MessageId_MID_PONG )
Message identities
const MaxProtocols = ycfg.MaxProtocols
Max protocols supported
const PeInstDirInbound = -1 // inbound connection
const PeInstDirNull = 0 // null, so connection should be nil
const PeInstDirOutbound = +1 // outbound connection
const PeInstMailboxSize = 32 // mailbox size
const PeInstMaxP2packages = 32 // max p2p packages pending to be sent
const PeInstMaxPingpongCnt = 4 // max pingpong counter value
const PeInstPingpongCycle = time.Second * 2 // pingpong period
const PeerAccepterName = sch.PeerAccepterName
Accept task
const PeerLsnMgrName = sch.PeerLsnMgrName
Listener manager
const PeerMgrName = sch.PeerMgrName
Peer manager
Variables ¶
var Lock4Cb sync.Mutex
Lock for syncing callbacks
Functions ¶
func LsnMgrProc ¶
func LsnMgrProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno
Listen manager entry
func PeerAcceptProc ¶
func PeerAcceptProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno
Accept task entry
func PeerInstProc ¶
func PeerInstProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno
Peer instance entry
func PeerMgrProc ¶
func PeerMgrProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno
Peer manager entry
Types ¶
type Handshake ¶
type Handshake struct { NodeId ycfg.NodeID // node identity IP net.IP // ip address UDP uint32 // udp port number TCP uint32 // tcp port number ProtoNum uint32 // number of protocols supported Protocols []Protocol // version of protocol }
Handshake message
type MsgCloseCfm ¶
type MsgCloseCfm struct {
// contains filtered or unexported fields
}
EvPeCloseCfm message
type MsgCloseInd ¶
type MsgCloseInd struct {
// contains filtered or unexported fields
}
EvPeCloseInd message
type MsgPingpongReq ¶
type MsgPingpongReq struct {
// contains filtered or unexported fields
}
EvPePingpongReq message
type P2pIndConnStatusPara ¶
type P2pIndPeerActivatedPara ¶
type P2pIndPeerActivatedPara struct { Ptn interface{} // task node pointer PeerInfo *Handshake // handshake info }
type P2pIndPeerClosedPara ¶
type P2pIndPeerClosedPara struct {
PeerId PeerId // peer identity
}
type P2pInfIndCallback ¶
type P2pInfIndCallback func(what int, para interface{}) interface{}
var P2pIndHandler P2pInfIndCallback = nil
Indication handler
type P2pInfPkgCallback ¶
type P2pInfPkgCallback func(msg *P2pPackage4Callback) interface{}
P2p callback function type for package incoming
type P2pMessage ¶
Message for TCP message
type P2pPackage ¶
type P2pPackage struct { Pid uint32 // protocol identity PayloadLength uint32 // payload length Payload []byte // payload }
Package for TCP message
func (*P2pPackage) GetMessage ¶
func (upkg *P2pPackage) GetMessage(pmsg *P2pMessage) PeMgrErrno
Decode message from package
func (*P2pPackage) RecvPackage ¶
func (upkg *P2pPackage) RecvPackage(inst *peerInstance) PeMgrErrno
Receive user package
func (*P2pPackage) SendPackage ¶
func (upkg *P2pPackage) SendPackage(inst *peerInstance) PeMgrErrno
type P2pPackage2Peer ¶
type P2pPackage2Peer struct { IdList []PeerId // peer identity list ProtoId int // protocol identity PayloadLength int // payload length Payload []byte // payload Extra interface{} // extra info: user this field to tell p2p more about this message, }
Message from user
type P2pPackage4Callback ¶
type P2pPackage4Callback struct { PeerInfo *PeerInfo // peer information ProtoId int // protocol identity PayloadLength int // bytes in payload buffer Payload []byte // payload buffer }
Package passed into user's callback
type PeMgrErrno ¶
type PeMgrErrno int
func PeMgrInited ¶
func PeMgrInited() PeMgrErrno
Get initialization result of peer manager. This function is exported to outside telling the initialization result of peer manager.
func PeMgrStart ¶
func PeMgrStart() PeMgrErrno
Startup the peer manager. This function is exported to outside modules to choose a "good" chance to start the manager up.
func SetP2pkgCallback ¶
func SetP2pkgCallback(cb interface{}, ptn interface{}) PeMgrErrno
Set callback for incoming packages