fix path building so that it works for real

pull/3/head
Jeff Becker 6 years ago
parent 6633fb151d
commit 5439947781
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -66,7 +66,7 @@ testnet-build: testnet-configure
testnet: testnet-build
mkdir -p $(TESTNET_ROOT)
python3 contrib/testnet/genconf.py --bin=$(REPO)/llarpd --svc=5 --clients=10 --dir=$(TESTNET_ROOT) --out $(TESTNET_CONF)
python3 contrib/testnet/genconf.py --bin=$(REPO)/llarpd --svc=5 --clients=1 --dir=$(TESTNET_ROOT) --out $(TESTNET_CONF)
supervisord -n -d $(TESTNET_ROOT) -l $(TESTNET_LOG) -c $(TESTNET_CONF)
test: debug-configure

@ -49,11 +49,11 @@ namespace llarp
ShouldBuildMore() const;
private:
typedef std::map< PathID_t, Path* > PathMap_t;
typedef std::pair< RouterID, PathID_t > PathInfo_t;
typedef std::map< PathInfo_t, Path* > PathMap_t;
size_t m_NumPaths;
PathMap_t m_Tx;
PathMap_t m_Rx;
PathMap_t m_Paths;
};
} // namespace path

@ -266,10 +266,16 @@ namespace llarp
hops[idx].txID.Randomize();
hops[idx].rxID.Randomize();
}
/*
for(size_t idx = (h->numHops - 1); idx > 0; --idx)
{
hops[idx].txID = hops[idx - 1].rxID;
}
*/
for(size_t idx = 0; idx < h->numHops - 1; ++idx)
{
hops[idx].txID = hops[idx + 1].rxID;
}
}
void
@ -376,6 +382,7 @@ namespace llarp
{
// confirm that we build the path
status = ePathEstablished;
llarp::Info("path is confirmed rx=", RXID(), " tx=", TXID());
if(m_BuiltHook)
m_BuiltHook(this);
m_BuiltHook = nullptr;

@ -12,37 +12,22 @@ namespace llarp
bool
PathSet::ShouldBuildMore() const
{
return m_Tx.size() < m_NumPaths;
return m_Paths.size() < m_NumPaths;
}
void
PathSet::ExpirePaths(llarp_time_t now)
{
auto itr = m_Paths.begin();
while(itr != m_Paths.end())
{
auto itr = m_Rx.begin();
while(itr != m_Rx.end())
if(itr->second->Expired(now))
{
if(itr->second->Expired(now))
{
itr = m_Rx.erase(itr);
}
else
++itr;
}
}
{
auto itr = m_Tx.begin();
while(itr != m_Tx.end())
{
if(itr->second->Expired(now))
{
// delete path on second iteration
delete itr->second;
itr = m_Tx.erase(itr);
}
else
++itr;
delete itr->second;
itr = m_Paths.erase(itr);
}
else
++itr;
}
}
@ -50,8 +35,8 @@ namespace llarp
PathSet::NumInStatus(PathStatus st) const
{
size_t count = 0;
auto itr = m_Tx.begin();
while(itr != m_Tx.end())
auto itr = m_Paths.begin();
while(itr != m_Paths.end())
{
if(itr->second->status == st)
++count;
@ -63,28 +48,22 @@ namespace llarp
void
PathSet::AddPath(Path* path)
{
m_Tx.emplace(path->TXID(), path);
m_Rx.emplace(path->RXID(), path);
m_Paths.emplace(std::make_pair(path->Upstream(), path->RXID()), path);
}
void
PathSet::RemovePath(Path* path)
{
m_Tx.erase(path->TXID());
m_Rx.erase(path->RXID());
m_Paths.erase({path->Upstream(), path->RXID()});
}
Path*
PathSet::GetByUpstream(const RouterID& remote, const PathID_t& rxid)
{
auto itr = m_Rx.begin();
while(itr != m_Rx.end())
{
if(itr->second->Upstream() == remote)
return itr->second;
++itr;
}
return nullptr;
auto itr = m_Paths.find({remote, rxid});
if(itr == m_Paths.end())
return nullptr;
return itr->second;
}
void

@ -63,6 +63,8 @@ namespace llarp
result = msg->HandleMessage(h);
delete msg;
}
else
llarp::Error("read dict failed");
return result;
}
} // namespace routing

@ -62,7 +62,7 @@ namespace llarp
llarp_router* r)
{
RelayDownstreamMessage* msg = new RelayDownstreamMessage;
msg->pathid = info.txID;
msg->pathid = info.rxID;
msg->Y = Y;
r->crypto.xchacha20(buf, pathKey, Y);
@ -77,7 +77,7 @@ namespace llarp
llarp_router* r)
{
RelayUpstreamMessage* msg = new RelayUpstreamMessage;
msg->pathid = info.rxID;
msg->pathid = info.txID;
msg->Y = Y;
r->crypto.xchacha20(buf, pathKey, Y);

Loading…
Cancel
Save