From b502b129b7e7daca4422c8691bf7a53461a9f781 Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Sat, 11 Dec 2021 12:19:40 +0800 Subject: [PATCH] proxy: exit glider when it fails to listen (#284) --- proxy/http/server.go | 2 +- proxy/kcp/kcp.go | 2 +- proxy/mixed/mixed.go | 2 +- proxy/pxyproto/server.go | 2 +- proxy/redir/redir_linux.go | 2 +- proxy/smux/server.go | 2 +- proxy/socks5/server.go | 4 ++-- proxy/ss/server.go | 4 ++-- proxy/tcp/tcp.go | 2 +- proxy/tls/tls.go | 2 +- proxy/tproxy/server.go | 2 +- proxy/trojan/server.go | 2 +- proxy/udp/udp.go | 2 +- proxy/unix/server.go | 2 +- proxy/vless/server.go | 2 +- proxy/ws/server.go | 2 +- 16 files changed, 18 insertions(+), 18 deletions(-) diff --git a/proxy/http/server.go b/proxy/http/server.go index f47683d9..2c284895 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -22,7 +22,7 @@ func NewHTTPServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *HTTP) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[http] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[http] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/kcp/kcp.go b/proxy/kcp/kcp.go index 0b844468..d73496ab 100644 --- a/proxy/kcp/kcp.go +++ b/proxy/kcp/kcp.go @@ -163,7 +163,7 @@ func NewKCPServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *KCP) ListenAndServe() { l, err := kcp.ListenWithOptions(s.addr, s.block, s.dataShards, s.parityShards) if err != nil { - log.F("[kcp] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[kcp] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/mixed/mixed.go b/proxy/mixed/mixed.go index ba12fbcd..3ba58f45 100644 --- a/proxy/mixed/mixed.go +++ b/proxy/mixed/mixed.go @@ -61,7 +61,7 @@ func (m *Mixed) ListenAndServe() { l, err := net.Listen("tcp", m.addr) if err != nil { - log.F("[mixed] failed to listen on %s: %v", m.addr, err) + log.Fatalf("[mixed] failed to listen on %s: %v", m.addr, err) return } diff --git a/proxy/pxyproto/server.go b/proxy/pxyproto/server.go index fd2fae23..d36f311b 100644 --- a/proxy/pxyproto/server.go +++ b/proxy/pxyproto/server.go @@ -48,7 +48,7 @@ func NewPxyProtoServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *PxyProtoServer) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[pxyproto] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[pxyproto] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/redir/redir_linux.go b/proxy/redir/redir_linux.go index e5837105..240f4d81 100644 --- a/proxy/redir/redir_linux.go +++ b/proxy/redir/redir_linux.go @@ -55,7 +55,7 @@ func NewRedir6Server(s string, p proxy.Proxy) (proxy.Server, error) { func (s *RedirProxy) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[redir] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[redir] failed to listen on %s: %v", s.addr, err) return } diff --git a/proxy/smux/server.go b/proxy/smux/server.go index 96f7d286..bf08469e 100644 --- a/proxy/smux/server.go +++ b/proxy/smux/server.go @@ -50,7 +50,7 @@ func NewSmuxServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *SmuxServer) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[smux] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[smux] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/socks5/server.go b/proxy/socks5/server.go index 6cb7684e..8c737465 100644 --- a/proxy/socks5/server.go +++ b/proxy/socks5/server.go @@ -31,7 +31,7 @@ func (s *Socks5) ListenAndServe() { func (s *Socks5) ListenAndServeTCP() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[socks5] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[socks5] failed to listen on %s: %v", s.addr, err) return } @@ -99,7 +99,7 @@ func (s *Socks5) Serve(c net.Conn) { func (s *Socks5) ListenAndServeUDP() { lc, err := net.ListenPacket("udp", s.addr) if err != nil { - log.F("[socks5] failed to listen on UDP %s: %v", s.addr, err) + log.Fatalf("[socks5] failed to listen on UDP %s: %v", s.addr, err) return } defer lc.Close() diff --git a/proxy/ss/server.go b/proxy/ss/server.go index 51ff3cf5..f1fb05f5 100644 --- a/proxy/ss/server.go +++ b/proxy/ss/server.go @@ -30,7 +30,7 @@ func (s *SS) ListenAndServe() { func (s *SS) ListenAndServeTCP() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[ss] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[ss] failed to listen on %s: %v", s.addr, err) return } @@ -89,7 +89,7 @@ func (s *SS) Serve(c net.Conn) { func (s *SS) ListenAndServeUDP() { lc, err := net.ListenPacket("udp", s.addr) if err != nil { - log.F("[ss] failed to listen on UDP %s: %v", s.addr, err) + log.Fatalf("[ss] failed to listen on UDP %s: %v", s.addr, err) return } defer lc.Close() diff --git a/proxy/tcp/tcp.go b/proxy/tcp/tcp.go index 51c63488..781bcb12 100644 --- a/proxy/tcp/tcp.go +++ b/proxy/tcp/tcp.go @@ -52,7 +52,7 @@ func NewTCPServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *TCP) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[tcp] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[tcp] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/tls/tls.go b/proxy/tls/tls.go index a9fbfc72..977c2681 100644 --- a/proxy/tls/tls.go +++ b/proxy/tls/tls.go @@ -137,7 +137,7 @@ func NewTLSServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *TLS) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[tls] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[tls] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/tproxy/server.go b/proxy/tproxy/server.go index dde7253c..13a58f2b 100644 --- a/proxy/tproxy/server.go +++ b/proxy/tproxy/server.go @@ -64,7 +64,7 @@ func (s *TProxy) Serve(c net.Conn) { func (s *TProxy) ListenAndServeUDP() { laddr, err := net.ResolveUDPAddr("udp", s.addr) if err != nil { - log.F("[tproxyu] failed to resolve addr %s: %v", s.addr, err) + log.Fatalf("[tproxyu] failed to resolve addr %s: %v", s.addr, err) return } diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index 4b869491..9ad1f1c5 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -56,7 +56,7 @@ func NewTrojanServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *Trojan) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[trojan] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[trojan] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/udp/udp.go b/proxy/udp/udp.go index 788ce19b..f69b1499 100644 --- a/proxy/udp/udp.go +++ b/proxy/udp/udp.go @@ -57,7 +57,7 @@ func NewUDPServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *UDP) ListenAndServe() { c, err := net.ListenPacket("udp", s.addr) if err != nil { - log.F("[udp] failed to listen on UDP %s: %v", s.addr, err) + log.Fatalf("[udp] failed to listen on UDP %s: %v", s.addr, err) return } defer c.Close() diff --git a/proxy/unix/server.go b/proxy/unix/server.go index 574de0bc..fedc385d 100644 --- a/proxy/unix/server.go +++ b/proxy/unix/server.go @@ -47,7 +47,7 @@ func (s *Unix) ListenAndServeTCP() { os.Remove(s.addr) l, err := net.Listen("unix", s.addr) if err != nil { - log.F("[unix] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[unix] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/vless/server.go b/proxy/vless/server.go index 97de8aac..48cb191b 100644 --- a/proxy/vless/server.go +++ b/proxy/vless/server.go @@ -22,7 +22,7 @@ func NewVLessServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *VLess) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[vless] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[vless] failed to listen on %s: %v", s.addr, err) return } defer l.Close() diff --git a/proxy/ws/server.go b/proxy/ws/server.go index 75e09e5d..aa12c6ef 100644 --- a/proxy/ws/server.go +++ b/proxy/ws/server.go @@ -69,7 +69,7 @@ func NewWSSServer(s string, p proxy.Proxy) (proxy.Server, error) { func (s *WS) ListenAndServe() { l, err := net.Listen("tcp", s.addr) if err != nil { - log.F("[ws] failed to listen on %s: %v", s.addr, err) + log.Fatalf("[ws] failed to listen on %s: %v", s.addr, err) return } defer l.Close()