From 555db9d272565b869be7d825b07f81e93827bd7f Mon Sep 17 00:00:00 2001 From: fatedier Date: Mon, 29 May 2023 14:10:34 +0800 Subject: [PATCH] format import package name (#3455) --- client/admin.go | 6 ++--- client/proxy/proxy.go | 10 ++++---- client/proxy/sudp.go | 12 +++++----- client/proxy/udp.go | 12 +++++----- client/proxy/xtcp.go | 6 ++--- client/service.go | 8 +++---- client/visitor/stcp.go | 8 +++---- client/visitor/sudp.go | 10 ++++---- client/visitor/xtcp.go | 14 +++++------ pkg/plugin/client/http2https.go | 4 ++-- pkg/plugin/client/http_proxy.go | 16 ++++++------- pkg/plugin/client/https2http.go | 4 ++-- pkg/plugin/client/https2https.go | 4 ++-- pkg/plugin/client/socks5.go | 4 ++-- pkg/plugin/client/static_file.go | 8 +++---- pkg/plugin/client/unix_domain_socket.go | 4 ++-- pkg/util/net/listener.go | 31 +++++++++++++++++-------- pkg/util/net/tls.go | 4 ++-- pkg/util/tcpmux/httpconnect.go | 4 ++-- pkg/util/vhost/http.go | 4 ++-- pkg/util/vhost/https.go | 4 ++-- pkg/util/vhost/vhost.go | 4 ++-- server/control.go | 6 ++--- server/dashboard.go | 6 ++--- server/proxy/http.go | 14 +++++------ server/proxy/proxy.go | 16 ++++++------- server/proxy/udp.go | 12 +++++----- server/service.go | 20 ++++++++-------- server/visitor/visitor.go | 18 +++++++------- 29 files changed, 142 insertions(+), 131 deletions(-) diff --git a/client/admin.go b/client/admin.go index 949ab8a..37959e7 100644 --- a/client/admin.go +++ b/client/admin.go @@ -23,7 +23,7 @@ import ( "github.com/gorilla/mux" "github.com/fatedier/frp/assets" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) var ( @@ -48,7 +48,7 @@ func (svr *Service) RunAdminServer(address string) (err error) { subRouter := router.NewRoute().Subrouter() user, passwd := svr.cfg.AdminUser, svr.cfg.AdminPwd - subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd).SetAuthFailDelay(200 * time.Millisecond).Middleware) + subRouter.Use(utilnet.NewHTTPAuthMiddleware(user, passwd).SetAuthFailDelay(200 * time.Millisecond).Middleware) // api, see admin_api.go subRouter.HandleFunc("/api/reload", svr.apiReload).Methods("GET") @@ -58,7 +58,7 @@ func (svr *Service) RunAdminServer(address string) (err error) { // view subRouter.Handle("/favicon.ico", http.FileServer(assets.FileSystem)).Methods("GET") - subRouter.PathPrefix("/static/").Handler(frpNet.MakeHTTPGzipHandler(http.StripPrefix("/static/", http.FileServer(assets.FileSystem)))).Methods("GET") + subRouter.PathPrefix("/static/").Handler(utilnet.MakeHTTPGzipHandler(http.StripPrefix("/static/", http.FileServer(assets.FileSystem)))).Methods("GET") subRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/static/", http.StatusMovedPermanently) }) diff --git a/client/proxy/proxy.go b/client/proxy/proxy.go index 61e6763..e961d60 100644 --- a/client/proxy/proxy.go +++ b/client/proxy/proxy.go @@ -24,7 +24,7 @@ import ( "sync" "time" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" libdial "github.com/fatedier/golib/net/dial" pp "github.com/pires/go-proxyproto" "golang.org/x/time/rate" @@ -279,7 +279,7 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf ) remote = workConn if limiter != nil { - remote = frpIo.WrapReadWriteCloser(limit.NewReader(workConn, limiter), limit.NewWriter(workConn, limiter), func() error { + remote = libio.WrapReadWriteCloser(limit.NewReader(workConn, limiter), limit.NewWriter(workConn, limiter), func() error { return workConn.Close() }) } @@ -287,7 +287,7 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf xl.Trace("handle tcp work connection, use_encryption: %t, use_compression: %t", baseInfo.UseEncryption, baseInfo.UseCompression) if baseInfo.UseEncryption { - remote, err = frpIo.WithEncryption(remote, encKey) + remote, err = libio.WithEncryption(remote, encKey) if err != nil { workConn.Close() xl.Error("create encryption stream error: %v", err) @@ -295,7 +295,7 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf } } if baseInfo.UseCompression { - remote = frpIo.WithCompression(remote) + remote = libio.WithCompression(remote) } // check if we need to send proxy protocol info @@ -360,7 +360,7 @@ func HandleTCPWorkConnection(ctx context.Context, localInfo *config.LocalSvrConf } } - _, _, errs := frpIo.Join(localConn, remote) + _, _, errs := libio.Join(localConn, remote) xl.Debug("join connections closed") if len(errs) > 0 { xl.Trace("join connections errors: %v", errs) diff --git a/client/proxy/sudp.go b/client/proxy/sudp.go index f540590..ff88bf7 100644 --- a/client/proxy/sudp.go +++ b/client/proxy/sudp.go @@ -22,13 +22,13 @@ import ( "time" "github.com/fatedier/golib/errors" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" "github.com/fatedier/frp/pkg/config" "github.com/fatedier/frp/pkg/msg" "github.com/fatedier/frp/pkg/proto/udp" "github.com/fatedier/frp/pkg/util/limit" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) type SUDPProxy struct { @@ -67,12 +67,12 @@ func (pxy *SUDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) { var rwc io.ReadWriteCloser = conn var err error if pxy.limiter != nil { - rwc = frpIo.WrapReadWriteCloser(limit.NewReader(conn, pxy.limiter), limit.NewWriter(conn, pxy.limiter), func() error { + rwc = libio.WrapReadWriteCloser(limit.NewReader(conn, pxy.limiter), limit.NewWriter(conn, pxy.limiter), func() error { return conn.Close() }) } if pxy.cfg.UseEncryption { - rwc, err = frpIo.WithEncryption(rwc, []byte(pxy.clientCfg.Token)) + rwc, err = libio.WithEncryption(rwc, []byte(pxy.clientCfg.Token)) if err != nil { conn.Close() xl.Error("create encryption stream error: %v", err) @@ -80,9 +80,9 @@ func (pxy *SUDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) { } } if pxy.cfg.UseCompression { - rwc = frpIo.WithCompression(rwc) + rwc = libio.WithCompression(rwc) } - conn = frpNet.WrapReadWriteCloserToConn(rwc, conn) + conn = utilnet.WrapReadWriteCloserToConn(rwc, conn) workConn := conn readCh := make(chan *msg.UDPPacket, 1024) diff --git a/client/proxy/udp.go b/client/proxy/udp.go index 8a59936..0dc1179 100644 --- a/client/proxy/udp.go +++ b/client/proxy/udp.go @@ -21,13 +21,13 @@ import ( "time" "github.com/fatedier/golib/errors" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" "github.com/fatedier/frp/pkg/config" "github.com/fatedier/frp/pkg/msg" "github.com/fatedier/frp/pkg/proto/udp" "github.com/fatedier/frp/pkg/util/limit" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) // UDP @@ -79,12 +79,12 @@ func (pxy *UDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) { var rwc io.ReadWriteCloser = conn var err error if pxy.limiter != nil { - rwc = frpIo.WrapReadWriteCloser(limit.NewReader(conn, pxy.limiter), limit.NewWriter(conn, pxy.limiter), func() error { + rwc = libio.WrapReadWriteCloser(limit.NewReader(conn, pxy.limiter), limit.NewWriter(conn, pxy.limiter), func() error { return conn.Close() }) } if pxy.cfg.UseEncryption { - rwc, err = frpIo.WithEncryption(rwc, []byte(pxy.clientCfg.Token)) + rwc, err = libio.WithEncryption(rwc, []byte(pxy.clientCfg.Token)) if err != nil { conn.Close() xl.Error("create encryption stream error: %v", err) @@ -92,9 +92,9 @@ func (pxy *UDPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) { } } if pxy.cfg.UseCompression { - rwc = frpIo.WithCompression(rwc) + rwc = libio.WithCompression(rwc) } - conn = frpNet.WrapReadWriteCloserToConn(rwc, conn) + conn = utilnet.WrapReadWriteCloserToConn(rwc, conn) pxy.mu.Lock() pxy.workConn = conn diff --git a/client/proxy/xtcp.go b/client/proxy/xtcp.go index 9535a31..64ce507 100644 --- a/client/proxy/xtcp.go +++ b/client/proxy/xtcp.go @@ -27,7 +27,7 @@ import ( "github.com/fatedier/frp/pkg/nathole" plugin "github.com/fatedier/frp/pkg/plugin/client" "github.com/fatedier/frp/pkg/transport" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) // XTCP @@ -132,7 +132,7 @@ func (pxy *XTCPProxy) listenByKCP(listenConn *net.UDPConn, raddr *net.UDPAddr, s } defer lConn.Close() - remote, err := frpNet.NewKCPConnFromUDP(lConn, true, raddr.String()) + remote, err := utilnet.NewKCPConnFromUDP(lConn, true, raddr.String()) if err != nil { xl.Warn("create kcp connection from udp connection error: %v", err) return @@ -195,6 +195,6 @@ func (pxy *XTCPProxy) listenByQUIC(listenConn *net.UDPConn, _ *net.UDPAddr, star return } go HandleTCPWorkConnection(pxy.ctx, &pxy.cfg.LocalSvrConf, pxy.proxyPlugin, pxy.cfg.GetBaseInfo(), pxy.limiter, - frpNet.QuicStreamToNetConn(stream, c), []byte(pxy.cfg.Sk), startWorkConnMsg) + utilnet.QuicStreamToNetConn(stream, c), []byte(pxy.cfg.Sk), startWorkConnMsg) } } diff --git a/client/service.go b/client/service.go index 83439c7..e6ff6d9 100644 --- a/client/service.go +++ b/client/service.go @@ -39,7 +39,7 @@ import ( "github.com/fatedier/frp/pkg/msg" "github.com/fatedier/frp/pkg/transport" "github.com/fatedier/frp/pkg/util/log" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/util" "github.com/fatedier/frp/pkg/util/version" "github.com/fatedier/frp/pkg/util/xlog" @@ -409,7 +409,7 @@ func (cm *ConnectionManager) Connect() (net.Conn, error) { if err != nil { return nil, err } - return frpNet.QuicStreamToNetConn(stream, cm.quicConn), nil + return utilnet.QuicStreamToNetConn(stream, cm.quicConn), nil } else if cm.muxSession != nil { stream, err := cm.muxSession.OpenStream() if err != nil { @@ -451,7 +451,7 @@ func (cm *ConnectionManager) realConnect() (net.Conn, error) { protocol := cm.cfg.Protocol if protocol == "websocket" { protocol = "tcp" - dialOptions = append(dialOptions, libdial.WithAfterHook(libdial.AfterHook{Hook: frpNet.DialHookWebsocket()})) + dialOptions = append(dialOptions, libdial.WithAfterHook(libdial.AfterHook{Hook: utilnet.DialHookWebsocket()})) } if cm.cfg.ConnectServerLocalIP != "" { dialOptions = append(dialOptions, libdial.WithLocalAddr(cm.cfg.ConnectServerLocalIP)) @@ -464,7 +464,7 @@ func (cm *ConnectionManager) realConnect() (net.Conn, error) { libdial.WithProxyAuth(auth), libdial.WithTLSConfig(tlsConfig), libdial.WithAfterHook(libdial.AfterHook{ - Hook: frpNet.DialHookCustomTLSHeadByte(tlsConfig != nil, cm.cfg.DisableCustomTLSFirstByte), + Hook: utilnet.DialHookCustomTLSHeadByte(tlsConfig != nil, cm.cfg.DisableCustomTLSFirstByte), }), ) conn, err := libdial.Dial( diff --git a/client/visitor/stcp.go b/client/visitor/stcp.go index 2a7cf64..672aadf 100644 --- a/client/visitor/stcp.go +++ b/client/visitor/stcp.go @@ -20,7 +20,7 @@ import ( "strconv" "time" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" "github.com/fatedier/frp/pkg/config" "github.com/fatedier/frp/pkg/msg" @@ -103,7 +103,7 @@ func (sv *STCPVisitor) handleConn(userConn net.Conn) { var remote io.ReadWriteCloser remote = visitorConn if sv.cfg.UseEncryption { - remote, err = frpIo.WithEncryption(remote, []byte(sv.cfg.Sk)) + remote, err = libio.WithEncryption(remote, []byte(sv.cfg.Sk)) if err != nil { xl.Error("create encryption stream error: %v", err) return @@ -111,8 +111,8 @@ func (sv *STCPVisitor) handleConn(userConn net.Conn) { } if sv.cfg.UseCompression { - remote = frpIo.WithCompression(remote) + remote = libio.WithCompression(remote) } - frpIo.Join(userConn, remote) + libio.Join(userConn, remote) } diff --git a/client/visitor/sudp.go b/client/visitor/sudp.go index cd6f2af..e93d877 100644 --- a/client/visitor/sudp.go +++ b/client/visitor/sudp.go @@ -23,12 +23,12 @@ import ( "time" "github.com/fatedier/golib/errors" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" "github.com/fatedier/frp/pkg/config" "github.com/fatedier/frp/pkg/msg" "github.com/fatedier/frp/pkg/proto/udp" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/util" "github.com/fatedier/frp/pkg/util/xlog" ) @@ -232,16 +232,16 @@ func (sv *SUDPVisitor) getNewVisitorConn() (net.Conn, error) { var remote io.ReadWriteCloser remote = visitorConn if sv.cfg.UseEncryption { - remote, err = frpIo.WithEncryption(remote, []byte(sv.cfg.Sk)) + remote, err = libio.WithEncryption(remote, []byte(sv.cfg.Sk)) if err != nil { xl.Error("create encryption stream error: %v", err) return nil, err } } if sv.cfg.UseCompression { - remote = frpIo.WithCompression(remote) + remote = libio.WithCompression(remote) } - return frpNet.WrapReadWriteCloserToConn(remote, visitorConn), nil + return utilnet.WrapReadWriteCloserToConn(remote, visitorConn), nil } func (sv *SUDPVisitor) Close() { diff --git a/client/visitor/xtcp.go b/client/visitor/xtcp.go index 6ace768..7cbb90e 100644 --- a/client/visitor/xtcp.go +++ b/client/visitor/xtcp.go @@ -24,7 +24,7 @@ import ( "sync" "time" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" fmux "github.com/hashicorp/yamux" quic "github.com/quic-go/quic-go" "golang.org/x/time/rate" @@ -33,7 +33,7 @@ import ( "github.com/fatedier/frp/pkg/msg" "github.com/fatedier/frp/pkg/nathole" "github.com/fatedier/frp/pkg/transport" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/util" "github.com/fatedier/frp/pkg/util/xlog" ) @@ -153,17 +153,17 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) { var muxConnRWCloser io.ReadWriteCloser = tunnelConn if sv.cfg.UseEncryption { - muxConnRWCloser, err = frpIo.WithEncryption(muxConnRWCloser, []byte(sv.cfg.Sk)) + muxConnRWCloser, err = libio.WithEncryption(muxConnRWCloser, []byte(sv.cfg.Sk)) if err != nil { xl.Error("create encryption stream error: %v", err) return } } if sv.cfg.UseCompression { - muxConnRWCloser = frpIo.WithCompression(muxConnRWCloser) + muxConnRWCloser = libio.WithCompression(muxConnRWCloser) } - _, _, errs := frpIo.Join(userConn, muxConnRWCloser) + _, _, errs := libio.Join(userConn, muxConnRWCloser) xl.Debug("join connections closed") if len(errs) > 0 { xl.Trace("join connections errors: %v", errs) @@ -302,7 +302,7 @@ func (ks *KCPTunnelSession) Init(listenConn *net.UDPConn, raddr *net.UDPAddr) er if err != nil { return fmt.Errorf("dial udp error: %v", err) } - remote, err := frpNet.NewKCPConnFromUDP(lConn, true, raddr.String()) + remote, err := utilnet.NewKCPConnFromUDP(lConn, true, raddr.String()) if err != nil { return fmt.Errorf("create kcp connection from udp connection error: %v", err) } @@ -393,7 +393,7 @@ func (qs *QUICTunnelSession) OpenConn(ctx context.Context) (net.Conn, error) { if err != nil { return nil, err } - return frpNet.QuicStreamToNetConn(stream, session), nil + return utilnet.QuicStreamToNetConn(stream, session), nil } func (qs *QUICTunnelSession) Close() { diff --git a/pkg/plugin/client/http2https.go b/pkg/plugin/client/http2https.go index f50a6c4..f84b0a0 100644 --- a/pkg/plugin/client/http2https.go +++ b/pkg/plugin/client/http2https.go @@ -23,7 +23,7 @@ import ( "net/http/httputil" "strings" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) const PluginHTTP2HTTPS = "http2https" @@ -98,7 +98,7 @@ func NewHTTP2HTTPSPlugin(params map[string]string) (Plugin, error) { } func (p *HTTP2HTTPSPlugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBufToLocal []byte) { - wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn) + wrapConn := utilnet.WrapReadWriteCloserToConn(conn, realConn) _ = p.l.PutConn(wrapConn) } diff --git a/pkg/plugin/client/http_proxy.go b/pkg/plugin/client/http_proxy.go index 8654204..51a191b 100644 --- a/pkg/plugin/client/http_proxy.go +++ b/pkg/plugin/client/http_proxy.go @@ -23,10 +23,10 @@ import ( "strings" "time" - frpIo "github.com/fatedier/golib/io" - gnet "github.com/fatedier/golib/net" + libio "github.com/fatedier/golib/io" + libnet "github.com/fatedier/golib/net" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/util" ) @@ -69,9 +69,9 @@ func (hp *HTTPProxy) Name() string { } func (hp *HTTPProxy) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBufToLocal []byte) { - wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn) + wrapConn := utilnet.WrapReadWriteCloserToConn(conn, realConn) - sc, rd := gnet.NewSharedConn(wrapConn) + sc, rd := libnet.NewSharedConn(wrapConn) firstBytes := make([]byte, 7) _, err := rd.Read(firstBytes) if err != nil { @@ -86,7 +86,7 @@ func (hp *HTTPProxy) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBuf wrapConn.Close() return } - hp.handleConnectReq(request, frpIo.WrapReadWriteCloser(bufRd, wrapConn, wrapConn.Close)) + hp.handleConnectReq(request, libio.WrapReadWriteCloser(bufRd, wrapConn, wrapConn.Close)) return } @@ -158,7 +158,7 @@ func (hp *HTTPProxy) ConnectHandler(rw http.ResponseWriter, req *http.Request) { } _, _ = client.Write([]byte("HTTP/1.1 200 OK\r\n\r\n")) - go frpIo.Join(remote, client) + go libio.Join(remote, client) } func (hp *HTTPProxy) Auth(req *http.Request) bool { @@ -213,7 +213,7 @@ func (hp *HTTPProxy) handleConnectReq(req *http.Request, rwc io.ReadWriteCloser) } _, _ = rwc.Write([]byte("HTTP/1.1 200 OK\r\n\r\n")) - frpIo.Join(remote, rwc) + libio.Join(remote, rwc) } func copyHeaders(dst, src http.Header) { diff --git a/pkg/plugin/client/https2http.go b/pkg/plugin/client/https2http.go index 18138dc..55edf83 100644 --- a/pkg/plugin/client/https2http.go +++ b/pkg/plugin/client/https2http.go @@ -24,7 +24,7 @@ import ( "strings" "github.com/fatedier/frp/pkg/transport" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) const PluginHTTPS2HTTP = "https2http" @@ -123,7 +123,7 @@ func (p *HTTPS2HTTPPlugin) genTLSConfig() (*tls.Config, error) { } func (p *HTTPS2HTTPPlugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBufToLocal []byte) { - wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn) + wrapConn := utilnet.WrapReadWriteCloserToConn(conn, realConn) _ = p.l.PutConn(wrapConn) } diff --git a/pkg/plugin/client/https2https.go b/pkg/plugin/client/https2https.go index 596bdc1..c236c4c 100644 --- a/pkg/plugin/client/https2https.go +++ b/pkg/plugin/client/https2https.go @@ -24,7 +24,7 @@ import ( "strings" "github.com/fatedier/frp/pkg/transport" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) const PluginHTTPS2HTTPS = "https2https" @@ -128,7 +128,7 @@ func (p *HTTPS2HTTPSPlugin) genTLSConfig() (*tls.Config, error) { } func (p *HTTPS2HTTPSPlugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBufToLocal []byte) { - wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn) + wrapConn := utilnet.WrapReadWriteCloserToConn(conn, realConn) _ = p.l.PutConn(wrapConn) } diff --git a/pkg/plugin/client/socks5.go b/pkg/plugin/client/socks5.go index f731e87..06a88b6 100644 --- a/pkg/plugin/client/socks5.go +++ b/pkg/plugin/client/socks5.go @@ -21,7 +21,7 @@ import ( gosocks5 "github.com/armon/go-socks5" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) const PluginSocks5 = "socks5" @@ -52,7 +52,7 @@ func NewSocks5Plugin(params map[string]string) (p Plugin, err error) { func (sp *Socks5Plugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBufToLocal []byte) { defer conn.Close() - wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn) + wrapConn := utilnet.WrapReadWriteCloserToConn(conn, realConn) _ = sp.Server.ServeConn(wrapConn) } diff --git a/pkg/plugin/client/static_file.go b/pkg/plugin/client/static_file.go index 097af06..32a888a 100644 --- a/pkg/plugin/client/static_file.go +++ b/pkg/plugin/client/static_file.go @@ -22,7 +22,7 @@ import ( "github.com/gorilla/mux" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) const PluginStaticFile = "static_file" @@ -65,8 +65,8 @@ func NewStaticFilePlugin(params map[string]string) (Plugin, error) { } router := mux.NewRouter() - router.Use(frpNet.NewHTTPAuthMiddleware(httpUser, httpPasswd).SetAuthFailDelay(200 * time.Millisecond).Middleware) - router.PathPrefix(prefix).Handler(frpNet.MakeHTTPGzipHandler(http.StripPrefix(prefix, http.FileServer(http.Dir(localPath))))).Methods("GET") + router.Use(utilnet.NewHTTPAuthMiddleware(httpUser, httpPasswd).SetAuthFailDelay(200 * time.Millisecond).Middleware) + router.PathPrefix(prefix).Handler(utilnet.MakeHTTPGzipHandler(http.StripPrefix(prefix, http.FileServer(http.Dir(localPath))))).Methods("GET") sp.s = &http.Server{ Handler: router, } @@ -77,7 +77,7 @@ func NewStaticFilePlugin(params map[string]string) (Plugin, error) { } func (sp *StaticFilePlugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBufToLocal []byte) { - wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn) + wrapConn := utilnet.WrapReadWriteCloserToConn(conn, realConn) _ = sp.l.PutConn(wrapConn) } diff --git a/pkg/plugin/client/unix_domain_socket.go b/pkg/plugin/client/unix_domain_socket.go index 6890247..416938b 100644 --- a/pkg/plugin/client/unix_domain_socket.go +++ b/pkg/plugin/client/unix_domain_socket.go @@ -19,7 +19,7 @@ import ( "io" "net" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" ) const PluginUnixDomainSocket = "unix_domain_socket" @@ -62,7 +62,7 @@ func (uds *UnixDomainSocketPlugin) Handle(conn io.ReadWriteCloser, realConn net. } } - frpIo.Join(localConn, conn) + libio.Join(localConn, conn) } func (uds *UnixDomainSocketPlugin) Name() string { diff --git a/pkg/util/net/listener.go b/pkg/util/net/listener.go index 3b199c8..6f2d8a5 100644 --- a/pkg/util/net/listener.go +++ b/pkg/util/net/listener.go @@ -22,20 +22,21 @@ import ( "github.com/fatedier/golib/errors" ) -// Custom listener -type CustomListener struct { +// InternalListener is a listener that can be used to accept connections from +// other goroutines. +type InternalListener struct { acceptCh chan net.Conn closed bool mu sync.Mutex } -func NewCustomListener() *CustomListener { - return &CustomListener{ - acceptCh: make(chan net.Conn, 64), +func NewInternalListener() *InternalListener { + return &InternalListener{ + acceptCh: make(chan net.Conn, 128), } } -func (l *CustomListener) Accept() (net.Conn, error) { +func (l *InternalListener) Accept() (net.Conn, error) { conn, ok := <-l.acceptCh if !ok { return nil, fmt.Errorf("listener closed") @@ -43,7 +44,7 @@ func (l *CustomListener) Accept() (net.Conn, error) { return conn, nil } -func (l *CustomListener) PutConn(conn net.Conn) error { +func (l *InternalListener) PutConn(conn net.Conn) error { err := errors.PanicToError(func() { select { case l.acceptCh <- conn: @@ -54,7 +55,7 @@ func (l *CustomListener) PutConn(conn net.Conn) error { return err } -func (l *CustomListener) Close() error { +func (l *InternalListener) Close() error { l.mu.Lock() defer l.mu.Unlock() if !l.closed { @@ -64,6 +65,16 @@ func (l *CustomListener) Close() error { return nil } -func (l *CustomListener) Addr() net.Addr { - return (*net.TCPAddr)(nil) +func (l *InternalListener) Addr() net.Addr { + return &InternalAddr{} +} + +type InternalAddr struct{} + +func (ia *InternalAddr) Network() string { + return "internal" +} + +func (ia *InternalAddr) String() string { + return "internal" } diff --git a/pkg/util/net/tls.go b/pkg/util/net/tls.go index 3aecb48..6645dfa 100644 --- a/pkg/util/net/tls.go +++ b/pkg/util/net/tls.go @@ -20,7 +20,7 @@ import ( "net" "time" - gnet "github.com/fatedier/golib/net" + libnet "github.com/fatedier/golib/net" ) var FRPTLSHeadByte = 0x17 @@ -28,7 +28,7 @@ var FRPTLSHeadByte = 0x17 func CheckAndEnableTLSServerConnWithTimeout( c net.Conn, tlsConfig *tls.Config, tlsOnly bool, timeout time.Duration, ) (out net.Conn, isTLS bool, custom bool, err error) { - sc, r := gnet.NewSharedConnSize(c, 2) + sc, r := libnet.NewSharedConnSize(c, 2) buf := make([]byte, 1) var n int _ = c.SetReadDeadline(time.Now().Add(timeout)) diff --git a/pkg/util/tcpmux/httpconnect.go b/pkg/util/tcpmux/httpconnect.go index 970897a..d6c0ce5 100644 --- a/pkg/util/tcpmux/httpconnect.go +++ b/pkg/util/tcpmux/httpconnect.go @@ -22,7 +22,7 @@ import ( "net/http" "time" - gnet "github.com/fatedier/golib/net" + libnet "github.com/fatedier/golib/net" "github.com/fatedier/frp/pkg/util/util" "github.com/fatedier/frp/pkg/util/vhost" @@ -94,7 +94,7 @@ func (muxer *HTTPConnectTCPMuxer) auth(c net.Conn, username, password string, re func (muxer *HTTPConnectTCPMuxer) getHostFromHTTPConnect(c net.Conn) (net.Conn, map[string]string, error) { reqInfoMap := make(map[string]string, 0) - sc, rd := gnet.NewSharedConn(c) + sc, rd := libnet.NewSharedConn(c) host, httpUser, httpPwd, err := muxer.readHTTPConnectRequest(rd) if err != nil { diff --git a/pkg/util/vhost/http.go b/pkg/util/vhost/http.go index 5addb47..af3a4ab 100644 --- a/pkg/util/vhost/http.go +++ b/pkg/util/vhost/http.go @@ -28,7 +28,7 @@ import ( "strings" "time" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" "github.com/fatedier/golib/pool" frpLog "github.com/fatedier/frp/pkg/util/log" @@ -256,7 +256,7 @@ func (rp *HTTPReverseProxy) connectHandler(rw http.ResponseWriter, req *http.Req return } _ = req.Write(remote) - go frpIo.Join(remote, client) + go libio.Join(remote, client) } func parseBasicAuth(auth string) (username, password string, ok bool) { diff --git a/pkg/util/vhost/https.go b/pkg/util/vhost/https.go index 2e94b4a..991c929 100644 --- a/pkg/util/vhost/https.go +++ b/pkg/util/vhost/https.go @@ -20,7 +20,7 @@ import ( "net" "time" - gnet "github.com/fatedier/golib/net" + libnet "github.com/fatedier/golib/net" ) type HTTPSMuxer struct { @@ -37,7 +37,7 @@ func NewHTTPSMuxer(listener net.Listener, timeout time.Duration) (*HTTPSMuxer, e func GetHTTPSHostname(c net.Conn) (_ net.Conn, _ map[string]string, err error) { reqInfoMap := make(map[string]string, 0) - sc, rd := gnet.NewSharedConn(c) + sc, rd := libnet.NewSharedConn(c) clientHello, err := readClientHello(rd) if err != nil { diff --git a/pkg/util/vhost/vhost.go b/pkg/util/vhost/vhost.go index acb9cb1..6051a21 100644 --- a/pkg/util/vhost/vhost.go +++ b/pkg/util/vhost/vhost.go @@ -22,7 +22,7 @@ import ( "github.com/fatedier/golib/errors" "github.com/fatedier/frp/pkg/util/log" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/xlog" ) @@ -282,7 +282,7 @@ func (l *Listener) Accept() (net.Conn, error) { xl.Debug("rewrite host to [%s] success", l.rewriteHost) conn = sConn } - return frpNet.NewContextConn(l.ctx, conn), nil + return utilnet.NewContextConn(l.ctx, conn), nil } func (l *Listener) Close() error { diff --git a/server/control.go b/server/control.go index d7ed327..a4bffe3 100644 --- a/server/control.go +++ b/server/control.go @@ -30,7 +30,7 @@ import ( "github.com/fatedier/frp/pkg/auth" "github.com/fatedier/frp/pkg/config" "github.com/fatedier/frp/pkg/consts" - frpErr "github.com/fatedier/frp/pkg/errors" + pkgerr "github.com/fatedier/frp/pkg/errors" "github.com/fatedier/frp/pkg/msg" plugin "github.com/fatedier/frp/pkg/plugin/server" "github.com/fatedier/frp/pkg/transport" @@ -268,7 +268,7 @@ func (ctl *Control) GetWorkConn() (workConn net.Conn, err error) { select { case workConn, ok = <-ctl.workConnCh: if !ok { - err = frpErr.ErrCtlClosed + err = pkgerr.ErrCtlClosed return } xl.Debug("get work connection from pool") @@ -283,7 +283,7 @@ func (ctl *Control) GetWorkConn() (workConn net.Conn, err error) { select { case workConn, ok = <-ctl.workConnCh: if !ok { - err = frpErr.ErrCtlClosed + err = pkgerr.ErrCtlClosed xl.Warn("no work connections available, %v", err) return } diff --git a/server/dashboard.go b/server/dashboard.go index ff94139..a5c46ba 100644 --- a/server/dashboard.go +++ b/server/dashboard.go @@ -25,7 +25,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/fatedier/frp/assets" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" ) var ( @@ -50,7 +50,7 @@ func (svr *Service) RunDashboardServer(address string) (err error) { subRouter := router.NewRoute().Subrouter() user, passwd := svr.cfg.DashboardUser, svr.cfg.DashboardPwd - subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd).SetAuthFailDelay(200 * time.Millisecond).Middleware) + subRouter.Use(utilnet.NewHTTPAuthMiddleware(user, passwd).SetAuthFailDelay(200 * time.Millisecond).Middleware) // metrics if svr.cfg.EnablePrometheus { @@ -65,7 +65,7 @@ func (svr *Service) RunDashboardServer(address string) (err error) { // view subRouter.Handle("/favicon.ico", http.FileServer(assets.FileSystem)).Methods("GET") - subRouter.PathPrefix("/static/").Handler(frpNet.MakeHTTPGzipHandler(http.StripPrefix("/static/", http.FileServer(assets.FileSystem)))).Methods("GET") + subRouter.PathPrefix("/static/").Handler(utilnet.MakeHTTPGzipHandler(http.StripPrefix("/static/", http.FileServer(assets.FileSystem)))).Methods("GET") subRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/static/", http.StatusMovedPermanently) diff --git a/server/proxy/http.go b/server/proxy/http.go index 0f25c8c..143665b 100644 --- a/server/proxy/http.go +++ b/server/proxy/http.go @@ -19,12 +19,12 @@ import ( "net" "strings" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" "golang.org/x/time/rate" "github.com/fatedier/frp/pkg/config" "github.com/fatedier/frp/pkg/util/limit" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/util" "github.com/fatedier/frp/pkg/util/vhost" "github.com/fatedier/frp/server/metrics" @@ -157,24 +157,24 @@ func (pxy *HTTPProxy) GetRealConn(remoteAddr string) (workConn net.Conn, err err var rwc io.ReadWriteCloser = tmpConn if pxy.cfg.UseEncryption { - rwc, err = frpIo.WithEncryption(rwc, []byte(pxy.serverCfg.Token)) + rwc, err = libio.WithEncryption(rwc, []byte(pxy.serverCfg.Token)) if err != nil { xl.Error("create encryption stream error: %v", err) return } } if pxy.cfg.UseCompression { - rwc = frpIo.WithCompression(rwc) + rwc = libio.WithCompression(rwc) } if pxy.GetLimiter() != nil { - rwc = frpIo.WrapReadWriteCloser(limit.NewReader(rwc, pxy.GetLimiter()), limit.NewWriter(rwc, pxy.GetLimiter()), func() error { + rwc = libio.WrapReadWriteCloser(limit.NewReader(rwc, pxy.GetLimiter()), limit.NewWriter(rwc, pxy.GetLimiter()), func() error { return rwc.Close() }) } - workConn = frpNet.WrapReadWriteCloserToConn(rwc, tmpConn) - workConn = frpNet.WrapStatsConn(workConn, pxy.updateStatsAfterClosedConn) + workConn = utilnet.WrapReadWriteCloserToConn(rwc, tmpConn) + workConn = utilnet.WrapStatsConn(workConn, pxy.updateStatsAfterClosedConn) metrics.Server.OpenConnection(pxy.GetName(), pxy.GetConf().GetBaseInfo().ProxyType) return } diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index 088d637..56dcea8 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -23,14 +23,14 @@ import ( "sync" "time" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" "golang.org/x/time/rate" "github.com/fatedier/frp/pkg/config" "github.com/fatedier/frp/pkg/msg" plugin "github.com/fatedier/frp/pkg/plugin/server" "github.com/fatedier/frp/pkg/util/limit" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/xlog" "github.com/fatedier/frp/server/controller" "github.com/fatedier/frp/server/metrics" @@ -113,7 +113,7 @@ func (pxy *BaseProxy) GetWorkConnFromPool(src, dst net.Addr) (workConn net.Conn, } xl.Debug("get a new work connection: [%s]", workConn.RemoteAddr().String()) xl.Spawn().AppendPrefix(pxy.GetName()) - workConn = frpNet.NewContextConn(pxy.ctx, workConn) + workConn = utilnet.NewContextConn(pxy.ctx, workConn) var ( srcAddr string @@ -156,7 +156,7 @@ func (pxy *BaseProxy) GetWorkConnFromPool(src, dst net.Addr) (workConn net.Conn, } // startListenHandler start a goroutine handler for each listener. -// p: p will just be passed to handler(Proxy, frpNet.Conn). +// p: p will just be passed to handler(Proxy, utilnet.Conn). // handler: each proxy type can set different handler function to deal with connections accepted from listeners. func (pxy *BaseProxy) startListenHandler(p Proxy, handler func(Proxy, net.Conn, config.ServerCommonConf)) { xl := xlog.FromContextSafe(pxy.ctx) @@ -297,18 +297,18 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv cfg := pxy.GetConf().GetBaseInfo() xl.Trace("handler user tcp connection, use_encryption: %t, use_compression: %t", cfg.UseEncryption, cfg.UseCompression) if cfg.UseEncryption { - local, err = frpIo.WithEncryption(local, []byte(serverCfg.Token)) + local, err = libio.WithEncryption(local, []byte(serverCfg.Token)) if err != nil { xl.Error("create encryption stream error: %v", err) return } } if cfg.UseCompression { - local = frpIo.WithCompression(local) + local = libio.WithCompression(local) } if pxy.GetLimiter() != nil { - local = frpIo.WrapReadWriteCloser(limit.NewReader(local, pxy.GetLimiter()), limit.NewWriter(local, pxy.GetLimiter()), func() error { + local = libio.WrapReadWriteCloser(limit.NewReader(local, pxy.GetLimiter()), limit.NewWriter(local, pxy.GetLimiter()), func() error { return local.Close() }) } @@ -319,7 +319,7 @@ func HandleUserTCPConnection(pxy Proxy, userConn net.Conn, serverCfg config.Serv name := pxy.GetName() proxyType := pxy.GetConf().GetBaseInfo().ProxyType metrics.Server.OpenConnection(name, proxyType) - inCount, outCount, _ := frpIo.Join(local, userConn) + inCount, outCount, _ := libio.Join(local, userConn) metrics.Server.CloseConnection(name, proxyType) metrics.Server.AddTrafficIn(name, proxyType, inCount) metrics.Server.AddTrafficOut(name, proxyType, outCount) diff --git a/server/proxy/udp.go b/server/proxy/udp.go index 3a136c3..f1b7d06 100644 --- a/server/proxy/udp.go +++ b/server/proxy/udp.go @@ -23,14 +23,14 @@ import ( "time" "github.com/fatedier/golib/errors" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" "golang.org/x/time/rate" "github.com/fatedier/frp/pkg/config" "github.com/fatedier/frp/pkg/msg" "github.com/fatedier/frp/pkg/proto/udp" "github.com/fatedier/frp/pkg/util/limit" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/server/metrics" ) @@ -189,7 +189,7 @@ func (pxy *UDPProxy) Run() (remoteAddr string, err error) { var rwc io.ReadWriteCloser = workConn if pxy.cfg.UseEncryption { - rwc, err = frpIo.WithEncryption(rwc, []byte(pxy.serverCfg.Token)) + rwc, err = libio.WithEncryption(rwc, []byte(pxy.serverCfg.Token)) if err != nil { xl.Error("create encryption stream error: %v", err) workConn.Close() @@ -197,16 +197,16 @@ func (pxy *UDPProxy) Run() (remoteAddr string, err error) { } } if pxy.cfg.UseCompression { - rwc = frpIo.WithCompression(rwc) + rwc = libio.WithCompression(rwc) } if pxy.GetLimiter() != nil { - rwc = frpIo.WrapReadWriteCloser(limit.NewReader(rwc, pxy.GetLimiter()), limit.NewWriter(rwc, pxy.GetLimiter()), func() error { + rwc = libio.WrapReadWriteCloser(limit.NewReader(rwc, pxy.GetLimiter()), limit.NewWriter(rwc, pxy.GetLimiter()), func() error { return rwc.Close() }) } - pxy.workConn = frpNet.WrapReadWriteCloserToConn(rwc, workConn) + pxy.workConn = utilnet.WrapReadWriteCloserToConn(rwc, workConn) ctx, cancel := context.WithCancel(context.Background()) go workConnReaderFn(pxy.workConn) go workConnSenderFn(pxy.workConn, ctx) diff --git a/server/service.go b/server/service.go index 0cdd266..4378b95 100644 --- a/server/service.go +++ b/server/service.go @@ -39,7 +39,7 @@ import ( plugin "github.com/fatedier/frp/pkg/plugin/server" "github.com/fatedier/frp/pkg/transport" "github.com/fatedier/frp/pkg/util/log" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/tcpmux" "github.com/fatedier/frp/pkg/util/util" "github.com/fatedier/frp/pkg/util/version" @@ -210,7 +210,7 @@ func NewService(cfg config.ServerCommonConf) (svr *Service, err error) { // Listen for accepting connections from client using kcp protocol. if cfg.KCPBindPort > 0 { address := net.JoinHostPort(cfg.BindAddr, strconv.Itoa(cfg.KCPBindPort)) - svr.kcpListener, err = frpNet.ListenKcp(address) + svr.kcpListener, err = utilnet.ListenKcp(address) if err != nil { err = fmt.Errorf("listen on kcp udp address %s error: %v", address, err) return @@ -235,11 +235,11 @@ func NewService(cfg config.ServerCommonConf) (svr *Service, err error) { } // Listen for accepting connections from client using websocket protocol. - websocketPrefix := []byte("GET " + frpNet.FrpWebsocketPath) + websocketPrefix := []byte("GET " + utilnet.FrpWebsocketPath) websocketLn := svr.muxer.Listen(0, uint32(len(websocketPrefix)), func(data []byte) bool { return bytes.Equal(data, websocketPrefix) }) - svr.websocketListener = frpNet.NewWebsocketListener(websocketLn) + svr.websocketListener = utilnet.NewWebsocketListener(websocketLn) // Create http vhost muxer. if cfg.VhostHTTPPort > 0 { @@ -294,7 +294,7 @@ func NewService(cfg config.ServerCommonConf) (svr *Service, err error) { // frp tls listener svr.tlsListener = svr.muxer.Listen(2, 1, func(data []byte) bool { // tls first byte can be 0x16 only when vhost https port is not same with bind port - return int(data[0]) == frpNet.FRPTLSHeadByte || int(data[0]) == 0x16 + return int(data[0]) == utilnet.FRPTLSHeadByte || int(data[0]) == 0x16 }) // Create nat hole controller. @@ -442,12 +442,12 @@ func (svr *Service) HandleListener(l net.Listener) { xl := xlog.New() ctx := context.Background() - c = frpNet.NewContextConn(xlog.NewContext(ctx, xl), c) + c = utilnet.NewContextConn(xlog.NewContext(ctx, xl), c) log.Trace("start check TLS connection...") originConn := c var isTLS, custom bool - c, isTLS, custom, err = frpNet.CheckAndEnableTLSServerConnWithTimeout(c, svr.tlsConfig, svr.cfg.TLSOnly, connReadTimeout) + c, isTLS, custom, err = utilnet.CheckAndEnableTLSServerConnWithTimeout(c, svr.tlsConfig, svr.cfg.TLSOnly, connReadTimeout) if err != nil { log.Warn("CheckAndEnableTLSServerConnWithTimeout error: %v", err) originConn.Close() @@ -501,7 +501,7 @@ func (svr *Service) HandleQUICListener(l quic.Listener) { _ = frpConn.CloseWithError(0, "") return } - go svr.handleConnection(ctx, frpNet.QuicStreamToNetConn(stream, frpConn)) + go svr.handleConnection(ctx, utilnet.QuicStreamToNetConn(stream, frpConn)) } }(context.Background(), c) } @@ -517,7 +517,7 @@ func (svr *Service) RegisterControl(ctlConn net.Conn, loginMsg *msg.Login) (err } } - ctx := frpNet.NewContextFromConn(ctlConn) + ctx := utilnet.NewContextFromConn(ctlConn) xl := xlog.FromContextSafe(ctx) xl.AppendPrefix(loginMsg.RunID) ctx = xlog.NewContext(ctx, xl) @@ -555,7 +555,7 @@ func (svr *Service) RegisterControl(ctlConn net.Conn, loginMsg *msg.Login) (err // RegisterWorkConn register a new work connection to control and proxies need it. func (svr *Service) RegisterWorkConn(workConn net.Conn, newMsg *msg.NewWorkConn) error { - xl := frpNet.NewLogFromConn(workConn) + xl := utilnet.NewLogFromConn(workConn) ctl, exist := svr.ctlManager.GetByID(newMsg.RunID) if !exist { xl.Warn("No client control found for run id [%s]", newMsg.RunID) diff --git a/server/visitor/visitor.go b/server/visitor/visitor.go index 70f603b..e66f7a0 100644 --- a/server/visitor/visitor.go +++ b/server/visitor/visitor.go @@ -20,15 +20,15 @@ import ( "net" "sync" - frpIo "github.com/fatedier/golib/io" + libio "github.com/fatedier/golib/io" - frpNet "github.com/fatedier/frp/pkg/util/net" + utilnet "github.com/fatedier/frp/pkg/util/net" "github.com/fatedier/frp/pkg/util/util" ) // Manager for visitor listeners. type Manager struct { - visitorListeners map[string]*frpNet.CustomListener + visitorListeners map[string]*utilnet.InternalListener skMap map[string]string mu sync.RWMutex @@ -36,12 +36,12 @@ type Manager struct { func NewManager() *Manager { return &Manager{ - visitorListeners: make(map[string]*frpNet.CustomListener), + visitorListeners: make(map[string]*utilnet.InternalListener), skMap: make(map[string]string), } } -func (vm *Manager) Listen(name string, sk string) (l *frpNet.CustomListener, err error) { +func (vm *Manager) Listen(name string, sk string) (l *utilnet.InternalListener, err error) { vm.mu.Lock() defer vm.mu.Unlock() @@ -50,7 +50,7 @@ func (vm *Manager) Listen(name string, sk string) (l *frpNet.CustomListener, err return } - l = frpNet.NewCustomListener() + l = utilnet.NewInternalListener() vm.visitorListeners[name] = l vm.skMap[name] = sk return @@ -71,15 +71,15 @@ func (vm *Manager) NewConn(name string, conn net.Conn, timestamp int64, signKey var rwc io.ReadWriteCloser = conn if useEncryption { - if rwc, err = frpIo.WithEncryption(rwc, []byte(sk)); err != nil { + if rwc, err = libio.WithEncryption(rwc, []byte(sk)); err != nil { err = fmt.Errorf("create encryption connection failed: %v", err) return } } if useCompression { - rwc = frpIo.WithCompression(rwc) + rwc = libio.WithCompression(rwc) } - err = l.PutConn(frpNet.WrapReadWriteCloserToConn(rwc, conn)) + err = l.PutConn(utilnet.WrapReadWriteCloserToConn(rwc, conn)) } else { err = fmt.Errorf("custom listener for [%s] doesn't exist", name) return