gota

package module
v0.0.1-beta6 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2017 License: Apache-2.0 Imports: 26 Imported by: 0

README

[WIP] Gota - a TCP Traffic Aggregator Written in Golang

Linux Build Status Go Report Card Apache License Version 2.0

Gota is a userspace multipath tcp solution.

Gota Active End(aka client) receives tcp traffic and forwards to Gota Passive End(aka server) use multipath tcp connections.

Usage Scenario

Sometimes, our network administrator enables rate-limiting for every tcp connection, the speed of our tcp connections can't reach the top. But if we create multi tcp connections, the traffic of all connections can be aggregated to reach the top speed.

Quick Start

We can use Gota as a library, or daemon.

Use Gota as Daemon
Fetch Gota binary
  • Build from source
go get github.com/jim3ma/gota/gota

Or

  • Download from Release page according to you os and architecture.
Update Server Configuration

PS: the config files already exist in examples folder, you can make a reference.

  • Update and save as config.server.yml
# default for server, did not change it
mode: server

# log level: info debug warn error fatal panic
log: debug
verbose: true

# tunnel authenticate credential
auth:
  username: gota
  password: gota

# white list for remote ip
#whiteips:
#  - 127.0.0.1/32

# remote address with port for forwarding traffic
# suppose you want to speed up you 8080 port
remote: 127.0.0.1:8080

# PS: try to enable fast open and pool for speed up connection time

# fast open in server
fastopen: true

# connection pool in server
pool:
  enable: false
  count: 10
  # sometimes server will close some connections for long idle time,
  # set keepalive to refresh connections which idle for the special time.
  # unit: second
  # 0: do not refresh connections
  keepalive: 10

# tunnel listen address with port
tunnel:
  - listen: 127.0.0.1:12333
  - listen: 127.0.0.1:12336
  • Launch Server
gota server --config config.server.yml
Update Client Configuration
  • Update and save as config.client.yml
# default for server, did not change it
mode: client

# log level: info debug warn error fatal panic
log: debug
verbose: true

# tunnel authenticate credential
auth:
  username: gota
  password: gota

# local listen address with port
listen: 127.0.0.1:12363

# PS: try to enable fastopen and pool for speed up connection time

# fast open in server
fastopen: true

# Gota server addresses with port
tunnel:
  - remote: 127.0.0.1:12333 # connect server directly
  - remote: 127.0.0.1:12336
    # connect server using a proxy, currently Gota support http/https/socks5 proxy
    proxy: http://gota:gota@127.0.0.1:3128
  • Launch Client
gota client --config config.client.yml
Try yourself
telnet 127.0.0.1:12363
# or
curl 127.0.0.1:12363
Use Gota as a library

TBD

Architecture

Gota Architecture

Contributing

Contributions are welcome.

Copyright 2013-2017 Jim Ma

This software is licensed under the terms of the Apache License Version 2. See the LICENSE file.

Documentation

Index

Constants

View Source
const (
	TMControlStartSeq = iota

	TMHeartBeatPingSeq
	TMHeartBeatPongSeq

	TMCreateConnSeq
	TMCreateConnOKSeq
	TMCreateConnErrorSeq

	TMCloseConnSeq
	TMCloseConnForceSeq

	TMCloseTunnelSeq
	TMCloseTunnelOKSeq

	TMTunnelAuthOKSeq
	TMTunnelAuthErrorSeq

	// when a signal big than the boundary, it will contain a payload
	TMWithoutPayloadBoundary

	TMTunnelAuthSeq
	TMCreateFastOpenConnSeq
)
View Source
const (
	TMConnBiuniqueMode = iota
	TMConnOverlapMode
	TMConnMultiBiuniqueMode
	TMConnMultiOverlapMode
)
View Source
const (
	ActiveMode = iota
	PassiveMode
)
View Source
const CHMaxRetryTimes = 3
View Source
const ControlFlagBit = 1 << 31
View Source
const DefaultConnAliveSecond = 120
View Source
const DefaultConnCount = 10
View Source
const FastOpenDelayNanosecond = 1000
View Source
const FastOpenInitSeqNum = 0
View Source
const HeaderLength = 10
View Source
const MaxConnID = 1<<31 - 1
View Source
const MaxDataLength = 64 * 1024
View Source
const TMHeartBeatSecond = 60

Connection Manage HeartBeat Time

