fix(udp): read WSJT-X packets that arrive through a relay
A forwarder (W&P, seen in the field in front of MSHV) prepends the origin as
plain text before re-broadcasting:
"127.0.0.1:2237|" + <the original, untouched WSJT-X packet>
That puts the magic 15 bytes in, so every datagram failed on "bad magic
0x3132372e" — those four bytes being ASCII "127." — and an operator running
MSHV behind the relay saw no decodes, no callsigns and no auto-logged QSOs.
No new service type: what follows the header IS a WSJT-X packet, so the parser
and everything downstream apply unchanged, and a separate type would duplicate
decode, status and logged-ADIF handling to strip 15 bytes. ParseWSJT skips the
header instead, which also covers any other relay that wraps traffic this way.
The match is deliberately narrow — the magic must fall within the first 64
bytes AND every byte before it must be printable ASCII. A corrupt or truncated
packet that merely contains those four bytes somewhere is not resurrected into
a QSO; it fails exactly as it did before.
Test data is the real captured datagram, header included.
This commit is contained in:
@@ -56,12 +56,61 @@ type WSJTEvent struct {
|
||||
IsCQ bool // the decode was a CQ call
|
||||
}
|
||||
|
||||
// maxFwdHeader bounds how far into a packet the WSJT-X magic may sit behind a
|
||||
// forwarder's header. The one seen in the field ("127.0.0.1:2237|") is 15 bytes;
|
||||
// 64 leaves room for a longer address without ever scanning a real payload.
|
||||
const maxFwdHeader = 64
|
||||
|
||||
// stripForwarderHeader removes the origin header a UDP relay prepends.
|
||||
//
|
||||
// A relay that re-broadcasts WSJT-X traffic has to say where each datagram came
|
||||
// from, and it does so as plain text in front of the payload:
|
||||
//
|
||||
// "127.0.0.1:2237|" + <the original, untouched WSJT-X packet>
|
||||
//
|
||||
// The magic then sits 15 bytes in, every packet fails on "bad magic", and an
|
||||
// operator running MSHV behind such a relay gets nothing at all. There is no
|
||||
// need for a separate service type: what follows the header IS a WSJT-X packet,
|
||||
// so the whole parser and everything downstream apply unchanged.
|
||||
//
|
||||
// Deliberately narrow. The magic must appear within maxFwdHeader bytes AND
|
||||
// everything before it must be printable ASCII — a truncated or corrupt packet
|
||||
// that happens to contain those four bytes somewhere is not resurrected into a
|
||||
// QSO. Anything else is returned untouched, and still fails as it did.
|
||||
func stripForwarderHeader(pkt []byte) []byte {
|
||||
if len(pkt) < 4 {
|
||||
return pkt
|
||||
}
|
||||
if binary.BigEndian.Uint32(pkt) == wsjtMagic {
|
||||
return pkt // no header — the overwhelmingly common case
|
||||
}
|
||||
limit := len(pkt) - 4
|
||||
if limit > maxFwdHeader {
|
||||
limit = maxFwdHeader
|
||||
}
|
||||
for i := 1; i <= limit; i++ {
|
||||
if binary.BigEndian.Uint32(pkt[i:]) != wsjtMagic {
|
||||
continue
|
||||
}
|
||||
for _, b := range pkt[:i] {
|
||||
if b < 0x20 || b >= 0x7f {
|
||||
return pkt // not a text header — leave it alone
|
||||
}
|
||||
}
|
||||
return pkt[i:]
|
||||
}
|
||||
return pkt
|
||||
}
|
||||
|
||||
// ParseWSJT decodes one UDP packet. Returns ok=false for messages we
|
||||
// don't care about (heartbeat, clears, etc.).
|
||||
func ParseWSJT(pkt []byte) (WSJTEvent, bool, error) {
|
||||
if len(pkt) < 12 {
|
||||
return WSJTEvent{}, false, fmt.Errorf("packet too short")
|
||||
}
|
||||
// A relay (W&P and friends) puts its own origin header in front — skip it so
|
||||
// the packet parses exactly as if it had arrived from WSJT-X directly.
|
||||
pkt = stripForwarderHeader(pkt)
|
||||
r := bytes.NewReader(pkt)
|
||||
var magic, schema, mtype uint32
|
||||
if err := binary.Read(r, binary.BigEndian, &magic); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user