diff options
author | David Timber <mieabby@gmail.com> | 2021-09-11 11:11:40 +0800 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2021-09-11 11:11:40 +0800 |
commit | eb56a23613638ca705f5be707cacc1b0989a2a76 (patch) | |
tree | 09d8fe6e428608421c7062399d1821121d254af6 /src/htbt.c | |
parent | 8219894fcb3c4c89b55a0dd0afcbbda4ded5aea3 (diff) |
Use prne_htbt_gen_msgid() to unify msg_id gen algo
* Add PRNE_HTBT_MSG_ID_NOTIFY for protocol error w/o associated msg_id
* Remove PRNE_HTBT_MSG_ID_MAX(wrong value)
Diffstat (limited to 'src/htbt.c')
-rw-r--r-- | src/htbt.c | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -826,11 +826,12 @@ static bool htbt_slv_recv_mh ( const bool mid, pth_event_t ev) { + static const uint16_t ERR_MSGID = PRNE_HTBT_MSG_ID_NOTIFY; bool ret = htbt_slv_recv_frame( ctx, mh, (prne_htbt_dser_ft)prne_htbt_dser_msg_head, - corr_id, + &ERR_MSGID, mid, ev); @@ -2196,25 +2197,26 @@ static bool htbt_main_slv_loopchk_f (void *ioctx) { return ctx->parent->loop_flag; } +static uint16_t htbt_main_gen_msgid (void *ctx) { + uint16_t ret = PRNE_HTBT_MSG_ID_MIN; + mbedtls_ctr_drbg_random( + (mbedtls_ctr_drbg_context*)ctx, + (unsigned char *)&ret, + sizeof(ret)); + return ret; +} + static bool htbt_main_slv_setup_f (void *ioctx, pth_event_t ev) { htbt_main_client_t *ctx = (htbt_main_client_t*)ioctx; bool ret = true; size_t actual; prne_htbt_msg_head_t mh; - int f_ret; prne_htbt_init_msg_head(&mh); - f_ret = mbedtls_ctr_drbg_random( + mh.id = prne_htbt_gen_msgid( ctx->parent->param.ctr_drbg, - (unsigned char *)&mh.id, - sizeof(mh.id)); - if (f_ret == 0) { - mh.id = (mh.id % PRNE_HTBT_MSG_ID_DELTA) + PRNE_HTBT_MSG_ID_MIN; - } - else { - mh.id = PRNE_HTBT_MSG_ID_MIN; - } + htbt_main_gen_msgid); mh.is_rsp = false; mh.op = PRNE_HTBT_OP_SOLICIT; prne_htbt_ser_msg_head(NULL, 0, &actual, &mh); |