clang-format

pull/20/head
despair86 6 years ago
parent 3c7b7f2176
commit 3c13101beb

@ -100,7 +100,8 @@ main(int argc, char *argv[])
conffname = fname.string(); conffname = fname.string();
if(basedir.string().empty()) if(basedir.string().empty())
{ {
if(!llarp_ensure_config(fname.string().c_str(), nullptr, overWrite, asRouter)) if(!llarp_ensure_config(fname.string().c_str(), nullptr, overWrite,
asRouter))
return 1; return 1;
} }
else else

@ -137,18 +137,18 @@ namespace llarp
size_t m_NumPaths; size_t m_NumPaths;
private: private:
typedef std::pair< RouterID, PathID_t > PathInfo_t; typedef std::pair< RouterID, PathID_t > PathInfo_t;
struct PathInfoHash struct PathInfoHash
{ {
size_t operator()(const PathInfo_t & i) const size_t
operator()(const PathInfo_t& i) const
{ {
return *i.first.data_l() ^ *i.second.data_l(); return *i.first.data_l() ^ *i.second.data_l();
} }
}; };
typedef std::unordered_map< PathInfo_t, Path* , PathInfoHash> PathMap_t; typedef std::unordered_map< PathInfo_t, Path*, PathInfoHash > PathMap_t;
PathMap_t m_Paths; PathMap_t m_Paths;
}; };

