aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/htbt.c24
-rw-r--r--src/proone-hostinfod.c11
-rw-r--r--src/protocol.h4
3 files changed, 22 insertions, 17 deletions
diff --git a/src/htbt.c b/src/htbt.c
index 971c7d4..1389c5f 100644
--- a/src/htbt.c
+++ b/src/htbt.c
@@ -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);
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)) {
diff --git a/src/protocol.h b/src/protocol.h
index 72f39ca..da500b3 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -344,8 +344,8 @@ typedef prne_htbt_ser_rc_t(*prne_htbt_dser_ft)(
#define PRNE_HTBT_TLS_ALP "prne-htbt"
#define PRNE_HTBT_MSG_ID_MIN 1
-#define PRNE_HTBT_MSG_ID_MAX INT16_MAX
-#define PRNE_HTBT_MSG_ID_DELTA INT16_MAX
+#define PRNE_HTBT_MSG_ID_DELTA (INT16_MAX - 1)
+#define PRNE_HTBT_MSG_ID_NOTIFY INT16_MAX
#define PRNE_HTBT_PROTO_PORT 64420
// _POSIX_ARG_MAX equiv
#define PRNE_HTBT_ARGS_MAX 255