msocks

package
v2.1.2+incompatible Latest Latest
Warning

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

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

Documentation

Index

Constants

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_ADDRS
)
View Source
const (
	PINGTIME       = 5000
	PINGRANDOM     = 1000
	TIMEOUT_COUNT  = 6
	GAMEOVER_COUNT = 60

	DIAL_RETRY   = 6
	DIAL_TIMEOUT = 30000

	WINDOWSIZE = 2 * 1024 * 1024

	AUTH_TIMEOUT      = 5000
	MIN_SESS_NUM      = 2
	MAX_CONN_PRE_SESS = 16

	SHRINK_TIME = 5000
	SHRINK_RATE = 0.9
)
View Source
const (
	ERR_NONE = iota
	ERR_AUTH
	ERR_IDEXIST
	ERR_CONNFAILED
	ERR_TIMEOUT
	ERR_CLOSED
)

Variables

View Source
var (
	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")
	ErrSessionNotFound = errors.New("session not found")
)

Functions

func LoadPassfile

func LoadPassfile(filename string) (userpass map[string]string, err error)

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 Conn

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

func NewConn

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

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

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

func (*Conn) GetReadBufSize

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

func (*Conn) GetStatus

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

func (*Conn) GetStreamId

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

func (*Conn) GetWriteBufSize

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

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

func (c *Conn) WaitForConn(address string) (err error)

func (*Conn) Write

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

func (*Conn) WriteSlice

func (c *Conn) WriteSlice(data []byte) (err error)

type Dialer

type Dialer struct {
	SessionPool
	sutils.Dialer
	// contains filtered or unexported fields
}

func NewDialer

func NewDialer(dialer sutils.Dialer, serveraddr, username, password string) (d *Dialer, err error)

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (conn net.Conn, err error)

func (*Dialer) LookupIP

func (d *Dialer) LookupIP(host string) (addrs []net.IP, err error)

func (*Dialer) MakeSess

func (d *Dialer) MakeSess() (sess *Session, err error)

Do I really need sleep? When tcp connect, syn retris will took 2 min(127s). I retry this retry 6 times, it will be 762s = 12mins 42s, right? I think that's really enough for most of time. REMEMBER: don't modify net.ipv4.tcp_syn_retries, unless you know what you do.

type Frame

type Frame interface {
	GetStreamid() uint16
	GetSize() uint16
	Packed() (buf *bytes.Buffer, err error)
	Unpack(r io.Reader) error
	Debug(prefix 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(prefix 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 (*FrameData) Packed

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

func (*FrameData) Unpack

func (f *FrameData) 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 FrameSyn

type FrameSyn struct {
	FrameBase
	Address string
}

func NewFrameSyn

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

func (*FrameSyn) Debug

func (f *FrameSyn) Debug(prefix 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(prefix 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 MsocksService

type MsocksService struct {
	SessionPool
	// contains filtered or unexported fields
}

func NewService

func NewService(auth map[string]string, dialer sutils.Dialer) (ms *MsocksService, err error)

func (*MsocksService) Handler

func (ms *MsocksService) Handler(conn net.Conn)

func (*MsocksService) Serve

func (ms *MsocksService) Serve(listener net.Listener) (err error)

type PingPong

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

func NewPingPong

func NewPingPong(sender FrameSender) (p *PingPong)

func (*PingPong) GetLastPing

func (p *PingPong) GetLastPing() (d time.Duration)

func (*PingPong) IsGameOver

func (p *PingPong) IsGameOver() bool

func (*PingPong) Reset

func (p *PingPong) Reset()

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 {
	PingPong
	// contains filtered or unexported fields
}

func DialSession

func DialSession(conn net.Conn, username, password string) (s *Session, err error)

func NewSession

func NewSession(conn net.Conn) (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) GetId

func (s *Session) GetId() string

func (*Session) GetPorts

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

func (*Session) GetReadSpeed

func (s *Session) GetReadSpeed() int64

func (*Session) GetSize

func (s *Session) GetSize() int

func (*Session) GetWriteSpeed

func (s *Session) GetWriteSpeed() int64

func (*Session) LocalAddr

func (s *Session) LocalAddr() net.Addr

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

func (s *Session) RemoteAddr() net.Addr

func (*Session) RemovePorts

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

func (*Session) Run

func (s *Session) Run()

func (*Session) SendFrame

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

type SessionMaker

type SessionMaker interface {
	MakeSess() (*Session, error)
}

type SessionPool

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

func CreateSessionPool

func CreateSessionPool(sm SessionMaker) (sp SessionPool)

func (*SessionPool) Add

func (sp *SessionPool) Add(s *Session)

func (*SessionPool) CutAll

func (sp *SessionPool) CutAll()

func (*SessionPool) GetOrCreateSess

func (sp *SessionPool) GetOrCreateSess() (sess *Session)

func (*SessionPool) GetSess

func (sp *SessionPool) GetSess() (sess []*Session)

func (*SessionPool) GetSize

func (sp *SessionPool) GetSize() int

func (*SessionPool) Remove

func (sp *SessionPool) Remove(s *Session) (n int, err error)

Jump to

Keyboard shortcuts

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