diff --git a/include/llarp/path.hpp b/include/llarp/path.hpp index 8cd57fac0..c5bc32332 100644 --- a/include/llarp/path.hpp +++ b/include/llarp/path.hpp @@ -26,6 +26,7 @@ #define DEFAULT_PATH_LIFETIME (10 * 60 * 1000) #define PATH_BUILD_TIMEOUT (30 * 1000) #define MESSAGE_PAD_SIZE (512) +#define PATH_ALIVE_TIMEOUT (10 * 1000) namespace llarp { diff --git a/include/llarp/profiling.hpp b/include/llarp/profiling.hpp index 529f9beef..4010c9e91 100644 --- a/include/llarp/profiling.hpp +++ b/include/llarp/profiling.hpp @@ -38,7 +38,7 @@ namespace llarp } bool - IsBad(const RouterID& r, uint64_t chances = 8); + IsBad(const RouterID& r, uint64_t chances = 2); void MarkSuccess(const RouterID& r); diff --git a/include/llarp/service/endpoint.hpp b/include/llarp/service/endpoint.hpp index 8a4f86ce1..4254640b0 100644 --- a/include/llarp/service/endpoint.hpp +++ b/include/llarp/service/endpoint.hpp @@ -460,7 +460,7 @@ namespace llarp uint64_t m_CurrentPublishTX = 0; llarp_time_t m_LastPublish = 0; llarp_time_t m_LastPublishAttempt = 0; - llarp_time_t m_MinPathLatency = 10000; + llarp_time_t m_MinPathLatency = (5 * 1000); /// our introset service::IntroSet m_IntroSet; /// pending remote service lookups by id diff --git a/llarp/config.cpp b/llarp/config.cpp index 0f9b4201c..0e77ce74f 100644 --- a/llarp/config.cpp +++ b/llarp/config.cpp @@ -168,6 +168,10 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath) void llarp_ensure_router_config(std::ofstream &f, std::string basepath) { + f << "# network settings " << std::endl; + f << "[network]" << std::endl; + f << "profiles=" << basepath << "profiles.dat" << std::endl; + f << std::endl; f << "# ROUTERS ONLY: publish network interfaces for handling inbound traffic" << std::endl; f << "[bind]" << std::endl; @@ -192,6 +196,7 @@ llarp_ensure_client_config(std::ofstream &f, std::string basepath) f << "# network settings " << std::endl; f << "[network]" << std::endl; + f << "profiles=" << basepath << "profiles.dat" << std::endl; #ifndef __linux__ f << "# "; #endif diff --git a/llarp/path.cpp b/llarp/path.cpp index 9637867f8..e2c00b26f 100644 --- a/llarp/path.cpp +++ b/llarp/path.cpp @@ -431,7 +431,7 @@ namespace llarp if(_status == ePathEstablished) { if(m_LastRecvMessage && now > m_LastRecvMessage - && now - m_LastRecvMessage > (20 * 1000)) + && now - m_LastRecvMessage > PATH_ALIVE_TIMEOUT) { if(m_CheckForDead) { @@ -441,6 +441,11 @@ namespace llarp EnterState(ePathTimeout); } } + else + { + r->routerProfiling.MarkPathFail(this); + EnterState(ePathTimeout); + } } else if(dlt >= 10000 && m_LastRecvMessage == 0) { diff --git a/llarp/router.cpp b/llarp/router.cpp index 1e3a52bde..be463a156 100644 --- a/llarp/router.cpp +++ b/llarp/router.cpp @@ -135,11 +135,6 @@ bool llarp_router::HandleRecvLinkMessageBuffer(llarp::ILinkSession *session, llarp_buffer_t buf) { - if(!session) - { - llarp::LogWarn("no link session"); - return false; - } return inbound_link_msg_parser.ProcessFrom(session, buf); } @@ -648,7 +643,9 @@ void llarp_router::Run() { routerProfiling.Load(routerProfilesFile.string().c_str()); - llarp::Addr publicAddr(this->ip4addr); + // zero out router contact + sockaddr *dest = (sockaddr *)&this->ip4addr; + llarp::Addr publicAddr(*dest); if(this->publicOverride) { if(publicAddr) @@ -684,20 +681,14 @@ llarp_router::Run() } else { - if(inboundLinks.size()) + if(!inboundLinks.size()) { - link = inboundLinks[0].get(); - } - else - { - llarp::LogWarn( - "No need to set public ipv4 and port if no external interface " - "binds, turning off public override"); - this->publicOverride = false; - link = nullptr; + llarp::LogError("No inbound links found, aborting"); + return; } + link = inboundLinks[0].get(); } - if(link && link->GetOurAddressInfo(this->addrInfo)) + if(link->GetOurAddressInfo(this->addrInfo)) { // override ip and port this->addrInfo.ip = *publicAddr.addr6(); @@ -769,13 +760,9 @@ llarp_router::Run() return; } - // don't create default if we already have some defined - if(this->ShouldCreateDefaultHiddenService()) - { - // generate default hidden service - if(!CreateDefaultHiddenService()) - return; - } + // generate default hidden service + if(!CreateDefaultHiddenService()) + return; // delayed connect all for clients uint64_t delay = ((llarp_randint() % 10) * 500) + 500; llarp_logic_call_later(logic, {delay, this, &ConnectAll}); @@ -788,54 +775,6 @@ llarp_router::Run() ScheduleTicker(1000); } -bool -llarp_router::ShouldCreateDefaultHiddenService() -{ - // llarp::LogInfo("IfName: ", this->defaultIfName, " defaultIfName: ", - // this->defaultIfName); - if(this->defaultIfName == "auto" || this->defaultIfName == "auto") - { - // auto detect if we have any pre-defined endpoints - // no if we have a endpoints - llarp::LogInfo("Auto mode detected, hasEndpoints: ", - std::to_string(this->hiddenServiceContext.hasEndpoints())); - if(this->hiddenServiceContext.hasEndpoints()) - return false; - // we don't have any endpoints, auto configure settings - - // set a default IP range - this->defaultIfAddr = llarp::findFreePrivateRange(); - if(this->defaultIfAddr == "") - { - llarp::LogError( - "Could not find any free lokitun interface names, can't auto set up " - "default HS context for client"); - this->defaultIfAddr = "no"; - return false; - } - - // pick an ifName - this->defaultIfName = llarp::findFreeLokiTunIfName(); - if(this->defaultIfName == "") - { - llarp::LogError( - "Could not find any free private ip ranges, can't auto set up " - "default HS context for client"); - this->defaultIfName = "no"; - return false; - } - // auto config'd, go ahead and create it - return true; - } - // not auto mode then just check to make sure it's explicitly disabled - if(this->defaultIfAddr != "" && this->defaultIfAddr != "no" - && this->defaultIfName != "" && this->defaultIfName != "no") - { - return true; - } - return false; -} - void llarp_router::InitServiceNode() { @@ -1133,7 +1072,7 @@ namespace llarp } if(StrEq(key, "ifname")) { - self->defaultIfName = val; + self->defaultIfAddr = val; } if(StrEq(key, "enabled")) { @@ -1200,10 +1139,10 @@ namespace llarp if(strlen(val) < 17) { // assume IPv4 - // inet_pton(AF_INET, val, &self->ip4addr.sin_addr); + inet_pton(AF_INET, val, &self->ip4addr.sin_addr); // struct sockaddr dest; - // sockaddr *dest = (sockaddr *)&self->ip4addr; - llarp::Addr a(val); + sockaddr *dest = (sockaddr *)&self->ip4addr; + llarp::Addr a(*dest); llarp::LogInfo("setting public ipv4 ", a); self->addrInfo.ip = *a.addr6(); self->publicOverride = true; diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 1c779ee94..ea5f26515 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -926,6 +926,29 @@ namespace llarp Endpoint::OutboundContext::SwapIntros() { remoteIntro = m_NextIntro; + // prepare next intro + auto now = llarp_time_now_ms(); + for(const auto& intro : currentIntroSet.I) + { + if(intro.ExpiresSoon(now)) + continue; + if(m_BadIntros.find(intro) == m_BadIntros.end() + && remoteIntro.router == intro.router) + { + m_NextIntro = intro; + return; + } + } + for(const auto& intro : currentIntroSet.I) + { + if(intro.ExpiresSoon(now)) + continue; + if(m_BadIntros.find(intro) == m_BadIntros.end()) + { + m_NextIntro = intro; + return; + } + } } bool