From a7a101e33ce3e34762a9888e4db1751810bd4c69 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 3 Jan 2020 07:52:19 -0500 Subject: [PATCH] more intellegent path failure profiling using LRSM --- llarp/path/path.cpp | 30 +++++++++++++++++++++++------- llarp/profiling.cpp | 8 ++++++++ llarp/profiling.hpp | 3 +++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index c442cc250..c7cbaf85c 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -135,11 +135,13 @@ namespace llarp uint64_t currentStatus = status; size_t index = 0; + absl::optional< RouterID > failedAt; while(index < hops.size()) { if(!frames[index].DoDecrypt(hops[index].shared)) { currentStatus = LR_StatusRecord::FAIL_DECRYPT_ERROR; + failedAt = hops[index].rc.pubkey; break; } llarp::LogDebug("decrypted LRSM frame from ", hops[index].rc.pubkey); @@ -154,22 +156,31 @@ namespace llarp llarp::LogWarn("malformed frame inside LRCM from ", hops[index].rc.pubkey); currentStatus = LR_StatusRecord::FAIL_MALFORMED_RECORD; + failedAt = hops[index].rc.pubkey; break; } llarp::LogDebug("Decoded LR Status Record from ", hops[index].rc.pubkey); currentStatus = record.status; - - if((currentStatus & LR_StatusRecord::SUCCESS) == 0) + if((record.status & LR_StatusRecord::SUCCESS) + != LR_StatusRecord::SUCCESS) { + // failed at next hop + if(index + 1 < hops.size()) + { + failedAt = hops[index + 1].rc.pubkey; + } + else + { + failedAt = hops[index].rc.pubkey; + } break; } - ++index; } - if(currentStatus & LR_StatusRecord::SUCCESS) + if((currentStatus & LR_StatusRecord::SUCCESS) == LR_StatusRecord::SUCCESS) { llarp::LogDebug("LR_Status message processed, path build successful"); auto self = shared_from_this(); @@ -177,8 +188,13 @@ namespace llarp } else { - r->routerProfiling().MarkPathFail(this); - + if(failedAt.has_value()) + { + LogWarn(Name(), " build failed at ", failedAt.value()); + r->routerProfiling().MarkHopFail(failedAt.value()); + } + else + r->routerProfiling().MarkPathFail(this); llarp::LogDebug("LR_Status message processed, path build failed"); if(currentStatus & LR_StatusRecord::FAIL_TIMEOUT) @@ -230,7 +246,7 @@ namespace llarp // TODO: meaningful return value? return true; - } + } // namespace path void Path::EnterState(PathStatus st, llarp_time_t now) diff --git a/llarp/profiling.cpp b/llarp/profiling.cpp index b6764eef9..3ee2ea0b5 100644 --- a/llarp/profiling.cpp +++ b/llarp/profiling.cpp @@ -180,6 +180,14 @@ namespace llarp m_Profiles.erase(r); } + void + Profiling::MarkHopFail(const RouterID& r) + { + lock_t lock(&m_ProfilesMutex); + m_Profiles[r].pathFailCount += 1; + m_Profiles[r].lastUpdated = llarp::time_now_ms(); + } + void Profiling::MarkPathFail(path::Path* p) { diff --git a/llarp/profiling.hpp b/llarp/profiling.hpp index f82c93169..ebb205f69 100644 --- a/llarp/profiling.hpp +++ b/llarp/profiling.hpp @@ -77,6 +77,9 @@ namespace llarp void MarkPathSuccess(path::Path* p) LOCKS_EXCLUDED(m_ProfilesMutex); + void + MarkHopFail(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex); + void ClearProfile(const RouterID& r) LOCKS_EXCLUDED(m_ProfilesMutex);