aboutsummaryrefslogtreecommitdiff
path: root/src/trunnel
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2021-12-14 11:38:22 -0500
committerMike Perry <mikeperry-git@torproject.org>2022-02-22 19:28:34 +0000
commitbbf160d31199ffe75fac5b8921da904dbd45e2fb (patch)
tree13af67cbcdff1fc3eb95d08fe403456d2cf03551 /src/trunnel
parentb5439d6bd0eb72501abce6e5f897f473d9b27fc1 (diff)
downloadtor-bbf160d31199ffe75fac5b8921da904dbd45e2fb.tar.gz
tor-bbf160d31199ffe75fac5b8921da904dbd45e2fb.zip
cc: Use trunnel extension for ntorv3 circ parameters
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/trunnel')
-rw-r--r--src/trunnel/circ_params.c452
-rw-r--r--src/trunnel/circ_params.h147
-rw-r--r--src/trunnel/circ_params.trunnel25
-rw-r--r--src/trunnel/congestion_control.c183
-rw-r--r--src/trunnel/congestion_control.h67
-rw-r--r--src/trunnel/congestion_control.trunnel22
-rw-r--r--src/trunnel/include.am6
7 files changed, 275 insertions, 627 deletions
diff --git a/src/trunnel/circ_params.c b/src/trunnel/circ_params.c
deleted file mode 100644
index 650b533a0c..0000000000
--- a/src/trunnel/circ_params.c
+++ /dev/null
@@ -1,452 +0,0 @@
-/* circ_params.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 "circ_params.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 circparams_deadcode_dummy__ = 0;
-#define OR_DEADCODE_DUMMY || circparams_deadcode_dummy__
-#else
-#define OR_DEADCODE_DUMMY
-#endif
-
-#define CHECK_REMAINING(nbytes, label) \
- do { \
- if (remaining < (nbytes) OR_DEADCODE_DUMMY) { \
- goto label; \
- } \
- } while (0)
-
-circ_params_request_t *
-circ_params_request_new(void)
-{
- circ_params_request_t *val = trunnel_calloc(1, sizeof(circ_params_request_t));
- if (NULL == val)
- return NULL;
- return val;
-}
-
-/** Release all storage held inside 'obj', but do not free 'obj'.
- */
-static void
-circ_params_request_clear(circ_params_request_t *obj)
-{
- (void) obj;
-}
-
-void
-circ_params_request_free(circ_params_request_t *obj)
-{
- if (obj == NULL)
- return;
- circ_params_request_clear(obj);
- trunnel_memwipe(obj, sizeof(circ_params_request_t));
- trunnel_free_(obj);
-}
-
-uint8_t
-circ_params_request_get_version(const circ_params_request_t *inp)
-{
- return inp->version;
-}
-int
-circ_params_request_set_version(circ_params_request_t *inp, uint8_t val)
-{
- if (! ((val == 0))) {
- TRUNNEL_SET_ERROR_CODE(inp);
- return -1;
- }
- inp->version = val;
- return 0;
-}
-uint8_t
-circ_params_request_get_cc_supported(const circ_params_request_t *inp)
-{
- return inp->cc_supported;
-}
-int
-circ_params_request_set_cc_supported(circ_params_request_t *inp, uint8_t val)
-{
- if (! ((val == 0 || val == 1))) {
- TRUNNEL_SET_ERROR_CODE(inp);
- return -1;
- }
- inp->cc_supported = val;
- return 0;
-}
-const char *
-circ_params_request_check(const circ_params_request_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 == 0))
- return "Integer out of bounds";
- if (! (obj->cc_supported == 0 || obj->cc_supported == 1))
- return "Integer out of bounds";
- return NULL;
-}
-
-ssize_t
-circ_params_request_encoded_len(const circ_params_request_t *obj)
-{
- ssize_t result = 0;
-
- if (NULL != circ_params_request_check(obj))
- return -1;
-
-
- /* Length of u8 version IN [0] */
- result += 1;
-
- /* Length of u8 cc_supported IN [0, 1] */
- result += 1;
- return result;
-}
-int
-circ_params_request_clear_errors(circ_params_request_t *obj)
-{
- int r = obj->trunnel_error_code_;
- obj->trunnel_error_code_ = 0;
- return r;
-}
-ssize_t
-circ_params_request_encode(uint8_t *output, const size_t avail, const circ_params_request_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 = circ_params_request_encoded_len(obj);
-#endif
-
- if (NULL != (msg = circ_params_request_check(obj)))
- goto check_failed;
-
-#ifdef TRUNNEL_CHECK_ENCODED_LEN
- trunnel_assert(encoded_len >= 0);
-#endif
-
- /* Encode u8 version IN [0] */
- trunnel_assert(written <= avail);
- if (avail - written < 1)
- goto truncated;
- trunnel_set_uint8(ptr, (obj->version));
- written += 1; ptr += 1;
-
- /* Encode u8 cc_supported IN [0, 1] */
- trunnel_assert(written <= avail);
- if (avail - written < 1)
- goto truncated;
- trunnel_set_uint8(ptr, (obj->cc_supported));
- 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 circ_params_request_parse(), but do not allocate the output
- * object.
- */
-static ssize_t
-circ_params_request_parse_into(circ_params_request_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 [0] */
- CHECK_REMAINING(1, truncated);
- obj->version = (trunnel_get_uint8(ptr));
- remaining -= 1; ptr += 1;
- if (! (obj->version == 0))
- goto fail;
-
- /* Parse u8 cc_supported IN [0, 1] */
- CHECK_REMAINING(1, truncated);
- obj->cc_supported = (trunnel_get_uint8(ptr));
- remaining -= 1; ptr += 1;
- if (! (obj->cc_supported == 0 || obj->cc_supported == 1))
- goto fail;
- trunnel_assert(ptr + remaining == input + len_in);
- return len_in - remaining;
-
- truncated:
- return -2;
- fail:
- result = -1;
- return result;
-}
-
-ssize_t
-circ_params_request_parse(circ_params_request_t **output, const uint8_t *input, const size_t len_in)
-{
- ssize_t result;
- *output = circ_params_request_new();
- if (NULL == *output)
- return -1;
- result = circ_params_request_parse_into(*output, input, len_in);
- if (result < 0) {
- circ_params_request_free(*output);
- *output = NULL;
- }
- return result;
-}
-circ_params_response_t *
-circ_params_response_new(void)
-{
- circ_params_response_t *val = trunnel_calloc(1, sizeof(circ_params_response_t));
- if (NULL == val)
- return NULL;
- return val;
-}
-
-/** Release all storage held inside 'obj', but do not free 'obj'.
- */
-static void
-circ_params_response_clear(circ_params_response_t *obj)
-{
- (void) obj;
-}
-
-void
-circ_params_response_free(circ_params_response_t *obj)
-{
- if (obj == NULL)
- return;
- circ_params_response_clear(obj);
- trunnel_memwipe(obj, sizeof(circ_params_response_t));
- trunnel_free_(obj);
-}
-
-uint8_t
-circ_params_response_get_version(const circ_params_response_t *inp)
-{
- return inp->version;
-}
-int
-circ_params_response_set_version(circ_params_response_t *inp, uint8_t val)
-{
- if (! ((val == 0))) {
- TRUNNEL_SET_ERROR_CODE(inp);
- return -1;
- }
- inp->version = val;
- return 0;
-}
-uint8_t
-circ_params_response_get_cc_enabled(const circ_params_response_t *inp)
-{
- return inp->cc_enabled;
-}
-int
-circ_params_response_set_cc_enabled(circ_params_response_t *inp, uint8_t val)
-{
- if (! ((val == 0 || val == 1))) {
- TRUNNEL_SET_ERROR_CODE(inp);
- return -1;
- }
- inp->cc_enabled = val;
- return 0;
-}
-uint8_t
-circ_params_response_get_sendme_inc_cells(const circ_params_response_t *inp)
-{
- return inp->sendme_inc_cells;
-}
-int
-circ_params_response_set_sendme_inc_cells(circ_params_response_t *inp, uint8_t val)
-{
- inp->sendme_inc_cells = val;
- return 0;
-}
-const char *
-circ_params_response_check(const circ_params_response_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 == 0))
- return "Integer out of bounds";
- if (! (obj->cc_enabled == 0 || obj->cc_enabled == 1))
- return "Integer out of bounds";
- return NULL;
-}
-
-ssize_t
-circ_params_response_encoded_len(const circ_params_response_t *obj)
-{
- ssize_t result = 0;
-
- if (NULL != circ_params_response_check(obj))
- return -1;
-
-
- /* Length of u8 version IN [0] */
- result += 1;
-
- /* Length of u8 cc_enabled IN [0, 1] */
- result += 1;
-
- /* Length of u8 sendme_inc_cells */
- result += 1;
- return result;
-}
-int
-circ_params_response_clear_errors(circ_params_response_t *obj)
-{
- int r = obj->trunnel_error_code_;
- obj->trunnel_error_code_ = 0;
- return r;
-}
-ssize_t
-circ_params_response_encode(uint8_t *output, const size_t avail, const circ_params_response_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 = circ_params_response_encoded_len(obj);
-#endif
-
- if (NULL != (msg = circ_params_response_check(obj)))
- goto check_failed;
-
-#ifdef TRUNNEL_CHECK_ENCODED_LEN
- trunnel_assert(encoded_len >= 0);
-#endif
-
- /* Encode u8 version IN [0] */
- trunnel_assert(written <= avail);
- if (avail - written < 1)
- goto truncated;
- trunnel_set_uint8(ptr, (obj->version));
- written += 1; ptr += 1;
-
- /* Encode u8 cc_enabled IN [0, 1] */
- trunnel_assert(written <= avail);
- if (avail - written < 1)
- goto truncated;
- trunnel_set_uint8(ptr, (obj->cc_enabled));
- written += 1; ptr += 1;
-
- /* Encode u8 sendme_inc_cells */
- trunnel_assert(written <= avail);
- if (avail - written < 1)
- goto truncated;
- trunnel_set_uint8(ptr, (obj->sendme_inc_cells));
- 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 circ_params_response_parse(), but do not allocate the output
- * object.
- */
-static ssize_t
-circ_params_response_parse_into(circ_params_response_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 [0] */
- CHECK_REMAINING(1, truncated);
- obj->version = (trunnel_get_uint8(ptr));
- remaining -= 1; ptr += 1;
- if (! (obj->version == 0))
- goto fail;
-
- /* Parse u8 cc_enabled IN [0, 1] */
- CHECK_REMAINING(1, truncated);
- obj->cc_enabled = (trunnel_get_uint8(ptr));
- remaining -= 1; ptr += 1;
- if (! (obj->cc_enabled == 0 || obj->cc_enabled == 1))
- goto fail;
-
- /* Parse u8 sendme_inc_cells */
- CHECK_REMAINING(1, truncated);
- obj->sendme_inc_cells = (trunnel_get_uint8(ptr));
- remaining -= 1; ptr += 1;
- trunnel_assert(ptr + remaining == input + len_in);
- return len_in - remaining;
-
- truncated:
- return -2;
- fail:
- result = -1;
- return result;
-}
-
-ssize_t
-circ_params_response_parse(circ_params_response_t **output, const uint8_t *input, const size_t len_in)
-{
- ssize_t result;
- *output = circ_params_response_new();
- if (NULL == *output)
- return -1;
- result = circ_params_response_parse_into(*output, input, len_in);
- if (result < 0) {
- circ_params_response_free(*output);
- *output = NULL;
- }
- return result;
-}
diff --git a/src/trunnel/circ_params.h b/src/trunnel/circ_params.h
deleted file mode 100644
index f69b0073dc..0000000000
--- a/src/trunnel/circ_params.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/* circ_params.h -- generated by Trunnel v1.5.3.
- * https://gitweb.torproject.org/trunnel.git
- * You probably shouldn't edit this file.
- */
-#ifndef TRUNNEL_CIRC_PARAMS_H
-#define TRUNNEL_CIRC_PARAMS_H
-
-#include <stdint.h>
-#include "trunnel.h"
-
-#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CIRC_PARAMS_REQUEST)
-struct circ_params_request_st {
- uint8_t version;
- uint8_t cc_supported;
- uint8_t trunnel_error_code_;
-};
-#endif
-typedef struct circ_params_request_st circ_params_request_t;
-#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CIRC_PARAMS_RESPONSE)
-struct circ_params_response_st {
- uint8_t version;
- uint8_t cc_enabled;
- uint8_t sendme_inc_cells;
- uint8_t trunnel_error_code_;
-};
-#endif
-typedef struct circ_params_response_st circ_params_response_t;
-/** Return a newly allocated circ_params_request with all elements set
- * to zero.
- */
-circ_params_request_t *circ_params_request_new(void);
-/** Release all storage held by the circ_params_request in 'victim'.
- * (Do nothing if 'victim' is NULL.)
- */
-void circ_params_request_free(circ_params_request_t *victim);
-/** Try to parse a circ_params_request 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 circ_params_request_t. On failure, return -2 if the input
- * appears truncated, and -1 if the input is otherwise invalid.
- */
-ssize_t circ_params_request_parse(circ_params_request_t **output, const uint8_t *input, const size_t len_in);
-/** Return the number of bytes we expect to need to encode the
- * circ_params_request 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 circ_params_request_encoded_len(const circ_params_request_t *obj);
-/** Try to encode the circ_params_request 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 circ_params_request_encode(uint8_t *output, size_t avail, const circ_params_request_t *input);
-/** Check whether the internal state of the circ_params_request in
- * 'obj' is consistent. Return NULL if it is, and a short message if
- * it is not.
- */
-const char *circ_params_request_check(const circ_params_request_t *obj);
-/** Clear any errors that were set on the object 'obj' by its setter
- * functions. Return true iff errors were cleared.
- */
-int circ_params_request_clear_errors(circ_params_request_t *obj);
-/** Return the value of the version field of the circ_params_request_t
- * in 'inp'
- */
-uint8_t circ_params_request_get_version(const circ_params_request_t *inp);
-/** Set the value of the version field of the circ_params_request_t in
- * 'inp' to 'val'. Return 0 on success; return -1 and set the error
- * code on 'inp' on failure.
- */
-int circ_params_request_set_version(circ_params_request_t *inp, uint8_t val);
-/** Return the value of the cc_supported field of the
- * circ_params_request_t in 'inp'
- */
-uint8_t circ_params_request_get_cc_supported(const circ_params_request_t *inp);
-/** Set the value of the cc_supported field of the
- * circ_params_request_t in 'inp' to 'val'. Return 0 on success;
- * return -1 and set the error code on 'inp' on failure.
- */
-int circ_params_request_set_cc_supported(circ_params_request_t *inp, uint8_t val);
-/** Return a newly allocated circ_params_response with all elements
- * set to zero.
- */
-circ_params_response_t *circ_params_response_new(void);
-/** Release all storage held by the circ_params_response in 'victim'.
- * (Do nothing if 'victim' is NULL.)
- */
-void circ_params_response_free(circ_params_response_t *victim);
-/** Try to parse a circ_params_response 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 circ_params_response_t. On failure, return -2 if the
- * input appears truncated, and -1 if the input is otherwise invalid.
- */
-ssize_t circ_params_response_parse(circ_params_response_t **output, const uint8_t *input, const size_t len_in);
-/** Return the number of bytes we expect to need to encode the
- * circ_params_response 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 circ_params_response_encoded_len(const circ_params_response_t *obj);
-/** Try to encode the circ_params_response 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 circ_params_response_encode(uint8_t *output, size_t avail, const circ_params_response_t *input);
-/** Check whether the internal state of the circ_params_response in
- * 'obj' is consistent. Return NULL if it is, and a short message if
- * it is not.
- */
-const char *circ_params_response_check(const circ_params_response_t *obj);
-/** Clear any errors that were set on the object 'obj' by its setter
- * functions. Return true iff errors were cleared.
- */
-int circ_params_response_clear_errors(circ_params_response_t *obj);
-/** Return the value of the version field of the
- * circ_params_response_t in 'inp'
- */
-uint8_t circ_params_response_get_version(const circ_params_response_t *inp);
-/** Set the value of the version field of the circ_params_response_t
- * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
- * code on 'inp' on failure.
- */
-int circ_params_response_set_version(circ_params_response_t *inp, uint8_t val);
-/** Return the value of the cc_enabled field of the
- * circ_params_response_t in 'inp'
- */
-uint8_t circ_params_response_get_cc_enabled(const circ_params_response_t *inp);
-/** Set the value of the cc_enabled field of the
- * circ_params_response_t in 'inp' to 'val'. Return 0 on success;
- * return -1 and set the error code on 'inp' on failure.
- */
-int circ_params_response_set_cc_enabled(circ_params_response_t *inp, uint8_t val);
-/** Return the value of the sendme_inc_cells field of the
- * circ_params_response_t in 'inp'
- */
-uint8_t circ_params_response_get_sendme_inc_cells(const circ_params_response_t *inp);
-/** Set the value of the sendme_inc_cells field of the
- * circ_params_response_t in 'inp' to 'val'. Return 0 on success;
- * return -1 and set the error code on 'inp' on failure.
- */
-int circ_params_response_set_sendme_inc_cells(circ_params_response_t *inp, uint8_t val);
-
-
-#endif
diff --git a/src/trunnel/circ_params.trunnel b/src/trunnel/circ_params.trunnel
deleted file mode 100644
index 74f84b05ff..0000000000
--- a/src/trunnel/circ_params.trunnel
+++ /dev/null
@@ -1,25 +0,0 @@
-/* This file contains the definition for the encrypted payload of
- * a circuit parameter negotiation request/response portion of the
- * ntorv3 onionskin handshake. Currently only supports congestion
- * control params. */
-
-/* Param definitions */
-struct circ_params_request {
- /* Version */
- u8 version IN [0];
-
- /* Is cc supported or not? */
- u8 cc_supported IN [0, 1];
-}
-
-/* Param definitions */
-struct circ_params_response {
- /* Version */
- u8 version IN [0];
-
- /* Is cc supported or not? */
- u8 cc_enabled IN [0, 1];
-
- /* How many cells does a SENDME ack? */
- u8 sendme_inc_cells;
-}
diff --git a/src/trunnel/congestion_control.c b/src/trunnel/congestion_control.c
new file mode 100644
index 0000000000..371612bfe0
--- /dev/null
+++ b/src/trunnel/congestion_control.c
@@ -0,0 +1,183 @@
+/* congestion_control.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 "congestion_control.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 congestioncontrol_deadcode_dummy__ = 0;
+#define OR_DEADCODE_DUMMY || congestioncontrol_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_extension_field_cc_t *
+trn_extension_field_cc_new(void)
+{
+ trn_extension_field_cc_t *val = trunnel_calloc(1, sizeof(trn_extension_field_cc_t));
+ if (NULL == val)
+ return NULL;
+ return val;
+}
+
+/** Release all storage held inside 'obj', but do not free 'obj'.
+ */
+static void
+trn_extension_field_cc_clear(trn_extension_field_cc_t *obj)
+{
+ (void) obj;
+}
+
+void
+trn_extension_field_cc_free(trn_extension_field_cc_t *obj)
+{
+ if (obj == NULL)
+ return;
+ trn_extension_field_cc_clear(obj);
+ trunnel_memwipe(obj, sizeof(trn_extension_field_cc_t));
+ trunnel_free_(obj);
+}
+
+uint8_t
+trn_extension_field_cc_get_sendme_inc(const trn_extension_field_cc_t *inp)
+{
+ return inp->sendme_inc;
+}
+int
+trn_extension_field_cc_set_sendme_inc(trn_extension_field_cc_t *inp, uint8_t val)
+{
+ inp->sendme_inc = val;
+ return 0;
+}
+const char *
+trn_extension_field_cc_check(const trn_extension_field_cc_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_extension_field_cc_encoded_len(const trn_extension_field_cc_t *obj)
+{
+ ssize_t result = 0;
+
+ if (NULL != trn_extension_field_cc_check(obj))
+ return -1;
+
+
+ /* Length of u8 sendme_inc */
+ result += 1;
+ return result;
+}
+int
+trn_extension_field_cc_clear_errors(trn_extension_field_cc_t *obj)
+{
+ int r = obj->trunnel_error_code_;
+ obj->trunnel_error_code_ = 0;
+ return r;
+}
+ssize_t
+trn_extension_field_cc_encode(uint8_t *output, const size_t avail, const trn_extension_field_cc_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_extension_field_cc_encoded_len(obj);
+#endif
+
+ if (NULL != (msg = trn_extension_field_cc_check(obj)))
+ goto check_failed;
+
+#ifdef TRUNNEL_CHECK_ENCODED_LEN
+ trunnel_assert(encoded_len >= 0);
+#endif
+
+ /* Encode u8 sendme_inc */
+ trunnel_assert(written <= avail);
+ if (avail - written < 1)
+ goto truncated;
+ trunnel_set_uint8(ptr, (obj->sendme_inc));
+ 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_extension_field_cc_parse(), but do not allocate the output
+ * object.
+ */
+static ssize_t
+trn_extension_field_cc_parse_into(trn_extension_field_cc_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 sendme_inc */
+ CHECK_REMAINING(1, truncated);
+ obj->sendme_inc = (trunnel_get_uint8(ptr));
+ remaining -= 1; ptr += 1;
+ trunnel_assert(ptr + remaining == input + len_in);
+ return len_in - remaining;
+
+ truncated:
+ return -2;
+}
+
+ssize_t
+trn_extension_field_cc_parse(trn_extension_field_cc_t **output, const uint8_t *input, const size_t len_in)
+{
+ ssize_t result;
+ *output = trn_extension_field_cc_new();
+ if (NULL == *output)
+ return -1;
+ result = trn_extension_field_cc_parse_into(*output, input, len_in);
+ if (result < 0) {
+ trn_extension_field_cc_free(*output);
+ *output = NULL;
+ }
+ return result;
+}
diff --git a/src/trunnel/congestion_control.h b/src/trunnel/congestion_control.h
new file mode 100644
index 0000000000..0cc21a1db5
--- /dev/null
+++ b/src/trunnel/congestion_control.h
@@ -0,0 +1,67 @@
+/* congestion_control.h -- generated by Trunnel v1.5.3.
+ * https://gitweb.torproject.org/trunnel.git
+ * You probably shouldn't edit this file.
+ */
+#ifndef TRUNNEL_CONGESTION_CONTROL_H
+#define TRUNNEL_CONGESTION_CONTROL_H
+
+#include <stdint.h>
+#include "trunnel.h"
+
+#define TRUNNEL_EXT_TYPE_CC_FIELD_REQUEST 1
+#define TRUNNEL_EXT_TYPE_CC_FIELD_RESPONSE 2
+#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_EXTENSION_FIELD_CC)
+struct trn_extension_field_cc_st {
+ uint8_t sendme_inc;
+ uint8_t trunnel_error_code_;
+};
+#endif
+typedef struct trn_extension_field_cc_st trn_extension_field_cc_t;
+/** Return a newly allocated trn_extension_field_cc with all elements
+ * set to zero.
+ */
+trn_extension_field_cc_t *trn_extension_field_cc_new(void);
+/** Release all storage held by the trn_extension_field_cc in
+ * 'victim'. (Do nothing if 'victim' is NULL.)
+ */
+void trn_extension_field_cc_free(trn_extension_field_cc_t *victim);
+/** Try to parse a trn_extension_field_cc 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_extension_field_cc_t. On failure, return -2 if the
+ * input appears truncated, and -1 if the input is otherwise invalid.
+ */
+ssize_t trn_extension_field_cc_parse(trn_extension_field_cc_t **output, const uint8_t *input, const size_t len_in);
+/** Return the number of bytes we expect to need to encode the
+ * trn_extension_field_cc 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_extension_field_cc_encoded_len(const trn_extension_field_cc_t *obj);
+/** Try to encode the trn_extension_field_cc 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_extension_field_cc_encode(uint8_t *output, size_t avail, const trn_extension_field_cc_t *input);
+/** Check whether the internal state of the trn_extension_field_cc in
+ * 'obj' is consistent. Return NULL if it is, and a short message if
+ * it is not.
+ */
+const char *trn_extension_field_cc_check(const trn_extension_field_cc_t *obj);
+/** Clear any errors that were set on the object 'obj' by its setter
+ * functions. Return true iff errors were cleared.
+ */
+int trn_extension_field_cc_clear_errors(trn_extension_field_cc_t *obj);
+/** Return the value of the sendme_inc field of the
+ * trn_extension_field_cc_t in 'inp'
+ */
+uint8_t trn_extension_field_cc_get_sendme_inc(const trn_extension_field_cc_t *inp);
+/** Set the value of the sendme_inc field of the
+ * trn_extension_field_cc_t in 'inp' to 'val'. Return 0 on success;
+ * return -1 and set the error code on 'inp' on failure.
+ */
+int trn_extension_field_cc_set_sendme_inc(trn_extension_field_cc_t *inp, uint8_t val);
+
+
+#endif
diff --git a/src/trunnel/congestion_control.trunnel b/src/trunnel/congestion_control.trunnel
new file mode 100644
index 0000000000..50697a0cd2
--- /dev/null
+++ b/src/trunnel/congestion_control.trunnel
@@ -0,0 +1,22 @@
+/* This file contains the definition for the encrypted payload of a circuit
+ * parameter negotiation request/response portion of the trn_ntorv3 onionskin
+ * handshake. Currently only supports congestion control params. */
+
+/* The following is encoded in the extension format. */
+
+/* Field types. */
+const TRUNNEL_EXT_TYPE_CC_FIELD_REQUEST = 0x01;
+const TRUNNEL_EXT_TYPE_CC_FIELD_RESPONSE = 0x02;
+
+/*
+ * "Request" is an empty payload signalling that CC is enabled.
+ */
+
+/*
+ * "Response" consists of 1 single byte:
+ * SENDME_INC -- Min: 0, Max: 255
+ */
+
+struct trn_extension_field_cc {
+ u8 sendme_inc;
+};
diff --git a/src/trunnel/include.am b/src/trunnel/include.am
index 43d44d7720..b2aee81da9 100644
--- a/src/trunnel/include.am
+++ b/src/trunnel/include.am
@@ -14,7 +14,7 @@ TRUNNELINPUTS = \
src/trunnel/channelpadding_negotiation.trunnel \
src/trunnel/sendme_cell.trunnel \
src/trunnel/flow_control_cells.trunnel \
- src/trunnel/circ_params.trunnel \
+ src/trunnel/congestion_control.trunnel \
src/trunnel/socks5.trunnel \
src/trunnel/circpad_negotiation.trunnel
@@ -30,7 +30,7 @@ TRUNNELSOURCES = \
src/trunnel/channelpadding_negotiation.c \
src/trunnel/sendme_cell.c \
src/trunnel/flow_control_cells.c \
- src/trunnel/circ_params.c \
+ src/trunnel/congestion_control.c \
src/trunnel/socks5.c \
src/trunnel/netinfo.c \
src/trunnel/circpad_negotiation.c
@@ -49,7 +49,7 @@ TRUNNELHEADERS = \
src/trunnel/channelpadding_negotiation.h \
src/trunnel/sendme_cell.h \
src/trunnel/flow_control_cells.h \
- src/trunnel/circ_params.h \
+ src/trunnel/congestion_control.h \
src/trunnel/socks5.h \
src/trunnel/netinfo.h \
src/trunnel/circpad_negotiation.h