tunnel

package
v4.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2019 License: BSD-3-Clause, GPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ST_UNKNOWN = 0x00
	ST_SYN     = 0x01
	ST_EST     = 0x03
)
View Source
const (
	MSG_UNKNOWN = iota
	MSG_SYN
	MSG_RESULT
	MSG_DATA
	MSG_WND
	MSG_FIN
)
View Source
const (
	ERR_NONE = iota
	ERR_IDEXIST
	ERR_CONNFAILED
	ERR_TIMEOUT
	ERR_CLOSED
	ERR_UNKNOWN_PROTOCOL
)
View Source
const (
	PULSEBUFSIZE = 64
)

Variables

View Source
var (
	ErrTypeError      = errors.New("type dismatch")
	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("stream id exist.")
	ErrIdNotExist     = errors.New("stream id not exist.")
	ErrState          = errors.New("status error.")
	ErrNotImpl        = errors.New("not implemented")
	ErrDialFailed     = errors.New("dial failed")
)
View Source
var ErrnoText = map[uint32]string{
	ERR_NONE:             "none",
	ERR_IDEXIST:          "stream id existed",
	ERR_CONNFAILED:       "connected failed",
	ERR_TIMEOUT:          "timeout",
	ERR_CLOSED:           "connect closed",
	ERR_UNKNOWN_PROTOCOL: "unknown network protocol",
}
View Source
var (
	MSG_OK = []byte{0x00}
)
View Source
var MsgText = map[uint8]string{
	MSG_UNKNOWN: "UNKNOWN",
	MSG_SYN:     "SYN",
	MSG_RESULT:  "RESULT",
	MSG_DATA:    "DATA",
	MSG_WND:     "WND",
	MSG_FIN:     "FIN",
}
View Source
var Protocols map[string]TunHandler
View Source
var StatusText = map[uint8]string{
	ST_UNKNOWN: "UNKNOWN",
	ST_SYN:     "SYN",
	ST_EST:     "ESTAB",
}

Functions

func RegisterNetwork

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

FIXME: protocol pulse

func SendFrame

func SendFrame(fiber Fiber, 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 Client

type Client struct {
	*Fabric
	// contains filtered or unexported fields
}

func NewClient

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

func (*Client) Dial

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

func (*Client) DialTimeout

func (client *Client) DialTimeout(network, address string, timeout time.Duration) (conn net.Conn, err error)

func (*Client) RunPulse

func (cli *Client) RunPulse()

type Conn

type Conn struct {
	Network string
	Address string
	Tx      int
	Rx      int

	TxSpeed int
	RxSpeed int
	// contains filtered or unexported fields
}

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

func (*Conn) Accept

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

func (*Conn) Close

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

func (*Conn) Deny

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

func (*Conn) Details

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

func (*Conn) Final

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

func (*Conn) GetStatus

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

func (*Conn) GetStreamId

func (c *Conn) GetStreamId() uint16

func (*Conn) GetTarget

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

func (*Conn) HandleFrame

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

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) 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) UpdateSpeed

func (c *Conn) UpdateSpeed(interval int)

func (*Conn) Uptime

func (c *Conn) Uptime() (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 DatagramConn

type DatagramConn struct {
	*Conn
	// contains filtered or unexported fields
}

func NewDatagramConn

func NewDatagramConn(c *Conn) (dc *DatagramConn)

func (*DatagramConn) Read

func (dc *DatagramConn) Read(data []byte) (n int, err error)

func (*DatagramConn) Write

func (dc *DatagramConn) Write(data []byte) (n int, err error)

type Fabric

type Fabric struct {
	net.Conn

	Tx int
	Rx int

	TxSpeed int
	RxSpeed int
	// 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) Details

func (fab *Fabric) Details() (s string)

func (*Fabric) Final

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

func (*Fabric) GetConn

func (fab *Fabric) GetConn(id uint16) (c *Conn, err error)

func (*Fabric) GetConnections

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

func (*Fabric) GetSize

func (fab *Fabric) GetSize() int

func (*Fabric) HandleFrame

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

func (*Fabric) Loop

func (fab *Fabric) Loop()

func (*Fabric) RunUpdateSpeed

func (fab *Fabric) RunUpdateSpeed()

func (*Fabric) String

func (fab *Fabric) String() string

func (*Fabric) UpdateSpeed

func (fab *Fabric) UpdateSpeed(interval int)

func (*Fabric) Uptime

func (fab *Fabric) Uptime() (s string)

type Fiber

type Fiber interface {
	HandleFrame(*Frame) error
	Final() 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)
type Header struct {
	Type     uint8
	Length   uint16
	Streamid uint16
}

func (*Header) Debug

func (hdr *Header) Debug() string

type Pulse

type Pulse struct {
}

func (*Pulse) ServeTun

func (p *Pulse) ServeTun(c *Conn) (err error)

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 Server

type Server struct {
	*Fabric
}

func NewServer

func NewServer(conn net.Conn) (s *Server)

func (*Server) HandleFrame

func (s *Server) HandleFrame(f *Frame) (err error)

type Syn

type Syn struct {
	Network string
	Address string
}

type TCPProxy

type TCPProxy struct {
}

func (*TCPProxy) ServeTun

func (p *TCPProxy) ServeTun(c *Conn) (err error)

type TunHandler

type TunHandler interface {
	ServeTun(*Conn) error
}

type Tunnel

type Tunnel interface {
	Loop()
	LocalAddr() net.Addr
	String() string
	Close() error
	Uptime() string
	GetSize() int
	Details() string
	GetConnections() ConnSlice
	GetConn(uint16) (*Conn, error)
}

type UDPProxy

type UDPProxy struct {
}

func (*UDPProxy) ServeTun

func (p *UDPProxy) ServeTun(c *Conn) (err error)

Jump to

Keyboard shortcuts

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