Documentation ¶
Overview ¶
客户端实现udp代理使用, 服务端没有使用此文件
Index ¶
- Constants
- Variables
- func CheckCipherMethod(method string) error
- func CreateURI(method, password, host, port string) (uri string)
- func GetPublicIP() string
- func IsFileExist(path string) (bool, error)
- func PipeThenClose(src, dst net.Conn, addTraffic func(int))
- func Pipeloop(write net.PacketConn, writeAddr net.Addr, readClose net.PacketConn, ...)
- func PrintVersion()
- func RawAddr(addr string) (buf []byte, err error)
- func ReadAndHandleUDPReq(c *SecurePacketConn, addTraffic func(int)) (err error)
- func SetDebug(b bool)
- func SetReadTimeout(c net.Conn)
- func UpdateConfig(old, new *Config)
- type Cipher
- type Config
- type Conn
- type DecOrEnc
- type Dialer
- type LeakyBuf
- type NoneCipherStream
- type ProxyAddr
- type ProxyConn
- type SecurePacketConn
- func (c *SecurePacketConn) LocalAddr() net.Addr
- func (c *SecurePacketConn) ReadFrom(b []byte) (n int, src net.Addr, err error)
- func (c *SecurePacketConn) SetDeadline(t time.Time) error
- func (c *SecurePacketConn) SetReadDeadline(t time.Time) error
- func (c *SecurePacketConn) SetWriteDeadline(t time.Time) error
- func (c *SecurePacketConn) WriteTo(b []byte, dst net.Addr) (n int, err error)
Constants ¶
const ( // 地址类型 S5ipv4 byte = 0x01 S5domain byte = 0x03 S5ipv6 byte = 0x04 S5lenPort = 2 // port 字段长度 // VER NMETHODS CMD位置, S5VerIdx = 0 S5NmethodIdx = 1 S5CmdIdx = 1 // ATYP 字段前面的字节数 S5reqBaseLen = 3 S5repBaseLen = 3 // 从 ATYP 字段算起的下标 S5TypeIdx = 0 // address type index S5IP0Idx = 1 // ip address start index S5DmLenIdx = 1 // domain address length index S5Dm0Idx = 2 // domain address start index S5lenIPv4 = 1 + net.IPv4len + 2 // 1addrType + ipv4 + 2port S5lenIPv6 = 1 + net.IPv6len + 2 // 1addrType + ipv6 + 2port S5lenDmBase = 1 + 1 + 2 // 1addrType + 1addrLen + 2port, plus addrLen // 认证方式 S5NoAuthentication byte = 0x00 // 版本 S5Ver byte = 0x05 // CMD 字段 S5CmdConnect byte = 0x01 S5CmdBind byte = 0x02 S5CmdUdp byte = 0x03 )
客户端 -> 代理服务器, 请求认证:
+----+----------+----------+ |VER | NMETHODS | METHODS | +----+----------+----------+ | 1 | 1 | 1 to 255 | +----+----------+----------+
VER 版本号 固定为 5 NMETHODS 可供选择的认证方法 选了多少种 METHODS 选择的方法
代理服务器 -> 客户端, 确认信息
+----+--------+ |VER | METHOD | +----+--------+ | 1 | 1 | +----+--------+
METHOD 认证方式: o X'00' NO AUTHENTICATION REQUIRED o X'01' GSSAPI o X'02' USERNAME/PASSWORD o X'03' to X'7F' IANA ASSIGNED o X'80' to X'FE' RESERVED FOR PRIVATE METHODS o X'FF' NO ACCEPTABLE METHODS
客户端 -> 代理服务器,代理请求 SOCKS request is formed as follows:
+----+-----+-------+------+----------+----------+ |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT | +----+-----+-------+------+----------+----------+ | 1 | 1 | X'00' | 1 | Variable | 2 | +----+-----+-------+------+----------+----------+
Replies ¶
+----+-----+-------+------+----------+----------+ |VER | REP | RSV | ATYP | BND.ADDR | BND.PORT | +----+-----+-------+------+----------+----------+ | 1 | 1 | X'00' | 1 | Variable | 2 | +----+-----+-------+------+----------+----------+
const ( S5socksVer5 = 5 S5socksCmdConnect = 1 )
const (
AddrMask byte = 0xf
)
Variables ¶
var Debug = ezlog.New(os.Stdout, "", ezlog.BitDefault, ezlog.LogAll)
var ErrNilCipher = errors.New("cipher can not be nil")
Functions ¶
func CheckCipherMethod ¶
func GetPublicIP ¶
func GetPublicIP() string
func IsFileExist ¶
检查常规文件是否存在, 常规文件不是 ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice | ModeCharDevice | ModeIrregular
func PipeThenClose ¶
PipeThenClose 从 src 读取数据送到 dst, 完成后关闭 dst
func Pipeloop ¶
func Pipeloop(write net.PacketConn, writeAddr net.Addr, readClose net.PacketConn, addTraffic func(int))
通过 write 将 readClose 发来的数据 发送给 writeaddr 这个地址
func PrintVersion ¶
func PrintVersion()
func ReadAndHandleUDPReq ¶
func ReadAndHandleUDPReq(c *SecurePacketConn, addTraffic func(int)) (err error)
func SetReadTimeout ¶
func UpdateConfig ¶
func UpdateConfig(old, new *Config)
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
负责提供加密解密功能
type Config ¶
type Config struct { Server interface{} `json:"server"` // ss local 用 ServerPort int `json:"server_port"` LocalPort int `json:"local_port"` // ss local 用 LocalAddress string `json:"local_address"` // ss local 用 Password string `json:"password"` Method string `json:"method"` // 以下选项只用于 ss server PortPassword map[string]string `json:"port_password"` // port:password 如果指定,会忽略上面的 server_port password Timeout int `json:"timeout"` // 以下选项只用于 ss client // 客户端配置中, 服务器顺序很重要, 因此使用数组而不是map ServerPassword [][]string `json:"server_password"` // 多个服务器 [](server, passwd [,method]) }
func ParseConfig ¶
func (*Config) GetServerArray ¶
type Conn ¶
type Conn struct { net.Conn // 内嵌接口,可以使用所有实现了 net.Conn 接口的实例来初始化 *Cipher // 组合,Conn 可以直接使用 Cipher 成员 [ˈsaɪfər] 密码; 暗号; // contains filtered or unexported fields }
func DialWithRawAddr ¶
DialWithRawAddr 为实现本地SOCKS代理的用户使用 rawaddr应该包含socks请求中的部分数据,从ATYP字段开始。
type LeakyBuf ¶
type LeakyBuf struct {
// contains filtered or unexported fields
}
buffer pool 重复使用避免申请内存的开销
func NewLeakyBuf ¶
NewLeakyBuf 创建一个 leaky buffer, 可以包含 n 个 buffer, 每个大小为 bufSize
type NoneCipherStream ¶ added in v1.2.4
type NoneCipherStream struct { }
无加密模式
func (*NoneCipherStream) XORKeyStream ¶ added in v1.2.4
func (none *NoneCipherStream) XORKeyStream(dst, src []byte)
type ProxyConn ¶
type ProxyConn struct { *Conn // contains filtered or unexported fields }
func (*ProxyConn) RemoteAddr ¶
type SecurePacketConn ¶
type SecurePacketConn struct { net.PacketConn *Cipher }
加密的 分组 传输
func NewSecurePacketConn ¶
func NewSecurePacketConn(c net.PacketConn, cipher *Cipher) *SecurePacketConn
func (*SecurePacketConn) LocalAddr ¶
func (c *SecurePacketConn) LocalAddr() net.Addr
func (*SecurePacketConn) SetDeadline ¶
func (c *SecurePacketConn) SetDeadline(t time.Time) error
func (*SecurePacketConn) SetReadDeadline ¶
func (c *SecurePacketConn) SetReadDeadline(t time.Time) error
func (*SecurePacketConn) SetWriteDeadline ¶
func (c *SecurePacketConn) SetWriteDeadline(t time.Time) error