udpmsg

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: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UdpMsgTypePing = iota
	UdpMsgTypePong
	UdpMsgTypeFindNode
	UdpMsgTypeNeighbors
	UdpMsgTypeUnknown
	UdpMsgTypeAny
)

message type

View Source
const (
	UdpMsgEnoNone = iota
	UdpMsgEnoParameter
	UdpMsgEnoEncodeFailed
	UdpMsgEnoDecodeFailed
	UdpMsgEnoMessage
	UdpMsgEnoUnknown
)

errno

View Source
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

func (*FindNode) String

func (findnode *FindNode) String() string

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

func (*Neighbors) String

func (neighbors *Neighbors) String() string

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

func (n *Node) CompareWith(n2 *Node) int

func (*Node) Srting

func (n *Node) Srting() string

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

func (*Ping) String

func (ping *Ping) String() string

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

func (*Pong) String

func (pong *Pong) String() string

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 NewUdpMsg

func NewUdpMsg() *UdpMsg

Create UdpMsg object

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) Decode

func (pum *UdpMsg) Decode() UdpMsgErrno

Decoding

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) EncodePing

func (pum *UdpMsg) EncodePing(ping *Ping) UdpMsgErrno

Encode Ping

func (*UdpMsg) EncodePong

func (pum *UdpMsg) EncodePong(pong *Pong) UdpMsgErrno

Encode Pong

func (*UdpMsg) GetDecodedMsg

func (pum *UdpMsg) GetDecodedMsg() interface{}

Get decoded message

func (*UdpMsg) GetDecodedMsgType

func (pum *UdpMsg) GetDecodedMsgType() UdpMsgType

Get deocded message type

func (*UdpMsg) GetFindNode

func (pum *UdpMsg) GetFindNode() interface{}

Get decoded FindNode

func (*UdpMsg) GetNeighbors

func (pum *UdpMsg) GetNeighbors() interface{}

Get decoded Neighbors

func (*UdpMsg) GetPbMessage

func (pum *UdpMsg) GetPbMessage() *pb.UdpMessage

Get decoded message

func (*UdpMsg) GetPing

func (pum *UdpMsg) GetPing() interface{}

Get decoded Ping

func (*UdpMsg) GetPong

func (pum *UdpMsg) GetPong() interface{}

Get decoded Pong

func (*UdpMsg) GetRawMessage

func (pum *UdpMsg) GetRawMessage() (buf []byte, len int)

func (*UdpMsg) SetRawMessage

func (pum *UdpMsg) SetRawMessage(pbuf *[]byte, bytes int, from *net.UDPAddr) UdpMsgErrno

Set raw message

type UdpMsgErrno

type UdpMsgErrno int

type UdpMsgType

type UdpMsgType = int

Directories

Path Synopsis
Package udpmsg_pb is a generated protocol buffer package.
Package udpmsg_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