make format and attempt to fix #158

pull/181/head
Jeff 6 years ago
parent a66f997702
commit 4b2a1ea9f3

@ -51,7 +51,7 @@ handle_signal_win32(DWORD fdwCtrlType)
{ {
UNREFERENCED_PARAMETER(fdwCtrlType); UNREFERENCED_PARAMETER(fdwCtrlType);
handle_signal(SIGINT); handle_signal(SIGINT);
return TRUE; // probably unreachable return TRUE; // probably unreachable
} }
#endif #endif

@ -343,8 +343,8 @@ namespace tl
using enable_assign_forward = detail::enable_if_t< using enable_assign_forward = detail::enable_if_t<
!std::is_same< optional< T >, detail::decay_t< U > >::value !std::is_same< optional< T >, detail::decay_t< U > >::value
&& !detail::conjunction< && !detail::conjunction<
std::is_scalar< T >, std::is_scalar< T >,
std::is_same< T, detail::decay_t< U > > >::value std::is_same< T, detail::decay_t< U > > >::value
&& std::is_constructible< T, U >::value && std::is_constructible< T, U >::value
&& std::is_assignable< T &, U >::value >; && std::is_assignable< T &, U >::value >;
@ -465,7 +465,7 @@ namespace tl
0))::value &&detail::swap_adl_tests:: 0))::value &&detail::swap_adl_tests::
is_std_swap_noexcept< T >::value) is_std_swap_noexcept< T >::value)
|| (!decltype(detail::swap_adl_tests::uses_std< T, U >( || (!decltype(detail::swap_adl_tests::uses_std< T, U >(
0))::value &&detail::swap_adl_tests:: 0))::value &&detail::swap_adl_tests::
is_adl_swap_noexcept< T, U >::value)) > is_adl_swap_noexcept< T, U >::value)) >
{ {
}; };

@ -257,9 +257,9 @@ namespace llarp
}; };
private: private:
using AlignedStorage = using AlignedStorage = typename std::aligned_storage< sizeof(Data),
typename std::aligned_storage< sizeof(Data), alignof(uint64_t) >::
alignof(uint64_t) >::type; // why did we align to the nearest double-precision float type; // why did we align to the nearest double-precision float
AlignedStorage val; AlignedStorage val;
}; };

@ -669,7 +669,8 @@ namespace llarp
"cannot handle exploritory router lookup, no dht peers"); "cannot handle exploritory router lookup, no dht peers");
return false; return false;
} }
llarp::LogDebug("We have ", nodes->Size(), " connected nodes into the DHT"); llarp::LogDebug("We have ", nodes->Size(),
" connected nodes into the DHT");
// ourKey should never be in the connected list // ourKey should never be in the connected list
// requester is likely in the connected list // requester is likely in the connected list
// 4 or connection nodes (minus a potential requestor), whatever is less // 4 or connection nodes (minus a potential requestor), whatever is less

@ -165,7 +165,7 @@ llarp_ev_add_tun(llarp_ev_loop *loop, llarp_tun_io *tun)
auto dev = new win32_tun_io(tun); auto dev = new win32_tun_io(tun);
tun->impl = dev; tun->impl = dev;
// We're not even going to add this to the socket event loop // We're not even going to add this to the socket event loop
if (dev) if(dev)
{ {
dev->setup(); dev->setup();
return dev->add_ev(); // start up tun and add to event queue return dev->add_ev(); // start up tun and add to event queue
@ -194,7 +194,8 @@ llarp_ev_tun_async_write(struct llarp_tun_io *tun, llarp_buffer_t buf)
llarp::LogWarn("packet too big, ", buf.sz, " > ", EV_WRITE_BUF_SZ); llarp::LogWarn("packet too big, ", buf.sz, " > ", EV_WRITE_BUF_SZ);
return false; return false;
} }
return static_cast< win32_tun_io * >(tun->impl)->queue_write(buf.base, buf.sz); return static_cast< win32_tun_io * >(tun->impl)->queue_write(buf.base,
buf.sz);
} }
#endif #endif

