summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2021-12-09 22:45:43 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2021-12-09 22:45:59 +0100
commit380f8e539d73f37c2ef5d7133d3e1b6dda105f4a (patch)
tree505f743d8de3e1fcb20f10e99ab56f81feae8461 /src
parent1cef5fc2744d2428f28976c7adb0f476d8bc3bcf (diff)
Test: distinguish address and identity info for peers
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp17
-rw-r--r--src/network.cpp7
2 files changed, 20 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index a3805e0..b061747 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4,6 +4,10 @@
#include <erebos/storage.h>
#include <erebos/sync.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
#include <filesystem>
#include <functional>
#include <future>
@@ -140,11 +144,16 @@ void startServer(const vector<string> &)
server->peerList().onUpdate([](size_t idx, const Peer * peer) {
ostringstream ss;
- ss << "peer " << idx;
+ ss << "peer " << idx + 1;
if (peer) {
- ss << " " << peer->name();
- if (peer->identity() && peer->identity()->name())
- ss << " " << *peer->identity()->name();
+ if (peer->identity()) {
+ ss << " 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);
+ }
} else {
ss << " deleted";
}
diff --git a/src/network.cpp b/src/network.cpp
index 1d38bdd..b735262 100644
--- a/src/network.cpp
+++ b/src/network.cpp
@@ -116,6 +116,13 @@ optional<Identity> Peer::identity() const
return nullopt;
}
+const sockaddr_in & Peer::address() const
+{
+ if (auto speer = p->speer.lock())
+ return speer->addr;
+ throw runtime_error("Server no longer running");
+}
+
void Peer::Priv::notifyWatchers()
{
if (auto slist = list.lock()) {