mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 23:24:01 +03:00
FILE / ScuroNeko/mtg
mtglib/internal/doppel/scout_conn.go
Исходный файл и его история в репозитории.
Instead of a separate cert_probe.go that duplicates the scout's TLS connection logic, measure the cert chain size directly from the same HTTPS connections the scout already makes. Changes: - Extend ScoutConnResult with payloadLen field - Add Write interception to ScoutConn for handshake boundary detection - Scout.learn() now computes cert size (sum of ApplicationData between CCS and first client Write) alongside inter-record durations - Ganger aggregates cert sizes across raids and exposes NoiseParams() via atomic pointer for lock-free reads from proxy goroutines - Proxy reads NoiseParams from Ganger on each handshake instead of probing at startup - Remove cert_probe.go, disk cache, and related config options (noise-cache-path, noise-cache-ttl, noise-probe-count) Falls back to legacy 2500-4700 range until the first scout raid completes (typically within 1-2 seconds of startup).
71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
package doppel
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"io"
|
|
|
|
"github.com/9seconds/mtg/v2/essentials"
|
|
"github.com/9seconds/mtg/v2/mtglib/internal/tls"
|
|
)
|
|
|
|
type ScoutConn struct {
|
|
tls.Conn
|
|
|
|
results *ScoutConnCollected
|
|
rawBuf *bytes.Buffer
|
|
seenCCS bool
|
|
}
|
|
|
|
func (s *ScoutConn) Read(p []byte) (int, error) {
|
|
buf := &bytes.Buffer{}
|
|
|
|
for {
|
|
if n, err := s.rawBuf.Read(p); err == nil {
|
|
return n, nil
|
|
}
|
|
|
|
s.rawBuf.Reset()
|
|
|
|
recordType, length, err := tls.ReadRecord(s.Conn, buf)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
if recordType == tls.TypeChangeCipherSpec {
|
|
s.seenCCS = true
|
|
}
|
|
|
|
s.results.Add(recordType, int(length))
|
|
s.rawBuf.Write([]byte{recordType})
|
|
s.rawBuf.Write(tls.TLSVersion[:])
|
|
|
|
if err := binary.Write(s.rawBuf, binary.BigEndian, uint16(length)); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
if _, err := io.Copy(s.rawBuf, buf); err != nil {
|
|
return 0, err
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *ScoutConn) Write(p []byte) (int, error) {
|
|
if s.seenCCS {
|
|
s.results.MarkWrite()
|
|
}
|
|
|
|
return s.Conn.Write(p)
|
|
}
|
|
|
|
func NewScoutConn(conn essentials.Conn, results *ScoutConnCollected) *ScoutConn {
|
|
rawBuf := &bytes.Buffer{}
|
|
rawBuf.Grow(tls.MaxRecordSize)
|
|
|
|
return &ScoutConn{
|
|
Conn: tls.New(conn, false, false),
|
|
results: results,
|
|
rawBuf: rawBuf,
|
|
}
|
|
}
|