make format and attempt to fix #158

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

@ -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

@ -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;
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()

@ -132,8 +132,10 @@ struct WriteBuffer
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

@ -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,20 +545,40 @@ 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;
}
// 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;
}
}
}
}
} // namespace handlers
} // namespace llarp

@ -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 >

@ -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);

@ -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())
{

Loading…
Cancel
Save