#ifndef NET_DECK_H
#define NET_DECK_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define NET_DECK_OK 0
#define NET_DECK_ERR_NULL -1
#define NET_DECK_ERR_CALL_FAILED -2
#define NET_DECK_ERR_INVALID_ARG -3
#define NET_DECK_ERR_ALREADY_SHUTDOWN -4
#define NET_DECK_ERR_END_OF_STREAM -5
#define NET_DECK_EVENT_KIND_UNKNOWN 0
#define NET_DECK_EVENT_KIND_DRAIN 1
#define NET_DECK_EVENT_KIND_ENTER_MAINTENANCE 2
#define NET_DECK_EVENT_KIND_EXIT_MAINTENANCE 3
#define NET_DECK_EVENT_KIND_CORDON 4
#define NET_DECK_EVENT_KIND_UNCORDON 5
#define NET_DECK_EVENT_KIND_DROP_REPLICAS 6
#define NET_DECK_EVENT_KIND_INVALIDATE_PLACEMENT 7
#define NET_DECK_EVENT_KIND_RESTART_ALL_DAEMONS 8
#define NET_DECK_EVENT_KIND_CLEAR_AVOID_LIST 9
typedef struct {
unsigned int healthy;
unsigned int degraded;
unsigned int unreachable;
unsigned int unknown;
} NetDeckPeerCounts;
typedef struct {
unsigned int running;
unsigned int starting;
unsigned int stopping;
unsigned int stopped;
unsigned int backing_off;
unsigned int crash_looping;
} NetDeckDaemonCounts;
typedef struct {
NetDeckPeerCounts peers;
NetDeckDaemonCounts daemons;
unsigned int replica_chains;
unsigned int avoid_list_entries;
unsigned int recently_emitted_count;
unsigned int recent_failure_count;
unsigned int admin_audit_ring_depth;
int freeze_remaining_present;
uint64_t freeze_remaining_ms;
int local_maintenance_active;
} NetDeckStatusSummary;
typedef struct {
uint64_t commit_id;
uint64_t operator_id;
int event_kind;
uint64_t committed_at_ms;
} NetDeckChainCommit;
typedef struct NetDeckClient NetDeckClient;
typedef struct NetDeckSnapshotStream NetDeckSnapshotStream;
typedef struct NetDeckStatusSummaryStream NetDeckStatusSummaryStream;
int net_deck_client_new(
uint64_t this_node,
uint64_t tick_interval_ms,
size_t event_queue_capacity,
size_t action_queue_capacity,
uint64_t snapshot_poll_interval_ms,
size_t ice_signature_threshold,
const uint8_t* operator_seed_ptr,
NetDeckClient** out
);
void net_deck_client_free(NetDeckClient* client);
uint64_t net_deck_client_operator_id(const NetDeckClient* client);
char* net_deck_status(const NetDeckClient* client);
int net_deck_status_summary(
const NetDeckClient* client,
NetDeckStatusSummary* out
);
void net_deck_free_string(char* s);
int net_deck_admin_drain(
const NetDeckClient* client,
uint64_t node,
uint64_t drain_for_ms,
NetDeckChainCommit* out
);
int net_deck_admin_enter_maintenance(
const NetDeckClient* client,
uint64_t node,
uint64_t drain_for_ms,
int has_drain_for,
NetDeckChainCommit* out
);
int net_deck_admin_exit_maintenance(
const NetDeckClient* client,
uint64_t node,
NetDeckChainCommit* out
);
int net_deck_admin_cordon(
const NetDeckClient* client,
uint64_t node,
NetDeckChainCommit* out
);
int net_deck_admin_uncordon(
const NetDeckClient* client,
uint64_t node,
NetDeckChainCommit* out
);
int net_deck_admin_drop_replicas(
const NetDeckClient* client,
uint64_t node,
const uint64_t* chains_ptr,
size_t chains_len,
NetDeckChainCommit* out
);
int net_deck_admin_invalidate_placement(
const NetDeckClient* client,
uint64_t node,
NetDeckChainCommit* out
);
int net_deck_admin_restart_all_daemons(
const NetDeckClient* client,
uint64_t node,
NetDeckChainCommit* out
);
int net_deck_admin_clear_avoid_list(
const NetDeckClient* client,
uint64_t node,
NetDeckChainCommit* out
);
int net_deck_subscribe_snapshots(
const NetDeckClient* client,
NetDeckSnapshotStream** out
);
int net_deck_snapshot_stream_next(
NetDeckSnapshotStream* stream,
uint64_t timeout_ms,
char** out
);
void net_deck_snapshot_stream_free(NetDeckSnapshotStream* stream);
int net_deck_subscribe_status_summaries(
const NetDeckClient* client,
NetDeckStatusSummaryStream** out
);
int net_deck_status_summary_stream_next(
NetDeckStatusSummaryStream* stream,
uint64_t timeout_ms,
NetDeckStatusSummary* out,
int* has_item_out
);
void net_deck_status_summary_stream_free(NetDeckStatusSummaryStream* stream);
#define NET_DECK_LOG_TRACE 0
#define NET_DECK_LOG_DEBUG 1
#define NET_DECK_LOG_INFO 2
#define NET_DECK_LOG_WARN 3
#define NET_DECK_LOG_ERROR 4
typedef struct {
int min_level_present;
int min_level;
int daemon_id_present;
uint64_t daemon_id;
int node_id_present;
uint64_t node_id;
int since_seq_present;
uint64_t since_seq;
} NetDeckLogFilter;
typedef struct {
uint64_t seq;
uint64_t ts_ms;
int level;
int daemon_id_present;
uint64_t daemon_id;
int node_id_present;
uint64_t node_id;
char* message;
} NetDeckLogRecord;
void net_deck_log_record_drop(NetDeckLogRecord* record);
typedef struct {
uint64_t seq;
char* source;
char* reason;
uint64_t recorded_at_ms;
} NetDeckFailureRecord;
void net_deck_failure_record_drop(NetDeckFailureRecord* record);
typedef struct NetDeckLogStream NetDeckLogStream;
typedef struct NetDeckFailureStream NetDeckFailureStream;
int net_deck_subscribe_logs(
const NetDeckClient* client,
const NetDeckLogFilter* filter,
NetDeckLogStream** out
);
int net_deck_log_stream_next(
NetDeckLogStream* stream,
uint64_t timeout_ms,
NetDeckLogRecord* out,
int* has_item_out
);
void net_deck_log_stream_free(NetDeckLogStream* stream);
int net_deck_subscribe_failures(
const NetDeckClient* client,
uint64_t since_seq,
NetDeckFailureStream** out
);
int net_deck_failure_stream_next(
NetDeckFailureStream* stream,
uint64_t timeout_ms,
NetDeckFailureRecord* out,
int* has_item_out
);
void net_deck_failure_stream_free(NetDeckFailureStream* stream);
typedef struct NetDeckAuditQuery NetDeckAuditQuery;
typedef struct NetDeckAuditStream NetDeckAuditStream;
int net_deck_audit_query_new(NetDeckAuditQuery** out);
void net_deck_audit_query_free(NetDeckAuditQuery* query);
int net_deck_audit_query_recent(NetDeckAuditQuery* query, size_t limit);
int net_deck_audit_query_by_operator(NetDeckAuditQuery* query, uint64_t operator_id);
int net_deck_audit_query_between(
NetDeckAuditQuery* query, uint64_t start_ms, uint64_t end_ms
);
int net_deck_audit_query_force_only(NetDeckAuditQuery* query);
int net_deck_audit_query_since(NetDeckAuditQuery* query, uint64_t seq);
int net_deck_audit_query_collect(
const NetDeckAuditQuery* query,
const NetDeckClient* client,
char*** records_out,
size_t* count_out
);
void net_deck_audit_records_free(char** records, size_t count);
int net_deck_audit_query_stream(
const NetDeckAuditQuery* query,
const NetDeckClient* client,
NetDeckAuditStream** out
);
int net_deck_audit_stream_next(
NetDeckAuditStream* stream,
uint64_t timeout_ms,
char** out
);
void net_deck_audit_stream_free(NetDeckAuditStream* stream);
#define NET_DECK_AVOID_SCOPE_GLOBAL 0
#define NET_DECK_AVOID_SCOPE_LOCAL 1
#define NET_DECK_AVOID_SCOPE_ON_PEER 2
typedef struct {
uint64_t operator_id;
const uint8_t* signature_ptr;
size_t signature_len;
} NetDeckOperatorSignature;
typedef struct NetDeckIceProposal NetDeckIceProposal;
typedef struct NetDeckSimulatedIceProposal NetDeckSimulatedIceProposal;
int net_deck_ice_freeze_cluster(
const NetDeckClient* client,
uint64_t ttl_ms,
NetDeckIceProposal** out
);
int net_deck_ice_flush_avoid_lists(
const NetDeckClient* client,
int scope_kind,
uint64_t scope_node,
uint64_t scope_peer,
NetDeckIceProposal** out
);
int net_deck_ice_force_evict_replica(
const NetDeckClient* client,
uint64_t chain,
uint64_t victim,
NetDeckIceProposal** out
);
int net_deck_ice_force_restart_daemon(
const NetDeckClient* client,
uint64_t id,
const char* name_ptr,
size_t name_len,
NetDeckIceProposal** out
);
int net_deck_ice_force_cutover(
const NetDeckClient* client,
uint64_t chain,
uint64_t target,
NetDeckIceProposal** out
);
int net_deck_ice_kill_migration(
const NetDeckClient* client,
uint64_t migration,
NetDeckIceProposal** out
);
int net_deck_ice_thaw_cluster(
const NetDeckClient* client,
NetDeckIceProposal** out
);
uint64_t net_deck_ice_proposal_issued_at_ms(
const NetDeckIceProposal* proposal
);
void net_deck_ice_proposal_free(NetDeckIceProposal* proposal);
int net_deck_ice_proposal_simulate(
NetDeckIceProposal* proposal,
const NetDeckClient* client,
NetDeckSimulatedIceProposal** out
);
uint64_t net_deck_simulated_issued_at_ms(
const NetDeckSimulatedIceProposal* simulated
);
char* net_deck_simulated_blast_radius(
const NetDeckSimulatedIceProposal* simulated
);
int net_deck_simulated_blast_hash(
const NetDeckSimulatedIceProposal* simulated,
uint8_t* out_buf
);
int net_deck_simulated_commit(
NetDeckSimulatedIceProposal* simulated,
const NetDeckClient* client,
const NetDeckOperatorSignature* sigs_ptr,
size_t sigs_count,
NetDeckChainCommit* out
);
void net_deck_simulated_free(NetDeckSimulatedIceProposal* simulated);
int net_deck_simulated_signing_payload(
const NetDeckSimulatedIceProposal* simulated,
uint8_t** out_ptr,
size_t* out_len
);
void net_deck_signing_payload_free(uint8_t* ptr, size_t len);
typedef struct NetDeckOperatorIdentity NetDeckOperatorIdentity;
NetDeckOperatorIdentity* net_deck_operator_identity_generate(void);
int net_deck_operator_identity_from_seed(
const uint8_t* seed_ptr,
NetDeckOperatorIdentity** out
);
uint64_t net_deck_operator_identity_operator_id(
const NetDeckOperatorIdentity* identity
);
int net_deck_operator_identity_public_key(
const NetDeckOperatorIdentity* identity,
uint8_t* out_buf
);
int net_deck_operator_identity_sign_proposal(
const NetDeckOperatorIdentity* identity,
const NetDeckSimulatedIceProposal* simulated,
uint64_t* out_operator_id,
uint8_t* out_signature
);
int net_deck_operator_identity_sign_payload(
const NetDeckOperatorIdentity* identity,
const uint8_t* payload_ptr,
size_t payload_len,
uint64_t* out_operator_id,
uint8_t* out_signature
);
void net_deck_operator_identity_free(NetDeckOperatorIdentity* identity);
typedef struct NetDeckOperatorRegistry NetDeckOperatorRegistry;
NetDeckOperatorRegistry* net_deck_operator_registry_new(void);
int net_deck_operator_registry_insert(
NetDeckOperatorRegistry* registry,
uint64_t operator_id,
const uint8_t* public_key
);
int net_deck_operator_registry_register(
NetDeckOperatorRegistry* registry,
const NetDeckOperatorIdentity* identity
);
int net_deck_operator_registry_contains(
const NetDeckOperatorRegistry* registry,
uint64_t operator_id
);
size_t net_deck_operator_registry_len(
const NetDeckOperatorRegistry* registry
);
int net_deck_operator_registry_verify(
const NetDeckOperatorRegistry* registry,
const NetDeckOperatorSignature* signature,
const uint8_t* payload_ptr,
size_t payload_len
);
int net_deck_operator_registry_verify_bundle(
const NetDeckOperatorRegistry* registry,
const NetDeckOperatorSignature* sigs_ptr,
size_t sigs_count,
const uint8_t* payload_ptr,
size_t payload_len,
size_t threshold
);
void net_deck_operator_registry_free(NetDeckOperatorRegistry* registry);
typedef struct NetDeckAdminVerifier NetDeckAdminVerifier;
NetDeckAdminVerifier* net_deck_admin_verifier_new(
const NetDeckOperatorRegistry* registry,
size_t threshold
);
NetDeckAdminVerifier* net_deck_admin_verifier_with_freshness(
const NetDeckOperatorRegistry* registry,
size_t threshold,
uint64_t freshness_window_ms,
uint64_t future_skew_ms
);
NetDeckAdminVerifier* net_deck_admin_verifier_with_full_policy(
const NetDeckOperatorRegistry* registry,
size_t threshold,
uint64_t freshness_window_ms,
uint64_t future_skew_ms,
uint64_t ice_cooldown_ms
);
size_t net_deck_admin_verifier_threshold(const NetDeckAdminVerifier* verifier);
uint64_t net_deck_admin_verifier_freshness_window_ms(const NetDeckAdminVerifier* verifier);
uint64_t net_deck_admin_verifier_future_skew_ms(const NetDeckAdminVerifier* verifier);
uint64_t net_deck_admin_verifier_ice_cooldown_ms(const NetDeckAdminVerifier* verifier);
void net_deck_admin_verifier_free(NetDeckAdminVerifier* verifier);
const char* net_deck_last_error_message(void);
const char* net_deck_last_error_kind(void);
void net_deck_clear_last_error(void);
#ifdef __cplusplus
}
#endif
#endif