diff --git a/src/conn_mgr.c b/src/conn_mgr.c index f816864a..4e8ef001 100644 --- a/src/conn_mgr.c +++ b/src/conn_mgr.c @@ -471,7 +471,7 @@ static void cm_start_phase_direct(struct CONN_MGR_ENTRY* entry) { struct sockaddr_storage sa; memset(&sa, 0, sizeof(sa)); memcpy(&sa, &sin, sizeof(sin)); struct ETCP_CONN* conn = etcp_connection_create(entry->mgr->instance, NULL); if (conn) { - etcp_conn_set_init_cbk(conn, cm_direct_init_cb, entry); + etcp_conn_add_init_cbk(conn, cm_direct_init_cb, entry); sc_init_ctx(&conn->crypto_ctx, &entry->mgr->instance->my_keys); sc_set_peer_public_key(&conn->crypto_ctx, target->node->public_key, 0); if (etcp_link_new(conn, s, &sa, 0)) { @@ -859,7 +859,7 @@ static void cm_handle_direct_req(struct ETCP_CONN* conn, const uint8_t* data, si sc_set_peer_public_key(&new_conn->crypto_ctx, nq->node->public_key, 0); } struct cm_reverse_pending* rp = u_calloc(1, sizeof(struct cm_reverse_pending)); if (rp) { rp->request_id = req->request_id; rp->entry = NULL; rp->next = mgr->reverse_pending; - etcp_conn_set_init_cbk(new_conn, cm_reverse_init_cb, rp); mgr->reverse_pending = rp; } + etcp_conn_add_init_cbk(new_conn, cm_reverse_init_cb, rp); mgr->reverse_pending = rp; } etcp_link_new(new_conn, s, &sa, 0); } break; diff --git a/src/etcp_api.c b/src/etcp_api.c index 35c86ee7..1cd2dfd0 100644 --- a/src/etcp_api.c +++ b/src/etcp_api.c @@ -12,35 +12,6 @@ #define DEBUG_CATEGORY_ETCP_API DEBUG_CATEGORY_ETCP -void etcp_conn_set_init_cbk(struct ETCP_CONN* e, etcp_cbk_fn fn, void* arg) { - if (!e) return; - struct etcp_cbk_entry* entry = e->init_cbks; - while (entry) { struct etcp_cbk_entry* next = entry->next; u_free(entry); entry = next; } - e->init_cbks = NULL; - if (fn) etcp_conn_add_init_cbk(e, fn, arg); -} -void etcp_conn_set_up_cbk(struct ETCP_CONN* e, etcp_cbk_fn fn, void* arg) { - if (!e) return; - struct etcp_cbk_entry* entry = e->up_cbks; - while (entry) { struct etcp_cbk_entry* next = entry->next; u_free(entry); entry = next; } - e->up_cbks = NULL; - if (fn) etcp_conn_add_up_cbk(e, fn, arg); -} -void etcp_conn_set_down_cbk(struct ETCP_CONN* e, etcp_cbk_fn fn, void* arg) { - if (!e) return; - struct etcp_cbk_entry* entry = e->down_cbks; - while (entry) { struct etcp_cbk_entry* next = entry->next; u_free(entry); entry = next; } - e->down_cbks = NULL; - if (fn) etcp_conn_add_down_cbk(e, fn, arg); -} -void etcp_set_new_conn_cbk(struct UTUN_INSTANCE* inst, etcp_cbk_fn fn, void* arg) { - if (!inst) return; - struct etcp_cbk_entry* entry = inst->new_conn_cbks; - while (entry) { struct etcp_cbk_entry* next = entry->next; u_free(entry); entry = next; } - inst->new_conn_cbks = NULL; - if (fn) etcp_add_new_conn_cbk(inst, fn, arg); -} - static void etcp_cbk_add_to_chain(struct etcp_cbk_entry** head, etcp_cbk_fn fn, void* arg) { if (!head || !fn) return; struct etcp_cbk_entry* e = u_malloc(sizeof(struct etcp_cbk_entry)); @@ -89,14 +60,6 @@ static void etcp_status_cbk_remove_chain(struct etcp_status_cbk_entry** head, et } void etcp_add_conn_status_cbk(struct UTUN_INSTANCE* inst, etcp_conn_status_fn fn, void* arg) { if (inst) etcp_status_cbk_add_chain(&inst->conn_status_cbks, fn, arg); } void etcp_remove_conn_status_cbk(struct UTUN_INSTANCE* inst, etcp_conn_status_fn fn, void* arg) { if (inst) etcp_status_cbk_remove_chain(&inst->conn_status_cbks, fn, arg); } -void etcp_set_conn_status_cbk(struct UTUN_INSTANCE* inst, etcp_conn_status_fn fn, void* arg) { - if (!inst) return; - struct etcp_status_cbk_entry* entry = inst->conn_status_cbks; - while (entry) { struct etcp_status_cbk_entry* next = entry->next; u_free(entry); entry = next; } - inst->conn_status_cbks = NULL; - if (fn) etcp_status_cbk_add_chain(&inst->conn_status_cbks, fn, arg); -} - void etcp_set_routing_exchange_state(struct ETCP_CONN* conn, uint8_t new_state) { if (!conn) return; conn->routing_exchange_active = new_state; diff --git a/src/etcp_api.h b/src/etcp_api.h index 1ae57e5b..f20af532 100644 --- a/src/etcp_api.h +++ b/src/etcp_api.h @@ -99,15 +99,6 @@ typedef void (*etcp_connect_callback_t)(void* arg, struct ETCP_CONN* conn, int t int etcp_connect(struct UTUN_INSTANCE* instance, struct TOPO_NODEQ* node, etcp_connect_callback_t cb, void* arg, uint8_t flags); -/** - * @brief Установить callback при создании нового ETCP соединения - * - * @param instance UTUN instance - * @param callback_fn Коллбэк который будет вызван при создании нового соединения - * @param arg Аргумент для коллбэка - */ -void etcp_set_new_conn_cbk(struct UTUN_INSTANCE* instance, etcp_cbk_fn callback_fn, void* arg); - /** * @brief Структура bindings для ETCP API (per-instance) */ @@ -151,21 +142,6 @@ int etcp_bind(struct UTUN_INSTANCE* inst, uint8_t id, etcp_recv_fn callback); */ int etcp_unbind(struct UTUN_INSTANCE* inst, uint8_t id); -/** - * @brief Установить callback на событие готовности соединения - * - * После создания подключения надо дождаться conn_ready (соединение инициализировано). - * Только после этого можно передавать сообщения. Иначе сообщения могут потеряться. - * conn_ready может вызываться несколько раз (после каждого переподключения). - * - * @param conn ETCP соединение - * @param callback_fn Коллбэк который будет вызван при готовности - * @param arg Аргумент для коллбэка - */ -void etcp_conn_set_init_cbk(struct ETCP_CONN* conn, etcp_cbk_fn callback_fn, void* arg); -void etcp_conn_set_up_cbk (struct ETCP_CONN* conn, etcp_cbk_fn callback_fn, void* arg); -void etcp_conn_set_down_cbk (struct ETCP_CONN* conn, etcp_cbk_fn callback_fn, void* arg); - void etcp_conn_add_init_cbk(struct ETCP_CONN* conn, etcp_cbk_fn fn, void* arg); void etcp_conn_remove_init_cbk(struct ETCP_CONN* conn, etcp_cbk_fn fn, void* arg); void etcp_conn_add_up_cbk(struct ETCP_CONN* conn, etcp_cbk_fn fn, void* arg); @@ -177,7 +153,6 @@ void etcp_remove_new_conn_cbk(struct UTUN_INSTANCE* inst, etcp_cbk_fn fn, void* void etcp_add_conn_status_cbk(struct UTUN_INSTANCE* inst, etcp_conn_status_fn fn, void* arg); void etcp_remove_conn_status_cbk(struct UTUN_INSTANCE* inst, etcp_conn_status_fn fn, void* arg); -void etcp_set_conn_status_cbk(struct UTUN_INSTANCE* inst, etcp_conn_status_fn fn, void* arg); void etcp_set_routing_exchange_state(struct ETCP_CONN* conn, uint8_t new_state); diff --git a/tools/chatgui/transport/chat_core.c b/tools/chatgui/transport/chat_core.c index 8a69c33e..7f3e029d 100644 --- a/tools/chatgui/transport/chat_core.c +++ b/tools/chatgui/transport/chat_core.c @@ -860,7 +860,7 @@ void chat_core_connect_auto(uint64_t node_id, pctx->state = pst; pctx->addr_index = i; pst->ctxs[i] = pctx; - etcp_conn_set_init_cbk(conn, ca_init_cb, pctx); + etcp_conn_add_init_cbk(conn, ca_init_cb, pctx); if (!etcp_link_new(conn, best_socket, &sa, 0)) { DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: auto_connect etcp_link_new failed idx=%d", CC_ID, i);