circpad_negotiation.h (9774B)
1 /* circpad_negotiation.h -- generated by Trunnel v1.5.3. 2 * https://gitweb.torproject.org/trunnel.git 3 * You probably shouldn't edit this file. 4 */ 5 #ifndef TRUNNEL_CIRCPAD_NEGOTIATION_H 6 #define TRUNNEL_CIRCPAD_NEGOTIATION_H 7 8 #include <stdint.h> 9 #include "trunnel.h" 10 11 #define CIRCPAD_COMMAND_STOP 1 12 #define CIRCPAD_COMMAND_START 2 13 #define CIRCPAD_RESPONSE_OK 1 14 #define CIRCPAD_RESPONSE_ERR 2 15 #define CIRCPAD_MACHINE_CIRC_SETUP 1 16 /** 17 * This command tells the relay to alter its min and max netflow 18 * timeout range values, and send padding at that rate (resuming 19 * if stopped). */ 20 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CIRCPAD_NEGOTIATE) 21 struct circpad_negotiate_st { 22 uint8_t version; 23 uint8_t command; 24 /** Machine type is left unbounded because we can specify 25 * new machines in the consensus */ 26 uint8_t machine_type; 27 /** If true, send a relay_drop reply.. */ 28 uint8_t echo_request; 29 uint32_t machine_ctr; 30 uint8_t trunnel_error_code_; 31 }; 32 #endif 33 typedef struct circpad_negotiate_st circpad_negotiate_t; 34 /** 35 * This command tells the relay to alter its min and max netflow 36 * timeout range values, and send padding at that rate (resuming 37 * if stopped). */ 38 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CIRCPAD_NEGOTIATED) 39 struct circpad_negotiated_st { 40 uint8_t version; 41 uint8_t command; 42 uint8_t response; 43 /** Machine type is left unbounded because we can specify 44 * new machines in the consensus */ 45 uint8_t machine_type; 46 /** 47 * This field is used for shutdown synchronization. It is OK if 48 * it wraps, because all we need to do is make sure the STOP 49 * command is actually for the currently active machine. 50 * For backward-compatibility, though, 0 has special meaning 51 * (it means match any machine). 52 */ 53 uint32_t machine_ctr; 54 uint8_t trunnel_error_code_; 55 }; 56 #endif 57 typedef struct circpad_negotiated_st circpad_negotiated_t; 58 /** Return a newly allocated circpad_negotiate with all elements set 59 * to zero. 60 */ 61 circpad_negotiate_t *circpad_negotiate_new(void); 62 /** Release all storage held by the circpad_negotiate in 'victim'. (Do 63 * nothing if 'victim' is NULL.) 64 */ 65 void circpad_negotiate_free(circpad_negotiate_t *victim); 66 /** Try to parse a circpad_negotiate from the buffer in 'input', using 67 * up to 'len_in' bytes from the input buffer. On success, return the 68 * number of bytes consumed and set *output to the newly allocated 69 * circpad_negotiate_t. On failure, return -2 if the input appears 70 * truncated, and -1 if the input is otherwise invalid. 71 */ 72 ssize_t circpad_negotiate_parse(circpad_negotiate_t **output, const uint8_t *input, const size_t len_in); 73 /** Return the number of bytes we expect to need to encode the 74 * circpad_negotiate in 'obj'. On failure, return a negative value. 75 * Note that this value may be an overestimate, and can even be an 76 * underestimate for certain unencodeable objects. 77 */ 78 ssize_t circpad_negotiate_encoded_len(const circpad_negotiate_t *obj); 79 /** Try to encode the circpad_negotiate from 'input' into the buffer 80 * at 'output', using up to 'avail' bytes of the output buffer. On 81 * success, return the number of bytes used. On failure, return -2 if 82 * the buffer was not long enough, and -1 if the input was invalid. 83 */ 84 ssize_t circpad_negotiate_encode(uint8_t *output, size_t avail, const circpad_negotiate_t *input); 85 /** Check whether the internal state of the circpad_negotiate in 'obj' 86 * is consistent. Return NULL if it is, and a short message if it is 87 * not. 88 */ 89 const char *circpad_negotiate_check(const circpad_negotiate_t *obj); 90 /** Clear any errors that were set on the object 'obj' by its setter 91 * functions. Return true iff errors were cleared. 92 */ 93 int circpad_negotiate_clear_errors(circpad_negotiate_t *obj); 94 /** Return the value of the version field of the circpad_negotiate_t 95 * in 'inp' 96 */ 97 uint8_t circpad_negotiate_get_version(const circpad_negotiate_t *inp); 98 /** Set the value of the version field of the circpad_negotiate_t in 99 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 100 * code on 'inp' on failure. 101 */ 102 int circpad_negotiate_set_version(circpad_negotiate_t *inp, uint8_t val); 103 /** Return the value of the command field of the circpad_negotiate_t 104 * in 'inp' 105 */ 106 uint8_t circpad_negotiate_get_command(const circpad_negotiate_t *inp); 107 /** Set the value of the command field of the circpad_negotiate_t in 108 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 109 * code on 'inp' on failure. 110 */ 111 int circpad_negotiate_set_command(circpad_negotiate_t *inp, uint8_t val); 112 /** Return the value of the machine_type field of the 113 * circpad_negotiate_t in 'inp' 114 */ 115 uint8_t circpad_negotiate_get_machine_type(const circpad_negotiate_t *inp); 116 /** Set the value of the machine_type field of the circpad_negotiate_t 117 * in 'inp' to 'val'. Return 0 on success; return -1 and set the error 118 * code on 'inp' on failure. 119 */ 120 int circpad_negotiate_set_machine_type(circpad_negotiate_t *inp, uint8_t val); 121 /** Return the value of the echo_request field of the 122 * circpad_negotiate_t in 'inp' 123 */ 124 uint8_t circpad_negotiate_get_echo_request(const circpad_negotiate_t *inp); 125 /** Set the value of the echo_request field of the circpad_negotiate_t 126 * in 'inp' to 'val'. Return 0 on success; return -1 and set the error 127 * code on 'inp' on failure. 128 */ 129 int circpad_negotiate_set_echo_request(circpad_negotiate_t *inp, uint8_t val); 130 /** Return the value of the machine_ctr field of the 131 * circpad_negotiate_t in 'inp' 132 */ 133 uint32_t circpad_negotiate_get_machine_ctr(const circpad_negotiate_t *inp); 134 /** Set the value of the machine_ctr field of the circpad_negotiate_t 135 * in 'inp' to 'val'. Return 0 on success; return -1 and set the error 136 * code on 'inp' on failure. 137 */ 138 int circpad_negotiate_set_machine_ctr(circpad_negotiate_t *inp, uint32_t val); 139 /** Return a newly allocated circpad_negotiated with all elements set 140 * to zero. 141 */ 142 circpad_negotiated_t *circpad_negotiated_new(void); 143 /** Release all storage held by the circpad_negotiated in 'victim'. 144 * (Do nothing if 'victim' is NULL.) 145 */ 146 void circpad_negotiated_free(circpad_negotiated_t *victim); 147 /** Try to parse a circpad_negotiated from the buffer in 'input', 148 * using up to 'len_in' bytes from the input buffer. On success, 149 * return the number of bytes consumed and set *output to the newly 150 * allocated circpad_negotiated_t. On failure, return -2 if the input 151 * appears truncated, and -1 if the input is otherwise invalid. 152 */ 153 ssize_t circpad_negotiated_parse(circpad_negotiated_t **output, const uint8_t *input, const size_t len_in); 154 /** Return the number of bytes we expect to need to encode the 155 * circpad_negotiated in 'obj'. On failure, return a negative value. 156 * Note that this value may be an overestimate, and can even be an 157 * underestimate for certain unencodeable objects. 158 */ 159 ssize_t circpad_negotiated_encoded_len(const circpad_negotiated_t *obj); 160 /** Try to encode the circpad_negotiated from 'input' into the buffer 161 * at 'output', using up to 'avail' bytes of the output buffer. On 162 * success, return the number of bytes used. On failure, return -2 if 163 * the buffer was not long enough, and -1 if the input was invalid. 164 */ 165 ssize_t circpad_negotiated_encode(uint8_t *output, size_t avail, const circpad_negotiated_t *input); 166 /** Check whether the internal state of the circpad_negotiated in 167 * 'obj' is consistent. Return NULL if it is, and a short message if 168 * it is not. 169 */ 170 const char *circpad_negotiated_check(const circpad_negotiated_t *obj); 171 /** Clear any errors that were set on the object 'obj' by its setter 172 * functions. Return true iff errors were cleared. 173 */ 174 int circpad_negotiated_clear_errors(circpad_negotiated_t *obj); 175 /** Return the value of the version field of the circpad_negotiated_t 176 * in 'inp' 177 */ 178 uint8_t circpad_negotiated_get_version(const circpad_negotiated_t *inp); 179 /** Set the value of the version field of the circpad_negotiated_t in 180 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 181 * code on 'inp' on failure. 182 */ 183 int circpad_negotiated_set_version(circpad_negotiated_t *inp, uint8_t val); 184 /** Return the value of the command field of the circpad_negotiated_t 185 * in 'inp' 186 */ 187 uint8_t circpad_negotiated_get_command(const circpad_negotiated_t *inp); 188 /** Set the value of the command field of the circpad_negotiated_t in 189 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 190 * code on 'inp' on failure. 191 */ 192 int circpad_negotiated_set_command(circpad_negotiated_t *inp, uint8_t val); 193 /** Return the value of the response field of the circpad_negotiated_t 194 * in 'inp' 195 */ 196 uint8_t circpad_negotiated_get_response(const circpad_negotiated_t *inp); 197 /** Set the value of the response field of the circpad_negotiated_t in 198 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 199 * code on 'inp' on failure. 200 */ 201 int circpad_negotiated_set_response(circpad_negotiated_t *inp, uint8_t val); 202 /** Return the value of the machine_type field of the 203 * circpad_negotiated_t in 'inp' 204 */ 205 uint8_t circpad_negotiated_get_machine_type(const circpad_negotiated_t *inp); 206 /** Set the value of the machine_type field of the 207 * circpad_negotiated_t in 'inp' to 'val'. Return 0 on success; return 208 * -1 and set the error code on 'inp' on failure. 209 */ 210 int circpad_negotiated_set_machine_type(circpad_negotiated_t *inp, uint8_t val); 211 /** Return the value of the machine_ctr field of the 212 * circpad_negotiated_t in 'inp' 213 */ 214 uint32_t circpad_negotiated_get_machine_ctr(const circpad_negotiated_t *inp); 215 /** Set the value of the machine_ctr field of the circpad_negotiated_t 216 * in 'inp' to 'val'. Return 0 on success; return -1 and set the error 217 * code on 'inp' on failure. 218 */ 219 int circpad_negotiated_set_machine_ctr(circpad_negotiated_t *inp, uint32_t val); 220 221 222 #endif