From 023b931ee13964866b6fcdd4f464c7f04c585f9c Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Fri, 24 Nov 2017 15:19:14 +0300 Subject: [PATCH] odissey: reuse client id as a forge backend key --- sources/frontend.c | 4 ++-- sources/id.c | 3 +++ sources/id.h | 6 ++++-- sources/instance.c | 6 +----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sources/frontend.c b/sources/frontend.c index fac39bec..2ebb477b 100644 --- a/sources/frontend.c +++ b/sources/frontend.c @@ -244,8 +244,8 @@ od_frontend_key(od_client_t *client) * possibility of cancelling requests by a previous * server owners. */ - client->key.key_pid = *(int32_t*)client->id.id; - client->key.key = 1 + rand(); + client->key.key_pid = client->id.id_a; + client->key.key = client->id.id_b; } static inline int diff --git a/sources/id.c b/sources/id.c index f0a3f6b4..11b8e567 100644 --- a/sources/id.c +++ b/sources/id.c @@ -71,6 +71,9 @@ void od_idmgr_generate(od_idmgr_t *mgr, od_id_t *id, char *prefix) memcpy(seed + 4, &b, 2); id->id_prefix = prefix; + id->id_a = a; + id->id_b = b; + static const char *hex = "0123456789abcdef"; int q, w; for (q = 0, w = 0; q < OD_ID_SEEDMAX; q++) { diff --git a/sources/id.h b/sources/id.h index c852d2c5..2dd73455 100644 --- a/sources/id.h +++ b/sources/id.h @@ -14,8 +14,10 @@ typedef struct od_idmgr od_idmgr_t; struct od_id { - char *id_prefix; - char id[OD_ID_SEEDMAX * 2]; + char *id_prefix; + char id[OD_ID_SEEDMAX * 2]; + uint64_t id_a; + uint64_t id_b; }; struct od_idmgr diff --git a/sources/instance.c b/sources/instance.c index a7cd95ce..2493b060 100644 --- a/sources/instance.c +++ b/sources/instance.c @@ -175,11 +175,7 @@ int od_instance_main(od_instance_t *instance, int argc, char **argv) od_pid_create(&instance->pid, instance->scheme.pid_file); /* seed id manager */ - rc = od_idmgr_seed(&instance->id_mgr); - if (rc == -1) { - od_error(&instance->logger, "init", NULL, NULL, - "failed to open random source device"); - } + od_idmgr_seed(&instance->id_mgr); /* run system services */ od_router_t router;