9#define CONFLUX_CELL_PRIVATE
20#include "trunnel/conflux.h"
23#include "core/or/or_circuit_st.h"
29 ssize_t cell_len = -1;
30 trn_cell_conflux_link_t *cell = NULL;
31 trn_cell_conflux_link_payload_v1_t *payload = NULL;
35 cell = trn_cell_conflux_link_new();
36 trn_cell_conflux_link_set_version(cell, 0x01);
38 payload = trn_cell_conflux_link_payload_v1_new();
41 size_t nonce_len = trn_cell_conflux_link_payload_v1_getlen_nonce(payload);
43 memcpy(trn_cell_conflux_link_payload_v1_getarray_nonce(payload),
44 link->nonce, nonce_len);
47 trn_cell_conflux_link_payload_v1_set_last_seqno_recv(payload,
48 link->last_seqno_recv);
49 trn_cell_conflux_link_payload_v1_set_last_seqno_sent(payload,
50 link->last_seqno_sent);
53 trn_cell_conflux_link_payload_v1_set_desired_ux(payload, link->desired_ux);
56 ssize_t pay_len = trn_cell_conflux_link_payload_v1_encoded_len(payload);
59 trn_cell_conflux_link_setlen_payload(cell, pay_len);
61 trn_cell_conflux_link_payload_v1_encode(
62 trn_cell_conflux_link_getarray_payload(cell),
63 trn_cell_conflux_link_getlen_payload(cell), payload);
68 trn_cell_conflux_link_payload_v1_free(payload);
69 trn_cell_conflux_link_free(cell);
78 return build_link_cell(link, cell_out);
82build_linked_ack_cell(uint8_t *cell_out)
84 ssize_t cell_len = -1;
85 trn_cell_conflux_linked_ack_t *cell = NULL;
89 cell = trn_cell_conflux_linked_ack_new();
93 trn_cell_conflux_linked_ack_free(cell);
106 log_info(
LD_CIRC,
"Sending CONFLUX_LINK cell onto origin circuit");
109 cell_len = build_link_cell(link, payload);
110 if (BUG(cell_len < 0)) {
111 log_info(
LD_CIRC,
"Unable to build CONFLUX_LINK cell.");
112 circuit_mark_for_close(
TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
117 if (relay_send_command_from_edge(CONTROL_CELL_ID,
TO_CIRCUIT(circ),
118 RELAY_COMMAND_CONFLUX_LINK,
119 (
char *) payload, cell_len,
121 log_info(
LD_CIRC,
"Unable to send CONFLUX_LINK cell.");
140 log_info(
LD_CIRC,
"Sending CONFLUX_LINKED cell onto OR circuit");
143 cell_len = build_linked_cell(link, payload);
144 if (BUG(cell_len < 0)) {
145 log_info(
LD_CIRC,
"Unable to build CONFLUX_LINKED cell.");
146 circuit_mark_for_close(
TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
151 if (relay_send_command_from_edge(CONTROL_CELL_ID,
TO_CIRCUIT(circ),
152 RELAY_COMMAND_CONFLUX_LINKED,
153 (
char *) payload, cell_len, NULL) < 0) {
154 log_info(
LD_CIRC,
"Unable to send CONFLUX_LINKED cell.");
172 log_info(
LD_CIRC,
"Sending CONFLUX_LINKED_ACK cell onto origin circuit");
175 cell_len = build_linked_ack_cell(payload);
176 if (BUG(cell_len < 0)) {
177 log_info(
LD_CIRC,
"Unable to build CONFLUX_LINKED_ACK cell.");
178 circuit_mark_for_close(
TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
183 if (relay_send_command_from_edge(CONTROL_CELL_ID,
TO_CIRCUIT(circ),
184 RELAY_COMMAND_CONFLUX_LINKED_ACK,
185 (
char *) payload, cell_len,
187 log_info(
LD_CIRC,
"Unable to send CONFLUX_LINKED_ACK cell.");
198conflux_cell_parse_link_v1(
const trn_cell_conflux_link_t *trn_link)
201 trn_cell_conflux_link_payload_v1_t *payload = NULL;
203 if (trn_cell_conflux_link_payload_v1_parse(&payload,
204 trn_cell_conflux_link_getconstarray_payload(trn_link),
205 trn_cell_conflux_link_getlen_payload(trn_link)) < 0) {
207 "Unable to parse CONFLUX_LINK v1 payload.");
211 link = tor_malloc_zero(
sizeof(*link));
212 link->version = trn_cell_conflux_link_get_version(trn_link);
214 trn_cell_conflux_link_payload_v1_get_desired_ux(payload);
215 link->last_seqno_recv =
216 trn_cell_conflux_link_payload_v1_get_last_seqno_recv(payload);
217 link->last_seqno_sent =
218 trn_cell_conflux_link_payload_v1_get_last_seqno_sent(payload);
220 trn_cell_conflux_link_payload_v1_getconstarray_nonce(payload),
221 trn_cell_conflux_link_payload_v1_getlen_nonce(payload));
224 trn_cell_conflux_link_payload_v1_free(payload);
229conflux_cell_parse_link(
const cell_t *cell,
const uint16_t cell_len)
232 trn_cell_conflux_link_t *trn_cell = NULL;
236 if (trn_cell_conflux_link_parse(&trn_cell,
240 "Unable to parse CONFLUX_LINK cell.");
244 uint8_t version = trn_cell_conflux_link_get_version(trn_cell);
247 link = conflux_cell_parse_link_v1(trn_cell);
251 "Unsupported version %d in CONFLUX_LINK cell", version);
256 trn_cell_conflux_link_free(trn_cell);
261conflux_cell_parse_linked(
const cell_t *cell,
const uint16_t cell_len)
264 return conflux_cell_parse_link(cell, cell_len);
268conflux_cell_new_link(
const uint8_t *nonce, uint64_t last_seqno_sent,
269 uint64_t last_seqno_recv, uint8_t ux)
273 link->version = 0x01;
274 link->desired_ux = ux;
276 link->last_seqno_sent = last_seqno_sent;
277 link->last_seqno_recv = last_seqno_recv;
278 memcpy(link->nonce, nonce,
sizeof(link->nonce));
290 trn_cell_conflux_switch_t *switch_cell = NULL;
293 if (trn_cell_conflux_switch_parse(&switch_cell,
296 log_warn(
LD_BUG,
"Failed to parse switch cell");
302 seq = trn_cell_conflux_switch_get_seqnum(switch_cell);
304 trn_cell_conflux_switch_free(switch_cell);
313 trn_cell_conflux_switch_t *switch_cell = trn_cell_conflux_switch_new();
320 memset(&cell, 0,
sizeof(cell));
322 trn_cell_conflux_switch_set_seqnum(switch_cell, (uint32_t)relative_seq);
326 log_warn(
LD_BUG,
"Failed to encode conflux switch cell");
333 relay_send_command_from_edge(0, send_circ,
334 RELAY_COMMAND_CONFLUX_SWITCH,
339 relay_send_command_from_edge(0, send_circ,
340 RELAY_COMMAND_CONFLUX_SWITCH,
346 trn_cell_conflux_switch_free(switch_cell);
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
Header file for circuitlist.c.
#define CIRCUIT_IS_ORIGIN(c)
Header file for config.c.
Public APIs for conflux multipath support.
uint32_t conflux_cell_parse_switch(const cell_t *cell, uint16_t rh_len)
bool conflux_send_switch_command(circuit_t *send_circ, uint64_t relative_seq)
Header file for conflux_cell.c.
Path structures for origin circuits.
Common functions for using (pseudo-)random number generators.
#define log_fn(severity, domain, args,...)
#define RELAY_PAYLOAD_SIZE
#define RELAY_HEADER_SIZE
Origin circuit structure.
uint8_t payload[CELL_PAYLOAD_SIZE]
struct crypt_path_t * prev