try fixing deadlock

pull/1576/head
Jeff Becker 3 years ago
parent 4889b8cddf
commit 07eaeb681a
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -11,24 +11,24 @@ namespace llarp
{
Endpoint::Endpoint(
const llarp::PubKey& remoteIdent,
const llarp::PathID_t& beginPath,
const llarp::path::HopHandler_ptr& beginPath,
bool rewriteIP,
huint128_t ip,
llarp::handlers::ExitEndpoint* parent)
: createdAt(parent->Now())
, m_Parent(parent)
, m_remoteSignKey(remoteIdent)
, m_CurrentPath(beginPath)
, m_IP(ip)
, m_RewriteSource(rewriteIP)
, m_Counter(0)
: createdAt{parent->Now()}
, m_Parent{parent}
, m_remoteSignKey{remoteIdent}
, m_CurrentPath{beginPath}
, m_IP{ip}
, m_RewriteSource{rewriteIP}
{
m_LastActive = parent->Now();
}
Endpoint::~Endpoint()
{
m_Parent->DelEndpointInfo(m_CurrentPath);
if (m_CurrentPath)
m_Parent->DelEndpointInfo(m_CurrentPath->RXID());
}
void
@ -59,7 +59,8 @@ namespace llarp
{
if (!m_Parent->UpdateEndpointPath(m_remoteSignKey, nextPath))
return false;
m_CurrentPath = nextPath;
const RouterID us{m_Parent->GetRouter()->pubkey()};
m_CurrentPath = m_Parent->GetRouter()->pathContext().GetByUpstream(us, nextPath);
return true;
}
@ -98,7 +99,7 @@ namespace llarp
if (ExpiresSoon(now, timeout))
return true;
auto path = GetCurrentPath();
if (!path)
if (not path)
return true;
auto lastPing = path->LastRemoteActivityAt();
if (lastPing == 0s || (now > lastPing && now - lastPing > timeout))
@ -240,12 +241,5 @@ namespace llarp
item.second.clear();
return sent;
}
llarp::path::HopHandler_ptr
Endpoint::GetCurrentPath() const
{
auto router = m_Parent->GetRouter();
return router->pathContext().GetByUpstream(router->pubkey(), m_CurrentPath);
}
} // namespace exit
} // namespace llarp

@ -2,7 +2,8 @@
#include <llarp/crypto/types.hpp>
#include <llarp/net/ip_packet.hpp>
#include <llarp/path/path.hpp>
#include <llarp/path/ihophandler.hpp>
#include <llarp/routing/transfer_traffic_message.hpp>
#include <llarp/service/protocol_type.hpp>
#include <llarp/util/time.hpp>
@ -23,9 +24,9 @@ namespace llarp
{
static constexpr size_t MaxUpstreamQueueSize = 256;
Endpoint(
explicit Endpoint(
const llarp::PubKey& remoteIdent,
const llarp::PathID_t& beginPath,
const llarp::path::HopHandler_ptr& path,
bool rewriteIP,
huint128_t ip,
llarp::handlers::ExitEndpoint* parent);
@ -75,7 +76,10 @@ namespace llarp
UpdateLocalPath(const llarp::PathID_t& nextPath);
llarp::path::HopHandler_ptr
GetCurrentPath() const;
GetCurrentPath() const
{
return m_CurrentPath;
}
const llarp::PubKey&
PubKey() const
@ -83,12 +87,6 @@ namespace llarp
return m_remoteSignKey;
}
const llarp::PathID_t&
LocalPath() const
{
return m_CurrentPath;
}
uint64_t
TxRate() const
{
@ -112,7 +110,7 @@ namespace llarp
private:
llarp::handlers::ExitEndpoint* m_Parent;
llarp::PubKey m_remoteSignKey;
llarp::PathID_t m_CurrentPath;
llarp::path::HopHandler_ptr m_CurrentPath;
llarp::huint128_t m_IP;
uint64_t m_TxRate, m_RxRate;
llarp_time_t m_LastActive;

@ -66,7 +66,8 @@ namespace llarp
auto visit = [&tag](exit::Endpoint* const ep) -> bool {
if (not ep)
return false;
tag = service::ConvoTag{ep->LocalPath().as_array()};
if (auto path = ep->GetCurrentPath())
tag = service::ConvoTag{path->RXID().as_array()};
return true;
};
if (VisitEndpointsFor(PubKey{*rid}, visit) and not tag.IsZero())
@ -789,6 +790,10 @@ namespace llarp
{
if (wantInternet && !m_PermitExit)
return false;
path::HopHandler_ptr handler =
m_Router->pathContext().GetByUpstream(m_Router->pubkey(), path);
if (handler == nullptr)
return false;
auto ip = GetIPForIdent(pk);
if (GetRouter()->pathContext().TransitHopPreviousIsRouter(path, pk.as_array()))
{
@ -797,7 +802,7 @@ namespace llarp
m_SNodeKeys.emplace(pk.as_array());
}
m_ActiveExits.emplace(
pk, std::make_unique<exit::Endpoint>(pk, path, !wantInternet, ip, this));
pk, std::make_unique<exit::Endpoint>(pk, handler, !wantInternet, ip, this));
m_Paths[path] = pk;
@ -823,12 +828,13 @@ namespace llarp
auto itr = range.first;
while (itr != range.second)
{
if (itr->second->LocalPath() == ep->LocalPath())
if (itr->second->GetCurrentPath() == ep->GetCurrentPath())
{
itr = m_ActiveExits.erase(itr);
// now ep is gone af
return;
}
++itr;
}
}

@ -30,6 +30,9 @@ namespace llarp
virtual ~IHopHandler() = default;
virtual PathID_t
RXID() const = 0;
void
DecayFilters(llarp_time_t now);

@ -360,7 +360,7 @@ namespace llarp
IsEndpoint(const RouterID& router, const PathID_t& path) const;
PathID_t
RXID() const;
RXID() const override;
RouterID
Upstream() const;

@ -73,6 +73,12 @@ namespace llarp
llarp_proto_version_t version;
llarp_time_t m_LastActivity = 0s;
PathID_t
RXID() const override
{
return info.rxID;
}
void
Stop();

Loading…
Cancel
Save