diff --git a/include/llarp/dht/context.hpp b/include/llarp/dht/context.hpp index 412de7cf0..3d2a6323b 100644 --- a/include/llarp/dht/context.hpp +++ b/include/llarp/dht/context.hpp @@ -72,7 +72,7 @@ namespace llarp void PropagateIntroSetTo(const Key_t& from, uint64_t fromTX, const service::IntroSet& introset, const Key_t& peer, - uint64_t S); + uint64_t S, const std::set< Key_t >& exclude); void Init(const Key_t& us, llarp_router* router); diff --git a/include/llarp/logger.hpp b/include/llarp/logger.hpp index dddd0834b..4e05e80b4 100644 --- a/include/llarp/logger.hpp +++ b/include/llarp/logger.hpp @@ -97,7 +97,6 @@ namespace llarp } } // namespace llarp - #define LogDebug(x, ...) _Log(llarp::eLogDebug, LOG_TAG, x, ##__VA_ARGS__) #define LogInfo(x, ...) _Log(llarp::eLogInfo, LOG_TAG, x, ##__VA_ARGS__) #define LogWarn(x, ...) _Log(llarp::eLogWarn, LOG_TAG, x, ##__VA_ARGS__) @@ -108,5 +107,8 @@ namespace llarp #define LogWarnTag(tag, x, ...) _Log(llarp::eLogWarn, tag, x, ##__VA_ARGS__) #define LogErrorTag(tag, x, ...) _Log(llarp::eLogError, tag, x, ##__VA_ARGS__) +#ifndef LOG_TAG +#define LOG_TAG "default" +#endif #endif diff --git a/include/llarp/pathset.hpp b/include/llarp/pathset.hpp index 5d3b392b5..a7492c7d5 100644 --- a/include/llarp/pathset.hpp +++ b/include/llarp/pathset.hpp @@ -51,7 +51,7 @@ namespace llarp AddPath(Path* path); Path* - GetByUpstream(const RouterID& remote, const PathID_t& rxid); + GetByUpstream(const RouterID& remote, const PathID_t& rxid) const; void ExpirePaths(llarp_time_t now); @@ -79,10 +79,13 @@ namespace llarp } Path* - PickRandomEstablishedPath(); + GetEstablishedPathClosestTo(const RouterID& router) const; Path* - GetPathByRouter(const RouterID& router); + PickRandomEstablishedPath() const; + + Path* + GetPathByRouter(const RouterID& router) const; bool GetCurrentIntroductions( diff --git a/llarp/dht/context.cpp b/llarp/dht/context.cpp index 32371eed3..4304b99af 100644 --- a/llarp/dht/context.cpp +++ b/llarp/dht/context.cpp @@ -90,12 +90,17 @@ namespace llarp void Context::PropagateIntroSetTo(const Key_t &from, uint64_t txid, const service::IntroSet &introset, - const Key_t &peer, uint64_t S) + const Key_t &peer, uint64_t S, + const std::set< Key_t > &exclude) { llarp::LogInfo("Propagate Introset for ", introset.A.Name(), " to ", peer); auto id = ++ids; + std::vector< Key_t > E; + for(const auto &ex : exclude) + E.push_back(ex); + TXOwner ownerKey; ownerKey.node = peer; ownerKey.txid = id; @@ -103,7 +108,7 @@ namespace llarp [](const std::vector< service::IntroSet > &) {}); pendingTX[ownerKey] = job; auto msg = new llarp::DHTImmeidateMessage(peer); - msg->msgs.push_back(new PublishIntroMessage(introset, id, S)); + msg->msgs.push_back(new PublishIntroMessage(introset, id, S, E)); router->SendToOrQueue(peer, msg); } diff --git a/llarp/dht/publish_intro.cpp b/llarp/dht/publish_intro.cpp index 8eb382025..d5ca20139 100644 --- a/llarp/dht/publish_intro.cpp +++ b/llarp/dht/publish_intro.cpp @@ -76,7 +76,7 @@ namespace llarp exclude.insert(dht.OurKey()); if(S && dht.nodes->FindCloseExcluding(addr, peer, exclude)) { - dht.PropagateIntroSetTo(From, txID, I, peer, S - 1); + dht.PropagateIntroSetTo(From, txID, I, peer, S - 1, exclude); } return true; } diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index 3400f0663..db37b3713 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -520,7 +520,7 @@ handle_generated_intro(iwp_async_intro *i) } link->EnterState(llarp_link_session::eIntroSent); link->lastIntroSentAt = llarp_time_now_ms(); - auto dlt = (link->createdAt - link->lastIntroSentAt); + auto dlt = (link->createdAt - link->lastIntroSentAt) + 500; auto logic = link->serv->logic; link->intro_resend_job_id = llarp_logic_call_later( logic, {dlt, link, &llarp_link_session::handle_introack_timeout}); diff --git a/llarp/pathset.cpp b/llarp/pathset.cpp index b08aa1574..e5fde8d9b 100644 --- a/llarp/pathset.cpp +++ b/llarp/pathset.cpp @@ -46,7 +46,25 @@ namespace llarp } Path* - PathSet::GetPathByRouter(const RouterID& id) + PathSet::GetEstablishedPathClosestTo(const RouterID& id) const + { + Path* path = nullptr; + RouterID dist; + dist.Fill(0xff); + for(const auto& item : m_Paths) + { + RouterID localDist = item.second->Endpoint() ^ id; + if(localDist < dist) + { + dist = localDist; + path = item.second; + } + } + return path; + } + + Path* + PathSet::GetPathByRouter(const RouterID& id) const { auto itr = m_Paths.begin(); while(itr != m_Paths.end()) @@ -89,7 +107,7 @@ namespace llarp } Path* - PathSet::GetByUpstream(const RouterID& remote, const PathID_t& rxid) + PathSet::GetByUpstream(const RouterID& remote, const PathID_t& rxid) const { auto itr = m_Paths.find({remote, rxid}); if(itr == m_Paths.end()) @@ -125,7 +143,7 @@ namespace llarp } Path* - PathSet::PickRandomEstablishedPath() + PathSet::PickRandomEstablishedPath() const { std::vector< Path* > established; auto itr = m_Paths.begin();