From eb56a23613638ca705f5be707cacc1b0989a2a76 Mon Sep 17 00:00:00 2001 From: David Timber Date: Sat, 11 Sep 2021 11:11:40 +0800 Subject: 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) --- src/proone-hostinfod.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/proone-hostinfod.c') diff --git a/src/proone-hostinfod.c b/src/proone-hostinfod.c index ea6536b..97f4d09 100644 --- a/src/proone-hostinfod.c +++ b/src/proone-hostinfod.c @@ -1414,6 +1414,12 @@ END: // CATCH return ret; } +static uint16_t gen_msgid (void *ctx) { + uint16_t ret = PRNE_HTBT_MSG_ID_MIN; + prne_rnd((prne_rnd_t*)ctx, (uint8_t*)&ret, sizeof(ret)); + return ret; +} + static int proc_client_stream (th_ctx_t *ctx, client_ctx_t *c) { prne_htbt_msg_head_t mh; prne_htbt_ser_rc_t src; @@ -1444,10 +1450,7 @@ static int proc_client_stream (th_ctx_t *ctx, client_ctx_t *c) { } mh.op = PRNE_HTBT_OP_HOST_INFO; - prne_rnd(&ctx->rnd, (uint8_t*)&mh.id, sizeof(mh.id)); - mh.id = - PRNE_HTBT_MSG_ID_MIN + - ((mh.id % PRNE_HTBT_MSG_ID_MAX) - PRNE_HTBT_MSG_ID_MIN); + mh.id = prne_htbt_gen_msgid(&ctx->rnd, gen_msgid); prne_htbt_ser_msg_head(NULL, 0, &actual, &mh); if (prne_alloc_iobuf(c->ib + 1, actual)) { -- cgit