From 2a1b3b2aedb2e1bf222371520b055f31d8d8331f Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Thu, 11 Dec 2025 14:10:59 +0800 Subject: [PATCH] chore: allow sudoku inbound handle sing-mux request --- listener/config/sudoku.go | 9 ++++++++- listener/inbound/sudoku.go | 4 ++++ listener/inbound/sudoku_test.go | 2 ++ listener/sudoku/server.go | 17 ++++++++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/listener/config/sudoku.go b/listener/config/sudoku.go index b49e0255..b581f3f5 100644 --- a/listener/config/sudoku.go +++ b/listener/config/sudoku.go @@ -1,6 +1,10 @@ package config -import "encoding/json" +import ( + "encoding/json" + + "github.com/metacubex/mihomo/listener/sing" +) // SudokuServer describes a Sudoku inbound server configuration. // It is internal to the listener layer and mainly used for logging and wiring. @@ -15,6 +19,9 @@ type SudokuServer struct { HandshakeTimeoutSecond *int `json:"handshake-timeout,omitempty"` EnablePureDownlink *bool `json:"enable-pure-downlink,omitempty"` CustomTable string `json:"custom-table,omitempty"` + + // mihomo private extension (not the part of standard Sudoku protocol) + MuxOption sing.MuxOption `json:"mux-option,omitempty"` } func (s SudokuServer) String() string { diff --git a/listener/inbound/sudoku.go b/listener/inbound/sudoku.go index be69dd39..6c409247 100644 --- a/listener/inbound/sudoku.go +++ b/listener/inbound/sudoku.go @@ -21,6 +21,9 @@ type SudokuOption struct { HandshakeTimeoutSecond *int `inbound:"handshake-timeout,omitempty"` EnablePureDownlink *bool `inbound:"enable-pure-downlink,omitempty"` CustomTable string `inbound:"custom-table,omitempty"` // optional custom byte layout, e.g. xpxvvpvv + + // mihomo private extension (not the part of standard Sudoku protocol) + MuxOption MuxOption `inbound:"mux-option,omitempty"` } func (o SudokuOption) Equal(config C.InboundConfig) bool { @@ -55,6 +58,7 @@ func NewSudoku(options *SudokuOption) (*Sudoku, error) { EnablePureDownlink: options.EnablePureDownlink, CustomTable: options.CustomTable, } + serverConf.MuxOption = options.MuxOption.Build() return &Sudoku{ Base: base, diff --git a/listener/inbound/sudoku_test.go b/listener/inbound/sudoku_test.go index c3fbcc6f..6ba9e63b 100644 --- a/listener/inbound/sudoku_test.go +++ b/listener/inbound/sudoku_test.go @@ -50,6 +50,8 @@ func testInboundSudoku(t *testing.T, inboundOptions inbound.SudokuOption, outbou defer out.Close() tunnel.DoTest(t, out) + + testSingMux(t, tunnel, out) } func TestInboundSudoku_Basic(t *testing.T) { diff --git a/listener/sudoku/server.go b/listener/sudoku/server.go index 072f372b..8351e365 100644 --- a/listener/sudoku/server.go +++ b/listener/sudoku/server.go @@ -9,6 +9,7 @@ import ( "github.com/metacubex/mihomo/adapter/inbound" C "github.com/metacubex/mihomo/constant" LC "github.com/metacubex/mihomo/listener/config" + "github.com/metacubex/mihomo/listener/sing" "github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/transport/socks5" "github.com/metacubex/mihomo/transport/sudoku" @@ -19,6 +20,7 @@ type Listener struct { addr string closed bool protoConf sudoku.ProtocolConfig + handler *sing.ListenerHandler } // RawAddress implements C.Listener @@ -59,7 +61,8 @@ func (l *Listener) handleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou _ = session.Conn.Close() return } - tunnel.HandleTCPConn(inbound.NewSocket(targetAddr, session.Conn, C.SUDOKU, additions...)) + l.handler.HandleSocket(targetAddr, session.Conn, additions...) + //tunnel.HandleTCPConn(inbound.NewSocket(targetAddr, session.Conn, C.SUDOKU, additions...)) } } @@ -122,6 +125,17 @@ func New(config LC.SudokuServer, tunnel C.Tunnel, additions ...inbound.Addition) } } + // Using sing handler for sing-mux support + h, err := sing.NewListenerHandler(sing.ListenerConfig{ + Tunnel: tunnel, + Type: C.SUDOKU, + Additions: additions, + MuxOption: config.MuxOption, + }) + if err != nil { + return nil, err + } + l, err := inbound.Listen("tcp", config.Listen) if err != nil { return nil, err @@ -180,6 +194,7 @@ func New(config LC.SudokuServer, tunnel C.Tunnel, additions ...inbound.Addition) listener: l, addr: config.Listen, protoConf: protoConf, + handler: h, } go func() {