msocks

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2017 License: BSD-3-Clause, GPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AUTH_TIMEOUT  = 10000
	DIAL_TIMEOUT  = 30000
	DNS_TIMEOUT   = 30000
	WRITE_TIMEOUT = 60000
	WINDOWSIZE    = 4 * 1024 * 1024
)
View Source
const (
	ERR_NONE = iota
	ERR_AUTH
	ERR_IDEXIST
	ERR_CONNFAILED
	ERR_TIMEOUT
	ERR_CLOSED
)
View Source
const (
	ST_UNKNOWN = iota
	ST_SYN_RECV
	ST_SYN_SENT
	ST_EST
	ST_CLOSE_WAIT
	ST_FIN_WAIT
)
View Source
const (
	MSG_UNKNOWN = iota
	MSG_RESULT
	MSG_AUTH
	MSG_DATA
	MSG_SYN
	MSG_WND
	MSG_FIN
	MSG_RST
	MSG_PING
	MSG_DNS
	MSG_SPAM
)

Variables

View Source
var (
	ErrAuthFailed     = errors.New("auth failed %s.")
	ErrAuthTimeout    = errors.New("auth timeout %s.")
	ErrStreamNotExist = errors.New("stream not exist.")
	ErrQueueClosed    = errors.New("queue closed.")
	ErrUnexpectedPkg  = errors.New("unexpected package.")
	ErrNotSyn         = errors.New("frame result in conn which status is not syn.")
	ErrFinState       = errors.New("status not est or fin wait when get fin.")
	ErrIdExist        = errors.New("frame sync stream id exist.")
	ErrState          = errors.New("status error.")
	ErrUnknownState   = errors.New("unknown status.")
	ErrChanClosed     = errors.New("chan closed.")
	ErrDnsTimeOut     = errors.New("dns timeout.")
	ErrDnsMsgIllegal  = errors.New("dns message illegal.")
	ErrDnsLookuper    = errors.New("dns lookuper can't exchange.")
	ErrNoDnsServer    = errors.New("no proper dns server.")
)

Functions

func NewListener

func NewListener(raw net.Listener, auth *map[string]string) (listener net.Listener)

func ReadString

func ReadString(r io.Reader) (s string, err error)

func RecvWithTimeout

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

func WriteString

