Compact peer list
Decode six-byte groups as IPv4 plus big-endian port and remove duplicates.
Compact peer list
Decode six-byte groups as IPv4 plus big-endian port and remove duplicates. The implementation is cumulative and must preserve earlier operations.
Observable contract
The harness reads JSON and represents binary data as hexadecimal. Tracker and peer replies are supplied as fixtures to avoid external networking and randomness.
{ "op": "compact-peers", "hex": "7f0000011ae17f0000011ae2" }
produces exactly:
{
"peers": [
["127.0.0.1", 6881],
["127.0.0.1", 6882]
]
}
Emit compact JSON and a final newline. Invalid requests leave stdout empty, include error on stderr, and exit non-zero.
Implementation
Keep binary data as bytes: do not turn hashes, peer IDs, or pieces into text except where the protocol says so. Separate framing, peer state, scheduling, and integrity. Verify lengths and hashes before publishing a piece as complete.
Walk through the fixture by offsets and test fragmentation, duplicate messages, timeouts, and peers advertising inconsistent data. Tests do not use the Internet; connect the same logic to real sockets outside the harness.
Acceptance criteria
- The representative case produces the exact output.
- No unverified data reaches the final file.
- Scheduling is deterministic for the same input.