frame size limit for negentropy syncs

This commit is contained in:
Doug Hoyte
2023-06-11 23:44:33 -04:00
parent c18ff8099c
commit a3b4e7baf5
4 changed files with 9 additions and 5 deletions

2
golpe

Submodule golpe updated: 79ae8de092...3b61bd2d17

View File

@ -79,7 +79,7 @@ class WSConnection {
}); });
hubGroup->onDisconnection([&](uWS::WebSocket<uWS::CLIENT> *ws, int code, char *message, size_t length) { hubGroup->onDisconnection([&](uWS::WebSocket<uWS::CLIENT> *ws, int code, char *message, size_t length) {
LI << "Disconnected"; LI << "Disconnected: " << code << "/" << (message ? std::string_view(message, length) : "-");
if (ws == currWs) { if (ws == currWs) {
currWs = nullptr; currWs = nullptr;

View File

@ -16,11 +16,12 @@
static const char USAGE[] = static const char USAGE[] =
R"( R"(
Usage: Usage:
sync <url> [--filter=<filter>] [--dir=<dir>] sync <url> [--filter=<filter>] [--dir=<dir>] [--frame-size-limit=<frame-size-limit>]
Options: Options:
--filter=<filter> Nostr filter (either single filter object or array of filters) --filter=<filter> Nostr filter (either single filter object or array of filters)
--dir=<dir> Direction: both, down, up, none [default: both] --dir=<dir> Direction: both, down, up, none [default: both]
--frame-size-limit=<frame-size-limit> Limit outgoing negentropy message size (default 60k, 0 for no limit)
)"; )";
@ -36,6 +37,9 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
std::string dir = args["--dir"] ? args["--dir"].asString() : "both"; std::string dir = args["--dir"] ? args["--dir"].asString() : "both";
if (dir != "both" && dir != "up" && dir != "down" && dir != "none") throw herr("invalid direction: ", dir, ". Should be one of both/up/down/none"); if (dir != "both" && dir != "up" && dir != "down" && dir != "none") throw herr("invalid direction: ", dir, ". Should be one of both/up/down/none");
uint64_t frameSizeLimit = 0;
if (args["--frame-size-limit"]) frameSizeLimit = args["--frame-size-limit"].asLong();
const uint64_t idSize = 16; const uint64_t idSize = 16;
const bool doUp = dir == "both" || dir == "up"; const bool doUp = dir == "both" || dir == "up";
const bool doDown = dir == "both" || dir == "down"; const bool doDown = dir == "both" || dir == "down";
@ -80,7 +84,7 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
ws.reconnect = false; ws.reconnect = false;
ws.onConnect = [&]{ ws.onConnect = [&]{
auto neMsg = to_hex(ne.initiate()); auto neMsg = to_hex(ne.initiate(frameSizeLimit));
ws.send(tao::json::to_string(tao::json::value::array({ ws.send(tao::json::to_string(tao::json::value::array({
"NEG-OPEN", "NEG-OPEN",
"N", "N",