connection

package
v0.0.0-...-df93b5d Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2016 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Provides leaky buffer, based on the example in Effective Go.

Index

Constants

View Source
const (
	OneTimeAuthMask byte = 0x10
	AddrMask        byte = 0xf
)

Variables

View Source
var ReqList = map[string]*ReqNode{}

Functions

func CheckCipherMethod

func CheckCipherMethod(method string) error

func ParseHeader

func ParseHeader(addr net.Addr) ([]byte, int)

func PipeThenClose

func PipeThenClose(src, dst net.Conn, timeout time.Duration)

PipeThenClose copies data from src to dst, closes dst when done.

func PipeThenCloseOta

func PipeThenCloseOta(src *Conn, dst net.Conn, timeout time.Duration)

PipeThenClose copies data from src to dst, closes dst when done, with ota verification.

func Pipeloop

func Pipeloop(ss *UDPConn, srcaddr *net.UDPAddr, remote UDP)

func RawAddr

func RawAddr(addr string) (buf []byte, err error)

func SetReadTimeout

func SetReadTimeout(c net.Conn, timeout time.Duration)

Types

type CachedUDPConn

type CachedUDPConn struct {
	UDP
	// contains filtered or unexported fields
}

func NewCachedUDPConn

func NewCachedUDPConn(cn UDP) *CachedUDPConn

func (*CachedUDPConn) Check

func (c *CachedUDPConn) Check()

func (*CachedUDPConn) Close

func (c *CachedUDPConn) Close() error

func (*CachedUDPConn) Refresh

func (c *CachedUDPConn) Refresh() bool

func (*CachedUDPConn) SetTimer

func (c *CachedUDPConn) SetTimer(index string)

type Cipher

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

func NewCipher

func NewCipher(method, password string) (c *Cipher, err error)

NewCipher creates a cipher that can be used in Dial() etc. Use cipher.Copy() to create a new cipher with the same method and password to avoid the cost of repeated cipher initialization.

func (*Cipher) Copy

func (c *Cipher) Copy() *Cipher

Copy creates a new cipher at it's initial state.

type Conn

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

func Dial

func Dial(addr, server string, cipher *Cipher) (c *Conn, err error)

addr should be in the form of host:port

func DialWithRawAddr

func DialWithRawAddr(rawaddr []byte, server string, cipher *Cipher) (c *Conn, err error)

This is intended for use by users implementing a local socks proxy. rawaddr shoud contain part of the data in socks request, starting from the ATYP field. (Refer to rfc1928 for more information.)

func NewConn

func NewConn(c net.Conn, cipher *Cipher) *Conn

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) GetAndIncrChunkId

func (c *Conn) GetAndIncrChunkId() (chunkId uint32)

func (*Conn) GetIv

func (c *Conn) GetIv() (iv []byte)

func (*Conn) GetKey

func (c *Conn) GetKey() (key []byte)

func (*Conn) IsOta

func (c *Conn) IsOta() bool

func (*Conn) Read

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

func (*Conn) Write

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

type DecOrEnc

type DecOrEnc int
const (
	Decrypt DecOrEnc = iota
	Encrypt
)

type LeakyBuf

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

func NewLeakyBuf

func NewLeakyBuf(n, bufSize int) *LeakyBuf

NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each with bufSize bytes.

func (*LeakyBuf) Get

func (lb *LeakyBuf) Get() (b []byte)

Get returns a buffer from the leaky buffer or create a new buffer.

func (*LeakyBuf) Put

func (lb *LeakyBuf) Put(b []byte)

Put add the buffer into the free buffer pool for reuse. Panic if the buffer size is not the same with the leaky buffer's. This is intended to expose error usage of leaky buffer.

type NATlist

type NATlist struct {
	sync.Mutex
	Conns      map[string]*CachedUDPConn
	AliveConns int
}

func (*NATlist) Delete

func (nl *NATlist) Delete(srcaddr string)

func (*NATlist) Get

func (nl *NATlist) Get(srcaddr *net.UDPAddr, ss *UDPConn) (c *CachedUDPConn, ok bool, err error)

type ReqNode

type ReqNode struct {
	Req    []byte
	ReqLen int
}

type UDP

type UDP interface {
	ReadFromUDP(b []byte) (n int, src *net.UDPAddr, err error)
	Read(b []byte) (n int, err error)
	WriteToUDP(b []byte, src *net.UDPAddr) (n int, err error)
	Write(b []byte) (n int, err error)
	Close() error
	SetWriteDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	ReadFrom(b []byte) (int, net.Addr, error)
}

UDP is a udp relay interface

type UDPConn

type UDPConn struct {
	UDP
	*Cipher
	// contains filtered or unexported fields
}

UDPConn maintain a udp connection list

func NewUDPConn

func NewUDPConn(cn UDP, cipher *Cipher, timeout time.Duration) *UDPConn

func (*UDPConn) Read

func (c *UDPConn) Read(b []byte) (n int, err error)

func (*UDPConn) ReadAndHandleUDPReq

func (c *UDPConn) ReadAndHandleUDPReq()

func (*UDPConn) ReadFromUDP

func (c *UDPConn) ReadFromUDP(b []byte) (n int, src *net.UDPAddr, err error)

n is the size of the payload

func (*UDPConn) Write

func (c *UDPConn) Write(b []byte) (n int, err error)

func (*UDPConn) WriteToUDP

func (c *UDPConn) WriteToUDP(b []byte, src *net.UDPAddr) (n int, err error)

n = iv + payload

Jump to

Keyboard shortcuts

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