mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
node/path: generate UUIDs using new util funcs
This commit is contained in:
parent
8a6902bd90
commit
1bd4d8b2d4
2 changed files with 17 additions and 18 deletions
12
lib/node.cpp
12
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 */
|
||||
|
|
23
lib/path.cpp
23
lib/path.cpp
|
@ -31,7 +31,6 @@
|
|||
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#include <openssl/md5.h>
|
||||
|
||||
#include <villas/node/config.h>
|
||||
#include <villas/utils.hpp>
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue