attempt fix for libunbound on win32

* run unbound stuff in another thread because LOL windows
* because unbound runs in another thread callbacks for libunbound need to be wrapped in a deferred call so they are done in the logic thread
* bump sqlite3 dep because it's gone, repin hash.
pull/1324/head
Jeff Becker 4 years ago
parent 6f3d881a0f
commit 4bb214eba0
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -25,11 +25,11 @@ set(UNBOUND_SOURCE unbound-${UNBOUND_VERSION}.tar.gz)
set(UNBOUND_HASH SHA256=b73677c21a71cf92f15cc8cfe76a3d875e40f65b6150081c39620b286582d536
CACHE STRING "unbound source hash")
set(SQLITE3_VERSION 3320200 CACHE STRING "sqlite3 version")
set(SQLITE3_VERSION 3320300 CACHE STRING "sqlite3 version")
set(SQLITE3_MIRROR ${LOCAL_MIRROR} https://www.sqlite.org/2020
CACHE STRING "sqlite3 download mirror(s)")
set(SQLITE3_SOURCE sqlite-autoconf-${SQLITE3_VERSION}.tar.gz)
set(SQLITE3_HASH SHA512=5b551a1366ce4fd5dfaa687e5021194d34315935b26dd7d71f8abc9935d03c3caea323263a8330fb42038c487cd399e95de68e451cc26d573f852f219c00a02f
set(SQLITE3_HASH SHA512=add0ef47c059be0a75add7ab4fe52b2fbd4060cacbf1cbb93f1b4007cdeb8fc92256b1aadc224c4839e733fb868e56d9d73dd33c56a6f66180d1ff001d8d275e
CACHE STRING "sqlite3 source hash")
set(SODIUM_VERSION 1.0.18 CACHE STRING "libsodium version")

@ -27,23 +27,45 @@ namespace llarp::dns
void
UnboundResolver::DeregisterPollFD()
{
#ifdef _WIN32
runnerThread->join();
#else
eventLoop->deregister_poll_fd_readable(ub_fd(unboundContext));
#endif
}
void
UnboundResolver::RegisterPollFD()
{
#ifdef _WIN32
runnerThread = std::make_unique<std::thread>([self = shared_from_this()]() {
while (self->started)
{
ub_wait(self->unboundContext);
}
});
#else
eventLoop->register_poll_fd_readable(
ub_fd(unboundContext), [=]() { ub_process(unboundContext); });
#endif
}
UnboundResolver::UnboundResolver(
llarp_ev_loop_ptr eventLoop, ReplyFunction replyFunc, FailFunction failFunc)
UnboundResolver::UnboundResolver(llarp_ev_loop_ptr loop, ReplyFunction reply, FailFunction fail)
: unboundContext(nullptr)
, started(false)
, eventLoop(eventLoop)
, replyFunc(replyFunc)
, failFunc(failFunc)
, eventLoop(loop)
#ifdef _WIN32
// on win32 we use another thread for io because LOL windows
, replyFunc([loop, reply](auto source, auto buf) {
loop->call_soon([source, buf, reply]() { reply(source, buf); });
})
, failFunc([loop, fail](auto source, auto message) {
loop->call_soon([source, message, fail]() { fail(source, message); });
})
#else
, replyFunc(reply)
, failFunc(fail)
#endif
{
}
@ -99,9 +121,8 @@ namespace llarp::dns
{
return false;
}
started = true;
RegisterPollFD();
return true;
}
@ -126,8 +147,6 @@ namespace llarp::dns
return;
}
started = true;
const auto& q = msg.questions[0];
auto* lookup = new PendingUnboundLookup{weak_from_this(), msg, source};
int err = ub_resolve_async(

@ -11,6 +11,10 @@
#include <dns/message.hpp>
#ifdef _WIN32
#include <thread>
#endif
namespace llarp::dns
{
using ReplyFunction = std::function<void(SockAddr source, std::vector<byte_t> buf)>;
@ -20,8 +24,12 @@ namespace llarp::dns
{
private:
ub_ctx* unboundContext;
#ifdef _WIN32
/// windows needs to run as blocking in another thread to work at all becuase LOL windows
std::unique_ptr<std::thread> runnerThread;
#endif
bool started;
std::atomic<bool> started;
llarp_ev_loop_ptr eventLoop;
ReplyFunction replyFunc;

@ -4,6 +4,7 @@
#include <thread>
#include <shared_mutex>
#include <mutex>
#include <condition_variable>
#include <optional>
#include "annotations.hpp"

Loading…
Cancel
Save