refactor: симметрия, вынос серверных хендлеров
- internal/proxy/udpserver: handleUDPConnection вынесен из server-main - internal/proxy/tcpfwdserver: handleVLESSConnection + prefixedConn + pipeConn вынесены из server-main - cmd/vk-turn-server/main.go: 396 → 134 строк, глобалы убраны - internal/proxy/udprelay: добавлен entrypoint Run() симметрично tcpfwd.Run; Pool → packetPool (unexported); listener+fan-in вынесены из client-main - cmd/vk-turn-client/main.go: 262 → 130 строк, package-глобалы убраны - dtlsdial.Dialer: кеш self-signed сертификата на Dialer (sync.Once) вместо регенерации на каждый handshake - captcha.solveCaptchaPoW: переиспользование буфера (вместо 10M конкатенаций строк), ctx-проверка каждые 1024 итерации (было 4096) Тесты + lint проходят.
This commit is contained in:
1 parent
ed6825976a
commit
51bda46446
7 files changed
+465
-460
No files matched your search
@@ -463,15 +463,20 @@ func solveCaptchaPoW(ctx context.Context, input string, difficulty int) string {
|
||||
return ""
|
||||
}
|
||||
target := strings.Repeat("0", difficulty)
|
||||
// ctx-check every 1024 iterations keeps cancel latency under a few ms
|
||||
// even on weak ARM (was every 4096).
|
||||
buf := make([]byte, 0, len(input)+20)
|
||||
buf = append(buf, input...)
|
||||
for nonce := 1; nonce <= 10_000_000; nonce++ {
|
||||
if nonce%4096 == 0 {
|
||||
if nonce&1023 == 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ""
|
||||
default:
|
||||
}
|
||||
}
|
||||
sum := sha256.Sum256([]byte(input + strconv.Itoa(nonce)))
|
||||
buf = strconv.AppendInt(buf[:len(input)], int64(nonce), 10)
|
||||
sum := sha256.Sum256(buf)
|
||||
hashHex := hex.EncodeToString(sum[:])
|
||||
if strings.HasPrefix(hashHex, target) {
|
||||
return hashHex
|
||||
|
||||
Reference in new issue
Block a user