protocol

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2018 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package protocol provides functionalities to create payloads and compose packet that conform to the booster protocol.

Index

Constants

View Source
const (
	PacketOpeningTag  = ">"
	PacketClosingTag  = "<"
	PayloadOpeningTag = "["
	PayloadClosingTag = "]"
	Separator         = ":"
)

Tags used in the encoding and decoding of packets.

View Source
const Version = "v0.1.0"

Booster protocol version

Variables

View Source
var HeaderDecoder = decodeHeader
View Source
var HeaderEncoder = encodeHeader

HeaderEncoder is the default function used to encode the headers.

View Source
var PayloadDecoders = map[Message]DecoderFunc{
	MessageHello:      decodeHello,
	MessageConnect:    decodeConnect,
	MessageDisconnect: decodeDisconnect,
	MessageHeartbeat:  decodeHeartbeat,
	MessageMonitor:    decodeMonitor,
	MessageCtrl:       decodeCtrl,

	MessageNetworkStatus: decodeBandwidth,
	MessageNodeStatus:    decodeNode,
	MessageProxyUpdate:   decodeProxyUpdate,
}

Implemented default decoders

View Source
var PayloadEncoders = map[Message]EncoderFunc{
	MessageHello:      encodeHello,
	MessageConnect:    encodeConnect,
	MessageDisconnect: encodeDisconnect,
	MessageHeartbeat:  encodeHeartbeat,
	MessageMonitor:    encodeMonitor,
	MessageCtrl:       encodeCtrl,

	MessageNetworkStatus: encodeBandwidth,
	MessageNodeStatus:    encodeNode,
	MessageProxyUpdate:   encodeProxyUpdate,
}

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

func IsVersionSupported(v string) bool

IsVersionSupported returns true if the current protocol version is compatible with the requested version.

Types

type DecoderFunc added in v0.4.0

type DecoderFunc func([]byte) (interface{}, error)

DecoderFunc defines how a decoder should behave.

type EncoderFunc added in v0.4.0

type EncoderFunc func(interface{}) ([]byte, error)

EncoderFunc defines how an encoder should behave.

type Encoding added in v0.4.0

type Encoding uint8
const (
	EncodingProtobuf Encoding = iota
	EncodingJson
)

Possible encodings

type Header struct {
	ID              Message
	ProtocolVersion string
	SentAt          time.Time
	Modules         []string
}

func (*Header) HasModule

func (h *Header) HasModule(m string) bool

type Message

type Message int32
const (
	// Commands
	MessageHello Message = iota
	MessageConnect
	MessageDisconnect
	MessageHeartbeat
	MessageNotify
	MessageMonitor
	MessageCtrl

	// Monitor related
	MessageNetworkStatus
	MessageNodeStatus
	MessageProxyUpdate
)

Booster possible packet messages

const (
	MonitorProxy Message = iota
	MonitorNet
)

Booster possible monitor features

type Module added in v0.4.0

type Module string
const (
	ModuleHeader  Module = "HE"
	ModulePayload Module = "PA"
)

Module Identifiers

type Operation

type Operation int32
const (
	TunnelAdd Operation = iota
	TunnelAck
	TunnelRemove
)

Tunnel operations

const (
	CtrlStop Operation = iota
	CtrlRestart
)

Ctrl operations

func OperationFromString

func OperationFromString(raw string) (Operation, error)

OperationFromString converts raw, if possible, into a protocol known operation. Returns an error if no match is found.

type PayloadBandwidth

type PayloadBandwidth struct {
	Tot       int    `json:"tot"`
	Bandwidth int    `json:"bandwidth"`
	Type      string `json:"type"`
}

type PayloadConnect

type PayloadConnect struct {
	Target string
}

type PayloadCtrl

type PayloadCtrl struct {
	Operation Operation
}

type PayloadDisconnect

type PayloadDisconnect struct {
	ID string
}

type PayloadHeartbeat

type PayloadHeartbeat struct {
	ID   string
	Hops int
	TTL  time.Time
}

type PayloadHello

type PayloadHello struct {
	BPort string
	PPort string
}

type PayloadMonitor added in v0.4.0

type PayloadMonitor struct {
	Features []Message
}

type PayloadNode

type PayloadNode struct {
	ID      string    `json:"id"`
	BAddr   string    `json:"baddr"`
	PAddr   string    `json:"paddr"`
	Active  bool      `json:"active"`
	Tunnels []*Tunnel `json:"tunnels"`
}

type PayloadProxyUpdate added in v0.4.0

type PayloadProxyUpdate struct {
	Target    string    `json:"target"`
	ProxiedBy string    `json:"proxied_by"`
	Operation Operation `json:"operation"`
}

type Tunnel

type Tunnel struct {
	ID        string `json:"id"`
	Target    string `json:"target"`
	ProxiedBy string `json:"proxied_by"`
	Acks      int    `json:"acks"`
	Copies    int    `json:"copies"`
}

Directories

Path Synopsis
Package internal is a generated protocol buffer package.
Package internal is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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