Documentation
¶
Index ¶
Constants ¶
const ( // IDLen PeerInfo ID length. IDLen = 16 // NonceLen PoW-Nonce length. NonceLen = 4 // PingMsg wire Ping message id. PingMsg = 0 // PongMsg wire Pong message id. PongMsg = 1 // FindNodesMsg wire FindNodes message id. FindNodesMsg = 2 // NodesMsg wire Nodes message id. NodesMsg = 3 // BroadcastMsg Message propagation type. BroadcastMsg = 10 )
const PeerBytesSize int = 22
PeerBytesSize represents the amount of bytes necessary to represent .
Variables ¶
This section is empty.
Functions ¶
func ComputeNonce ¶
ComputeNonce receives the user's `Peer` ID and computes the ID nonce in order to be able to join the network.
This operation is basically a PoW algorithm that ensures that Sybil attacks are more costly.
func MarshalBinary ¶
func MarshalBinary(header Header, payload BinaryMarshaler, buf *bytes.Buffer) error
MarshalBinary marshals message into binary buffer.
func MsgTypeToString ¶
MsgTypeToString translates wire message into string name.
Types ¶
type BinaryMarshaler ¶
type BinaryMarshaler interface {
// Marshal payload to binary.
MarshalBinary(buf *bytes.Buffer) error
// Unmarshal payload from binary.
UnmarshalBinary(buf *bytes.Buffer) error
}
BinaryMarshaler interface for marshal/unmarshal wire unit.
type BroadcastPayload ¶
BroadcastPayload payload data of BROADCAST message.
func (*BroadcastPayload) MarshalBinary ¶
func (payload *BroadcastPayload) MarshalBinary(buf *bytes.Buffer) error
MarshalBinary implements BinaryMarshaler.
func (*BroadcastPayload) UnmarshalBinary ¶
func (payload *BroadcastPayload) UnmarshalBinary(buf *bytes.Buffer) error
UnmarshalBinary implements BinaryMarshaler.
type Header ¶
type Header struct {
MsgType byte
// Remote peer details.
RemotePeerID [IDLen]byte
RemotePeerNonce uint32
RemotePeerPort uint16
// Reserved bytes for future use.
Reserved [2]byte
}
Header represents the header part of kadcast wire messages. Both TCP and UDP are sharing same header structure.
func (*Header) MarshalBinary ¶
MarshalBinary marshal wire header into bytes buffer, if valid.
type NodesPayload ¶
type NodesPayload struct {
Peers []PeerInfo
}
NodesPayload payload data of NODES message.
func (*NodesPayload) MarshalBinary ¶
func (payload *NodesPayload) MarshalBinary(buf *bytes.Buffer) error
MarshalBinary implements BinaryMarshaler.
func (*NodesPayload) UnmarshalBinary ¶
func (payload *NodesPayload) UnmarshalBinary(buf *bytes.Buffer) error
UnmarshalBinary implements BinaryMarshaler.
type PeerInfo ¶
PeerInfo stores peer addr and ID. A slice of PeerInfo is wired on NODES message.
func MakePeerFromAddr ¶
MakePeerFromAddr is same as MakePeer but resolve addr with ResolveTCPAddr.
func MakePeerFromIP ¶
MakePeerFromIP from ipaddr (resolvable by ResolveTCPAddr) and port.
func (PeerInfo) GetUDPAddr ¶
GetUDPAddr make net.UDPAddr from PeerInfo IP:port.
func (*PeerInfo) MarshalBinary ¶
MarshalBinary marshal peer tuple into binary buffer.