general: optimize domain parts operations

This commit is contained in:
nadoo committed 2020-08-16 12:00:46 +08:00
1 parent 3a6fd63bc0
commit a118ec5837
14 files changed
+51 -65

No files matched your search

+3 -3
View File
@@ -21,7 +21,7 @@ type PktConn struct {
ctrlConn net.Conn // tcp control conn
}
// NewPktConn returns a PktConn
// NewPktConn returns a PktConn.
func NewPktConn(c net.PacketConn, writeAddr net.Addr, tgtAddr socks.Addr, tgtHeader bool, ctrlConn net.Conn) *PktConn {
pc := &PktConn{
PacketConn: c,
@@ -48,7 +48,7 @@ func NewPktConn(c net.PacketConn, writeAddr net.Addr, tgtAddr socks.Addr, tgtHea
return pc
}
// ReadFrom overrides the original function from net.PacketConn
// ReadFrom overrides the original function from net.PacketConn.
func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
if !pc.tgtHeader {
return pc.PacketConn.ReadFrom(b)
@@ -90,7 +90,7 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
return n - len(tgtAddr) - 3, raddr, err
}
// WriteTo overrides the original function from net.PacketConn
// WriteTo overrides the original function from net.PacketConn.
func (pc *PktConn) WriteTo(b []byte, addr net.Addr) (int, error) {
if !pc.tgtHeader {
return pc.PacketConn.WriteTo(b, addr)
+1 -1
View File
@@ -42,7 +42,7 @@ func init() {
proxy.RegisterServer("socks5", NewSocks5Server)
}
// NewSocks5 returns a Proxy that makes SOCKS v5 connections to the given address
// NewSocks5 returns a Proxy that makes SOCKS v5 connections to the given address.
// with an optional username and password. (RFC 1928)
func NewSocks5(s string, d proxy.Dialer, p proxy.Proxy) (*Socks5, error) {
u, err := url.Parse(s)
+4 -4
View File
@@ -5,7 +5,7 @@ import (
"strconv"
)
// Atyp is vmess addr type
// Atyp is vmess addr type.
type Atyp byte
// Atyp
@@ -16,13 +16,13 @@ const (
AtypIP6 Atyp = 3
)
// Addr is vmess addr
// Addr is vmess addr.
type Addr []byte
// Port is vmess addr port
// Port is vmess addr port.
type Port uint16
// ParseAddr parses the address in string s
// ParseAddr parses the address in string s.
func ParseAddr(s string) (Atyp, Addr, Port, error) {
var atyp Atyp
var addr Addr
+2 -2
View File
@@ -16,7 +16,7 @@ type aeadWriter struct {
iv []byte
}
// AEADWriter returns a aead writer
// AEADWriter returns a aead writer.
func AEADWriter(w io.Writer, aead cipher.AEAD, iv []byte) io.Writer {
return &aeadWriter{
Writer: w,
@@ -79,7 +79,7 @@ type aeadReader struct {
iv []byte
}
// AEADReader returns a aead reader
// AEADReader returns a aead reader.
func AEADReader(r io.Reader, aead cipher.AEAD, iv []byte) io.Reader {
return &aeadReader{
Reader: r,
+2 -2
View File
@@ -16,7 +16,7 @@ type chunkedWriter struct {
io.Writer
}
// ChunkedWriter returns a chunked writer
// ChunkedWriter returns a chunked writer.
func ChunkedWriter(w io.Writer) io.Writer {
return &chunkedWriter{Writer: w}
}
@@ -52,7 +52,7 @@ type chunkedReader struct {
left int
}
// ChunkedReader returns a chunked reader
// ChunkedReader returns a chunked reader.
func ChunkedReader(r io.Reader) io.Reader {
return &chunkedReader{Reader: r}
}
+3 -3
View File
@@ -39,7 +39,7 @@ const (
CmdUDP byte = 2
)
// Client is a vmess client
// Client is a vmess client.
type Client struct {
users []*User
count int
@@ -47,7 +47,7 @@ type Client struct {
security byte
}
// Conn is a connection to vmess server
// Conn is a connection to vmess server.
type Conn struct {
user *User
opt byte
@@ -142,7 +142,7 @@ func (c *Client) NewConn(rc net.Conn, target string) (*Conn, error) {
return conn, nil
}
// Auth send auth info: HMAC("md5", UUID, UTC)
// Auth send auth info: HMAC("md5", UUID, UTC).
func (c *Conn) Auth() error {
ts := pool.GetBuffer(8)
defer pool.PutBuffer(ts)
+5 -5
View File
@@ -12,13 +12,13 @@ import (
"github.com/nadoo/glider/common/pool"
)
// User of vmess client
// User of vmess client.
type User struct {
UUID [16]byte
CmdKey [16]byte
}
// NewUser .
// NewUser returns a new user.
func NewUser(uuid [16]byte) *User {
u := &User{UUID: uuid}
copy(u.CmdKey[:], GetKey(uuid))
@@ -38,7 +38,7 @@ func nextID(oldID [16]byte) (newID [16]byte) {
}
}
// GenAlterIDUsers generates users according to primary user's id and alterID
// GenAlterIDUsers generates users according to primary user's id and alterID.
func (u *User) GenAlterIDUsers(alterID int) []*User {
users := make([]*User, alterID)
preID := u.UUID
@@ -63,7 +63,7 @@ func StrToUUID(s string) (uuid [16]byte, err error) {
return
}
// GetKey returns the key of AES-128-CFB encrypter
// GetKey returns the key of AES-128-CFB encrypter.
// Key:MD5(UUID + []byte('c48619fe-8f02-49e0-b9e9-edf763e17e21'))
func GetKey(uuid [16]byte) []byte {
md5hash := md5.New()
@@ -72,7 +72,7 @@ func GetKey(uuid [16]byte) []byte {
return md5hash.Sum(nil)
}
// TimestampHash returns the iv of AES-128-CFB encrypter
// TimestampHash returns the iv of AES-128-CFB encrypter.
// IV:MD5(X + X + X + X),X = []byte(timestamp.now) (8 bytes, Big Endian)
func TimestampHash(t time.Time) []byte {
ts := pool.GetBuffer(8)