mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-24 12:10:05 +08:00
feat. add uot for sudoku
This commit is contained in:
parent
4a249a0717
commit
b8e06d4543
@ -14,18 +14,18 @@ import (
|
||||
"github.com/saba-futai/sudoku/apis"
|
||||
"github.com/saba-futai/sudoku/pkg/crypto"
|
||||
"github.com/saba-futai/sudoku/pkg/obfs/httpmask"
|
||||
"github.com/saba-futai/sudoku/pkg/obfs/sudoku"
|
||||
sudokuobfs "github.com/saba-futai/sudoku/pkg/obfs/sudoku"
|
||||
|
||||
N "github.com/metacubex/mihomo/common/net"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
"github.com/metacubex/mihomo/log"
|
||||
"github.com/metacubex/mihomo/transport/sudotun"
|
||||
ts "github.com/metacubex/mihomo/transport/sudoku"
|
||||
)
|
||||
|
||||
type Sudoku struct {
|
||||
*Base
|
||||
option *SudokuOption
|
||||
table *sudoku.Table
|
||||
table *sudokuobfs.Table
|
||||
baseConf apis.ProtocolConfig
|
||||
}
|
||||
|
||||
@ -101,12 +101,12 @@ func (s *Sudoku) ListenPacketContext(ctx context.Context, metadata *C.Metadata)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = sudotun.WritePreface(c); err != nil {
|
||||
if err = ts.WritePreface(c); err != nil {
|
||||
_ = c.Close()
|
||||
return nil, fmt.Errorf("send uot preface failed: %w", err)
|
||||
}
|
||||
|
||||
return newPacketConn(N.NewThreadSafePacketConn(sudotun.NewUoTPacketConn(c)), s), nil
|
||||
return newPacketConn(N.NewThreadSafePacketConn(ts.NewUoTPacketConn(c)), s), nil
|
||||
}
|
||||
|
||||
// SupportUOT implements C.ProxyAdapter
|
||||
@ -142,7 +142,7 @@ func (s *Sudoku) handshakeConn(rawConn net.Conn, cfg *apis.ProtocolConfig) (_ ne
|
||||
}
|
||||
}
|
||||
|
||||
obfsConn := sudoku.NewConn(rawConn, cfg.Table, cfg.PaddingMin, cfg.PaddingMax, false)
|
||||
obfsConn := sudokuobfs.NewConn(rawConn, cfg.Table, cfg.PaddingMin, cfg.PaddingMax, false)
|
||||
cConn, err := crypto.NewAEADConn(obfsConn, cfg.Key, cfg.AEADMethod)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("setup crypto failed: %w", err)
|
||||
@ -196,7 +196,7 @@ func NewSudoku(option SudokuOption) (*Sudoku, error) {
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
table := sudoku.NewTable(seed, tableType)
|
||||
table := sudokuobfs.NewTable(seed, tableType)
|
||||
log.Infoln("[Sudoku] Tables initialized (%s) in %v", tableType, time.Since(start))
|
||||
|
||||
defaultConf := apis.DefaultConfig()
|
||||
|
||||
@ -14,7 +14,7 @@ import (
|
||||
LC "github.com/metacubex/mihomo/listener/config"
|
||||
"github.com/metacubex/mihomo/log"
|
||||
"github.com/metacubex/mihomo/transport/socks5"
|
||||
"github.com/metacubex/mihomo/transport/sudotun"
|
||||
ts "github.com/metacubex/mihomo/transport/sudoku"
|
||||
)
|
||||
|
||||
type Listener struct {
|
||||
@ -47,14 +47,14 @@ func (l *Listener) Close() error {
|
||||
}
|
||||
|
||||
func (l *Listener) handleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbound.Addition) {
|
||||
session, err := sudotun.ServerHandshake(conn, &l.protoConf)
|
||||
session, err := ts.ServerHandshake(conn, &l.protoConf)
|
||||
if err != nil {
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
switch session.Type {
|
||||
case sudotun.SessionTypeUoT:
|
||||
case ts.SessionTypeUoT:
|
||||
l.handleUoTSession(session.Conn, tunnel, additions...)
|
||||
default:
|
||||
targetAddr := socks5.ParseAddr(session.Target)
|
||||
@ -67,11 +67,11 @@ func (l *Listener) handleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou
|
||||
}
|
||||
|
||||
func (l *Listener) handleUoTSession(conn net.Conn, tunnel C.Tunnel, additions ...inbound.Addition) {
|
||||
writer := sudotun.NewUoTPacketConn(conn)
|
||||
writer := ts.NewUoTPacketConn(conn)
|
||||
remoteAddr := conn.RemoteAddr()
|
||||
|
||||
for {
|
||||
addrStr, payload, err := sudotun.ReadDatagram(conn)
|
||||
addrStr, payload, err := ts.ReadDatagram(conn)
|
||||
if err != nil {
|
||||
if !errors.Is(err, io.EOF) {
|
||||
log.Debugln("[Sudoku][UoT] session closed: %v", err)
|
||||
@ -97,7 +97,7 @@ func (l *Listener) handleUoTSession(conn net.Conn, tunnel C.Tunnel, additions ..
|
||||
|
||||
type uotPacket struct {
|
||||
payload []byte
|
||||
writer *sudotun.UoTPacketConn
|
||||
writer *ts.UoTPacketConn
|
||||
rAddr net.Addr
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package sudotun
|
||||
package sudoku
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -1,4 +1,4 @@
|
||||
package sudotun
|
||||
package sudoku
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
Loading…
Reference in New Issue
Block a user