tweak parameters for path build and obtain path if we have none

pull/15/head
Jeff Becker 6 years ago
parent 8e4b0a7963
commit f110f3f3ad
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -24,7 +24,7 @@
#define MAXHOPS (8)
#define DEFAULT_PATH_LIFETIME (10 * 60 * 1000)
#define PATH_BUILD_TIMEOUT (30 * 1000)
#define PATH_BUILD_TIMEOUT (15 * 1000)
#define MESSAGE_PAD_SIZE (512)
namespace llarp

@ -101,6 +101,9 @@ namespace llarp
Path*
GetPathByRouter(const RouterID& router) const;
Path*
GetNewestPathByRouter(const RouterID& router) const;
Path*
GetPathByID(const PathID_t& id) const;

@ -64,6 +64,28 @@ namespace llarp
return path;
}
Path*
PathSet::GetNewestPathByRouter(const RouterID& id) const
{
Path* chosen = nullptr;
auto itr = m_Paths.begin();
while(itr != m_Paths.end())
{
if(itr->second->IsReady())
{
if(itr->second->Endpoint() == id)
{
if(chosen == nullptr)
chosen = itr->second;
else if(chosen->intro.expiresAt < itr->second->intro.expiresAt)
chosen = itr->second;
}
}
++itr;
}
return chosen;
}
Path*
PathSet::GetPathByRouter(const RouterID& id) const
{

@ -906,29 +906,27 @@ namespace llarp
}
}
}
if(p == nullptr)
if(p)
{
llarp::LogError("no path found");
return false;
}
// TODO: check expiration of our end
ProtocolMessage m(f.T);
m.proto = t;
m.introReply = p->intro;
m.sender = m_Identity.pub;
m.PutBuffer(data);
f.N.Randomize();
f.S = GetSeqNoForConvo(f.T);
f.C.Zero();
transfer.Y.Randomize();
transfer.P = remoteIntro.pathID;
if(!f.EncryptAndSign(&Router()->crypto, m, K, m_Identity))
{
llarp::LogError("failed to encrypt and sign");
return false;
// TODO: check expiration of our end
ProtocolMessage m(f.T);
m.proto = t;
m.introReply = p->intro;
m.sender = m_Identity.pub;
m.PutBuffer(data);
f.N.Randomize();
f.S = GetSeqNoForConvo(f.T);
f.C.Zero();
transfer.Y.Randomize();
transfer.P = remoteIntro.pathID;
if(!f.EncryptAndSign(&Router()->crypto, m, K, m_Identity))
{
llarp::LogError("failed to encrypt and sign");
return false;
}
llarp::LogInfo(Name(), " send ", data.sz, " via ", remoteIntro);
return p->SendRoutingMessage(&transfer, Router());
}
llarp::LogInfo(Name(), " send ", data.sz, " via ", remoteIntro);
return p->SendRoutingMessage(&transfer, Router());
}
}
if(HasPathToService(remote))
@ -1242,7 +1240,7 @@ namespace llarp
f.T = *tags.begin();
f.S = m_Endpoint->GetSeqNoForConvo(f.T);
auto path = m_PathSet->GetPathByRouter(remoteIntro.router);
auto path = m_PathSet->GetNewestPathByRouter(remoteIntro.router);
if(!path)
{
llarp::LogError("cannot encrypt and send: no path for intro ",

Loading…
Cancel
Save