mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-19 00:10:06 +08:00
chore: allow sudoku inbound handle sing-mux request
This commit is contained in:
parent
2211789a7c
commit
2a1b3b2aed
@ -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 {
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user