style: перевести комментарии на русский, убрать очевидные
This commit is contained in:
1 parent
ada9b949a4
commit
e417dac087
48 files changed
+659
-671
No files matched your search
@@ -1,9 +1,9 @@
|
||||
// Package tcpfwd implements VLESS mode: TCP forwarding over a pool of TURN-tunneled
|
||||
// smux sessions. Each accepted local TCP connection is opened as a smux stream
|
||||
// (round-robin across sessions) or, with bond, striped across all live sessions.
|
||||
// Package tcpfwd реализует VLESS-режим: пересылка TCP через пул TURN-туннелированных
|
||||
// smux-сессий. Каждое принятое TCP-соединение открывается как smux-поток
|
||||
// (round-robin по сессиям) или, с bond, распределяется по всем активным сессиям.
|
||||
//
|
||||
// SessionPool/PooledSession are exported so the bond client (internal/proxy/bondclient)
|
||||
// can stripe a single TCP connection across multiple live sessions.
|
||||
// SessionPool/PooledSession экспортированы, чтобы bond-клиент (internal/proxy/bondclient)
|
||||
// мог распределять одно TCP-соединение по нескольким сессиям.
|
||||
package tcpfwd
|
||||
|
||||
import (
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
// PooledSession is a single TURN+DTLS+KCP+smux session inside the pool, with
|
||||
// its lifetime counters. Fields are exported so internal/proxy/bondclient can
|
||||
// account per-lane traffic; mutate the atomics via their atomic methods only.
|
||||
// PooledSession — одна TURN+DTLS+KCP+smux сессия в пуле с lifetime-счётчиками.
|
||||
// Поля экспортированы для учёта per-lane трафика в bondclient;
|
||||
// атомики изменять только через их методы.
|
||||
type PooledSession struct {
|
||||
ID int
|
||||
Sess *smux.Session
|
||||
@@ -26,7 +26,7 @@ type PooledSession struct {
|
||||
FromSession atomic.Uint64
|
||||
}
|
||||
|
||||
// SessionPool is a concurrency-safe round-robin pool of live smux sessions.
|
||||
// SessionPool — конкурентно-безопасный round-robin пул активных smux-сессий.
|
||||
type SessionPool struct {
|
||||
mu sync.RWMutex
|
||||
sessions []*PooledSession
|
||||
@@ -37,7 +37,7 @@ type SessionPool struct {
|
||||
ready chan struct{}
|
||||
}
|
||||
|
||||
// Ready returns a channel closed the first time the pool gains a session.
|
||||
// Ready возвращает канал, закрытый при первом появлении сессии в пуле.
|
||||
func (p *SessionPool) Ready() <-chan struct{} {
|
||||
p.mu.Lock()
|
||||
if p.ready == nil {
|
||||
@@ -48,7 +48,7 @@ func (p *SessionPool) Ready() <-chan struct{} {
|
||||
return ch
|
||||
}
|
||||
|
||||
// Add registers a freshly connected session in the pool.
|
||||
// Add регистрирует только что подключённую сессию в пуле.
|
||||
func (p *SessionPool) Add(id int, s *smux.Session) *PooledSession {
|
||||
ps := &PooledSession{ID: id, Sess: s}
|
||||
p.mu.Lock()
|
||||
@@ -62,7 +62,7 @@ func (p *SessionPool) Add(id int, s *smux.Session) *PooledSession {
|
||||
return ps
|
||||
}
|
||||
|
||||
// Remove drops ps from the pool. No-op if not present.
|
||||
// Remove удаляет ps из пула. No-op если не найден.
|
||||
func (p *SessionPool) Remove(ps *PooledSession) {
|
||||
p.mu.Lock()
|
||||
for i, sess := range p.sessions {
|
||||
@@ -74,7 +74,7 @@ func (p *SessionPool) Remove(ps *PooledSession) {
|
||||
p.mu.Unlock()
|
||||
}
|
||||
|
||||
// Pick returns the next session in round-robin order, or nil if pool is empty.
|
||||
// Pick возвращает следующую сессию в round-robin порядке или nil если пул пуст.
|
||||
func (p *SessionPool) Pick() *PooledSession {
|
||||
p.mu.RLock()
|
||||
defer p.mu.RUnlock()
|
||||
@@ -86,12 +86,12 @@ func (p *SessionPool) Pick() *PooledSession {
|
||||
return p.sessions[idx]
|
||||
}
|
||||
|
||||
// NextConnID returns a monotonically increasing connection ID.
|
||||
// NextConnID возвращает монотонно возрастающий идентификатор соединения.
|
||||
func (p *SessionPool) NextConnID() uint64 {
|
||||
return p.connCounter.Add(1)
|
||||
}
|
||||
|
||||
// Snapshot returns a copy of all currently-live (non-closed) sessions.
|
||||
// Snapshot возвращает копию всех активных (незакрытых) сессий.
|
||||
func (p *SessionPool) Snapshot() []*PooledSession {
|
||||
p.mu.RLock()
|
||||
defer p.mu.RUnlock()
|
||||
@@ -104,8 +104,8 @@ func (p *SessionPool) Snapshot() []*PooledSession {
|
||||
return out
|
||||
}
|
||||
|
||||
// Count returns the number of sessions currently in the pool (including any
|
||||
// that may have just closed; use Snapshot for live-only).
|
||||
// Count возвращает число сессий в пуле (включая только что закрытые;
|
||||
// используй Snapshot для live-only).
|
||||
func (p *SessionPool) Count() int {
|
||||
p.mu.RLock()
|
||||
defer p.mu.RUnlock()
|
||||
|
||||
@@ -18,11 +18,10 @@ import (
|
||||
"github.com/xtaci/smux"
|
||||
)
|
||||
|
||||
// GetCredsFunc is re-exported from common so callers can keep their imports
|
||||
// scoped to this package.
|
||||
// GetCredsFunc реэкспортирован из common, чтобы вызывающие не выходили за пределы импортов пакета.
|
||||
type GetCredsFunc = common.GetCredsFunc
|
||||
|
||||
// Params is the per-pool TURN/wrap configuration.
|
||||
// Params — конфигурация TURN/wrap для пула.
|
||||
type Params struct {
|
||||
Host string
|
||||
Port string
|
||||
@@ -34,12 +33,12 @@ type Params struct {
|
||||
KCPFEC kcptun.FEC
|
||||
}
|
||||
|
||||
// BondHandler stripes one accepted TCP connection across all currently-live
|
||||
// pool sessions. Nil disables bond mode (callers will then use round-robin).
|
||||
// The bond client implementation lives in internal/proxy/bondclient.
|
||||
// BondHandler распределяет одно принятое TCP-соединение по всем активным сессиям пула.
|
||||
// Nil отключает bond-режим (будет round-robin).
|
||||
// Реализация — internal/proxy/bondclient.
|
||||
type BondHandler func(ctx context.Context, tcpConn net.Conn, connID uint64, lanes []*PooledSession)
|
||||
|
||||
// Deps groups host-process dependencies needed by the VLESS loop.
|
||||
// Deps — зависимости хост-процесса для VLESS-цикла.
|
||||
type Deps struct {
|
||||
DTLSDialer *dtlsdial.Dialer
|
||||
Log logx.Logger
|
||||
@@ -53,9 +52,9 @@ func (d *Deps) log() logx.Logger {
|
||||
return d.Log
|
||||
}
|
||||
|
||||
// Run is the VLESS-mode entrypoint. It spawns numSessions maintainers, waits
|
||||
// for at least one to connect, then accepts local TCP connections and forwards
|
||||
// each as a smux stream (round-robin) or bonded across all live sessions.
|
||||
// Run — точка входа VLESS-режима. Запускает numSessions maintainer-горутин, ждёт
|
||||
// первого подключения, затем принимает локальные TCP-соединения и форвардит
|
||||
// каждое как smux-поток (round-robin) или bonded по всем активным сессиям.
|
||||
func Run(ctx context.Context, deps *Deps, params *Params, peer *net.UDPAddr, listenAddr string, numSessions int, useBond bool) error {
|
||||
pool := &SessionPool{}
|
||||
|
||||
@@ -176,9 +175,9 @@ func Run(ctx context.Context, deps *Deps, params *Params, peer *net.UDPAddr, lis
|
||||
}
|
||||
}
|
||||
|
||||
// maintainSession keeps one TURN+DTLS+KCP+smux session alive: 3s backoff on
|
||||
// setup failure, 2s after a successful session disconnects, in both cases
|
||||
// before the next reconnect attempt.
|
||||
// maintainSession поддерживает одну TURN+DTLS+KCP+smux сессию живой:
|
||||
// 3s backoff при ошибке инициализации, 2s после отключения успешной сессии,
|
||||
// в обоих случаях перед следующей попыткой подключения.
|
||||
func maintainSession(ctx context.Context, deps *Deps, params *Params, peer *net.UDPAddr, id int, pool *SessionPool) {
|
||||
for {
|
||||
select {
|
||||
@@ -223,8 +222,8 @@ func maintainSession(ctx context.Context, deps *Deps, params *Params, peer *net.
|
||||
}
|
||||
}
|
||||
|
||||
// createSmuxSession establishes a full TURN+DTLS+KCP+smux pipeline and returns
|
||||
// the smux session along with a cleanup function (LIFO teardown).
|
||||
// createSmuxSession создаёт полный TURN+DTLS+KCP+smux pipeline и возвращает
|
||||
// smux-сессию вместе с функцией cleanup (LIFO-разрушение).
|
||||
func createSmuxSession(ctx context.Context, deps *Deps, params *Params, peer *net.UDPAddr, id int) (*smux.Session, func(), error) {
|
||||
var cleanupFns []func()
|
||||
cleanup := func() {
|
||||
|
||||
Reference in new issue
Block a user