summaryrefslogtreecommitdiff
path: root/src/or/circuitmux.c
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2013-11-30 01:25:20 -0800
committerAndrea Shepard <andrea@torproject.org>2014-09-30 22:49:35 -0700
commit9db596d2ef441d9293f5341be28150739baac98d (patch)
tree3b6cdb9dd010013f6101f7a0a9223f64510c557d /src/or/circuitmux.c
parent1275002a46dfb131f6db5c0fe28bc1828db327e2 (diff)
downloadtor-9db596d2ef441d9293f5341be28150739baac98d.tar.gz
tor-9db596d2ef441d9293f5341be28150739baac98d.zip
Add cmux support for inter-cmux comparisons
Diffstat (limited to 'src/or/circuitmux.c')
-rw-r--r--src/or/circuitmux.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/or/circuitmux.c b/src/or/circuitmux.c
index 3ca33b03ce..29c3be17d5 100644
--- a/src/or/circuitmux.c
+++ b/src/or/circuitmux.c
@@ -1951,3 +1951,51 @@ circuitmux_count_queued_destroy_cells(const channel_t *chan,
return n_destroy_cells;
}
+/**
+ * Compare cmuxes to see which is more preferred; return < 0 if
+ * cmux_1 has higher priority (i.e., cmux_1 < cmux_2 in the scheduler's
+ * sort order), > 0 if cmux_2 has higher priority, or 0 if they are
+ * equally preferred.
+ *
+ * If the cmuxes have different cmux policies or the policy does not
+ * support the cmp_cmux method, return 0.
+ */
+
+int
+circuitmux_compare_muxes(circuitmux_t *cmux_1, circuitmux_t *cmux_2)
+{
+ const circuitmux_policy_t *policy;
+
+ tor_assert(cmux_1);
+ tor_assert(cmux_2);
+
+ if (cmux_1 == cmux_2) {
+ /* Equivalent because they're the same cmux */
+ return 0;
+ }
+
+ if (cmux_1->policy && cmux_2->policy) {
+ if (cmux_1->policy == cmux_2->policy) {
+ policy = cmux_1->policy;
+
+ if (policy->cmp_cmux) {
+ /* Okay, we can compare! */
+ return policy->cmp_cmux(cmux_1, cmux_1->policy_data,
+ cmux_2, cmux_2->policy_data);
+ } else {
+ /*
+ * Equivalent because the policy doesn't know how to compare between
+ * muxes.
+ */
+ return 0;
+ }
+ } else {
+ /* Equivalent because they have different policies */
+ return 0;
+ }
+ } else {
+ /* Equivalent because one or both are missing a policy */
+ return 0;
+ }
+}
+