From 36f09a0c35657f5c7379624c8a2463aafb953bd4 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 7 Sep 2026 14:30:40 -0400 Subject: Add function to query rpc clients' clock skew Signed-off-by: Andrew Opalach --- src/rpc2.h | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/rpc2.h') diff --git a/src/rpc2.h b/src/rpc2.h index bed8822..52e14ec 100644 --- a/src/rpc2.h +++ b/src/rpc2.h @@ -13,11 +13,27 @@ struct nn_rpc_callback { void *userdata; }; +enum { + NNWT_SKEW_POSITIVE = 0, + NNWT_SKEW_NEGATIVE +}; + +struct nn_skew { + u64 ts; + bool direction; +}; + struct nn_rpc_connection { struct nn_packet_stream *stream; array(struct nn_rpc_callback) callbacks; u32 outgoing; bool flushing; + struct { + struct nn_skew s; + s8 query_active; + u32 repeat; + array(struct nn_skew) results; + } skew; struct nn_rpc *rpc; }; @@ -31,21 +47,26 @@ struct nn_rpc { struct nn_event_loop *loop; u32 increment; array(struct nn_rpc_command) commands; + bool do_query_skew; struct nn_rpc_connection *conn; // client array(struct nn_rpc_connection *) connections; void (*connection_callback)(void *, struct nn_rpc_connection *); + void (*ready_callback)(void *, struct nn_rpc_connection *); void (*connection_closed_callback)(void *, struct nn_rpc_connection *); void *userdata; }; bool nn_rpc_init(struct nn_rpc *rpc, struct nn_event_loop *loop, void (*connection_callback)(void *, struct nn_rpc_connection *), + void (*ready_callback)(void *, struct nn_rpc_connection *), void (*connection_closed_callback)(void *, struct nn_rpc_connection *), void *userdata); +void nn_rpc_query_clock_skews(struct nn_rpc *rpc, bool do_query_skew); void nn_rpc_add_command(struct nn_rpc *rpc, struct nn_rpc_command *command); void nn_rpc_add_stream(struct nn_rpc *rpc, struct nn_packet_stream *stream); -struct nn_rpc_connection *nn_rpc_prepare_client(struct nn_rpc *rpc); -void nn_rpc_connect(struct nn_rpc *rpc, u8 id, u8 type, str *addr, u16 port); - struct nn_rpc_connection *nn_rpc_reconnect(struct nn_rpc *rpc, str *addr, u16 port); +void nn_rpc_prepare_client(struct nn_rpc *rpc); +bool nn_rpc_connect(struct nn_rpc *rpc, u8 id, u8 type, str *addr, u16 port); +bool nn_rpc_reconnect(struct nn_rpc *rpc, str *addr, u16 port); +void nn_rpc_disconnect(struct nn_rpc *rpc); struct nn_packet *nn_rpc_get_packet(struct nn_rpc *rpc, s8 op); void nn_rpc_free(struct nn_rpc *rpc); -- cgit v1.2.3-101-g0448