mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
general: add comments
This commit is contained in:
parent
61f7131d53
commit
b2d40b69ff
@ -29,7 +29,7 @@ func (d *direct) Dial(network, addr string) (net.Conn, error) {
|
||||
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) {
|
||||
pc, err := net.ListenPacket(network, "")
|
||||
if err != nil {
|
||||
|
@ -18,16 +18,17 @@ import (
|
||||
|
||||
// netfilter netlink message types
|
||||
// https://github.com/torvalds/linux/blob/9e66317d3c92ddaab330c125dfe9d06eee268aff/include/uapi/linux/netfilter/nfnetlink.h#L56
|
||||
// NFNL_SUBSYS_IPSET
|
||||
const NFNL_SUBSYS_IPSET = 6
|
||||
|
||||
// http://git.netfilter.org/ipset/tree/include/libipset/linux_ip_set.h
|
||||
/* The protocol version */
|
||||
// IPSET_PROTOCOL: The protocol version
|
||||
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
|
||||
|
||||
/* Message types and commands */
|
||||
// Message types and commands
|
||||
const IPSET_CMD_CREATE = 2
|
||||
const IPSET_CMD_FLUSH = 4
|
||||
const IPSET_CMD_ADD = 9
|
||||
|
1
rule.go
1
rule.go
@ -113,6 +113,7 @@ func (rd *RuleDialer) Dial(network, addr string) (net.Conn, error) {
|
||||
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) {
|
||||
return rd.NextDialer(addr).DialUDP(network, addr)
|
||||
}
|
||||
|
@ -563,6 +563,7 @@ func NewSocks5PktConn(c net.PacketConn, writeAddr net.Addr, tgtAddr Addr, tgtHea
|
||||
return pc
|
||||
}
|
||||
|
||||
// ReadFrom overrides the original function from net.PacketConn
|
||||
func (pc *Socks5PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
if !pc.tgtHeader {
|
||||
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
|
||||
}
|
||||
|
||||
// WriteTo overrides the original function from net.PacketConn
|
||||
func (pc *Socks5PktConn) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||
if !pc.tgtHeader {
|
||||
return pc.PacketConn.WriteTo(b, addr)
|
||||
|
6
ss.go
6
ss.go
@ -87,14 +87,14 @@ func (s *SS) ServeTCP(c net.Conn) {
|
||||
|
||||
rc, err := net.ListenPacket("udp", "")
|
||||
if err != nil {
|
||||
logf("UDP remote listen error: %v", err)
|
||||
logf("proxy-ss UDP remote listen error: %v", err)
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
req := make([]byte, udpBufSize)
|
||||
n, err := c.Read(req)
|
||||
if err != nil {
|
||||
logf("error in ioutil.ReadAll: %s\n", err)
|
||||
logf("proxy-ss error in ioutil.ReadAll: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -263,6 +263,7 @@ func NewPktConn(c net.PacketConn, writeAddr net.Addr, tgtAddr Addr, tgtHeader bo
|
||||
return pc
|
||||
}
|
||||
|
||||
// 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)
|
||||
@ -289,6 +290,7 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
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) {
|
||||
if !pc.tgtHeader {
|
||||
return pc.PacketConn.WriteTo(b, addr)
|
||||
|
Loading…
Reference in New Issue
Block a user