Loading src/cluster.cpp +41 −2 Changes for src/cluster.cpp: 41 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -46,6 +46,9 @@ #pragma comment(lib, "ws2_32.lib") #else #include <unistd.h> #include <ifaddrs.h> #include <netinet/in.h> #include <arpa/inet.h> #endif namespace authdb { Loading Loading @@ -269,13 +272,49 @@ namespace authdb { // Setup client for talking to peers — filter out self size_t peer_count = 0; if (!cfg_.peers.empty()) { // Collect all local identities: hostname + all local IP addresses std::vector<std::string> local_addrs; { char hostname[256] = {}; gethostname(hostname, sizeof(hostname)); std::string self_host(hostname); local_addrs.emplace_back(hostname); } #ifndef _WIN32 { struct ifaddrs *ifaddr = nullptr; if (getifaddrs(&ifaddr) == 0) { for (struct ifaddrs *ifa = ifaddr; ifa; ifa = ifa->ifa_next) { if (!ifa->ifa_addr) continue; char buf[INET6_ADDRSTRLEN] = {}; if (ifa->ifa_addr->sa_family == AF_INET) { inet_ntop(AF_INET, &reinterpret_cast<struct sockaddr_in*>(ifa->ifa_addr)->sin_addr, buf, sizeof(buf)); local_addrs.emplace_back(buf); } else if (ifa->ifa_addr->sa_family == AF_INET6) { inet_ntop(AF_INET6, &reinterpret_cast<struct sockaddr_in6*>(ifa->ifa_addr)->sin6_addr, buf, sizeof(buf)); local_addrs.emplace_back(buf); } } freeifaddrs(ifaddr); } } #endif std::vector<paritypp::client::node_info> nodes; for (const auto &peer : cfg_.peers) { if (peer.address == self_host && peer.port == cfg_.port) { bool is_self = false; if (peer.port == cfg_.port) { for (const auto &addr : local_addrs) { if (peer.address == addr) { is_self = true; break; } } } if (is_self) { std::cerr << "Cluster: skipping self (" << peer.address << ":" << peer.port << ")" << std::endl; continue; Loading Loading
src/cluster.cpp +41 −2 Changes for src/cluster.cpp: 41 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -46,6 +46,9 @@ #pragma comment(lib, "ws2_32.lib") #else #include <unistd.h> #include <ifaddrs.h> #include <netinet/in.h> #include <arpa/inet.h> #endif namespace authdb { Loading Loading @@ -269,13 +272,49 @@ namespace authdb { // Setup client for talking to peers — filter out self size_t peer_count = 0; if (!cfg_.peers.empty()) { // Collect all local identities: hostname + all local IP addresses std::vector<std::string> local_addrs; { char hostname[256] = {}; gethostname(hostname, sizeof(hostname)); std::string self_host(hostname); local_addrs.emplace_back(hostname); } #ifndef _WIN32 { struct ifaddrs *ifaddr = nullptr; if (getifaddrs(&ifaddr) == 0) { for (struct ifaddrs *ifa = ifaddr; ifa; ifa = ifa->ifa_next) { if (!ifa->ifa_addr) continue; char buf[INET6_ADDRSTRLEN] = {}; if (ifa->ifa_addr->sa_family == AF_INET) { inet_ntop(AF_INET, &reinterpret_cast<struct sockaddr_in*>(ifa->ifa_addr)->sin_addr, buf, sizeof(buf)); local_addrs.emplace_back(buf); } else if (ifa->ifa_addr->sa_family == AF_INET6) { inet_ntop(AF_INET6, &reinterpret_cast<struct sockaddr_in6*>(ifa->ifa_addr)->sin6_addr, buf, sizeof(buf)); local_addrs.emplace_back(buf); } } freeifaddrs(ifaddr); } } #endif std::vector<paritypp::client::node_info> nodes; for (const auto &peer : cfg_.peers) { if (peer.address == self_host && peer.port == cfg_.port) { bool is_self = false; if (peer.port == cfg_.port) { for (const auto &addr : local_addrs) { if (peer.address == addr) { is_self = true; break; } } } if (is_self) { std::cerr << "Cluster: skipping self (" << peer.address << ":" << peer.port << ")" << std::endl; continue; Loading