Documentation ¶
Index ¶
- Constants
- type Endpoint
- type FindNode
- type Neighbors
- type Node
- type Ping
- type Pong
- type SubNetworkID
- type UdpMsg
- func (pum *UdpMsg) CheckUdpMsgFromPeer(from *net.UDPAddr, chkAddr bool) UdpMsgErrno
- func (pum *UdpMsg) DebugMessageFromPeer()
- func (pum *UdpMsg) DebugMessageToPeer()
- func (pum *UdpMsg) Decode() UdpMsgErrno
- func (pum *UdpMsg) Encode(t int, msg interface{}) UdpMsgErrno
- func (pum *UdpMsg) EncodeFindNode(fn *FindNode) UdpMsgErrno
- func (pum *UdpMsg) EncodeNeighbors(ngb *Neighbors) UdpMsgErrno
- func (pum *UdpMsg) EncodePbMsg() UdpMsgErrno
- func (pum *UdpMsg) EncodePing(ping *Ping) UdpMsgErrno
- func (pum *UdpMsg) EncodePong(pong *Pong) UdpMsgErrno
- func (pum *UdpMsg) GetDecodedMsg() interface{}
- func (pum *UdpMsg) GetDecodedMsgType() UdpMsgType
- func (pum *UdpMsg) GetFindNode() interface{}
- func (pum *UdpMsg) GetNeighbors() interface{}
- func (pum *UdpMsg) GetPbMessage() *pb.UdpMessage
- func (pum *UdpMsg) GetPing() interface{}
- func (pum *UdpMsg) GetPong() interface{}
- func (pum *UdpMsg) GetRawMessage() (buf []byte, len int)
- func (pum *UdpMsg) SetRawMessage(pbuf *[]byte, bytes int, from *net.UDPAddr) UdpMsgErrno
- type UdpMsgErrno
- type UdpMsgType
Constants ¶
const ( UdpMsgTypePing = iota UdpMsgTypePong UdpMsgTypeFindNode UdpMsgTypeNeighbors UdpMsgTypeUnknown UdpMsgTypeAny )
message type
const ( UdpMsgEnoNone = iota UdpMsgEnoParameter UdpMsgEnoEncodeFailed UdpMsgEnoDecodeFailed UdpMsgEnoMessage UdpMsgEnoUnknown )
errno
const ( CmpNodeEqu = iota CmpNodeNotEquId CmpNodeNotEquIp CmpNodeNotEquUdpPort CmpNodeNotEquTcpPort )
Compare two nodes
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶
type Endpoint struct { IP net.IP // ip address UDP uint16 // udp port number TCP uint16 // tcp port number }
Endpoint
type FindNode ¶
type FindNode struct { From Node // source node To Node // destination node FromSubNetId []SubNetworkID // sub network identities of "From" SubNetId SubNetworkID // sub network identity MaskBits int // mask bits for subnet identity Target config.NodeID // target node identity Id uint64 // message identity Expiration uint64 // time to expired of this message Extra []byte // extra info }
FindNode: request the endpoint of the target
type Neighbors ¶
type Neighbors struct { From Node // source node To Node // destination node FromSubNetId []SubNetworkID // sub network identities of "From" SubNetId SubNetworkID // sub network identity Nodes []*Node // neighbor nodes Id uint64 // message identity Expiration uint64 // time to expired of this message Extra []byte // extra info }
Neighbors: response to FindNode
type Node ¶
type Node struct { IP net.IP // ip address UDP, TCP uint16 // udp port number NodeId config.NodeID // node identity }
Node: endpoint with node identity
func (*Node) CompareWith ¶
type Ping ¶
type Ping struct { From Node // source node To Node // destination node FromSubNetId []SubNetworkID // sub network identities of "From" SubNetId SubNetworkID // sub network identity Id uint64 // message identity Expiration uint64 // time to expired of this message Extra []byte // extra info }
Ping
type Pong ¶
type Pong struct { From Node // source node To Node // destination node FromSubNetId []SubNetworkID // sub network identities of "From" SubNetId SubNetworkID // sub network identity Id uint64 // message identity Expiration uint64 // time to expired of this message Extra []byte // extra info }
Pong: response to Ping
type SubNetworkID ¶
type SubNetworkID = config.SubNetworkID
type UdpMsg ¶
type UdpMsg struct { Pbuf *[]byte // buffer pointer Len int // bytes buffered From *net.UDPAddr // source address from underlying network library Msg *pb.UdpMessage // protobuf message Eno UdpMsgErrno // current errno Key interface{} // private key // contains filtered or unexported fields }
UDP message: tow parts, the first is the raw bytes ... the seconde is protobuf message. for decoding, protobuf message will be extract from the raw one; for encoding, bytes will be wriiten into raw buffer.
func (*UdpMsg) CheckUdpMsgFromPeer ¶
func (pum *UdpMsg) CheckUdpMsgFromPeer(from *net.UDPAddr, chkAddr bool) UdpMsgErrno
Check decoded message with endpoint where the message from
func (*UdpMsg) DebugMessageFromPeer ¶
func (pum *UdpMsg) DebugMessageFromPeer()
func (*UdpMsg) DebugMessageToPeer ¶
func (pum *UdpMsg) DebugMessageToPeer()
func (*UdpMsg) Encode ¶
func (pum *UdpMsg) Encode(t int, msg interface{}) UdpMsgErrno
Encode for UDP messages
func (*UdpMsg) EncodeFindNode ¶
func (pum *UdpMsg) EncodeFindNode(fn *FindNode) UdpMsgErrno
Encode FindNode
func (*UdpMsg) EncodeNeighbors ¶
func (pum *UdpMsg) EncodeNeighbors(ngb *Neighbors) UdpMsgErrno
Encode Neighbors
func (*UdpMsg) EncodePbMsg ¶
func (pum *UdpMsg) EncodePbMsg() UdpMsgErrno
Encode directly from protobuf message. Notice: pb message to be encoded must be setup and buffer for encoded bytes must be allocated firstly for this function.
func (*UdpMsg) GetDecodedMsgType ¶
func (pum *UdpMsg) GetDecodedMsgType() UdpMsgType
Get deocded message type
func (*UdpMsg) GetRawMessage ¶
func (*UdpMsg) SetRawMessage ¶
Set raw message
type UdpMsgErrno ¶
type UdpMsgErrno int
type UdpMsgType ¶
type UdpMsgType = int