2013-01-16 07:54:56 +01:00
|
|
|
/* * Copyright (c) 2012-2013, The Tor Project, Inc. */
|
2012-09-21 23:45:32 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file circuitmux.h
|
|
|
|
* \brief Header file for circuitmux.c
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_CIRCUITMUX_H
|
|
|
|
#define TOR_CIRCUITMUX_H
|
2012-09-21 23:45:32 +02:00
|
|
|
|
|
|
|
#include "or.h"
|
2013-07-10 21:07:32 +02:00
|
|
|
#include "testsupport.h"
|
2012-09-21 23:45:32 +02:00
|
|
|
|
2012-09-27 20:38:27 +02:00
|
|
|
typedef struct circuitmux_policy_s circuitmux_policy_t;
|
|
|
|
typedef struct circuitmux_policy_data_s circuitmux_policy_data_t;
|
|
|
|
typedef struct circuitmux_policy_circ_data_s circuitmux_policy_circ_data_t;
|
|
|
|
|
|
|
|
struct circuitmux_policy_s {
|
|
|
|
/* Allocate cmux-wide policy-specific data */
|
|
|
|
circuitmux_policy_data_t * (*alloc_cmux_data)(circuitmux_t *cmux);
|
|
|
|
/* Free cmux-wide policy-specific data */
|
|
|
|
void (*free_cmux_data)(circuitmux_t *cmux,
|
|
|
|
circuitmux_policy_data_t *pol_data);
|
|
|
|
/* Allocate circuit policy-specific data for a newly attached circuit */
|
|
|
|
circuitmux_policy_circ_data_t *
|
|
|
|
(*alloc_circ_data)(circuitmux_t *cmux,
|
|
|
|
circuitmux_policy_data_t *pol_data,
|
|
|
|
circuit_t *circ,
|
|
|
|
cell_direction_t direction,
|
|
|
|
unsigned int cell_count);
|
|
|
|
/* Free circuit policy-specific data */
|
|
|
|
void (*free_circ_data)(circuitmux_t *cmux,
|
|
|
|
circuitmux_policy_data_t *pol_data,
|
|
|
|
circuit_t *circ,
|
|
|
|
circuitmux_policy_circ_data_t *pol_circ_data);
|
|
|
|
/* Notify that a circuit has become active/inactive */
|
|
|
|
void (*notify_circ_active)(circuitmux_t *cmux,
|
|
|
|
circuitmux_policy_data_t *pol_data,
|
|
|
|
circuit_t *circ,
|
|
|
|
circuitmux_policy_circ_data_t *pol_circ_data);
|
|
|
|
void (*notify_circ_inactive)(circuitmux_t *cmux,
|
|
|
|
circuitmux_policy_data_t *pol_data,
|
|
|
|
circuit_t *circ,
|
|
|
|
circuitmux_policy_circ_data_t *pol_circ_data);
|
2012-09-27 21:20:05 +02:00
|
|
|
/* Notify of arriving/transmitted cells on a circuit */
|
|
|
|
void (*notify_set_n_cells)(circuitmux_t *cmux,
|
|
|
|
circuitmux_policy_data_t *pol_data,
|
|
|
|
circuit_t *circ,
|
|
|
|
circuitmux_policy_circ_data_t *pol_circ_data,
|
|
|
|
unsigned int n_cells);
|
|
|
|
void (*notify_xmit_cells)(circuitmux_t *cmux,
|
|
|
|
circuitmux_policy_data_t *pol_data,
|
|
|
|
circuit_t *circ,
|
|
|
|
circuitmux_policy_circ_data_t *pol_circ_data,
|
|
|
|
unsigned int n_cells);
|
2012-09-29 01:56:46 +02:00
|
|
|
/* Choose a circuit */
|
|
|
|
circuit_t * (*pick_active_circuit)(circuitmux_t *cmux,
|
|
|
|
circuitmux_policy_data_t *pol_data);
|
2013-11-30 10:25:20 +01:00
|
|
|
/* Optional: channel comparator for use by the scheduler */
|
|
|
|
int (*cmp_cmux)(circuitmux_t *cmux_1, circuitmux_policy_data_t *pol_data_1,
|
|
|
|
circuitmux_t *cmux_2, circuitmux_policy_data_t *pol_data_2);
|
2012-09-27 20:38:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Circuitmux policy implementations can subclass this to store circuitmux-
|
|
|
|
* wide data; it just has the magic number in the base struct.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct circuitmux_policy_data_s {
|
|
|
|
uint32_t magic;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Circuitmux policy implementations can subclass this to store circuit-
|
|
|
|
* specific data; it just has the magic number in the base struct.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct circuitmux_policy_circ_data_s {
|
|
|
|
uint32_t magic;
|
|
|
|
};
|
|
|
|
|
2012-10-01 10:48:52 +02:00
|
|
|
/*
|
|
|
|
* Upcast #defines for the above types
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a circuitmux_policy_data_t subtype to a circuitmux_policy_data_t.
|
|
|
|
*/
|
|
|
|
|
2012-10-12 18:22:13 +02:00
|
|
|
#define TO_CMUX_POL_DATA(x) (&((x)->base_))
|
2012-10-01 10:48:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a circuitmux_policy_circ_data_t subtype to a
|
|
|
|
* circuitmux_policy_circ_data_t.
|
|
|
|
*/
|
|
|
|
|
2012-10-12 18:22:13 +02:00
|
|
|
#define TO_CMUX_POL_CIRC_DATA(x) (&((x)->base_))
|
2012-10-01 10:48:52 +02:00
|
|
|
|
2012-09-21 23:45:32 +02:00
|
|
|
/* Consistency check */
|
|
|
|
void circuitmux_assert_okay(circuitmux_t *cmux);
|
|
|
|
|
|
|
|
/* Create/destroy */
|
|
|
|
circuitmux_t * circuitmux_alloc(void);
|
2013-09-09 19:48:44 +02:00
|
|
|
void circuitmux_detach_all_circuits(circuitmux_t *cmux,
|
|
|
|
smartlist_t *detached_out);
|
2012-09-21 23:45:32 +02:00
|
|
|
void circuitmux_free(circuitmux_t *cmux);
|
|
|
|
|
2012-09-27 20:38:27 +02:00
|
|
|
/* Policy control */
|
|
|
|
void circuitmux_clear_policy(circuitmux_t *cmux);
|
|
|
|
const circuitmux_policy_t * circuitmux_get_policy(circuitmux_t *cmux);
|
|
|
|
void circuitmux_set_policy(circuitmux_t *cmux,
|
|
|
|
const circuitmux_policy_t *pol);
|
|
|
|
|
2012-09-21 23:45:32 +02:00
|
|
|
/* Status inquiries */
|
|
|
|
cell_direction_t circuitmux_attached_circuit_direction(
|
|
|
|
circuitmux_t *cmux,
|
|
|
|
circuit_t *circ);
|
|
|
|
int circuitmux_is_circuit_attached(circuitmux_t *cmux, circuit_t *circ);
|
|
|
|
int circuitmux_is_circuit_active(circuitmux_t *cmux, circuit_t *circ);
|
|
|
|
unsigned int circuitmux_num_cells_for_circuit(circuitmux_t *cmux,
|
|
|
|
circuit_t *circ);
|
2014-01-22 10:00:25 +01:00
|
|
|
MOCK_DECL(unsigned int, circuitmux_num_cells, (circuitmux_t *cmux));
|
2012-09-21 23:45:32 +02:00
|
|
|
unsigned int circuitmux_num_circuits(circuitmux_t *cmux);
|
|
|
|
unsigned int circuitmux_num_active_circuits(circuitmux_t *cmux);
|
|
|
|
|
2014-06-10 19:35:45 +02:00
|
|
|
/* Debuging interface - slow. */
|
|
|
|
int64_t circuitmux_count_queued_destroy_cells(const channel_t *chan,
|
|
|
|
const circuitmux_t *cmux);
|
|
|
|
|
2012-09-21 23:45:32 +02:00
|
|
|
/* Channel interface */
|
2013-03-21 19:51:27 +01:00
|
|
|
circuit_t * circuitmux_get_first_active_circuit(circuitmux_t *cmux,
|
|
|
|
cell_queue_t **destroy_queue_out);
|
2012-09-21 23:45:32 +02:00
|
|
|
void circuitmux_notify_xmit_cells(circuitmux_t *cmux, circuit_t *circ,
|
|
|
|
unsigned int n_cells);
|
2013-06-13 07:22:21 +02:00
|
|
|
void circuitmux_notify_xmit_destroy(circuitmux_t *cmux);
|
2012-09-21 23:45:32 +02:00
|
|
|
|
|
|
|
/* Circuit interface */
|
2013-07-15 23:35:56 +02:00
|
|
|
MOCK_DECL(void, circuitmux_attach_circuit, (circuitmux_t *cmux,
|
|
|
|
circuit_t *circ,
|
2013-07-10 21:07:32 +02:00
|
|
|
cell_direction_t direction));
|
|
|
|
MOCK_DECL(void, circuitmux_detach_circuit,
|
|
|
|
(circuitmux_t *cmux, circuit_t *circ));
|
2012-09-21 23:45:32 +02:00
|
|
|
void circuitmux_clear_num_cells(circuitmux_t *cmux, circuit_t *circ);
|
|
|
|
void circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ,
|
|
|
|
unsigned int n_cells);
|
|
|
|
|
2013-03-21 19:51:27 +01:00
|
|
|
void circuitmux_append_destroy_cell(channel_t *chan,
|
|
|
|
circuitmux_t *cmux, circid_t circ_id,
|
|
|
|
uint8_t reason);
|
2013-06-17 17:30:56 +02:00
|
|
|
void circuitmux_mark_destroyed_circids_usable(circuitmux_t *cmux,
|
|
|
|
channel_t *chan);
|
2013-03-21 19:51:27 +01:00
|
|
|
|
2013-11-30 10:25:20 +01:00
|
|
|
/* Optional interchannel comparisons for scheduling */
|
|
|
|
int circuitmux_compare_muxes(circuitmux_t *cmux_1, circuitmux_t *cmux_2);
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#endif /* TOR_CIRCUITMUX_H */
|
2012-09-21 23:45:32 +02:00
|
|
|
|