refactor(kcptun): передавать Profile/FEC явно через config вместо process-wide env

This commit is contained in:
samosvalishe committed 2026-05-20 11:52:27 +03:00
1 parent 9459e94066
commit 483e45d68a
6 files changed
+114 -137

No files matched your search

+9 -7
View File
@@ -24,12 +24,14 @@ type GetCredsFunc = common.GetCredsFunc
// Params is the per-pool TURN/wrap configuration.
type Params struct {
Host string
Port string
Link string
UDP bool
WrapKey []byte
GetCreds GetCredsFunc
Host string
Port string
Link string
UDP bool
WrapKey []byte
GetCreds GetCredsFunc
KCPProfile kcptun.Profile
KCPFEC kcptun.FEC
}
// BondHandler stripes one accepted TCP connection across all currently-live
@@ -254,7 +256,7 @@ func createSmuxSession(ctx context.Context, deps *Deps, params *Params, peer *ne
st := stats.New(deps.log().DebugEnabled())
go st.LogEvery(statsCtx, deps.log().Debugf, fmt.Sprintf("[session %d] VLESS", id), "to-turn", "from-turn")
kcpSess, err := kcptun.NewKCPOverDTLS(&stats.CountingConn{Conn: dtlsConn, Stats: st}, false)
kcpSess, err := kcptun.NewKCPOverDTLS(&stats.CountingConn{Conn: dtlsConn, Stats: st}, false, params.KCPProfile, params.KCPFEC)
if err != nil {
cleanup()
return nil, nil, fmt.Errorf("KCP session: %w", err)
+2 -2
View File
@@ -22,7 +22,7 @@ import (
// Handle wraps dtlsConn in KCP+smux and forwards each accepted stream as a TCP
// connection to connectAddr. Streams whose first 4 bytes match the bond magic
// are handed off to registry.
func Handle(ctx context.Context, logger logx.Logger, registry *bondserver.Registry, dtlsConn net.Conn, connectAddr string) {
func Handle(ctx context.Context, logger logx.Logger, registry *bondserver.Registry, dtlsConn net.Conn, connectAddr string, kcpProfile kcptun.Profile, kcpFEC kcptun.FEC) {
statsCtx, statsCancel := context.WithCancel(ctx)
defer statsCancel()
st := stats.New(logger.DebugEnabled())
@@ -34,7 +34,7 @@ func Handle(ctx context.Context, logger logx.Logger, registry *bondserver.Regist
"from-client",
)
kcpSess, err := kcptun.NewKCPOverDTLS(&stats.CountingConn{Conn: dtlsConn, Stats: st}, true)
kcpSess, err := kcptun.NewKCPOverDTLS(&stats.CountingConn{Conn: dtlsConn, Stats: st}, true, kcpProfile, kcpFEC)
if err != nil {
logger.Errorf("tcpfwdserver: KCP session: %s", err)
return