peer

package
v0.0.0-...-bd3bf0e Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeMgrEnoNone = iota
	PeMgrEnoParameter
	PeMgrEnoScheduler
	PeMgrEnoConfig
	PeMgrEnoResource
	PeMgrEnoOs
	PeMgrEnoMessage
	PeMgrEnoDuplicaated
	PeMgrEnoNotfound
	PeMgrEnoInternal
	PeMgrEnoPingpongTh
	PeMgrEnoUnknown
)

Peer manager errno

View Source
const (
	P2pInfIndCb = iota
	P2pInfPkgCb
)

callback type

View Source
const (
	P2pIndPeerActivated = iota // peer activated
	P2pIndConnStatus           // connection status changed
	P2pIndPeerClosed           // connection closed
)

P2p peer status indication callback type

View Source
const (
	PID_P2P = pb.ProtocolId_PID_P2P
	PID_EXT = pb.ProtocolId_PID_EXT
)

Protocol identities

View Source
const (
	MID_HANDSHAKE = pb.MessageId_MID_HANDSHAKE
	MID_PING      = pb.MessageId_MID_PING
	MID_PONG      = pb.MessageId_MID_PONG
)

Message identities

View Source
const MaxProtocols = ycfg.MaxProtocols

Max protocols supported

View Source
const PeInstDirInbound = -1 // inbound connection
View Source
const PeInstDirNull = 0 // null, so connection should be nil
View Source
const PeInstDirOutbound = +1 // outbound connection
View Source
const PeInstMailboxSize = 32 // mailbox size
View Source
const PeInstMaxP2packages = 32 // max p2p packages pending to be sent
View Source
const PeInstMaxPingpongCnt = 4 // max pingpong counter value
View Source
const PeInstPingpongCycle = time.Second * 2 // pingpong period
View Source
const PeerAccepterName = sch.PeerAccepterName

Accept task

View Source
const PeerLsnMgrName = sch.PeerLsnMgrName

Listener manager

View Source
const PeerMgrName = sch.PeerMgrName

Peer manager

Variables

View Source
var Lock4Cb sync.Mutex

Lock for syncing callbacks

Functions

func LsnMgrProc

func LsnMgrProc(ptn interface{}, msg *sch.SchMessage) sch.SchErrno

Listen manager entry

func PauseAccept

func PauseAccept() bool

Pause accept

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

func ResumeAccept

func ResumeAccept() bool

Resume accept

func SendPackage

func SendPackage(pkg *P2pPackage2Peer) (PeMgrErrno, []*PeerId)

Send package

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 P2pIndConnStatusPara struct {
	Ptn      interface{} // task node pointer
	PeerInfo *Handshake  // handshake info
	Status   int         // status code

	Flag bool // flag

	Description string // description
}

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

type P2pMessage struct {
	Mid       uint32
	Ping      *Pingpong
	Pong      *Pingpong
	Handshake *Handshake
}

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 ClosePeer

func ClosePeer(id *PeerId) PeMgrErrno

Close connection to a peer

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

type PeerId

type PeerId ycfg.NodeID

Peer identity as string

type PeerInfo

type PeerInfo Handshake

Peer information

type Pingpong

type Pingpong struct {
	Seq   uint64 // sequence
	Extra []byte // extra info
}

PingPong message

type Protocol

type Protocol struct {
	Pid uint32  // protocol identity
	Ver [4]byte // protocol version: M.m0.m1.m2
}

Protocol

Directories

Path Synopsis
Package tcpmsg_pb is a generated protocol buffer package.
Package tcpmsg_pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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