@ -121,13 +121,17 @@ namespace llarp
using LosslessWriteQueue_t = std::deque< WriteBuffer >; using LosslessWriteQueue_t = std::deque< WriteBuffer >;
intptr_t fd; // Sockets only, fuck UNIX-style reactive IO with a rusty knife intptr_t
fd; // Sockets only, fuck UNIX-style reactive IO with a rusty knife
int flags = 0; int flags = 0;
win32_ev_io(intptr_t f) : fd(f){}; win32_ev_io(intptr_t f) : fd(f){};
/// for tcp /// for tcp
win32_ev_io(intptr_t f, LosslessWriteQueue_t* q) : fd(f), m_BlockingWriteQueue(q){} win32_ev_io(intptr_t f, LosslessWriteQueue_t* q)
: fd(f), m_BlockingWriteQueue(q)
{
}
virtual void virtual void
error() error()
@ -189,7 +193,7 @@ namespace llarp
virtual void virtual void
flush_write_buffers(size_t amount) flush_write_buffers(size_t amount)
{ {
if(m_BlockingWriteQueue) if(m_BlockingWriteQueue)
{ {
if(amount) if(amount)
{ {

@ -57,7 +57,7 @@ struct win32_tun_io
device* tunif; device* tunif;
byte_t readbuf[EV_READ_BUF_SZ] = {0}; byte_t readbuf[EV_READ_BUF_SZ] = {0};
struct WriteBuffer struct WriteBuffer
{ {
llarp_time_t timestamp = 0; llarp_time_t timestamp = 0;
size_t bufsz; size_t bufsz;
@ -128,12 +128,14 @@ struct WriteBuffer
WriteBuffer::GetNow, llarp::util::NullMutex, WriteBuffer::GetNow, llarp::util::NullMutex,
llarp::util::NullLock, 5, 100, 128 >; llarp::util::NullLock, 5, 100, 128 >;
std::unique_ptr<LossyWriteQueue_t> m_LossyWriteQueue; std::unique_ptr< LossyWriteQueue_t > m_LossyWriteQueue;
win32_tun_io(llarp_tun_io* tio) : t(tio), tunif(tuntap_init()) win32_tun_io(llarp_tun_io* tio) : t(tio), tunif(tuntap_init())
{ {
// This is not your normal everyday event loop, this is _advanced_ event handling :> // This is not your normal everyday event loop, this is _advanced_ event
m_LossyWriteQueue = std::make_unique<LossyWriteQueue_t>("win32_tun_queue", nullptr, nullptr); // handling :>
m_LossyWriteQueue = std::make_unique< LossyWriteQueue_t >("win32_tun_queue",
nullptr, nullptr);
}; };
bool bool
@ -276,7 +278,7 @@ tun_ev_loop(void* unused)
win32_tun_io* ev = reinterpret_cast< win32_tun_io* >(listener); win32_tun_io* ev = reinterpret_cast< win32_tun_io* >(listener);
if(!pkt->write) if(!pkt->write)
{ {
//llarp::LogInfo("read tun ", size, " bytes, pass to handler"); // llarp::LogInfo("read tun ", size, " bytes, pass to handler");
if(ev->t->recvpkt) if(ev->t->recvpkt)
ev->t->recvpkt(ev->t, llarp::InitBuffer(pkt->buf, size)); ev->t->recvpkt(ev->t, llarp::InitBuffer(pkt->buf, size));
ev->flush_write(); ev->flush_write();
@ -765,7 +767,7 @@ struct llarp_win32_loop : public llarp_ev_loop
void void
stop() stop()
{ {
// do nothing // do nothing
} }
}; };

@ -9,7 +9,8 @@ namespace llarp
Endpoint::Endpoint(const llarp::PubKey& remoteIdent, Endpoint::Endpoint(const llarp::PubKey& remoteIdent,
const llarp::PathID_t& beginPath, bool rewriteIP, const llarp::PathID_t& beginPath, bool rewriteIP,
huint32_t ip, llarp::handlers::ExitEndpoint* parent) huint32_t ip, llarp::handlers::ExitEndpoint* parent)
: m_Parent(parent) : createdAt(parent->Now())
, m_Parent(parent)
, m_remoteSignKey(remoteIdent) , m_remoteSignKey(remoteIdent)
, m_CurrentPath(beginPath) , m_CurrentPath(beginPath)
, m_IP(ip) , m_IP(ip)
@ -73,9 +74,7 @@ namespace llarp
{ {
if(ExpiresSoon(now, timeout)) if(ExpiresSoon(now, timeout))
return true; return true;
if(now > m_LastActive) return now > m_LastActive && now - m_LastActive > timeout;
return now - m_LastActive > timeout;
return true;
} }
bool bool

@ -97,6 +97,8 @@ namespace llarp
return m_IP; return m_IP;
} }
const llarp_time_t createdAt;
private: private:
llarp::handlers::ExitEndpoint* m_Parent; llarp::handlers::ExitEndpoint* m_Parent;
llarp::PubKey m_remoteSignKey; llarp::PubKey m_remoteSignKey;

@ -132,7 +132,6 @@ namespace llarp
void void
ExitEndpoint::Flush() ExitEndpoint::Flush()
{ {
auto now = Now();
m_InetToNetwork.Process([&](Pkt_t &pkt) { m_InetToNetwork.Process([&](Pkt_t &pkt) {
llarp::PubKey pk; llarp::PubKey pk;
{ {
@ -160,20 +159,7 @@ namespace llarp
return; return;
} }
} }
llarp::exit::Endpoint *ep = nullptr; llarp::exit::Endpoint *ep = m_ChosenExits[pk];
auto range = m_ActiveExits.equal_range(pk);
auto itr = range.first;
uint64_t min = std::numeric_limits< uint64_t >::max();
/// pick non dead looking path with lowest tx rate
while(itr != range.second)
{
if(itr->second->TxRate() < min && !itr->second->LooksDead(now))
{
ep = itr->second.get();
min = ep->TxRate();
}
++itr;
}
if(ep == nullptr) if(ep == nullptr)
{ {
@ -427,8 +413,8 @@ namespace llarp
dnsport = std::atoi(v.substr(pos + 1).c_str()); dnsport = std::atoi(v.substr(pos + 1).c_str());
} }
m_UpstreamResolvers.emplace_back(resolverAddr, dnsport); m_UpstreamResolvers.emplace_back(resolverAddr, dnsport);
llarp::LogInfo(Name(), " adding upstream dns set to ", resolverAddr, ":", llarp::LogInfo(Name(), " adding upstream dns set to ", resolverAddr,
dnsport); ":", dnsport);
} }
if(k == "ifaddr") if(k == "ifaddr")
{ {
@ -559,18 +545,38 @@ namespace llarp
} }
} }
{ {
// expire
auto itr = m_ActiveExits.begin(); auto itr = m_ActiveExits.begin();
while(itr != m_ActiveExits.end()) while(itr != m_ActiveExits.end())
{ {
if(itr->second->IsExpired(now)) if(itr->second->IsExpired(now))
{
itr = m_ActiveExits.erase(itr); itr = m_ActiveExits.erase(itr);
}
else else
{
itr->second->Tick(now);
++itr; ++itr;
}
// pick chosen exits and tick
m_ChosenExits.clear();
itr = m_ActiveExits.begin();
while(itr != m_ActiveExits.end())
{
// do we have an exit set for this key?
if(m_ChosenExits.find(itr->first) != m_ChosenExits.end())
{
// yes
if(m_ChosenExits[itr->first]->createdAt < itr->second->createdAt)
{
// if the iterators's exit is newer use it for the chosen exit for
// key
m_ChosenExits[itr->first] = itr->second.get();
}
} }
else if(!itr->second->LooksDead(
now)) // set chosen exit if not dead for key that doesn't
// have one yet
m_ChosenExits[itr->first] = itr->second.get();
// tick which clears the tx rx counters
itr->second->Tick(now);
++itr;
} }
} }
} }

@ -125,6 +125,11 @@ namespace llarp
std::unordered_map< llarp::PathID_t, llarp::PubKey, std::unordered_map< llarp::PathID_t, llarp::PubKey,
llarp::PathID_t::Hash > llarp::PathID_t::Hash >
m_Paths; m_Paths;
std::unordered_map< llarp::PubKey, llarp::exit::Endpoint*,
llarp::PubKey::Hash >
m_ChosenExits;
std::unordered_multimap< llarp::PubKey, std::unordered_multimap< llarp::PubKey,
std::unique_ptr< llarp::exit::Endpoint >, std::unique_ptr< llarp::exit::Endpoint >,
llarp::PubKey::Hash > llarp::PubKey::Hash >

@ -37,7 +37,7 @@ namespace llarp
tunif.user = this; tunif.user = this;
tunif.netmask = DefaultTunNetmask; tunif.netmask = DefaultTunNetmask;
// eh this shouldn't do anything on windows anyway // eh this shouldn't do anything on windows anyway
strncpy(tunif.ifaddr, DefaultTunSrcAddr, sizeof(tunif.ifaddr) - 1); strncpy(tunif.ifaddr, DefaultTunSrcAddr, sizeof(tunif.ifaddr) - 1);
strncpy(tunif.ifname, DefaultTunIfname, sizeof(tunif.ifname) - 1); strncpy(tunif.ifname, DefaultTunIfname, sizeof(tunif.ifname) - 1);

@ -18,13 +18,13 @@ namespace llarp
std::vector< std::unique_ptr< llarp::dht::IMessage > > msgs; std::vector< std::unique_ptr< llarp::dht::IMessage > > msgs;
bool bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf); DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
bool bool
BEncode(llarp_buffer_t* buf) const; BEncode(llarp_buffer_t* buf) const override;
bool bool
HandleMessage(llarp::Router* router) const; HandleMessage(llarp::Router* router) const override;
void void
Clear() override; Clear() override;

@ -27,13 +27,13 @@ namespace llarp
operator=(const LinkIntroMessage& msg); operator=(const LinkIntroMessage& msg);
bool bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf); DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
bool bool
BEncode(llarp_buffer_t* buf) const; BEncode(llarp_buffer_t* buf) const override;
bool bool
HandleMessage(llarp::Router* router) const; HandleMessage(llarp::Router* router) const override;
bool bool
Sign(llarp::Crypto* c, const SecretKey& signKeySecret); Sign(llarp::Crypto* c, const SecretKey& signKeySecret);

@ -753,7 +753,7 @@ llarp_getifaddr(const char* ifname, int af, struct sockaddr* addr)
#ifndef _WIN32 #ifndef _WIN32
if(getifaddrs(&ifa) == -1) if(getifaddrs(&ifa) == -1)
#else #else
if (!strcmp(ifname, "lo") || !strcmp(ifname, "lo0")) if(!strcmp(ifname, "lo") || !strcmp(ifname, "lo0"))
{ {
sockaddr_in* lo = (sockaddr_in*)addr; sockaddr_in* lo = (sockaddr_in*)addr;
lo->sin_family = af; lo->sin_family = af;

@ -664,7 +664,8 @@ namespace llarp
if(N < minRequiredRouters) if(N < minRequiredRouters)
{ {
llarp::LogInfo("We need at least ", minRequiredRouters, llarp::LogInfo("We need at least ", minRequiredRouters,
" service nodes to build paths but we have ", N, " in nodedb"); " service nodes to build paths but we have ", N,
" in nodedb");
// TODO: only connect to random subset // TODO: only connect to random subset
if(bootstrapRCList.size()) if(bootstrapRCList.size())
{ {

@ -274,7 +274,7 @@ int
upoll_wait(upoll_t* upq, upoll_event_t* evs, int nev, int timeout) upoll_wait(upoll_t* upq, upoll_event_t* evs, int nev, int timeout)
{ {
int r = 0; int r = 0;
r = upoll_wait_select(upq, evs, nev, timeout); r = upoll_wait_select(upq, evs, nev, timeout);
return r; return r;
} }

Loading…
Cancel
Save