Publish incoming UDP peers before callbacks and preserve accepted ownership
This commit is contained in:
1 parent
c7d7789a58
commit
032f8e83b2
2 files changed
+18
-22
No files matched your search
@@ -138,7 +138,7 @@ void tcp_server_on_link(struct stcp_link *link, struct ETCP_SOCKET *tcp_sock) {
|
||||
etcp_connection_close(conn); stcp_link_close(link); return;
|
||||
}
|
||||
etcp_update_log_name(conn);
|
||||
{ struct conn_queue_entry* ce = (struct conn_queue_entry*)conn->conn_queue_entry->data; ce->peer_node_id = node_id; queue_remove_data(conn->conn_queue, conn->conn_queue_entry); queue_data_put_with_index(conn->conn_queue, conn->conn_queue_entry); }
|
||||
if (etcp_conn_index_peer(conn) < 0) { etcp_connection_close(conn); stcp_link_close(link); return; }
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "tcp_server_on_link: new ETCP_CONN peer=0x%016llx", (unsigned long long)node_id);
|
||||
}
|
||||
|
||||
@@ -2514,6 +2514,9 @@ static void etcp_process_packet(struct ETCP_SOCKET* e_sock, uint8_t* data,
|
||||
(unsigned long long)peer_id, conn->crypto_ctx.session_ready);
|
||||
conn->peer_node_id = peer_id;
|
||||
etcp_update_log_name(conn);
|
||||
if (etcp_conn_index_peer(conn) < 0) {
|
||||
etcp_connection_close(conn); errorcode = 55; goto ec_fr;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "New connection received on socket %s: log_name=%s peer_id=%lu peer:%s", e_sock->name, conn->log_name, (unsigned long)peer_id, sockaddr_storage_to_str(&addr).str);
|
||||
}
|
||||
else {// check keys если существующее подключение
|
||||
@@ -2658,7 +2661,17 @@ create_new_link:
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] NO existing link for id=%d, socket=[%s]", conn->log_name, req->link_id, e_sock->name);
|
||||
// Create new link
|
||||
link = etcp_link_new(conn, e_sock, &addr, 1);
|
||||
if (!link) { if (new_conn) etcp_connection_close(conn); errorcode=66; DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "failed to create link for connection"); goto ec_fr; }// облом
|
||||
if (!link) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_ETCP, "[%s] UDP link creation failed/cancelled peer=%016llx from=%s",
|
||||
conn->log_name, (unsigned long long)peer_id, sockaddr_storage_to_str(&addr).str);
|
||||
if (new_conn) {
|
||||
int owners = node_conn_direct_handle_count(conn);
|
||||
if (!conn->links && !owners) etcp_connection_close(conn);
|
||||
else DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] cancelled UDP accept preserves connection: other_links=%u owners=%d closing=%u",
|
||||
conn->log_name, conn->links != NULL, owners, conn->close_requested);
|
||||
}
|
||||
errorcode = 66; goto ec_fr;
|
||||
}
|
||||
link->remote_link_id = req->link_id;
|
||||
link->remote_socket_id = req->socket_id;
|
||||
link->remote_only_local = req->only_local;
|
||||
|
||||
@@ -892,16 +892,8 @@ int node_conn_direct_open(struct UTUN_INSTANCE* inst, uint64_t node_id,
|
||||
etcp_connection_close(conn); topo_node_registry_unref(inst->topo_groups, ni->node_id); return NCD_ERR;
|
||||
}
|
||||
|
||||
/* Подключаем conn в inst->connections с индексом по node_id */
|
||||
if (conn->conn_queue && conn->conn_queue_entry) {
|
||||
queue_remove_data(conn->conn_queue, conn->conn_queue_entry);
|
||||
queue_entry_free(conn->conn_queue_entry);
|
||||
}
|
||||
{ struct ll_entry* qe = queue_entry_new(sizeof(struct conn_queue_entry));
|
||||
if (qe) { struct conn_queue_entry* ce = (struct conn_queue_entry*)qe->data;
|
||||
ce->peer_node_id = node_id; ce->conn = conn;
|
||||
conn->conn_queue_entry = qe; conn->conn_queue = inst->connections;
|
||||
queue_data_put_with_index(inst->connections, qe); }
|
||||
if (etcp_conn_index_peer(conn) < 0) {
|
||||
etcp_connection_close(conn); topo_node_registry_unref(inst->topo_groups, ni->node_id); return NCD_ERR;
|
||||
}
|
||||
|
||||
entry = u_calloc(1, sizeof(*entry));
|
||||
@@ -1043,16 +1035,7 @@ static int ncd_open_node(struct UTUN_INSTANCE* inst, uint64_t node_id,
|
||||
etcp_connection_close(conn); return NCD_ERR;
|
||||
}
|
||||
|
||||
if (conn->conn_queue && conn->conn_queue_entry) {
|
||||
queue_remove_data(conn->conn_queue, conn->conn_queue_entry);
|
||||
queue_entry_free(conn->conn_queue_entry);
|
||||
}
|
||||
{ struct ll_entry* qe = queue_entry_new(sizeof(struct conn_queue_entry));
|
||||
if (qe) { struct conn_queue_entry* ce = (struct conn_queue_entry*)qe->data;
|
||||
ce->peer_node_id = node_id; ce->conn = conn;
|
||||
conn->conn_queue_entry = qe; conn->conn_queue = inst->connections;
|
||||
queue_data_put_with_index(inst->connections, qe); }
|
||||
}
|
||||
if (etcp_conn_index_peer(conn) < 0) { etcp_connection_close(conn); return NCD_ERR; }
|
||||
|
||||
struct ncd_entry* entry = u_calloc(1, sizeof(*entry));
|
||||
if (!entry) {
|
||||
|
||||
Reference in new issue
Block a user