Documentation ¶
Overview ¶
Package protocol provides functionalities to create payloads and compose packet that conform to the booster protocol.
Index ¶
- Constants
- Variables
- func Decode(p []byte, v interface{}, f DecoderFunc) error
- func Encode(v interface{}, f EncoderFunc) ([]byte, error)
- func IsVersionSupported(v string) bool
- type DecoderFunc
- type EncoderFunc
- type Header
- type Message
- type Module
- type MonitorFeature
- type Operation
- type PayloadBandwidth
- type PayloadConnect
- type PayloadCtrl
- type PayloadDisconnect
- type PayloadHeartbeat
- type PayloadHello
- type PayloadMonitor
- type PayloadNetworkUpdate
- type PayloadNode
- type PayloadProxyUpdate
- type Tunnel
Constants ¶
const ( EncodingProtobuf uint8 = iota + 1 EncodingJson )
Possible encodings
const ( PacketOpeningTag = ">" PacketClosingTag = "<" ModuleOpeningTag = "[" ModuleClosingTag = "]" Separator = ":" )
Tags used in the encoding and decoding of packets.
const CompressionNone uint8 = 1
const EncryptionNone uint8 = 1
const Version = "0.3"
Booster protocol version
Variables ¶
var HeaderDecoder = decodeHeader
var HeaderEncoder = encodeHeader
HeaderEncoder is the default function used to encode the headers.
var PayloadDecoders = map[Message]DecoderFunc{
MessageHello: decodeHello,
MessageConnect: decodeConnect,
MessageDisconnect: decodeDisconnect,
MessageHeartbeat: decodeHeartbeat,
MessageMonitor: decodeMonitor,
MessageCtrl: decodeCtrl,
MessageNodeStatus: decodeNode,
MessageNetworkUsageUpdate: decodeBandwidth,
MessageProxyUpdate: decodeProxyUpdate,
MessageNetworkUpdate: decodeNetworkUpdate,
}
Implemented default decoders
var PayloadEncoders = map[Message]EncoderFunc{
MessageHello: encodeHello,
MessageConnect: encodeConnect,
MessageDisconnect: encodeDisconnect,
MessageHeartbeat: encodeHeartbeat,
MessageMonitor: encodeMonitor,
MessageCtrl: encodeCtrl,
MessageNodeStatus: encodeNode,
MessageNetworkUsageUpdate: encodeBandwidth,
MessageProxyUpdate: encodeProxyUpdate,
MessageNetworkUpdate: encodeNetworkUpdate,
}
Implemented default encoders
Functions ¶
func Decode ¶ added in v0.4.0
func Decode(p []byte, v interface{}, f DecoderFunc) error
Decode takes as input a byte slice and tries to decode it into v. f is used for the internal mapping between public and private structs used for the data transmission.
v has to be a pointer to a struct.
func Encode ¶ added in v0.4.0
func Encode(v interface{}, f EncoderFunc) ([]byte, error)
Encoder tries to encode v using f.
v has to be a value, not a pointer (in fact we don't want v to be modified by this function in any way). When encoding an header using the default HeaderEncoders, v has to be a Message, which will be used to choose how to build the header using a default configuration, such as the encoding will be set to protobuf, the modules field will contain the payload module, etc. When encoding custom packets its betters to pass a custom EncoderFunc as parameter.
func IsVersionSupported ¶
IsVersionSupported returns true if the current protocol version is compatible with the requested version.
Types ¶
type DecoderFunc ¶ added in v0.4.0
DecoderFunc defines how a decoder should behave.
type EncoderFunc ¶ added in v0.4.0
EncoderFunc defines how an encoder should behave.
type Header ¶
type MonitorFeature ¶ added in v0.5.1
type MonitorFeature Message
const ( MonitorNode MonitorFeature = iota + 1 MonitorNet )
Booster possible monitor features
type Operation ¶
type Operation int32
func OperationFromString ¶
OperationFromString converts raw, if possible, into a protocol known operation. Returns an error if no match is found.
type PayloadBandwidth ¶
type PayloadConnect ¶
type PayloadConnect struct {
Target string
}
type PayloadCtrl ¶
type PayloadCtrl struct {
Operation Operation
}
type PayloadDisconnect ¶
type PayloadDisconnect struct {
ID string
}
type PayloadHello ¶
type PayloadMonitor ¶ added in v0.4.0
type PayloadMonitor struct {
Feature MonitorFeature
}
type PayloadNetworkUpdate ¶ added in v0.5.1
type PayloadNetworkUpdate struct { NodeID string `json:"node_id"` Operation Operation `json:"operation"` RemoteNode *PayloadNode `json:"remote_node"` }