fix: Mux missing sing logger & initializing race
This commit is contained in:
parent
05b9071ca6
commit
4362dfacc9
7 changed files with 31 additions and 15 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/metacubex/mihomo/component/proxydialer"
|
||||
"github.com/metacubex/mihomo/component/resolver"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
"github.com/metacubex/mihomo/log"
|
||||
|
||||
mux "github.com/sagernet/sing-mux"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
|
@ -107,6 +108,7 @@ func NewSingMux(option SingMuxOption, proxy C.ProxyAdapter, base ProxyBase) (C.P
|
|||
singDialer := proxydialer.NewSingDialer(proxy, dialer.NewDialer(), option.Statistic)
|
||||
client, err := mux.NewClient(mux.Options{
|
||||
Dialer: singDialer,
|
||||
Logger: log.SingLogger,
|
||||
Protocol: option.Protocol,
|
||||
MaxConnections: option.MaxConnections,
|
||||
MinStreams: option.MinStreams,
|
||||
|
|
|
@ -31,7 +31,7 @@ type ListenerHandler struct {
|
|||
Type C.Type
|
||||
Additions []inbound.Addition
|
||||
UDPTimeout time.Duration
|
||||
MuxService *mux.Service
|
||||
muxService *mux.Service
|
||||
}
|
||||
|
||||
func UpstreamMetadata(metadata M.Metadata) M.Metadata {
|
||||
|
@ -49,8 +49,8 @@ func ConvertMetadata(metadata *C.Metadata) M.Metadata {
|
|||
}
|
||||
}
|
||||
|
||||
func (h *ListenerHandler) ConfigureSingMux() (err error) {
|
||||
h.MuxService, err = mux.NewService(mux.ServiceOptions{
|
||||
func (h *ListenerHandler) Initialize() (err error) {
|
||||
h.muxService, err = mux.NewService(mux.ServiceOptions{
|
||||
NewStreamContext: func(ctx context.Context, conn net.Conn) context.Context {
|
||||
return ctx
|
||||
},
|
||||
|
@ -65,26 +65,20 @@ func (h *ListenerHandler) ConfigureSingMux() (err error) {
|
|||
|
||||
func (h *ListenerHandler) IsSpecialFqdn(fqdn string) bool {
|
||||
switch fqdn {
|
||||
case mux.Destination.Fqdn:
|
||||
case vmess.MuxDestination.Fqdn:
|
||||
case uot.MagicAddress:
|
||||
case uot.LegacyMagicAddress:
|
||||
case mux.Destination.Fqdn,
|
||||
vmess.MuxDestination.Fqdn,
|
||||
uot.MagicAddress,
|
||||
uot.LegacyMagicAddress:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (h *ListenerHandler) ParseSpecialFqdn(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
|
||||
switch metadata.Destination.Fqdn {
|
||||
case mux.Destination.Fqdn:
|
||||
if h.MuxService == nil {
|
||||
err := h.ConfigureSingMux()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return h.MuxService.NewConnection(ctx, conn, UpstreamMetadata(metadata))
|
||||
return h.muxService.NewConnection(ctx, conn, UpstreamMetadata(metadata))
|
||||
case vmess.MuxDestination.Fqdn:
|
||||
return vmess.HandleMuxConnection(ctx, conn, h)
|
||||
case uot.MagicAddress:
|
||||
|
|
|
@ -47,6 +47,10 @@ func New(config LC.Hysteria2Server, tunnel C.Tunnel, additions ...inbound.Additi
|
|||
Type: C.HYSTERIA2,
|
||||
Additions: additions,
|
||||
}
|
||||
err = h.Initialize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sl = &Listener{false, config, nil, nil}
|
||||
|
||||
|
|
|
@ -55,6 +55,10 @@ func New(config LC.ShadowsocksServer, tunnel C.Tunnel, additions ...inbound.Addi
|
|||
Type: C.SHADOWSOCKS,
|
||||
Additions: additions,
|
||||
}
|
||||
err = h.Initialize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sl = &Listener{false, config, nil, nil, nil}
|
||||
|
||||
|
|
|
@ -159,6 +159,10 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
|
|||
},
|
||||
DnsAdds: dnsAdds,
|
||||
}
|
||||
err = handler.Initialize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l = &Listener{
|
||||
closed: false,
|
||||
options: options,
|
||||
|
|
|
@ -45,6 +45,10 @@ func New(config LC.VmessServer, tunnel C.Tunnel, additions ...inbound.Addition)
|
|||
Type: C.VMESS,
|
||||
Additions: additions,
|
||||
}
|
||||
err = h.Initialize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
service := vmess.NewService[string](h, vmess.ServiceWithDisableHeaderProtection(), vmess.ServiceWithTimeFunc(ntp.Now))
|
||||
err = service.UpdateUsers(
|
||||
|
|
|
@ -43,6 +43,10 @@ func New(config LC.TuicServer, tunnel C.Tunnel, additions ...inbound.Addition) (
|
|||
Type: C.TUIC,
|
||||
Additions: additions,
|
||||
}
|
||||
err := h.Initialize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cert, err := CN.ParseCert(config.Certificate, config.PrivateKey, C.Path)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue