utils

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdBufSize    = 64       // command frame size
	TransBufSize  = 2048 - 3 // forward frame size
	BrokersCntMax = 40       // max broker count
)
View Source
const (
	// Version application version
	Version = "0.0.12"
	// Channel empty or dev or something else
	Channel = ""
)
View Source
const (
	// TunnelVersion tunnel compatible version
	TunnelVersion byte = 2
)

Variables

This section is empty.

Functions

func GenerateTLSConfig

func GenerateTLSConfig() (*tls.Config, error)

GenerateTLSConfig setup a bare-bones TLS config for the server

func LittleIndia2Int added in v0.0.11

func LittleIndia2Int(b []byte) int

LittleIndia2Int cover little india byte array into int

func NewDataFrame

func NewDataFrame(t DataType, b []byte) []byte

NewDataFrame build data frame, b can be nil

+------+--------+--------------+
| type | length |   raw data   |
| 0  7 | 8   23 | 24    < 2047 |
+------+--------+--------------+

type is defined in DataType

Types

type DataStream

type DataStream struct {
	// contains filtered or unexported fields
}

DataStream parser to receive and parse data stream

func NewDataStream

func NewDataStream() *DataStream

NewDataStream return a empty data stream parser

func (*DataStream) Append

func (c *DataStream) Append(b []byte)

Append append new data to data stream

func (*DataStream) CompressRateAva

func (c *DataStream) CompressRateAva() float64

CompressRateAva average compress rate (calculated from decompressed data)

func (*DataStream) Data added in v0.0.6

func (c *DataStream) Data() []byte

func (*DataStream) Len added in v0.0.6

func (c *DataStream) Len() int

func (*DataStream) Parse

func (c *DataStream) Parse() bool

Parse when return true, new parsed data frame will sign to rawData, dataLength and dataType

func (*DataStream) Type

func (c *DataStream) Type() DataType

type DataType

type DataType int

DataType 4bit type of data frame

const (
	DATA            DataType = iota // DATA pure data
	PING                            // PING ping
	TUNNEL                          // TUNNEL ask for new tunnel
	LZW_DATA                        // LZW_DATA lzw compressed data
	NET_INFO                        // NET_INFO ask for all broker address in this net
	NET_INFO_UPDATE                 // NET_INFO_UPDATE add or delete broker address in net
	BROKER_INFO                     // BROKER_INFO info of this broker
	VERSION                         // VERSION of tunnel
	RUBBISH                         // RUBBISH nobody care about this package
)

type PluginCallback added in v0.0.9

type PluginCallback func([]byte) (bool, []byte)

PluginCallback read/write DATA, in udp tunnel, first byte is udp multiplex id return value: reply and data; if data is nil or length of it is 0, stop sending; if reply is false, the data will continue to send (data could be modified); if reply is true, the data will reverse its send direction, and send it; caution that the first byte of data is udp multiplex id.

type PluginGoroutine added in v0.0.9

type PluginGoroutine func(interface{}, *net.UDPConn)

PluginGoroutine goroutine for plugin parameters are a quic.Stream or a *net.TCPConn and a *net.UDPConn, which are two sides of a Tunnel

type PluginSetQuitFlag added in v0.0.11

type PluginSetQuitFlag func()

PluginSetQuitFlag set quit flag and plugin will stop function when it found it

type Tunnel added in v0.0.6

type Tunnel struct {
	// contains filtered or unexported fields
}

Tunnel just like a bidirectional pipe

func NewTunnel added in v0.0.6

func NewTunnel(config *TunnelConfig) (*Tunnel, error)

NewTunnel set up a new tunnel

func (*Tunnel) Close added in v0.0.6

func (t *Tunnel) Close()

Close make sure all connection be closed after use

func (*Tunnel) PingDelay added in v0.0.7

func (t *Tunnel) PingDelay() time.Duration

PingDelay delay between two tunnel

func (*Tunnel) Ports added in v0.0.6

func (t *Tunnel) Ports() (int, int)

Ports return port peer: port0, port1.

func (*Tunnel) Serve added in v0.0.6

func (t *Tunnel) Serve(readFunc, writeFunc PluginCallback, plRoutine PluginGoroutine, plQuit PluginSetQuitFlag) error

Serve wait for connection and sync data readFunc, writeFunc: see syncUdp

func (*Tunnel) Status added in v0.0.11

func (t *Tunnel) Status() TunnelStatus

Status return TunnelStatus, get current tunnel status

func (*Tunnel) Type added in v0.0.6

func (t *Tunnel) Type() TunnelType

Type return TunnelType.

type TunnelConfig added in v0.0.6

type TunnelConfig struct {
	Type     TunnelType
	Address0 string
	Address1 string
}

TunnelConfig default IP is 0.0.0.0:0

type TunnelStatus added in v0.0.11

type TunnelStatus int
const (
	STATUS_INIT TunnelStatus = iota
	STATUS_CONNECTED
	STATUS_CLOSED
	STATUS_FAILED
)

type TunnelType added in v0.0.6

type TunnelType int

TunnelType type of tunnel Dial/Listen Address0 and Dial/Listen Address1. Warn that Address1 is for communicate between client and broker, that means DataStream and DataFrame(see NewDataFrame) will be used. Address2 is for generic connection

const (
	DialQuicDialUdp TunnelType = iota
	DialTcpDialUdp
	ListenQuicListenUdp
	ListenTcpListenUdp
)

Jump to

Keyboard shortcuts

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