cleanup: remove dead nd_handle from CONN_MGR_HANDLE, fix double semicolons in node_conn_direct, protect close from NULL conn
This commit is contained in:
1 parent
eb2a8f6975
commit
4ba4ab038c
3 files changed
+24
-29
No files matched your search
@@ -24,7 +24,6 @@
|
||||
#include "route_ping.h"
|
||||
#include "route_connectivity.h"
|
||||
#include "conn_mgr.h"
|
||||
#include "../transport_layer/node_conn_direct.h"
|
||||
|
||||
static struct CONN_MGR_ENTRY* cm_find_entry(struct CONN_MGR* mgr, uint64_t node_id);
|
||||
static void cm_start_phase_direct(struct CONN_MGR_ENTRY* entry);
|
||||
@@ -209,7 +208,7 @@ static void cm_deliver_result(struct CONN_MGR_ENTRY* entry, int result) {
|
||||
while (h) {
|
||||
struct CONN_MGR_HANDLE* next = h->next;
|
||||
if (h->result_cb) h->result_cb(result, entry->node_id, h->result_arg);
|
||||
h->nd_handle = NULL; h->entry = NULL;
|
||||
h->entry = NULL;
|
||||
u_free(h);
|
||||
h = next;
|
||||
}
|
||||
@@ -353,7 +352,7 @@ int conn_mgr_cancel_callback(struct CONN_MGR* mgr, uint64_t node_id,
|
||||
if (h) {
|
||||
struct CONN_MGR_HANDLE** pp = &entry->handles;
|
||||
while (*pp) { if (*pp == h) { *pp = h->next; break; } pp = &(*pp)->next; }
|
||||
h->nd_handle = NULL; h->entry = NULL; u_free(h);
|
||||
h->entry = NULL; u_free(h);
|
||||
cb_count--;
|
||||
}
|
||||
|
||||
@@ -361,7 +360,7 @@ int conn_mgr_cancel_callback(struct CONN_MGR* mgr, uint64_t node_id,
|
||||
cm_entry_destroy(entry);
|
||||
cm_clear_nodeinfo(mgr, node_id);
|
||||
struct CONN_MGR_HANDLE* rem = h ? entry->handles : NULL;
|
||||
while (rem) { struct CONN_MGR_HANDLE* nx = rem->next; rem->nd_handle = NULL; u_free(rem); rem = nx; }
|
||||
while (rem) { struct CONN_MGR_HANDLE* nx = rem->next; u_free(rem); rem = nx; }
|
||||
entry->handles = NULL;
|
||||
}
|
||||
return CONN_MGR_OK;
|
||||
@@ -375,8 +374,6 @@ void conn_mgr_release_handle(struct CONN_MGR_HANDLE* h) {
|
||||
struct CONN_MGR_HANDLE** pp = &entry->handles;
|
||||
while (*pp) { if (*pp == h) { *pp = h->next; break; } pp = &(*pp)->next; }
|
||||
|
||||
if (h->nd_handle) { node_conn_direct_close(h->nd_handle); h->nd_handle = NULL; }
|
||||
|
||||
if (!entry->handles) { cm_entry_destroy(entry); cm_clear_nodeinfo(entry->mgr, entry->node_id); }
|
||||
h->entry = NULL; u_free(h);
|
||||
}
|
||||
|
||||
@@ -311,9 +311,6 @@ struct CONN_MGR_INVITE_INFO_RESP {
|
||||
*/
|
||||
typedef void (*conn_mgr_connect_callback_t)(int result, uint64_t node_id, void* arg);
|
||||
|
||||
/* forward declaration для handle */
|
||||
struct NODE_CONN_DIRECT;
|
||||
|
||||
/**
|
||||
* @struct CONN_MGR_HANDLE
|
||||
* @brief Универсальный handle подключения (один на каждый conn_mgr_connect_node).
|
||||
@@ -323,7 +320,6 @@ struct CONN_MGR_HANDLE {
|
||||
uint8_t conn_type;
|
||||
uint64_t intermediary_node_id;
|
||||
uint64_t bridge_session_id;
|
||||
struct NODE_CONN_DIRECT* nd_handle;
|
||||
conn_mgr_connect_callback_t result_cb;
|
||||
void* result_arg;
|
||||
struct CONN_MGR_HANDLE* next;
|
||||
|
||||
@@ -193,9 +193,9 @@ static void ncd_down_cb(struct ETCP_CONN* conn, int event, void* arg) { (void)ev
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] DOWN during fin_wait, cleaning up node=0x%016llx", (unsigned long long)entry->node_id);
|
||||
conn->fin_wait = 0; conn->fin_wait_clear_cb = NULL; conn->fin_wait_clear_arg = NULL;
|
||||
if (entry->fin_wait_timer) { uasync_cancel_timeout(entry->ua, entry->fin_wait_timer); entry->fin_wait_timer = NULL; }
|
||||
etcp_conn_remove_cbk(conn, ncd_init_cb, entry);;
|
||||
etcp_conn_remove_cbk(conn, ncd_up_cb, entry);;
|
||||
etcp_conn_remove_cbk(conn, ncd_down_cb, entry);;
|
||||
etcp_conn_remove_cbk(conn, ncd_init_cb, entry);
|
||||
etcp_conn_remove_cbk(conn, ncd_up_cb, entry);
|
||||
etcp_conn_remove_cbk(conn, ncd_down_cb, entry);
|
||||
etcp_connection_close(conn);
|
||||
ncd_registry_remove(entry);
|
||||
u_free(entry);
|
||||
@@ -354,9 +354,9 @@ int node_conn_direct_open(struct UTUN_INSTANCE* inst, uint64_t node_id,
|
||||
entry->handle_count = 1;
|
||||
*out_handle = h;
|
||||
|
||||
etcp_conn_add_cbk(conn, ncd_init_cb, entry, ETCP_CBK_EVENT_INIT);;
|
||||
etcp_conn_add_cbk(conn, ncd_up_cb, entry, ETCP_CBK_EVENT_UP);;
|
||||
etcp_conn_add_cbk(conn, ncd_down_cb, entry, ETCP_CBK_EVENT_DOWN);;
|
||||
etcp_conn_add_cbk(conn, ncd_init_cb, entry, ETCP_CBK_EVENT_INIT);
|
||||
etcp_conn_add_cbk(conn, ncd_up_cb, entry, ETCP_CBK_EVENT_UP);
|
||||
etcp_conn_add_cbk(conn, ncd_down_cb, entry, ETCP_CBK_EVENT_DOWN);
|
||||
|
||||
if (conn->state == 1 && entry->up) {
|
||||
uasync_call_soon(inst->ua, h, ncd_deliver_up_cb);
|
||||
@@ -421,9 +421,9 @@ int node_conn_direct_open(struct UTUN_INSTANCE* inst, uint64_t node_id,
|
||||
entry->handle_count = 1;
|
||||
*out_handle = h;
|
||||
|
||||
etcp_conn_add_cbk(conn, ncd_init_cb, entry, ETCP_CBK_EVENT_INIT);;
|
||||
etcp_conn_add_cbk(conn, ncd_up_cb, entry, ETCP_CBK_EVENT_UP);;
|
||||
etcp_conn_add_cbk(conn, ncd_down_cb, entry, ETCP_CBK_EVENT_DOWN);;
|
||||
etcp_conn_add_cbk(conn, ncd_init_cb, entry, ETCP_CBK_EVENT_INIT);
|
||||
etcp_conn_add_cbk(conn, ncd_up_cb, entry, ETCP_CBK_EVENT_UP);
|
||||
etcp_conn_add_cbk(conn, ncd_down_cb, entry, ETCP_CBK_EVENT_DOWN);
|
||||
|
||||
int link_count = ncd_create_links(entry, ni);
|
||||
|
||||
@@ -489,9 +489,9 @@ int node_conn_direct_open_node(struct UTUN_INSTANCE* inst, uint64_t node_id,
|
||||
entry->handle_count = 1;
|
||||
*out_handle = h;
|
||||
|
||||
etcp_conn_add_cbk(conn, ncd_init_cb, entry, ETCP_CBK_EVENT_INIT);;
|
||||
etcp_conn_add_cbk(conn, ncd_up_cb, entry, ETCP_CBK_EVENT_UP);;
|
||||
etcp_conn_add_cbk(conn, ncd_down_cb, entry, ETCP_CBK_EVENT_DOWN);;
|
||||
etcp_conn_add_cbk(conn, ncd_init_cb, entry, ETCP_CBK_EVENT_INIT);
|
||||
etcp_conn_add_cbk(conn, ncd_up_cb, entry, ETCP_CBK_EVENT_UP);
|
||||
etcp_conn_add_cbk(conn, ncd_down_cb, entry, ETCP_CBK_EVENT_DOWN);
|
||||
|
||||
if (conn->state == 1 && entry->up) {
|
||||
uasync_call_soon(inst->ua, h, ncd_deliver_up_cb);
|
||||
@@ -548,9 +548,9 @@ int node_conn_direct_open_node(struct UTUN_INSTANCE* inst, uint64_t node_id,
|
||||
entry->handle_count = 1;
|
||||
*out_handle = h;
|
||||
|
||||
etcp_conn_add_cbk(conn, ncd_init_cb, entry, ETCP_CBK_EVENT_INIT);;
|
||||
etcp_conn_add_cbk(conn, ncd_up_cb, entry, ETCP_CBK_EVENT_UP);;
|
||||
etcp_conn_add_cbk(conn, ncd_down_cb, entry, ETCP_CBK_EVENT_DOWN);;
|
||||
etcp_conn_add_cbk(conn, ncd_init_cb, entry, ETCP_CBK_EVENT_INIT);
|
||||
etcp_conn_add_cbk(conn, ncd_up_cb, entry, ETCP_CBK_EVENT_UP);
|
||||
etcp_conn_add_cbk(conn, ncd_down_cb, entry, ETCP_CBK_EVENT_DOWN);
|
||||
|
||||
int link_count = ncd_create_links(entry, ni);
|
||||
|
||||
@@ -596,10 +596,12 @@ void node_conn_direct_close(struct NODE_CONN_DIRECT* h) {
|
||||
entry->fin_wait_timer = uasync_set_timeout(entry->ua, NCD_FIN_WAIT_TIMEOUT_TB, entry, ncd_fin_wait_timeout_cb, "ncd_fin_wait");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] fin_wait started node=0x%016llx", (unsigned long long)node_id);
|
||||
} else {
|
||||
etcp_conn_remove_cbk(conn, ncd_init_cb, entry);;
|
||||
etcp_conn_remove_cbk(conn, ncd_up_cb, entry);;
|
||||
etcp_conn_remove_cbk(conn, ncd_down_cb, entry);;
|
||||
if (conn) etcp_connection_close(conn);
|
||||
if (conn) {
|
||||
etcp_conn_remove_cbk(conn, ncd_init_cb, entry);
|
||||
etcp_conn_remove_cbk(conn, ncd_up_cb, entry);
|
||||
etcp_conn_remove_cbk(conn, ncd_down_cb, entry);
|
||||
etcp_connection_close(conn);
|
||||
}
|
||||
ncd_registry_remove(entry);
|
||||
u_free(entry);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user