fmr binds two IPv4 addresses. connFor picked whichever socket of the right family came first in the bind list, so a downtrain for a session established on .150 went out from .151 — and every packet was dropped by the client's NAT, which has no mapping for that pair. tcpdump on the server showed all 50 leaving; the client saw none. Read as "100% downstream loss", which is the worst kind of wrong: a confident measurement of something that never happened. Sessions now record which of our own bound addresses received their traffic, and granted sends (and delayed echo) go back out through that socket. The fallback to a family match is kept for the case where nothing has been received yet, and the test pins both paths — a single-homed lab can never reproduce this. Also: the client-side halves of the same work — anonymizer (core-privacy), local run archive with retention (core-archive), upload client, and the app's settings and history screens. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
// SPDX-FileCopyrightText: 2026 Echolot contributors
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package tcpecho
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/json"
|
|
"net"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Plain echo must be server-speaks-first: a client that sends nothing still
|
|
// gets the greeting (via the peek timeout), then its bytes are echoed.
|
|
func TestPlainEchoServerSpeaksFirst(t *testing.T) {
|
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer ln.Close()
|
|
go (&Server{}).Serve(ln)
|
|
|
|
c, err := net.Dial("tcp", ln.Addr().String())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer c.Close()
|
|
c.SetDeadline(time.Now().Add(3 * time.Second))
|
|
|
|
line, err := bufio.NewReader(c).ReadBytes('\n')
|
|
if err != nil {
|
|
t.Fatalf("no greeting: %v", err)
|
|
}
|
|
var g struct {
|
|
TLS bool `json:"tls"`
|
|
Src string `json:"observed_src"`
|
|
}
|
|
if err := json.Unmarshal(line, &g); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if g.TLS {
|
|
t.Fatal("plain connection reported tls=true")
|
|
}
|
|
if g.Src == "" {
|
|
t.Fatal("greeting missing observed_src")
|
|
}
|
|
c.Write([]byte("xyz"))
|
|
buf := make([]byte, 3)
|
|
if _, err := c.Read(buf); err != nil || string(buf) != "xyz" {
|
|
t.Fatalf("echo failed: %q %v", buf, err)
|
|
}
|
|
}
|