mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-19 09:36:43 +00:00
re-org plugins
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
#include "Subscription.h"
|
||||
#include "WSConnection.h"
|
||||
#include "events.h"
|
||||
#include "PluginWritePolicy.h"
|
||||
#include "PluginEventSifter.h"
|
||||
|
||||
|
||||
static const char USAGE[] =
|
||||
@ -35,8 +35,7 @@ void cmd_stream(const std::vector<std::string> &subArgs) {
|
||||
WriterPipeline writer;
|
||||
WSConnection ws(url);
|
||||
Decompressor decomp;
|
||||
|
||||
PluginWritePolicy writePolicy;
|
||||
PluginEventSifter writePolicyPlugin;
|
||||
|
||||
|
||||
ws.onConnect = [&]{
|
||||
@ -68,8 +67,8 @@ void cmd_stream(const std::vector<std::string> &subArgs) {
|
||||
auto &evJson = origJson.at(2);
|
||||
|
||||
std::string okMsg;
|
||||
auto res = writePolicy.acceptEvent(evJson, hoytech::curr_time_s(), EventSourceType::Stream, ws.remoteAddr, okMsg);
|
||||
if (res == WritePolicyResult::Accept) {
|
||||
auto res = writePolicyPlugin.acceptEvent(cfg().relay__writePolicy__plugin, evJson, hoytech::curr_time_s(), EventSourceType::Stream, ws.remoteAddr, okMsg);
|
||||
if (res == PluginEventSifterResult::Accept) {
|
||||
downloadedIds.emplace(from_hex(evJson.at("id").get_string()));
|
||||
writer.write({ std::move(evJson), EventSourceType::Stream, url });
|
||||
} else {
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "DBQuery.h"
|
||||
#include "filters.h"
|
||||
#include "events.h"
|
||||
#include "PluginWritePolicy.h"
|
||||
#include "PluginEventSifter.h"
|
||||
|
||||
|
||||
static const char USAGE[] =
|
||||
@ -84,7 +84,7 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
|
||||
|
||||
WriterPipeline writer;
|
||||
WSConnection ws(url);
|
||||
PluginWritePolicy writePolicy;
|
||||
PluginEventSifter writePolicyPlugin;
|
||||
|
||||
|
||||
ws.reconnect = false;
|
||||
@ -160,8 +160,8 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
|
||||
auto &evJson = msg.at(2);
|
||||
|
||||
std::string okMsg;
|
||||
auto res = writePolicy.acceptEvent(evJson, hoytech::curr_time_s(), EventSourceType::Sync, ws.remoteAddr, okMsg);
|
||||
if (res == WritePolicyResult::Accept) {
|
||||
auto res = writePolicyPlugin.acceptEvent(cfg().relay__writePolicy__plugin, evJson, hoytech::curr_time_s(), EventSourceType::Sync, ws.remoteAddr, okMsg);
|
||||
if (res == PluginEventSifterResult::Accept) {
|
||||
writer.write({ std::move(evJson), EventSourceType::Sync, url });
|
||||
} else {
|
||||
LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg;
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "RelayServer.h"
|
||||
|
||||
#include "PluginWritePolicy.h"
|
||||
#include "PluginEventSifter.h"
|
||||
|
||||
|
||||
void RelayServer::runWriter(ThreadPool<MsgWriter>::Thread &thr) {
|
||||
PluginWritePolicy writePolicy;
|
||||
PluginEventSifter writePolicyPlugin;
|
||||
|
||||
while(1) {
|
||||
auto newMsgs = thr.inbox.pop_all();
|
||||
@ -40,9 +40,9 @@ void RelayServer::runWriter(ThreadPool<MsgWriter>::Thread &thr) {
|
||||
tao::json::value evJson = tao::json::from_string(msg->jsonStr);
|
||||
EventSourceType sourceType = msg->ipAddr.size() == 4 ? EventSourceType::IP4 : EventSourceType::IP6;
|
||||
std::string okMsg;
|
||||
auto res = writePolicy.acceptEvent(evJson, msg->receivedAt, sourceType, msg->ipAddr, okMsg);
|
||||
auto res = writePolicyPlugin.acceptEvent(cfg().relay__writePolicy__plugin, evJson, msg->receivedAt, sourceType, msg->ipAddr, okMsg);
|
||||
|
||||
if (res == WritePolicyResult::Accept) {
|
||||
if (res == PluginEventSifterResult::Accept) {
|
||||
newEvents.emplace_back(std::move(msg->flatStr), std::move(msg->jsonStr), msg->receivedAt, sourceType, std::move(msg->ipAddr), msg);
|
||||
} else {
|
||||
auto *flat = flatbuffers::GetRoot<NostrIndex::Event>(msg->flatStr.data());
|
||||
@ -50,7 +50,7 @@ void RelayServer::runWriter(ThreadPool<MsgWriter>::Thread &thr) {
|
||||
|
||||
LI << "[" << msg->connId << "] write policy blocked event " << eventIdHex << ": " << okMsg;
|
||||
|
||||
sendOKResponse(msg->connId, eventIdHex, res == WritePolicyResult::ShadowReject, okMsg);
|
||||
sendOKResponse(msg->connId, eventIdHex, res == PluginEventSifterResult::ShadowReject, okMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user