Write the raw response bytes (which we couldn't parse cleanly) to a temp file. Returns the file path on success, empty string on failure. Used for the "compressed response" path — see on_request_failed().
| 224 | // temp file. Returns the file path on success, empty string on failure. |
| 225 | // Used for the "compressed response" path — see on_request_failed(). |
| 226 | static std::string write_response_temp_file(const RNS::Bytes& request_id, |
| 227 | const RNS::Bytes& payload) { |
| 228 | std::string filename = "/tmp/nomadnet_"; |
| 229 | filename += request_id.toHex(); |
| 230 | filename += ".bin"; |
| 231 | FILE* f = fopen(filename.c_str(), "wb"); |
| 232 | if (!f) return std::string(); |
| 233 | if (payload.size() > 0) { |
| 234 | fwrite(payload.data(), 1, payload.size(), f); |
| 235 | } |
| 236 | fclose(f); |
| 237 | return filename; |
| 238 | } |
| 239 | |
| 240 | void on_response(const RNS::RequestReceipt& receipt) { |
| 241 | const RNS::Bytes request_id = receipt.get_request_id(); |
no test coverage detected