View Source
const TMHeartBeatTickerSecond = 600
View Source
const TMHeartBeatTimeOutSecond = 3000
View Source
const TMStatReportSecond = 60

Variables

View Source
var (
	Version = "gota_version"
	Commit  = "gota_commit"
)
View Source
var Direct = direct{}

Direct is a direct proxy: one that makes network connections directly.

View Source
var ErrInsufficientData = errors.New("Error Header, Insufficient Data for GotaFrame Header")
View Source
var ErrNoMoreBytes = errors.New("Read io.EOF, received bytes count less than required")
View Source
var ErrUnmatchedDataLength = errors.New("Unmatched Data Length for GotaFrame")
View Source
var HTTPSDialer = httpsDialer{}

HTTPSDialer is a https proxy: one that makes network connections on tls.

View Source
var HeaderOnly = errors.New("Gota Header Only")
View Source
var TLSConfig = &tls.Config{}
View Source
var TMCloseTunnelBytes []byte
View Source
var TMCloseTunnelOKBytes []byte
View Source
var TMControlSignalMap map[uint32]string
View Source
var TMErrUnsupportedConfig = errors.New("Unsupported configuration")
View Source
var TMHeartBeatPingBytes []byte
View Source
var TMHeartBeatPongBytes []byte
View Source
var TMTunnelAuthErrBytes []byte
View Source
var TMTunnelAuthOKBytes []byte

Functions

func CompareGotaFrame

func CompareGotaFrame(a, b *GotaFrame) bool

CompareGotaFrame compares GotaFrame a and b If they are same GotaFrame, return true else return false

func DumpStacks

func DumpStacks()

func EmbedClientIDHeaderToPayload

func EmbedClientIDHeaderToPayload(gf *GotaFrame)

func FromEnvironment

func FromEnvironment() proxy.Dialer

func FromURL

func FromURL(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error)

func GoFileLine

func GoFileLine() int

GoFileLine return the current executing line number

func GoFileName

func GoFileName() string

GoFileName return the file name

func GoFileNameFull

func GoFileNameFull() string

GofileNameFull return the full path of the current file

func GoFuncName

func GoFuncName() string

GoFuncName return the current executing function name

func IsVerbose

func IsVerbose() bool

func ParseClientIDHeaderFromPayload

func ParseClientIDHeaderFromPayload(gf *GotaFrame)

func ReadNBytes

func ReadNBytes(r io.Reader, n int) ([]byte, error)

ReadNBytes read N bytes from io.Reader, it never returns the io.EOF.

If it read N bytes from io.Reader, returns nil. If it read io.EOF, but less than N bytes, return ErrNoMoreBytes. If it read other errors, returns them.

func Recover

func Recover()

func RuntimeInfo

func RuntimeInfo(depthList ...int) string

RuntimeInfo return a string containing the file name, function name and the line number of a specified entry on the call stack use list for parameter, we can call this function pass null parameter

func SetLogLevel

func SetLogLevel(l string)

func SetVerbose

func SetVerbose(v bool)

func ShutdownGota

func ShutdownGota()

func TMAuth

func TMAuth(auth *TunnelAuthCredential) func(tm *TunnelManager) error

func Verbosef

func Verbosef(format string, args ...interface{})

func WrapGotaFrame

func WrapGotaFrame(gf *GotaFrame) []byte

func WriteNBytes

func WriteNBytes(w io.Writer, n int, d []byte) error

WriteNBytes write N bytes to io.Writer

Types

type ByteSize

type ByteSize float64
const (
	KB ByteSize = 1 << (10 * iota)
	MB
	GB
	TB
	PB
	EB
	ZB
	YB
)

func (ByteSize) String

func (b ByteSize) String() string

type CCID

type CCID uint64

CCID combines client ID and connection ID into a uint64 for the key of map struct +-----------------------+-----------------------+ | client id: 32 bit | connection id: 32 bit | +-----------------------+-----------------------+

func NewCCID

func NewCCID(clientID ClientID, connID uint32) (cc CCID)

NewCCID return a new CCID with client id and conn id

func (CCID) ClientID

func (cc CCID) ClientID() ClientID

ClientID return client id

func (CCID) ConnID

func (cc CCID) ConnID() uint32

ConnID return connection id

type ClientID

type ClientID = uint32

type ConnHandler

type ConnHandler struct {
	ClientID ClientID
	ConnID   uint32

	WriteToTunnelC  chan *GotaFrame
	ReadFromTunnelC chan *GotaFrame
	// contains filtered or unexported fields
}

