| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | #ifndef ACLK_H |
| 3 | #define ACLK_H |
| 4 | |
| 5 | #include "database/rrd.h" |
| 6 | |
| 7 | #include "aclk_util.h" |
| 8 | |
| 9 | // Forward declaration - defined in aclk_query_queue.h |
| 10 | struct aclk_sync_completion; |
| 11 | //#include "aclk_rrdhost_state.h" |
| 12 | |
| 13 | #include "https_client.h" |
| 14 | |
| 15 | // How many MQTT PUBACKs we need to get to consider connection |
| 16 | // stable for the purposes of TBEB (truncated binary exponential backoff) |
| 17 | #define ACLK_PUBACKS_CONN_STABLE 3 |
| 18 | |
| 19 | typedef enum { |
| 20 | ACLK_NO_DISCONNECT = 0, |
| 21 | ACLK_CLOUD_DISCONNECT = 1, |
| 22 | ACLK_RELOAD_CONF = 2, |
| 23 | ACLK_PING_TIMEOUT = 3 |
| 24 | } ACLK_DISCONNECT_ACTION; |
| 25 | |
| 26 | typedef enum { |
| 27 | ACLK_STATUS_CONNECTED = 0, |
| 28 | |
| 29 | // ND_SOCK_ERR_XXX is included here |
| 30 | // HTTPS_CLIENT_RESP_XXX is included here |
| 31 | |
| 32 | ACLK_STATUS_OFFLINE = HTTPS_CLIENT_RESP_MAX, |
| 33 | ACLK_STATUS_DISABLED, |
| 34 | ACLK_STATUS_CANT_CONNECT_NO_CLOUD_URL, |
| 35 | ACLK_STATUS_CANT_CONNECT_INVALID_CLOUD_URL, |
| 36 | ACLK_STATUS_BLOCKED, |
| 37 | ACLK_STATUS_NO_OLD_PROTOCOL, |
| 38 | ACLK_STATUS_NO_PROTOCOL_CAPABILITY, |
| 39 | ACLK_STATUS_INVALID_ENV_AUTH_URL, |
| 40 | ACLK_STATUS_INVALID_ENV_TRANSPORT_IDX, |
| 41 | ACLK_STATUS_INVALID_ENV_TRANSPORT_URL, |
| 42 | ACLK_STATUS_NO_LWT_TOPIC, |
| 43 | |
| 44 | // disconnection reasons |
| 45 | ACLK_STATUS_OFFLINE_CLOUD_REQUESTED_DISCONNECT, |
| 46 | ACLK_STATUS_OFFLINE_PING_TIMEOUT, |
| 47 | ACLK_STATUS_OFFLINE_RELOADING_CONFIG, |
| 48 | ACLK_STATUS_OFFLINE_POLL_ERROR, |
| 49 | ACLK_STATUS_OFFLINE_CLOSED_BY_REMOTE, |
| 50 | ACLK_STATUS_OFFLINE_SOCKET_ERROR, |
| 51 | ACLK_STATUS_OFFLINE_MQTT_PROTOCOL_ERROR, |
| 52 | ACLK_STATUS_OFFLINE_WS_PROTOCOL_ERROR, |
| 53 | ACLK_STATUS_OFFLINE_MESSAGE_TOO_BIG, |
| 54 | |
| 55 | } ACLK_STATUS; |
| 56 | |
| 57 | extern ACLK_STATUS aclk_status; |
| 58 | extern const char *aclk_cloud_base_url; |
| 59 | const char *aclk_status_to_string(void); |
| 60 | |
| 61 | extern int aclk_ctx_based; |
| 62 | extern int aclk_disable_runtime; |
| 63 | //extern int aclk_stats_enabled; |
| 64 | extern int aclk_kill_link; |
| 65 | |
| 66 | bool aclk_online(void); |
| 67 | bool aclk_online_for_contexts(void); |
| 68 | bool aclk_online_for_alerts(void); |
| 69 | bool aclk_online_for_nodes(void); |
| 70 | |
| 71 | void aclk_config_get_query_scope(void); |
| 72 | bool aclk_query_scope_has(HTTP_ACL acl); |
| 73 | |
| 74 | extern time_t last_conn_time_mqtt; |
| 75 | extern time_t last_conn_time_appl; |
| 76 | extern time_t last_disconnect_time; |
| 77 | extern time_t next_connection_attempt; |
| 78 | extern float last_backoff_value; |
| 79 | |
| 80 | extern usec_t aclk_session_us; |
| 81 | extern time_t aclk_session_sec; |
| 82 | |
| 83 | extern time_t aclk_block_until; |
| 84 | |
| 85 | extern int aclk_connection_counter; |
| 86 | extern ACLK_DISCONNECT_ACTION disconnect_req; |
| 87 | |
| 88 | extern struct aclk_shared_state { |
| 89 | // To wait for `disconnect` message PUBACK |
| 90 | // when shutting down |
| 91 | // at the same time if > 0 we know link is |
| 92 | // shutting down |
| 93 | int mqtt_shutdown_msg_id; |
| 94 | int mqtt_shutdown_msg_rcvd; |
| 95 | } aclk_shared_state; |
| 96 | |
| 97 | void aclk_host_state_update(RRDHOST *host, int live, int queryable, struct aclk_sync_completion *sync_completion); |
| 98 | bool aclk_host_state_update_auto(RRDHOST *host); |
| 99 | |
| 100 | void aclk_send_node_instances(); |
| 101 | |
| 102 | void aclk_send_bin_msg(char *msg, size_t msg_len, enum aclk_topics subtopic, const char *msgname); |
| 103 | |
| 104 | char *aclk_state(void); |
| 105 | char *aclk_state_json(void); |
| 106 | void add_aclk_host_labels(void); |
| 107 | |
| 108 | struct mqtt_wss_stats aclk_statistics(void); |
| 109 | void aclk_status_set(ACLK_STATUS status); |
| 110 | |
| 111 | #endif /* ACLK_H */ |