Documentation
¶
Index ¶
- Constants
- Variables
- func CompareGotaFrame(a, b *GotaFrame) bool
- func DumpStacks()
- func EmbedClientIDHeaderToPayload(gf *GotaFrame)
- func FromEnvironment() proxy.Dialer
- func FromURL(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error)
- func GoFileLine() int
- func GoFileName() string
- func GoFileNameFull() string
- func GoFuncName() string
- func IsVerbose() bool
- func ParseClientIDHeaderFromPayload(gf *GotaFrame)
- func ReadNBytes(r io.Reader, n int) ([]byte, error)
- func Recover()
- func RuntimeInfo(depthList ...int) string
- func SetLogLevel(l string)
- func SetVerbose(v bool)
- func ShutdownGota()
- func TMAuth(auth *TunnelAuthCredential) func(tm *TunnelManager) error
- func Verbosef(format string, args ...interface{})
- func WrapGotaFrame(gf *GotaFrame) []byte
- func WriteNBytes(w io.Writer, n int, d []byte) error
- type ByteSize
- type CCID
- type ClientID
- type ConnHandler
- type ConnManager
- func (cm *ConnManager) EnableFastOpen()
- func (cm *ConnManager) ListenAndServe(addr string) error
- func (cm *ConnManager) NewCCIDChannel() chan CCID
- func (cm *ConnManager) ReadFromTunnelChannel() chan *GotaFrame
- func (cm *ConnManager) Serve(addr string)
- func (cm *ConnManager) SetConnPool(n int, alive int)
- func (cm *ConnManager) Stop()
- func (cm *ConnManager) WriteToTunnelChannel() chan *GotaFrame
- type ConnPool
- type Gota
- type GotaFrame
- type RWCloseReader
- type RWCloseWriter
- type Statistic
- type TunnelActiveConfig
- type TunnelAuthCredential
- type TunnelManager
- func (tm *TunnelManager) Mode() int
- func (tm *TunnelManager) SetCCIDChannel(c chan CCID)
- func (tm *TunnelManager) SetClientID(c ClientID)
- func (tm *TunnelManager) SetConfig(config interface{}) error
- func (tm *TunnelManager) SetWhiteIPs(s []string)
- func (tm *TunnelManager) Start()
- func (tm *TunnelManager) Stop()
- type TunnelPassiveConfig
- type TunnelTransport
Constants ¶
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 )
const ( TMConnBiuniqueMode = iota TMConnOverlapMode TMConnMultiBiuniqueMode TMConnMultiOverlapMode )
const ( ActiveMode = iota PassiveMode )
const CHMaxRetryTimes = 3
const ControlFlagBit = 1 << 31
const DefaultConnAliveSecond = 120
const DefaultConnCount = 10
const FastOpenDelayNanosecond = 1000
const FastOpenInitSeqNum = 0
const HeaderLength = 10
const MaxConnID = 1<<31 - 1
const MaxDataLength = 64 * 1024
const TMHeartBeatSecond = 60
Connection Manage HeartBeat Time
const TMHeartBeatTickerSecond = 600
const TMHeartBeatTimeOutSecond = 3000
const TMStatReportSecond = 60
Variables ¶
var ( Version = "gota_version" Commit = "gota_commit" )
var Direct = direct{}
Direct is a direct proxy: one that makes network connections directly.
var ErrInsufficientData = errors.New("Error Header, Insufficient Data for GotaFrame Header")
var ErrNoMoreBytes = errors.New("Read io.EOF, received bytes count less than required")
var ErrUnmatchedDataLength = errors.New("Unmatched Data Length for GotaFrame")
var HTTPSDialer = httpsDialer{}
HTTPSDialer is a https proxy: one that makes network connections on tls.
var HeaderOnly = errors.New("Gota Header Only")
var TLSConfig = &tls.Config{}
var TMCloseTunnelBytes []byte
var TMCloseTunnelOKBytes []byte
var TMControlSignalMap map[uint32]string
var TMErrUnsupportedConfig = errors.New("Unsupported configuration")
var TMHeartBeatPingBytes []byte
var TMHeartBeatPongBytes []byte
var TMTunnelAuthErrBytes []byte
var TMTunnelAuthOKBytes []byte
Functions ¶
func CompareGotaFrame ¶
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 GoFileNameFull ¶
func GoFileNameFull() string
GofileNameFull return the full path of the current file
func ParseClientIDHeaderFromPayload ¶
func ParseClientIDHeaderFromPayload(gf *GotaFrame)
func ReadNBytes ¶
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 RuntimeInfo ¶
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 WrapGotaFrame ¶
Types ¶
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 | +-----------------------+-----------------------+
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) 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) 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 (*ConnPool) Fetch ¶
func (c *ConnPool) Fetch() io.ReadWriteCloser
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 ¶
ListenAndServe listen at local for user connections and connect remote tunnel for forwarding traffic
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 UnwrapGotaFrame ¶
func (*GotaFrame) MarshalBinary ¶
MarshalBinary generates GotaFrame to bytes
func (*GotaFrame) UnmarshalBinary ¶
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 (*Statistic) AddReceivedBytes ¶
AddReceivedBytes update the ReceivedBytes by bytes
func (*Statistic) AddSentBytes ¶
AddSentBytes update the SentBytes by bytes
func (*Statistic) ReceiveSpeed ¶
ReceiveSpeed return the bytes received per second
func (*Statistic) ReceiveSpeedSecond ¶
ReceiveSpeedSecond return the bytes received per second
func (*Statistic) SendSpeedSecond ¶
SendSpeedSecond return the bytes sent per second
type TunnelActiveConfig ¶
type TunnelAuthCredential ¶
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 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