Browse Source

Expose actual NCD handle ownership for an ETCP transport

master
evgeny 15 hours ago
parent
commit
0d7f7630b0
  1. 9
      src/transport_layer/node_conn_direct.c
  2. 3
      src/transport_layer/node_conn_direct.h

9
src/transport_layer/node_conn_direct.c

@ -91,6 +91,15 @@ static struct ncd_entry* ncd_registry_find(struct UTUN_INSTANCE* inst, uint64_t
while (e) { if (e->node_id == node_id && !e->closed && !e->conn->close_requested && e->conn->state != 2) return e; e = e->next; } while (e) { if (e->node_id == node_id && !e->closed && !e->conn->close_requested && e->conn->state != 2) return e; e = e->next; }
return NULL; return NULL;
} }
// Проверка владения по объекту conn исключает смешение старого и нового транспорта одного пира.
int node_conn_direct_handle_count(const struct ETCP_CONN* conn) {
if (!conn || !conn->instance) return 0;
for (const struct ncd_entry* entry = conn->instance->ncd_registry; entry; entry = entry->next)
if (entry->conn == conn && !entry->closed) return entry->handle_count;
return 0;
}
static int ncd_registry_add(struct UTUN_INSTANCE* inst, struct ncd_entry* entry) { static int ncd_registry_add(struct UTUN_INSTANCE* inst, struct ncd_entry* entry) {
entry->inst = inst; entry->inst = inst;
if (etcp_conn_ref_take(entry->conn) != 0) { DEBUG_ERROR(DEBUG_CATEGORY_NCD, "[ncd] register closing conn"); return -1; } if (etcp_conn_ref_take(entry->conn) != 0) { DEBUG_ERROR(DEBUG_CATEGORY_NCD, "[ncd] register closing conn"); return -1; }

3
src/transport_layer/node_conn_direct.h

@ -39,6 +39,9 @@ struct ETCP_SOCKET;
/* Привязать CLOSE/KEEP_ALIVE при запуске ядра, в том числе без исходящих handles. */ /* Привязать CLOSE/KEEP_ALIVE при запуске ядра, в том числе без исходящих handles. */
int node_conn_direct_init(struct UTUN_INSTANCE* inst); int node_conn_direct_init(struct UTUN_INSTANCE* inst);
/* Число локальных владельцев конкретного транспорта; внешние ETCP refs сюда не входят. */
int node_conn_direct_handle_count(const struct ETCP_CONN* conn);
/* ─── Return codes ─── */ /* ─── Return codes ─── */
#define NCD_NEW 0 /* создано новое соединение */ #define NCD_NEW 0 /* создано новое соединение */
#define NCD_REUSED 1 /* переиспользовано существующее */ #define NCD_REUSED 1 /* переиспользовано существующее */

Loading…
Cancel
Save