Parse the msgpack request payload sent by rnpath: ["table"|"rates", destination_hash_or_nil, max_hops_or_nil] rnpath always sends a 2- or 3-element array; the trailing slots may be nil (Python None) when the user did not pass a filter. Returns false on any malformed input; the handler then sends no response.
| 3963 | // (Python None) when the user did not pass a filter. Returns false on any |
| 3964 | // malformed input; the handler then sends no response. |
| 3965 | static bool remote_path_parse_request(const Bytes& data, RemotePathRequest& out) { |
| 3966 | if (!data || data.size() == 0) return false; |
| 3967 | MsgPack::Unpacker u; |
| 3968 | u.feed(data.data(), data.size()); |
| 3969 | |
| 3970 | if (!u.isArray()) { |
| 3971 | TRACE("remote_path_parse_request: Data is not array of elements"); |
| 3972 | return false; |
| 3973 | } |
| 3974 | size_t n = u.unpackArraySize(); |
| 3975 | if (n < 1) { |
| 3976 | TRACE("remote_path_parse_request: No elements in data array"); |
| 3977 | return false; |
| 3978 | } |
| 3979 | |
| 3980 | // Element 0: command (required) |
| 3981 | if (!u.isStr()) { |
| 3982 | TRACE("remote_path_parse_request: Command element is not a string"); |
| 3983 | return false; |
| 3984 | } |
| 3985 | if (!u.deserialize(out.command)) { |
| 3986 | TRACE("remote_path_parse_request: Failed to deseriaize command element"); |
| 3987 | return false; |
| 3988 | } |
| 3989 | |
| 3990 | // Element 1: destination_hash (optional, may be nil) |
| 3991 | if (n >= 2) { |
| 3992 | if (u.isNil()) { |
| 3993 | u.unpackNil(); |
| 3994 | } else if (u.isBin()) { |
| 3995 | MsgPack::bin_t<uint8_t> ph; |
| 3996 | if (!u.deserialize(ph)) return false; |
| 3997 | out.dest_hash = Bytes(ph.data(), ph.size()); |
| 3998 | } else { |
| 3999 | TRACE("remote_path_parse_request: Failed to deseriaize destination_hash element"); |
| 4000 | return false; |
| 4001 | } |
| 4002 | } |
| 4003 | |
| 4004 | // Element 2: max_hops (optional, may be nil) |
| 4005 | if (n >= 3) { |
| 4006 | if (u.isNil()) { |
| 4007 | u.unpackNil(); |
| 4008 | } else if (u.isUInt() || u.isInt()) { |
| 4009 | uint32_t hops = 0; |
| 4010 | if (!u.deserialize(hops)) return false; |
| 4011 | out.max_hops = hops; |
| 4012 | out.max_hops_present = true; |
| 4013 | } else { |
| 4014 | TRACE("remote_path_parse_request: Failed to deseriaize max_hops element"); |
| 4015 | return false; |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | return true; |
| 4020 | } |
| 4021 | |
| 4022 | // Packs one path-table entry as a 6-key map. Insertion order matches |
no test coverage detected