flow_control_cells.h (5047B)
1 /* flow_control_cells.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_FLOW_CONTROL_CELLS_H 6 #define TRUNNEL_FLOW_CONTROL_CELLS_H 7 8 #include <stdint.h> 9 #include "trunnel.h" 10 11 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_XOFF_CELL) 12 struct xoff_cell_st { 13 uint8_t version; 14 uint8_t trunnel_error_code_; 15 }; 16 #endif 17 typedef struct xoff_cell_st xoff_cell_t; 18 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_XON_CELL) 19 struct xon_cell_st { 20 uint8_t version; 21 uint32_t kbps_ewma; 22 uint8_t trunnel_error_code_; 23 }; 24 #endif 25 typedef struct xon_cell_st xon_cell_t; 26 /** Return a newly allocated xoff_cell with all elements set to zero. 27 */ 28 xoff_cell_t *xoff_cell_new(void); 29 /** Release all storage held by the xoff_cell in 'victim'. (Do nothing 30 * if 'victim' is NULL.) 31 */ 32 void xoff_cell_free(xoff_cell_t *victim); 33 /** Try to parse a xoff_cell from the buffer in 'input', using up to 34 * 'len_in' bytes from the input buffer. On success, return the number 35 * of bytes consumed and set *output to the newly allocated 36 * xoff_cell_t. On failure, return -2 if the input appears truncated, 37 * and -1 if the input is otherwise invalid. 38 */ 39 ssize_t xoff_cell_parse(xoff_cell_t **output, const uint8_t *input, const size_t len_in); 40 /** Return the number of bytes we expect to need to encode the 41 * xoff_cell in 'obj'. On failure, return a negative value. Note that 42 * this value may be an overestimate, and can even be an underestimate 43 * for certain unencodeable objects. 44 */ 45 ssize_t xoff_cell_encoded_len(const xoff_cell_t *obj); 46 /** Try to encode the xoff_cell from 'input' into the buffer at 47 * 'output', using up to 'avail' bytes of the output buffer. On 48 * success, return the number of bytes used. On failure, return -2 if 49 * the buffer was not long enough, and -1 if the input was invalid. 50 */ 51 ssize_t xoff_cell_encode(uint8_t *output, size_t avail, const xoff_cell_t *input); 52 /** Check whether the internal state of the xoff_cell in 'obj' is 53 * consistent. Return NULL if it is, and a short message if it is not. 54 */ 55 const char *xoff_cell_check(const xoff_cell_t *obj); 56 /** Clear any errors that were set on the object 'obj' by its setter 57 * functions. Return true iff errors were cleared. 58 */ 59 int xoff_cell_clear_errors(xoff_cell_t *obj); 60 /** Return the value of the version field of the xoff_cell_t in 'inp' 61 */ 62 uint8_t xoff_cell_get_version(const xoff_cell_t *inp); 63 /** Set the value of the version field of the xoff_cell_t in 'inp' to 64 * 'val'. Return 0 on success; return -1 and set the error code on 65 * 'inp' on failure. 66 */ 67 int xoff_cell_set_version(xoff_cell_t *inp, uint8_t val); 68 /** Return a newly allocated xon_cell with all elements set to zero. 69 */ 70 xon_cell_t *xon_cell_new(void); 71 /** Release all storage held by the xon_cell in 'victim'. (Do nothing 72 * if 'victim' is NULL.) 73 */ 74 void xon_cell_free(xon_cell_t *victim); 75 /** Try to parse a xon_cell from the buffer in 'input', using up to 76 * 'len_in' bytes from the input buffer. On success, return the number 77 * of bytes consumed and set *output to the newly allocated 78 * xon_cell_t. On failure, return -2 if the input appears truncated, 79 * and -1 if the input is otherwise invalid. 80 */ 81 ssize_t xon_cell_parse(xon_cell_t **output, const uint8_t *input, const size_t len_in); 82 /** Return the number of bytes we expect to need to encode the 83 * xon_cell in 'obj'. On failure, return a negative value. Note that 84 * this value may be an overestimate, and can even be an underestimate 85 * for certain unencodeable objects. 86 */ 87 ssize_t xon_cell_encoded_len(const xon_cell_t *obj); 88 /** Try to encode the xon_cell from 'input' into the buffer at 89 * 'output', using up to 'avail' bytes of the output buffer. On 90 * success, return the number of bytes used. On failure, return -2 if 91 * the buffer was not long enough, and -1 if the input was invalid. 92 */ 93 ssize_t xon_cell_encode(uint8_t *output, size_t avail, const xon_cell_t *input); 94 /** Check whether the internal state of the xon_cell in 'obj' is 95 * consistent. Return NULL if it is, and a short message if it is not. 96 */ 97 const char *xon_cell_check(const xon_cell_t *obj); 98 /** Clear any errors that were set on the object 'obj' by its setter 99 * functions. Return true iff errors were cleared. 100 */ 101 int xon_cell_clear_errors(xon_cell_t *obj); 102 /** Return the value of the version field of the xon_cell_t in 'inp' 103 */ 104 uint8_t xon_cell_get_version(const xon_cell_t *inp); 105 /** Set the value of the version field of the xon_cell_t in 'inp' to 106 * 'val'. Return 0 on success; return -1 and set the error code on 107 * 'inp' on failure. 108 */ 109 int xon_cell_set_version(xon_cell_t *inp, uint8_t val); 110 /** Return the value of the kbps_ewma field of the xon_cell_t in 'inp' 111 */ 112 uint32_t xon_cell_get_kbps_ewma(const xon_cell_t *inp); 113 /** Set the value of the kbps_ewma field of the xon_cell_t in 'inp' to 114 * 'val'. Return 0 on success; return -1 and set the error code on 115 * 'inp' on failure. 116 */ 117 int xon_cell_set_kbps_ewma(xon_cell_t *inp, uint32_t val); 118 119 120 #endif