func (*ConnHandler) CreateFastOpenConn

func (ch *ConnHandler) CreateFastOpenConn()

CreateFastOpenConn send request to create a peer connection, but does not wait the response.

func (*ConnHandler) CreatePeerConn

func (ch *ConnHandler) CreatePeerConn() bool

CreatePeerConn send request to create a peer connection. It will wait for the first response, if the response gota frame is not a control for "TMCreateConnOKSeq", it will return false.

func (*ConnHandler) Start

func (ch *ConnHandler) Start()

Start forward traffic between local request and remote response

func (*ConnHandler) Stop

func (ch *ConnHandler) Stop()

Stop froward traffic

func (*ConnHandler) Stopped

func (ch *ConnHandler) Stopped() bool

Stopped return the connection handler's current status

type ConnManager

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

ConnManager manage connections from listening from local port or connecting to remote server

func NewConnManager

func NewConnManager() *ConnManager

NewConnManager returns a new ConnManager, We should use the channels of this ConnManager to set up TunnelMangager

func (*ConnManager) EnableFastOpen

func (cm *ConnManager) EnableFastOpen()

func (*ConnManager) ListenAndServe

func (cm *ConnManager) ListenAndServe(addr string) error

ListenAndServe listens for addr with port and handles connections coming from them. This function can be both client and server

func (*ConnManager) NewCCIDChannel

func (cm *ConnManager) NewCCIDChannel() chan CCID

NewCCIDChannel returns the newCCIDChannel for creating a new connection

func (*ConnManager) ReadFromTunnelChannel

func (cm *ConnManager) ReadFromTunnelChannel() chan *GotaFrame

ReadFromTunnelChannel returns the channel which ConnHandler should use to read from tunnel

func (*ConnManager) Serve

func (cm *ConnManager) Serve(addr string)

Serve just waits request for new connections from tunnel This function can be used in both client and server

func (*ConnManager) SetConnPool

func (cm *ConnManager) SetConnPool(n int, alive int)

func (*ConnManager) Stop

func (cm *ConnManager) Stop()

Stop connection manager

func (*ConnManager) WriteToTunnelChannel

func (cm *ConnManager) WriteToTunnelChannel() chan *GotaFrame

WriteToTunnelChannel returns the channel which ConnHandler should use to write to tunnel

type ConnPool

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

func NewConnPool

func NewConnPool(n int, alive int, addr *net.TCPAddr) *ConnPool

func (*ConnPool) Fetch

func (c *ConnPool) Fetch() io.ReadWriteCloser

func (*ConnPool) Start

func (c *ConnPool) Start()

func (*ConnPool) Stop

func (c *ConnPool) Stop()

type Gota

type Gota struct {
	ConnManager   *ConnManager
	TunnelManager *TunnelManager
}

Gota provides quick usage for gota

func NewGota

func NewGota(config interface{}, auth *TunnelAuthCredential) *Gota

NewGota returns a Gota with mounted ConnManager and TunnelManager

func (*Gota) ListenAndServe

func (g *Gota) ListenAndServe(addr string)

ListenAndServe listen at local for user connections and connect remote tunnel for forwarding traffic

func (*Gota) Serve

func (g *Gota) Serve(addr string)

Serve listen at local for tunnels

type GotaFrame

type GotaFrame struct {
	// Control
	Control bool
	// Connection ID, when ConnID > (1 << 31), this frame is a control frame
	ConnID uint32
	// Sequence number, when this frame is a control frame, SeqNum will be used from control
	SeqNum uint32
	// Data length
	Length int
	// Data
	Payload []byte
	// contains filtered or unexported fields
}
var TMCloseTunnelGotaFrame *GotaFrame
var TMCloseTunnelOKGotaFrame *GotaFrame
var TMHeartBeatPingGotaFrame *GotaFrame
var TMHeartBeatPongGotaFrame *GotaFrame
var TMTunnelAuthErrGotaFrame *GotaFrame
var TMTunnelAuthOKGotaFrame *GotaFrame

func NewBasicAuthGotaFrame

func NewBasicAuthGotaFrame(username, password string) *GotaFrame

func ReadGotaFrame

func ReadGotaFrame(r io.Reader) (*GotaFrame, error)

func UnwrapGotaFrame

func UnwrapGotaFrame(data []byte) *GotaFrame

func (GotaFrame) IsControl