@ -82,7 +82,7 @@ writecname_dnss_response(std::string cname, const struct sockaddr *from,
dnsd_question_request *request) dnsd_question_request *request)
{ {
const size_t BUFFER_SIZE = 1024 + (request->question.name.size() * 2); const size_t BUFFER_SIZE = 1024 + (request->question.name.size() * 2);
char buf[BUFFER_SIZE]; // heh, another UNIX compiler extension: VLAs in C++ char buf[BUFFER_SIZE]; // heh, another UNIX compiler extension: VLAs in C++
memset(buf, 0, BUFFER_SIZE); memset(buf, 0, BUFFER_SIZE);
char *write_buffer = buf; char *write_buffer = buf;
char *bufferBegin = buf; char *bufferBegin = buf;

@ -206,13 +206,13 @@ struct llarp_kqueue_loop : public llarp_ev_loop
while(idx < result) while(idx < result)
{ {
llarp::ev_io* ev = static_cast< llarp::ev_io* >(events[idx].udata); llarp::ev_io* ev = static_cast< llarp::ev_io* >(events[idx].udata);
if (ev) if(ev)
{ {
ev->read(readbuf, sizeof(readbuf)); ev->read(readbuf, sizeof(readbuf));
} }
else else
{ {
llarp::LogWarn("event[", idx,"] udata is not an ev_io"); llarp::LogWarn("event[", idx, "] udata is not an ev_io");
} }
++idx; ++idx;
} }

@ -22,7 +22,7 @@ namespace llarp
udp_listener(SOCKET fd, llarp_udp_io* u) : ev_io(fd), udp(u) udp_listener(SOCKET fd, llarp_udp_io* u) : ev_io(fd), udp(u)
{ {
memset((void*)&portfd, 0, sizeof(WSAOVERLAPPED)); memset((void*)&portfd, 0, sizeof(WSAOVERLAPPED));
}; };
~udp_listener() ~udp_listener()
@ -46,9 +46,8 @@ namespace llarp
WSABUF wbuf = {sz, static_cast< char* >(buf)}; WSABUF wbuf = {sz, static_cast< char* >(buf)};
// WSARecvFrom // WSARecvFrom
llarp::LogDebug("read ", sz, " bytes into socket"); llarp::LogDebug("read ", sz, " bytes into socket");
int ret = int ret = ::WSARecvFrom(std::get< SOCKET >(fd), &wbuf, 1, nullptr, &flags,
::WSARecvFrom(std::get< SOCKET >(fd), &wbuf, 1, nullptr, &flags, addr, addr, &slen, &portfd, nullptr);
&slen, &portfd, nullptr);
// 997 is the error code for queued ops // 997 is the error code for queued ops
int s_errno = ::WSAGetLastError(); int s_errno = ::WSAGetLastError();
if(ret && s_errno != 997) if(ret && s_errno != 997)
@ -121,7 +120,7 @@ namespace llarp
ev_io::flush_write(); ev_io::flush_write();
} }
bool bool
do_write(void* data, size_t sz) 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);
@ -212,7 +211,7 @@ struct llarp_win32_loop : public llarp_ev_loop
// as an arch-specific pointer value // as an arch-specific pointer value
ULONG_PTR ev_id = 0; ULONG_PTR ev_id = 0;
WSAOVERLAPPED* qdata = nullptr; WSAOVERLAPPED* qdata = nullptr;
int idx = 0; int idx = 0;
BOOL result = BOOL result =
::GetQueuedCompletionStatus(iocpfd, &iolen, &ev_id, &qdata, ms); ::GetQueuedCompletionStatus(iocpfd, &iolen, &ev_id, &qdata, ms);
@ -221,7 +220,8 @@ struct llarp_win32_loop : public llarp_ev_loop
llarp::udp_listener* ev = reinterpret_cast< llarp::udp_listener* >(ev_id); llarp::udp_listener* ev = reinterpret_cast< llarp::udp_listener* >(ev_id);
if(ev && !ev->fd.valueless_by_exception()) if(ev && !ev->fd.valueless_by_exception())
{ {
llarp::LogDebug("size: ", iolen, "\tev_id: ", ev_id, "\tqdata: ", qdata); llarp::LogDebug("size: ", iolen, "\tev_id: ", ev_id,
"\tqdata: ", qdata);
ev->getData(readbuf, sizeof(readbuf), iolen); ev->getData(readbuf, sizeof(readbuf), iolen);
} }
++idx; ++idx;
@ -251,22 +251,21 @@ struct llarp_win32_loop : public llarp_ev_loop
ULONG_PTR ev_id = 0; ULONG_PTR ev_id = 0;
WSAOVERLAPPED* qdata = nullptr; WSAOVERLAPPED* qdata = nullptr;
int idx = 0; int idx = 0;
int result = ::GetQueuedCompletionStatus(iocpfd, &iolen, &ev_id, &qdata, 10); int result =
::GetQueuedCompletionStatus(iocpfd, &iolen, &ev_id, &qdata, 10);
// unlike epoll and kqueue, we only need to run so long as the // unlike epoll and kqueue, we only need to run so long as the
// system call returns TRUE // system call returns TRUE
if(result) if(result)
{
llarp::udp_listener* ev = reinterpret_cast< llarp::udp_listener* >(ev_id);
if(ev && !ev->fd.valueless_by_exception())
{ {
llarp::udp_listener* ev = llarp::LogInfo("size: ", iolen, "\tev_id: ", ev_id, "\tqdata: ", qdata);
reinterpret_cast< llarp::udp_listener* >(ev_id); ev->getData(readbuf, sizeof(readbuf), iolen);
if(ev && !ev->fd.valueless_by_exception())
{
llarp::LogInfo("size: ", iolen, "\tev_id: ", ev_id,
"\tqdata: ", qdata);
ev->getData(readbuf, sizeof(readbuf), iolen);
}
++idx;
} }
++idx;
}
if(!idx) if(!idx)
return -1; return -1;
@ -294,7 +293,7 @@ struct llarp_win32_loop : public llarp_ev_loop
default: default:
return INVALID_SOCKET; return INVALID_SOCKET;
} }
DWORD on = 1; DWORD on = 1;
SOCKET fd = ::socket(addr->sa_family, SOCK_DGRAM, 0); SOCKET fd = ::socket(addr->sa_family, SOCK_DGRAM, 0);
if(fd == INVALID_SOCKET) if(fd == INVALID_SOCKET)
{ {
@ -365,33 +364,34 @@ struct llarp_win32_loop : public llarp_ev_loop
bool bool
add_ev(llarp::ev_io* ev, bool write) add_ev(llarp::ev_io* ev, bool write)
{ {
uint8_t buf[1024]; uint8_t buf[1024];
llarp::udp_listener *udp = nullptr; llarp::udp_listener* udp = nullptr;
llarp::tun *t = nullptr; llarp::tun* t = nullptr;
ev->listener_id = reinterpret_cast< ULONG_PTR >(ev); ev->listener_id = reinterpret_cast< ULONG_PTR >(ev);
memset(&buf, 0, 1024); memset(&buf, 0, 1024);
switch(ev->fd.index()) switch(ev->fd.index())
{ {
case 0: case 0:
udp = dynamic_cast<llarp::udp_listener*>(ev); udp = dynamic_cast< llarp::udp_listener* >(ev);
if(!::CreateIoCompletionPort((HANDLE)std::get< 0 >(ev->fd), iocpfd, if(!::CreateIoCompletionPort((HANDLE)std::get< 0 >(ev->fd), iocpfd,
ev->listener_id, 0)) ev->listener_id, 0))
{ {
delete ev; delete ev;
return false; return false;
} }
::ReadFile((HANDLE)std::get<0>(ev->fd), &buf, 1024, nullptr, &udp->portfd); ::ReadFile((HANDLE)std::get< 0 >(ev->fd), &buf, 1024, nullptr,
&udp->portfd);
break; break;
case 1: case 1:
t = dynamic_cast<llarp::tun*>(ev); t = dynamic_cast< llarp::tun* >(ev);
if(!::CreateIoCompletionPort(std::get< 1 >(ev->fd), iocpfd, if(!::CreateIoCompletionPort(std::get< 1 >(ev->fd), iocpfd,
ev->listener_id, 0)) ev->listener_id, 0))
{ {
delete ev; delete ev;
return false; 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);
break; break;
default: default:
return false; return false;

@ -110,7 +110,8 @@ namespace llarp
llarp::Addr tunIp(source_addr); llarp::Addr tunIp(source_addr);
// related to dns_iptracker_setup_dotLokiLookup(&this->dll, tunIp); // related to dns_iptracker_setup_dotLokiLookup(&this->dll, tunIp);
dns_iptracker_setup(this->dll.ip_tracker, tunIp); // claim GW IP to make sure it's not inuse dns_iptracker_setup(this->dll.ip_tracker,
tunIp); // claim GW IP to make sure it's not inuse
return true; return true;
} }
return Endpoint::SetOption(k, v); return Endpoint::SetOption(k, v);
@ -150,7 +151,8 @@ namespace llarp
llarp::Addr tunIp(tunif.ifaddr); llarp::Addr tunIp(tunif.ifaddr);
dns_iptracker_setup_dotLokiLookup( dns_iptracker_setup_dotLokiLookup(
&this->dll, tunIp); // just set ups dll to use global iptracker &this->dll, tunIp); // just set ups dll to use global iptracker
dns_iptracker_setup(this->dll.ip_tracker, tunIp); // claim GW IP to make sure it's not inuse dns_iptracker_setup(this->dll.ip_tracker,
tunIp); // claim GW IP to make sure it's not inuse
// set up networking in currrent thread if we are not isolated // set up networking in currrent thread if we are not isolated
if(!SetupNetworking()) if(!SetupNetworking())
@ -162,8 +164,9 @@ namespace llarp
llarp::Addr tunIp(tunif.ifaddr); llarp::Addr tunIp(tunif.ifaddr);
this->dll.ip_tracker = new dns_iptracker; this->dll.ip_tracker = new dns_iptracker;
dns_iptracker_setup_dotLokiLookup( dns_iptracker_setup_dotLokiLookup(
&this->dll, tunIp); // just set ups dll to use global iptracker &this->dll, tunIp); // just set ups dll to use global iptracker
dns_iptracker_setup(this->dll.ip_tracker, tunIp); // claim GW IP to make sure it's not inuse dns_iptracker_setup(this->dll.ip_tracker,
tunIp); // claim GW IP to make sure it's not inuse
} }
// wait for result for network setup // wait for result for network setup
llarp::LogInfo("waiting for tun interface..."); llarp::LogInfo("waiting for tun interface...");
@ -254,7 +257,8 @@ namespace llarp
{ {
llarp::LogInfo("Set Up networking for ", Name()); llarp::LogInfo("Set Up networking for ", Name());
bool result = SetupTun(); bool result = SetupTun();
m_TunSetupResult.set_value(result); // now that NT has tun, we don't need the CPP guard m_TunSetupResult.set_value(
result); // now that NT has tun, we don't need the CPP guard
if(!NetworkIsIsolated()) if(!NetworkIsIsolated())
{ {
// need to check to see if we have more than one hidden service // need to check to see if we have more than one hidden service

@ -350,7 +350,8 @@ namespace llarp
" bytes"); " bytes");
if(::sendto(l->m_udp.fd, (char*)arg->buf, arg->len, arg->flags, if(::sendto(l->m_udp.fd, (char*)arg->buf, arg->len, arg->flags,
arg->address, arg->address_len) arg->address, arg->address_len)
== -1 && errno) == -1
&& errno)
{ {
llarp::LogError("sendto failed: ", strerror(errno)); llarp::LogError("sendto failed: ", strerror(errno));
} }

Loading…
Cancel
Save