#ifndef CIRCE_CORE_H #define CIRCE_CORE_H #include "peer_table.h" #include #include enum circe_result { CIRCE_RESULT_SUCCESS = 0, CIRCE_RESULT_INSUFFICIENT_MEM, CIRCE_RESULT_INVALID_PACKET, CIRCE_RESULT_INVALID_MAC, CIRCE_RESULT_INTERNAL_ERROR, }; enum circe_version { CIRCE_VERSION_V1 = 0, }; struct circe_event { enum { CIRCE_EVENT_DATA_RECEIVED, CIRCE_EVENT_NEW_REMOTE, CIRCE_EVENT_REJECTED_REMOTE, } event_type; }; enum circe_deadline { CIRCE_DEADLINE_NOW, CIRCE_DEADLINE_INDEFINITE, CIRCE_DEADLINE_AS_INDICATED, }; /// Process a new incoming raw Circe packet. enum circe_result circe_handle_packet (const struct circe_location remote, const uint8_t *in, size_t len, uint64_t now_ms, uint8_t *out, size_t *out_len, struct circe_event *events, size_t *n_events); /// Put outgoing packet into Circe's internal logic. DOES NOT ACTUALLY SEND IT /// OVER THE NETWORK; that is handled opaquely by the caller and `circe_tick`. enum circe_result circe_send_outgoing_packet (const uint8_t remote_identity[CIRCE_IDENTITY_LEN], const uint8_t *in, size_t len, uint64_t now_ms, struct circe_event *events, size_t *n_events); /// Get deadline and corresponding millisecond timestamp (for /// `CIRCE_DEADLINE_AS_INDICATED`) for next timer deadline, at which point /// `circe_tick` should be called. Should always be called immediately after /// any other core API function is called to stay up-to-date. enum circe_deadline circe_next_deadline (uint64_t *ms_timestamp); /// Iterate the Circe core logic. Assumes `now_ms` increases monotonically with /// time. If `out_len` is nonzero (do not pass in NULL), then `out` contains a /// new raw Circe packet to be sent out to the location `destination`. enum circe_result circe_tick (uint64_t now_ms, uint8_t *out, size_t *out_len, struct circe_location *destination); #endif