feat(proxy): tcp-режим для xray/sing-box поверх turn
This commit is contained in:
1 parent
e63279db18
commit
f7129099f7
60 files changed
+2953
-135
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package stats
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -67,3 +69,81 @@ func TestStatsEnabledAccumulates(t *testing.T) {
|
||||
t.Fatalf("Counters() = (%d, %d), want (150, 7)", tx, rx)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatByteCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
bytes uint64
|
||||
want string
|
||||
}{
|
||||
{0, "0 B"},
|
||||
{1023, "1023 B"},
|
||||
{1024, "1.0 KiB"},
|
||||
{1024 * 1024, "1.00 MiB"},
|
||||
{2 * 1024 * 1024, "2.00 MiB"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := FormatByteCount(c.bytes)
|
||||
if got != c.want {
|
||||
t.Errorf("FormatByteCount(%d) = %q, want %q", c.bytes, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCountingConnCounts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
c1, c2 := net.Pipe()
|
||||
defer func() { _ = c1.Close() }()
|
||||
defer func() { _ = c2.Close() }()
|
||||
|
||||
st := New(true)
|
||||
conn := &CountingConn{Conn: c1, Stats: st}
|
||||
|
||||
go func() {
|
||||
peer := make([]byte, 4)
|
||||
_, _ = io.ReadFull(c2, peer)
|
||||
_, _ = c2.Write([]byte("pong"))
|
||||
}()
|
||||
|
||||
if _, err := conn.Write([]byte("ping")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buf := make([]byte, 4)
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tx, rx := st.Counters()
|
||||
if tx != 4 || rx != 4 {
|
||||
t.Errorf("tx=%d rx=%d, want 4/4", tx, rx)
|
||||
}
|
||||
}
|
||||
|
||||
// Живость канала подтверждают и служебные кадры транспорта, а UI они врали бы.
|
||||
func TestLivenessRxSeparateFromUserCounters(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := New(true)
|
||||
s.AddRx(100)
|
||||
s.AddTx(50)
|
||||
s.AddWireRx(900)
|
||||
|
||||
tx, rx := s.Counters()
|
||||
if tx != 50 || rx != 100 {
|
||||
t.Errorf("Counters() = %d/%d, want 50/100", tx, rx)
|
||||
}
|
||||
if got := s.LivenessRx(); got != 1000 {
|
||||
t.Errorf("LivenessRx() = %d, want 1000", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddWireRxRespectsDisabled(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := New(false)
|
||||
s.AddWireRx(512)
|
||||
if got := s.LivenessRx(); got != 0 {
|
||||
t.Errorf("LivenessRx() = %d, want 0 when disabled", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user