Merge branch 'maint-0.4.8'
[tor.git] / src / core / or / sendme.h
blobbc1daef23d027582cf3b0d082c83587e5e96cb75
1 /* Copyright (c) 2019-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 /**
5 * \file sendme.h
6 * \brief Header file for sendme.c.
7 **/
9 #ifndef TOR_SENDME_H
10 #define TOR_SENDME_H
12 #include "core/or/edge_connection_st.h"
13 #include "core/or/crypt_path_st.h"
14 #include "core/or/circuit_st.h"
16 /* Sending SENDME cell. */
17 void sendme_connection_edge_consider_sending(edge_connection_t *edge_conn);
18 void sendme_circuit_consider_sending(circuit_t *circ,
19 crypt_path_t *layer_hint);
21 /* Processing SENDME cell. */
22 int sendme_process_circuit_level(crypt_path_t *layer_hint,
23 circuit_t *circ, const uint8_t *cell_payload,
24 uint16_t cell_payload_len);
25 int sendme_process_circuit_level_impl(crypt_path_t *, circuit_t *);
26 int sendme_process_stream_level(edge_connection_t *conn, circuit_t *circ,
27 uint16_t cell_body_len);
29 /* Update deliver window functions. */
30 int sendme_stream_data_received(edge_connection_t *conn);
31 int sendme_circuit_data_received(circuit_t *circ, crypt_path_t *layer_hint);
33 /* Update package window functions. */
34 int sendme_note_circuit_data_packaged(circuit_t *circ,
35 crypt_path_t *layer_hint);
36 int sendme_note_stream_data_packaged(edge_connection_t *conn, size_t len);
38 /* Record cell digest on circuit. */
39 void sendme_record_cell_digest_on_circ(circuit_t *circ, crypt_path_t *cpath);
40 /* Record cell digest as the SENDME digest. */
41 void sendme_record_received_cell_digest(circuit_t *circ, crypt_path_t *cpath);
42 void sendme_record_sending_cell_digest(circuit_t *circ, crypt_path_t *cpath);
44 /* Private section starts. */
45 #ifdef SENDME_PRIVATE
47 /* The maximum supported version. Above that value, the cell can't be
48 * recognized as a valid SENDME. */
49 #define SENDME_MAX_SUPPORTED_VERSION 1
51 /* The cell version constants for when emitting a cell. */
52 #define SENDME_EMIT_MIN_VERSION_DEFAULT 1
53 #define SENDME_EMIT_MIN_VERSION_MIN 0
54 #define SENDME_EMIT_MIN_VERSION_MAX UINT8_MAX
56 /* The cell version constants for when accepting a cell. */
57 #define SENDME_ACCEPT_MIN_VERSION_DEFAULT 0
58 #define SENDME_ACCEPT_MIN_VERSION_MIN 0
59 #define SENDME_ACCEPT_MIN_VERSION_MAX UINT8_MAX
62 * Unit tests declaractions.
64 #ifdef TOR_UNIT_TESTS
66 STATIC int get_emit_min_version(void);
67 STATIC int get_accept_min_version(void);
69 STATIC bool cell_version_can_be_handled(uint8_t cell_version);
71 STATIC ssize_t build_cell_payload_v1(const uint8_t *cell_digest,
72 uint8_t *payload);
73 STATIC bool sendme_is_valid(const circuit_t *circ,
74 const uint8_t *cell_payload,
75 size_t cell_payload_len);
76 STATIC bool circuit_sendme_cell_is_next(int deliver_window,
77 int sendme_inc);
79 #endif /* defined(TOR_UNIT_TESTS) */
81 #endif /* defined(SENDME_PRIVATE) */
83 #endif /* !defined(TOR_SENDME_H) */