chore: sync internal logic

This commit is contained in:
wwqgtxx committed 2026-07-15 16:59:59 +08:00
1 parent 0e7c3c79e3
commit bc5976f4ed
2 files changed
+12 -40

No files matched your search

+6 -20
View File
@@ -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)
}
+6 -20
View File
@@ -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)
}