This is an automated email from the git hooks/post-receive script.
ahf pushed a commit to branch main in repository tor.
commit 45432175fe6b0929274d6db94aa50aab9a39b452 Author: David Goulet dgoulet@torproject.org AuthorDate: Mon Dec 12 13:09:27 2022 -0500
trunnel: Add Conflux related cell definition
Signed-off-by: David Goulet dgoulet@torproject.org --- src/trunnel/conflux.c | 1158 +++++++++++++++++++++++++++++++++++++++++++ src/trunnel/conflux.h | 422 ++++++++++++++++ src/trunnel/conflux.trunnel | 66 +++ src/trunnel/include.am | 9 +- 4 files changed, 1652 insertions(+), 3 deletions(-)
diff --git a/src/trunnel/conflux.c b/src/trunnel/conflux.c new file mode 100644 index 0000000000..5f1cb41ff2 --- /dev/null +++ b/src/trunnel/conflux.c @@ -0,0 +1,1158 @@ +/* conflux.c -- generated by Trunnel v1.5.3. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#include <stdlib.h> +#include "trunnel-impl.h" + +#include "conflux.h" + +#define TRUNNEL_SET_ERROR_CODE(obj) \ + do { \ + (obj)->trunnel_error_code_ = 1; \ + } while (0) + +#if defined(__COVERITY__) || defined(__clang_analyzer__) +/* If we're running a static analysis tool, we don't want it to complain + * that some of our remaining-bytes checks are dead-code. */ +int conflux_deadcode_dummy__ = 0; +#define OR_DEADCODE_DUMMY || conflux_deadcode_dummy__ +#else +#define OR_DEADCODE_DUMMY +#endif + +#define CHECK_REMAINING(nbytes, label) \ + do { \ + if (remaining < (nbytes) OR_DEADCODE_DUMMY) { \ + goto label; \ + } \ + } while (0) + +trn_cell_conflux_link_t * +trn_cell_conflux_link_new(void) +{ + trn_cell_conflux_link_t *val = trunnel_calloc(1, sizeof(trn_cell_conflux_link_t)); + if (NULL == val) + return NULL; + val->version = 1; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +trn_cell_conflux_link_clear(trn_cell_conflux_link_t *obj) +{ + (void) obj; + TRUNNEL_DYNARRAY_WIPE(&obj->payload); + TRUNNEL_DYNARRAY_CLEAR(&obj->payload); +} + +void +trn_cell_conflux_link_free(trn_cell_conflux_link_t *obj) +{ + if (obj == NULL) + return; + trn_cell_conflux_link_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_conflux_link_t)); + trunnel_free_(obj); +} + +uint8_t +trn_cell_conflux_link_get_version(const trn_cell_conflux_link_t *inp) +{ + return inp->version; +} +int +trn_cell_conflux_link_set_version(trn_cell_conflux_link_t *inp, uint8_t val) +{ + if (! ((val == 1))) { + TRUNNEL_SET_ERROR_CODE(inp); + return -1; + } + inp->version = val; + return 0; +} +size_t +trn_cell_conflux_link_getlen_payload(const trn_cell_conflux_link_t *inp) +{ + return TRUNNEL_DYNARRAY_LEN(&inp->payload); +} + +uint8_t +trn_cell_conflux_link_get_payload(trn_cell_conflux_link_t *inp, size_t idx) +{ + return TRUNNEL_DYNARRAY_GET(&inp->payload, idx); +} + +uint8_t +trn_cell_conflux_link_getconst_payload(const trn_cell_conflux_link_t *inp, size_t idx) +{ + return trn_cell_conflux_link_get_payload((trn_cell_conflux_link_t*)inp, idx); +} +int +trn_cell_conflux_link_set_payload(trn_cell_conflux_link_t *inp, size_t idx, uint8_t elt) +{ + TRUNNEL_DYNARRAY_SET(&inp->payload, idx, elt); + return 0; +} +int +trn_cell_conflux_link_add_payload(trn_cell_conflux_link_t *inp, uint8_t elt) +{ + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->payload, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +trn_cell_conflux_link_getarray_payload(trn_cell_conflux_link_t *inp) +{ + return inp->payload.elts_; +} +const uint8_t * +trn_cell_conflux_link_getconstarray_payload(const trn_cell_conflux_link_t *inp) +{ + return (const uint8_t *)trn_cell_conflux_link_getarray_payload((trn_cell_conflux_link_t*)inp); +} +int +trn_cell_conflux_link_setlen_payload(trn_cell_conflux_link_t *inp, size_t newlen) +{ + uint8_t *newptr; + newptr = trunnel_dynarray_setlen(&inp->payload.allocated_, + &inp->payload.n_, inp->payload.elts_, newlen, + sizeof(inp->payload.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->payload.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +trn_cell_conflux_link_check(const trn_cell_conflux_link_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + if (! (obj->version == 1)) + return "Integer out of bounds"; + return NULL; +} + +ssize_t +trn_cell_conflux_link_encoded_len(const trn_cell_conflux_link_t *obj) +{ + ssize_t result = 0; + + if (NULL != trn_cell_conflux_link_check(obj)) + return -1; + + + /* Length of u8 version IN [1] */ + result += 1; + + /* Length of u8 payload[] */ + result += TRUNNEL_DYNARRAY_LEN(&obj->payload); + return result; +} +int +trn_cell_conflux_link_clear_errors(trn_cell_conflux_link_t *obj) +{ + int r = obj->trunnel_error_code_; + obj->trunnel_error_code_ = 0; + return r; +} +ssize_t +trn_cell_conflux_link_encode(uint8_t *output, const size_t avail, const trn_cell_conflux_link_t *obj) +{ + ssize_t result = 0; + size_t written = 0; + uint8_t *ptr = output; + const char *msg; +#ifdef TRUNNEL_CHECK_ENCODED_LEN + const ssize_t encoded_len = trn_cell_conflux_link_encoded_len(obj); +#endif + + if (NULL != (msg = trn_cell_conflux_link_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 version IN [1] */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->version)); + written += 1; ptr += 1; + + /* Encode u8 payload[] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->payload); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->payload.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As trn_cell_conflux_link_parse(), but do not allocate the output + * object. + */ +static ssize_t +trn_cell_conflux_link_parse_into(trn_cell_conflux_link_t *obj, const uint8_t *input, const size_t len_in) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 version IN [1] */ + CHECK_REMAINING(1, truncated); + obj->version = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + if (! (obj->version == 1)) + goto fail; + + /* Parse u8 payload[] */ + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->payload, remaining, {}); + obj->payload.n_ = remaining; + if (remaining) + memcpy(obj->payload.elts_, ptr, remaining); + ptr += remaining; remaining -= remaining; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + trunnel_alloc_failed: + return -1; + fail: + result = -1; + return result; +} + +ssize_t +trn_cell_conflux_link_parse(trn_cell_conflux_link_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = trn_cell_conflux_link_new(); + if (NULL == *output) + return -1; + result = trn_cell_conflux_link_parse_into(*output, input, len_in); + if (result < 0) { + trn_cell_conflux_link_free(*output); + *output = NULL; + } + return result; +} +trn_cell_conflux_link_payload_v1_t * +trn_cell_conflux_link_payload_v1_new(void) +{ + trn_cell_conflux_link_payload_v1_t *val = trunnel_calloc(1, sizeof(trn_cell_conflux_link_payload_v1_t)); + if (NULL == val) + return NULL; + val->desired_ux = CONFLUX_UX_HIGH_THROUGHPUT; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +trn_cell_conflux_link_payload_v1_clear(trn_cell_conflux_link_payload_v1_t *obj) +{ + (void) obj; +} + +void +trn_cell_conflux_link_payload_v1_free(trn_cell_conflux_link_payload_v1_t *obj) +{ + if (obj == NULL) + return; + trn_cell_conflux_link_payload_v1_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_conflux_link_payload_v1_t)); + trunnel_free_(obj); +} + +size_t +trn_cell_conflux_link_payload_v1_getlen_nonce(const trn_cell_conflux_link_payload_v1_t *inp) +{ + (void)inp; return 32; +} + +uint8_t +trn_cell_conflux_link_payload_v1_get_nonce(trn_cell_conflux_link_payload_v1_t *inp, size_t idx) +{ + trunnel_assert(idx < 32); + return inp->nonce[idx]; +} + +uint8_t +trn_cell_conflux_link_payload_v1_getconst_nonce(const trn_cell_conflux_link_payload_v1_t *inp, size_t idx) +{ + return trn_cell_conflux_link_payload_v1_get_nonce((trn_cell_conflux_link_payload_v1_t*)inp, idx); +} +int +trn_cell_conflux_link_payload_v1_set_nonce(trn_cell_conflux_link_payload_v1_t *inp, size_t idx, uint8_t elt) +{ + trunnel_assert(idx < 32); + inp->nonce[idx] = elt; + return 0; +} + +uint8_t * +trn_cell_conflux_link_payload_v1_getarray_nonce(trn_cell_conflux_link_payload_v1_t *inp) +{ + return inp->nonce; +} +const uint8_t * +trn_cell_conflux_link_payload_v1_getconstarray_nonce(const trn_cell_conflux_link_payload_v1_t *inp) +{ + return (const uint8_t *)trn_cell_conflux_link_payload_v1_getarray_nonce((trn_cell_conflux_link_payload_v1_t*)inp); +} +uint64_t +trn_cell_conflux_link_payload_v1_get_last_seqno_sent(const trn_cell_conflux_link_payload_v1_t *inp) +{ + return inp->last_seqno_sent; +} +int +trn_cell_conflux_link_payload_v1_set_last_seqno_sent(trn_cell_conflux_link_payload_v1_t *inp, uint64_t val) +{ + inp->last_seqno_sent = val; + return 0; +} +uint64_t +trn_cell_conflux_link_payload_v1_get_last_seqno_recv(const trn_cell_conflux_link_payload_v1_t *inp) +{ + return inp->last_seqno_recv; +} +int +trn_cell_conflux_link_payload_v1_set_last_seqno_recv(trn_cell_conflux_link_payload_v1_t *inp, uint64_t val) +{ + inp->last_seqno_recv = val; + return 0; +} +uint8_t +trn_cell_conflux_link_payload_v1_get_desired_ux(const trn_cell_conflux_link_payload_v1_t *inp) +{ + return inp->desired_ux; +} +int +trn_cell_conflux_link_payload_v1_set_desired_ux(trn_cell_conflux_link_payload_v1_t *inp, uint8_t val) +{ + if (! ((val == CONFLUX_UX_HIGH_THROUGHPUT || val == CONFLUX_UX_LOW_MEM_LATENCY || val == CONFLUX_UX_LOW_MEM_THROUGHPUT || val == CONFLUX_UX_MIN_LATENCY || val == CONFLUX_UX_NO_OPINION))) { + TRUNNEL_SET_ERROR_CODE(inp); + return -1; + } + inp->desired_ux = val; + return 0; +} +const char * +trn_cell_conflux_link_payload_v1_check(const trn_cell_conflux_link_payload_v1_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + if (! (obj->desired_ux == CONFLUX_UX_HIGH_THROUGHPUT || obj->desired_ux == CONFLUX_UX_LOW_MEM_LATENCY || obj->desired_ux == CONFLUX_UX_LOW_MEM_THROUGHPUT || obj->desired_ux == CONFLUX_UX_MIN_LATENCY || obj->desired_ux == CONFLUX_UX_NO_OPINION)) + return "Integer out of bounds"; + return NULL; +} + +ssize_t +trn_cell_conflux_link_payload_v1_encoded_len(const trn_cell_conflux_link_payload_v1_t *obj) +{ + ssize_t result = 0; + + if (NULL != trn_cell_conflux_link_payload_v1_check(obj)) + return -1; + + + /* Length of u8 nonce[32] */ + result += 32; + + /* Length of u64 last_seqno_sent */ + result += 8; + + /* Length of u64 last_seqno_recv */ + result += 8; + + /* Length of u8 desired_ux IN [CONFLUX_UX_HIGH_THROUGHPUT, CONFLUX_UX_LOW_MEM_LATENCY, CONFLUX_UX_LOW_MEM_THROUGHPUT, CONFLUX_UX_MIN_LATENCY, CONFLUX_UX_NO_OPINION] */ + result += 1; + return result; +} +int +trn_cell_conflux_link_payload_v1_clear_errors(trn_cell_conflux_link_payload_v1_t *obj) +{ + int r = obj->trunnel_error_code_; + obj->trunnel_error_code_ = 0; + return r; +} +ssize_t +trn_cell_conflux_link_payload_v1_encode(uint8_t *output, const size_t avail, const trn_cell_conflux_link_payload_v1_t *obj) +{ + ssize_t result = 0; + size_t written = 0; + uint8_t *ptr = output; + const char *msg; +#ifdef TRUNNEL_CHECK_ENCODED_LEN + const ssize_t encoded_len = trn_cell_conflux_link_payload_v1_encoded_len(obj); +#endif + + if (NULL != (msg = trn_cell_conflux_link_payload_v1_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 nonce[32] */ + trunnel_assert(written <= avail); + if (avail - written < 32) + goto truncated; + memcpy(ptr, obj->nonce, 32); + written += 32; ptr += 32; + + /* Encode u64 last_seqno_sent */ + trunnel_assert(written <= avail); + if (avail - written < 8) + goto truncated; + trunnel_set_uint64(ptr, trunnel_htonll(obj->last_seqno_sent)); + written += 8; ptr += 8; + + /* Encode u64 last_seqno_recv */ + trunnel_assert(written <= avail); + if (avail - written < 8) + goto truncated; + trunnel_set_uint64(ptr, trunnel_htonll(obj->last_seqno_recv)); + written += 8; ptr += 8; + + /* Encode u8 desired_ux IN [CONFLUX_UX_HIGH_THROUGHPUT, CONFLUX_UX_LOW_MEM_LATENCY, CONFLUX_UX_LOW_MEM_THROUGHPUT, CONFLUX_UX_MIN_LATENCY, CONFLUX_UX_NO_OPINION] */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->desired_ux)); + written += 1; ptr += 1; + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As trn_cell_conflux_link_payload_v1_parse(), but do not allocate + * the output object. + */ +static ssize_t +trn_cell_conflux_link_payload_v1_parse_into(trn_cell_conflux_link_payload_v1_t *obj, const uint8_t *input, const size_t len_in) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 nonce[32] */ + CHECK_REMAINING(32, truncated); + memcpy(obj->nonce, ptr, 32); + remaining -= 32; ptr += 32; + + /* Parse u64 last_seqno_sent */ + CHECK_REMAINING(8, truncated); + obj->last_seqno_sent = trunnel_ntohll(trunnel_get_uint64(ptr)); + remaining -= 8; ptr += 8; + + /* Parse u64 last_seqno_recv */ + CHECK_REMAINING(8, truncated); + obj->last_seqno_recv = trunnel_ntohll(trunnel_get_uint64(ptr)); + remaining -= 8; ptr += 8; + + /* Parse u8 desired_ux IN [CONFLUX_UX_HIGH_THROUGHPUT, CONFLUX_UX_LOW_MEM_LATENCY, CONFLUX_UX_LOW_MEM_THROUGHPUT, CONFLUX_UX_MIN_LATENCY, CONFLUX_UX_NO_OPINION] */ + CHECK_REMAINING(1, truncated); + obj->desired_ux = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + if (! (obj->desired_ux == CONFLUX_UX_HIGH_THROUGHPUT || obj->desired_ux == CONFLUX_UX_LOW_MEM_LATENCY || obj->desired_ux == CONFLUX_UX_LOW_MEM_THROUGHPUT || obj->desired_ux == CONFLUX_UX_MIN_LATENCY || obj->desired_ux == CONFLUX_UX_NO_OPINION)) + goto fail; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + fail: + result = -1; + return result; +} + +ssize_t +trn_cell_conflux_link_payload_v1_parse(trn_cell_conflux_link_payload_v1_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = trn_cell_conflux_link_payload_v1_new(); + if (NULL == *output) + return -1; + result = trn_cell_conflux_link_payload_v1_parse_into(*output, input, len_in); + if (result < 0) { + trn_cell_conflux_link_payload_v1_free(*output); + *output = NULL; + } + return result; +} +trn_cell_conflux_linked_t * +trn_cell_conflux_linked_new(void) +{ + trn_cell_conflux_linked_t *val = trunnel_calloc(1, sizeof(trn_cell_conflux_linked_t)); + if (NULL == val) + return NULL; + val->version = 1; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +trn_cell_conflux_linked_clear(trn_cell_conflux_linked_t *obj) +{ + (void) obj; + TRUNNEL_DYNARRAY_WIPE(&obj->payload); + TRUNNEL_DYNARRAY_CLEAR(&obj->payload); +} + +void +trn_cell_conflux_linked_free(trn_cell_conflux_linked_t *obj) +{ + if (obj == NULL) + return; + trn_cell_conflux_linked_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_conflux_linked_t)); + trunnel_free_(obj); +} + +uint8_t +trn_cell_conflux_linked_get_version(const trn_cell_conflux_linked_t *inp) +{ + return inp->version; +} +int +trn_cell_conflux_linked_set_version(trn_cell_conflux_linked_t *inp, uint8_t val) +{ + if (! ((val == 1))) { + TRUNNEL_SET_ERROR_CODE(inp); + return -1; + } + inp->version = val; + return 0; +} +size_t +trn_cell_conflux_linked_getlen_payload(const trn_cell_conflux_linked_t *inp) +{ + return TRUNNEL_DYNARRAY_LEN(&inp->payload); +} + +uint8_t +trn_cell_conflux_linked_get_payload(trn_cell_conflux_linked_t *inp, size_t idx) +{ + return TRUNNEL_DYNARRAY_GET(&inp->payload, idx); +} + +uint8_t +trn_cell_conflux_linked_getconst_payload(const trn_cell_conflux_linked_t *inp, size_t idx) +{ + return trn_cell_conflux_linked_get_payload((trn_cell_conflux_linked_t*)inp, idx); +} +int +trn_cell_conflux_linked_set_payload(trn_cell_conflux_linked_t *inp, size_t idx, uint8_t elt) +{ + TRUNNEL_DYNARRAY_SET(&inp->payload, idx, elt); + return 0; +} +int +trn_cell_conflux_linked_add_payload(trn_cell_conflux_linked_t *inp, uint8_t elt) +{ + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->payload, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +trn_cell_conflux_linked_getarray_payload(trn_cell_conflux_linked_t *inp) +{ + return inp->payload.elts_; +} +const uint8_t * +trn_cell_conflux_linked_getconstarray_payload(const trn_cell_conflux_linked_t *inp) +{ + return (const uint8_t *)trn_cell_conflux_linked_getarray_payload((trn_cell_conflux_linked_t*)inp); +} +int +trn_cell_conflux_linked_setlen_payload(trn_cell_conflux_linked_t *inp, size_t newlen) +{ + uint8_t *newptr; + newptr = trunnel_dynarray_setlen(&inp->payload.allocated_, + &inp->payload.n_, inp->payload.elts_, newlen, + sizeof(inp->payload.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->payload.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +trn_cell_conflux_linked_check(const trn_cell_conflux_linked_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + if (! (obj->version == 1)) + return "Integer out of bounds"; + return NULL; +} + +ssize_t +trn_cell_conflux_linked_encoded_len(const trn_cell_conflux_linked_t *obj) +{ + ssize_t result = 0; + + if (NULL != trn_cell_conflux_linked_check(obj)) + return -1; + + + /* Length of u8 version IN [1] */ + result += 1; + + /* Length of u8 payload[] */ + result += TRUNNEL_DYNARRAY_LEN(&obj->payload); + return result; +} +int +trn_cell_conflux_linked_clear_errors(trn_cell_conflux_linked_t *obj) +{ + int r = obj->trunnel_error_code_; + obj->trunnel_error_code_ = 0; + return r; +} +ssize_t +trn_cell_conflux_linked_encode(uint8_t *output, const size_t avail, const trn_cell_conflux_linked_t *obj) +{ + ssize_t result = 0; + size_t written = 0; + uint8_t *ptr = output; + const char *msg; +#ifdef TRUNNEL_CHECK_ENCODED_LEN + const ssize_t encoded_len = trn_cell_conflux_linked_encoded_len(obj); +#endif + + if (NULL != (msg = trn_cell_conflux_linked_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 version IN [1] */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->version)); + written += 1; ptr += 1; + + /* Encode u8 payload[] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->payload); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->payload.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As trn_cell_conflux_linked_parse(), but do not allocate the output + * object. + */ +static ssize_t +trn_cell_conflux_linked_parse_into(trn_cell_conflux_linked_t *obj, const uint8_t *input, const size_t len_in) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 version IN [1] */ + CHECK_REMAINING(1, truncated); + obj->version = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + if (! (obj->version == 1)) + goto fail; + + /* Parse u8 payload[] */ + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->payload, remaining, {}); + obj->payload.n_ = remaining; + if (remaining) + memcpy(obj->payload.elts_, ptr, remaining); + ptr += remaining; remaining -= remaining; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + trunnel_alloc_failed: + return -1; + fail: + result = -1; + return result; +} + +ssize_t +trn_cell_conflux_linked_parse(trn_cell_conflux_linked_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = trn_cell_conflux_linked_new(); + if (NULL == *output) + return -1; + result = trn_cell_conflux_linked_parse_into(*output, input, len_in); + if (result < 0) { + trn_cell_conflux_linked_free(*output); + *output = NULL; + } + return result; +} +trn_cell_conflux_linked_ack_t * +trn_cell_conflux_linked_ack_new(void) +{ + trn_cell_conflux_linked_ack_t *val = trunnel_calloc(1, sizeof(trn_cell_conflux_linked_ack_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +trn_cell_conflux_linked_ack_clear(trn_cell_conflux_linked_ack_t *obj) +{ + (void) obj; + TRUNNEL_DYNARRAY_WIPE(&obj->payload); + TRUNNEL_DYNARRAY_CLEAR(&obj->payload); +} + +void +trn_cell_conflux_linked_ack_free(trn_cell_conflux_linked_ack_t *obj) +{ + if (obj == NULL) + return; + trn_cell_conflux_linked_ack_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_conflux_linked_ack_t)); + trunnel_free_(obj); +} + +size_t +trn_cell_conflux_linked_ack_getlen_payload(const trn_cell_conflux_linked_ack_t *inp) +{ + return TRUNNEL_DYNARRAY_LEN(&inp->payload); +} + +uint8_t +trn_cell_conflux_linked_ack_get_payload(trn_cell_conflux_linked_ack_t *inp, size_t idx) +{ + return TRUNNEL_DYNARRAY_GET(&inp->payload, idx); +} + +uint8_t +trn_cell_conflux_linked_ack_getconst_payload(const trn_cell_conflux_linked_ack_t *inp, size_t idx) +{ + return trn_cell_conflux_linked_ack_get_payload((trn_cell_conflux_linked_ack_t*)inp, idx); +} +int +trn_cell_conflux_linked_ack_set_payload(trn_cell_conflux_linked_ack_t *inp, size_t idx, uint8_t elt) +{ + TRUNNEL_DYNARRAY_SET(&inp->payload, idx, elt); + return 0; +} +int +trn_cell_conflux_linked_ack_add_payload(trn_cell_conflux_linked_ack_t *inp, uint8_t elt) +{ + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->payload, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +trn_cell_conflux_linked_ack_getarray_payload(trn_cell_conflux_linked_ack_t *inp) +{ + return inp->payload.elts_; +} +const uint8_t * +trn_cell_conflux_linked_ack_getconstarray_payload(const trn_cell_conflux_linked_ack_t *inp) +{ + return (const uint8_t *)trn_cell_conflux_linked_ack_getarray_payload((trn_cell_conflux_linked_ack_t*)inp); +} +int +trn_cell_conflux_linked_ack_setlen_payload(trn_cell_conflux_linked_ack_t *inp, size_t newlen) +{ + uint8_t *newptr; + newptr = trunnel_dynarray_setlen(&inp->payload.allocated_, + &inp->payload.n_, inp->payload.elts_, newlen, + sizeof(inp->payload.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->payload.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +trn_cell_conflux_linked_ack_check(const trn_cell_conflux_linked_ack_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + return NULL; +} + +ssize_t +trn_cell_conflux_linked_ack_encoded_len(const trn_cell_conflux_linked_ack_t *obj) +{ + ssize_t result = 0; + + if (NULL != trn_cell_conflux_linked_ack_check(obj)) + return -1; + + + /* Length of u8 payload[] */ + result += TRUNNEL_DYNARRAY_LEN(&obj->payload); + return result; +} +int +trn_cell_conflux_linked_ack_clear_errors(trn_cell_conflux_linked_ack_t *obj) +{ + int r = obj->trunnel_error_code_; + obj->trunnel_error_code_ = 0; + return r; +} +ssize_t +trn_cell_conflux_linked_ack_encode(uint8_t *output, const size_t avail, const trn_cell_conflux_linked_ack_t *obj) +{ + ssize_t result = 0; + size_t written = 0; + uint8_t *ptr = output; + const char *msg; +#ifdef TRUNNEL_CHECK_ENCODED_LEN + const ssize_t encoded_len = trn_cell_conflux_linked_ack_encoded_len(obj); +#endif + + if (NULL != (msg = trn_cell_conflux_linked_ack_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 payload[] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->payload); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->payload.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As trn_cell_conflux_linked_ack_parse(), but do not allocate the + * output object. + */ +static ssize_t +trn_cell_conflux_linked_ack_parse_into(trn_cell_conflux_linked_ack_t *obj, const uint8_t *input, const size_t len_in) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 payload[] */ + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->payload, remaining, {}); + obj->payload.n_ = remaining; + if (remaining) + memcpy(obj->payload.elts_, ptr, remaining); + ptr += remaining; remaining -= remaining; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + trunnel_alloc_failed: + return -1; +} + +ssize_t +trn_cell_conflux_linked_ack_parse(trn_cell_conflux_linked_ack_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = trn_cell_conflux_linked_ack_new(); + if (NULL == *output) + return -1; + result = trn_cell_conflux_linked_ack_parse_into(*output, input, len_in); + if (result < 0) { + trn_cell_conflux_linked_ack_free(*output); + *output = NULL; + } + return result; +} +trn_cell_conflux_switch_t * +trn_cell_conflux_switch_new(void) +{ + trn_cell_conflux_switch_t *val = trunnel_calloc(1, sizeof(trn_cell_conflux_switch_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +trn_cell_conflux_switch_clear(trn_cell_conflux_switch_t *obj) +{ + (void) obj; +} + +void +trn_cell_conflux_switch_free(trn_cell_conflux_switch_t *obj) +{ + if (obj == NULL) + return; + trn_cell_conflux_switch_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_conflux_switch_t)); + trunnel_free_(obj); +} + +uint32_t +trn_cell_conflux_switch_get_seqnum(const trn_cell_conflux_switch_t *inp) +{ + return inp->seqnum; +} +int +trn_cell_conflux_switch_set_seqnum(trn_cell_conflux_switch_t *inp, uint32_t val) +{ + inp->seqnum = val; + return 0; +} +const char * +trn_cell_conflux_switch_check(const trn_cell_conflux_switch_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + return NULL; +} + +ssize_t +trn_cell_conflux_switch_encoded_len(const trn_cell_conflux_switch_t *obj) +{ + ssize_t result = 0; + + if (NULL != trn_cell_conflux_switch_check(obj)) + return -1; + + + /* Length of u32 seqnum */ + result += 4; + return result; +} +int +trn_cell_conflux_switch_clear_errors(trn_cell_conflux_switch_t *obj) +{ + int r = obj->trunnel_error_code_; + obj->trunnel_error_code_ = 0; + return r; +} +ssize_t +trn_cell_conflux_switch_encode(uint8_t *output, const size_t avail, const trn_cell_conflux_switch_t *obj) +{ + ssize_t result = 0; + size_t written = 0; + uint8_t *ptr = output; + const char *msg; +#ifdef TRUNNEL_CHECK_ENCODED_LEN + const ssize_t encoded_len = trn_cell_conflux_switch_encoded_len(obj); +#endif + + if (NULL != (msg = trn_cell_conflux_switch_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u32 seqnum */ + trunnel_assert(written <= avail); + if (avail - written < 4) + goto truncated; + trunnel_set_uint32(ptr, trunnel_htonl(obj->seqnum)); + written += 4; ptr += 4; + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As trn_cell_conflux_switch_parse(), but do not allocate the output + * object. + */ +static ssize_t +trn_cell_conflux_switch_parse_into(trn_cell_conflux_switch_t *obj, const uint8_t *input, const size_t len_in) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u32 seqnum */ + CHECK_REMAINING(4, truncated); + obj->seqnum = trunnel_ntohl(trunnel_get_uint32(ptr)); + remaining -= 4; ptr += 4; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; +} + +ssize_t +trn_cell_conflux_switch_parse(trn_cell_conflux_switch_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = trn_cell_conflux_switch_new(); + if (NULL == *output) + return -1; + result = trn_cell_conflux_switch_parse_into(*output, input, len_in); + if (result < 0) { + trn_cell_conflux_switch_free(*output); + *output = NULL; + } + return result; +} diff --git a/src/trunnel/conflux.h b/src/trunnel/conflux.h new file mode 100644 index 0000000000..fa6f093b4f --- /dev/null +++ b/src/trunnel/conflux.h @@ -0,0 +1,422 @@ +/* conflux.h -- generated by Trunnel v1.5.3. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#ifndef TRUNNEL_CONFLUX_H +#define TRUNNEL_CONFLUX_H + +#include <stdint.h> +#include "trunnel.h" + +#define CONFLUX_UX_NO_OPINION 0 +#define CONFLUX_UX_MIN_LATENCY 1 +#define CONFLUX_UX_LOW_MEM_LATENCY 2 +#define CONFLUX_UX_HIGH_THROUGHPUT 3 +#define CONFLUX_UX_LOW_MEM_THROUGHPUT 4 +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_CONFLUX_LINK) +struct trn_cell_conflux_link_st { + uint8_t version; + TRUNNEL_DYNARRAY_HEAD(, uint8_t) payload; + uint8_t trunnel_error_code_; +}; +#endif +typedef struct trn_cell_conflux_link_st trn_cell_conflux_link_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_CONFLUX_LINK_PAYLOAD_V1) +struct trn_cell_conflux_link_payload_v1_st { + uint8_t nonce[32]; + uint64_t last_seqno_sent; + uint64_t last_seqno_recv; + uint8_t desired_ux; + uint8_t trunnel_error_code_; +}; +#endif +typedef struct trn_cell_conflux_link_payload_v1_st trn_cell_conflux_link_payload_v1_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_CONFLUX_LINKED) +struct trn_cell_conflux_linked_st { + uint8_t version; + TRUNNEL_DYNARRAY_HEAD(, uint8_t) payload; + uint8_t trunnel_error_code_; +}; +#endif +typedef struct trn_cell_conflux_linked_st trn_cell_conflux_linked_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_CONFLUX_LINKED_ACK) +struct trn_cell_conflux_linked_ack_st { + TRUNNEL_DYNARRAY_HEAD(, uint8_t) payload; + uint8_t trunnel_error_code_; +}; +#endif +typedef struct trn_cell_conflux_linked_ack_st trn_cell_conflux_linked_ack_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_CONFLUX_SWITCH) +struct trn_cell_conflux_switch_st { + uint32_t seqnum; + uint8_t trunnel_error_code_; +}; +#endif +typedef struct trn_cell_conflux_switch_st trn_cell_conflux_switch_t; +/** Return a newly allocated trn_cell_conflux_link with all elements + * set to zero. + */ +trn_cell_conflux_link_t *trn_cell_conflux_link_new(void); +/** Release all storage held by the trn_cell_conflux_link in 'victim'. + * (Do nothing if 'victim' is NULL.) + */ +void trn_cell_conflux_link_free(trn_cell_conflux_link_t *victim); +/** Try to parse a trn_cell_conflux_link from the buffer in 'input', + * using up to 'len_in' bytes from the input buffer. On success, + * return the number of bytes consumed and set *output to the newly + * allocated trn_cell_conflux_link_t. On failure, return -2 if the + * input appears truncated, and -1 if the input is otherwise invalid. + */ +ssize_t trn_cell_conflux_link_parse(trn_cell_conflux_link_t **output, const uint8_t *input, const size_t len_in); +/** Return the number of bytes we expect to need to encode the + * trn_cell_conflux_link in 'obj'. On failure, return a negative + * value. Note that this value may be an overestimate, and can even be + * an underestimate for certain unencodeable objects. + */ +ssize_t trn_cell_conflux_link_encoded_len(const trn_cell_conflux_link_t *obj); +/** Try to encode the trn_cell_conflux_link from 'input' into the + * buffer at 'output', using up to 'avail' bytes of the output buffer. + * On success, return the number of bytes used. On failure, return -2 + * if the buffer was not long enough, and -1 if the input was invalid. + */ +ssize_t trn_cell_conflux_link_encode(uint8_t *output, size_t avail, const trn_cell_conflux_link_t *input); +/** Check whether the internal state of the trn_cell_conflux_link in + * 'obj' is consistent. Return NULL if it is, and a short message if + * it is not. + */ +const char *trn_cell_conflux_link_check(const trn_cell_conflux_link_t *obj); +/** Clear any errors that were set on the object 'obj' by its setter + * functions. Return true iff errors were cleared. + */ +int trn_cell_conflux_link_clear_errors(trn_cell_conflux_link_t *obj); +/** Return the value of the version field of the + * trn_cell_conflux_link_t in 'inp' + */ +uint8_t trn_cell_conflux_link_get_version(const trn_cell_conflux_link_t *inp); +/** Set the value of the version field of the trn_cell_conflux_link_t + * in 'inp' to 'val'. Return 0 on success; return -1 and set the error + * code on 'inp' on failure. + */ +int trn_cell_conflux_link_set_version(trn_cell_conflux_link_t *inp, uint8_t val); +/** Return the length of the dynamic array holding the payload field + * of the trn_cell_conflux_link_t in 'inp'. + */ +size_t trn_cell_conflux_link_getlen_payload(const trn_cell_conflux_link_t *inp); +/** Return the element at position 'idx' of the dynamic array field + * payload of the trn_cell_conflux_link_t in 'inp'. + */ +uint8_t trn_cell_conflux_link_get_payload(trn_cell_conflux_link_t *inp, size_t idx); +/** As trn_cell_conflux_link_get_payload, but take and return a const + * pointer + */ +uint8_t trn_cell_conflux_link_getconst_payload(const trn_cell_conflux_link_t *inp, size_t idx); +/** Change the element at position 'idx' of the dynamic array field + * payload of the trn_cell_conflux_link_t in 'inp', so that it will + * hold the value 'elt'. + */ +int trn_cell_conflux_link_set_payload(trn_cell_conflux_link_t *inp, size_t idx, uint8_t elt); +/** Append a new element 'elt' to the dynamic array field payload of + * the trn_cell_conflux_link_t in 'inp'. + */ +int trn_cell_conflux_link_add_payload(trn_cell_conflux_link_t *inp, uint8_t elt); +/** Return a pointer to the variable-length array field payload of + * 'inp'. + */ +uint8_t * trn_cell_conflux_link_getarray_payload(trn_cell_conflux_link_t *inp); +/** As trn_cell_conflux_link_get_payload, but take and return a const + * pointer + */ +const uint8_t * trn_cell_conflux_link_getconstarray_payload(const trn_cell_conflux_link_t *inp); +/** Change the length of the variable-length array field payload of + * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; + * return -1 and set the error code on 'inp' on failure. + */ +int trn_cell_conflux_link_setlen_payload(trn_cell_conflux_link_t *inp, size_t newlen); +/** Return a newly allocated trn_cell_conflux_link_payload_v1 with all + * elements set to zero. + */ +trn_cell_conflux_link_payload_v1_t *trn_cell_conflux_link_payload_v1_new(void); +/** Release all storage held by the trn_cell_conflux_link_payload_v1 + * in 'victim'. (Do nothing if 'victim' is NULL.) + */ +void trn_cell_conflux_link_payload_v1_free(trn_cell_conflux_link_payload_v1_t *victim); +/** Try to parse a trn_cell_conflux_link_payload_v1 from the buffer in + * 'input', using up to 'len_in' bytes from the input buffer. On + * success, return the number of bytes consumed and set *output to the + * newly allocated trn_cell_conflux_link_payload_v1_t. On failure, + * return -2 if the input appears truncated, and -1 if the input is + * otherwise invalid. + */ +ssize_t trn_cell_conflux_link_payload_v1_parse(trn_cell_conflux_link_payload_v1_t **output, const uint8_t *input, const size_t len_in); +/** Return the number of bytes we expect to need to encode the + * trn_cell_conflux_link_payload_v1 in 'obj'. On failure, return a + * negative value. Note that this value may be an overestimate, and + * can even be an underestimate for certain unencodeable objects. + */ +ssize_t trn_cell_conflux_link_payload_v1_encoded_len(const trn_cell_conflux_link_payload_v1_t *obj); +/** Try to encode the trn_cell_conflux_link_payload_v1 from 'input' + * into the buffer at 'output', using up to 'avail' bytes of the + * output buffer. On success, return the number of bytes used. On + * failure, return -2 if the buffer was not long enough, and -1 if the + * input was invalid. + */ +ssize_t trn_cell_conflux_link_payload_v1_encode(uint8_t *output, size_t avail, const trn_cell_conflux_link_payload_v1_t *input); +/** Check whether the internal state of the + * trn_cell_conflux_link_payload_v1 in 'obj' is consistent. Return + * NULL if it is, and a short message if it is not. + */ +const char *trn_cell_conflux_link_payload_v1_check(const trn_cell_conflux_link_payload_v1_t *obj); +/** Clear any errors that were set on the object 'obj' by its setter + * functions. Return true iff errors were cleared. + */ +int trn_cell_conflux_link_payload_v1_clear_errors(trn_cell_conflux_link_payload_v1_t *obj); +/** Return the (constant) length of the array holding the nonce field + * of the trn_cell_conflux_link_payload_v1_t in 'inp'. + */ +size_t trn_cell_conflux_link_payload_v1_getlen_nonce(const trn_cell_conflux_link_payload_v1_t *inp); +/** Return the element at position 'idx' of the fixed array field + * nonce of the trn_cell_conflux_link_payload_v1_t in 'inp'. + */ +uint8_t trn_cell_conflux_link_payload_v1_get_nonce(trn_cell_conflux_link_payload_v1_t *inp, size_t idx); +/** As trn_cell_conflux_link_payload_v1_get_nonce, but take and return + * a const pointer + */ +uint8_t trn_cell_conflux_link_payload_v1_getconst_nonce(const trn_cell_conflux_link_payload_v1_t *inp, size_t idx); +/** Change the element at position 'idx' of the fixed array field + * nonce of the trn_cell_conflux_link_payload_v1_t in 'inp', so that + * it will hold the value 'elt'. + */ +int trn_cell_conflux_link_payload_v1_set_nonce(trn_cell_conflux_link_payload_v1_t *inp, size_t idx, uint8_t elt); +/** Return a pointer to the 32-element array field nonce of 'inp'. + */ +uint8_t * trn_cell_conflux_link_payload_v1_getarray_nonce(trn_cell_conflux_link_payload_v1_t *inp); +/** As trn_cell_conflux_link_payload_v1_get_nonce, but take and return + * a const pointer + */ +const uint8_t * trn_cell_conflux_link_payload_v1_getconstarray_nonce(const trn_cell_conflux_link_payload_v1_t *inp); +/** Return the value of the last_seqno_sent field of the + * trn_cell_conflux_link_payload_v1_t in 'inp' + */ +uint64_t trn_cell_conflux_link_payload_v1_get_last_seqno_sent(const trn_cell_conflux_link_payload_v1_t *inp); +/** Set the value of the last_seqno_sent field of the + * trn_cell_conflux_link_payload_v1_t in 'inp' to 'val'. Return 0 on + * success; return -1 and set the error code on 'inp' on failure. + */ +int trn_cell_conflux_link_payload_v1_set_last_seqno_sent(trn_cell_conflux_link_payload_v1_t *inp, uint64_t val); +/** Return the value of the last_seqno_recv field of the + * trn_cell_conflux_link_payload_v1_t in 'inp' + */ +uint64_t trn_cell_conflux_link_payload_v1_get_last_seqno_recv(const trn_cell_conflux_link_payload_v1_t *inp); +/** Set the value of the last_seqno_recv field of the + * trn_cell_conflux_link_payload_v1_t in 'inp' to 'val'. Return 0 on + * success; return -1 and set the error code on 'inp' on failure. + */ +int trn_cell_conflux_link_payload_v1_set_last_seqno_recv(trn_cell_conflux_link_payload_v1_t *inp, uint64_t val); +/** Return the value of the desired_ux field of the + * trn_cell_conflux_link_payload_v1_t in 'inp' + */ +uint8_t trn_cell_conflux_link_payload_v1_get_desired_ux(const trn_cell_conflux_link_payload_v1_t *inp); +/** Set the value of the desired_ux field of the + * trn_cell_conflux_link_payload_v1_t in 'inp' to 'val'. Return 0 on + * success; return -1 and set the error code on 'inp' on failure. + */ +int trn_cell_conflux_link_payload_v1_set_desired_ux(trn_cell_conflux_link_payload_v1_t *inp, uint8_t val); +/** Return a newly allocated trn_cell_conflux_linked with all elements + * set to zero. + */ +trn_cell_conflux_linked_t *trn_cell_conflux_linked_new(void); +/** Release all storage held by the trn_cell_conflux_linked in + * 'victim'. (Do nothing if 'victim' is NULL.) + */ +void trn_cell_conflux_linked_free(trn_cell_conflux_linked_t *victim); +/** Try to parse a trn_cell_conflux_linked from the buffer in 'input', + * using up to 'len_in' bytes from the input buffer. On success, + * return the number of bytes consumed and set *output to the newly + * allocated trn_cell_conflux_linked_t. On failure, return -2 if the + * input appears truncated, and -1 if the input is otherwise invalid. + */ +ssize_t trn_cell_conflux_linked_parse(trn_cell_conflux_linked_t **output, const uint8_t *input, const size_t len_in); +/** Return the number of bytes we expect to need to encode the + * trn_cell_conflux_linked in 'obj'. On failure, return a negative + * value. Note that this value may be an overestimate, and can even be + * an underestimate for certain unencodeable objects. + */ +ssize_t trn_cell_conflux_linked_encoded_len(const trn_cell_conflux_linked_t *obj); +/** Try to encode the trn_cell_conflux_linked from 'input' into the + * buffer at 'output', using up to 'avail' bytes of the output buffer. + * On success, return the number of bytes used. On failure, return -2 + * if the buffer was not long enough, and -1 if the input was invalid. + */ +ssize_t trn_cell_conflux_linked_encode(uint8_t *output, size_t avail, const trn_cell_conflux_linked_t *input); +/** Check whether the internal state of the trn_cell_conflux_linked in + * 'obj' is consistent. Return NULL if it is, and a short message if + * it is not. + */ +const char *trn_cell_conflux_linked_check(const trn_cell_conflux_linked_t *obj); +/** Clear any errors that were set on the object 'obj' by its setter + * functions. Return true iff errors were cleared. + */ +int trn_cell_conflux_linked_clear_errors(trn_cell_conflux_linked_t *obj); +/** Return the value of the version field of the + * trn_cell_conflux_linked_t in 'inp' + */ +uint8_t trn_cell_conflux_linked_get_version(const trn_cell_conflux_linked_t *inp); +/** Set the value of the version field of the + * trn_cell_conflux_linked_t in 'inp' to 'val'. Return 0 on success; + * return -1 and set the error code on 'inp' on failure. + */ +int trn_cell_conflux_linked_set_version(trn_cell_conflux_linked_t *inp, uint8_t val); +/** Return the length of the dynamic array holding the payload field + * of the trn_cell_conflux_linked_t in 'inp'. + */ +size_t trn_cell_conflux_linked_getlen_payload(const trn_cell_conflux_linked_t *inp); +/** Return the element at position 'idx' of the dynamic array field + * payload of the trn_cell_conflux_linked_t in 'inp'. + */ +uint8_t trn_cell_conflux_linked_get_payload(trn_cell_conflux_linked_t *inp, size_t idx); +/** As trn_cell_conflux_linked_get_payload, but take and return a + * const pointer + */ +uint8_t trn_cell_conflux_linked_getconst_payload(const trn_cell_conflux_linked_t *inp, size_t idx); +/** Change the element at position 'idx' of the dynamic array field + * payload of the trn_cell_conflux_linked_t in 'inp', so that it will + * hold the value 'elt'. + */ +int trn_cell_conflux_linked_set_payload(trn_cell_conflux_linked_t *inp, size_t idx, uint8_t elt); +/** Append a new element 'elt' to the dynamic array field payload of + * the trn_cell_conflux_linked_t in 'inp'. + */ +int trn_cell_conflux_linked_add_payload(trn_cell_conflux_linked_t *inp, uint8_t elt); +/** Return a pointer to the variable-length array field payload of + * 'inp'. + */ +uint8_t * trn_cell_conflux_linked_getarray_payload(trn_cell_conflux_linked_t *inp); +/** As trn_cell_conflux_linked_get_payload, but take and return a + * const pointer + */ +const uint8_t * trn_cell_conflux_linked_getconstarray_payload(const trn_cell_conflux_linked_t *inp); +/** Change the length of the variable-length array field payload of + * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; + * return -1 and set the error code on 'inp' on failure. + */ +int trn_cell_conflux_linked_setlen_payload(trn_cell_conflux_linked_t *inp, size_t newlen); +/** Return a newly allocated trn_cell_conflux_linked_ack with all + * elements set to zero. + */ +trn_cell_conflux_linked_ack_t *trn_cell_conflux_linked_ack_new(void); +/** Release all storage held by the trn_cell_conflux_linked_ack in + * 'victim'. (Do nothing if 'victim' is NULL.) + */ +void trn_cell_conflux_linked_ack_free(trn_cell_conflux_linked_ack_t *victim); +/** Try to parse a trn_cell_conflux_linked_ack from the buffer in + * 'input', using up to 'len_in' bytes from the input buffer. On + * success, return the number of bytes consumed and set *output to the + * newly allocated trn_cell_conflux_linked_ack_t. On failure, return + * -2 if the input appears truncated, and -1 if the input is otherwise + * invalid. + */ +ssize_t trn_cell_conflux_linked_ack_parse(trn_cell_conflux_linked_ack_t **output, const uint8_t *input, const size_t len_in); +/** Return the number of bytes we expect to need to encode the + * trn_cell_conflux_linked_ack in 'obj'. On failure, return a negative + * value. Note that this value may be an overestimate, and can even be + * an underestimate for certain unencodeable objects. + */ +ssize_t trn_cell_conflux_linked_ack_encoded_len(const trn_cell_conflux_linked_ack_t *obj); +/** Try to encode the trn_cell_conflux_linked_ack from 'input' into + * the buffer at 'output', using up to 'avail' bytes of the output + * buffer. On success, return the number of bytes used. On failure, + * return -2 if the buffer was not long enough, and -1 if the input + * was invalid. + */ +ssize_t trn_cell_conflux_linked_ack_encode(uint8_t *output, size_t avail, const trn_cell_conflux_linked_ack_t *input); +/** Check whether the internal state of the + * trn_cell_conflux_linked_ack in 'obj' is consistent. Return NULL if + * it is, and a short message if it is not. + */ +const char *trn_cell_conflux_linked_ack_check(const trn_cell_conflux_linked_ack_t *obj); +/** Clear any errors that were set on the object 'obj' by its setter + * functions. Return true iff errors were cleared. + */ +int trn_cell_conflux_linked_ack_clear_errors(trn_cell_conflux_linked_ack_t *obj); +/** Return the length of the dynamic array holding the payload field + * of the trn_cell_conflux_linked_ack_t in 'inp'. + */ +size_t trn_cell_conflux_linked_ack_getlen_payload(const trn_cell_conflux_linked_ack_t *inp); +/** Return the element at position 'idx' of the dynamic array field + * payload of the trn_cell_conflux_linked_ack_t in 'inp'. + */ +uint8_t trn_cell_conflux_linked_ack_get_payload(trn_cell_conflux_linked_ack_t *inp, size_t idx); +/** As trn_cell_conflux_linked_ack_get_payload, but take and return a + * const pointer + */ +uint8_t trn_cell_conflux_linked_ack_getconst_payload(const trn_cell_conflux_linked_ack_t *inp, size_t idx); +/** Change the element at position 'idx' of the dynamic array field + * payload of the trn_cell_conflux_linked_ack_t in 'inp', so that it + * will hold the value 'elt'. + */ +int trn_cell_conflux_linked_ack_set_payload(trn_cell_conflux_linked_ack_t *inp, size_t idx, uint8_t elt); +/** Append a new element 'elt' to the dynamic array field payload of + * the trn_cell_conflux_linked_ack_t in 'inp'. + */ +int trn_cell_conflux_linked_ack_add_payload(trn_cell_conflux_linked_ack_t *inp, uint8_t elt); +/** Return a pointer to the variable-length array field payload of + * 'inp'. + */ +uint8_t * trn_cell_conflux_linked_ack_getarray_payload(trn_cell_conflux_linked_ack_t *inp); +/** As trn_cell_conflux_linked_ack_get_payload, but take and return a + * const pointer + */ +const uint8_t * trn_cell_conflux_linked_ack_getconstarray_payload(const trn_cell_conflux_linked_ack_t *inp); +/** Change the length of the variable-length array field payload of + * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; + * return -1 and set the error code on 'inp' on failure. + */ +int trn_cell_conflux_linked_ack_setlen_payload(trn_cell_conflux_linked_ack_t *inp, size_t newlen); +/** Return a newly allocated trn_cell_conflux_switch with all elements + * set to zero. + */ +trn_cell_conflux_switch_t *trn_cell_conflux_switch_new(void); +/** Release all storage held by the trn_cell_conflux_switch in + * 'victim'. (Do nothing if 'victim' is NULL.) + */ +void trn_cell_conflux_switch_free(trn_cell_conflux_switch_t *victim); +/** Try to parse a trn_cell_conflux_switch from the buffer in 'input', + * using up to 'len_in' bytes from the input buffer. On success, + * return the number of bytes consumed and set *output to the newly + * allocated trn_cell_conflux_switch_t. On failure, return -2 if the + * input appears truncated, and -1 if the input is otherwise invalid. + */ +ssize_t trn_cell_conflux_switch_parse(trn_cell_conflux_switch_t **output, const uint8_t *input, const size_t len_in); +/** Return the number of bytes we expect to need to encode the + * trn_cell_conflux_switch in 'obj'. On failure, return a negative + * value. Note that this value may be an overestimate, and can even be + * an underestimate for certain unencodeable objects. + */ +ssize_t trn_cell_conflux_switch_encoded_len(const trn_cell_conflux_switch_t *obj); +/** Try to encode the trn_cell_conflux_switch from 'input' into the + * buffer at 'output', using up to 'avail' bytes of the output buffer. + * On success, return the number of bytes used. On failure, return -2 + * if the buffer was not long enough, and -1 if the input was invalid. + */ +ssize_t trn_cell_conflux_switch_encode(uint8_t *output, size_t avail, const trn_cell_conflux_switch_t *input); +/** Check whether the internal state of the trn_cell_conflux_switch in + * 'obj' is consistent. Return NULL if it is, and a short message if + * it is not. + */ +const char *trn_cell_conflux_switch_check(const trn_cell_conflux_switch_t *obj); +/** Clear any errors that were set on the object 'obj' by its setter + * functions. Return true iff errors were cleared. + */ +int trn_cell_conflux_switch_clear_errors(trn_cell_conflux_switch_t *obj); +/** Return the value of the seqnum field of the + * trn_cell_conflux_switch_t in 'inp' + */ +uint32_t trn_cell_conflux_switch_get_seqnum(const trn_cell_conflux_switch_t *inp); +/** Set the value of the seqnum field of the trn_cell_conflux_switch_t + * in 'inp' to 'val'. Return 0 on success; return -1 and set the error + * code on 'inp' on failure. + */ +int trn_cell_conflux_switch_set_seqnum(trn_cell_conflux_switch_t *inp, uint32_t val); + + +#endif diff --git a/src/trunnel/conflux.trunnel b/src/trunnel/conflux.trunnel new file mode 100644 index 0000000000..4f1855faf3 --- /dev/null +++ b/src/trunnel/conflux.trunnel @@ -0,0 +1,66 @@ +/* + * This file contains the definition for the Conflux related cells. See + * proposal 329. + */ + +/* No Opinion means the endpoint can choose whatever it thinks is best. */ +const CONFLUX_UX_NO_OPINION = 0x00; +/* Min latency always only uses the lowest RTT */ +const CONFLUX_UX_MIN_LATENCY = 0x01; +/* Min latency always only uses the lowest RTT */ +const CONFLUX_UX_LOW_MEM_LATENCY = 0x02; +/* Use a high-throughput algorithm that maximizes throughput + * by using the full congestion window of all circuits, at the expense + * of more reordering queue at the receiver */ +const CONFLUX_UX_HIGH_THROUGHPUT = 0x03; +/* THRPT_LO uses a high-throughput algorithm that tries to minimize + * out-of-order queues at the receiver */ +const CONFLUX_UX_LOW_MEM_THROUGHPUT = 0x04; + +/* The RELAY_CONFLUX_LINK definition. */ +struct trn_cell_conflux_link { + /* Version field. */ + u8 version IN [0x01]; + + /* Payload */ + u8 payload[]; +}; + +/* The RELAY_CIRCUIT_LINKED definition. */ +struct trn_cell_conflux_linked { + /* Version field. */ + u8 version IN [0x01]; + + /* Payload of the cell. */ + u8 payload[]; +}; + +/* The RELAY_CONFLUX_LINKED_ACK definition. */ +struct trn_cell_conflux_linked_ack { + /* Payload. At the moment, empty. */ + u8 payload[]; +}; + +/* The RELAY_CONFLUX_SWITCH definition. */ +struct trn_cell_conflux_switch { + /* Relative sequence number. */ + u32 seqnum; +}; + +/* The payload version 1 of RELAY_CONFLUX_LINK and RELAY_CIRCUIT_LINKED cells. + * */ +struct trn_cell_conflux_link_payload_v1 { + /* Used to identify the other conflux to link with. */ + u8 nonce[32]; + + /* Last sequence number sent and received. */ + u64 last_seqno_sent; + u64 last_seqno_recv; + + /* Desired user experience behavior */ + u8 desired_ux IN [CONFLUX_UX_NO_OPINION, + CONFLUX_UX_MIN_LATENCY, + CONFLUX_UX_LOW_MEM_LATENCY, + CONFLUX_UX_LOW_MEM_THROUGHPUT, + CONFLUX_UX_HIGH_THROUGHPUT]; +}; diff --git a/src/trunnel/include.am b/src/trunnel/include.am index b2aee81da9..8154a5e932 100644 --- a/src/trunnel/include.am +++ b/src/trunnel/include.am @@ -16,7 +16,8 @@ TRUNNELINPUTS = \ src/trunnel/flow_control_cells.trunnel \ src/trunnel/congestion_control.trunnel \ src/trunnel/socks5.trunnel \ - src/trunnel/circpad_negotiation.trunnel + src/trunnel/circpad_negotiation.trunnel \ + src/trunnel/conflux.trunnel
TRUNNELSOURCES = \ src/ext/trunnel/trunnel.c \ @@ -33,7 +34,8 @@ TRUNNELSOURCES = \ src/trunnel/congestion_control.c \ src/trunnel/socks5.c \ src/trunnel/netinfo.c \ - src/trunnel/circpad_negotiation.c + src/trunnel/circpad_negotiation.c \ + src/trunnel/conflux.c
TRUNNELHEADERS = \ src/ext/trunnel/trunnel.h \ @@ -52,7 +54,8 @@ TRUNNELHEADERS = \ src/trunnel/congestion_control.h \ src/trunnel/socks5.h \ src/trunnel/netinfo.h \ - src/trunnel/circpad_negotiation.h + src/trunnel/circpad_negotiation.h \ + src/trunnel/conflux.h
src_trunnel_libor_trunnel_a_SOURCES = $(TRUNNELSOURCES) src_trunnel_libor_trunnel_a_CPPFLAGS = \