From c191b15809aa234516e48de5b5af305035423d4e Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 17 Aug 2020 17:01:36 +0200 Subject: [PATCH] path: add UUID --- include/villas/path.h | 11 +++++++---- lib/path.cpp | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/villas/path.h b/include/villas/path.h index 72348d6f8..5cd3a2b1c 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -31,6 +31,7 @@ #include +#include #include #include @@ -59,6 +60,8 @@ struct vpath { enum PathMode mode; /**< Determines when this path is triggered. */ + uuid_t uuid; + struct { int nfds; struct pollfd *pfds; @@ -79,10 +82,10 @@ struct vpath { double rate; /**< A timeout for */ int enabled; /**< Is this path enabled. */ int poll; /**< Weather or not to use poll(2). */ - int reverse; /**< This path as a matching reverse path. */ + int reverse; /**< This path has a matching reverse path. */ int builtin; /**< This path should use built-in hooks by default. */ - int original_sequence_no; /**< Use original source sequence number when multiplexing */ - unsigned queuelen; /**< The queue length for each path_destination::queue */ + int original_sequence_no; /**< Use original source sequence number when multiplexing */ + unsigned queuelen; /**< The queue length for each path_destination::queue */ char *_name; /**< Singleton: A string which is used to print this path to screen. */ @@ -92,7 +95,7 @@ struct vpath { villas::Logger logger; std::bitset mask; /**< A mask of path_sources which are enabled for poll(). */ - std::bitset received; /**< A mask of path_sources for which we already received samples. */ + std::bitset received; /**< A mask of path_sources for which we already received samples. */ }; /** Initialize internal data structures. */ diff --git a/lib/path.cpp b/lib/path.cpp index 2babe99a7..fcef417f7 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -323,12 +324,12 @@ 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; + const char *mode = nullptr, *uuid = nullptr; struct vlist destinations; vlist_init(&destinations); - ret = json_unpack_ex(cfg, &err, 0, "{ s: o, s?: o, s?: o, s?: b, s?: b, s?: b, s?: i, s?: s, s?: b, s?: F, s?: o, s?: b}", + ret = json_unpack_ex(cfg, &err, 0, "{ s: o, s?: o, s?: o, s?: b, s?: b, s?: b, s?: i, s?: s, s?: b, s?: F, s?: o, s?: b, s?: s}", "in", &json_in, "out", &json_out, "hooks", &json_hooks, @@ -340,7 +341,8 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes) "poll", &p->poll, "rate", &p->rate, "mask", &json_mask, - "original_sequence_no", &p->original_sequence_no + "original_sequence_no", &p->original_sequence_no, + "uuid", &uuid ); if (ret) jerror(&err, "Failed to parse path configuration"); @@ -364,6 +366,20 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes) } } + if (uuid) { + ret = uuid_parse(uuid, p->uuid); + if (ret) + throw ConfigError(cfg, "node-config-path-uuid", "Failed to parse UUID: {}", uuid); + } + 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); + } + /* Output node(s) */ if (json_out) { ret = node_list_parse(&destinations, json_out, nodes);