From 3218e18b2dcad571d3acf8f9ee615346463e6dc0 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Mon, 11 Mar 2024 17:42:05 +0100 Subject: [PATCH] feat: remove ke from unicast undeclares --- src/net/primitives.c | 21 +++++++++++++++++--- src/protocol/definitions/declarations.c | 26 +++++++++++++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/net/primitives.c b/src/net/primitives.c index 87d138d47..4958b04be 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -237,7 +237,12 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) { return _Z_ERR_ENTITY_UNKNOWN; } // Build the declare message to send on the wire - _z_declaration_t declaration = _z_make_undecl_subscriber(sub->_entity_id, &s->in->val._key); + _z_declaration_t declaration; + if (sub->_zn.in->val._tp._type == _Z_TRANSPORT_UNICAST_TYPE) { + declaration = _z_make_undecl_subscriber(sub->_entity_id, NULL); + } else { + declaration = _z_make_undecl_subscriber(sub->_entity_id, &s->in->val._key); + } _z_network_message_t n_msg = _z_n_msg_make_declare(declaration); if (_z_send_n_msg(&sub->_zn.in->val, &n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { return _Z_ERR_TRANSPORT_TX_FAILED; @@ -318,7 +323,12 @@ int8_t _z_undeclare_queryable(_z_queryable_t *qle) { return _Z_ERR_ENTITY_UNKNOWN; } // Build the declare message to send on the wire - _z_declaration_t declaration = _z_make_undecl_queryable(qle->_entity_id, &q->in->val._key); + _z_declaration_t declaration; + if (qle->_zn.in->val._tp._type == _Z_TRANSPORT_UNICAST_TYPE) { + declaration = _z_make_undecl_queryable(qle->_entity_id, NULL); + } else { + declaration = _z_make_undecl_queryable(qle->_entity_id, &q->in->val._key); + } _z_network_message_t n_msg = _z_n_msg_make_declare(declaration); if (_z_send_n_msg(&qle->_zn.in->val, &n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { return _Z_ERR_TRANSPORT_TX_FAILED; @@ -461,7 +471,12 @@ int8_t _z_undeclare_interest(_z_session_t *zn, uint32_t interest_id) { return _Z_ERR_ENTITY_UNKNOWN; } // Build the declare message to send on the wire - _z_declaration_t declaration = _z_make_undecl_interest(sintr->in->val._id, &sintr->in->val._key); + _z_declaration_t declaration; + if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { + declaration = _z_make_undecl_interest(sintr->in->val._id, NULL); + } else { + declaration = _z_make_undecl_interest(sintr->in->val._id, &sintr->in->val._key); + } _z_network_message_t n_msg = _z_n_msg_make_declare(declaration); if (_z_send_n_msg(zn, &n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { return _Z_ERR_TRANSPORT_TX_FAILED; diff --git a/src/protocol/definitions/declarations.c b/src/protocol/definitions/declarations.c index 9f1973077..56f004a18 100644 --- a/src/protocol/definitions/declarations.c +++ b/src/protocol/definitions/declarations.c @@ -76,10 +76,14 @@ _z_declaration_t _z_make_decl_subscriber(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, ._keyexpr = _z_keyexpr_steal(key), ._ext_subinfo = {._pull_mode = pull_mode, ._reliable = reliable}}}}; } + _z_declaration_t _z_make_undecl_subscriber(uint32_t id, _Z_OPTIONAL const _z_keyexpr_t *key) { - return (_z_declaration_t){._tag = _Z_UNDECL_SUBSCRIBER, - ._body = {._undecl_subscriber = {._id = id, ._ext_keyexpr = _z_keyexpr_duplicate(*key)}}}; + return (_z_declaration_t){ + ._tag = _Z_UNDECL_SUBSCRIBER, + ._body = {._undecl_subscriber = { + ._id = id, ._ext_keyexpr = (key == NULL) ? _z_keyexpr_null() : _z_keyexpr_duplicate(*key)}}}; } + _z_declaration_t _z_make_decl_queryable(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, uint32_t distance, uint8_t complete) { return (_z_declaration_t){ ._tag = _Z_DECL_QUERYABLE, @@ -88,8 +92,10 @@ _z_declaration_t _z_make_decl_queryable(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, ._ext_queryable_info = {._complete = complete, ._distance = distance}}}}; } _z_declaration_t _z_make_undecl_queryable(uint32_t id, _Z_OPTIONAL const _z_keyexpr_t *key) { - return (_z_declaration_t){._tag = _Z_UNDECL_QUERYABLE, - ._body = {._undecl_queryable = {._id = id, ._ext_keyexpr = _z_keyexpr_duplicate(*key)}}}; + return (_z_declaration_t){ + ._tag = _Z_UNDECL_QUERYABLE, + ._body = {._undecl_queryable = { + ._id = id, ._ext_keyexpr = (key == NULL) ? _z_keyexpr_null() : _z_keyexpr_duplicate(*key)}}}; } _z_declaration_t _z_make_decl_token(_Z_MOVE(_z_keyexpr_t) key, uint32_t id) { return (_z_declaration_t){._tag = _Z_DECL_TOKEN, @@ -99,8 +105,10 @@ _z_declaration_t _z_make_decl_token(_Z_MOVE(_z_keyexpr_t) key, uint32_t id) { }}}; } _z_declaration_t _z_make_undecl_token(uint32_t id, _Z_OPTIONAL const _z_keyexpr_t *key) { - return (_z_declaration_t){._tag = _Z_UNDECL_TOKEN, - ._body = {._undecl_token = {._id = id, ._ext_keyexpr = _z_keyexpr_duplicate(*key)}}}; + return (_z_declaration_t){ + ._tag = _Z_UNDECL_TOKEN, + ._body = {._undecl_token = {._id = id, + ._ext_keyexpr = (key == NULL) ? _z_keyexpr_null() : _z_keyexpr_duplicate(*key)}}}; } _z_declaration_t _z_make_decl_interest(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, uint8_t interest_flags) { return (_z_declaration_t){._tag = _Z_DECL_INTEREST, @@ -111,8 +119,10 @@ _z_declaration_t _z_make_decl_interest(_Z_MOVE(_z_keyexpr_t) key, uint32_t id, u }}}; } _z_declaration_t _z_make_undecl_interest(uint32_t id, _Z_OPTIONAL const _z_keyexpr_t *key) { - return (_z_declaration_t){._tag = _Z_UNDECL_INTEREST, - ._body = {._undecl_interest = {._id = id, ._ext_keyexpr = _z_keyexpr_duplicate(*key)}}}; + return (_z_declaration_t){ + ._tag = _Z_UNDECL_INTEREST, + ._body = {._undecl_interest = { + ._id = id, ._ext_keyexpr = (key == NULL) ? _z_keyexpr_null() : _z_keyexpr_duplicate(*key)}}}; } _z_declaration_t _z_make_final_interest(uint32_t id) { return (_z_declaration_t){._tag = _Z_FINAL_INTEREST, ._body = {._final_interest = {._id = id}}};