general: add comments

This commit is contained in:
nadoo 2018-01-21 00:31:10 +08:00
parent 61f7131d53
commit b2d40b69ff
5 changed files with 12 additions and 6 deletions

View File

@ -29,7 +29,7 @@ func (d *direct) Dial(network, addr string) (net.Conn, error) {
return c, err return c, err
} }
// DialUDP connects to the given address via the proxy. // DialUDP connects to the given address via the proxy
func (d *direct) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) { func (d *direct) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
pc, err := net.ListenPacket(network, "") pc, err := net.ListenPacket(network, "")
if err != nil { if err != nil {

View File

@ -18,16 +18,17 @@ import (
// netfilter netlink message types // netfilter netlink message types
// https://github.com/torvalds/linux/blob/9e66317d3c92ddaab330c125dfe9d06eee268aff/include/uapi/linux/netfilter/nfnetlink.h#L56 // https://github.com/torvalds/linux/blob/9e66317d3c92ddaab330c125dfe9d06eee268aff/include/uapi/linux/netfilter/nfnetlink.h#L56
// NFNL_SUBSYS_IPSET
const NFNL_SUBSYS_IPSET = 6 const NFNL_SUBSYS_IPSET = 6
// http://git.netfilter.org/ipset/tree/include/libipset/linux_ip_set.h // http://git.netfilter.org/ipset/tree/include/libipset/linux_ip_set.h
/* The protocol version */ // IPSET_PROTOCOL: The protocol version
const IPSET_PROTOCOL = 6 const IPSET_PROTOCOL = 6
/* The max length of strings including NUL: set and type identifiers */ // IPSET_MAXNAMELEN: The max length of strings including NUL: set and type identifiers
const IPSET_MAXNAMELEN = 32 const IPSET_MAXNAMELEN = 32
/* Message types and commands */ // Message types and commands
const IPSET_CMD_CREATE = 2 const IPSET_CMD_CREATE = 2
const IPSET_CMD_FLUSH = 4 const IPSET_CMD_FLUSH = 4
const IPSET_CMD_ADD = 9 const IPSET_CMD_ADD = 9

View File

@ -113,6 +113,7 @@ func (rd *RuleDialer) Dial(network, addr string) (net.Conn, error) {
return rd.NextDialer(addr).Dial(network, addr) return rd.NextDialer(addr).Dial(network, addr)
} }
// DialUDP connects to the given address via the proxy
func (rd *RuleDialer) DialUDP(network, addr string) (pc net.PacketConn, writeTo net.Addr, err error) { func (rd *RuleDialer) DialUDP(network, addr string) (pc net.PacketConn, writeTo net.Addr, err error) {
return rd.NextDialer(addr).DialUDP(network, addr) return rd.NextDialer(addr).DialUDP(network, addr)
} }

View File

@ -563,6 +563,7 @@ func NewSocks5PktConn(c net.PacketConn, writeAddr net.Addr, tgtAddr Addr, tgtHea
return pc return pc
} }
// ReadFrom overrides the original function from net.PacketConn
func (pc *Socks5PktConn) ReadFrom(b []byte) (int, net.Addr, error) { func (pc *Socks5PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
if !pc.tgtHeader { if !pc.tgtHeader {
return pc.PacketConn.ReadFrom(b) return pc.PacketConn.ReadFrom(b)
@ -595,6 +596,7 @@ func (pc *Socks5PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
return n - len(tgtAddr), raddr, err return n - len(tgtAddr), raddr, err
} }
// WriteTo overrides the original function from net.PacketConn
func (pc *Socks5PktConn) WriteTo(b []byte, addr net.Addr) (int, error) { func (pc *Socks5PktConn) WriteTo(b []byte, addr net.Addr) (int, error) {
if !pc.tgtHeader { if !pc.tgtHeader {
return pc.PacketConn.WriteTo(b, addr) return pc.PacketConn.WriteTo(b, addr)

6
ss.go
View File

@ -87,14 +87,14 @@ func (s *SS) ServeTCP(c net.Conn) {
rc, err := net.ListenPacket("udp", "") rc, err := net.ListenPacket("udp", "")
if err != nil { if err != nil {
logf("UDP remote listen error: %v", err) logf("proxy-ss UDP remote listen error: %v", err)
} }
defer rc.Close() defer rc.Close()
req := make([]byte, udpBufSize) req := make([]byte, udpBufSize)
n, err := c.Read(req) n, err := c.Read(req)
if err != nil { if err != nil {
logf("error in ioutil.ReadAll: %s\n", err) logf("proxy-ss error in ioutil.ReadAll: %s\n", err)
return return
} }
@ -263,6 +263,7 @@ func NewPktConn(c net.PacketConn, writeAddr net.Addr, tgtAddr Addr, tgtHeader bo
return pc return pc
} }
// ReadFrom overrides the original function from net.PacketConn
func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) { func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
if !pc.tgtHeader { if !pc.tgtHeader {
return pc.PacketConn.ReadFrom(b) return pc.PacketConn.ReadFrom(b)
@ -289,6 +290,7 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
return n - len(tgtAddr), raddr, err return n - len(tgtAddr), raddr, err
} }
// WriteTo overrides the original function from net.PacketConn
func (pc *PktConn) WriteTo(b []byte, addr net.Addr) (int, error) { func (pc *PktConn) WriteTo(b []byte, addr net.Addr) (int, error) {
if !pc.tgtHeader { if !pc.tgtHeader {
return pc.PacketConn.WriteTo(b, addr) return pc.PacketConn.WriteTo(b, addr)