peer

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeMgrEnoNone = iota
	PeMgrEnoParameter
	PeMgrEnoScheduler
	PeMgrEnoConfig
	PeMgrEnoResource
	PeMgrEnoOs
	PeMgrEnoNetTemporary
	PeMgrEnoMessage
	PeMgrEnoDuplicated
	PeMgrEnoNotfound
	PeMgrEnoMismatched
	PeMgrEnoInternal
	PeMgrEnoPingpongTh
	PeMgrEnoRecofig
	PeMgrEnoSign
	PeMgrEnoVerify
	PeMgrEnoUnknown
)

Peer manager errno

View Source
const (
	PKI_FOR_CLOSE_CFM         = "peMgrConnCloseCfm"
	PKI_FOR_RECONFIG          = "reConfig"
	PKI_FOR_FAILED_INST_CFM   = "instCfmFailed"
	PKI_FOR_BOUNDOUT_FAILED   = "peMgrConnOutRsp"
	PKI_FOR_HANDSHAKE_FAILED  = "hsFailed"
	PKI_FOR_TOOMUCH_WORKERS   = "maxWorks"
	PKI_FOR_TOOMUCH_OUTBOUNDS = "maxOutbounds"
	PKI_FOR_TOOMUCH_INBOUNDS  = "maxInbounds"
	PKI_FOR_IBW_DUPLICATED    = "dup2InboundWorker"
	PKI_FOR_OBW_DUPLICATED    = "dup2OutboundWorker"
	PKI_FOR_IB2OB_DUPLICATED  = "inBoundDup2OutBound"
	PKI_FOR_OB2IB_DUPLICATED  = "outBoundDup2InBound"
)
View Source
const (
	P2pIndCb = iota
	P2pPkgCb
)

callback type

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

P2p peer status indication callback type

View Source
const (
	PID_P2P     = pb.ProtocolId_PID_P2P // p2p internal
	PID_EXT     = pb.ProtocolId_PID_EXT // external protocol
	PID_UNKNOWN = -1                    // invalid protocol identity
)

Protocol identities

View Source
const (

	// internal MID for PID_P2P
	MID_HANDSHAKE = pb.MessageId_MID_HANDSHAKE // handshake
	MID_PING      = pb.MessageId_MID_PING      // ping
	MID_PONG      = pb.MessageId_MID_PONG      // pong
	MID_CHKK      = pb.MessageId_MID_CHKK      // check key
	MID_RPTK      = pb.MessageId_MID_RPTK      // report key
	MID_GCD       = pb.MessageId_MID_GCD       // get chain data
	MID_PCD       = pb.MessageId_MID_PCD       // put chain data

	// external MID for PID_EXT
	MID_TX          = pb.MessageId_MID_TX
	MID_EVENT       = pb.MessageId_MID_EVENT
	MID_BLOCKHEADER = pb.MessageId_MID_BLOCKHEADER
	MID_BLOCK       = pb.MessageId_MID_BLOCK

	// invalid MID
	MID_INVALID    = pb.MessageId_MID_INVALID
	MID_INVALID_EX = 0xFF
)

Message identities

View Source
const (
	KS_NOTEXIST = pb.KeyStatus_KS_NOTEXIST
	KS_EXIST    = pb.KeyStatus_KS_EXIST
)

Key status

View Source
const MaxProtocols = config.MaxProtocols

Max protocols supported

View Source
const (
	PEMGR_STOP4NAT = "pubAddrSwitch"
)
View Source
const PeInstDirInbound = 0 // inbound connection
View Source
const PeInstDirNull = -1 // null, so connection should be nil
View Source
const PeInstDirOutbound = 1 // outbound connection
View Source
const PeInstMailboxSize = 512 // mailbox size
View Source
const PeInstMaxP2packages = 1024 // max p2p packages pending to be sent
View Source
const PeInstMaxPingpongCnt = 4 // max pingpong counter value
View Source
const PeInstMaxPings = 8 // max pings pending to be sent
View Source
const PeInstPingpongCycle = time.Second * 16 // pingpong period
View Source
const PeerAccepterName = sch.PeerAccepterName

Accepter task

View Source
const PeerLsnMgrName = sch.PeerLsnMgrName

peer listen manager

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckKey

type CheckKey struct {
	Key   []byte // key
	Extra []byte // extra info
}

Check key

func (*CheckKey) String

func (ck *CheckKey) String() string

type ExtMessage

type ExtMessage struct {
	Mid  uint32        // message identity
	Chkk *CheckKey     // check key message
	Rptk *ReportKey    // report key message
	Gcd  *GetChainData // get chain data
	Pcd  *PutChainData // put chain data
}

Message for external TCP message

type GetChainData

type GetChainData struct {
	Seq  uint64 // sequence number
	Name string // name
	Key  []byte // key
}

Get chain data

func (*GetChainData) String

func (gcd *GetChainData) String() string

type Handshake

