mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
chore: allow sudoku inbound handle sing-mux request
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "encoding/json"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/metacubex/mihomo/listener/sing"
|
||||||
|
)
|
||||||
|
|
||||||
// SudokuServer describes a Sudoku inbound server configuration.
|
// SudokuServer describes a Sudoku inbound server configuration.
|
||||||
// It is internal to the listener layer and mainly used for logging and wiring.
|
// 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"`
|
HandshakeTimeoutSecond *int `json:"handshake-timeout,omitempty"`
|
||||||
EnablePureDownlink *bool `json:"enable-pure-downlink,omitempty"`
|
EnablePureDownlink *bool `json:"enable-pure-downlink,omitempty"`
|
||||||
CustomTable string `json:"custom-table,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 {
|
func (s SudokuServer) String() string {
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ type SudokuOption struct {
|
|||||||
HandshakeTimeoutSecond *int `inbound:"handshake-timeout,omitempty"`
|
HandshakeTimeoutSecond *int `inbound:"handshake-timeout,omitempty"`
|
||||||
EnablePureDownlink *bool `inbound:"enable-pure-downlink,omitempty"`
|
EnablePureDownlink *bool `inbound:"enable-pure-downlink,omitempty"`
|
||||||
CustomTable string `inbound:"custom-table,omitempty"` // optional custom byte layout, e.g. xpxvvpvv
|
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 {
|
func (o SudokuOption) Equal(config C.InboundConfig) bool {
|
||||||
@@ -55,6 +58,7 @@ func NewSudoku(options *SudokuOption) (*Sudoku, error) {
|
|||||||
EnablePureDownlink: options.EnablePureDownlink,
|
EnablePureDownlink: options.EnablePureDownlink,
|
||||||
CustomTable: options.CustomTable,
|
CustomTable: options.CustomTable,
|
||||||
}
|
}
|
||||||
|
serverConf.MuxOption = options.MuxOption.Build()
|
||||||
|
|
||||||
return &Sudoku{
|
return &Sudoku{
|
||||||
Base: base,
|
Base: base,
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ func testInboundSudoku(t *testing.T, inboundOptions inbound.SudokuOption, outbou
|
|||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
tunnel.DoTest(t, out)
|
tunnel.DoTest(t, out)
|
||||||
|
|
||||||
|
testSingMux(t, tunnel, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInboundSudoku_Basic(t *testing.T) {
|
func TestInboundSudoku_Basic(t *testing.T) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/metacubex/mihomo/adapter/inbound"
|
"github.com/metacubex/mihomo/adapter/inbound"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
C "github.com/metacubex/mihomo/constant"
|
||||||
LC "github.com/metacubex/mihomo/listener/config"
|
LC "github.com/metacubex/mihomo/listener/config"
|
||||||
|
"github.com/metacubex/mihomo/listener/sing"
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
"github.com/metacubex/mihomo/transport/socks5"
|
"github.com/metacubex/mihomo/transport/socks5"
|
||||||
"github.com/metacubex/mihomo/transport/sudoku"
|
"github.com/metacubex/mihomo/transport/sudoku"
|
||||||
@@ -19,6 +20,7 @@ type Listener struct {
|
|||||||
addr string
|
addr string
|
||||||
closed bool
|
closed bool
|
||||||
protoConf sudoku.ProtocolConfig
|
protoConf sudoku.ProtocolConfig
|
||||||
|
handler *sing.ListenerHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// RawAddress implements C.Listener
|
// RawAddress implements C.Listener
|
||||||
@@ -59,7 +61,8 @@ func (l *Listener) handleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou
|
|||||||
_ = session.Conn.Close()
|
_ = session.Conn.Close()
|
||||||
return
|
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)
|
l, err := inbound.Listen("tcp", config.Listen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -180,6 +194,7 @@ func New(config LC.SudokuServer, tunnel C.Tunnel, additions ...inbound.Addition)
|
|||||||
listener: l,
|
listener: l,
|
||||||
addr: config.Listen,
|
addr: config.Listen,
|
||||||
protoConf: protoConf,
|
protoConf: protoConf,
|
||||||
|
handler: h,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user