Remove false positives from channel_is_client()
[tor.git] / src / or / command.c
blob894483e0013959f7c07bf56a6a29a53f68000d16
1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file command.c
9 * \brief Functions for processing incoming cells.
11 * When we receive a cell from a client or a relay, it arrives on some
12 * channel, and tells us what to do with it. In this module, we dispatch based
13 * on the cell type using the functions command_process_cell() and
14 * command_process_var_cell(), and deal with the cell accordingly. (These
15 * handlers are installed on a channel with the command_setup_channel()
16 * function.)
18 * Channels have a chance to handle some cell types on their own before they
19 * are ever passed here --- typically, they do this for cells that are
20 * specific to a given channel type. For example, in channeltls.c, the cells
21 * for the initial connection handshake are handled before we get here. (Of
22 * course, the fact that there _is_ only one channel type for now means that
23 * we may have gotten the factoring wrong here.)
25 * Handling other cell types is mainly farmed off to other modules, after
26 * initial sanity-checking. CREATE* cells are handled ultimately in onion.c,
27 * CREATED* cells trigger circuit creation in circuitbuild.c, DESTROY cells
28 * are handled here (since they're simple), and RELAY cells, in all their
29 * complexity, are passed off to relay.c.
30 **/
32 /* In-points to command.c:
34 * - command_process_cell(), called from
35 * incoming cell handlers of channel_t instances;
36 * callbacks registered in command_setup_channel(),
37 * called when channels are created in circuitbuild.c
39 #include "or.h"
40 #include "channel.h"
41 #include "circuitbuild.h"
42 #include "circuitlist.h"
43 #include "command.h"
44 #include "connection.h"
45 #include "connection_or.h"
46 #include "config.h"
47 #include "control.h"
48 #include "cpuworker.h"
49 #include "hibernate.h"
50 #include "nodelist.h"
51 #include "onion.h"
52 #include "rephist.h"
53 #include "relay.h"
54 #include "router.h"
55 #include "routerlist.h"
57 /** How many CELL_CREATE cells have we received, ever? */
58 uint64_t stats_n_create_cells_processed = 0;
59 /** How many CELL_CREATED cells have we received, ever? */
60 uint64_t stats_n_created_cells_processed = 0;
61 /** How many CELL_RELAY cells have we received, ever? */
62 uint64_t stats_n_relay_cells_processed = 0;
63 /** How many CELL_DESTROY cells have we received, ever? */
64 uint64_t stats_n_destroy_cells_processed = 0;
66 /* Handle an incoming channel */
67 static void command_handle_incoming_channel(channel_listener_t *listener,
68 channel_t *chan);
70 /* These are the main functions for processing cells */
71 static void command_process_create_cell(cell_t *cell, channel_t *chan);
72 static void command_process_created_cell(cell_t *cell, channel_t *chan);
73 static void command_process_relay_cell(cell_t *cell, channel_t *chan);
74 static void command_process_destroy_cell(cell_t *cell, channel_t *chan);
76 /** Convert the cell <b>command</b> into a lower-case, human-readable
77 * string. */
78 const char *
79 cell_command_to_string(uint8_t command)
81 switch (command) {
82 case CELL_PADDING: return "padding";
83 case CELL_CREATE: return "create";
84 case CELL_CREATED: return "created";
85 case CELL_RELAY: return "relay";
86 case CELL_DESTROY: return "destroy";
87 case CELL_CREATE_FAST: return "create_fast";
88 case CELL_CREATED_FAST: return "created_fast";
89 case CELL_VERSIONS: return "versions";
90 case CELL_NETINFO: return "netinfo";
91 case CELL_RELAY_EARLY: return "relay_early";
92 case CELL_CREATE2: return "create2";
93 case CELL_CREATED2: return "created2";
94 case CELL_VPADDING: return "vpadding";
95 case CELL_CERTS: return "certs";
96 case CELL_AUTH_CHALLENGE: return "auth_challenge";
97 case CELL_AUTHENTICATE: return "authenticate";
98 case CELL_AUTHORIZE: return "authorize";
99 default: return "unrecognized";
103 #ifdef KEEP_TIMING_STATS
104 /** This is a wrapper function around the actual function that processes the
105 * <b>cell</b> that just arrived on <b>conn</b>. Increment <b>*time</b>
106 * by the number of microseconds used by the call to <b>*func(cell, conn)</b>.
108 static void
109 command_time_process_cell(cell_t *cell, channel_t *chan, int *time,
110 void (*func)(cell_t *, channel_t *))
112 struct timeval start, end;
113 long time_passed;
115 tor_gettimeofday(&start);
117 (*func)(cell, chan);
119 tor_gettimeofday(&end);
120 time_passed = tv_udiff(&start, &end) ;
122 if (time_passed > 10000) { /* more than 10ms */
123 log_debug(LD_OR,"That call just took %ld ms.",time_passed/1000);
125 if (time_passed < 0) {
126 log_info(LD_GENERAL,"That call took us back in time!");
127 time_passed = 0;
129 *time += time_passed;
131 #endif
133 /** Process a <b>cell</b> that was just received on <b>chan</b>. Keep internal
134 * statistics about how many of each cell we've processed so far
135 * this second, and the total number of microseconds it took to
136 * process each type of cell.
138 void
139 command_process_cell(channel_t *chan, cell_t *cell)
141 #ifdef KEEP_TIMING_STATS
142 /* how many of each cell have we seen so far this second? needs better
143 * name. */
144 static int num_create=0, num_created=0, num_relay=0, num_destroy=0;
145 /* how long has it taken to process each type of cell? */
146 static int create_time=0, created_time=0, relay_time=0, destroy_time=0;
147 static time_t current_second = 0; /* from previous calls to time */
149 time_t now = time(NULL);
151 if (now > current_second) { /* the second has rolled over */
152 /* print stats */
153 log_info(LD_OR,
154 "At end of second: %d creates (%d ms), %d createds (%d ms), "
155 "%d relays (%d ms), %d destroys (%d ms)",
156 num_create, create_time/1000,
157 num_created, created_time/1000,
158 num_relay, relay_time/1000,
159 num_destroy, destroy_time/1000);
161 /* zero out stats */
162 num_create = num_created = num_relay = num_destroy = 0;
163 create_time = created_time = relay_time = destroy_time = 0;
165 /* remember which second it is, for next time */
166 current_second = now;
168 #endif
170 #ifdef KEEP_TIMING_STATS
171 #define PROCESS_CELL(tp, cl, cn) STMT_BEGIN { \
172 ++num ## tp; \
173 command_time_process_cell(cl, cn, & tp ## time , \
174 command_process_ ## tp ## _cell); \
175 } STMT_END
176 #else
177 #define PROCESS_CELL(tp, cl, cn) command_process_ ## tp ## _cell(cl, cn)
178 #endif
180 switch (cell->command) {
181 case CELL_CREATE:
182 case CELL_CREATE_FAST:
183 case CELL_CREATE2:
184 ++stats_n_create_cells_processed;
185 PROCESS_CELL(create, cell, chan);
186 break;
187 case CELL_CREATED:
188 case CELL_CREATED_FAST:
189 case CELL_CREATED2:
190 ++stats_n_created_cells_processed;
191 PROCESS_CELL(created, cell, chan);
192 break;
193 case CELL_RELAY:
194 case CELL_RELAY_EARLY:
195 ++stats_n_relay_cells_processed;
196 PROCESS_CELL(relay, cell, chan);
197 break;
198 case CELL_DESTROY:
199 ++stats_n_destroy_cells_processed;
200 PROCESS_CELL(destroy, cell, chan);
201 break;
202 default:
203 log_fn(LOG_INFO, LD_PROTOCOL,
204 "Cell of unknown or unexpected type (%d) received. "
205 "Dropping.",
206 cell->command);
207 break;
211 /** Process an incoming var_cell from a channel; in the current protocol all
212 * the var_cells are handshake-related and handled below the channel layer,
213 * so this just logs a warning and drops the cell.
216 void
217 command_process_var_cell(channel_t *chan, var_cell_t *var_cell)
219 tor_assert(chan);
220 tor_assert(var_cell);
222 log_info(LD_PROTOCOL,
223 "Received unexpected var_cell above the channel layer of type %d"
224 "; dropping it.",
225 var_cell->command);
228 /** Process a 'create' <b>cell</b> that just arrived from <b>chan</b>. Make a
229 * new circuit with the p_circ_id specified in cell. Put the circuit in state
230 * onionskin_pending, and pass the onionskin to the cpuworker. Circ will get
231 * picked up again when the cpuworker finishes decrypting it.
233 static void
234 command_process_create_cell(cell_t *cell, channel_t *chan)
236 or_circuit_t *circ;
237 const or_options_t *options = get_options();
238 int id_is_high;
239 create_cell_t *create_cell;
241 tor_assert(cell);
242 tor_assert(chan);
244 log_debug(LD_OR,
245 "Got a CREATE cell for circ_id %u on channel " U64_FORMAT
246 " (%p)",
247 (unsigned)cell->circ_id,
248 U64_PRINTF_ARG(chan->global_identifier), chan);
250 /* We check for the conditions that would make us drop the cell before
251 * we check for the conditions that would make us send a DESTROY back,
252 * since those conditions would make a DESTROY nonsensical. */
253 if (cell->circ_id == 0) {
254 log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
255 "Received a create cell (type %d) from %s with zero circID; "
256 " ignoring.", (int)cell->command,
257 channel_get_actual_remote_descr(chan));
258 return;
261 if (circuit_id_in_use_on_channel(cell->circ_id, chan)) {
262 const node_t *node = node_get_by_id(chan->identity_digest);
263 log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
264 "Received CREATE cell (circID %u) for known circ. "
265 "Dropping (age %d).",
266 (unsigned)cell->circ_id,
267 (int)(time(NULL) - channel_when_created(chan)));
268 if (node) {
269 char *p = esc_for_log(node_get_platform(node));
270 log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
271 "Details: router %s, platform %s.",
272 node_describe(node), p);
273 tor_free(p);
275 return;
278 if (we_are_hibernating()) {
279 log_info(LD_OR,
280 "Received create cell but we're shutting down. Sending back "
281 "destroy.");
282 channel_send_destroy(cell->circ_id, chan,
283 END_CIRC_REASON_HIBERNATING);
284 return;
287 if (!server_mode(options) ||
288 (!public_server_mode(options) && channel_is_outgoing(chan))) {
289 log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
290 "Received create cell (type %d) from %s, but we're connected "
291 "to it as a client. "
292 "Sending back a destroy.",
293 (int)cell->command, channel_get_canonical_remote_descr(chan));
294 channel_send_destroy(cell->circ_id, chan,
295 END_CIRC_REASON_TORPROTOCOL);
296 return;
299 /* If the high bit of the circuit ID is not as expected, close the
300 * circ. */
301 if (chan->wide_circ_ids)
302 id_is_high = cell->circ_id & (1u<<31);
303 else
304 id_is_high = cell->circ_id & (1u<<15);
305 if ((id_is_high &&
306 chan->circ_id_type == CIRC_ID_TYPE_HIGHER) ||
307 (!id_is_high &&
308 chan->circ_id_type == CIRC_ID_TYPE_LOWER)) {
309 log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
310 "Received create cell with unexpected circ_id %u. Closing.",
311 (unsigned)cell->circ_id);
312 channel_send_destroy(cell->circ_id, chan,
313 END_CIRC_REASON_TORPROTOCOL);
314 return;
317 circ = or_circuit_new(cell->circ_id, chan);
318 circ->base_.purpose = CIRCUIT_PURPOSE_OR;
319 circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_ONIONSKIN_PENDING);
320 create_cell = tor_malloc_zero(sizeof(create_cell_t));
321 if (create_cell_parse(create_cell, cell) < 0) {
322 tor_free(create_cell);
323 log_fn(LOG_PROTOCOL_WARN, LD_OR,
324 "Bogus/unrecognized create cell; closing.");
325 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
326 return;
329 if (connection_or_digest_is_known_relay(chan->identity_digest)) {
330 rep_hist_note_circuit_handshake_requested(create_cell->handshake_type);
333 if (create_cell->handshake_type != ONION_HANDSHAKE_TYPE_FAST) {
334 /* hand it off to the cpuworkers, and then return. */
336 if (assign_onionskin_to_cpuworker(circ, create_cell) < 0) {
337 log_debug(LD_GENERAL,"Failed to hand off onionskin. Closing.");
338 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_RESOURCELIMIT);
339 return;
341 log_debug(LD_OR,"success: handed off onionskin.");
342 } else {
343 /* This is a CREATE_FAST cell; we can handle it immediately without using
344 * a CPU worker. */
345 uint8_t keys[CPATH_KEY_MATERIAL_LEN];
346 uint8_t rend_circ_nonce[DIGEST_LEN];
347 int len;
348 created_cell_t created_cell;
350 /* If the client used CREATE_FAST, it's probably a tor client or bridge
351 * relay, and we must not use it for EXTEND requests (in most cases, we
352 * won't have an authenticated peer ID for the extend).
353 * Public relays on 0.2.9 and later will use CREATE_FAST if they have no
354 * ntor onion key for this relay, but that should be a rare occurrence.
355 * Clients on 0.3.1 and later avoid using CREATE_FAST as much as they can,
356 * even during bootstrap, so the CREATE_FAST check is most accurate for
357 * earlier tor client versions. */
358 channel_mark_client(chan);
360 memset(&created_cell, 0, sizeof(created_cell));
361 len = onion_skin_server_handshake(ONION_HANDSHAKE_TYPE_FAST,
362 create_cell->onionskin,
363 create_cell->handshake_len,
364 NULL,
365 created_cell.reply,
366 keys, CPATH_KEY_MATERIAL_LEN,
367 rend_circ_nonce);
368 tor_free(create_cell);
369 if (len < 0) {
370 log_warn(LD_OR,"Failed to generate key material. Closing.");
371 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
372 return;
374 created_cell.cell_type = CELL_CREATED_FAST;
375 created_cell.handshake_len = len;
377 if (onionskin_answer(circ, &created_cell,
378 (const char *)keys, rend_circ_nonce)<0) {
379 log_warn(LD_OR,"Failed to reply to CREATE_FAST cell. Closing.");
380 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
381 return;
383 memwipe(keys, 0, sizeof(keys));
387 /** Process a 'created' <b>cell</b> that just arrived from <b>chan</b>.
388 * Find the circuit
389 * that it's intended for. If we're not the origin of the circuit, package
390 * the 'created' cell in an 'extended' relay cell and pass it back. If we
391 * are the origin of the circuit, send it to circuit_finish_handshake() to
392 * finish processing keys, and then call circuit_send_next_onion_skin() to
393 * extend to the next hop in the circuit if necessary.
395 static void
396 command_process_created_cell(cell_t *cell, channel_t *chan)
398 circuit_t *circ;
399 extended_cell_t extended_cell;
401 circ = circuit_get_by_circid_channel(cell->circ_id, chan);
403 if (!circ) {
404 log_info(LD_OR,
405 "(circID %u) unknown circ (probably got a destroy earlier). "
406 "Dropping.", (unsigned)cell->circ_id);
407 return;
410 if (circ->n_circ_id != cell->circ_id || circ->n_chan != chan) {
411 log_fn(LOG_PROTOCOL_WARN,LD_PROTOCOL,
412 "got created cell from Tor client? Closing.");
413 circuit_mark_for_close(circ, END_CIRC_REASON_TORPROTOCOL);
414 return;
417 if (created_cell_parse(&extended_cell.created_cell, cell) < 0) {
418 log_fn(LOG_PROTOCOL_WARN, LD_OR, "Unparseable created cell.");
419 circuit_mark_for_close(circ, END_CIRC_REASON_TORPROTOCOL);
420 return;
423 if (CIRCUIT_IS_ORIGIN(circ)) { /* we're the OP. Handshake this. */
424 origin_circuit_t *origin_circ = TO_ORIGIN_CIRCUIT(circ);
425 int err_reason = 0;
426 log_debug(LD_OR,"at OP. Finishing handshake.");
427 if ((err_reason = circuit_finish_handshake(origin_circ,
428 &extended_cell.created_cell)) < 0) {
429 circuit_mark_for_close(circ, -err_reason);
430 return;
432 log_debug(LD_OR,"Moving to next skin.");
433 if ((err_reason = circuit_send_next_onion_skin(origin_circ)) < 0) {
434 log_info(LD_OR,"circuit_send_next_onion_skin failed.");
435 /* XXX push this circuit_close lower */
436 circuit_mark_for_close(circ, -err_reason);
437 return;
439 } else { /* pack it into an extended relay cell, and send it. */
440 uint8_t command=0;
441 uint16_t len=0;
442 uint8_t payload[RELAY_PAYLOAD_SIZE];
443 log_debug(LD_OR,
444 "Converting created cell to extended relay cell, sending.");
445 memset(payload, 0, sizeof(payload));
446 if (extended_cell.created_cell.cell_type == CELL_CREATED2)
447 extended_cell.cell_type = RELAY_COMMAND_EXTENDED2;
448 else
449 extended_cell.cell_type = RELAY_COMMAND_EXTENDED;
450 if (extended_cell_format(&command, &len, payload, &extended_cell) < 0) {
451 log_fn(LOG_PROTOCOL_WARN, LD_OR, "Can't format extended cell.");
452 circuit_mark_for_close(circ, END_CIRC_REASON_TORPROTOCOL);
453 return;
456 relay_send_command_from_edge(0, circ, command,
457 (const char*)payload, len, NULL);
461 /** Process a 'relay' or 'relay_early' <b>cell</b> that just arrived from
462 * <b>conn</b>. Make sure it came in with a recognized circ_id. Pass it on to
463 * circuit_receive_relay_cell() for actual processing.
465 static void
466 command_process_relay_cell(cell_t *cell, channel_t *chan)
468 const or_options_t *options = get_options();
469 circuit_t *circ;
470 int reason, direction;
472 circ = circuit_get_by_circid_channel(cell->circ_id, chan);
474 if (!circ) {
475 log_debug(LD_OR,
476 "unknown circuit %u on connection from %s. Dropping.",
477 (unsigned)cell->circ_id,
478 channel_get_canonical_remote_descr(chan));
479 return;
482 if (circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
483 log_fn(LOG_PROTOCOL_WARN,LD_PROTOCOL,"circuit in create_wait. Closing.");
484 circuit_mark_for_close(circ, END_CIRC_REASON_TORPROTOCOL);
485 return;
488 if (CIRCUIT_IS_ORIGIN(circ)) {
489 /* if we're a relay and treating connections with recent local
490 * traffic better, then this is one of them. */
491 channel_timestamp_client(chan);
494 if (!CIRCUIT_IS_ORIGIN(circ) &&
495 chan == TO_OR_CIRCUIT(circ)->p_chan &&
496 cell->circ_id == TO_OR_CIRCUIT(circ)->p_circ_id)
497 direction = CELL_DIRECTION_OUT;
498 else
499 direction = CELL_DIRECTION_IN;
501 /* If we have a relay_early cell, make sure that it's outbound, and we've
502 * gotten no more than MAX_RELAY_EARLY_CELLS_PER_CIRCUIT of them. */
503 if (cell->command == CELL_RELAY_EARLY) {
504 if (direction == CELL_DIRECTION_IN) {
505 /* Inbound early cells could once be encountered as a result of
506 * bug 1038; but relays running versions before 0.2.1.19 are long
507 * gone from the network, so any such cells now are surprising. */
508 log_warn(LD_OR,
509 "Received an inbound RELAY_EARLY cell on circuit %u."
510 " Closing circuit. Please report this event,"
511 " along with the following message.",
512 (unsigned)cell->circ_id);
513 if (CIRCUIT_IS_ORIGIN(circ)) {
514 circuit_log_path(LOG_WARN, LD_OR, TO_ORIGIN_CIRCUIT(circ));
515 } else if (circ->n_chan) {
516 log_warn(LD_OR, " upstream=%s",
517 channel_get_actual_remote_descr(circ->n_chan));
519 circuit_mark_for_close(circ, END_CIRC_REASON_TORPROTOCOL);
520 return;
521 } else {
522 or_circuit_t *or_circ = TO_OR_CIRCUIT(circ);
523 if (or_circ->remaining_relay_early_cells == 0) {
524 log_fn(LOG_PROTOCOL_WARN, LD_OR,
525 "Received too many RELAY_EARLY cells on circ %u from %s."
526 " Closing circuit.",
527 (unsigned)cell->circ_id,
528 safe_str(channel_get_canonical_remote_descr(chan)));
529 circuit_mark_for_close(circ, END_CIRC_REASON_TORPROTOCOL);
530 return;
532 --or_circ->remaining_relay_early_cells;
536 if ((reason = circuit_receive_relay_cell(cell, circ, direction)) < 0) {
537 log_fn(LOG_PROTOCOL_WARN,LD_PROTOCOL,"circuit_receive_relay_cell "
538 "(%s) failed. Closing.",
539 direction==CELL_DIRECTION_OUT?"forward":"backward");
540 circuit_mark_for_close(circ, -reason);
543 /* If this is a cell in an RP circuit, count it as part of the
544 hidden service stats */
545 if (options->HiddenServiceStatistics &&
546 !CIRCUIT_IS_ORIGIN(circ) &&
547 TO_OR_CIRCUIT(circ)->circuit_carries_hs_traffic_stats) {
548 rep_hist_seen_new_rp_cell();
552 /** Process a 'destroy' <b>cell</b> that just arrived from
553 * <b>chan</b>. Find the circ that it refers to (if any).
555 * If the circ is in state
556 * onionskin_pending, then call onion_pending_remove() to remove it
557 * from the pending onion list (note that if it's already being
558 * processed by the cpuworker, it won't be in the list anymore; but
559 * when the cpuworker returns it, the circuit will be gone, and the
560 * cpuworker response will be dropped).
562 * Then mark the circuit for close (which marks all edges for close,
563 * and passes the destroy cell onward if necessary).
565 static void
566 command_process_destroy_cell(cell_t *cell, channel_t *chan)
568 circuit_t *circ;
569 int reason;
571 circ = circuit_get_by_circid_channel(cell->circ_id, chan);
572 if (!circ) {
573 log_info(LD_OR,"unknown circuit %u on connection from %s. Dropping.",
574 (unsigned)cell->circ_id,
575 channel_get_canonical_remote_descr(chan));
576 return;
578 log_debug(LD_OR,"Received for circID %u.",(unsigned)cell->circ_id);
580 reason = (uint8_t)cell->payload[0];
581 circ->received_destroy = 1;
583 if (!CIRCUIT_IS_ORIGIN(circ) &&
584 chan == TO_OR_CIRCUIT(circ)->p_chan &&
585 cell->circ_id == TO_OR_CIRCUIT(circ)->p_circ_id) {
586 /* the destroy came from behind */
587 circuit_set_p_circid_chan(TO_OR_CIRCUIT(circ), 0, NULL);
588 circuit_mark_for_close(circ, reason|END_CIRC_REASON_FLAG_REMOTE);
589 } else { /* the destroy came from ahead */
590 circuit_set_n_circid_chan(circ, 0, NULL);
591 if (CIRCUIT_IS_ORIGIN(circ)) {
592 circuit_mark_for_close(circ, reason|END_CIRC_REASON_FLAG_REMOTE);
593 } else {
594 char payload[1];
595 log_debug(LD_OR, "Delivering 'truncated' back.");
596 payload[0] = (char)reason;
597 relay_send_command_from_edge(0, circ, RELAY_COMMAND_TRUNCATED,
598 payload, sizeof(payload), NULL);
603 /** Callback to handle a new channel; call command_setup_channel() to give
604 * it the right cell handlers.
607 static void
608 command_handle_incoming_channel(channel_listener_t *listener, channel_t *chan)
610 tor_assert(listener);
611 tor_assert(chan);
613 command_setup_channel(chan);
616 /** Given a channel, install the right handlers to process incoming
617 * cells on it.
620 void
621 command_setup_channel(channel_t *chan)
623 tor_assert(chan);
625 channel_set_cell_handlers(chan,
626 command_process_cell,
627 command_process_var_cell);
630 /** Given a listener, install the right handler to process incoming
631 * channels on it.
634 void
635 command_setup_listener(channel_listener_t *listener)
637 tor_assert(listener);
638 tor_assert(listener->state == CHANNEL_LISTENER_STATE_LISTENING);
640 channel_listener_set_listener_fn(listener, command_handle_incoming_channel);