func (gf GotaFrame) IsControl() bool

IsControl return if this frame is a control type

func (*GotaFrame) MarshalBinary

func (gf *GotaFrame) MarshalBinary() (data []byte, err error)

MarshalBinary generates GotaFrame to bytes

func (GotaFrame) String

func (gf GotaFrame) String() string

String for logging

func (*GotaFrame) UnmarshalBinary

func (gf *GotaFrame) UnmarshalBinary(data []byte) error

UnmarshalBinary parses from bytes and sets up GotaFrame

type RWCloseReader

type RWCloseReader interface {
	CloseRead() error
	io.ReadWriteCloser
}

RWCloseReader add CloseRead to io.ReadWriteCloser for only closing read after call func CloseRead, io.ReadWriteCloser can still be write

type RWCloseWriter

type RWCloseWriter interface {
	CloseWrite() error
	io.ReadWriteCloser
}

RWCloseWriter add CloseWrite to io.ReadWriteCloser for only closing write after call func CloseWrite, io.ReadWriteCloser can still be read

type Statistic

type Statistic struct {
	SentBytes     uint64
	ReceivedBytes uint64
	StartSeconds  int64
	// contains filtered or unexported fields
}

Statistic contains the traffic status

func NewStatistic

func NewStatistic(n int) *Statistic

func (*Statistic) AddReceivedBytes

func (s *Statistic) AddReceivedBytes(c uint64)

AddReceivedBytes update the ReceivedBytes by bytes

func (*Statistic) AddSentBytes

func (s *Statistic) AddSentBytes(c uint64)

AddSentBytes update the SentBytes by bytes

func (*Statistic) ReceiveSpeed

func (s *Statistic) ReceiveSpeed() uint64

ReceiveSpeed return the bytes received per second

func (*Statistic) ReceiveSpeedSecond

func (s *Statistic) ReceiveSpeedSecond(n int64) uint64

ReceiveSpeedSecond return the bytes received per second

func (*Statistic) SendSpeed

func (s *Statistic) SendSpeed() uint64

SendSpeed return the bytes sent per second

func (*Statistic) SendSpeedSecond

func (s *Statistic) SendSpeedSecond(n int64) uint64

SendSpeedSecond return the bytes sent per second

type TunnelActiveConfig

type TunnelActiveConfig struct {
	LocalAddr  *net.TCPAddr
	RemoteAddr *net.TCPAddr
	Proxy      *url.URL
}

type TunnelAuthCredential

type TunnelAuthCredential struct {
	UserName string
	Password string
}

type TunnelManager

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

func NewTunnelManager

func NewTunnelManager(rc chan *GotaFrame, wc chan *GotaFrame, options ...func(*TunnelManager) error) *TunnelManager

NewTunnelManager returns a new TunnelManager rc is used for reading from connection manager wc is used for writing to connection manager

func (*TunnelManager) Mode

func (tm *TunnelManager) Mode() int

func (*TunnelManager) SetCCIDChannel

func (tm *TunnelManager) SetCCIDChannel(c chan CCID)

func (*TunnelManager) SetClientID

func (tm *TunnelManager) SetClientID(c ClientID)

func (*TunnelManager) SetConfig

func (tm *TunnelManager) SetConfig(config interface{}) error

func (*TunnelManager) SetWhiteIPs

func (tm *TunnelManager) SetWhiteIPs(s []string)

func (*TunnelManager) Start

func (tm *TunnelManager) Start()

func (*TunnelManager) Stop

func (tm *TunnelManager) Stop()

type TunnelPassiveConfig

type TunnelPassiveConfig struct {
	*net.TCPAddr
}

type TunnelTransport

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

func NewTunnelTransport

func NewTunnelTransport(config interface{}, wp, rp chan<- chan *GotaFrame, rw io.ReadWriteCloser, mode int, cleanRead chan ClientID, cleanWrite chan ClientID, clientID ...ClientID) *TunnelTransport

func (*TunnelTransport) SetCCIDChannel

func (t *TunnelTransport) SetCCIDChannel(c chan CCID)

func (*TunnelTransport) Start

func (t *TunnelTransport) Start()

Start method starts the run loop for the worker, listening for a quit channel in case we need to stop it

func (*TunnelTransport) Stop

func (t *TunnelTransport) Stop()

Stop signals the worker to stop listening for work requests.

func (*TunnelTransport) Stopped

func (t *TunnelTransport) Stopped() bool

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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