fix: getInviteAddresses — use active direct-IP connections instead of DB peer list
Priority: iterate instance->connections for links with NAT_TYPE_DIRECT (connected and reachable). Fallback: own socket addresses. Removed broken getOnlinePeerAddresses() which returned other nodes' addresses.
This commit is contained in:
1 parent
2aa559acaf
commit
55e3a7af94
1 file changed
+30
-4
@@ -103,12 +103,38 @@ QString UtunNode::pubKeyHex() const {
|
||||
}
|
||||
|
||||
QList<NodeAddr> UtunNode::getInviteAddresses(DbManager* db) {
|
||||
(void)db;
|
||||
QList<NodeAddr> addrs;
|
||||
|
||||
if (db && db->isOpen()) {
|
||||
QList<NodeAddr> peerAddrs = db->getOnlinePeerAddresses(db->myNodeId());
|
||||
for (int i = 0; i < peerAddrs.size() && i < 2; i++)
|
||||
addrs.append(peerAddrs[i]);
|
||||
if (m_instance) {
|
||||
struct ll_entry* entry = m_instance->connections->head;
|
||||
while (entry) {
|
||||
struct conn_queue_entry* ce = (struct conn_queue_entry*)entry->data;
|
||||
struct ETCP_CONN* conn = ce->conn;
|
||||
if (conn && conn->initialized && conn->links_up > 0) {
|
||||
struct ETCP_LINK* link = conn->links;
|
||||
while (link) {
|
||||
if (link->link_state == 3 && link->nat_type == NAT_TYPE_DIRECT) {
|
||||
NodeAddr a;
|
||||
struct sockaddr_storage* sa = &link->remote_addr;
|
||||
if (sa->ss_family == AF_INET) {
|
||||
struct sockaddr_in* sin = (struct sockaddr_in*)sa;
|
||||
a.family = 4;
|
||||
a.address = QByteArray((const char*)&sin->sin_addr, 4);
|
||||
a.port = ntohs(sin->sin_port);
|
||||
} else {
|
||||
struct sockaddr_in6* sin6 = (struct sockaddr_in6*)sa;
|
||||
a.family = 6;
|
||||
a.address = QByteArray((const char*)&sin6->sin6_addr, 16);
|
||||
a.port = ntohs(sin6->sin6_port);
|
||||
}
|
||||
addrs.append(a);
|
||||
}
|
||||
link = link->next;
|
||||
}
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (addrs.isEmpty() && m_instance) {
|
||||
|
||||
Reference in new issue
Block a user