From aa1c1bad0b7b562f65dce2b7756860df289c5738 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 4 Jun 2021 09:03:18 -0400 Subject: [PATCH] record reason for path fail and the full hops --- llarp/messages/relay_status.cpp | 28 ++++++++++++++++++++++++++++ llarp/messages/relay_status.hpp | 3 +++ llarp/path/path.cpp | 9 ++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/llarp/messages/relay_status.cpp b/llarp/messages/relay_status.cpp index 9a72a07c8..dd02089fc 100644 --- a/llarp/messages/relay_status.cpp +++ b/llarp/messages/relay_status.cpp @@ -273,4 +273,32 @@ namespace llarp return status == other.status; } + std::string + LRStatusCodeToString(uint64_t status) + { + std::map codes = { + {LR_StatusRecord::SUCCESS, "success"}, + {LR_StatusRecord::FAIL_TIMEOUT, "timeout"}, + {LR_StatusRecord::FAIL_CONGESTION, "congestion"}, + {LR_StatusRecord::FAIL_DEST_UNKNOWN, "destination unknown"}, + {LR_StatusRecord::FAIL_DECRYPT_ERROR, "decrypt error"}, + {LR_StatusRecord::FAIL_MALFORMED_RECORD, "malformed record"}, + {LR_StatusRecord::FAIL_DEST_INVALID, "destination invalid"}, + {LR_StatusRecord::FAIL_CANNOT_CONNECT, "cannot connect"}, + {LR_StatusRecord::FAIL_DUPLICATE_HOP, "duplicate hop"}}; + std::stringstream ss; + ss << "["; + bool found = false; + for (const auto& [val, message] : codes) + { + if ((status & val) == val) + { + ss << (found ? ", " : "") << message; + found = true; + } + } + ss << "]"; + return ss.str(); + } + } // namespace llarp diff --git a/llarp/messages/relay_status.hpp b/llarp/messages/relay_status.hpp index 5faaf5946..e708e34e4 100644 --- a/llarp/messages/relay_status.hpp +++ b/llarp/messages/relay_status.hpp @@ -49,6 +49,9 @@ namespace llarp OnKey(llarp_buffer_t* buffer, llarp_buffer_t* key); }; + std::string + LRStatusCodeToString(uint64_t status); + struct LR_StatusMessage : public ILinkMessage { std::array frames; diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 986b5bd23..cb1d4d73d 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -199,7 +199,14 @@ namespace llarp if (failedAt) { r->NotifyRouterEvent(Endpoint(), RXID(), *failedAt); - LogWarn(Name(), " build failed at ", *failedAt); + LogWarn( + Name(), + " build failed at ", + *failedAt, + " status=", + LRStatusCodeToString(currentStatus), + " hops=", + HopsString()); r->routerProfiling().MarkHopFail(*failedAt); } else