mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-11 02:49:57 +00:00
chore: add customized byte style for sudoku (#2427)
This commit is contained in:
@@ -14,6 +14,7 @@ type SudokuServer struct {
|
||||
TableType string `json:"table-type,omitempty"`
|
||||
HandshakeTimeoutSecond *int `json:"handshake-timeout,omitempty"`
|
||||
EnablePureDownlink *bool `json:"enable-pure-downlink,omitempty"`
|
||||
CustomTable string `json:"custom-table,omitempty"`
|
||||
}
|
||||
|
||||
func (s SudokuServer) String() string {
|
||||
|
||||
@@ -20,6 +20,7 @@ type SudokuOption struct {
|
||||
TableType string `inbound:"table-type,omitempty"` // "prefer_ascii" or "prefer_entropy"
|
||||
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
|
||||
}
|
||||
|
||||
func (o SudokuOption) Equal(config C.InboundConfig) bool {
|
||||
@@ -52,6 +53,7 @@ func NewSudoku(options *SudokuOption) (*Sudoku, error) {
|
||||
TableType: options.TableType,
|
||||
HandshakeTimeoutSecond: options.HandshakeTimeoutSecond,
|
||||
EnablePureDownlink: options.EnablePureDownlink,
|
||||
CustomTable: options.CustomTable,
|
||||
}
|
||||
|
||||
return &Sudoku{
|
||||
|
||||
@@ -138,3 +138,27 @@ func TestInboundSudoku_PackedDownlink(t *testing.T) {
|
||||
testInboundSudoku(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
}
|
||||
|
||||
func TestInboundSudoku_CustomTable(t *testing.T) {
|
||||
key := "test_key_custom"
|
||||
custom := "xpxvvpvv"
|
||||
inboundOptions := inbound.SudokuOption{
|
||||
Key: key,
|
||||
TableType: "prefer_entropy",
|
||||
CustomTable: custom,
|
||||
}
|
||||
outboundOptions := outbound.SudokuOption{
|
||||
Key: key,
|
||||
TableType: "prefer_entropy",
|
||||
CustomTable: custom,
|
||||
}
|
||||
testInboundSudoku(t, inboundOptions, outboundOptions)
|
||||
|
||||
t.Run("ed25519key", func(t *testing.T) {
|
||||
inboundOptions := inboundOptions
|
||||
outboundOptions := outboundOptions
|
||||
inboundOptions.Key = sudokuPublicKey
|
||||
outboundOptions.Key = sudokuPrivateKey
|
||||
testInboundSudoku(t, inboundOptions, outboundOptions)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -152,6 +152,12 @@ func New(config LC.SudokuServer, tunnel C.Tunnel, additions ...inbound.Addition)
|
||||
enablePureDownlink = *config.EnablePureDownlink
|
||||
}
|
||||
|
||||
table, err := sudoku.NewTableWithCustom(config.Key, tableType, config.CustomTable)
|
||||
if err != nil {
|
||||
_ = l.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
handshakeTimeout := defaultConf.HandshakeTimeoutSeconds
|
||||
if config.HandshakeTimeoutSecond != nil {
|
||||
handshakeTimeout = *config.HandshakeTimeoutSecond
|
||||
@@ -160,7 +166,7 @@ func New(config LC.SudokuServer, tunnel C.Tunnel, additions ...inbound.Addition)
|
||||
protoConf := sudoku.ProtocolConfig{
|
||||
Key: config.Key,
|
||||
AEADMethod: defaultConf.AEADMethod,
|
||||
Table: sudoku.NewTable(config.Key, tableType),
|
||||
Table: table,
|
||||
PaddingMin: paddingMin,
|
||||
PaddingMax: paddingMax,
|
||||
EnablePureDownlink: enablePureDownlink,
|
||||
|
||||
Reference in New Issue
Block a user