client improvements

for real do correct timestamp comparison for introsets
pull/15/head
Jeff Becker 6 years ago
parent 2993e834a0
commit baf2e1fb3c
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -124,13 +124,13 @@ namespace llarp
void void
src(uint32_t ip) src(uint32_t ip)
{ {
Header()->saddr = htonl(ip); Header()->saddr = ip;
} }
void void
dst(uint32_t ip) dst(uint32_t ip)
{ {
Header()->daddr = htonl(ip); Header()->daddr = ip;
} }
// update ip packet checksum // update ip packet checksum

@ -31,14 +31,14 @@ namespace llarp
bool bool
IsExpired(llarp_time_t now) const IsExpired(llarp_time_t now) const
{ {
return now <= expiresAt; return now >= expiresAt;
} }
bool bool
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5000) const ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5000) const
{ {
if(dlt) if(dlt)
return now <= (expiresAt - (llarp_randint() % dlt)); return now >= (expiresAt - (llarp_randint() % dlt));
return IsExpired(now); return IsExpired(now);
} }

@ -255,6 +255,9 @@ namespace llarp
virtual void virtual void
IntroSetPublished(); IntroSetPublished();
void
RegenAndPublishIntroSet(llarp_time_t now);
IServiceLookup* IServiceLookup*
GenerateLookupByTag(const Tag& tag); GenerateLookupByTag(const Tag& tag);

@ -248,7 +248,7 @@ namespace llarp
} }
if(m_NextIP < m_MaxIP) if(m_NextIP < m_MaxIP)
{ {
nextIP = htonl(++m_NextIP); nextIP = ++m_NextIP;
m_AddrToIP.insert(std::make_pair(addr, nextIP)); m_AddrToIP.insert(std::make_pair(addr, nextIP));
m_IPToAddr.insert(std::make_pair(nextIP, addr)); m_IPToAddr.insert(std::make_pair(nextIP, addr));
} }

@ -498,7 +498,8 @@ namespace llarp
intro.expiresAt = buildStarted + hops[0].lifetime; intro.expiresAt = buildStarted + hops[0].lifetime;
// confirm that we build the path // confirm that we build the path
status = ePathEstablished; status = ePathEstablished;
llarp::LogInfo("path is confirmed tx=", TXID(), " rx=", RXID()); llarp::LogInfo("path is confirmed tx=", TXID(), " rx=", RXID(),
" took ", llarp_time_now_ms() - buildStarted, " ms");
if(m_BuiltHook) if(m_BuiltHook)
m_BuiltHook(this); m_BuiltHook(this);
m_BuiltHook = nullptr; m_BuiltHook = nullptr;

@ -105,7 +105,7 @@ namespace llarp
auto highest = now; auto highest = now;
for(const auto& i : I) for(const auto& i : I)
highest = std::max(i.expiresAt, highest); highest = std::max(i.expiresAt, highest);
return highest >= now; return highest <= now;
} }
Introduction::~Introduction() Introduction::~Introduction()

@ -84,6 +84,48 @@ namespace llarp
!= m_PendingServiceLookups.end(); != m_PendingServiceLookups.end();
} }
void
Endpoint::RegenAndPublishIntroSet(llarp_time_t now)
{
std::set< Introduction > I;
if(!GetCurrentIntroductions(I))
{
llarp::LogWarn("could not publish descriptors for endpoint ", Name(),
" because we couldn't get any introductions");
if(ShouldBuildMore())
ManualRebuild(1);
return;
}
IntroSet introset = m_IntroSet;
introset.I.clear();
for(const auto& intro : I)
{
llarp::LogInfo(intro);
if(!intro.ExpiresSoon(now))
introset.I.push_back(intro);
}
if(introset.I.size() == 0)
{
llarp::LogWarn("not enough intros to publish introset for ", Name());
return;
}
introset.topic = m_Tag;
if(!m_Identity.SignIntroSet(introset, &m_Router->crypto))
{
llarp::LogWarn("failed to sign introset for endpoint ", Name());
return;
}
m_IntroSet = introset;
if(PublishIntroSet(m_Router))
{
llarp::LogInfo("publishing introset for endpoint ", Name());
}
else
{
llarp::LogWarn("failed to publish intro set for endpoint ", Name());
}
}
void void
Endpoint::Tick(llarp_time_t now) Endpoint::Tick(llarp_time_t now)
{ {
@ -93,32 +135,7 @@ namespace llarp
// publish descriptors // publish descriptors
if(ShouldPublishDescriptors(now)) if(ShouldPublishDescriptors(now))
{ {
std::set< Introduction > I; RegenAndPublishIntroSet(now);
if(!GetCurrentIntroductions(I))
{
llarp::LogWarn("could not publish descriptors for endpoint ", Name(),
" because we couldn't get any introductions");
if(ShouldBuildMore())
ManualRebuild(1);
return;
}
m_IntroSet.I.clear();
for(const auto& intro : I)
m_IntroSet.I.push_back(intro);
m_IntroSet.topic = m_Tag;
if(!m_Identity.SignIntroSet(m_IntroSet, &m_Router->crypto))
{
llarp::LogWarn("failed to sign introset for endpoint ", Name());
return;
}
if(PublishIntroSet(m_Router))
{
llarp::LogInfo("publishing introset for endpoint ", Name());
}
else
{
llarp::LogWarn("failed to publish intro set for endpoint ", Name());
}
} }
// expire pending tx // expire pending tx
{ {
@ -448,7 +465,7 @@ namespace llarp
bool bool
Endpoint::PublishIntroSet(llarp_router* r) Endpoint::PublishIntroSet(llarp_router* r)
{ {
auto path = GetEstablishedPathClosestTo(m_Identity.pub.Addr().ToRouter()); auto path = PickRandomEstablishedPath();
if(path) if(path)
{ {
m_CurrentPublishTX = llarp_randint(); m_CurrentPublishTX = llarp_randint();
@ -478,8 +495,8 @@ namespace llarp
{ {
if(m_IntroSet.HasExpiredIntros(now)) if(m_IntroSet.HasExpiredIntros(now))
return now - m_LastPublishAttempt >= INTROSET_PUBLISH_RETRY_INTERVAL; return now - m_LastPublishAttempt >= INTROSET_PUBLISH_RETRY_INTERVAL;
return m_CurrentPublishTX == 0 return now - m_LastPublish >= INTROSET_PUBLISH_INTERVAL
&& now - m_LastPublish >= INTROSET_PUBLISH_INTERVAL; && m_CurrentPublishTX == 0;
} }
void void
@ -628,6 +645,7 @@ namespace llarp
{ {
p->SetDataHandler(std::bind(&Endpoint::HandleHiddenServiceFrame, this, p->SetDataHandler(std::bind(&Endpoint::HandleHiddenServiceFrame, this,
std::placeholders::_1)); std::placeholders::_1));
RegenAndPublishIntroSet(llarp_time_now_ms());
} }
bool bool

Loading…
Cancel
Save