diff --git a/listener/shadowsocks/tcp.go b/listener/shadowsocks/tcp.go index 0f5c942ce..cc7adac14 100644 --- a/listener/shadowsocks/tcp.go +++ b/listener/shadowsocks/tcp.go @@ -10,11 +10,10 @@ import ( N "github.com/metacubex/mihomo/common/net" C "github.com/metacubex/mihomo/constant" LC "github.com/metacubex/mihomo/listener/config" - "github.com/metacubex/mihomo/listener/inner" "github.com/metacubex/mihomo/listener/jls" + "github.com/metacubex/mihomo/listener/restls" "github.com/metacubex/mihomo/listener/shadowtls" "github.com/metacubex/mihomo/listener/sing" - "github.com/metacubex/mihomo/transport/restls" "github.com/metacubex/mihomo/transport/shadowsocks/core" obfs "github.com/metacubex/mihomo/transport/simple-obfs" "github.com/metacubex/mihomo/transport/socks5" @@ -27,7 +26,6 @@ type Listener struct { udpListeners []*UDPListener pickCipher core.Cipher handler *sing.ListenerHandler - resTLS *restls.ServerConfig simpleObfs func(net.Conn) net.Conn } @@ -60,16 +58,9 @@ func New(config LC.ShadowsocksServer, lc C.InboundListenConfig, tunnel C.Tunnel, } } + var restlsBuilder *restls.Builder if config.ResTLS.Enable { - sl.resTLS = &restls.ServerConfig{ - ServerHostname: config.ResTLS.Dest, - Password: config.ResTLS.Password, - RestlsScript: config.ResTLS.RestlsScript, - MinRecordLen: config.ResTLS.MinRecordLen, - DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { - return inner.HandleTcp(tunnel, address, config.ResTLS.Proxy) - }, - } + restlsBuilder = restls.New(config.ResTLS, tunnel) } var jlsBuilder *jls.Builder @@ -114,6 +105,9 @@ func New(config LC.ShadowsocksServer, lc C.InboundListenConfig, tunnel C.Tunnel, if jlsBuilder != nil { l = jlsBuilder.NewListener(l) } + if restlsBuilder != nil { + l = restlsBuilder.NewListener(l) + } sl.listeners = append(sl.listeners, l) go func() { @@ -172,14 +166,6 @@ func (l *Listener) HandleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou if loaded { additions = append(append([]inbound.Addition(nil), additions...), inbound.WithInUser(user)) } - if l.resTLS != nil { - c, err := restls.Server(context.TODO(), conn, l.resTLS) - if err != nil { - _ = conn.Close() - return - } - conn = c - } if l.simpleObfs != nil { conn = l.simpleObfs(conn) } diff --git a/listener/sing_shadowsocks/server.go b/listener/sing_shadowsocks/server.go index 670aeaae8..17f0ccf28 100644 --- a/listener/sing_shadowsocks/server.go +++ b/listener/sing_shadowsocks/server.go @@ -10,15 +10,14 @@ import ( "github.com/metacubex/mihomo/common/sockopt" C "github.com/metacubex/mihomo/constant" LC "github.com/metacubex/mihomo/listener/config" - "github.com/metacubex/mihomo/listener/inner" "github.com/metacubex/mihomo/listener/jls" + "github.com/metacubex/mihomo/listener/restls" embedSS "github.com/metacubex/mihomo/listener/shadowsocks" "github.com/metacubex/mihomo/listener/shadowtls" "github.com/metacubex/mihomo/listener/sing" "github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/ntp" "github.com/metacubex/mihomo/transport/kcptun" - "github.com/metacubex/mihomo/transport/restls" obfs "github.com/metacubex/mihomo/transport/simple-obfs" shadowsocks "github.com/metacubex/sing-shadowsocks" @@ -38,7 +37,6 @@ type Listener struct { listeners []net.Listener udpListeners []net.PacketConn service shadowsocks.Service - resTLS *restls.ServerConfig simpleObfs func(net.Conn) net.Conn } @@ -95,16 +93,9 @@ func New(config LC.ShadowsocksServer, lc C.InboundListenConfig, tunnel C.Tunnel, } } + var restlsBuilder *restls.Builder if config.ResTLS.Enable { - sl.resTLS = &restls.ServerConfig{ - ServerHostname: config.ResTLS.Dest, - Password: config.ResTLS.Password, - RestlsScript: config.ResTLS.RestlsScript, - MinRecordLen: config.ResTLS.MinRecordLen, - DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { - return inner.HandleTcp(tunnel, address, config.ResTLS.Proxy) - }, - } + restlsBuilder = restls.New(config.ResTLS, tunnel) } var jlsBuilder *jls.Builder @@ -207,6 +198,9 @@ func New(config LC.ShadowsocksServer, lc C.InboundListenConfig, tunnel C.Tunnel, if jlsBuilder != nil { l = jlsBuilder.NewListener(l) } + if restlsBuilder != nil { + l = restlsBuilder.NewListener(l) + } sl.listeners = append(sl.listeners, l) go func() { @@ -264,14 +258,6 @@ func (l *Listener) HandleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou if jlsUser, jlsLoaded := jls.UserFromConn(conn); jlsLoaded { user, loaded = jlsUser, true } - if l.resTLS != nil { - c, err := restls.Server(context.TODO(), conn, l.resTLS) - if err != nil { - _ = conn.Close() - return - } - conn = c - } if l.simpleObfs != nil { conn = l.simpleObfs(conn) }