From 1bd4d8b2d4b6a3f89e7bcc204efa15de9a3d3ff1 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 16 Oct 2020 09:25:23 +0200 Subject: [PATCH] node/path: generate UUIDs using new util funcs --- lib/node.cpp | 12 +++++++----- lib/path.cpp | 23 ++++++++++------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/node.cpp b/lib/node.cpp index c5650f503..3ed189730 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -64,6 +64,8 @@ int node_init(struct vnode *n, struct vnode_type *vt) new (&n->stats) stats_ptr(); + uuid_clear(n->uuid); + n->output_path = nullptr; n->name = nullptr; n->_name = nullptr; @@ -138,12 +140,12 @@ int node_parse(struct vnode *n, json_t *json, const char *name) json_error_t err; json_t *json_netem = nullptr; - const char *uuid = nullptr; + const char *uuid_str = nullptr; n->name = strdup(name); ret = json_unpack_ex(json, &err, 0, "{ s?: s, s?: b }", - "uuid", &uuid, + "uuid", &uuid_str, "enabled", &enabled ); if (ret) @@ -161,10 +163,10 @@ int node_parse(struct vnode *n, json_t *json, const char *name) return ret; #endif /* __linux__ */ - if (uuid) { - ret = uuid_parse(uuid, n->uuid); + if (uuid_str) { + ret = uuid_parse(uuid_str, n->uuid); if (ret) - throw ConfigError(json, "node-config-node-uuid", "Failed to parse UUID: {}", uuid); + throw ConfigError(json, "node-config-node-uuid", "Failed to parse UUID: {}", uuid_str); } else /* Generate UUID from hashed config including node name */ diff --git a/lib/path.cpp b/lib/path.cpp index 5fad3c6db..4e2d33eb7 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include @@ -142,6 +141,8 @@ int path_init(struct vpath *p) p->logger = logging.get("path"); + uuid_clear(p->uuid); + ret = vlist_init(&p->destinations); if (ret) return ret; @@ -395,7 +396,8 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes) json_t *json_hooks = nullptr; json_t *json_mask = nullptr; - const char *mode = nullptr, *uuid = nullptr; + const char *mode = nullptr; + const char *uuid_str = nullptr; struct vlist destinations; @@ -416,7 +418,7 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes) "rate", &p->rate, "mask", &json_mask, "original_sequence_no", &p->original_sequence_no, - "uuid", &uuid, + "uuid", &uuid_str, "affinity", &p->affinity ); if (ret) @@ -433,19 +435,14 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes) } /* UUID */ - if (uuid) { - ret = uuid_parse(uuid, p->uuid); + if (uuid_str) { + ret = uuid_parse(uuid_str, p->uuid); if (ret) - throw ConfigError(cfg, "node-config-path-uuid", "Failed to parse UUID: {}", uuid); + throw ConfigError(cfg, "node-config-path-uuid", "Failed to parse UUID: {}", uuid_str); } - else { + else /* Generate UUID from hashed config */ - char *json_str = json_dumps(cfg, JSON_COMPACT | JSON_SORT_KEYS); - - MD5((unsigned char*) json_str, strlen(json_str), (unsigned char*) &p->uuid); - - free(json_str); - } + uuid_generate_from_json(p->uuid, cfg); /* Input node(s) */ ret = mapping_list_parse(&p->mappings, json_in);