type Handshake struct {
	ChainId   uint32        // chain identity
	Snid      SubNetworkID  // sub network identity
	Dir       int           // direct
	NodeId    config.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 ListenerManager

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

func NewLsnMgr

func NewLsnMgr() *ListenerManager

func (*ListenerManager) TaskProc4Scheduler

func (lsnMgr *ListenerManager) TaskProc4Scheduler(ptn interface{}, msg *sch.SchMessage) sch.SchErrno

type MsgCloseCfm

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

type MsgCloseInd

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

type MsgPingpongReq

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

type P2pIndCallback

type P2pIndCallback func(what int, para interface{}, userData interface{}) interface{}

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 {
	P2pInst  *sch.Scheduler     // p2p instance pointer
	RxChan   chan *P2pPackageRx // channel for packages received
	PeerInfo *Handshake         // handshake info
}

type P2pIndPeerClosedPara

type P2pIndPeerClosedPara struct {
	P2pInst *sch.Scheduler // p2p instance pointer
	Snid    SubNetworkID   // sub network identity
	PeerId  PeerId         // peer identity
	Dir     int            // direction
}

type P2pMessage

type P2pMessage struct {
	Mid       uint32     // message identity
	Ping      *Pingpong  // ping message
	Pong      *Pingpong  // pong message
	Handshake *Handshake // handshake message
	Chkk      *CheckKey  // check key message
	Rptk      *ReportKey // report key message
}

Message for internal TCP message

type P2pPackage

type P2pPackage struct {
	Pid           uint32 // protocol identity
	Mid           uint32 // message identity
	Key           []byte // key of message
	PayloadLength uint32 // payload length
	Payload       []byte // payload
}

Package for TCP message

func (*P2pPackage) CheckKey

func (upkg *P2pPackage) CheckKey(inst *PeerInstance, chkk *CheckKey, write bool) PeMgrErrno

Check key

func (*P2pPackage) DebugPeerPackage

func (upkg *P2pPackage) DebugPeerPackage()

func (*P2pPackage) GetChainData

func (upkg *P2pPackage) GetChainData(inst *PeerInstance, gcd *GetChainData, write bool) PeMgrErrno

Get chain data

func (*P2pPackage) GetExtMessage

func (upkg *P2pPackage) GetExtMessage(extMsg *ExtMessage) PeMgrErrno

func (*P2pPackage) GetMessage

func (upkg *P2pPackage) GetMessage(pmsg *P2pMessage) PeMgrErrno

Decode message from package

func (*P2pPackage) PutChainData

func (upkg *P2pPackage) PutChainData(inst *PeerInstance, pcd *PutChainData, write bool) PeMgrErrno

Put chain data

func (*P2pPackage) RecvPackage

func (upkg *P2pPackage) RecvPackage(inst *PeerInstance) PeMgrErrno

Receive user package

func (*P2pPackage) ReportKey

func (upkg *P2pPackage) ReportKey(inst *PeerInstance, rptk *ReportKey, write bool) PeMgrErrno

Report key

func (*P2pPackage) SendPackage

func (upkg *P2pPackage) SendPackage(inst *PeerInstance) PeMgrErrno

func (*P2pPackage) String

func (upkg *P2pPackage) String() string

type P2pPackage2Peer

type P2pPackage2Peer struct {
	P2pInst       *sch.Scheduler // p2p network instance
	SubNetId      SubNetworkID   // sub network identity
	IdList        []PeerId       // peer identity list
	ProtoId       int            // protocol identity
	Mid           int            // message identity
	Key           []byte         // message key
	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 P2pPackageRx

type P2pPackageRx struct {
	Ptn           interface{} // instance task node pointer
	PeerInfo      *PeerInfo   // peer information
	ProtoId       int         // protocol identity
	MsgId         int         // message identity
	Key           []byte      // message key
	PayloadLength int         // bytes in payload buffer
	Payload       []byte      // payload buffer
}

Package passed into user's callback

type P2pPkgCallback

type P2pPkgCallback func(msg *P2pPackageRx, userData interface{}) interface{}

P2p callback function type for package incoming

type PeMgrErrno

type PeMgrErrno int

func SendPackage

func SendPackage(pkg *P2pPackage2Peer) PeMgrErrno

type PeerId

type PeerId = config.NodeID

Peer identity as string

type PeerIdEx

type PeerIdEx struct {
	Id  config.NodeID // node identity
	Dir int           // direction
}

type PeerIdExx

type PeerIdExx struct {
	Snid config.SubNetworkID // sub network identity
	Node config.Node         // node
	Dir  int                 // direction
}

type PeerInfo

type PeerInfo Handshake

Peer information

type PeerInstance

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

func (*PeerInstance) TaskProc4Scheduler

func (pi *PeerInstance) TaskProc4Scheduler(ptn interface{}, msg *sch.SchMessage) sch.SchErrno

type PeerManager

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

peer manager

func NewPeerMgr

func NewPeerMgr() *PeerManager

func (*PeerManager) ClosePeer

func (peMgr *PeerManager) ClosePeer(snid *SubNetworkID, id *PeerId) PeMgrErrno

func (*PeerManager) GetInstIndChannel

func (peMgr *PeerManager) GetInstIndChannel() chan interface{}

func (*PeerManager) GetLocalSubnetInfo

func (peMgr *PeerManager) GetLocalSubnetInfo() ([]config.SubNetworkID, map[config.SubNetworkID]config.Node)

func (*PeerManager) PeMgrInited

func (peMgr *PeerManager) PeMgrInited() PeMgrErrno

func (*PeerManager) PeMgrStart

func (peMgr *PeerManager) PeMgrStart() PeMgrErrno

func (*PeerManager) RegisterInstIndCallback

func (peMgr *PeerManager) RegisterInstIndCallback(cb interface{}, userData interface{}) PeMgrErrno

func (*PeerManager) TaskProc4Scheduler

func (peMgr *PeerManager) TaskProc4Scheduler(ptn interface{}, msg *sch.SchMessage) sch.SchErrno

type PeerReconfig

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

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

type PutChainData

type PutChainData struct {
	Seq  uint64 // sequence number
	Name string // name
	Key  []byte // key
	Data []byte // data
}

Put chain data

func (*PutChainData) String

func (pcd *PutChainData) String() string

type ReportKey

type ReportKey struct {
	Key    []byte // key
	Status int32  // key status
	Extra  []byte // extra info
}

Report key

func (*ReportKey) String

func (rk *ReportKey) String() string

type SubNetworkID

type SubNetworkID = config.SubNetworkID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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