Implement canonical JSON encoding for messages as per the format specified in the
protocol.
Implement message parsing, defragmentation, and canonical JSON encoding and decod-
ing. On receiving data from a connected node, decode and parse it as a JSON string.
If the received message is not a valid JSON or doesn’t parse into one of the valid mes-
sage types, send an "error" message with error name INVALID_FORMAT to the node.
Note that a single message may get split across different packets, e.g. you may re-
ceive "type":"ge and tpeers" in separate messages. So you should defragment such
JSON strings. Alternatively, a single packet could contain multiple messages (separated
by "\n") and your node should be able to separate them. Note that JSON strings you
receive may not be in canonical form, but they are valid messages nevertheless.
Scope
Decide on internal data structures
Implement encoding to canonical JSON from internal data structure
Implement decoding to canonical JSON from internal data structure
Note
Try leverage TS support in JSON.parse()
This seems like a larger task, maybe we can divide it, but I feel like making two different people work on the same problem from two different angles may lead to confusion
Description
Implement canonical JSON encoding for messages as per the format specified in the protocol. Implement message parsing, defragmentation, and canonical JSON encoding and decod- ing. On receiving data from a connected node, decode and parse it as a JSON string. If the received message is not a valid JSON or doesn’t parse into one of the valid mes- sage types, send an "error" message with error name INVALID_FORMAT to the node. Note that a single message may get split across different packets, e.g. you may re- ceive "type":"ge and tpeers" in separate messages. So you should defragment such JSON strings. Alternatively, a single packet could contain multiple messages (separated by "\n") and your node should be able to separate them. Note that JSON strings you receive may not be in canonical form, but they are valid messages nevertheless.
Scope
Note
Try leverage TS support in
JSON.parse()
This seems like a larger task, maybe we can divide it, but I feel like making two different people work on the same problem from two different angles may lead to confusion