|
|
|
|
@ -26,6 +26,7 @@
|
|
|
|
|
#include "topo_group.h" |
|
|
|
|
#include "topo_node.h" |
|
|
|
|
#include "topo_node_sqlite.h" |
|
|
|
|
#include "../utun_instance.h" |
|
|
|
|
#include "../transport_layer/node_conn_direct.h" |
|
|
|
|
#include "../lib/debug_config.h" |
|
|
|
|
#include "../lib/mem.h" |
|
|
|
|
@ -523,3 +524,59 @@ static void tgc_cycle_restart(struct TOPO_GROUP_CONNECT* gc) {
|
|
|
|
|
gc->phase_timer = uasync_set_timeout(gc->group->instance->ua, |
|
|
|
|
TGC_DIRECT_TIMEOUT_MS * 10, gc, tgc_phase1_timeout, "tgc_phase1"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* ═══════════════════════════════════════════════════════════════════════
|
|
|
|
|
* Однократное подключение к конкретному узлу (ручной "Connect" из GUI) |
|
|
|
|
* ══════════════════════════════════════════════════════════════════════ */ |
|
|
|
|
|
|
|
|
|
struct tgc_once_ctx { |
|
|
|
|
struct TOPO_GROUP* group; |
|
|
|
|
uint64_t node_id; |
|
|
|
|
struct NODE_CONN_DIRECT* h; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void tgc_once_cb(struct NODE_CONN_DIRECT* h, enum ncd_event ev, void* arg) { |
|
|
|
|
struct tgc_once_ctx* c = (struct tgc_once_ctx*)arg; |
|
|
|
|
struct ETCP_CONN* conn = node_conn_direct_get_conn(h); |
|
|
|
|
|
|
|
|
|
if (ev == NCD_EVENT_UP && conn) { |
|
|
|
|
struct TOPO_GROUP_NODE* nq = topo_node_find_by_id(c->group, c->node_id); |
|
|
|
|
if (nq) nq->handle = h; |
|
|
|
|
node_conn_direct_set_callback(h, NULL, NULL); |
|
|
|
|
topo_group_new_conn(c->group, conn); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s: once-connect UP node=0x%016llx ch=%s", |
|
|
|
|
TGC_ID, (unsigned long long)c->node_id, c->group->channel_id); |
|
|
|
|
} else if (ev == NCD_EVENT_TIMEOUT) { |
|
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_BGP, "%s: once-connect TIMEOUT node=0x%016llx ch=%s", |
|
|
|
|
TGC_ID, (unsigned long long)c->node_id, c->group->channel_id); |
|
|
|
|
node_conn_direct_close(h); |
|
|
|
|
} else if (ev == NCD_EVENT_DOWN) { |
|
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_BGP, "%s: once-connect DOWN node=0x%016llx ch=%s", |
|
|
|
|
TGC_ID, (unsigned long long)c->node_id, c->group->channel_id); |
|
|
|
|
node_conn_direct_close(h); |
|
|
|
|
} |
|
|
|
|
u_free(c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int topo_group_connect_node_once(struct TOPO_GROUP* group, uint64_t node_id) { |
|
|
|
|
if (!group || group->group_type != TOPO_GROUP_TYPE_CHAT || !node_id) return -1; |
|
|
|
|
if (node_id == group->instance->node_id) return -1; |
|
|
|
|
|
|
|
|
|
struct ETCP_CONN* ex = instance_find_conn(group->instance, node_id); |
|
|
|
|
if (ex && ex->links_up && ex->initialized) { |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s: once-connect node=0x%016llx already connected — add to group ch=%s", |
|
|
|
|
TGC_ID, (unsigned long long)node_id, group->channel_id); |
|
|
|
|
topo_group_new_conn(group, ex); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct tgc_once_ctx* c = u_calloc(1, sizeof(*c)); |
|
|
|
|
if (!c) return -1; |
|
|
|
|
c->group = group; c->node_id = node_id; |
|
|
|
|
|
|
|
|
|
int r = node_conn_direct_open(group->instance, node_id, tgc_once_cb, c, &c->h, NULL); |
|
|
|
|
if (r == NCD_ERR || !c->h) { u_free(c); return -1; } |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s: once-connect node=0x%016llx ch=%s started (rc=%d)", |
|
|
|
|
TGC_ID, (unsigned long long)node_id, group->channel_id, r); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|