tunnel

package
v3.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2018 License: BSD-3-Clause, GPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AUTH_TIMEOUT  = 10000
	DIAL_TIMEOUT  = 20000
	WRITE_TIMEOUT = 10000
	CLOSE_TIMEOUT = 30000
	WINDOWSIZE    = 4 * 1024 * 1024
)
View Source
const (
	MSG_UNKNOWN = iota
	MSG_RESULT
	MSG_AUTH
	MSG_DATA
	MSG_SYN
	MSG_WND
	MSG_FIN
	MSG_RST
)
View Source
const (
	ST_UNKNOWN  = 0x00
	ST_SYN_RECV = 0x01
	ST_SYN_SENT = 0x02
	ST_EST      = 0x03
	ST_FIN_RECV = 0x04
	ST_FIN_SENT = 0x06
)
View Source
const (
	ERR_NONE = iota
	ERR_AUTH
	ERR_IDEXIST
	ERR_CONNFAILED
	ERR_TIMEOUT
	ERR_CLOSED
	ERR_UNKNOWN_PROTOCOL
)

Variables

View Source
var (
	ErrFrameOverFlow  = errors.New("marshal overflow in frame")
	ErrUnknownNetwork = errors.New("unknown network.")
	ErrStreamOutOfID  = errors.New("stream out of id.")
	ErrUnexpectedPkg  = errors.New("unexpected package.")
	ErrIdExist        = errors.New("frame sync stream id exist.")
	ErrState          = errors.New("status error.")
)
View Source
var ErrnoText = map[uint32]string{
	ERR_NONE:       "none",
	ERR_AUTH:       "auth failed",
	ERR_IDEXIST:    "stream id existed",
	ERR_CONNFAILED: "connected failed",
	ERR_TIMEOUT:    "timeout",
	ERR_CLOSED:     "connect closed",
}
View Source
var ProtocolHandlers map[string]Handler
View Source
var StatusText = map[uint8]string{
	ST_UNKNOWN:  "UNKNOWN",
	ST_SYN_RECV: "SYN_RECV",
	ST_SYN_SENT: "SYN_SENT",
	ST_EST:      "ESTAB",
	ST_FIN_RECV: "FIN_RECV",
	ST_FIN_SENT: "FIN_SENT",
}

Functions

func AuthConn

func AuthConn(auth PasswordAuthenticator, conn net.Conn) (err error)

func RecvWithTimeout

func RecvWithTimeout(ch chan uint32, t time.Duration) (errno uint32)

func RegisterNetwork

func RegisterNetwork(network string, handler Handler) (ok bool)

func RunMockServer

func RunMockServer(wg *sync.WaitGroup) (err error)

func SendFrame

func SendFrame(fiber Fiber, tp uint8, streamid uint16, v interface{}) (err error)

func SetLogging

func SetLogging()

func WriteFrame

func WriteFrame(stream io.Writer, tp uint8, streamid uint16, v interface{}) (err error)

Types

type Addr

type Addr struct {
	net.Addr
	// contains filtered or unexported fields
}

func (*Addr) String

func (a *Addr) String() (s string)

type Auth

type Auth struct {
	Username string
	Password string
}

type Client

type Client struct {
	*Fabric
}

func NewClient

func NewClient(conn net.Conn) (client *Client)

func (*Client) CloseFiber

func (client *Client) CloseFiber(streamid uint16) (err error)

func (*Client) Dial

func (client *Client) Dial(network, address string) (conn net.Conn, err error)

func (*Client) SendFrame

func (client *Client) SendFrame(f *Frame) (err error)

type Conn

type Conn struct {
	Network string
	Address string
	// contains filtered or unexported fields
}

use lock to protect: status, window. SendFrame are not included.

func NewConn

func NewConn(fab *Fabric) (c *Conn)

func (*Conn) Accept

func (c *Conn) Accept() (err error)

func (*Conn) CheckAndSetStatus

func (c *Conn) CheckAndSetStatus(old uint8, new uint8) (err error)

func (*Conn) Close

func (c *Conn) Close() (err error)

func (*Conn) CloseFiber

func (c *Conn) CloseFiber(streamid uint16) (err error)

func (*Conn) Connect

func (c *Conn) Connect(network, address string) (err error)

func (*Conn) Deny

func (c *Conn) Deny() (err error)

func (*Conn) Final

func (c *Conn) Final()

func (*Conn) GetStatusString

func (c *Conn) GetStatusString() (st string)

func (*Conn) GetStreamId

func (c *Conn) GetStreamId() uint16

func (*Conn) GetTarget

func (c *Conn) GetTarget() (s string)

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (c *Conn) Read(data []byte) (n int, err error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) Reset

func (c *Conn) Reset()

