tor-commits
Threads by month
- ----- 2025 -----
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
October 2016
- 18 participants
- 868 discussions

[tor/master] prop224: Add INTRODUCE1 and INTRODUCE_ACK trunnel definition
by nickm@torproject.org 31 Oct '16
by nickm@torproject.org 31 Oct '16
31 Oct '16
commit 0fa671843e16f8e64c869726dc2cf3ffb206042a
Author: David Goulet <dgoulet(a)torproject.org>
Date: Mon Aug 29 15:31:38 2016 -0400
prop224: Add INTRODUCE1 and INTRODUCE_ACK trunnel definition
Signed-off-by: David Goulet <dgoulet(a)torproject.org>
---
src/trunnel/hs/cell_introduce1.c | 1345 ++++++++++++++++++++++++++++++++
src/trunnel/hs/cell_introduce1.h | 493 ++++++++++++
src/trunnel/hs/cell_introduce1.trunnel | 60 ++
src/trunnel/include.am | 6 +-
4 files changed, 1902 insertions(+), 2 deletions(-)
diff --git a/src/trunnel/hs/cell_introduce1.c b/src/trunnel/hs/cell_introduce1.c
new file mode 100644
index 0000000..d327ea8
--- /dev/null
+++ b/src/trunnel/hs/cell_introduce1.c
@@ -0,0 +1,1345 @@
+/* cell_introduce1.c -- generated by Trunnel v1.5.
+ * https://gitweb.torproject.org/trunnel.git
+ * You probably shouldn't edit this file.
+ */
+#include <stdlib.h>
+#include "trunnel-impl.h"
+
+#include "cell_introduce1.h"
+
+#define TRUNNEL_SET_ERROR_CODE(obj) \
+ do { \
+ (obj)->trunnel_error_code_ = 1; \
+ } while (0)
+
+#if defined(__COVERITY__) || defined(__clang_analyzer__)
+/* If we're runnning a static analysis tool, we don't want it to complain
+ * that some of our remaining-bytes checks are dead-code. */
+int cellintroduce_deadcode_dummy__ = 0;
+#define OR_DEADCODE_DUMMY || cellintroduce_deadcode_dummy__
+#else
+#define OR_DEADCODE_DUMMY
+#endif
+
+#define CHECK_REMAINING(nbytes, label) \
+ do { \
+ if (remaining < (nbytes) OR_DEADCODE_DUMMY) { \
+ goto label; \
+ } \
+ } while (0)
+
+typedef struct cell_extension_st cell_extension_t;
+cell_extension_t *cell_extension_new(void);
+void cell_extension_free(cell_extension_t *victim);
+ssize_t cell_extension_parse(cell_extension_t **output, const uint8_t *input, const size_t len_in);
+ssize_t cell_extension_encoded_len(const cell_extension_t *obj);
+ssize_t cell_extension_encode(uint8_t *output, size_t avail, const cell_extension_t *input);
+const char *cell_extension_check(const cell_extension_t *obj);
+int cell_extension_clear_errors(cell_extension_t *obj);
+typedef struct link_specifier_st link_specifier_t;
+link_specifier_t *link_specifier_new(void);
+void link_specifier_free(link_specifier_t *victim);
+ssize_t link_specifier_parse(link_specifier_t **output, const uint8_t *input, const size_t len_in);
+ssize_t link_specifier_encoded_len(const link_specifier_t *obj);
+ssize_t link_specifier_encode(uint8_t *output, size_t avail, const link_specifier_t *input);
+const char *link_specifier_check(const link_specifier_t *obj);
+int link_specifier_clear_errors(link_specifier_t *obj);
+hs_cell_introduce1_t *
+hs_cell_introduce1_new(void)
+{
+ hs_cell_introduce1_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce1_t));
+ if (NULL == val)
+ return NULL;
+ return val;
+}
+
+/** Release all storage held inside 'obj', but do not free 'obj'.
+ */
+static void
+hs_cell_introduce1_clear(hs_cell_introduce1_t *obj)
+{
+ (void) obj;
+ TRUNNEL_DYNARRAY_WIPE(&obj->auth_key);
+ TRUNNEL_DYNARRAY_CLEAR(&obj->auth_key);
+ cell_extension_free(obj->extensions);
+ obj->extensions = NULL;
+ TRUNNEL_DYNARRAY_WIPE(&obj->encrypted);
+ TRUNNEL_DYNARRAY_CLEAR(&obj->encrypted);
+}
+
+void
+hs_cell_introduce1_free(hs_cell_introduce1_t *obj)
+{
+ if (obj == NULL)
+ return;
+ hs_cell_introduce1_clear(obj);
+ trunnel_memwipe(obj, sizeof(hs_cell_introduce1_t));
+ trunnel_free_(obj);
+}
+
+size_t
+hs_cell_introduce1_getlen_legacy_key_id(const hs_cell_introduce1_t *inp)
+{
+ (void)inp; return TRUNNEL_SHA1_LEN;
+}
+
+uint8_t
+hs_cell_introduce1_get_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx)
+{
+ trunnel_assert(idx < TRUNNEL_SHA1_LEN);
+ return inp->legacy_key_id[idx];
+}
+
+uint8_t
+hs_cell_introduce1_getconst_legacy_key_id(const hs_cell_introduce1_t *inp, size_t idx)
+{
+ return hs_cell_introduce1_get_legacy_key_id((hs_cell_introduce1_t*)inp, idx);
+}
+int
+hs_cell_introduce1_set_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt)
+{
+ trunnel_assert(idx < TRUNNEL_SHA1_LEN);
+ inp->legacy_key_id[idx] = elt;
+ return 0;
+}
+
+uint8_t *
+hs_cell_introduce1_getarray_legacy_key_id(hs_cell_introduce1_t *inp)
+{
+ return inp->legacy_key_id;
+}
+const uint8_t *
+hs_cell_introduce1_getconstarray_legacy_key_id(const hs_cell_introduce1_t *inp)
+{
+ return (const uint8_t *)hs_cell_introduce1_getarray_legacy_key_id((hs_cell_introduce1_t*)inp);
+}
+uint8_t
+hs_cell_introduce1_get_auth_key_type(hs_cell_introduce1_t *inp)
+{
+ return inp->auth_key_type;
+}
+int
+hs_cell_introduce1_set_auth_key_type(hs_cell_introduce1_t *inp, uint8_t val)
+{
+ if (! ((val == 0 || val == 1 || val == 2))) {
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+ }
+ inp->auth_key_type = val;
+ return 0;
+}
+uint16_t
+hs_cell_introduce1_get_auth_key_len(hs_cell_introduce1_t *inp)
+{
+ return inp->auth_key_len;
+}
+int
+hs_cell_introduce1_set_auth_key_len(hs_cell_introduce1_t *inp, uint16_t val)
+{
+ inp->auth_key_len = val;
+ return 0;
+}
+size_t
+hs_cell_introduce1_getlen_auth_key(const hs_cell_introduce1_t *inp)
+{
+ return TRUNNEL_DYNARRAY_LEN(&inp->auth_key);
+}
+
+uint8_t
+hs_cell_introduce1_get_auth_key(hs_cell_introduce1_t *inp, size_t idx)
+{
+ return TRUNNEL_DYNARRAY_GET(&inp->auth_key, idx);
+}
+
+uint8_t
+hs_cell_introduce1_getconst_auth_key(const hs_cell_introduce1_t *inp, size_t idx)
+{
+ return hs_cell_introduce1_get_auth_key((hs_cell_introduce1_t*)inp, idx);
+}
+int
+hs_cell_introduce1_set_auth_key(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt)
+{
+ TRUNNEL_DYNARRAY_SET(&inp->auth_key, idx, elt);
+ return 0;
+}
+int
+hs_cell_introduce1_add_auth_key(hs_cell_introduce1_t *inp, uint8_t elt)
+{
+#if SIZE_MAX >= UINT16_MAX
+ if (inp->auth_key.n_ == UINT16_MAX)
+ goto trunnel_alloc_failed;
+#endif
+ TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->auth_key, elt, {});
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+
+uint8_t *
+hs_cell_introduce1_getarray_auth_key(hs_cell_introduce1_t *inp)
+{
+ return inp->auth_key.elts_;
+}
+const uint8_t *
+hs_cell_introduce1_getconstarray_auth_key(const hs_cell_introduce1_t *inp)
+{
+ return (const uint8_t *)hs_cell_introduce1_getarray_auth_key((hs_cell_introduce1_t*)inp);
+}
+int
+hs_cell_introduce1_setlen_auth_key(hs_cell_introduce1_t *inp, size_t newlen)
+{
+ uint8_t *newptr;
+#if UINT16_MAX < SIZE_MAX
+ if (newlen > UINT16_MAX)
+ goto trunnel_alloc_failed;
+#endif
+ newptr = trunnel_dynarray_setlen(&inp->auth_key.allocated_,
+ &inp->auth_key.n_, inp->auth_key.elts_, newlen,
+ sizeof(inp->auth_key.elts_[0]), (trunnel_free_fn_t) NULL,
+ &inp->trunnel_error_code_);
+ if (newlen != 0 && newptr == NULL)
+ goto trunnel_alloc_failed;
+ inp->auth_key.elts_ = newptr;
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+struct cell_extension_st *
+hs_cell_introduce1_get_extensions(hs_cell_introduce1_t *inp)
+{
+ return inp->extensions;
+}
+const struct cell_extension_st *
+hs_cell_introduce1_getconst_extensions(const hs_cell_introduce1_t *inp)
+{
+ return hs_cell_introduce1_get_extensions((hs_cell_introduce1_t*) inp);
+}
+int
+hs_cell_introduce1_set_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val)
+{
+ if (inp->extensions && inp->extensions != val)
+ cell_extension_free(inp->extensions);
+ return hs_cell_introduce1_set0_extensions(inp, val);
+}
+int
+hs_cell_introduce1_set0_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val)
+{
+ inp->extensions = val;
+ return 0;
+}
+size_t
+hs_cell_introduce1_getlen_encrypted(const hs_cell_introduce1_t *inp)
+{
+ return TRUNNEL_DYNARRAY_LEN(&inp->encrypted);
+}
+
+uint8_t
+hs_cell_introduce1_get_encrypted(hs_cell_introduce1_t *inp, size_t idx)
+{
+ return TRUNNEL_DYNARRAY_GET(&inp->encrypted, idx);
+}
+
+uint8_t
+hs_cell_introduce1_getconst_encrypted(const hs_cell_introduce1_t *inp, size_t idx)
+{
+ return hs_cell_introduce1_get_encrypted((hs_cell_introduce1_t*)inp, idx);
+}
+int
+hs_cell_introduce1_set_encrypted(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt)
+{
+ TRUNNEL_DYNARRAY_SET(&inp->encrypted, idx, elt);
+ return 0;
+}
+int
+hs_cell_introduce1_add_encrypted(hs_cell_introduce1_t *inp, uint8_t elt)
+{
+ TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->encrypted, elt, {});
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+
+uint8_t *
+hs_cell_introduce1_getarray_encrypted(hs_cell_introduce1_t *inp)
+{
+ return inp->encrypted.elts_;
+}
+const uint8_t *
+hs_cell_introduce1_getconstarray_encrypted(const hs_cell_introduce1_t *inp)
+{
+ return (const uint8_t *)hs_cell_introduce1_getarray_encrypted((hs_cell_introduce1_t*)inp);
+}
+int
+hs_cell_introduce1_setlen_encrypted(hs_cell_introduce1_t *inp, size_t newlen)
+{
+ uint8_t *newptr;
+ newptr = trunnel_dynarray_setlen(&inp->encrypted.allocated_,
+ &inp->encrypted.n_, inp->encrypted.elts_, newlen,
+ sizeof(inp->encrypted.elts_[0]), (trunnel_free_fn_t) NULL,
+ &inp->trunnel_error_code_);
+ if (newlen != 0 && newptr == NULL)
+ goto trunnel_alloc_failed;
+ inp->encrypted.elts_ = newptr;
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+const char *
+hs_cell_introduce1_check(const hs_cell_introduce1_t *obj)
+{
+ if (obj == NULL)
+ return "Object was NULL";
+ if (obj->trunnel_error_code_)
+ return "A set function failed on this object";
+ if (! (obj->auth_key_type == 0 || obj->auth_key_type == 1 || obj->auth_key_type == 2))
+ return "Integer out of bounds";
+ if (TRUNNEL_DYNARRAY_LEN(&obj->auth_key) != obj->auth_key_len)
+ return "Length mismatch for auth_key";
+ {
+ const char *msg;
+ if (NULL != (msg = cell_extension_check(obj->extensions)))
+ return msg;
+ }
+ return NULL;
+}
+
+ssize_t
+hs_cell_introduce1_encoded_len(const hs_cell_introduce1_t *obj)
+{
+ ssize_t result = 0;
+
+ if (NULL != hs_cell_introduce1_check(obj))
+ return -1;
+
+
+ /* Length of u8 legacy_key_id[TRUNNEL_SHA1_LEN] */
+ result += TRUNNEL_SHA1_LEN;
+
+ /* Length of u8 auth_key_type IN [0, 1, 2] */
+ result += 1;
+
+ /* Length of u16 auth_key_len */
+ result += 2;
+
+ /* Length of u8 auth_key[auth_key_len] */
+ result += TRUNNEL_DYNARRAY_LEN(&obj->auth_key);
+
+ /* Length of struct cell_extension extensions */
+ result += cell_extension_encoded_len(obj->extensions);
+
+ /* Length of u8 encrypted[] */
+ result += TRUNNEL_DYNARRAY_LEN(&obj->encrypted);
+ return result;
+}
+int
+hs_cell_introduce1_clear_errors(hs_cell_introduce1_t *obj)
+{
+ int r = obj->trunnel_error_code_;
+ obj->trunnel_error_code_ = 0;
+ return r;
+}
+ssize_t
+hs_cell_introduce1_encode(uint8_t *output, const size_t avail, const hs_cell_introduce1_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 = hs_cell_introduce1_encoded_len(obj);
+#endif
+
+ if (NULL != (msg = hs_cell_introduce1_check(obj)))
+ goto check_failed;
+
+#ifdef TRUNNEL_CHECK_ENCODED_LEN
+ trunnel_assert(encoded_len >= 0);
+#endif
+
+ /* Encode u8 legacy_key_id[TRUNNEL_SHA1_LEN] */
+ trunnel_assert(written <= avail);
+ if (avail - written < TRUNNEL_SHA1_LEN)
+ goto truncated;
+ memcpy(ptr, obj->legacy_key_id, TRUNNEL_SHA1_LEN);
+ written += TRUNNEL_SHA1_LEN; ptr += TRUNNEL_SHA1_LEN;
+
+ /* Encode u8 auth_key_type IN [0, 1, 2] */
+ trunnel_assert(written <= avail);
+ if (avail - written < 1)
+ goto truncated;
+ trunnel_set_uint8(ptr, (obj->auth_key_type));
+ written += 1; ptr += 1;
+
+ /* Encode u16 auth_key_len */
+ trunnel_assert(written <= avail);
+ if (avail - written < 2)
+ goto truncated;
+ trunnel_set_uint16(ptr, trunnel_htons(obj->auth_key_len));
+ written += 2; ptr += 2;
+
+ /* Encode u8 auth_key[auth_key_len] */
+ {
+ size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->auth_key);
+ trunnel_assert(obj->auth_key_len == elt_len);
+ trunnel_assert(written <= avail);
+ if (avail - written < elt_len)
+ goto truncated;
+ if (elt_len)
+ memcpy(ptr, obj->auth_key.elts_, elt_len);
+ written += elt_len; ptr += elt_len;
+ }
+
+ /* Encode struct cell_extension extensions */
+ trunnel_assert(written <= avail);
+ result = cell_extension_encode(ptr, avail - written, obj->extensions);
+ if (result < 0)
+ goto fail; /* XXXXXXX !*/
+ written += result; ptr += result;
+
+ /* Encode u8 encrypted[] */
+ {
+ size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->encrypted);
+ trunnel_assert(written <= avail);
+ if (avail - written < elt_len)
+ goto truncated;
+ if (elt_len)
+ memcpy(ptr, obj->encrypted.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 hs_cell_introduce1_parse(), but do not allocate the output
+ * object.
+ */
+static ssize_t
+hs_cell_introduce1_parse_into(hs_cell_introduce1_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 legacy_key_id[TRUNNEL_SHA1_LEN] */
+ CHECK_REMAINING(TRUNNEL_SHA1_LEN, truncated);
+ memcpy(obj->legacy_key_id, ptr, TRUNNEL_SHA1_LEN);
+ remaining -= TRUNNEL_SHA1_LEN; ptr += TRUNNEL_SHA1_LEN;
+
+ /* Parse u8 auth_key_type IN [0, 1, 2] */
+ CHECK_REMAINING(1, truncated);
+ obj->auth_key_type = (trunnel_get_uint8(ptr));
+ remaining -= 1; ptr += 1;
+ if (! (obj->auth_key_type == 0 || obj->auth_key_type == 1 || obj->auth_key_type == 2))
+ goto fail;
+
+ /* Parse u16 auth_key_len */
+ CHECK_REMAINING(2, truncated);
+ obj->auth_key_len = trunnel_ntohs(trunnel_get_uint16(ptr));
+ remaining -= 2; ptr += 2;
+
+ /* Parse u8 auth_key[auth_key_len] */
+ CHECK_REMAINING(obj->auth_key_len, truncated);
+ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->auth_key, obj->auth_key_len, {});
+ obj->auth_key.n_ = obj->auth_key_len;
+ if (obj->auth_key_len)
+ memcpy(obj->auth_key.elts_, ptr, obj->auth_key_len);
+ ptr += obj->auth_key_len; remaining -= obj->auth_key_len;
+
+ /* Parse struct cell_extension extensions */
+ result = cell_extension_parse(&obj->extensions, ptr, remaining);
+ if (result < 0)
+ goto relay_fail;
+ trunnel_assert((size_t)result <= remaining);
+ remaining -= result; ptr += result;
+
+ /* Parse u8 encrypted[] */
+ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->encrypted, remaining, {});
+ obj->encrypted.n_ = remaining;
+ if (remaining)
+ memcpy(obj->encrypted.elts_, ptr, remaining);
+ ptr += remaining; remaining -= remaining;
+ trunnel_assert(ptr + remaining == input + len_in);
+ return len_in - remaining;
+
+ truncated:
+ return -2;
+ relay_fail:
+ trunnel_assert(result < 0);
+ return result;
+ trunnel_alloc_failed:
+ return -1;
+ fail:
+ result = -1;
+ return result;
+}
+
+ssize_t
+hs_cell_introduce1_parse(hs_cell_introduce1_t **output, const uint8_t *input, const size_t len_in)
+{
+ ssize_t result;
+ *output = hs_cell_introduce1_new();
+ if (NULL == *output)
+ return -1;
+ result = hs_cell_introduce1_parse_into(*output, input, len_in);
+ if (result < 0) {
+ hs_cell_introduce1_free(*output);
+ *output = NULL;
+ }
+ return result;
+}
+hs_cell_introduce_ack_t *
+hs_cell_introduce_ack_new(void)
+{
+ hs_cell_introduce_ack_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce_ack_t));
+ if (NULL == val)
+ return NULL;
+ return val;
+}
+
+/** Release all storage held inside 'obj', but do not free 'obj'.
+ */
+static void
+hs_cell_introduce_ack_clear(hs_cell_introduce_ack_t *obj)
+{
+ (void) obj;
+ cell_extension_free(obj->extensions);
+ obj->extensions = NULL;
+}
+
+void
+hs_cell_introduce_ack_free(hs_cell_introduce_ack_t *obj)
+{
+ if (obj == NULL)
+ return;
+ hs_cell_introduce_ack_clear(obj);
+ trunnel_memwipe(obj, sizeof(hs_cell_introduce_ack_t));
+ trunnel_free_(obj);
+}
+
+uint16_t
+hs_cell_introduce_ack_get_status(hs_cell_introduce_ack_t *inp)
+{
+ return inp->status;
+}
+int
+hs_cell_introduce_ack_set_status(hs_cell_introduce_ack_t *inp, uint16_t val)
+{
+ if (! ((val == 0 || val == 1 || val == 2))) {
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+ }
+ inp->status = val;
+ return 0;
+}
+struct cell_extension_st *
+hs_cell_introduce_ack_get_extensions(hs_cell_introduce_ack_t *inp)
+{
+ return inp->extensions;
+}
+const struct cell_extension_st *
+hs_cell_introduce_ack_getconst_extensions(const hs_cell_introduce_ack_t *inp)
+{
+ return hs_cell_introduce_ack_get_extensions((hs_cell_introduce_ack_t*) inp);
+}
+int
+hs_cell_introduce_ack_set_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val)
+{
+ if (inp->extensions && inp->extensions != val)
+ cell_extension_free(inp->extensions);
+ return hs_cell_introduce_ack_set0_extensions(inp, val);
+}
+int
+hs_cell_introduce_ack_set0_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val)
+{
+ inp->extensions = val;
+ return 0;
+}
+const char *
+hs_cell_introduce_ack_check(const hs_cell_introduce_ack_t *obj)
+{
+ if (obj == NULL)
+ return "Object was NULL";
+ if (obj->trunnel_error_code_)
+ return "A set function failed on this object";
+ if (! (obj->status == 0 || obj->status == 1 || obj->status == 2))
+ return "Integer out of bounds";
+ {
+ const char *msg;
+ if (NULL != (msg = cell_extension_check(obj->extensions)))
+ return msg;
+ }
+ return NULL;
+}
+
+ssize_t
+hs_cell_introduce_ack_encoded_len(const hs_cell_introduce_ack_t *obj)
+{
+ ssize_t result = 0;
+
+ if (NULL != hs_cell_introduce_ack_check(obj))
+ return -1;
+
+
+ /* Length of u16 status IN [0, 1, 2] */
+ result += 2;
+
+ /* Length of struct cell_extension extensions */
+ result += cell_extension_encoded_len(obj->extensions);
+ return result;
+}
+int
+hs_cell_introduce_ack_clear_errors(hs_cell_introduce_ack_t *obj)
+{
+ int r = obj->trunnel_error_code_;
+ obj->trunnel_error_code_ = 0;
+ return r;
+}
+ssize_t
+hs_cell_introduce_ack_encode(uint8_t *output, const size_t avail, const hs_cell_introduce_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 = hs_cell_introduce_ack_encoded_len(obj);
+#endif
+
+ if (NULL != (msg = hs_cell_introduce_ack_check(obj)))
+ goto check_failed;
+
+#ifdef TRUNNEL_CHECK_ENCODED_LEN
+ trunnel_assert(encoded_len >= 0);
+#endif
+
+ /* Encode u16 status IN [0, 1, 2] */
+ trunnel_assert(written <= avail);
+ if (avail - written < 2)
+ goto truncated;
+ trunnel_set_uint16(ptr, trunnel_htons(obj->status));
+ written += 2; ptr += 2;
+
+ /* Encode struct cell_extension extensions */
+ trunnel_assert(written <= avail);
+ result = cell_extension_encode(ptr, avail - written, obj->extensions);
+ if (result < 0)
+ goto fail; /* XXXXXXX !*/
+ written += result; ptr += result;
+
+
+ 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 hs_cell_introduce_ack_parse(), but do not allocate the output
+ * object.
+ */
+static ssize_t
+hs_cell_introduce_ack_parse_into(hs_cell_introduce_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 u16 status IN [0, 1, 2] */
+ CHECK_REMAINING(2, truncated);
+ obj->status = trunnel_ntohs(trunnel_get_uint16(ptr));
+ remaining -= 2; ptr += 2;
+ if (! (obj->status == 0 || obj->status == 1 || obj->status == 2))
+ goto fail;
+
+ /* Parse struct cell_extension extensions */
+ result = cell_extension_parse(&obj->extensions, ptr, remaining);
+ if (result < 0)
+ goto relay_fail;
+ trunnel_assert((size_t)result <= remaining);
+ remaining -= result; ptr += result;
+ trunnel_assert(ptr + remaining == input + len_in);
+ return len_in - remaining;
+
+ truncated:
+ return -2;
+ relay_fail:
+ trunnel_assert(result < 0);
+ return result;
+ fail:
+ result = -1;
+ return result;
+}
+
+ssize_t
+hs_cell_introduce_ack_parse(hs_cell_introduce_ack_t **output, const uint8_t *input, const size_t len_in)
+{
+ ssize_t result;
+ *output = hs_cell_introduce_ack_new();
+ if (NULL == *output)
+ return -1;
+ result = hs_cell_introduce_ack_parse_into(*output, input, len_in);
+ if (result < 0) {
+ hs_cell_introduce_ack_free(*output);
+ *output = NULL;
+ }
+ return result;
+}
+hs_cell_introduce_encrypted_t *
+hs_cell_introduce_encrypted_new(void)
+{
+ hs_cell_introduce_encrypted_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce_encrypted_t));
+ if (NULL == val)
+ return NULL;
+ return val;
+}
+
+/** Release all storage held inside 'obj', but do not free 'obj'.
+ */
+static void
+hs_cell_introduce_encrypted_clear(hs_cell_introduce_encrypted_t *obj)
+{
+ (void) obj;
+ cell_extension_free(obj->extensions);
+ obj->extensions = NULL;
+ TRUNNEL_DYNARRAY_WIPE(&obj->onion_key);
+ TRUNNEL_DYNARRAY_CLEAR(&obj->onion_key);
+ {
+
+ unsigned idx;
+ for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->nspecs); ++idx) {
+ link_specifier_free(TRUNNEL_DYNARRAY_GET(&obj->nspecs, idx));
+ }
+ }
+ TRUNNEL_DYNARRAY_WIPE(&obj->nspecs);
+ TRUNNEL_DYNARRAY_CLEAR(&obj->nspecs);
+ TRUNNEL_DYNARRAY_WIPE(&obj->pad);
+ TRUNNEL_DYNARRAY_CLEAR(&obj->pad);
+}
+
+void
+hs_cell_introduce_encrypted_free(hs_cell_introduce_encrypted_t *obj)
+{
+ if (obj == NULL)
+ return;
+ hs_cell_introduce_encrypted_clear(obj);
+ trunnel_memwipe(obj, sizeof(hs_cell_introduce_encrypted_t));
+ trunnel_free_(obj);
+}
+
+size_t
+hs_cell_introduce_encrypted_getlen_rend_cookie(const hs_cell_introduce_encrypted_t *inp)
+{
+ (void)inp; return TRUNNEL_REND_COOKIE_LEN;
+}
+
+uint8_t
+hs_cell_introduce_encrypted_get_rend_cookie(hs_cell_introduce_encrypted_t *inp, size_t idx)
+{
+ trunnel_assert(idx < TRUNNEL_REND_COOKIE_LEN);
+ return inp->rend_cookie[idx];
+}
+
+uint8_t
+hs_cell_introduce_encrypted_getconst_rend_cookie(const hs_cell_introduce_encrypted_t *inp, size_t idx)
+{
+ return hs_cell_introduce_encrypted_get_rend_cookie((hs_cell_introduce_encrypted_t*)inp, idx);
+}
+int
+hs_cell_introduce_encrypted_set_rend_cookie(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt)
+{
+ trunnel_assert(idx < TRUNNEL_REND_COOKIE_LEN);
+ inp->rend_cookie[idx] = elt;
+ return 0;
+}
+
+uint8_t *
+hs_cell_introduce_encrypted_getarray_rend_cookie(hs_cell_introduce_encrypted_t *inp)
+{
+ return inp->rend_cookie;
+}
+const uint8_t *
+hs_cell_introduce_encrypted_getconstarray_rend_cookie(const hs_cell_introduce_encrypted_t *inp)
+{
+ return (const uint8_t *)hs_cell_introduce_encrypted_getarray_rend_cookie((hs_cell_introduce_encrypted_t*)inp);
+}
+struct cell_extension_st *
+hs_cell_introduce_encrypted_get_extensions(hs_cell_introduce_encrypted_t *inp)
+{
+ return inp->extensions;
+}
+const struct cell_extension_st *
+hs_cell_introduce_encrypted_getconst_extensions(const hs_cell_introduce_encrypted_t *inp)
+{
+ return hs_cell_introduce_encrypted_get_extensions((hs_cell_introduce_encrypted_t*) inp);
+}
+int
+hs_cell_introduce_encrypted_set_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val)
+{
+ if (inp->extensions && inp->extensions != val)
+ cell_extension_free(inp->extensions);
+ return hs_cell_introduce_encrypted_set0_extensions(inp, val);
+}
+int
+hs_cell_introduce_encrypted_set0_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val)
+{
+ inp->extensions = val;
+ return 0;
+}
+uint8_t
+hs_cell_introduce_encrypted_get_onion_key_type(hs_cell_introduce_encrypted_t *inp)
+{
+ return inp->onion_key_type;
+}
+int
+hs_cell_introduce_encrypted_set_onion_key_type(hs_cell_introduce_encrypted_t *inp, uint8_t val)
+{
+ inp->onion_key_type = val;
+ return 0;
+}
+uint16_t
+hs_cell_introduce_encrypted_get_onion_key_len(hs_cell_introduce_encrypted_t *inp)
+{
+ return inp->onion_key_len;
+}
+int
+hs_cell_introduce_encrypted_set_onion_key_len(hs_cell_introduce_encrypted_t *inp, uint16_t val)
+{
+ inp->onion_key_len = val;
+ return 0;
+}
+size_t
+hs_cell_introduce_encrypted_getlen_onion_key(const hs_cell_introduce_encrypted_t *inp)
+{
+ return TRUNNEL_DYNARRAY_LEN(&inp->onion_key);
+}
+
+uint8_t
+hs_cell_introduce_encrypted_get_onion_key(hs_cell_introduce_encrypted_t *inp, size_t idx)
+{
+ return TRUNNEL_DYNARRAY_GET(&inp->onion_key, idx);
+}
+
+uint8_t
+hs_cell_introduce_encrypted_getconst_onion_key(const hs_cell_introduce_encrypted_t *inp, size_t idx)
+{
+ return hs_cell_introduce_encrypted_get_onion_key((hs_cell_introduce_encrypted_t*)inp, idx);
+}
+int
+hs_cell_introduce_encrypted_set_onion_key(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt)
+{
+ TRUNNEL_DYNARRAY_SET(&inp->onion_key, idx, elt);
+ return 0;
+}
+int
+hs_cell_introduce_encrypted_add_onion_key(hs_cell_introduce_encrypted_t *inp, uint8_t elt)
+{
+#if SIZE_MAX >= UINT16_MAX
+ if (inp->onion_key.n_ == UINT16_MAX)
+ goto trunnel_alloc_failed;
+#endif
+ TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->onion_key, elt, {});
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+
+uint8_t *
+hs_cell_introduce_encrypted_getarray_onion_key(hs_cell_introduce_encrypted_t *inp)
+{
+ return inp->onion_key.elts_;
+}
+const uint8_t *
+hs_cell_introduce_encrypted_getconstarray_onion_key(const hs_cell_introduce_encrypted_t *inp)
+{
+ return (const uint8_t *)hs_cell_introduce_encrypted_getarray_onion_key((hs_cell_introduce_encrypted_t*)inp);
+}
+int
+hs_cell_introduce_encrypted_setlen_onion_key(hs_cell_introduce_encrypted_t *inp, size_t newlen)
+{
+ uint8_t *newptr;
+#if UINT16_MAX < SIZE_MAX
+ if (newlen > UINT16_MAX)
+ goto trunnel_alloc_failed;
+#endif
+ newptr = trunnel_dynarray_setlen(&inp->onion_key.allocated_,
+ &inp->onion_key.n_, inp->onion_key.elts_, newlen,
+ sizeof(inp->onion_key.elts_[0]), (trunnel_free_fn_t) NULL,
+ &inp->trunnel_error_code_);
+ if (newlen != 0 && newptr == NULL)
+ goto trunnel_alloc_failed;
+ inp->onion_key.elts_ = newptr;
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+uint8_t
+hs_cell_introduce_encrypted_get_nspec(hs_cell_introduce_encrypted_t *inp)
+{
+ return inp->nspec;
+}
+int
+hs_cell_introduce_encrypted_set_nspec(hs_cell_introduce_encrypted_t *inp, uint8_t val)
+{
+ inp->nspec = val;
+ return 0;
+}
+size_t
+hs_cell_introduce_encrypted_getlen_nspecs(const hs_cell_introduce_encrypted_t *inp)
+{
+ return TRUNNEL_DYNARRAY_LEN(&inp->nspecs);
+}
+
+struct link_specifier_st *
+hs_cell_introduce_encrypted_get_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx)
+{
+ return TRUNNEL_DYNARRAY_GET(&inp->nspecs, idx);
+}
+
+ const struct link_specifier_st *
+hs_cell_introduce_encrypted_getconst_nspecs(const hs_cell_introduce_encrypted_t *inp, size_t idx)
+{
+ return hs_cell_introduce_encrypted_get_nspecs((hs_cell_introduce_encrypted_t*)inp, idx);
+}
+int
+hs_cell_introduce_encrypted_set_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt)
+{
+ link_specifier_t *oldval = TRUNNEL_DYNARRAY_GET(&inp->nspecs, idx);
+ if (oldval && oldval != elt)
+ link_specifier_free(oldval);
+ return hs_cell_introduce_encrypted_set0_nspecs(inp, idx, elt);
+}
+int
+hs_cell_introduce_encrypted_set0_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt)
+{
+ TRUNNEL_DYNARRAY_SET(&inp->nspecs, idx, elt);
+ return 0;
+}
+int
+hs_cell_introduce_encrypted_add_nspecs(hs_cell_introduce_encrypted_t *inp, struct link_specifier_st * elt)
+{
+#if SIZE_MAX >= UINT8_MAX
+ if (inp->nspecs.n_ == UINT8_MAX)
+ goto trunnel_alloc_failed;
+#endif
+ TRUNNEL_DYNARRAY_ADD(struct link_specifier_st *, &inp->nspecs, elt, {});
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+
+struct link_specifier_st * *
+hs_cell_introduce_encrypted_getarray_nspecs(hs_cell_introduce_encrypted_t *inp)
+{
+ return inp->nspecs.elts_;
+}
+const struct link_specifier_st * const *
+hs_cell_introduce_encrypted_getconstarray_nspecs(const hs_cell_introduce_encrypted_t *inp)
+{
+ return (const struct link_specifier_st * const *)hs_cell_introduce_encrypted_getarray_nspecs((hs_cell_introduce_encrypted_t*)inp);
+}
+int
+hs_cell_introduce_encrypted_setlen_nspecs(hs_cell_introduce_encrypted_t *inp, size_t newlen)
+{
+ struct link_specifier_st * *newptr;
+#if UINT8_MAX < SIZE_MAX
+ if (newlen > UINT8_MAX)
+ goto trunnel_alloc_failed;
+#endif
+ newptr = trunnel_dynarray_setlen(&inp->nspecs.allocated_,
+ &inp->nspecs.n_, inp->nspecs.elts_, newlen,
+ sizeof(inp->nspecs.elts_[0]), (trunnel_free_fn_t) link_specifier_free,
+ &inp->trunnel_error_code_);
+ if (newlen != 0 && newptr == NULL)
+ goto trunnel_alloc_failed;
+ inp->nspecs.elts_ = newptr;
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+size_t
+hs_cell_introduce_encrypted_getlen_pad(const hs_cell_introduce_encrypted_t *inp)
+{
+ return TRUNNEL_DYNARRAY_LEN(&inp->pad);
+}
+
+uint8_t
+hs_cell_introduce_encrypted_get_pad(hs_cell_introduce_encrypted_t *inp, size_t idx)
+{
+ return TRUNNEL_DYNARRAY_GET(&inp->pad, idx);
+}
+
+uint8_t
+hs_cell_introduce_encrypted_getconst_pad(const hs_cell_introduce_encrypted_t *inp, size_t idx)
+{
+ return hs_cell_introduce_encrypted_get_pad((hs_cell_introduce_encrypted_t*)inp, idx);
+}
+int
+hs_cell_introduce_encrypted_set_pad(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt)
+{
+ TRUNNEL_DYNARRAY_SET(&inp->pad, idx, elt);
+ return 0;
+}
+int
+hs_cell_introduce_encrypted_add_pad(hs_cell_introduce_encrypted_t *inp, uint8_t elt)
+{
+ TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->pad, elt, {});
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+
+uint8_t *
+hs_cell_introduce_encrypted_getarray_pad(hs_cell_introduce_encrypted_t *inp)
+{
+ return inp->pad.elts_;
+}
+const uint8_t *
+hs_cell_introduce_encrypted_getconstarray_pad(const hs_cell_introduce_encrypted_t *inp)
+{
+ return (const uint8_t *)hs_cell_introduce_encrypted_getarray_pad((hs_cell_introduce_encrypted_t*)inp);
+}
+int
+hs_cell_introduce_encrypted_setlen_pad(hs_cell_introduce_encrypted_t *inp, size_t newlen)
+{
+ uint8_t *newptr;
+ newptr = trunnel_dynarray_setlen(&inp->pad.allocated_,
+ &inp->pad.n_, inp->pad.elts_, newlen,
+ sizeof(inp->pad.elts_[0]), (trunnel_free_fn_t) NULL,
+ &inp->trunnel_error_code_);
+ if (newlen != 0 && newptr == NULL)
+ goto trunnel_alloc_failed;
+ inp->pad.elts_ = newptr;
+ return 0;
+ trunnel_alloc_failed:
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+}
+const char *
+hs_cell_introduce_encrypted_check(const hs_cell_introduce_encrypted_t *obj)
+{
+ if (obj == NULL)
+ return "Object was NULL";
+ if (obj->trunnel_error_code_)
+ return "A set function failed on this object";
+ {
+ const char *msg;
+ if (NULL != (msg = cell_extension_check(obj->extensions)))
+ return msg;
+ }
+ if (TRUNNEL_DYNARRAY_LEN(&obj->onion_key) != obj->onion_key_len)
+ return "Length mismatch for onion_key";
+ {
+ const char *msg;
+
+ unsigned idx;
+ for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->nspecs); ++idx) {
+ if (NULL != (msg = link_specifier_check(TRUNNEL_DYNARRAY_GET(&obj->nspecs, idx))))
+ return msg;
+ }
+ }
+ if (TRUNNEL_DYNARRAY_LEN(&obj->nspecs) != obj->nspec)
+ return "Length mismatch for nspecs";
+ return NULL;
+}
+
+ssize_t
+hs_cell_introduce_encrypted_encoded_len(const hs_cell_introduce_encrypted_t *obj)
+{
+ ssize_t result = 0;
+
+ if (NULL != hs_cell_introduce_encrypted_check(obj))
+ return -1;
+
+
+ /* Length of u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN] */
+ result += TRUNNEL_REND_COOKIE_LEN;
+
+ /* Length of struct cell_extension extensions */
+ result += cell_extension_encoded_len(obj->extensions);
+
+ /* Length of u8 onion_key_type */
+ result += 1;
+
+ /* Length of u16 onion_key_len */
+ result += 2;
+
+ /* Length of u8 onion_key[onion_key_len] */
+ result += TRUNNEL_DYNARRAY_LEN(&obj->onion_key);
+
+ /* Length of u8 nspec */
+ result += 1;
+
+ /* Length of struct link_specifier nspecs[nspec] */
+ {
+
+ unsigned idx;
+ for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->nspecs); ++idx) {
+ result += link_specifier_encoded_len(TRUNNEL_DYNARRAY_GET(&obj->nspecs, idx));
+ }
+ }
+
+ /* Length of u8 pad[] */
+ result += TRUNNEL_DYNARRAY_LEN(&obj->pad);
+ return result;
+}
+int
+hs_cell_introduce_encrypted_clear_errors(hs_cell_introduce_encrypted_t *obj)
+{
+ int r = obj->trunnel_error_code_;
+ obj->trunnel_error_code_ = 0;
+ return r;
+}
+ssize_t
+hs_cell_introduce_encrypted_encode(uint8_t *output, const size_t avail, const hs_cell_introduce_encrypted_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 = hs_cell_introduce_encrypted_encoded_len(obj);
+#endif
+
+ if (NULL != (msg = hs_cell_introduce_encrypted_check(obj)))
+ goto check_failed;
+
+#ifdef TRUNNEL_CHECK_ENCODED_LEN
+ trunnel_assert(encoded_len >= 0);
+#endif
+
+ /* Encode u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN] */
+ trunnel_assert(written <= avail);
+ if (avail - written < TRUNNEL_REND_COOKIE_LEN)
+ goto truncated;
+ memcpy(ptr, obj->rend_cookie, TRUNNEL_REND_COOKIE_LEN);
+ written += TRUNNEL_REND_COOKIE_LEN; ptr += TRUNNEL_REND_COOKIE_LEN;
+
+ /* Encode struct cell_extension extensions */
+ trunnel_assert(written <= avail);
+ result = cell_extension_encode(ptr, avail - written, obj->extensions);
+ if (result < 0)
+ goto fail; /* XXXXXXX !*/
+ written += result; ptr += result;
+
+ /* Encode u8 onion_key_type */
+ trunnel_assert(written <= avail);
+ if (avail - written < 1)
+ goto truncated;
+ trunnel_set_uint8(ptr, (obj->onion_key_type));
+ written += 1; ptr += 1;
+
+ /* Encode u16 onion_key_len */
+ trunnel_assert(written <= avail);
+ if (avail - written < 2)
+ goto truncated;
+ trunnel_set_uint16(ptr, trunnel_htons(obj->onion_key_len));
+ written += 2; ptr += 2;
+
+ /* Encode u8 onion_key[onion_key_len] */
+ {
+ size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->onion_key);
+ trunnel_assert(obj->onion_key_len == elt_len);
+ trunnel_assert(written <= avail);
+ if (avail - written < elt_len)
+ goto truncated;
+ if (elt_len)
+ memcpy(ptr, obj->onion_key.elts_, elt_len);
+ written += elt_len; ptr += elt_len;
+ }
+
+ /* Encode u8 nspec */
+ trunnel_assert(written <= avail);
+ if (avail - written < 1)
+ goto truncated;
+ trunnel_set_uint8(ptr, (obj->nspec));
+ written += 1; ptr += 1;
+
+ /* Encode struct link_specifier nspecs[nspec] */
+ {
+
+ unsigned idx;
+ for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->nspecs); ++idx) {
+ trunnel_assert(written <= avail);
+ result = link_specifier_encode(ptr, avail - written, TRUNNEL_DYNARRAY_GET(&obj->nspecs, idx));
+ if (result < 0)
+ goto fail; /* XXXXXXX !*/
+ written += result; ptr += result;
+ }
+ }
+
+ /* Encode u8 pad[] */
+ {
+ size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->pad);
+ trunnel_assert(written <= avail);
+ if (avail - written < elt_len)
+ goto truncated;
+ if (elt_len)
+ memcpy(ptr, obj->pad.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 hs_cell_introduce_encrypted_parse(), but do not allocate the
+ * output object.
+ */
+static ssize_t
+hs_cell_introduce_encrypted_parse_into(hs_cell_introduce_encrypted_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 rend_cookie[TRUNNEL_REND_COOKIE_LEN] */
+ CHECK_REMAINING(TRUNNEL_REND_COOKIE_LEN, truncated);
+ memcpy(obj->rend_cookie, ptr, TRUNNEL_REND_COOKIE_LEN);
+ remaining -= TRUNNEL_REND_COOKIE_LEN; ptr += TRUNNEL_REND_COOKIE_LEN;
+
+ /* Parse struct cell_extension extensions */
+ result = cell_extension_parse(&obj->extensions, ptr, remaining);
+ if (result < 0)
+ goto relay_fail;
+ trunnel_assert((size_t)result <= remaining);
+ remaining -= result; ptr += result;
+
+ /* Parse u8 onion_key_type */
+ CHECK_REMAINING(1, truncated);
+ obj->onion_key_type = (trunnel_get_uint8(ptr));
+ remaining -= 1; ptr += 1;
+
+ /* Parse u16 onion_key_len */
+ CHECK_REMAINING(2, truncated);
+ obj->onion_key_len = trunnel_ntohs(trunnel_get_uint16(ptr));
+ remaining -= 2; ptr += 2;
+
+ /* Parse u8 onion_key[onion_key_len] */
+ CHECK_REMAINING(obj->onion_key_len, truncated);
+ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->onion_key, obj->onion_key_len, {});
+ obj->onion_key.n_ = obj->onion_key_len;
+ if (obj->onion_key_len)
+ memcpy(obj->onion_key.elts_, ptr, obj->onion_key_len);
+ ptr += obj->onion_key_len; remaining -= obj->onion_key_len;
+
+ /* Parse u8 nspec */
+ CHECK_REMAINING(1, truncated);
+ obj->nspec = (trunnel_get_uint8(ptr));
+ remaining -= 1; ptr += 1;
+
+ /* Parse struct link_specifier nspecs[nspec] */
+ TRUNNEL_DYNARRAY_EXPAND(link_specifier_t *, &obj->nspecs, obj->nspec, {});
+ {
+ link_specifier_t * elt;
+ unsigned idx;
+ for (idx = 0; idx < obj->nspec; ++idx) {
+ result = link_specifier_parse(&elt, ptr, remaining);
+ if (result < 0)
+ goto relay_fail;
+ trunnel_assert((size_t)result <= remaining);
+ remaining -= result; ptr += result;
+ TRUNNEL_DYNARRAY_ADD(link_specifier_t *, &obj->nspecs, elt, {link_specifier_free(elt);});
+ }
+ }
+
+ /* Parse u8 pad[] */
+ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->pad, remaining, {});
+ obj->pad.n_ = remaining;
+ if (remaining)
+ memcpy(obj->pad.elts_, ptr, remaining);
+ ptr += remaining; remaining -= remaining;
+ trunnel_assert(ptr + remaining == input + len_in);
+ return len_in - remaining;
+
+ truncated:
+ return -2;
+ relay_fail:
+ trunnel_assert(result < 0);
+ return result;
+ trunnel_alloc_failed:
+ return -1;
+}
+
+ssize_t
+hs_cell_introduce_encrypted_parse(hs_cell_introduce_encrypted_t **output, const uint8_t *input, const size_t len_in)
+{
+ ssize_t result;
+ *output = hs_cell_introduce_encrypted_new();
+ if (NULL == *output)
+ return -1;
+ result = hs_cell_introduce_encrypted_parse_into(*output, input, len_in);
+ if (result < 0) {
+ hs_cell_introduce_encrypted_free(*output);
+ *output = NULL;
+ }
+ return result;
+}
diff --git a/src/trunnel/hs/cell_introduce1.h b/src/trunnel/hs/cell_introduce1.h
new file mode 100644
index 0000000..09ee0fb
--- /dev/null
+++ b/src/trunnel/hs/cell_introduce1.h
@@ -0,0 +1,493 @@
+/* cell_introduce1.h -- generated by by Trunnel v1.5.
+ * https://gitweb.torproject.org/trunnel.git
+ * You probably shouldn't edit this file.
+ */
+#ifndef TRUNNEL_CELL_INTRODUCE1_H
+#define TRUNNEL_CELL_INTRODUCE1_H
+
+#include <stdint.h>
+#include "trunnel.h"
+
+struct cell_extension_st;
+struct link_specifier_st;
+#define TRUNNEL_SHA1_LEN 20
+#define TRUNNEL_REND_COOKIE_LEN 20
+#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE1)
+struct hs_cell_introduce1_st {
+ uint8_t legacy_key_id[TRUNNEL_SHA1_LEN];
+ uint8_t auth_key_type;
+ uint16_t auth_key_len;
+ TRUNNEL_DYNARRAY_HEAD(, uint8_t) auth_key;
+ struct cell_extension_st *extensions;
+ TRUNNEL_DYNARRAY_HEAD(, uint8_t) encrypted;
+ uint8_t trunnel_error_code_;
+};
+#endif
+typedef struct hs_cell_introduce1_st hs_cell_introduce1_t;
+#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE_ACK)
+struct hs_cell_introduce_ack_st {
+ uint16_t status;
+ struct cell_extension_st *extensions;
+ uint8_t trunnel_error_code_;
+};
+#endif
+typedef struct hs_cell_introduce_ack_st hs_cell_introduce_ack_t;
+#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE_ENCRYPTED)
+struct hs_cell_introduce_encrypted_st {
+ uint8_t rend_cookie[TRUNNEL_REND_COOKIE_LEN];
+ struct cell_extension_st *extensions;
+ uint8_t onion_key_type;
+ uint16_t onion_key_len;
+ TRUNNEL_DYNARRAY_HEAD(, uint8_t) onion_key;
+ uint8_t nspec;
+ TRUNNEL_DYNARRAY_HEAD(, struct link_specifier_st *) nspecs;
+ TRUNNEL_DYNARRAY_HEAD(, uint8_t) pad;
+ uint8_t trunnel_error_code_;
+};
+#endif
+typedef struct hs_cell_introduce_encrypted_st hs_cell_introduce_encrypted_t;
+/** Return a newly allocated hs_cell_introduce1 with all elements set
+ * to zero.
+ */
+hs_cell_introduce1_t *hs_cell_introduce1_new(void);
+/** Release all storage held by the hs_cell_introduce1 in 'victim'.
+ * (Do nothing if 'victim' is NULL.)
+ */
+void hs_cell_introduce1_free(hs_cell_introduce1_t *victim);
+/** Try to parse a hs_cell_introduce1 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 hs_cell_introduce1_t. On failure, return -2 if the input
+ * appears truncated, and -1 if the input is otherwise invalid.
+ */
+ssize_t hs_cell_introduce1_parse(hs_cell_introduce1_t **output, const uint8_t *input, const size_t len_in);
+/** Return the number of bytes we expect to need to encode the
+ * hs_cell_introduce1 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 hs_cell_introduce1_encoded_len(const hs_cell_introduce1_t *obj);
+/** Try to encode the hs_cell_introduce1 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 hs_cell_introduce1_encode(uint8_t *output, size_t avail, const hs_cell_introduce1_t *input);
+/** Check whether the internal state of the hs_cell_introduce1 in
+ * 'obj' is consistent. Return NULL if it is, and a short message if
+ * it is not.
+ */
+const char *hs_cell_introduce1_check(const hs_cell_introduce1_t *obj);
+/** Clear any errors that were set on the object 'obj' by its setter
+ * functions. Return true iff errors were cleared.
+ */
+int hs_cell_introduce1_clear_errors(hs_cell_introduce1_t *obj);
+/** Return the (constant) length of the array holding the
+ * legacy_key_id field of the hs_cell_introduce1_t in 'inp'.
+ */
+size_t hs_cell_introduce1_getlen_legacy_key_id(const hs_cell_introduce1_t *inp);
+/** Return the element at position 'idx' of the fixed array field
+ * legacy_key_id of the hs_cell_introduce1_t in 'inp'.
+ */
+uint8_t hs_cell_introduce1_get_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx);
+/** As hs_cell_introduce1_get_legacy_key_id, but take and return a
+ * const pointer
+ */
+uint8_t hs_cell_introduce1_getconst_legacy_key_id(const hs_cell_introduce1_t *inp, size_t idx);
+/** Change the element at position 'idx' of the fixed array field
+ * legacy_key_id of the hs_cell_introduce1_t in 'inp', so that it will
+ * hold the value 'elt'.
+ */
+int hs_cell_introduce1_set_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt);
+/** Return a pointer to the TRUNNEL_SHA1_LEN-element array field
+ * legacy_key_id of 'inp'.
+ */
+uint8_t * hs_cell_introduce1_getarray_legacy_key_id(hs_cell_introduce1_t *inp);
+/** As hs_cell_introduce1_get_legacy_key_id, but take and return a
+ * const pointer
+ */
+const uint8_t * hs_cell_introduce1_getconstarray_legacy_key_id(const hs_cell_introduce1_t *inp);
+/** Return the value of the auth_key_type field of the
+ * hs_cell_introduce1_t in 'inp'
+ */
+uint8_t hs_cell_introduce1_get_auth_key_type(hs_cell_introduce1_t *inp);
+/** Set the value of the auth_key_type field of the
+ * hs_cell_introduce1_t in 'inp' to 'val'. Return 0 on success; return
+ * -1 and set the error code on 'inp' on failure.
+ */
+int hs_cell_introduce1_set_auth_key_type(hs_cell_introduce1_t *inp, uint8_t val);
+/** Return the value of the auth_key_len field of the
+ * hs_cell_introduce1_t in 'inp'
+ */
+uint16_t hs_cell_introduce1_get_auth_key_len(hs_cell_introduce1_t *inp);
+/** Set the value of the auth_key_len field of the
+ * hs_cell_introduce1_t in 'inp' to 'val'. Return 0 on success; return
+ * -1 and set the error code on 'inp' on failure.
+ */
+int hs_cell_introduce1_set_auth_key_len(hs_cell_introduce1_t *inp, uint16_t val);
+/** Return the length of the dynamic array holding the auth_key field
+ * of the hs_cell_introduce1_t in 'inp'.
+ */
+size_t hs_cell_introduce1_getlen_auth_key(const hs_cell_introduce1_t *inp);
+/** Return the element at position 'idx' of the dynamic array field
+ * auth_key of the hs_cell_introduce1_t in 'inp'.
+ */
+uint8_t hs_cell_introduce1_get_auth_key(hs_cell_introduce1_t *inp, size_t idx);
+/** As hs_cell_introduce1_get_auth_key, but take and return a const
+ * pointer
+ */
+uint8_t hs_cell_introduce1_getconst_auth_key(const hs_cell_introduce1_t *inp, size_t idx);
+/** Change the element at position 'idx' of the dynamic array field
+ * auth_key of the hs_cell_introduce1_t in 'inp', so that it will hold
+ * the value 'elt'.
+ */
+int hs_cell_introduce1_set_auth_key(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt);
+/** Append a new element 'elt' to the dynamic array field auth_key of
+ * the hs_cell_introduce1_t in 'inp'.
+ */
+int hs_cell_introduce1_add_auth_key(hs_cell_introduce1_t *inp, uint8_t elt);
+/** Return a pointer to the variable-length array field auth_key of
+ * 'inp'.
+ */
+uint8_t * hs_cell_introduce1_getarray_auth_key(hs_cell_introduce1_t *inp);
+/** As hs_cell_introduce1_get_auth_key, but take and return a const
+ * pointer
+ */
+const uint8_t * hs_cell_introduce1_getconstarray_auth_key(const hs_cell_introduce1_t *inp);
+/** Change the length of the variable-length array field auth_key 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 hs_cell_introduce1_setlen_auth_key(hs_cell_introduce1_t *inp, size_t newlen);
+/** Return the value of the extensions field of the
+ * hs_cell_introduce1_t in 'inp'
+ */
+struct cell_extension_st * hs_cell_introduce1_get_extensions(hs_cell_introduce1_t *inp);
+/** As hs_cell_introduce1_get_extensions, but take and return a const
+ * pointer
+ */
+const struct cell_extension_st * hs_cell_introduce1_getconst_extensions(const hs_cell_introduce1_t *inp);
+/** Set the value of the extensions field of the hs_cell_introduce1_t
+ * in 'inp' to 'val'. Free the old value if any. Steals the
+ * referenceto 'val'.Return 0 on success; return -1 and set the error
+ * code on 'inp' on failure.
+ */
+int hs_cell_introduce1_set_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val);
+/** As hs_cell_introduce1_set_extensions, but does not free the
+ * previous value.
+ */
+int hs_cell_introduce1_set0_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val);
+/** Return the length of the dynamic array holding the encrypted field
+ * of the hs_cell_introduce1_t in 'inp'.
+ */
+size_t hs_cell_introduce1_getlen_encrypted(const hs_cell_introduce1_t *inp);
+/** Return the element at position 'idx' of the dynamic array field
+ * encrypted of the hs_cell_introduce1_t in 'inp'.
+ */
+uint8_t hs_cell_introduce1_get_encrypted(hs_cell_introduce1_t *inp, size_t idx);
+/** As hs_cell_introduce1_get_encrypted, but take and return a const
+ * pointer
+ */
+uint8_t hs_cell_introduce1_getconst_encrypted(const hs_cell_introduce1_t *inp, size_t idx);
+/** Change the element at position 'idx' of the dynamic array field
+ * encrypted of the hs_cell_introduce1_t in 'inp', so that it will
+ * hold the value 'elt'.
+ */
+int hs_cell_introduce1_set_encrypted(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt);
+/** Append a new element 'elt' to the dynamic array field encrypted of
+ * the hs_cell_introduce1_t in 'inp'.
+ */
+int hs_cell_introduce1_add_encrypted(hs_cell_introduce1_t *inp, uint8_t elt);
+/** Return a pointer to the variable-length array field encrypted of
+ * 'inp'.
+ */
+uint8_t * hs_cell_introduce1_getarray_encrypted(hs_cell_introduce1_t *inp);
+/** As hs_cell_introduce1_get_encrypted, but take and return a const
+ * pointer
+ */
+const uint8_t * hs_cell_introduce1_getconstarray_encrypted(const hs_cell_introduce1_t *inp);
+/** Change the length of the variable-length array field encrypted 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 hs_cell_introduce1_setlen_encrypted(hs_cell_introduce1_t *inp, size_t newlen);
+/** Return a newly allocated hs_cell_introduce_ack with all elements
+ * set to zero.
+ */
+hs_cell_introduce_ack_t *hs_cell_introduce_ack_new(void);
+/** Release all storage held by the hs_cell_introduce_ack in 'victim'.
+ * (Do nothing if 'victim' is NULL.)
+ */
+void hs_cell_introduce_ack_free(hs_cell_introduce_ack_t *victim);
+/** Try to parse a hs_cell_introduce_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 hs_cell_introduce_ack_t. On failure, return -2 if the
+ * input appears truncated, and -1 if the input is otherwise invalid.
+ */
+ssize_t hs_cell_introduce_ack_parse(hs_cell_introduce_ack_t **output, const uint8_t *input, const size_t len_in);
+/** Return the number of bytes we expect to need to encode the
+ * hs_cell_introduce_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 hs_cell_introduce_ack_encoded_len(const hs_cell_introduce_ack_t *obj);
+/** Try to encode the hs_cell_introduce_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 hs_cell_introduce_ack_encode(uint8_t *output, size_t avail, const hs_cell_introduce_ack_t *input);
+/** Check whether the internal state of the hs_cell_introduce_ack in
+ * 'obj' is consistent. Return NULL if it is, and a short message if
+ * it is not.
+ */
+const char *hs_cell_introduce_ack_check(const hs_cell_introduce_ack_t *obj);
+/** Clear any errors that were set on the object 'obj' by its setter
+ * functions. Return true iff errors were cleared.
+ */
+int hs_cell_introduce_ack_clear_errors(hs_cell_introduce_ack_t *obj);
+/** Return the value of the status field of the
+ * hs_cell_introduce_ack_t in 'inp'
+ */
+uint16_t hs_cell_introduce_ack_get_status(hs_cell_introduce_ack_t *inp);
+/** Set the value of the status field of the hs_cell_introduce_ack_t
+ * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
+ * code on 'inp' on failure.
+ */
+int hs_cell_introduce_ack_set_status(hs_cell_introduce_ack_t *inp, uint16_t val);
+/** Return the value of the extensions field of the
+ * hs_cell_introduce_ack_t in 'inp'
+ */
+struct cell_extension_st * hs_cell_introduce_ack_get_extensions(hs_cell_introduce_ack_t *inp);
+/** As hs_cell_introduce_ack_get_extensions, but take and return a
+ * const pointer
+ */
+const struct cell_extension_st * hs_cell_introduce_ack_getconst_extensions(const hs_cell_introduce_ack_t *inp);
+/** Set the value of the extensions field of the
+ * hs_cell_introduce_ack_t in 'inp' to 'val'. Free the old value if
+ * any. Steals the referenceto 'val'.Return 0 on success; return -1
+ * and set the error code on 'inp' on failure.
+ */
+int hs_cell_introduce_ack_set_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val);
+/** As hs_cell_introduce_ack_set_extensions, but does not free the
+ * previous value.
+ */
+int hs_cell_introduce_ack_set0_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val);
+/** Return a newly allocated hs_cell_introduce_encrypted with all
+ * elements set to zero.
+ */
+hs_cell_introduce_encrypted_t *hs_cell_introduce_encrypted_new(void);
+/** Release all storage held by the hs_cell_introduce_encrypted in
+ * 'victim'. (Do nothing if 'victim' is NULL.)
+ */
+void hs_cell_introduce_encrypted_free(hs_cell_introduce_encrypted_t *victim);
+/** Try to parse a hs_cell_introduce_encrypted 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 hs_cell_introduce_encrypted_t. On failure, return
+ * -2 if the input appears truncated, and -1 if the input is otherwise
+ * invalid.
+ */
+ssize_t hs_cell_introduce_encrypted_parse(hs_cell_introduce_encrypted_t **output, const uint8_t *input, const size_t len_in);
+/** Return the number of bytes we expect to need to encode the
+ * hs_cell_introduce_encrypted 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 hs_cell_introduce_encrypted_encoded_len(const hs_cell_introduce_encrypted_t *obj);
+/** Try to encode the hs_cell_introduce_encrypted 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 hs_cell_introduce_encrypted_encode(uint8_t *output, size_t avail, const hs_cell_introduce_encrypted_t *input);
+/** Check whether the internal state of the
+ * hs_cell_introduce_encrypted in 'obj' is consistent. Return NULL if
+ * it is, and a short message if it is not.
+ */
+const char *hs_cell_introduce_encrypted_check(const hs_cell_introduce_encrypted_t *obj);
+/** Clear any errors that were set on the object 'obj' by its setter
+ * functions. Return true iff errors were cleared.
+ */
+int hs_cell_introduce_encrypted_clear_errors(hs_cell_introduce_encrypted_t *obj);
+/** Return the (constant) length of the array holding the rend_cookie
+ * field of the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+size_t hs_cell_introduce_encrypted_getlen_rend_cookie(const hs_cell_introduce_encrypted_t *inp);
+/** Return the element at position 'idx' of the fixed array field
+ * rend_cookie of the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+uint8_t hs_cell_introduce_encrypted_get_rend_cookie(hs_cell_introduce_encrypted_t *inp, size_t idx);
+/** As hs_cell_introduce_encrypted_get_rend_cookie, but take and
+ * return a const pointer
+ */
+uint8_t hs_cell_introduce_encrypted_getconst_rend_cookie(const hs_cell_introduce_encrypted_t *inp, size_t idx);
+/** Change the element at position 'idx' of the fixed array field
+ * rend_cookie of the hs_cell_introduce_encrypted_t in 'inp', so that
+ * it will hold the value 'elt'.
+ */
+int hs_cell_introduce_encrypted_set_rend_cookie(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt);
+/** Return a pointer to the TRUNNEL_REND_COOKIE_LEN-element array
+ * field rend_cookie of 'inp'.
+ */
+uint8_t * hs_cell_introduce_encrypted_getarray_rend_cookie(hs_cell_introduce_encrypted_t *inp);
+/** As hs_cell_introduce_encrypted_get_rend_cookie, but take and
+ * return a const pointer
+ */
+const uint8_t * hs_cell_introduce_encrypted_getconstarray_rend_cookie(const hs_cell_introduce_encrypted_t *inp);
+/** Return the value of the extensions field of the
+ * hs_cell_introduce_encrypted_t in 'inp'
+ */
+struct cell_extension_st * hs_cell_introduce_encrypted_get_extensions(hs_cell_introduce_encrypted_t *inp);
+/** As hs_cell_introduce_encrypted_get_extensions, but take and return
+ * a const pointer
+ */
+const struct cell_extension_st * hs_cell_introduce_encrypted_getconst_extensions(const hs_cell_introduce_encrypted_t *inp);
+/** Set the value of the extensions field of the
+ * hs_cell_introduce_encrypted_t in 'inp' to 'val'. Free the old value
+ * if any. Steals the referenceto 'val'.Return 0 on success; return -1
+ * and set the error code on 'inp' on failure.
+ */
+int hs_cell_introduce_encrypted_set_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val);
+/** As hs_cell_introduce_encrypted_set_extensions, but does not free
+ * the previous value.
+ */
+int hs_cell_introduce_encrypted_set0_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val);
+/** Return the value of the onion_key_type field of the
+ * hs_cell_introduce_encrypted_t in 'inp'
+ */
+uint8_t hs_cell_introduce_encrypted_get_onion_key_type(hs_cell_introduce_encrypted_t *inp);
+/** Set the value of the onion_key_type field of the
+ * hs_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on
+ * success; return -1 and set the error code on 'inp' on failure.
+ */
+int hs_cell_introduce_encrypted_set_onion_key_type(hs_cell_introduce_encrypted_t *inp, uint8_t val);
+/** Return the value of the onion_key_len field of the
+ * hs_cell_introduce_encrypted_t in 'inp'
+ */
+uint16_t hs_cell_introduce_encrypted_get_onion_key_len(hs_cell_introduce_encrypted_t *inp);
+/** Set the value of the onion_key_len field of the
+ * hs_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on
+ * success; return -1 and set the error code on 'inp' on failure.
+ */
+int hs_cell_introduce_encrypted_set_onion_key_len(hs_cell_introduce_encrypted_t *inp, uint16_t val);
+/** Return the length of the dynamic array holding the onion_key field
+ * of the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+size_t hs_cell_introduce_encrypted_getlen_onion_key(const hs_cell_introduce_encrypted_t *inp);
+/** Return the element at position 'idx' of the dynamic array field
+ * onion_key of the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+uint8_t hs_cell_introduce_encrypted_get_onion_key(hs_cell_introduce_encrypted_t *inp, size_t idx);
+/** As hs_cell_introduce_encrypted_get_onion_key, but take and return
+ * a const pointer
+ */
+uint8_t hs_cell_introduce_encrypted_getconst_onion_key(const hs_cell_introduce_encrypted_t *inp, size_t idx);
+/** Change the element at position 'idx' of the dynamic array field
+ * onion_key of the hs_cell_introduce_encrypted_t in 'inp', so that it
+ * will hold the value 'elt'.
+ */
+int hs_cell_introduce_encrypted_set_onion_key(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt);
+/** Append a new element 'elt' to the dynamic array field onion_key of
+ * the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+int hs_cell_introduce_encrypted_add_onion_key(hs_cell_introduce_encrypted_t *inp, uint8_t elt);
+/** Return a pointer to the variable-length array field onion_key of
+ * 'inp'.
+ */
+uint8_t * hs_cell_introduce_encrypted_getarray_onion_key(hs_cell_introduce_encrypted_t *inp);
+/** As hs_cell_introduce_encrypted_get_onion_key, but take and return
+ * a const pointer
+ */
+const uint8_t * hs_cell_introduce_encrypted_getconstarray_onion_key(const hs_cell_introduce_encrypted_t *inp);
+/** Change the length of the variable-length array field onion_key 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 hs_cell_introduce_encrypted_setlen_onion_key(hs_cell_introduce_encrypted_t *inp, size_t newlen);
+/** Return the value of the nspec field of the
+ * hs_cell_introduce_encrypted_t in 'inp'
+ */
+uint8_t hs_cell_introduce_encrypted_get_nspec(hs_cell_introduce_encrypted_t *inp);
+/** Set the value of the nspec field of the
+ * hs_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on
+ * success; return -1 and set the error code on 'inp' on failure.
+ */
+int hs_cell_introduce_encrypted_set_nspec(hs_cell_introduce_encrypted_t *inp, uint8_t val);
+/** Return the length of the dynamic array holding the nspecs field of
+ * the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+size_t hs_cell_introduce_encrypted_getlen_nspecs(const hs_cell_introduce_encrypted_t *inp);
+/** Return the element at position 'idx' of the dynamic array field
+ * nspecs of the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+struct link_specifier_st * hs_cell_introduce_encrypted_get_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx);
+/** As hs_cell_introduce_encrypted_get_nspecs, but take and return a
+ * const pointer
+ */
+ const struct link_specifier_st * hs_cell_introduce_encrypted_getconst_nspecs(const hs_cell_introduce_encrypted_t *inp, size_t idx);
+/** Change the element at position 'idx' of the dynamic array field
+ * nspecs of the hs_cell_introduce_encrypted_t in 'inp', so that it
+ * will hold the value 'elt'. Free the previous value, if any.
+ */
+int hs_cell_introduce_encrypted_set_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt);
+/** As hs_cell_introduce_encrypted_set_nspecs, but does not free the
+ * previous value.
+ */
+int hs_cell_introduce_encrypted_set0_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt);
+/** Append a new element 'elt' to the dynamic array field nspecs of
+ * the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+int hs_cell_introduce_encrypted_add_nspecs(hs_cell_introduce_encrypted_t *inp, struct link_specifier_st * elt);
+/** Return a pointer to the variable-length array field nspecs of
+ * 'inp'.
+ */
+struct link_specifier_st * * hs_cell_introduce_encrypted_getarray_nspecs(hs_cell_introduce_encrypted_t *inp);
+/** As hs_cell_introduce_encrypted_get_nspecs, but take and return a
+ * const pointer
+ */
+const struct link_specifier_st * const * hs_cell_introduce_encrypted_getconstarray_nspecs(const hs_cell_introduce_encrypted_t *inp);
+/** Change the length of the variable-length array field nspecs of
+ * 'inp' to 'newlen'.Fill extra elements with NULL; free removed
+ * elements. Return 0 on success; return -1 and set the error code on
+ * 'inp' on failure.
+ */
+int hs_cell_introduce_encrypted_setlen_nspecs(hs_cell_introduce_encrypted_t *inp, size_t newlen);
+/** Return the length of the dynamic array holding the pad field of
+ * the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+size_t hs_cell_introduce_encrypted_getlen_pad(const hs_cell_introduce_encrypted_t *inp);
+/** Return the element at position 'idx' of the dynamic array field
+ * pad of the hs_cell_introduce_encrypted_t in 'inp'.
+ */
+uint8_t hs_cell_introduce_encrypted_get_pad(hs_cell_introduce_encrypted_t *inp, size_t idx);
+/** As hs_cell_introduce_encrypted_get_pad, but take and return a
+ * const pointer
+ */
+uint8_t hs_cell_introduce_encrypted_getconst_pad(const hs_cell_introduce_encrypted_t *inp, size_t idx);
+/** Change the element at position 'idx' of the dynamic array field
+ * pad of the hs_cell_introduce_encrypted_t in 'inp', so that it will
+ * hold the value 'elt'.
+ */
+int hs_cell_introduce_encrypted_set_pad(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt);
+/** Append a new element 'elt' to the dynamic array field pad of the
+ * hs_cell_introduce_encrypted_t in 'inp'.
+ */
+int hs_cell_introduce_encrypted_add_pad(hs_cell_introduce_encrypted_t *inp, uint8_t elt);
+/** Return a pointer to the variable-length array field pad of 'inp'.
+ */
+uint8_t * hs_cell_introduce_encrypted_getarray_pad(hs_cell_introduce_encrypted_t *inp);
+/** As hs_cell_introduce_encrypted_get_pad, but take and return a
+ * const pointer
+ */
+const uint8_t * hs_cell_introduce_encrypted_getconstarray_pad(const hs_cell_introduce_encrypted_t *inp);
+/** Change the length of the variable-length array field pad 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 hs_cell_introduce_encrypted_setlen_pad(hs_cell_introduce_encrypted_t *inp, size_t newlen);
+
+
+#endif
diff --git a/src/trunnel/hs/cell_introduce1.trunnel b/src/trunnel/hs/cell_introduce1.trunnel
new file mode 100644
index 0000000..f777687
--- /dev/null
+++ b/src/trunnel/hs/cell_introduce1.trunnel
@@ -0,0 +1,60 @@
+/*
+ * This contains the definition of the INTRODUCE1 and INTRODUCE_ACK cell for
+ * onion service version 3 and onward. The following format is specified in
+ * proposal 224 section 3.2.
+ */
+
+/* From cell_common.trunnel. */
+extern struct cell_extension;
+/* From ed25519_cert.trunnel. */
+extern struct link_specifier;
+
+const TRUNNEL_SHA1_LEN = 20;
+const TRUNNEL_REND_COOKIE_LEN = 20;
+
+/* INTRODUCE1 payload. See details in section 3.2.1. */
+struct hs_cell_introduce1 {
+ /* Always zeroed. MUST be checked explicitely by the caller. */
+ u8 legacy_key_id[TRUNNEL_SHA1_LEN];
+
+ /* Authentication key material. */
+ u8 auth_key_type IN [0x00, 0x01, 0x02];
+ u16 auth_key_len;
+ u8 auth_key[auth_key_len];
+
+ /* Extension(s). Reserved fields. */
+ struct cell_extension extensions;
+
+ /* Variable length, up to the end of cell. */
+ u8 encrypted[];
+};
+
+/* INTRODUCE_ACK payload. See details in section 3.2.2. */
+struct hs_cell_introduce_ack {
+ /* Status of introduction. */
+ u16 status IN [0x0000, 0x0001, 0x0002];
+
+ /* Extension(s). Reserved fields. */
+ struct cell_extension extensions;
+};
+
+/* Encrypted section of the INTRODUCE1/INTRODUCE2 cell. */
+struct hs_cell_introduce_encrypted {
+ /* Rendezvous cookie. */
+ u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN];
+
+ /* Extension(s). Reserved fields. */
+ struct cell_extension extensions;
+
+ /* Onion key material. */
+ u8 onion_key_type IN [0x01];
+ u16 onion_key_len;
+ u8 onion_key[onion_key_len];
+
+ /* Link specifiers(s) */
+ u8 nspec;
+ struct link_specifier nspecs[nspec];
+
+ /* Optional padding. This might be empty or not. */
+ u8 pad[];
+};
diff --git a/src/trunnel/include.am b/src/trunnel/include.am
index d48971a..9b26d58 100644
--- a/src/trunnel/include.am
+++ b/src/trunnel/include.am
@@ -19,7 +19,8 @@ TRUNNELSOURCES = \
src/trunnel/link_handshake.c \
src/trunnel/pwbox.c \
src/trunnel/hs/cell_common.c \
- src/trunnel/hs/cell_establish_intro.c
+ src/trunnel/hs/cell_establish_intro.c \
+ src/trunnel/hs/cell_introduce1.c
TRUNNELHEADERS = \
src/ext/trunnel/trunnel.h \
@@ -29,7 +30,8 @@ TRUNNELHEADERS = \
src/trunnel/link_handshake.h \
src/trunnel/pwbox.h \
src/trunnel/hs/cell_common.h \
- src/trunnel/hs/cell_establish_intro.h
+ src/trunnel/hs/cell_establish_intro.h \
+ src/trunnel/hs/cell_introduce1.h
src_trunnel_libor_trunnel_a_SOURCES = $(TRUNNELSOURCES)
src_trunnel_libor_trunnel_a_CPPFLAGS = -DTRUNNEL_LOCAL_H $(AM_CPPFLAGS)
1
0
commit 1d76d389033e09645ff746c2d2c449ea5af098a3
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Mon Oct 31 16:25:34 2016 -0400
Re-run trunnel.
---
src/trunnel/hs/cell_introduce1.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/trunnel/hs/cell_introduce1.c b/src/trunnel/hs/cell_introduce1.c
index d327ea8..51f5676 100644
--- a/src/trunnel/hs/cell_introduce1.c
+++ b/src/trunnel/hs/cell_introduce1.c
@@ -733,6 +733,7 @@ hs_cell_introduce_encrypted_new(void)
hs_cell_introduce_encrypted_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce_encrypted_t));
if (NULL == val)
return NULL;
+ val->onion_key_type = 1;
return val;
}
@@ -836,6 +837,10 @@ hs_cell_introduce_encrypted_get_onion_key_type(hs_cell_introduce_encrypted_t *in
int
hs_cell_introduce_encrypted_set_onion_key_type(hs_cell_introduce_encrypted_t *inp, uint8_t val)
{
+ if (! ((val == 1))) {
+ TRUNNEL_SET_ERROR_CODE(inp);
+ return -1;
+ }
inp->onion_key_type = val;
return 0;
}
@@ -1074,6 +1079,8 @@ hs_cell_introduce_encrypted_check(const hs_cell_introduce_encrypted_t *obj)
if (NULL != (msg = cell_extension_check(obj->extensions)))
return msg;
}
+ if (! (obj->onion_key_type == 1))
+ return "Integer out of bounds";
if (TRUNNEL_DYNARRAY_LEN(&obj->onion_key) != obj->onion_key_len)
return "Length mismatch for onion_key";
{
@@ -1105,7 +1112,7 @@ hs_cell_introduce_encrypted_encoded_len(const hs_cell_introduce_encrypted_t *obj
/* Length of struct cell_extension extensions */
result += cell_extension_encoded_len(obj->extensions);
- /* Length of u8 onion_key_type */
+ /* Length of u8 onion_key_type IN [1] */
result += 1;
/* Length of u16 onion_key_len */
@@ -1169,7 +1176,7 @@ hs_cell_introduce_encrypted_encode(uint8_t *output, const size_t avail, const hs
goto fail; /* XXXXXXX !*/
written += result; ptr += result;
- /* Encode u8 onion_key_type */
+ /* Encode u8 onion_key_type IN [1] */
trunnel_assert(written <= avail);
if (avail - written < 1)
goto truncated;
@@ -1273,10 +1280,12 @@ hs_cell_introduce_encrypted_parse_into(hs_cell_introduce_encrypted_t *obj, const
trunnel_assert((size_t)result <= remaining);
remaining -= result; ptr += result;
- /* Parse u8 onion_key_type */
+ /* Parse u8 onion_key_type IN [1] */
CHECK_REMAINING(1, truncated);
obj->onion_key_type = (trunnel_get_uint8(ptr));
remaining -= 1; ptr += 1;
+ if (! (obj->onion_key_type == 1))
+ goto fail;
/* Parse u16 onion_key_len */
CHECK_REMAINING(2, truncated);
@@ -1327,6 +1336,9 @@ hs_cell_introduce_encrypted_parse_into(hs_cell_introduce_encrypted_t *obj, const
return result;
trunnel_alloc_failed:
return -1;
+ fail:
+ result = -1;
+ return result;
}
ssize_t
1
0
commit 0ba3444b4a9d408573a442b32be794a78b9250b5
Author: David Goulet <dgoulet(a)torproject.org>
Date: Thu Sep 1 10:07:41 2016 -0400
Make trunnel find files recursively
Signed-off-by: David Goulet <dgoulet(a)torproject.org>
---
scripts/codegen/run_trunnel.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/scripts/codegen/run_trunnel.sh b/scripts/codegen/run_trunnel.sh
index d266993..c574ea8 100755
--- a/scripts/codegen/run_trunnel.sh
+++ b/scripts/codegen/run_trunnel.sh
@@ -5,7 +5,11 @@ if test "x$TRUNNEL_PATH" != "x"; then
export PYTHONPATH
fi
-python -m trunnel --require-version=1.4 ./src/trunnel/*.trunnel
+# Get all .trunnel files recursively from that directory so we can support
+# multiple sub-directories.
+for file in `find ./src/trunnel/ -name '*.trunnel'`; do
+ python -m trunnel --require-version=1.4 $file
+done
python -m trunnel --require-version=1.4 --write-c-files --target-dir=./src/ext/trunnel/
1
0

[tor/master] Actually free the worker_state_t object when we do an update with it
by nickm@torproject.org 31 Oct '16
by nickm@torproject.org 31 Oct '16
31 Oct '16
commit 24b7b922ae9adc814890feae661ad64f474307f3
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Mon Oct 31 14:36:15 2016 -0400
Actually free the worker_state_t object when we do an update with it
Previously we freed the old "keys" object, but leaked the
worker_state_t that we had taken it from.
Fixes bug 20401; bugfix on 0.2.6.3-alpha.
---
changes/bug20401 | 4 ++++
src/or/cpuworker.c | 1 +
2 files changed, 5 insertions(+)
diff --git a/changes/bug20401 b/changes/bug20401
new file mode 100644
index 0000000..85ab3c7
--- /dev/null
+++ b/changes/bug20401
@@ -0,0 +1,4 @@
+ o Minor bugfixes (relay):
+ - Avoid a small memory leak when informing worker threads about rotated
+ onion keys. Fixes bug 20401; bugfix on 0.2.6.3-alpha.
+
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 26bc54b..fd6de6e 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -168,6 +168,7 @@ update_state_threadfn(void *state_, void *work_)
server_onion_keys_free(state->onion_keys);
state->onion_keys = update->onion_keys;
update->onion_keys = NULL;
+ worker_state_free(update);
++state->generation;
return WQ_RPL_REPLY;
}
1
0
commit 59a78187cdf9c48f492e92c3a33ce17b75f7472d
Merge: cac495f 24b7b92
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Mon Oct 31 15:20:45 2016 -0400
Merge branch 'maint-0.2.9'
changes/bug20401 | 4 ++++
src/or/cpuworker.c | 1 +
2 files changed, 5 insertions(+)
1
0

[tor/maint-0.2.9] Actually free the worker_state_t object when we do an update with it
by nickm@torproject.org 31 Oct '16
by nickm@torproject.org 31 Oct '16
31 Oct '16
commit 24b7b922ae9adc814890feae661ad64f474307f3
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Mon Oct 31 14:36:15 2016 -0400
Actually free the worker_state_t object when we do an update with it
Previously we freed the old "keys" object, but leaked the
worker_state_t that we had taken it from.
Fixes bug 20401; bugfix on 0.2.6.3-alpha.
---
changes/bug20401 | 4 ++++
src/or/cpuworker.c | 1 +
2 files changed, 5 insertions(+)
diff --git a/changes/bug20401 b/changes/bug20401
new file mode 100644
index 0000000..85ab3c7
--- /dev/null
+++ b/changes/bug20401
@@ -0,0 +1,4 @@
+ o Minor bugfixes (relay):
+ - Avoid a small memory leak when informing worker threads about rotated
+ onion keys. Fixes bug 20401; bugfix on 0.2.6.3-alpha.
+
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 26bc54b..fd6de6e 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -168,6 +168,7 @@ update_state_threadfn(void *state_, void *work_)
server_onion_keys_free(state->onion_keys);
state->onion_keys = update->onion_keys;
update->onion_keys = NULL;
+ worker_state_free(update);
++state->generation;
return WQ_RPL_REPLY;
}
1
0
commit dc9b874bdc8bcf5556ba8a03e98beb50221fae41
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Oct 29 23:00:16 2016 -0700
Occasional failure of cwd() on OSX
Interesting. Teor ran into an issue due to lsof returning three (rather than
the expected two) values on OSX...
https://trac.torproject.org/projects/tor/ticket/20477
Not quite sure why but meh, easy to fix.
---
stem/util/system.py | 4 ++--
test/unit/util/system.py | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/stem/util/system.py b/stem/util/system.py
index 7798048..600ab49 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -737,8 +737,8 @@ def cwd(pid):
if is_available('lsof'):
results = call(GET_CWD_LSOF % pid, [])
- if len(results) == 2 and results[1].startswith('n/'):
- lsof_result = results[1][1:].strip()
+ if len(results) >= 2 and results[-1].startswith('n/'):
+ lsof_result = results[-1][1:].strip()
# If we lack read permissions for the cwd then it returns...
# p2683
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index 0bb59f3..509b9cb 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -362,6 +362,7 @@ class TestSystem(unittest.TestCase):
responses = {
'75717': ['p75717', 'n/Users/atagar/tor/src/or'],
+ '75717': ['p75717', 'fcwd', 'n/Users/atagar/tor/src/or'],
'1234': ['malformed output'],
'7878': [],
}
1
0

29 Oct '16
commit aec24a2c3ca5bf74dec3b1390e4dd69a93972028
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Oct 29 15:39:23 2016 -0700
Correct docs about router status entry bandwidths
Good point from Tom that our docs around this are wrong...
https://trac.torproject.org/projects/tor/ticket/20493
https://gitweb.torproject.org/torspec.git/tree/dir-spec.txt#n2012
---
stem/descriptor/router_status_entry.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index cc6c659..bf146a9 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -550,11 +550,11 @@ class RouterStatusEntryV3(RouterStatusEntry):
:var str identifier: base64 encoded identity digest
:var str digest: **\*** router's upper-case hex digest
- :var int bandwidth: bandwidth claimed by the relay (in kb/s)
- :var int measured: bandwidth measured to be available by the relay, this is a
+ :var int bandwidth: bandwidth measured to be available by the relay, this is a
unit-less heuristic generated by the Bandwidth authoritites to weight relay
selection
- :var bool is_unmeasured: bandwidth measurement isn't based on three or more
+ :var int measured: *bandwidth* vote provided by a bandwidth authority
+ :var bool is_unmeasured: *bandwidth* measurement isn't based on three or more
measurements
:var list unrecognized_bandwidth_entries: **\*** bandwidth weighting
information that isn't yet recognized
1
0
commit 4e496fe47aed4ce39a9f0d455c87104a2a8a3f89
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Oct 29 15:06:48 2016 -0700
Make module_exists() private
Lets not vend this helper to Stem users just yet. Also fixing pycodestyle
regressions that were introduced as part of the prior changes. :P
---
stem/util/test_tools.py | 45 +++++++++++++++++++++++----------------------
test/util.py | 16 ++--------------
2 files changed, 25 insertions(+), 36 deletions(-)
diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py
index 450e18a..82c0d0b 100644
--- a/stem/util/test_tools.py
+++ b/stem/util/test_tools.py
@@ -86,18 +86,6 @@ def clean_orphaned_pyc(paths):
return orphaned_pyc
-def module_exists(module_name):
- """
- Checks if a module exists
-
- :returns: **True** if module exists and **False** otherwise
- """
- try:
- mod = __import__(module_name)
- except ImportError:
- return False
- else:
- return True
def is_pyflakes_available():
"""
@@ -106,12 +94,7 @@ def is_pyflakes_available():
:returns: **True** if we can use pyflakes and **False** otherwise
"""
- try:
- import pyflakes.api
- import pyflakes.reporter
- return True
- except ImportError:
- return False
+ return _module_exists('pyflakes.api') and _module_exists('pyflakes.reporter')
def is_pycodestyle_available():
@@ -121,9 +104,9 @@ def is_pycodestyle_available():
:returns: **True** if we can use pycodestyle and **False** otherwise
"""
- if module_exists('pycodestyle'):
+ if _module_exists('pycodestyle'):
import pycodestyle
- elif module_exists('pep8'):
+ elif _module_exists('pep8'):
import pep8 as pycodestyle
else:
return False
@@ -133,6 +116,7 @@ def is_pycodestyle_available():
else:
return True
+
def stylistic_issues(paths, check_newlines = False, check_exception_keyword = False, prefer_single_quotes = False):
"""
Checks for stylistic issues that are an issue according to the parts of
@@ -213,9 +197,9 @@ def stylistic_issues(paths, check_newlines = False, check_exception_keyword = Fa
return False
if is_pycodestyle_available():
- if module_exists('pycodestyle'):
+ if _module_exists('pycodestyle'):
import pycodestyle
- elif module_exists('pep8'):
+ elif _module_exists('pep8'):
import pep8 as pycodestyle
class StyleReport(pycodestyle.BaseReport):
@@ -351,6 +335,23 @@ def pyflakes_issues(paths):
return issues
+def _module_exists(module_name):
+ """
+ Checks if a module exists.
+
+ :param str module_name: module to check existance of
+
+ :returns: **True** if module exists and **False** otherwise
+ """
+
+ try:
+ __import__(module_name)
+ except ImportError:
+ return False
+ else:
+ return True
+
+
def _python_files(paths):
for path in paths:
for file_path in stem.util.system.files_with_suffix(path, '.py'):
diff --git a/test/util.py b/test/util.py
index 6812898..1cb59eb 100644
--- a/test/util.py
+++ b/test/util.py
@@ -84,18 +84,6 @@ STEM_BASE = os.path.sep.join(__file__.split(os.path.sep)[:-2])
NEW_CAPABILITIES = []
-def module_exists(module_name):
- """
- Checks if a module exists
-
- :returns: **True** if module exists and **False** otherwise
- """
- try:
- mod = __import__(module_name)
- except ImportError:
- return False
- else:
- return True
def get_unit_tests(module_prefix = None):
"""
@@ -239,9 +227,9 @@ def check_pyflakes_version():
def check_pycodestyle_version():
- if module_exists('pycodestyle'):
+ if stem.util.test_tools._module_exists('pycodestyle'):
import pycodestyle
- elif module_exists('pep8'):
+ elif stem.util.test_tools._module_exists('pep8'):
import pep8 as pycodestyle
else:
return 'missing'
1
0

[stem/master] Switch to 'import pycodestyle' and add fallback mechanism
by atagar@torproject.org 29 Oct '16
by atagar@torproject.org 29 Oct '16
29 Oct '16
commit 5d7f24c5dd6b34dfaccd534707d018e2889bb31e
Author: Neel Chauhan <neel(a)neelc.org>
Date: Wed Oct 26 20:35:15 2016 -0400
Switch to 'import pycodestyle' and add fallback mechanism
---
stem/util/test_tools.py | 74 ++++++++++++++++++++++++++++++-------------------
1 file changed, 45 insertions(+), 29 deletions(-)
diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py
index 9a9f7f6..450e18a 100644
--- a/stem/util/test_tools.py
+++ b/stem/util/test_tools.py
@@ -11,9 +11,9 @@ Helper functions for testing.
clean_orphaned_pyc - delete *.pyc files without corresponding *.py
is_pyflakes_available - checks if pyflakes is available
- is_pep8_available - checks if pep8 is available
+ is_pycodestyle_available - checks if pycodestyle is available
- stylistic_issues - checks for PEP8 and other stylistic issues
+ stylistic_issues - checks for pycodestyle and other stylistic issues
pyflakes_issues - static checks for problems via pyflakes
"""
@@ -26,7 +26,7 @@ import stem.util.conf
import stem.util.system
CONFIG = stem.util.conf.config_dict('test', {
- 'pep8.ignore': [],
+ 'pycodestyle.ignore': [],
'pyflakes.ignore': [],
'exclude_paths': [],
})
@@ -34,7 +34,7 @@ CONFIG = stem.util.conf.config_dict('test', {
class Issue(collections.namedtuple('Issue', ['line_number', 'message', 'line'])):
"""
- Issue encountered by pyflakes or pep8.
+ Issue encountered by pyflakes or pycodestyle.
:var int line_number: line number the issue occured on
:var str message: description of the issue
@@ -86,6 +86,18 @@ def clean_orphaned_pyc(paths):
return orphaned_pyc
+def module_exists(module_name):
+ """
+ Checks if a module exists
+
+ :returns: **True** if module exists and **False** otherwise
+ """
+ try:
+ mod = __import__(module_name)
+ except ImportError:
+ return False
+ else:
+ return True
def is_pyflakes_available():
"""
@@ -102,44 +114,45 @@ def is_pyflakes_available():
return False
-def is_pep8_available():
+def is_pycodestyle_available():
"""
- Checks if pep8 is availalbe.
+ Checks if pycodestyle is availalbe.
- :returns: **True** if we can use pep8 and **False** otherwise
+ :returns: **True** if we can use pycodestyle and **False** otherwise
"""
- try:
- import pep8
-
- if not hasattr(pep8, 'BaseReport'):
- raise ImportError()
-
- return True
- except ImportError:
+ if module_exists('pycodestyle'):
+ import pycodestyle
+ elif module_exists('pep8'):
+ import pep8 as pycodestyle
+ else:
return False
+ if not hasattr(pycodestyle, 'BaseReport'):
+ return False
+ else:
+ return True
def stylistic_issues(paths, check_newlines = False, check_exception_keyword = False, prefer_single_quotes = False):
"""
- Checks for stylistic issues that are an issue according to the parts of PEP8
- we conform to. You can suppress PEP8 issues by making a 'test' configuration
- that sets 'pep8.ignore'.
+ Checks for stylistic issues that are an issue according to the parts of
+ pycodestyle we conform to. You can suppress pycodestyle issues by making a
+ 'test' configuration that sets 'pycodestyle.ignore'.
For example, with a 'test/settings.cfg' of...
::
- # PEP8 compliance issues that we're ignoreing...
+ # pycodestyle compliance issues that we're ignoreing...
#
# * E111 and E121 four space indentations
# * E501 line is over 79 characters
- pep8.ignore E111
- pep8.ignore E121
- pep8.ignore E501
+ pycodestyle.ignore E111
+ pycodestyle.ignore E121
+ pycodestyle.ignore E501
- pep8.ignore run_tests.py => E402: import stem.util.enum
+ pycodestyle.ignore run_tests.py => E402: import stem.util.enum
... you can then run tests with...
@@ -182,7 +195,7 @@ def stylistic_issues(paths, check_newlines = False, check_exception_keyword = Fa
ignore_rules = []
ignore_for_file = []
- for rule in CONFIG['pep8.ignore']:
+ for rule in CONFIG['pycodestyle.ignore']:
if '=>' in rule:
path, rule_entry = rule.split('=>', 1)
@@ -199,10 +212,13 @@ def stylistic_issues(paths, check_newlines = False, check_exception_keyword = Fa
return False
- if is_pep8_available():
- import pep8
+ if is_pycodestyle_available():
+ if module_exists('pycodestyle'):
+ import pycodestyle
+ elif module_exists('pep8'):
+ import pep8 as pycodestyle
- class StyleReport(pep8.BaseReport):
+ class StyleReport(pycodestyle.BaseReport):
def __init__(self, options):
super(StyleReport, self).__init__(options)
@@ -215,7 +231,7 @@ def stylistic_issues(paths, check_newlines = False, check_exception_keyword = Fa
if not is_ignored(self.filename, code, line):
issues.setdefault(self.filename, []).append(Issue(line_number, text, line))
- style_checker = pep8.StyleGuide(ignore = ignore_rules, reporter = StyleReport)
+ style_checker = pycodestyle.StyleGuide(ignore = ignore_rules, reporter = StyleReport)
style_checker.check_files(list(_python_files(paths)))
if check_newlines or check_exception_keyword:
@@ -269,7 +285,7 @@ def pyflakes_issues(paths):
::
pyflakes.ignore stem/util/test_tools.py => 'pyflakes' imported but unused
- pyflakes.ignore stem/util/test_tools.py => 'pep8' imported but unused
+ pyflakes.ignore stem/util/test_tools.py => 'pycodestyle' imported but unused
If a 'exclude_paths' was set in our test config then we exclude any absolute
paths matching those regexes.
1
0