aboutsummaryrefslogtreecommitdiff
path: root/src/or/channeltls.c
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2013-10-29 02:13:53 -0700
committerAndrea Shepard <andrea@torproject.org>2014-09-30 22:48:26 -0700
commit2efbab2aaf98d8f8f0df504efd4fdd0fac77d354 (patch)
tree2099658b3d71719d09c16db6590453ebb6f94b95 /src/or/channeltls.c
parent472b62bfe4edb2f5e332c997be2ec69bdf590660 (diff)
downloadtor-2efbab2aaf98d8f8f0df504efd4fdd0fac77d354.tar.gz
tor-2efbab2aaf98d8f8f0df504efd4fdd0fac77d354.zip
Provide generic mechanism for scheduler to query writeable cells on a channel
Diffstat (limited to 'src/or/channeltls.c')
-rw-r--r--src/or/channeltls.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index af1aab36d3..b828b152b5 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -68,6 +68,7 @@ channel_tls_matches_extend_info_method(channel_t *chan,
extend_info_t *extend_info);
static int channel_tls_matches_target_method(channel_t *chan,
const tor_addr_t *target);
+static int channel_tls_num_cells_writeable_method(channel_t *chan);
static int channel_tls_write_cell_method(channel_t *chan,
cell_t *cell);
static int channel_tls_write_packed_cell_method(channel_t *chan,
@@ -124,6 +125,7 @@ channel_tls_common_init(channel_tls_t *tlschan)
chan->is_canonical = channel_tls_is_canonical_method;
chan->matches_extend_info = channel_tls_matches_extend_info_method;
chan->matches_target = channel_tls_matches_target_method;
+ chan->num_cells_writeable = channel_tls_num_cells_writeable_method;
chan->write_cell = channel_tls_write_cell_method;
chan->write_packed_cell = channel_tls_write_packed_cell_method;
chan->write_var_cell = channel_tls_write_var_cell_method;
@@ -674,6 +676,34 @@ channel_tls_matches_target_method(channel_t *chan,
}
/**
+ * Tell the upper layer how many cells we can accept to write
+ *
+ * This implements the num_cells_writeable method for channel_tls_t; it
+ * returns an estimate of the number of cells we can accept with
+ * channel_tls_write_*_cell().
+ */
+
+static int
+channel_tls_num_cells_writeable_method(channel_t *chan)
+{
+ size_t outbuf_len;
+ int n;
+ channel_tls_t *tlschan = BASE_CHAN_TO_TLS(chan);
+ size_t cell_network_size;
+
+ tor_assert(tlschan);
+ tor_assert(tlschan->conn);
+
+ cell_network_size = get_cell_network_size(tlschan->conn->wide_circ_ids);
+ outbuf_len = connection_get_outbuf_len(TO_CONN(tlschan->conn));
+ /* Get the number of cells */
+ n = CEIL_DIV(OR_CONN_HIGHWATER - outbuf_len, cell_network_size);
+ if (n < 0) n = 0;
+
+ return n;
+}
+
+/**
* Write a cell to a channel_tls_t
*
* This implements the write_cell method for channel_tls_t; given a