summaryrefslogtreecommitdiff
path: root/src/or/channel.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/channel.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/channel.c')
-rw-r--r--src/or/channel.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/or/channel.c b/src/or/channel.c
index da2493a758..e9451f1e9b 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -3826,6 +3826,40 @@ channel_mark_outgoing(channel_t *chan)
chan->is_incoming = 0;
}
+/************************
+ * Flow control queries *
+ ***********************/
+
+/*
+ * Estimate the number of writeable cells
+ *
+ * Ask the lower layer for an estimate of how many cells it can accept, and
+ * then subtract the length of our outgoing_queue, if any, to produce an
+ * estimate of the number of cells this channel can accept for writes.
+ */
+
+int
+channel_num_cells_writeable(channel_t *chan)
+{
+ int result;
+
+ tor_assert(chan);
+ tor_assert(chan->num_cells_writeable);
+
+ if (chan->state == CHANNEL_STATE_OPEN) {
+ /* Query lower layer */
+ result = chan->num_cells_writeable(chan);
+ /* Subtract cell queue length, if any */
+ result -= chan_cell_queue_len(&chan->outgoing_queue);
+ if (result < 0) result = 0;
+ } else {
+ /* No cells are writeable in any other state */
+ result = 0;
+ }
+
+ return result;
+}
+
/*********************
* Timestamp updates *
********************/