finish remaining changes

pull/962/head
Jeff Becker 5 years ago
parent abf9544ddc
commit c4f08e5145
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -211,6 +211,10 @@ namespace llarp
bool bool
KeyManager::loadIdentityFromLokid() KeyManager::loadIdentityFromLokid()
{ {
#if defined(_WIN32) || defined(_WIN64)
LogError("service node mode not supported on windows");
return false;
#else
CURL* curl = curl_easy_init(); CURL* curl = curl_easy_init();
if(curl) if(curl)
{ {
@ -307,6 +311,7 @@ namespace llarp
LogError("failed to init curl"); LogError("failed to init curl");
return false; return false;
} }
#endif
} }
} // namespace llarp } // namespace llarp

@ -103,7 +103,7 @@ llarp_ev_add_tun(struct llarp_ev_loop *loop, struct llarp_tun_io *tun)
if(dev) if(dev)
{ {
dev->setup(); dev->setup();
return dev->add_ev(); // start up tun and add to event queue return dev->add_ev(loop); // start up tun and add to event queue
} }
llarp::LogWarn("Loop could not create tun"); llarp::LogWarn("Loop could not create tun");
return false; return false;

@ -542,8 +542,11 @@ namespace libuv
llarp::LogError("failed to start ticker"); llarp::LogError("failed to start ticker");
return false; return false;
} }
#if defined(_WIN32) || defined(_WIN64)
#else
if(uv_fileno((const uv_handle_t*)&m_Handle, &m_UDP->fd)) if(uv_fileno((const uv_handle_t*)&m_Handle, &m_UDP->fd))
return false; return false;
#endif
m_UDP->sendto = &SendTo; m_UDP->sendto = &SendTo;
m_UDP->impl = this; m_UDP->impl = this;
return true; return true;
@ -640,7 +643,8 @@ namespace libuv
uv_poll_t m_Handle; uv_poll_t m_Handle;
uv_check_t m_Ticker; uv_check_t m_Ticker;
}; };
#if defined(_WIN32) || defined(_WIN64)
#else
struct tun_glue : public glue struct tun_glue : public glue
{ {
uv_poll_t m_Handle; uv_poll_t m_Handle;
@ -654,7 +658,7 @@ namespace libuv
{ {
m_Handle.data = this; m_Handle.data = this;
m_Ticker.data = this; m_Ticker.data = this;
readpkt = false; readpkt = false;
} }
~tun_glue() override ~tun_glue() override
@ -784,11 +788,11 @@ namespace libuv
return false; return false;
} }
m_Tun->writepkt = &WritePkt; m_Tun->writepkt = &WritePkt;
m_Tun->impl = this; m_Tun->impl = this;
return true; return true;
} }
}; };
#endif
bool bool
Loop::init() Loop::init()
{ {
@ -801,7 +805,10 @@ namespace libuv
#endif #endif
m_Impl.data = this; m_Impl.data = this;
#if defined(_WIN32) || defined(_WIN64)
#else
uv_loop_configure(&m_Impl, UV_LOOP_BLOCK_SIGNAL, SIGPIPE); uv_loop_configure(&m_Impl, UV_LOOP_BLOCK_SIGNAL, SIGPIPE);
#endif
m_TickTimer.data = this; m_TickTimer.data = this;
m_LogicCaller.data = this; m_LogicCaller.data = this;
uv_async_init(&m_Impl, &m_LogicCaller, [](uv_async_t* h) { uv_async_init(&m_Impl, &m_LogicCaller, [](uv_async_t* h) {
@ -938,14 +945,19 @@ namespace libuv
bool bool
Loop::tun_listen(llarp_tun_io* tun) Loop::tun_listen(llarp_tun_io* tun)
{ {
#if defined(_WIN32) || defined(_WIN64)
(void)tun;
return false;
#else
auto* glue = new tun_glue(tun); auto* glue = new tun_glue(tun);
tun->impl = glue; tun->impl = glue;
if(glue->Init(&m_Impl)) if(glue->Init(&m_Impl))
{ {
return true; return true;
} }
delete glue; delete glue;
return false; return false;
#endif
} }
bool bool

@ -16,13 +16,12 @@ static CRITICAL_SECTION HandlerMtx;
std::list< win32_tun_io* > tun_listeners; std::list< win32_tun_io* > tun_listeners;
void void
begin_tun_loop(int nThreads) begin_tun_loop(int nThreads, llarp_ev_loop* loop)
{ {
kThreadPool = new HANDLE[nThreads]; kThreadPool = new HANDLE[nThreads];
for(int i = 0; i < nThreads; ++i) for(int i = 0; i < nThreads; ++i)
{ {
kThreadPool[i] = kThreadPool[i] = CreateThread(nullptr, 0, &tun_ev_loop, loop, 0, nullptr);
CreateThread(nullptr, 0, &tun_ev_loop, nullptr, 0, nullptr);
} }
llarp::LogInfo("created ", nThreads, " threads for TUN event queue"); llarp::LogInfo("created ", nThreads, " threads for TUN event queue");
poolSize = nThreads; poolSize = nThreads;
@ -74,7 +73,7 @@ win32_tun_io::setup()
// first TUN device gets to set up the event port // first TUN device gets to set up the event port
bool bool
win32_tun_io::add_ev() win32_tun_io::add_ev(llarp_ev_loop* loop)
{ {
if(tun_event_queue == INVALID_HANDLE_VALUE) if(tun_event_queue == INVALID_HANDLE_VALUE)
{ {
@ -85,7 +84,7 @@ win32_tun_io::add_ev()
// threads // threads
tun_event_queue = CreateIoCompletionPort(tunif->tun_fd, nullptr, tun_event_queue = CreateIoCompletionPort(tunif->tun_fd, nullptr,
(ULONG_PTR)this, numCPU * 2); (ULONG_PTR)this, numCPU * 2);
begin_tun_loop(numCPU * 2); begin_tun_loop(numCPU * 2, loop);
} }
else else
CreateIoCompletionPort(tunif->tun_fd, tun_event_queue, (ULONG_PTR)this, 0); CreateIoCompletionPort(tunif->tun_fd, tun_event_queue, (ULONG_PTR)this, 0);
@ -106,7 +105,7 @@ win32_tun_io::do_write(void* data, size_t sz)
pkt->sz = sz; pkt->sz = sz;
pkt->write = true; pkt->write = true;
memset(&pkt->pkt, '\0', sizeof(pkt->pkt)); memset(&pkt->pkt, '\0', sizeof(pkt->pkt));
WriteFile(tunif->tun_fd, data, sz, nullptr, &pkt->pkt); WriteFile(tunif->tun_fd, data, sz, nullptr, p & pkt->pkt);
} }
// while this one is called from the event loop // while this one is called from the event loop
@ -131,9 +130,9 @@ win32_tun_io::read(byte_t* buf, size_t sz)
// and now the event loop itself // and now the event loop itself
extern "C" DWORD FAR PASCAL extern "C" DWORD FAR PASCAL
tun_ev_loop(void* unused) tun_ev_loop(void* u)
{ {
UNREFERENCED_PARAMETER(unused); llarp_ev_loop* logic = static_cast< llarp_ev_loop* >(u);
DWORD size = 0; DWORD size = 0;
OVERLAPPED* ovl = nullptr; OVERLAPPED* ovl = nullptr;
@ -154,9 +153,11 @@ tun_ev_loop(void* unused)
for(const auto& tun : tun_listeners) for(const auto& tun : tun_listeners)
{ {
EnterCriticalSection(&HandlerMtx); EnterCriticalSection(&HandlerMtx);
if(tun->t->tick) logic->call_soon([tun = tun.get()]() {
tun->t->tick(tun->t); if(tun->t->tick)
tun->flush_write(); tun->t->tick(tun->t);
tun->flush_write();
});
LeaveCriticalSection(&HandlerMtx); LeaveCriticalSection(&HandlerMtx);
} }
continue; // let's go at it once more continue; // let's go at it once more
@ -178,8 +179,11 @@ tun_ev_loop(void* unused)
continue; continue;
} }
// EnterCriticalSection(&HandlerMtx); // EnterCriticalSection(&HandlerMtx);
if(ev->t->recvpkt) logic->call_soon([pkt, size, ev]() {
ev->t->recvpkt(ev->t, llarp_buffer_t(pkt->buf, size)); if(ev->t->recvpkt)
ev->t->recvpkt(ev->t, llarp_buffer_t(pkt->buf, size));
delete pkt;
});
ev->read(ev->readbuf, sizeof(ev->readbuf)); ev->read(ev->readbuf, sizeof(ev->readbuf));
// LeaveCriticalSection(&HandlerMtx); // LeaveCriticalSection(&HandlerMtx);
} }
@ -191,11 +195,12 @@ tun_ev_loop(void* unused)
// LeaveCriticalSection(&HandlerMtx); // LeaveCriticalSection(&HandlerMtx);
} }
EnterCriticalSection(&HandlerMtx); EnterCriticalSection(&HandlerMtx);
if(ev->t->tick) logic->call_soon([ev]() {
ev->t->tick(ev->t); if(ev->t->tick)
ev->flush_write(); ev->t->tick(ev->t);
ev->flush_write();
});
LeaveCriticalSection(&HandlerMtx); LeaveCriticalSection(&HandlerMtx);
delete pkt; // don't leak
} }
llarp::LogDebug("exit TUN event loop thread from system managed thread pool"); llarp::LogDebug("exit TUN event loop thread from system managed thread pool");
return 0; return 0;

@ -78,7 +78,7 @@ struct win32_tun_io
// first TUN device gets to set up the event port // first TUN device gets to set up the event port
bool bool
add_ev(); add_ev(llarp_ev_loop* l);
// places data in event queue for kernel to process // places data in event queue for kernel to process
void void

Loading…
Cancel
Save