"WSJT parse error: bad magic 0x3132372e" named neither the sender nor the payload, so there was nothing to act on — even though those four bytes are ASCII "127.", i.e. some program broadcasting an address on a port expecting WSJT-X binary. The line now carries the remote address, the size, a printable preview and a hex dump of the first 96 bytes. Text senders are readable at a glance; a genuinely binary payload still shows its bytes. And it stops after five. The reported case wrote that line about 150 times a second: a permanently misconfigured port would fill the 10 MB rotating log with one repeated sentence and bury every other piece of evidence — the log's whole purpose. The fifth line names the two things worth checking, the sender and the service type. N1MM's parse error goes through the same path; it had no packet detail either.
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package udp
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The diagnostic that matters: a text payload arriving on a WSJT port must be
|
|
// READABLE in the log. "bad magic 0x3132372e" alone told the operator nothing —
|
|
// those four bytes are ASCII "127.", i.e. some program broadcasting an address
|
|
// where WSJT-X binary was expected.
|
|
func TestDescribePacketShowsTextAndHex(t *testing.T) {
|
|
got := describePacket([]byte("127.0.0.1:4532"))
|
|
for _, want := range []string{`14 bytes`, `"127.0.0.1:4532"`, `31 32 37 2e`} {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("describePacket missing %q\ngot: %s", want, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Binary stays inspectable: unprintable bytes become dots in the preview and
|
|
// the hex carries the real values.
|
|
func TestDescribePacketHandlesBinary(t *testing.T) {
|
|
got := describePacket([]byte{0xad, 0xbc, 0xcb, 0xda, 0x00})
|
|
if !strings.Contains(got, `"....."`) || !strings.Contains(got, "ad bc cb da 00") {
|
|
t.Errorf("binary preview wrong: %s", got)
|
|
}
|
|
}
|
|
|
|
// A long datagram is truncated, and says so, rather than dumping a whole packet
|
|
// into the log on every line.
|
|
func TestDescribePacketTruncates(t *testing.T) {
|
|
got := describePacket([]byte(strings.Repeat("A", 300)))
|
|
if !strings.Contains(got, "300 bytes") {
|
|
t.Errorf("lost the real length: %s", got)
|
|
}
|
|
if !strings.Contains(got, "…") {
|
|
t.Errorf("truncation not marked: %s", got)
|
|
}
|
|
if strings.Count(got, "41 ") > 96 {
|
|
t.Errorf("hex not capped: %s", got)
|
|
}
|
|
}
|