func WriteString(w io.Writer, s string) (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 ChanFrameSender

type ChanFrameSender chan Frame

func CreateChanFrameSender

func CreateChanFrameSender(n int) ChanFrameSender

func (*ChanFrameSender) CloseFrame

func (cfs *ChanFrameSender) CloseFrame() (err error)

func (*ChanFrameSender) RecvWithTimeout

func (cfs *ChanFrameSender) RecvWithTimeout(t time.Duration) (f Frame, err error)

func (*ChanFrameSender) SendFrame

func (cfs *ChanFrameSender) SendFrame(f Frame) (err error)

type Conn

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

func NewConn

func NewConn(streamid uint16, sess *Session, network, address string) (c *Conn)

func (*Conn) CheckAndSetStatus

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

func (*Conn) Close

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

func (*Conn) CloseFrame

func (c *Conn) CloseFrame() error

func (*Conn) Final

func (c *Conn) Final()

func (*Conn) GetAddress

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

func (*Conn) GetReadBufSize

func (c *Conn) GetReadBufSize() (n int32)

func (*Conn) GetStatusString

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

func (*Conn) GetStreamId

func (c *Conn) GetStreamId() uint16

func (*Conn) GetWriteBufSize

func (c *Conn) GetWriteBufSize() (n int32)

func (*Conn) InConnect

func (c *Conn) InConnect(errno uint32) (err error)

func (*Conn) InData

func (c *Conn) InData(ft *FrameData) (err error)

func (*Conn) InFin

func (c *Conn) InFin(ft *FrameFin) (err error)

func (*Conn) InWnd

func (c *Conn) InWnd(ft *FrameWnd) (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) SendFrame

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

func (*Conn) SendSynAndWait

func (c *Conn) SendSynAndWait() (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 {
	sutils.Dialer
	// contains filtered or unexported fields
}

func NewDialerCreator

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

func (*DialerCreator) Create

func (dc *DialerCreator) Create() (sess *Session, err error)

type Frame

type Frame interface {
	GetStreamid() uint16
	GetSize() uint16
	Packed() (buf *bytes.Buffer, err error)
	Unpack(r io.Reader) error
	Debug() string
}

func ReadFrame

func ReadFrame(r io.Reader) (f Frame, err error)

type FrameAuth

type FrameAuth struct {
	FrameBase
	Username string
	Password string
}

func NewFrameAuth

func NewFrameAuth(streamid uint16, username, password string) (f *FrameAuth)

func (*FrameAuth) Packed

func (f *FrameAuth) Packed() (buf *bytes.Buffer, err error)

func (*FrameAuth) Unpack

func (f *FrameAuth) Unpack(r io.Reader) (err error)

type FrameBase

type FrameBase struct {
	Type     uint8
	Length   uint16
	Streamid uint16
}

func (*FrameBase) Debug

func (f *FrameBase) Debug() string

func (*FrameBase) GetSize

func (f *FrameBase) GetSize() uint16

func (*FrameBase) GetStreamid

func (f *FrameBase) GetStreamid() uint16

func (*FrameBase) Packed

func (f *FrameBase) Packed() (buf *bytes.Buffer, err error)

func (*FrameBase) Unpack

func (f *FrameBase) Unpack(r io.Reader) (err error)

type FrameData

type FrameData struct {
	FrameBase
	Data []byte
}

func NewFrameData

func NewFrameData(streamid uint16, data []byte) (f *FrameData)

func NewFrameSpam

func NewFrameSpam(streamid uint16, data []byte) (f *FrameData)

func (*FrameData) Packed

func (f *FrameData) Packed() (buf *bytes.Buffer, err error)

func (*FrameData) Unpack

func (f *FrameData) Unpack(r io.Reader) (err error)

type FrameDns

type FrameDns struct {
	FrameBase
	Data []byte
}

func NewFrameDns

func NewFrameDns(streamid uint16, data []byte) (f *FrameDns)

func (*FrameDns) Packed

func (f *FrameDns) Packed() (buf *bytes.Buffer, err error)

func (*FrameDns) Unpack

func (f *FrameDns) Unpack(r io.Reader) (err error)

type FrameFin

type FrameFin struct {
	FrameBase
}

func NewFrameFin

func NewFrameFin(streamid uint16) (f *FrameFin)

func (*FrameFin) Unpack

func (f *FrameFin) Unpack(r io.Reader) (err error)

type FramePing

type FramePing struct {
	FrameBase
}

func NewFramePing

func NewFramePing() (f *FramePing)

func (*FramePing) Unpack

func (f *FramePing) Unpack(r io.Reader) (err error)

type FrameResult

type FrameResult struct {
	FrameBase
	Errno uint32
}

func NewFrameResult

func NewFrameResult(streamid uint16, errno uint32) (f *FrameResult)

func (*FrameResult) Packed

func (f *FrameResult) Packed() (buf *bytes.Buffer, err error)

func (*FrameResult) Unpack

func (f *FrameResult) Unpack(r io.Reader) (err error)

type FrameRst

type FrameRst struct {
	FrameBase
}

func NewFrameRst

func NewFrameRst(streamid uint16) (f *FrameRst)

func (*FrameRst) Unpack

func (f *FrameRst) Unpack(r io.Reader) (err error)

type FrameSender

type FrameSender interface {
	SendFrame(Frame) error
	CloseFrame() error
}

type FrameSpam

type FrameSpam struct {
	FrameBase
	Data []byte
}

func (*FrameSpam) Packed

func (f *FrameSpam) Packed() (buf *bytes.Buffer, err error)

func (*FrameSpam) Unpack

func (f *FrameSpam) Unpack(r io.Reader) (err error)

type FrameSyn

type FrameSyn struct {
	FrameBase
	Network string
	Address string
}

func NewFrameSyn

func NewFrameSyn(streamid uint16, net, addr string) (f *FrameSyn)

func (*FrameSyn) Debug

func (f *FrameSyn) Debug() string

func (*FrameSyn) Packed

func (f *FrameSyn) Packed() (buf *bytes.Buffer, err error)

func (*FrameSyn) Unpack

func (f *FrameSyn) Unpack(r io.Reader) (err error)

type FrameWnd

type FrameWnd struct {
	FrameBase
	Window uint32
}

func NewFrameWnd

func NewFrameWnd(streamid uint16, window uint32) (f *FrameWnd)

func (*FrameWnd) Debug

func (f *FrameWnd) Debug() string

func (*FrameWnd) Packed

func (f *FrameWnd) Packed() (buf *bytes.Buffer, err error)

func (*FrameWnd) Unpack

func (f *FrameWnd) Unpack(r io.Reader) (err error)

type Listener

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

func (*Listener) Accept

func (l *Listener) Accept() (conn net.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 Session

type Session struct {
	*sutils.ExchangerToLookuper
	net.Conn

	Readcnt  *SpeedCounter
	Writecnt *SpeedCounter
	// contains filtered or unexported fields
}

func NewSession

func NewSession(conn net.Conn, next_id uint16) (s *Session)

func (*Session) Close

func (s *Session) Close() (err error)

func (*Session) CloseFrame

func (s *Session) CloseFrame() error

func (*Session) Dial

func (s *Session) Dial(network, address string) (c *Conn, err error)

func (*Session) Exchange

func (s *Session) Exchange(quiz *dns.Msg) (resp *dns.Msg, err error)

func (*Session) GetPorts

func (s *Session) GetPorts() (ports []*Conn)

func (*Session) GetSize

func (s *Session) GetSize() int

func (*Session) GetSortedPorts

func (s *Session) GetSortedPorts() (ports ConnSlice)

func (*Session) LocalPort

func (s *Session) LocalPort() int

func (*Session) PutIntoId

func (s *Session) PutIntoId(id uint16, fs FrameSender) (err error)

func (*Session) PutIntoNextId

func (s *Session) PutIntoNextId(fs FrameSender) (id uint16, err error)

func (*Session) RemovePort

func (s *Session) RemovePort(streamid uint16) (err error)

func (*Session) Run

func (s *Session) Run()

func (*Session) SendFrame

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

func (*Session) String

func (s *Session) String() string

type SpeedCounter

type SpeedCounter struct {
	Spd uint32
	All uint64
	// contains filtered or unexported fields
}

func NewSpeedCounter

func NewSpeedCounter() (sc *SpeedCounter)

func (*SpeedCounter) Add

func (sc *SpeedCounter) Add(s uint32) uint32

func (*SpeedCounter) Close

func (sc *SpeedCounter) Close() error

func (*SpeedCounter) Update

func (sc *SpeedCounter) Update()

Jump to

Keyboard shortcuts

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