1 /* congestion_control.c -- generated by Trunnel v1.5.3.
2 * https://gitweb.torproject.org/trunnel.git
3 * You probably shouldn't edit this file.
6 #include "trunnel-impl.h"
8 #include "congestion_control.h"
10 #define TRUNNEL_SET_ERROR_CODE(obj) \
12 (obj)->trunnel_error_code_ = 1; \
15 #if defined(__COVERITY__) || defined(__clang_analyzer__)
16 /* If we're running a static analysis tool, we don't want it to complain
17 * that some of our remaining-bytes checks are dead-code. */
18 int congestioncontrol_deadcode_dummy__
= 0;
19 #define OR_DEADCODE_DUMMY || congestioncontrol_deadcode_dummy__
21 #define OR_DEADCODE_DUMMY
24 #define CHECK_REMAINING(nbytes, label) \
26 if (remaining < (nbytes) OR_DEADCODE_DUMMY) { \
31 trn_extension_field_cc_t
*
32 trn_extension_field_cc_new(void)
34 trn_extension_field_cc_t
*val
= trunnel_calloc(1, sizeof(trn_extension_field_cc_t
));
40 /** Release all storage held inside 'obj', but do not free 'obj'.
43 trn_extension_field_cc_clear(trn_extension_field_cc_t
*obj
)
49 trn_extension_field_cc_free(trn_extension_field_cc_t
*obj
)
53 trn_extension_field_cc_clear(obj
);
54 trunnel_memwipe(obj
, sizeof(trn_extension_field_cc_t
));
59 trn_extension_field_cc_get_sendme_inc(const trn_extension_field_cc_t
*inp
)
61 return inp
->sendme_inc
;
64 trn_extension_field_cc_set_sendme_inc(trn_extension_field_cc_t
*inp
, uint8_t val
)
66 inp
->sendme_inc
= val
;
70 trn_extension_field_cc_check(const trn_extension_field_cc_t
*obj
)
73 return "Object was NULL";
74 if (obj
->trunnel_error_code_
)
75 return "A set function failed on this object";
80 trn_extension_field_cc_encoded_len(const trn_extension_field_cc_t
*obj
)
84 if (NULL
!= trn_extension_field_cc_check(obj
))
88 /* Length of u8 sendme_inc */
93 trn_extension_field_cc_clear_errors(trn_extension_field_cc_t
*obj
)
95 int r
= obj
->trunnel_error_code_
;
96 obj
->trunnel_error_code_
= 0;
100 trn_extension_field_cc_encode(uint8_t *output
, const size_t avail
, const trn_extension_field_cc_t
*obj
)
104 uint8_t *ptr
= output
;
106 #ifdef TRUNNEL_CHECK_ENCODED_LEN
107 const ssize_t encoded_len
= trn_extension_field_cc_encoded_len(obj
);
110 if (NULL
!= (msg
= trn_extension_field_cc_check(obj
)))
113 #ifdef TRUNNEL_CHECK_ENCODED_LEN
114 trunnel_assert(encoded_len
>= 0);
117 /* Encode u8 sendme_inc */
118 trunnel_assert(written
<= avail
);
119 if (avail
- written
< 1)
121 trunnel_set_uint8(ptr
, (obj
->sendme_inc
));
122 written
+= 1; ptr
+= 1;
125 trunnel_assert(ptr
== output
+ written
);
126 #ifdef TRUNNEL_CHECK_ENCODED_LEN
128 trunnel_assert(encoded_len
>= 0);
129 trunnel_assert((size_t)encoded_len
== written
);
144 trunnel_assert(result
< 0);
148 /** As trn_extension_field_cc_parse(), but do not allocate the output
152 trn_extension_field_cc_parse_into(trn_extension_field_cc_t
*obj
, const uint8_t *input
, const size_t len_in
)
154 const uint8_t *ptr
= input
;
155 size_t remaining
= len_in
;
159 /* Parse u8 sendme_inc */
160 CHECK_REMAINING(1, truncated
);
161 obj
->sendme_inc
= (trunnel_get_uint8(ptr
));
162 remaining
-= 1; ptr
+= 1;
163 trunnel_assert(ptr
+ remaining
== input
+ len_in
);
164 return len_in
- remaining
;
171 trn_extension_field_cc_parse(trn_extension_field_cc_t
**output
, const uint8_t *input
, const size_t len_in
)
174 *output
= trn_extension_field_cc_new();
177 result
= trn_extension_field_cc_parse_into(*output
, input
, len_in
);
179 trn_extension_field_cc_free(*output
);