feat(proxy): tcp-режим для xray/sing-box поверх turn

This commit is contained in:
samosvalishe committed 2026-08-25 15:44:16 +03:00
1 parent e63279db18
commit f7129099f7
60 files changed
+2953 -135

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
// Package allocpace распределяет во времени вызовы TURN Allocate: квота считается на
// username, поэтому залп от всех потоков сразу упирается в неё плотнее, чем очередь.
package allocpace
import (
"context"
"sync"
"time"
)
const DefaultInterval = 200 * time.Millisecond
type Pacer struct {
mu sync.Mutex
next time.Time
step time.Duration
}
func New(step time.Duration) *Pacer {
return &Pacer{step: step}
}
// Wait возвращает false, только если ctx отменён - слот всё равно занят и не переиспользуется.
func (p *Pacer) Wait(ctx context.Context) bool {
if p == nil {
return ctx.Err() == nil
}
wait := time.Until(p.slot())
if wait <= 0 {
return ctx.Err() == nil
}
t := time.NewTimer(wait)
defer t.Stop()
select {
case <-t.C:
return true
case <-ctx.Done():
return false
}
}
func (p *Pacer) slot() time.Time {
p.mu.Lock()
defer p.mu.Unlock()
now := time.Now()
if p.next.Before(now) {
p.next = now
}
slot := p.next
p.next = slot.Add(p.step)
return slot
}