diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 11:19:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:07:37 +0000 |
commit | b485aab7e71c1625cfc27e0f92c9509f42378458 (patch) | |
tree | ae9abe108601079d1679194de237c9a435ae5b55 /src/libnetdata/uuid | |
parent | Adding upstream version 1.44.3. (diff) | |
download | netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.tar.xz netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.zip |
Adding upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/libnetdata/uuid/README.md | 13 | ||||
-rw-r--r-- | src/libnetdata/uuid/uuid.c (renamed from libnetdata/uuid/uuid.c) | 20 | ||||
-rw-r--r-- | src/libnetdata/uuid/uuid.h (renamed from libnetdata/uuid/uuid.h) | 18 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/libnetdata/uuid/README.md b/src/libnetdata/uuid/README.md new file mode 100644 index 000000000..a0da380a9 --- /dev/null +++ b/src/libnetdata/uuid/README.md @@ -0,0 +1,13 @@ +<!-- +title: "UUID" +custom_edit_url: https://github.com/netdata/netdata/edit/master/src/libnetdata/uuid/README.md +sidebar_label: "UUID" +learn_topic_type: "Tasks" +learn_rel_path: "Developers/libnetdata" +--> + +# UUID + +Netdata uses libuuid for managing UUIDs. + +In this folder are a few custom helpers.
\ No newline at end of file diff --git a/libnetdata/uuid/uuid.c b/src/libnetdata/uuid/uuid.c index 55b66db9b..f062d0bc5 100644 --- a/libnetdata/uuid/uuid.c +++ b/src/libnetdata/uuid/uuid.c @@ -2,6 +2,26 @@ #include "../libnetdata.h" + +UUID UUID_generate_from_hash(const void *payload, size_t payload_len) { + assert(sizeof(XXH128_hash_t) == sizeof(UUID)); + + UUID uuid; + XXH128_hash_t *xxh3_128 = (XXH128_hash_t *)&uuid; + + // Hash the payload using XXH128 + // Assume xxh128_hash_function is your function to generate XXH128 hash + *xxh3_128 = XXH3_128bits(payload, payload_len); + + // Set the UUID version (here, setting it to 4) + uuid.uuid[6] = (uuid.uuid[6] & 0x0F) | 0x40; // Version 4 + + // Set the UUID variant (standard variant for UUID) + uuid.uuid[8] = (uuid.uuid[8] & 0x3F) | 0x80; // Variant is 10xxxxxx + + return uuid; +} + void uuid_unparse_lower_compact(const uuid_t uuid, char *out) { static const char *hex_chars = "0123456789abcdef"; for (int i = 0; i < 16; i++) { diff --git a/libnetdata/uuid/uuid.h b/src/libnetdata/uuid/uuid.h index 567646846..6d5f024f8 100644 --- a/libnetdata/uuid/uuid.h +++ b/src/libnetdata/uuid/uuid.h @@ -10,6 +10,24 @@ UUID_DEFINE(health_alert_transition_msgid, 0x9c, 0xe0, 0xcb, 0x58, 0xab, 0x8b, 0 // this is also defined in alarm-notify.sh.in UUID_DEFINE(health_alert_notification_msgid, 0x6d, 0xb0, 0x01, 0x8e, 0x83, 0xe3, 0x43, 0x20, 0xae, 0x2a, 0x65, 0x9d, 0x78, 0x01, 0x9f, 0xb7); +typedef struct { + union { + uuid_t uuid; + struct { + uint64_t hig64; + uint64_t low64; + } parts; + }; +} UUID; +UUID UUID_generate_from_hash(const void *payload, size_t payload_len); + +#define UUIDeq(a, b) ((a).parts.hig64 == (b).parts.hig64 && (a).parts.low64 == (b).parts.low64) + +static inline UUID uuid2UUID(uuid_t uu1) { + UUID *ret = (UUID *)uu1; + return *ret; +} + #define UUID_COMPACT_STR_LEN 33 void uuid_unparse_lower_compact(const uuid_t uuid, char *out); int uuid_parse_compact(const char *in, uuid_t uuid); |