From abde6936e12cce360a91c7c735315f5e7ea725ad Mon Sep 17 00:00:00 2001 From: Matthew Zipkin Date: Fri, 17 Jan 2025 10:04:59 -0500 Subject: [PATCH] use CScheduler for HTTPRPCTimer This removes the dependency on libevent for scheduled events, like re-locking a wallet some time after decryption. --- src/httprpc.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 7a31b1bc41e..5d226cbaf8d 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -9,8 +9,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -27,6 +29,7 @@ #include using http_libevent::HTTPRequest; +using node::NodeContext; using util::SplitString; using util::TrimStringView; @@ -39,22 +42,16 @@ static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\""; class HTTPRPCTimer : public RPCTimerBase { public: - HTTPRPCTimer(struct event_base* eventBase, std::function& func, int64_t millis) : - ev(eventBase, false, func) + HTTPRPCTimer(NodeContext* context, std::function& func, int64_t millis) { - struct timeval tv; - tv.tv_sec = millis/1000; - tv.tv_usec = (millis%1000)*1000; - ev.trigger(&tv); + context->scheduler->scheduleFromNow(func, std::chrono::milliseconds(millis)); } -private: - HTTPEvent ev; }; class HTTPRPCTimerInterface : public RPCTimerInterface { public: - explicit HTTPRPCTimerInterface(struct event_base* _base) : base(_base) + explicit HTTPRPCTimerInterface(const std::any& context) : m_context(std::any_cast(context)) { } const char* Name() override @@ -63,10 +60,10 @@ public: } RPCTimerBase* NewTimer(std::function& func, int64_t millis) override { - return new HTTPRPCTimer(base, func, millis); + return new HTTPRPCTimer(m_context, func, millis); } private: - struct event_base* base; + NodeContext* m_context; }; @@ -371,9 +368,7 @@ bool StartHTTPRPC(const std::any& context) if (g_wallet_init_interface.HasWalletSupport()) { RegisterHTTPHandler("/wallet/", false, handle_rpc); } - struct event_base* eventBase = EventBase(); - assert(eventBase); - httpRPCTimerInterface = std::make_unique(eventBase); + httpRPCTimerInterface = std::make_unique(context); RPCSetTimerInterface(httpRPCTimerInterface.get()); return true; }