From 543994778151dbea3085d24a6946655fffb9a535 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 26 Jun 2018 10:52:19 -0400 Subject: [PATCH] fix path building so that it works for real --- Makefile | 2 +- include/llarp/pathset.hpp | 6 ++-- llarp/path.cpp | 7 +++++ llarp/pathset.cpp | 53 ++++++++++---------------------- llarp/routing/message_parser.cpp | 2 ++ llarp/transit_hop.cpp | 4 +-- 6 files changed, 31 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index 74f47f838..51fba0941 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/include/llarp/pathset.hpp b/include/llarp/pathset.hpp index afb7c35c5..fa1c74161 100644 --- a/include/llarp/pathset.hpp +++ b/include/llarp/pathset.hpp @@ -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 diff --git a/llarp/path.cpp b/llarp/path.cpp index 4e1ce967d..b9b689faa 100644 --- a/llarp/path.cpp +++ b/llarp/path.cpp @@ -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; diff --git a/llarp/pathset.cpp b/llarp/pathset.cpp index eb3503f5a..bf4a12f95 100644 --- a/llarp/pathset.cpp +++ b/llarp/pathset.cpp @@ -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 diff --git a/llarp/routing/message_parser.cpp b/llarp/routing/message_parser.cpp index 90a4e4f82..a61a5edfe 100644 --- a/llarp/routing/message_parser.cpp +++ b/llarp/routing/message_parser.cpp @@ -63,6 +63,8 @@ namespace llarp result = msg->HandleMessage(h); delete msg; } + else + llarp::Error("read dict failed"); return result; } } // namespace routing diff --git a/llarp/transit_hop.cpp b/llarp/transit_hop.cpp index dcb3ec2a5..ce3d92b3a 100644 --- a/llarp/transit_hop.cpp +++ b/llarp/transit_hop.cpp @@ -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);