Normally when a plugin blocks an event, it will log a message. Especially when using plugins in stream, router, etc, this might be too verbose. In order to silence these logs, return an empty string for msg (or no msg at all).

This commit is contained in:
Doug Hoyte
2023-09-08 17:46:55 -04:00
parent 90494cb8b3
commit b2a128d2f3
5 changed files with 6 additions and 5 deletions

View File

@ -77,4 +77,5 @@ To install:
* If applicable, you should ensure stdout is *line buffered* (for example, in perl use `$|++`). * If applicable, you should ensure stdout is *line buffered* (for example, in perl use `$|++`).
* If events are being rejected with `error: internal error`, then check the strfry logs. The plugin is misconfigured or failing. * If events are being rejected with `error: internal error`, then check the strfry logs. The plugin is misconfigured or failing.
* Normally when a plugin blocks an event, it will log a message. Especially when using plugins in `stream`, `router`, etc, this might be too verbose. In order to silence these logs, return an empty string for `msg` (or no `msg` at all).
* When returning an action of `accept`, it doesn't necessarily guarantee that the event will be accepted. The regular strfry checks are still subsequently applied, such as expiration, deletion, etc. * When returning an action of `accept`, it doesn't necessarily guarantee that the event will be accepted. The regular strfry checks are still subsequently applied, such as expiration, deletion, etc.

View File

@ -187,7 +187,7 @@ struct Router {
if (res == PluginEventSifterResult::Accept) { if (res == PluginEventSifterResult::Accept) {
router->writer.write({ std::move(evJson), EventSourceType::Stream, url }); router->writer.write({ std::move(evJson), EventSourceType::Stream, url });
} else { } else {
LI << groupName << " / " << url << " : pluginDown blocked event " << evJson.at("id").get_string() << ": " << okMsg; if (okMsg.size()) LI << groupName << " / " << url << " : pluginDown blocked event " << evJson.at("id").get_string() << ": " << okMsg;
} }
} }
@ -212,7 +212,7 @@ struct Router {
if (c.ws) c.ws->send(responseStr.data(), responseStr.size(), uWS::OpCode::TEXT, nullptr, nullptr, true); if (c.ws) c.ws->send(responseStr.data(), responseStr.size(), uWS::OpCode::TEXT, nullptr, nullptr, true);
} }
} else { } else {
LI << groupName << " : pluginUp blocked event " << evJson.at("id").get_string() << ": " << okMsg; if (okMsg.size()) LI << groupName << " : pluginUp blocked event " << evJson.at("id").get_string() << ": " << okMsg;
} }
} }
}; };

View File

@ -72,7 +72,7 @@ void cmd_stream(const std::vector<std::string> &subArgs) {
downloadedIds.emplace(from_hex(evJson.at("id").get_string())); downloadedIds.emplace(from_hex(evJson.at("id").get_string()));
writer.write({ std::move(evJson), EventSourceType::Stream, url }); writer.write({ std::move(evJson), EventSourceType::Stream, url });
} else { } else {
LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg; if (okMsg.size()) LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg;
} }
} else { } else {
LW << "Unexpected EVENT"; LW << "Unexpected EVENT";

View File

@ -164,7 +164,7 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
if (res == PluginEventSifterResult::Accept) { if (res == PluginEventSifterResult::Accept) {
writer.write({ std::move(evJson), EventSourceType::Sync, url }); writer.write({ std::move(evJson), EventSourceType::Sync, url });
} else { } else {
LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg; if (okMsg.size()) LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg;
} }
} else if (msg.at(0) == "EOSE") { } else if (msg.at(0) == "EOSE") {
inFlightDown = false; inFlightDown = false;

View File

@ -48,7 +48,7 @@ void RelayServer::runWriter(ThreadPool<MsgWriter>::Thread &thr) {
auto *flat = flatbuffers::GetRoot<NostrIndex::Event>(msg->flatStr.data()); auto *flat = flatbuffers::GetRoot<NostrIndex::Event>(msg->flatStr.data());
auto eventIdHex = to_hex(sv(flat->id())); auto eventIdHex = to_hex(sv(flat->id()));
LI << "[" << msg->connId << "] write policy blocked event " << eventIdHex << ": " << okMsg; if (okMsg.size()) LI << "[" << msg->connId << "] write policy blocked event " << eventIdHex << ": " << okMsg;
sendOKResponse(msg->connId, eventIdHex, res == PluginEventSifterResult::ShadowReject, okMsg); sendOKResponse(msg->connId, eventIdHex, res == PluginEventSifterResult::ShadowReject, okMsg);
} }