mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-18 09:17:12 +00:00
bugfix: handle malformed/old-format negentropy messages gracefully
This commit is contained in:
@ -126,7 +126,14 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
|
|||||||
if (msg.at(0) == "NEG-MSG") {
|
if (msg.at(0) == "NEG-MSG") {
|
||||||
uint64_t origHaves = have.size(), origNeeds = need.size();
|
uint64_t origHaves = have.size(), origNeeds = need.size();
|
||||||
|
|
||||||
auto neMsg = ne.reconcile(from_hex(msg.at(2).get_string()), have, need);
|
std::optional<std::string> neMsg;
|
||||||
|
|
||||||
|
try {
|
||||||
|
neMsg = ne.reconcile(from_hex(msg.at(2).get_string()), have, need);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
LE << "Unable to parse negentropy message from relay: " << e.what();
|
||||||
|
doExit(1);
|
||||||
|
}
|
||||||
|
|
||||||
totalHaves += have.size() - origHaves;
|
totalHaves += have.size() - origHaves;
|
||||||
totalNeeds += need.size() - origNeeds;
|
totalNeeds += need.size() - origNeeds;
|
||||||
|
@ -111,7 +111,23 @@ void RelayServer::runNegentropy(ThreadPool<MsgNegentropy>::Thread &thr) {
|
|||||||
|
|
||||||
view->ne.seal();
|
view->ne.seal();
|
||||||
|
|
||||||
auto resp = view->ne.reconcile(view->initialMsg);
|
std::string resp;
|
||||||
|
|
||||||
|
try {
|
||||||
|
resp = view->ne.reconcile(view->initialMsg);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
LI << "[" << sub.connId << "] Error parsing negentropy initial message: " << e.what();
|
||||||
|
|
||||||
|
sendToConn(sub.connId, tao::json::to_string(tao::json::value::array({
|
||||||
|
"NEG-ERR",
|
||||||
|
sub.subId.str(),
|
||||||
|
"PROTOCOL-ERROR"
|
||||||
|
})));
|
||||||
|
|
||||||
|
views.removeView(sub.connId, sub.subId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
view->initialMsg = "";
|
view->initialMsg = "";
|
||||||
|
|
||||||
sendToConn(sub.connId, tao::json::to_string(tao::json::value::array({
|
sendToConn(sub.connId, tao::json::to_string(tao::json::value::array({
|
||||||
@ -150,15 +166,30 @@ void RelayServer::runNegentropy(ThreadPool<MsgNegentropy>::Thread &thr) {
|
|||||||
"CLOSED"
|
"CLOSED"
|
||||||
})));
|
})));
|
||||||
|
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!view->ne.sealed) {
|
if (!view->ne.sealed) {
|
||||||
sendNoticeError(msg->connId, "negentropy error: got NEG-MSG before NEG-OPEN complete");
|
sendNoticeError(msg->connId, "negentropy error: got NEG-MSG before NEG-OPEN complete");
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto resp = view->ne.reconcile(msg->negPayload);
|
std::string resp;
|
||||||
|
|
||||||
|
try {
|
||||||
|
resp = view->ne.reconcile(msg->negPayload);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
LI << "[" << msg->connId << "] Error parsing negentropy continuation message: " << e.what();
|
||||||
|
|
||||||
|
sendToConn(msg->connId, tao::json::to_string(tao::json::value::array({
|
||||||
|
"NEG-ERR",
|
||||||
|
msg->subId.str(),
|
||||||
|
"PROTOCOL-ERROR"
|
||||||
|
})));
|
||||||
|
|
||||||
|
views.removeView(msg->connId, msg->subId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
sendToConn(msg->connId, tao::json::to_string(tao::json::value::array({
|
sendToConn(msg->connId, tao::json::to_string(tao::json::value::array({
|
||||||
"NEG-MSG",
|
"NEG-MSG",
|
||||||
|
Reference in New Issue
Block a user