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