func (*Conn) SendFrame

func (c *Conn) SendFrame(f *Frame) (err error)

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) String

func (c *Conn) String() (s string)

func (*Conn) Write

func (c *Conn) Write(data []byte) (n int, err error)

type ConnSlice

type ConnSlice []*Conn

func (ConnSlice) Len

func (cs ConnSlice) Len() int

func (ConnSlice) Less

func (cs ConnSlice) Less(i, j int) bool

func (ConnSlice) Swap

func (cs ConnSlice) Swap(i, j int)

type DialerCreator

type DialerCreator struct {
	netutil.Dialer
	// contains filtered or unexported fields
}

func NewDialerCreator

func NewDialerCreator(raw netutil.Dialer, network, serveraddr, username, password string) (dc *DialerCreator)

func (*DialerCreator) Create

func (dc *DialerCreator) Create() (client *Client, err error)

type Fabric

type Fabric struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewFabric

func NewFabric(conn net.Conn, next_id uint16) (fab *Fabric)

func (*Fabric) Close

func (fab *Fabric) Close() (err error)

func (*Fabric) CloseFiber

func (fab *Fabric) CloseFiber(streamid uint16) (err error)

func (*Fabric) GetConnections

func (fab *Fabric) GetConnections() (conns ConnSlice)

func (*Fabric) GetSize

func (fab *Fabric) GetSize() int

func (*Fabric) Loop

func (fab *Fabric) Loop()

func (*Fabric) PutIntoId

func (fab *Fabric) PutIntoId(id uint16, f Fiber) (err error)

func (*Fabric) PutIntoNextId

func (fab *Fabric) PutIntoNextId(f Fiber) (id uint16, err error)

func (*Fabric) SendFrame

func (fab *Fabric) SendFrame(f *Frame) (err error)

func (*Fabric) String

func (fab *Fabric) String() string

func (*Fabric) Uptime

func (fab *Fabric) Uptime() (d time.Duration)

type Fiber

type Fiber interface {
	SendFrame(*Frame) error
	CloseFiber(uint16) error
}

type Frame

type Frame struct {
	Header
	Data []byte
}

func NewFrame

func NewFrame(tp uint8, streamid uint16) (f *Frame)

func ReadFrame

func ReadFrame(r io.Reader, v interface{}) (f *Frame, err error)

func (*Frame) Marshal

func (f *Frame) Marshal(v interface{}) (err error)

func (*Frame) Pack

func (f *Frame) Pack() (b []byte)

func (*Frame) Unmarshal

func (f *Frame) Unmarshal(v interface{}) (err error)

func (*Frame) WriteTo

func (f *Frame) WriteTo(stream io.Writer) (err error)

type Handler

type Handler interface {
	Handle(net.Conn) error
}
type Header struct {
	Type     uint8
	Length   uint16
	Streamid uint16
}

func (*Header) Debug

func (hdr *Header) Debug() string

type MockServer

type MockServer struct {
}

func (*MockServer) AuthPass

func (m *MockServer) AuthPass(username, password string) bool

func (*MockServer) Handle

func (m *MockServer) Handle(conn net.Conn) (err error)

type PasswordAuthenticator

type PasswordAuthenticator interface {
	AuthPass(string, string) bool
}

type Queue

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

func NewQueue

func NewQueue() (q *Queue)

func (*Queue) Close

func (q *Queue) Close() (err error)

func (*Queue) Pop

func (q *Queue) Pop(block bool) (v interface{}, err error)

func (*Queue) Push

func (q *Queue) Push(v interface{}) (err error)

type Result

type Result uint32

type Server

type Server struct {
	Handler
}

func (*Server) Serve

func (server *Server) Serve(listener net.Listener) (err error)

type Syn

type Syn struct {
	Network string
	Address string
}

type TcpProxy

type TcpProxy struct {
}

func (*TcpProxy) DialMaybeTimeout

func (p *TcpProxy) DialMaybeTimeout(network, address string) (conn net.Conn, err error)

func (*TcpProxy) Handle

func (p *TcpProxy) Handle(fabconn net.Conn) (err error)

type Tunnel

type Tunnel interface {
	String() string
	GetSize() int
	Loop()
	Close() error
}

type TunnelServer

type TunnelServer struct {
	*Fabric
}

func NewTunnelServer

func NewTunnelServer(conn net.Conn) (s *TunnelServer)

func (*TunnelServer) CloseFiber

func (s *TunnelServer) CloseFiber(streamid uint16) (err error)

never called as default fiber.

func (*TunnelServer) SendFrame

func (s *TunnelServer) SendFrame(f *Frame) (err error)

type Wnd

type Wnd uint32

TODO: use json in wnd may cause performance problem.

Jump to

Keyboard shortcuts

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