master
h 65 lines 2.43 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef NETDATA_STREAM_PATH_H
4 #define NETDATA_STREAM_PATH_H
5
6 #include "stream-capabilities.h"
7
8 #define STREAM_PATH_JSON_MEMBER "streaming_path"
9
10 typedef struct stream_path STREAM_PATH;
11
12 typedef struct rrdhost_stream_path {
13 RW_SPINLOCK spinlock;
14 uint16_t size;
15 uint16_t used;
16 STREAM_PATH *array;
17 } RRDHOST_STREAM_PATH;
18
19 struct rrdhost;
20
21 void rrdhost_stream_path_init(struct rrdhost *host);
22
23 void stream_path_send_to_parent(struct rrdhost *host);
24 void stream_path_send_to_child(struct rrdhost *host);
25
26 void rrdhost_stream_path_to_json(BUFFER *wb, struct rrdhost *host, const char *key, bool add_version);
27 void rrdhost_stream_path_clear(struct rrdhost *host, bool destroy);
28
29 void stream_path_retention_updated(struct rrdhost *host);
30 void stream_path_node_id_updated(struct rrdhost *host);
31
32 void stream_path_child_disconnected(struct rrdhost *host);
33 void stream_path_parent_disconnected(struct rrdhost *host);
34
35 uint64_t rrdhost_stream_path_total_reboot_time_ms(struct rrdhost *host);
36
37 bool stream_path_set_from_json(struct rrdhost *host, const char *json, bool from_parent);
38
39 bool rrdhost_is_host_in_stream_path_before_us(struct rrdhost *host, ND_UUID remote_agent_host_id, int16_t our_hops);
40
41 // copy host_ids from the streaming path, starting at position 'from', into host_ids array
42 // returns the number of entries copied (up to max)
43 uint16_t rrdhost_stream_path_get_host_ids(struct rrdhost *host, uint16_t from, ND_UUID *host_ids, uint16_t max);
44
45 // Visitor callback. Called once per stream-path entry from index 'from' onward.
46 // hostname is a borrowed reference; do NOT retain it after the callback returns.
47 // flags is the STREAM_PATH_FLAGS bitmap as a uint32_t (treat as opaque).
48 // Return false from the callback to stop iteration early.
49 typedef bool (*stream_path_visit_cb)(
50 void *userdata, uint16_t index,
51 STRING *hostname,
52 ND_UUID host_id, ND_UUID node_id, ND_UUID claim_id,
53 int16_t hops,
54 time_t since, time_t first_time_t,
55 uint32_t start_time_ms, uint32_t shutdown_time_ms,
56 STREAM_CAPABILITIES capabilities,
57 uint32_t flags);
58
59 // Visit each path entry from 'from' onward. Acquires the path read-spinlock
60 // for the duration of the iteration; keep the callback fast. Returns the
61 // number of entries visited.
62 uint16_t rrdhost_stream_path_visit(struct rrdhost *host, uint16_t from,
63 stream_path_visit_cb cb, void *userdata);
64
65 #endif //NETDATA_STREAM_PATH_H