circpad_negotiation.h 8.4 KB

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