make format and attempt to fix #158

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

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

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

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

@ -669,7 +669,8 @@ namespace llarp
"cannot handle exploritory router lookup, no dht peers");
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
// requester is likely in the connected list
// 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);
tun->impl = dev;
// We're not even going to add this to the socket event loop
if (dev)
if(dev)
{
dev->setup();
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);
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

@ -121,13 +121,17 @@ namespace llarp
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){};
/// 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
error()
@ -189,7 +193,7 @@ namespace llarp
virtual void
flush_write_buffers(size_t amount)
{
if(m_BlockingWriteQueue)
if(m_BlockingWriteQueue)
{
if(amount)
{

@ -57,7 +57,7 @@ struct win32_tun_io
device* tunif;
byte_t readbuf[EV_READ_BUF_SZ] = {0};
struct WriteBuffer
struct WriteBuffer
{
llarp_time_t timestamp = 0;
size_t bufsz;
@ -128,12 +128,14 @@ struct WriteBuffer
WriteBuffer::GetNow, llarp::util::NullMutex,
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())
{
// This is not your normal everyday event loop, this is _advanced_ event handling :>
m_LossyWriteQueue = std::make_unique<LossyWriteQueue_t>("win32_tun_queue", nullptr, nullptr);
// This is not your normal everyday event loop, this is _advanced_ event
// handling :>
m_LossyWriteQueue = std::make_unique< LossyWriteQueue_t >("win32_tun_queue",
nullptr, nullptr);
};
bool
@ -276,7 +278,7 @@ tun_ev_loop(void* unused)
win32_tun_io* ev = reinterpret_cast< win32_tun_io* >(listener);
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)
ev->t->recvpkt(ev->t, llarp::InitBuffer(pkt->buf, size));
ev->flush_write();
@ -765,7 +767,7 @@ struct llarp_win32_loop : public llarp_ev_loop
void
stop()
{
// do nothing
// do nothing
}
};

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

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

@ -132,7 +132,6 @@ namespace llarp
void
ExitEndpoint::Flush()
{
auto now = Now();
m_InetToNetwork.Process([&](Pkt_t &pkt) {
llarp::PubKey pk;
{
@ -160,20 +159,7 @@ namespace llarp
return;
}
}
llarp::exit::Endpoint *ep = nullptr;
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;
}
llarp::exit::Endpoint *ep = m_ChosenExits[pk];
if(ep == nullptr)
{
@ -427,8 +413,8 @@ namespace llarp
dnsport = std::atoi(v.substr(pos + 1).c_str());
}
m_UpstreamResolvers.emplace_back(resolverAddr, dnsport);
llarp::LogInfo(Name(), " adding upstream dns set to ", resolverAddr, ":",
dnsport);
llarp::LogInfo(Name(), " adding upstream dns set to ", resolverAddr,
":", dnsport);
}
if(k == "ifaddr")
{
@ -559,18 +545,38 @@ namespace llarp
}
}
{
// expire
auto itr = m_ActiveExits.begin();
while(itr != m_ActiveExits.end())
{
if(itr->second->IsExpired(now))
{
itr = m_ActiveExits.erase(itr);
}
else
{
itr->second->Tick(now);
++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,
llarp::PathID_t::Hash >
m_Paths;
std::unordered_map< llarp::PubKey, llarp::exit::Endpoint*,
llarp::PubKey::Hash >
m_ChosenExits;
std::unordered_multimap< llarp::PubKey,
std::unique_ptr< llarp::exit::Endpoint >,
llarp::PubKey::Hash >

@ -37,7 +37,7 @@ namespace llarp
tunif.user = this;
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.ifname, DefaultTunIfname, sizeof(tunif.ifname) - 1);

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

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

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

@ -664,7 +664,8 @@ namespace llarp
if(N < 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
if(bootstrapRCList.size())
{

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

Loading…
Cancel
Save