summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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()) {