diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-11-08 20:28:26 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-11-08 20:30:43 +0100 |
commit | dd136f7214cf68c9164fd32e76c48d2504a4e66a (patch) | |
tree | 6ff4402204ac78af4532bf0991e2e0162fcfd341 /src | |
parent | 4d82c7e2704c035e33b9b606c409e5fac0f4f708 (diff) |
Test: make sure to report peer address when added
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 23 |
1 files 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<string> &) 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() : "<unnamed>"); - } 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()); }); } |