mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
commit
a63397855c
@ -23,9 +23,9 @@ struct dnsd_context;
|
||||
struct dns_tracker
|
||||
{
|
||||
// uint c_responses;
|
||||
uint c_requests;
|
||||
uint32_t c_requests;
|
||||
// request has to be a pointer
|
||||
std::unordered_map< uint, std::unique_ptr< dnsc_answer_request > >
|
||||
std::unordered_map< uint32_t, std::unique_ptr< dnsc_answer_request > >
|
||||
client_request;
|
||||
// FIXME: support multiple dns server contexts
|
||||
dnsd_context *dnsd;
|
||||
|
@ -145,7 +145,7 @@ extern "C"
|
||||
int mode;
|
||||
#endif
|
||||
#if defined(Windows)
|
||||
OVERLAPPED ovl;
|
||||
OVERLAPPED ovl[2];
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -228,7 +228,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
|
||||
|
||||
// FIXME: only handling one atm
|
||||
dns_msg_question *question = nullptr;
|
||||
for(uint i = 0; i < hdr->qdCount; i++)
|
||||
for(uint32_t i = 0; i < hdr->qdCount; i++)
|
||||
{
|
||||
question = decode_question((const char *)castBuf);
|
||||
llarp::LogDebug("Read a question");
|
||||
@ -241,7 +241,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
|
||||
// FIXME: only handling one atm
|
||||
std::vector< dns_msg_answer * > answers;
|
||||
dns_msg_answer *answer = nullptr;
|
||||
for(uint i = 0; i < hdr->anCount; i++)
|
||||
for(uint32_t i = 0; i < hdr->anCount; i++)
|
||||
{
|
||||
answer = decode_answer((const char *)castBuf);
|
||||
answers.push_back(answer);
|
||||
@ -275,7 +275,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
|
||||
|
||||
// handle authority records (usually no answers with these, so we'll just
|
||||
// stomp) usually NS records tho
|
||||
for(uint i = 0; i < hdr->nsCount; i++)
|
||||
for(uint32_t i = 0; i < hdr->nsCount; i++)
|
||||
{
|
||||
answer = decode_answer((const char *)castBuf);
|
||||
// answers.push_back(answer);
|
||||
@ -602,7 +602,7 @@ llarp_host_resolved(dnsc_answer_request *const request)
|
||||
dns_tracker *tracker = (dns_tracker *)request->context->tracker;
|
||||
auto val = std::find_if(
|
||||
tracker->client_request.begin(), tracker->client_request.end(),
|
||||
[request](std::pair< const uint, std::unique_ptr< dnsc_answer_request > >
|
||||
[request](std::pair< const uint32_t, std::unique_ptr< dnsc_answer_request > >
|
||||
&element) { return element.second.get() == request; });
|
||||
if(val != tracker->client_request.end())
|
||||
{
|
||||
|
@ -71,7 +71,7 @@ write404_dnss_response(const struct sockaddr *from,
|
||||
put16bits(write_buffer, 1); // rdLength
|
||||
*write_buffer++ = 0; // write a null byte
|
||||
|
||||
uint out_bytes = write_buffer - bufferBegin;
|
||||
uint32_t out_bytes = write_buffer - bufferBegin;
|
||||
llarp::LogDebug("Sending 404, ", out_bytes, " bytes");
|
||||
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
|
||||
request->sendto_hook(request->user, from, buf, out_bytes);
|
||||
@ -140,7 +140,7 @@ writecname_dnss_response(std::string cname, const struct sockaddr *from,
|
||||
*write_buffer++ = 0;
|
||||
*write_buffer++ = 1;
|
||||
|
||||
uint out_bytes = write_buffer - bufferBegin;
|
||||
uint32_t out_bytes = write_buffer - bufferBegin;
|
||||
llarp::LogDebug("Sending cname, ", out_bytes, " bytes");
|
||||
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
|
||||
request->sendto_hook(request->user, from, buf, out_bytes);
|
||||
@ -180,7 +180,7 @@ writesend_dnss_revresponse(std::string reverse, const struct sockaddr *from,
|
||||
put16bits(write_buffer, reverse.length() + 2); // rdLength
|
||||
code_domain(write_buffer, reverse);
|
||||
|
||||
uint out_bytes = write_buffer - bufferBegin;
|
||||
uint32_t out_bytes = write_buffer - bufferBegin;
|
||||
llarp::LogDebug("Sending reverse: ", reverse, " ", out_bytes, " bytes");
|
||||
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
|
||||
request->sendto_hook(request->user, from, buf, out_bytes);
|
||||
@ -243,7 +243,7 @@ writesend_dnss_response(struct sockaddr *hostRes, const struct sockaddr *from,
|
||||
*write_buffer++ = ip[2];
|
||||
*write_buffer++ = ip[3];
|
||||
|
||||
uint out_bytes = write_buffer - bufferBegin;
|
||||
uint32_t out_bytes = write_buffer - bufferBegin;
|
||||
llarp::LogDebug("Sending found, ", out_bytes, " bytes");
|
||||
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
|
||||
request->sendto_hook(request->user, from, buf, out_bytes);
|
||||
|
@ -17,25 +17,17 @@ namespace llarp
|
||||
// we receive queued data in the OVERLAPPED data field,
|
||||
// much like the pipefds in the UNIX kqueue and loonix
|
||||
// epoll handles
|
||||
WSAOVERLAPPED portfd;
|
||||
size_t iosz;
|
||||
WSAOVERLAPPED portfd[2];
|
||||
|
||||
udp_listener(SOCKET fd, llarp_udp_io* u) : ev_io(fd), udp(u)
|
||||
{
|
||||
memset((void*)&portfd, 0, sizeof(WSAOVERLAPPED));
|
||||
memset((void*)&portfd[0], 0, sizeof(WSAOVERLAPPED)*2);
|
||||
};
|
||||
|
||||
~udp_listener()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
getData(void* buf, size_t sz, size_t ret)
|
||||
{
|
||||
iosz = ret;
|
||||
return read(buf, sz);
|
||||
}
|
||||
|
||||
virtual int
|
||||
read(void* buf, size_t sz)
|
||||
{
|
||||
@ -47,7 +39,7 @@ namespace llarp
|
||||
// WSARecvFrom
|
||||
llarp::LogDebug("read ", sz, " bytes into socket");
|
||||
int ret = ::WSARecvFrom(std::get< SOCKET >(fd), &wbuf, 1, nullptr, &flags,
|
||||
addr, &slen, &portfd, nullptr);
|
||||
addr, &slen, &portfd[0], nullptr);
|
||||
// 997 is the error code for queued ops
|
||||
int s_errno = ::WSAGetLastError();
|
||||
if(ret && s_errno != 997)
|
||||
@ -55,8 +47,10 @@ namespace llarp
|
||||
llarp::LogWarn("recv socket error ", s_errno);
|
||||
return -1;
|
||||
}
|
||||
// get the _real_ payload size from tick()
|
||||
udp->recvfrom(udp, addr, buf, iosz);
|
||||
/*if (sz > EV_READ_BUF_SZ)
|
||||
return -1;*/
|
||||
|
||||
udp->recvfrom(udp, addr, buf, sz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -79,7 +73,7 @@ namespace llarp
|
||||
// WSASendTo
|
||||
llarp::LogDebug("write ", sz, " bytes into socket");
|
||||
ssize_t sent = ::WSASendTo(std::get< SOCKET >(fd), &wbuf, 1, nullptr, 0,
|
||||
to, slen, &portfd, nullptr);
|
||||
to, slen, &portfd[1], nullptr);
|
||||
int s_errno = ::WSAGetLastError();
|
||||
if(sent && s_errno != 997)
|
||||
{
|
||||
@ -94,7 +88,7 @@ namespace llarp
|
||||
{
|
||||
llarp_tun_io* t;
|
||||
device* tunif;
|
||||
OVERLAPPED* tun_async;
|
||||
OVERLAPPED* tun_async[2];
|
||||
tun(llarp_tun_io* tio)
|
||||
: ev_io(INVALID_HANDLE_VALUE)
|
||||
, t(tio)
|
||||
@ -123,7 +117,7 @@ namespace llarp
|
||||
bool
|
||||
do_write(void* data, size_t sz)
|
||||
{
|
||||
return WriteFile(std::get< HANDLE >(fd), data, sz, nullptr, tun_async);
|
||||
return WriteFile(std::get< HANDLE >(fd), data, sz, nullptr, tun_async[1]);
|
||||
}
|
||||
|
||||
int
|
||||
@ -159,7 +153,8 @@ namespace llarp
|
||||
}
|
||||
|
||||
fd = tunif->tun_fd;
|
||||
tun_async = &tunif->ovl;
|
||||
tun_async[0] = &tunif->ovl[0];
|
||||
tun_async[1] = &tunif->ovl[1];
|
||||
if(std::get< HANDLE >(fd) == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
@ -222,7 +217,7 @@ struct llarp_win32_loop : public llarp_ev_loop
|
||||
{
|
||||
llarp::LogDebug("size: ", iolen, "\tev_id: ", ev_id,
|
||||
"\tqdata: ", qdata);
|
||||
ev->getData(readbuf, sizeof(readbuf), iolen);
|
||||
ev->read(readbuf, iolen);
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
@ -262,7 +257,7 @@ struct llarp_win32_loop : public llarp_ev_loop
|
||||
if(ev && !ev->fd.valueless_by_exception())
|
||||
{
|
||||
llarp::LogInfo("size: ", iolen, "\tev_id: ", ev_id, "\tqdata: ", qdata);
|
||||
ev->getData(readbuf, sizeof(readbuf), iolen);
|
||||
ev->read(readbuf, sizeof(readbuf));
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
@ -381,7 +376,7 @@ struct llarp_win32_loop : public llarp_ev_loop
|
||||
return false;
|
||||
}
|
||||
::ReadFile((HANDLE)std::get< 0 >(ev->fd), &buf, 1024, nullptr,
|
||||
&udp->portfd);
|
||||
&udp->portfd[0]);
|
||||
break;
|
||||
case 1:
|
||||
t = dynamic_cast< llarp::tun* >(ev);
|
||||
@ -391,7 +386,7 @@ struct llarp_win32_loop : public llarp_ev_loop
|
||||
delete ev;
|
||||
return false;
|
||||
}
|
||||
::ReadFile(std::get< 1 >(ev->fd), &buf, 1024, nullptr, t->tun_async);
|
||||
::ReadFile(std::get< 1 >(ev->fd), &buf, 1024, nullptr, t->tun_async[0]);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
@ -685,7 +685,7 @@ llarp_router::Run()
|
||||
{
|
||||
llarp::LogInfo("Found adapter for public address");
|
||||
}
|
||||
if(!a.isPrivate())
|
||||
if(!llarp::IsBogon(*a.addr6()))
|
||||
{
|
||||
llarp::LogInfo("Loading Addr: ", a, " into our RC");
|
||||
_rc.addrs.push_back(addr);
|
||||
|
@ -18,12 +18,6 @@
|
||||
#include <llarp/linux/netns.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <windows.h>
|
||||
extern "C" void
|
||||
SetThreadName(DWORD dwThreadID, LPCSTR szThreadName);
|
||||
#endif
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace thread
|
||||
@ -43,8 +37,6 @@ namespace llarp
|
||||
pthread_set_name_np(pthread_self(), name);
|
||||
#elif(__linux__) || (__MINGW32__)
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
#elif defined(_MSC_VER)
|
||||
SetThreadName(GetCurrentThreadId(), name);
|
||||
#endif
|
||||
}
|
||||
for(;;)
|
||||
|
4
vendor/libtuntap-master/tuntap-windows.c
vendored
4
vendor/libtuntap-master/tuntap-windows.c
vendored
@ -394,7 +394,7 @@ tuntap_read(struct device *dev, void *buf, size_t size)
|
||||
{
|
||||
DWORD len;
|
||||
|
||||
if(ReadFile(dev->tun_fd, buf, (DWORD)size, &len, &dev->ovl) == 0)
|
||||
if(ReadFile(dev->tun_fd, buf, (DWORD)size, &len, &dev->ovl[0]) == 0)
|
||||
{
|
||||
int errcode = GetLastError();
|
||||
|
||||
@ -415,7 +415,7 @@ tuntap_write(struct device *dev, void *buf, size_t size)
|
||||
{
|
||||
DWORD len;
|
||||
|
||||
if(WriteFile(dev->tun_fd, buf, (DWORD)size, &len, &dev->ovl) == 0)
|
||||
if(WriteFile(dev->tun_fd, buf, (DWORD)size, &len, &dev->ovl[1]) == 0)
|
||||
{
|
||||
int errcode = GetLastError();
|
||||
|
||||
|
2
vendor/libtuntap-master/tuntap.cpp
vendored
2
vendor/libtuntap-master/tuntap.cpp
vendored
@ -69,7 +69,7 @@ extern "C"
|
||||
dev->ctrl_sock = -1;
|
||||
dev->flags = 0;
|
||||
#if defined(Windows)
|
||||
memset(&dev->ovl, 0, sizeof(OVERLAPPED));
|
||||
memset(&dev->ovl[0], 0, sizeof(OVERLAPPED)*2);
|
||||
#endif
|
||||
|
||||
__tuntap_log = &tuntap_log_default;
|
||||
|
Loading…
Reference in New Issue
Block a user