From dd136f7214cf68c9164fd32e76c48d2504a4e66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 8 Nov 2022 20:28:26 +0100 Subject: Test: make sure to report peer address when added --- src/main.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 95d3eeb..dad307c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -270,31 +270,34 @@ void startServer(const vector &) server->peerList().onUpdate([](size_t idx, const Peer * peer) { size_t i = 0; - while (idx > 0 && i < testPeers.size() && testPeers[i].deleted) { + while (idx > 0 && i < testPeers.size()) { if (!testPeers[i].deleted) idx--; i++; } - ostringstream ss; - ss << "peer " << i + 1; + string prefix = "peer " + to_string(i + 1); if (peer) { - if (i >= testPeers.size()) + if (i >= testPeers.size()) { testPeers.push_back(TestPeer { .peer = *peer, .id = i + 1 }); + const auto & paddr = peer->address(); + + ostringstream ss; + ss << prefix << " addr " << inet_ntoa(paddr.sin_addr) << " " << ntohs(paddr.sin_port); + printLine(ss.str()); + } if (peer->identity()) { - ss << " id"; + ostringstream ss; + ss << prefix << " id"; for (auto idt = peer->identity(); idt; idt = idt->owner()) ss << " " << (idt->name() ? *idt->name() : ""); - } else { - const auto & paddr = peer->address(); - ss << " addr " << inet_ntoa(paddr.sin_addr) << " " << ntohs(paddr.sin_port); + printLine(ss.str()); } } else { testPeers[i].deleted = true; - ss << " deleted"; + printLine(prefix + " deleted"); } - printLine(ss.str()); }); } -- cgit v1.2.3