myxce/src/include/request.h

167 lines
7.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#if !defined(_REQUEST_H_)
#define _REQUEST_H_ 1
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <openssl/ssl.h>
#include "netio.h"
#include "typemap.h"
#include "utils.h"
#include "xce/types.h"
typedef struct {
int wait;
} reqbar_t;
typedef int (*xce_check_fn_t)(void*);
extern int xce_encode(xce_request_t*, io_packet_t*);
extern int xce_decode(io_packet_t*, xce_request_t*);
extern int xce_reply(endpoint_t*, xce_peerinfo_t*, xce_reply_t*);
extern int xce_hello_req(endpoint_t*, char*);
extern int xce_nop_req(endpoint_t*);
extern int xce_shutdown_req(endpoint_t*);
extern void init_reply_by_req(xce_reply_t*, xce_request_t*);
extern int xce_join_req(endpoint_t*, int, hostattrs_t*);
extern int xce_pushconfig_req(endpoint_t*, xce_peerinfo_t*, xce_configdata_t*);
extern int xce_push_data_req(endpoint_t*, xce_peerinfo_t*, xce_data_t*,
xce_check_fn_t, void*, int);
extern int xce_workerlist_req(endpoint_t*, xce_peerinfo_t*);
extern int xce_reply_workerlist(endpoint_t*, uint64_t, int, xce_peerinfo_t*,
xce_workerlist_t*);
extern int xce_jobdispatch_req(endpoint_t*, xce_job_dispatch_t*);
extern int xce_jobsubmit_req(endpoint_t*, xce_job_submit_t*);
extern int xce_reply_jobdispatch(endpoint_t*, uint64_t, int32_t,
xce_peerinfo_t*);
extern int xce_reply_jobid(endpoint_t*, int, uint64_t, uint64_t,
xce_peerinfo_t*);
extern int xce_joblist_req(endpoint_t*, xce_peerinfo_t*);
extern int xce_reply_joblist(endpoint_t*, uint64_t, int, xce_peerinfo_t*,
xce_job_list_t*);
extern int xce_startjob_req(endpoint_t*, xce_job_exec_t*);
extern int xce_clusterconf_req(endpoint_t*);
extern int xce_reply_clusterconf(endpoint_t*, uint64_t, int, xce_peerinfo_t*,
xce_clusterconf_t*);
extern int xce_get_req(endpoint_t*, xce_get_t*);
extern int xce_reply_get(endpoint_t*, xce_peerinfo_t*, xce_reply_t*,
xce_check_fn_t, void*, int);
extern int xce_notify_req(endpoint_t*, xce_notify_data_t*);
extern int extract_data(dataset_t*, xce_data_t*);
extern int xce_update_req(endpoint_t*, xce_update_data_t*);
extern int xce_jobctrl_req(endpoint_t*, xce_jobctrl_t*);
extern int xce_queuectrl_req(endpoint_t*, xce_queuectrl_t*);
extern int xce_hostctrl_req(endpoint_t*, xce_hostctrl_t*);
extern int xce_runtask_req(endpoint_t*, xce_taskrun_t*);
extern int xce_set_pend_reason_req(endpoint_t*, xce_preason_set_t*);
extern int xce_clear_reason_req(endpoint_t*, xce_clear_reason_t*);
/*
* xce_replconfigpush_req_raw: send OP_replConfigPush carrying raw byte arrays.
* Bypasses the encode_ReplConfigPushRequest_ptr path (which maps sha256/bytes
* through xce_data_t — wrong type for raw bytes) by constructing the capnp
* message directly via capn_new_list8 + capn_setv8 + write_Request.
*/
extern int xce_replconfigpush_req_raw(endpoint_t *ep, xce_peerinfo_t *from,
uint64_t version_tag,
const uint8_t *sha256, size_t sha256_len,
const uint8_t *config_bytes,
size_t config_len);
/*
* xce_replconfig_reply_raw: primary sends an OP_replConfig reply with
* actual config bytes via endpoint (iomgr queued). Bypasses
* encode_ReplConfigReply_ptr (which maps sha256/bytes through xce_data_t).
*/
extern int xce_replconfig_reply_raw(endpoint_t *ep, xce_peerinfo_t *from,
uint64_t seq, uint64_t tag,
const uint8_t *sha256, size_t sha256_len,
const uint8_t *config, size_t config_len);
/*
* xce_replconfig_req_ssl: standby sends OP_replConfig over a raw SSL
* socket (no iomgr). Wire framing: uint64_t size + capnp payload
* (matches netio.c io_fsm_perform).
*/
extern int xce_replconfig_req_ssl(SSL *ssl, uint64_t version_tag);
/*
* xce_replconfig_reply_ssl_decode: standby reads + parses an
* OP_replConfig reply from a raw SSL socket. Output buffers are
* malloc'd and owned by the caller. Both *out_sha256 and *out_bytes
* may be NULL on the up_to_date == 1 fast path.
*/
extern int xce_replconfig_reply_ssl_decode(SSL *ssl,
int *out_up_to_date,
uint64_t *out_tag,
uint8_t **out_sha256,
uint8_t **out_bytes,
size_t *out_len);
/*
* xce_upgrade_config_req_extract: extract bytes from a decoded
* OP_upgradeConfig request. Returns -ENOTSUP — see request.c
* for the architectural finding. Use xce_upgrade_config_req_extract_raw
* with the raw packet buffer instead.
*/
extern int xce_upgrade_config_req_extract(const xce_request_t *req,
uint8_t **out_bytes,
size_t *out_len,
uint8_t **out_sha256);
/*
* xce_upgrade_config_req_extract_raw: parse OP_upgradeConfig request
* bytes from a raw on-wire packet buffer. Output buffers (*out_bytes,
* *out_sha256) are malloc'd and owned by the caller.
*/
extern int xce_upgrade_config_req_extract_raw(const uint8_t *pkt_data,
size_t pkt_sz,
uint8_t **out_bytes,
size_t *out_len,
uint8_t **out_sha256);
/* ── Task 10.2: Client-Side Transparent Retry (Req 7.1–7.6) ─────────────────
*
* xce_retry_config_t: configurable retry parameters with safe production defaults.
* Pass NULL to xce_request_with_retry() to use defaults.
*/
typedef struct {
int max_retries; /* default 20 */
int initial_retry_ms; /* default 50 */
int max_retry_ms; /* default 5000 */
double backoff_multiplier; /* default 2.0 (exponential) */
} xce_retry_config_t;
extern const xce_retry_config_t XCE_RETRY_DEFAULTS;
/*
* xce_request_with_retry: transparent retry wrapper for transient controller errors.
*
* - XCE_ERR_NOT_READY → backoff, retry same endpoint (Req 7.1)
* - XCE_ERR_STANDBY with redirect_host/port → reconnect, retry (Req 7.2)
* - XCE_ERR_STANDBY without redirect → backoff, retry (Req 7.2 fallback)
* - ECONNREFUSED / ETIMEDOUT → reconnect, retry (Req 7.3)
* - EPERM / EINVAL / ENOENT / EACCES → surface immediately (Req 7.4)
* - Exhausted max_retries → surface last error (Req 7.5)
* - Backoff jitter via rand_r() to prevent thundering herd (Req 7.6)
*
* NULL cfg → uses XCE_RETRY_DEFAULTS.
*/
extern int xce_request_with_retry(endpoint_t *ep,
xce_request_t *req,
const xce_retry_config_t *cfg);
/*
* xce_retry_send_hook: test-only injection point for the send+receive round-trip.
* When non-NULL, xce_request_with_retry() calls this instead of the real network path.
* Returns 0 on success (reply_out populated), -errno on transport failure.
*/
extern int (*xce_retry_send_hook)(endpoint_t *ep, xce_request_t *req,
xce_reply_t *reply_out);
#endif