protocol

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: AGPL-3.0 Imports: 6 Imported by: 8

Documentation

Overview

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

Index

Constants

View Source
const (
	EncodingProtobuf uint8 = iota + 1
	EncodingJson
)

Possible encodings

View Source
const (
	PacketOpeningTag = ">"
	PacketClosingTag = "<"
	ModuleOpeningTag = "["
	ModuleClosingTag = "]"
	Separator        = ":"
)

Tags used in the encoding and decoding of packets.

View Source
const CompressionNone uint8 = 1
View Source
const EncryptionNone uint8 = 1
View Source
const Version = "0.3"

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,

	MessageNodeStatus:         decodeNode,
	MessageNetworkUsageUpdate: decodeBandwidth,
	MessageProxyUpdate:        decodeProxyUpdate,
	MessageNetworkUpdate:      decodeNetworkUpdate,
}

Implemented default decoders

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

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 Header struct {
	ID              Message   `json:"id"`
	ProtocolVersion string    `json:"protocol_version"`
	SentAt          time.Time `json:"sent_at"`
	Modules         []string  `json:"modules"`
}

func (*Header) HasModule

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

type Message

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

	// Monitor related
	MessageNodeStatus
	MessageNetworkUsageUpdate
	MessageProxyUpdate
	MessageNetworkUpdate
)

Booster possible packet messages

type Module added in v0.4.0

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

Module Identifiers

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
const (
	TunnelAdded Operation = iota + 1
	TunnelRemoved
)

Tunnel operations

const (
	CtrlStop Operation = iota + 1
	CtrlRestart
)

Ctrl operations

const (
	NodeAdded Operation = iota + 1
	NodeRemoved
)

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 {
	NodeID    string `json:"-"`
	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 {
	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"`
}

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 {
	NodeID    string    `json:"node_id"`
	Target    string    `json:"target"`
	Operation Operation `json:"operation"`
}

type Tunnel

type Tunnel struct {
	ID     string `json:"-"`
	Target string `json:"target"`
	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