From f231a63e9322198deb8e4e65afd3572344f62d31 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Sun, 13 Jun 2021 23:05:22 +0800 Subject: [PATCH] Chore: Listener should not expose original net.Listener --- listener/http/server.go | 12 ++++++------ listener/mixed/mixed.go | 12 ++++++------ listener/redir/tcp.go | 8 ++++---- listener/socks/tcp.go | 8 ++++---- listener/socks/udp.go | 8 ++++---- listener/tproxy/tproxy.go | 10 +++++----- listener/tproxy/udp.go | 8 ++++---- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/listener/http/server.go b/listener/http/server.go index e52b84a9..a77e01da 100644 --- a/listener/http/server.go +++ b/listener/http/server.go @@ -17,10 +17,10 @@ import ( ) type Listener struct { - net.Listener - address string - closed bool - cache *cache.Cache + listener net.Listener + address string + closed bool + cache *cache.Cache } func New(addr string, in chan<- C.ConnContext) (*Listener, error) { @@ -31,7 +31,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) { hl := &Listener{l, addr, false, cache.New(30 * time.Second)} go func() { for { - c, err := hl.Accept() + c, err := hl.listener.Accept() if err != nil { if hl.closed { break @@ -47,7 +47,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func (l *Listener) Close() { l.closed = true - l.Listener.Close() + l.listener.Close() } func (l *Listener) Address() string { diff --git a/listener/mixed/mixed.go b/listener/mixed/mixed.go index b930d068..3c4b49a8 100644 --- a/listener/mixed/mixed.go +++ b/listener/mixed/mixed.go @@ -12,10 +12,10 @@ import ( ) type Listener struct { - net.Listener - address string - closed bool - cache *cache.Cache + listener net.Listener + address string + closed bool + cache *cache.Cache } func New(addr string, in chan<- C.ConnContext) (*Listener, error) { @@ -27,7 +27,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) { ml := &Listener{l, addr, false, cache.New(30 * time.Second)} go func() { for { - c, err := ml.Accept() + c, err := ml.listener.Accept() if err != nil { if ml.closed { break @@ -43,7 +43,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func (l *Listener) Close() { l.closed = true - l.Listener.Close() + l.listener.Close() } func (l *Listener) Address() string { diff --git a/listener/redir/tcp.go b/listener/redir/tcp.go index a54bfff8..37268840 100644 --- a/listener/redir/tcp.go +++ b/listener/redir/tcp.go @@ -8,9 +8,9 @@ import ( ) type Listener struct { - net.Listener - address string - closed bool + listener net.Listener + address string + closed bool } func New(addr string, in chan<- C.ConnContext) (*Listener, error) { @@ -38,7 +38,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func (l *Listener) Close() { l.closed = true - l.Listener.Close() + l.listener.Close() } func (l *Listener) Address() string { diff --git a/listener/socks/tcp.go b/listener/socks/tcp.go index eca36f0f..8e12ac71 100644 --- a/listener/socks/tcp.go +++ b/listener/socks/tcp.go @@ -12,9 +12,9 @@ import ( ) type Listener struct { - net.Listener - address string - closed bool + listener net.Listener + address string + closed bool } func New(addr string, in chan<- C.ConnContext) (*Listener, error) { @@ -42,7 +42,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func (l *Listener) Close() { l.closed = true - l.Listener.Close() + l.listener.Close() } func (l *Listener) Address() string { diff --git a/listener/socks/udp.go b/listener/socks/udp.go index 7ddeed20..b98ae897 100644 --- a/listener/socks/udp.go +++ b/listener/socks/udp.go @@ -12,9 +12,9 @@ import ( ) type UDPListener struct { - net.PacketConn - address string - closed bool + packetConn net.PacketConn + address string + closed bool } func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error) { @@ -48,7 +48,7 @@ func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error) func (l *UDPListener) Close() error { l.closed = true - return l.PacketConn.Close() + return l.packetConn.Close() } func (l *UDPListener) Address() string { diff --git a/listener/tproxy/tproxy.go b/listener/tproxy/tproxy.go index a787b359..142336fe 100644 --- a/listener/tproxy/tproxy.go +++ b/listener/tproxy/tproxy.go @@ -9,9 +9,9 @@ import ( ) type Listener struct { - net.Listener - address string - closed bool + listener net.Listener + address string + closed bool } func New(addr string, in chan<- C.ConnContext) (*Listener, error) { @@ -32,7 +32,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) { } rl := &Listener{ - Listener: l, + listener: l, address: addr, } @@ -54,7 +54,7 @@ func New(addr string, in chan<- C.ConnContext) (*Listener, error) { func (l *Listener) Close() { l.closed = true - l.Listener.Close() + l.listener.Close() } func (l *Listener) Address() string { diff --git a/listener/tproxy/udp.go b/listener/tproxy/udp.go index 88125016..20c2e083 100644 --- a/listener/tproxy/udp.go +++ b/listener/tproxy/udp.go @@ -10,9 +10,9 @@ import ( ) type UDPListener struct { - net.PacketConn - address string - closed bool + packetConn net.PacketConn + address string + closed bool } func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error) { @@ -61,7 +61,7 @@ func NewUDP(addr string, in chan<- *inbound.PacketAdapter) (*UDPListener, error) func (l *UDPListener) Close() error { l.closed = true - return l.PacketConn.Close() + return l.packetConn.Close() } func (l *UDPListener) Address() string {