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 MAXHOPS (8)
#define DEFAULT_PATH_LIFETIME (10 * 60 * 1000) #define DEFAULT_PATH_LIFETIME (10 * 60 * 1000)
#define PATH_BUILD_TIMEOUT (30 * 1000) #define PATH_BUILD_TIMEOUT (15 * 1000)
#define MESSAGE_PAD_SIZE (512) #define MESSAGE_PAD_SIZE (512)
namespace llarp namespace llarp

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

@ -64,6 +64,28 @@ namespace llarp
return path; 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* Path*
PathSet::GetPathByRouter(const RouterID& id) const PathSet::GetPathByRouter(const RouterID& id) const
{ {

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

Loading…
Cancel
Save