tor-commits
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 1 participants
- 216106 discussions
[stegotorus/master] Merge branch 'master' of https://git.safdef.isc.org/git/stegotorus
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit f65fb5c199bc2793d8c615506835df6ec33a8c61
Merge: d65537f 6966489
Author: Zack Weinberg <zackw(a)panix.com>
Date: Tue Feb 14 15:02:00 2012 -0800
Merge branch 'master' of https://git.safdef.isc.org/git/stegotorus
src/steg/b64cookies.cc | 233 ++++++++++++++++++++++++++++++++++++++++++++++++
src/steg/b64cookies.h | 20 ++++
src/steg/b64decode.cc | 88 ++++++++++++++++++
src/steg/b64decode.h | 66 ++++++++++++++
src/steg/b64encode.cc | 139 ++++++++++++++++++++++++++++
src/steg/b64encode.h | 75 +++++++++++++++
6 files changed, 621 insertions(+), 0 deletions(-)
1
0
[stegotorus/master] Comment out unused-but-set variable to avoid gcc 4.6 warning
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 44d9df6cf73e3beafd0b5e0736ae3d02269a9b36
Author: Zack Weinberg <zackw(a)panix.com>
Date: Wed Feb 15 08:02:14 2012 -0800
Comment out unused-but-set variable to avoid gcc 4.6 warning
---
src/steg/http.cc | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/steg/http.cc b/src/steg/http.cc
index 3251995..9d296b5 100644
--- a/src/steg/http.cc
+++ b/src/steg/http.cc
@@ -621,7 +621,7 @@ http_server_receive(http *s, conn_t *conn, struct evbuffer *dest, struct evbuffe
char outbuf[MAX_COOKIE_SIZE];
char outbuf2[MAX_COOKIE_SIZE];
int sofar = 0;
- int cookie_mode = 0;
+ //int cookie_mode = 0;
if (s2.pos == -1) {
@@ -646,7 +646,7 @@ http_server_receive(http *s, conn_t *conn, struct evbuffer *dest, struct evbuffe
if (strstr((char*) data, "Cookie") != NULL) {
p = strstr((char*) data, "Cookie:") + sizeof "Cookie: "-1;
- cookie_mode = 1;
+ //cookie_mode = 1;
}
else
p = data + sizeof "GET /" -1;
1
0
[stegotorus/master] Another round of adjustments to the benchmarks
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 42948a36f82b5d38223cb4691bc25a84b809e11a
Author: Zack Weinberg <zackw(a)panix.com>
Date: Wed Feb 15 08:01:37 2012 -0800
Another round of adjustments to the benchmarks
---
scripts/benchmark.py | 49 +++++++++++++++++--------
scripts/bm-fixedrate-cgi.c | 31 ++++++++--------
scripts/bm-tor-controller.py | 83 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 131 insertions(+), 32 deletions(-)
diff --git a/scripts/benchmark.py b/scripts/benchmark.py
index f4f8830..be45467 100755
--- a/scripts/benchmark.py
+++ b/scripts/benchmark.py
@@ -46,10 +46,10 @@ PROXY_SSH_CMD = ("ssh", PROXY)
TARGET = "storustest.nfshost.com"
-# Fudge factors. For some reason, bm-fixedrate generates data a
-# linear factor slower than it was meant to; this is the quick fix.
+# For some reason, bm-fixedrate generates data a linear factor slower
+# than it was meant to; this is the quick fix.
-FUDGE_FIXEDRATE = 2.5
+FUDGE_FIXEDRATE = 1.939
# Programs we need to run. Change these if any binary is not in the
# default path or hasn't got the default name.
@@ -58,7 +58,6 @@ FUDGE_FIXEDRATE = 2.5
# setup, write a wrapper script.
C_bwm = "bwm-ng"
-C_curl = "curl"
C_mcurl = "bm-mcurl"
C_storus = "stegotorus-wrapper"
C_tor = "/usr/sbin/tor"
@@ -232,10 +231,13 @@ def p_tor_direct():
ORPort %s
SocksPort 0
BridgeRelay 1
+AssumeReachable 1
PublishServerDescriptor 0
ExitPolicy reject *:*
DataDirectory .
Log err stderr
+ContactInfo zackw at cmu dot edu
+Nickname storustest
# unfortunately there doesn't seem to be any way to tell Tor to accept
# OR connections from specific IP addresses only.
""" % PROXY_PORT)
@@ -268,17 +270,24 @@ Log err stderr
Bridge %s:%s
UseBridges 1
SafeSocks 0
+ControlPort 9051
+__DisablePredictedCircuits 1
+__LeaveStreamsUnattached 1
""" % (PROXY_PORT, PROXY_IP, PROXY_PORT))
fp.close()
return ClientProcess((C_tor, "--quiet", "-f", "tor-direct-client.conf"))
+def c_torctl():
+ return ClientProcess((os.path.dirname(__file__) + '/bm-tor-controller.py'))
+
def c_curl(url, proxyhost):
- return ClientProcess((C_curl, "-s", "--socks5-hostname",
+ return ClientProcess((C_mcurl, '1', '1',
proxyhost + ":" + PROXY_PORT,
- url, "-o", "/dev/null"))
+ url))
def c_mcurl(prefix, cps, proxyhost):
- return ClientProcess((C_mcurl, str(cps), '200', proxyhost,
+ return ClientProcess((C_mcurl, str(cps), '200',
+ proxyhost + ':' + PROXY_PORT,
'http://' + TARGET + '/' + prefix +
'/[0-9]/[0-9]/[0-9]/[0-9].html'))
@@ -296,7 +305,7 @@ def bench_fixedrate_direct(report):
client = c_curl('http://' + TARGET + '/bm-fixedrate.cgi/' +
str(int(cap * 1000 * FUDGE_FIXEDRATE)),
PROXY)
- monitor(report, "fixedrate,direct,%d" % cap, 60)
+ monitor(report, "fixedrate,direct,%d" % cap, 10)
finally:
if client is not None:
client.terminate()
@@ -314,6 +323,7 @@ def bench_fixedrate_tor(report):
try:
proxy = p_tor_direct()
proxyl = c_tor_direct()
+ proxyc = c_torctl()
time.sleep(5) # tor startup is slow
for cap in range(10,810,10):
@@ -332,17 +342,20 @@ def bench_fixedrate_tor(report):
if proxy is not None:
proxy.terminate()
proxy.wait()
+ if proxyc is not None:
+ proxyc.terminate()
+ proxyc.wait()
if proxyl is not None:
proxyl.terminate()
proxyl.wait()
-def bench_files_direct(report, prefix):
+def bench_files_direct(report, prefix, maxconn):
client = None
proxy = None
try:
proxy = p_nylon()
- for cps in range(1,151):
+ for cps in range(1,maxconn+1):
sys.stderr.write("files.%s,direct,%d\n" % (prefix, cps))
try:
client = c_mcurl(prefix, cps, PROXY_IP)
@@ -357,16 +370,17 @@ def bench_files_direct(report, prefix):
proxy.terminate()
proxy.wait()
-def bench_files_tor(report, prefix):
+def bench_files_tor(report, prefix, maxconn):
client = None
proxy = None
proxyl = None
try:
proxy = p_tor_direct()
proxyl = c_tor_direct()
+ proxyc = c_torctl()
time.sleep(5) # tor startup is slow
- for cps in range(1,151):
+ for cps in range(1,maxconn+1):
sys.stderr.write("files.%s,tor,%d\n" % (prefix, cps))
try:
client = c_mcurl(prefix, cps, '127.0.0.1')
@@ -380,6 +394,9 @@ def bench_files_tor(report, prefix):
if proxy is not None:
proxy.terminate()
proxy.wait()
+ if proxyc is not None:
+ proxyc.terminate()
+ proxyc.wait()
if proxyl is not None:
proxyl.terminate()
proxyl.wait()
@@ -388,7 +405,7 @@ if __name__ == '__main__':
sys.stdout.write("benchmark,relay,cap,obs,up,down\n")
bench_fixedrate_direct(sys.stdout)
bench_fixedrate_tor(sys.stdout)
- bench_files_direct(sys.stdout, "fixed")
- bench_files_tor(sys.stdout, "fixed")
- bench_files_direct(sys.stdout, "pareto")
- bench_files_tor(sys.stdout, "pareto")
+ bench_files_direct(sys.stdout, "fixed", 120)
+ bench_files_tor(sys.stdout, "fixed", 120)
+ bench_files_direct(sys.stdout, "pareto", 80)
+ bench_files_tor(sys.stdout, "pareto", 80)
diff --git a/scripts/bm-fixedrate-cgi.c b/scripts/bm-fixedrate-cgi.c
index 2b48f98..851cda7 100644
--- a/scripts/bm-fixedrate-cgi.c
+++ b/scripts/bm-fixedrate-cgi.c
@@ -13,10 +13,6 @@
#include <time.h>
#include <unistd.h>
-/* 1400 bytes is a safe figure for per-packet transmissible payload. */
-#define BLOCKSZ 1400
-
-
#if __GNUC__ >= 3
#define NORETURN void __attribute__((noreturn))
#else
@@ -48,14 +44,22 @@ error_500(const char *syscall)
static void
generate(unsigned long rate, bool dryrun)
{
- double interval;
timer_t timerid;
struct sigevent sev;
struct itimerspec its;
sigset_t mask;
int sig;
char *data;
- size_t bufsz = BLOCKSZ;
+ size_t bufsz;
+
+ /* Despite our use of the high-resolution interval timers, we cannot
+ count on being scheduled more often than 1/CLOCKS_PER_SEC
+ seconds. We ask to be scheduled every 0.01 seconds to avoid a
+ class of rounding errors, since it is very likely that we will be
+ asked to generate at a rate that is a power of ten.
+
+ Therefore, every time we are scheduled we should produce R/100
+ bytes of data. */
/* You send data at R bytes per second in 1400-byte blocks by
calling write() every 1/(R/1400) second. However, despite our
@@ -63,24 +67,19 @@ generate(unsigned long rate, bool dryrun)
being scheduled more often than every 1/CLOCKS_PER_SEC seconds,
so if we need to send data faster than that, bump up the block
size instead. */
- interval = 1./(rate/(double)BLOCKSZ);
-
- if (interval < 1./CLOCKS_PER_SEC) {
- interval = 1./CLOCKS_PER_SEC;
- bufsz = rate / CLOCKS_PER_SEC;
- }
+ bufsz = rate / 100;
- its.it_value.tv_sec = lrint(floor(interval));
- its.it_value.tv_nsec = lrint((interval - its.it_value.tv_sec) * 1e9);
+ its.it_value.tv_sec = 0;
+ its.it_value.tv_nsec = 10000000; /* 1e7 ns = 0.01 s */
its.it_interval.tv_sec = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
if (dryrun) {
printf("Content-Type: text/plain\n\n"
"Goal %lu bytes per second:\n"
- "would send %lu bytes every %f seconds\n"
+ "would send %zu bytes every 0.01 seconds\n"
" \" \" \" \" \" %lu sec + %lu nsec\n",
- rate, bufsz, interval,
+ rate, bufsz,
(unsigned long)its.it_value.tv_sec,
(unsigned long)its.it_value.tv_nsec);
return;
diff --git a/scripts/bm-tor-controller.py b/scripts/bm-tor-controller.py
new file mode 100755
index 0000000..1b147be
--- /dev/null
+++ b/scripts/bm-tor-controller.py
@@ -0,0 +1,83 @@
+#! /usr/bin/python
+
+from torctl import TorCtl, TorUtil, PathSupport
+
+import time
+
+i = PathSupport.IdHexRestriction
+
+# in San Francisco
+amunet = PathSupport.OrNodeRestriction([
+ i('$0CE3CFB1E9CC47B63EA8869813BF6FAB7D4540C1'), # amunet4
+ i('$E0BD57A11F00041A9789577C53A1B784473669E4'), # amunet3
+ i('$E5E3E9A472EAF7BE9682B86E92305DB4C71048EF') # amunet2
+])
+
+# probably in L.A.
+hazare = PathSupport.OrNodeRestriction([
+ i('$3D0FAFB36EB9FC9D1EFD68758E2B0025117D3D1B'), # hazare2
+ i('$6586CEE14353DD1E6FAF3F172A23B00119A67C57'), # saeed
+ i('$6F383C2629471E1AE7DA053D04625AAED69844CC') # hazare
+])
+
+# very likely in L.A.
+noisebr = PathSupport.OrNodeRestriction([
+ i('$3A415473854F9F082F16EECDFE436218FE1169EA'), # noiseexit01c
+ i('$9C98B38FE270546C69205E16047B8D46BBBB0447'), # noiseexit01d
+ i('$F97F3B153FED6604230CD497A3D1E9815B007636') # noiseexit01a
+])
+
+# I shouldn't have to do this
+class TheseUniformly(PathSupport.BaseSelectionManager):
+ def __init__(self, res_entry, res_mid, res_exit):
+ PathSupport.BaseSelectionManager.__init__(self)
+ if not isinstance(res_entry, PathSupport.NodeRestrictionList):
+ res_entry = PathSupport.NodeRestrictionList([res_entry])
+ if not isinstance(res_mid, PathSupport.NodeRestrictionList):
+ res_mid = PathSupport.NodeRestrictionList([res_mid])
+ if not isinstance(res_exit, PathSupport.NodeRestrictionList):
+ res_exit = PathSupport.NodeRestrictionList([res_exit])
+ self.res_entry = res_entry
+ self.res_mid = res_mid
+ self.res_exit = res_exit
+ self.path_selector = None
+
+ def reconfigure(self, consensus):
+ if self.path_selector is not None:
+ try:
+ self.path_selector.rebuild_gens(consensus.sorted_r)
+ except NoNodesRemain:
+ pass
+
+ self.path_selector = PathSupport.PathSelector(
+ PathSupport.ExactUniformGenerator(consensus.sorted_r, self.res_entry),
+ PathSupport.ExactUniformGenerator(consensus.sorted_r, self.res_mid),
+ PathSupport.ExactUniformGenerator(consensus.sorted_r, self.res_exit),
+ PathSupport.PathRestrictionList([PathSupport.UniqueRestriction()]))
+
+ def new_consensus(self, consensus):
+ self.reconfigure(consensus)
+
+ def set_exit(self, exit_name):
+ pass
+
+ def set_target(self, host, port):
+ pass
+
+ def select_path(self):
+ return self.path_selector.select_path(3)
+
+TorUtil.loglevel = "WARN"
+
+s = TheseUniformly(amunet, hazare, noisebr)
+c = TorCtl.connect(ConnClass=PathSupport.Connection)
+h = PathSupport.PathBuilder(c, s)
+c.set_event_handler(h)
+c.set_events([TorCtl.EVENT_TYPE.STREAM,
+ TorCtl.EVENT_TYPE.BW,
+ TorCtl.EVENT_TYPE.NEWCONSENSUS,
+ TorCtl.EVENT_TYPE.NEWDESC,
+ TorCtl.EVENT_TYPE.CIRC,
+ TorCtl.EVENT_TYPE.STREAM_BW], True)
+
+while True: time.sleep(120)
1
0
[stegotorus/master] Merge branch 'master' of https://git.safdef.isc.org/git/stegotorus
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit c8b967ef7f599d1625e1abb227e2bc00f0fbf39f
Merge: 7539220 f65fb5c
Author: Vinod Yegneswaran <vinod(a)safdef.isc.org>
Date: Tue Feb 14 15:34:06 2012 -0800
Merge branch 'master' of https://git.safdef.isc.org/git/stegotorus
.gitignore | 2 ++
.gitmodules | 3 +++
scripts/benchmark.py | 50 +++++++++++++++++---------------------------------
scripts/bm-mcurl.c | 4 ++--
scripts/torctl | 1 +
5 files changed, 25 insertions(+), 35 deletions(-)
1
0
commit 15da94646e4d0bc9fd22458df98c23fc7cbd457d
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Feb 27 16:49:42 2012 -0800
Fix some old comments.
---
src/protocol.h | 13 ++++---------
src/steg.h | 7 +++----
2 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/protocol.h b/src/protocol.h
index 98ad39c..9643b1a 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -68,17 +68,12 @@ struct config_t
int config_is_supported(const char *name);
config_t *config_create(int n_options, const char *const *options);
-/**
- This struct defines a protocol and its methods; note that not all
- of them are methods on the same object in the C++ sense.
- See connections.h for the definitions of 'conn_t' and 'circuit_t'.
-
- A filled-in, statically allocated proto_module object is the
- principal interface between each individual protocol and generic code.
- */
+/** PROTO_DEFINE_MODULE defines an object with this type, plus the
+ function that it points to; there is a table of all such objects,
+ which generic code uses to know what protocols are available. */
struct proto_module
{
- /** The short name of this protocol. Must be a valid C identifier. */
+ /** Name of this protocol. Must be a valid C identifier. */
const char *name;
/** Create a config_t instance for this module from a set of command
diff --git a/src/steg.h b/src/steg.h
index 63f0fc9..dab44e5 100644
--- a/src/steg.h
+++ b/src/steg.h
@@ -44,10 +44,9 @@ struct steg_t
};
/** STEG_DEFINE_MODULE defines an object with this type, plus the
- function that it points to. You don't ever manipulate this object
- directly; however, read its documentation to understand the
- arguments to STEG_DEFINE_MODULE. */
-
+ function that it points to; there is a table of all such objects,
+ which generic code uses to know what steganography modules are
+ available. */
struct steg_module
{
/** Name of the steganography module. Must be a valid C identifier. */
1
0
[stegotorus/master] Remove ->circuit pointer from the generic conn_t.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 1f960800bbbdd8dbb52de125375384bcaf45f000
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Feb 27 16:34:13 2012 -0800
Remove ->circuit pointer from the generic conn_t.
Protocols are now expected to maintain a conn-to-circuit pointer
in the derived foo_conn_t. This allows it to have the correct
static type (i.e. foo_circuit_t) and thus eliminates a bunch of
casting back and forth.
---
src/connections.cc | 15 ++---
src/connections.h | 6 ++-
src/network.cc | 4 +-
src/protocol.h | 1 +
src/protocol/chop.cc | 171 +++++++++++++++++++++++++++----------------------
src/protocol/null.cc | 57 +++++++++++++----
src/util.cc | 9 ++-
7 files changed, 158 insertions(+), 105 deletions(-)
diff --git a/src/connections.cc b/src/connections.cc
index 6320746..37eaba3 100644
--- a/src/connections.cc
+++ b/src/connections.cc
@@ -115,10 +115,6 @@ conn_t::~conn_t()
log_debug(this, "closing connection; %lu remaining",
(unsigned long) connections.size());
- if (this->circuit) {
- circuit_drop_downstream(this->circuit, this);
- }
-
if (this->peername)
free((void *)this->peername);
if (this->buffer)
@@ -127,6 +123,13 @@ conn_t::~conn_t()
maybe_finish_shutdown();
}
+/** Potentially called during connection construction or destruction. */
+circuit_t *
+conn_t::circuit() const
+{
+ return 0;
+}
+
void
conn_close(conn_t *conn)
{
@@ -290,16 +293,12 @@ circuit_add_upstream(circuit_t *ckt, struct bufferevent *buf, const char *peer)
void
circuit_add_downstream(circuit_t *ckt, conn_t *down)
{
- log_assert(!down->circuit);
- down->circuit = ckt;
ckt->add_downstream(down);
}
void
circuit_drop_downstream(circuit_t *ckt, conn_t *down)
{
- log_assert(down->circuit == ckt);
- down->circuit = NULL;
ckt->drop_downstream(down);
}
diff --git a/src/connections.h b/src/connections.h
index 6c0c5f7..b0cac55 100644
--- a/src/connections.h
+++ b/src/connections.h
@@ -15,7 +15,6 @@
socket-level connections) as quickly as possible. */
struct conn_t {
config_t *cfg;
- circuit_t *circuit;
const char *peername;
struct bufferevent *buffer;
unsigned int serial;
@@ -25,6 +24,11 @@ struct conn_t {
conn_t() : connected(false), flushing(false) {}
virtual ~conn_t();
+ /** Return the upstream circuit for this connection, if there is one.
+ NOTE: this is *not* a pure virtual method because it can be called
+ legitimately after the subclass destructor has run. */
+ virtual circuit_t *circuit() const;
+
/** Create an upstream circuit for this connection, if it is
possible to do so without receiving data from the downstream
peer. If data must be received first, this method should do
diff --git a/src/network.cc b/src/network.cc
index a55e539..3ecb378 100644
--- a/src/network.cc
+++ b/src/network.cc
@@ -503,7 +503,7 @@ downstream_connect_cb(struct bufferevent *bev, short what, void *arg)
/* Upon successful connection, enable traffic on both sides of the
connection, and replace this callback with the regular event_cb */
if (what & BEV_EVENT_CONNECTED) {
- circuit_t *ckt = conn->circuit;
+ circuit_t *ckt = conn->circuit();
log_assert(ckt);
log_assert(ckt->up_peer);
log_assert(conn->buffer == bev);
@@ -539,7 +539,7 @@ static void
downstream_socks_connect_cb(struct bufferevent *bev, short what, void *arg)
{
conn_t *conn = (conn_t *)arg;
- circuit_t *ckt = conn->circuit;
+ circuit_t *ckt = conn->circuit();
socks_state_t *socks;
log_debug(conn, "what=%04hx", what);
diff --git a/src/protocol.h b/src/protocol.h
index c48238c..d28bf19 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -123,6 +123,7 @@ extern const proto_module *const supported_protos[];
#define CONN_DECLARE_METHODS(mod) \
mod##_conn_t(); \
virtual ~mod##_conn_t(); \
+ virtual circuit_t *circuit() const; \
virtual int maybe_open_upstream(); \
virtual int handshake(); \
virtual int recv(); \
diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index 89a9ccc..536481c 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -71,11 +71,13 @@ static const uint8_t s2c_key[] =
/* Connections and circuits */
-typedef unordered_map<uint64_t, circuit_t *> chop_circuit_table;
-
namespace {
+ struct chop_circuit_t;
+ typedef unordered_map<uint64_t, chop_circuit_t *> chop_circuit_table;
+
struct chop_conn_t : conn_t
{
+ chop_circuit_t *upstream;
steg_t *steg;
struct evbuffer *recv_pending;
struct event *must_transmit_timer;
@@ -87,7 +89,7 @@ namespace {
struct chop_circuit_t : circuit_t
{
chop_reassembly_elt reassembly_queue;
- unordered_set<conn_t *> downstreams;
+ unordered_set<chop_conn_t *> downstreams;
encryptor *send_crypt;
decryptor *recv_crypt;
@@ -240,22 +242,22 @@ chop_decrypt_header(chop_circuit_t *ckt,
/* Transmit subroutines. */
-static conn_t *
+static chop_conn_t *
chop_pick_connection(chop_circuit_t *ckt, size_t desired, size_t *blocksize)
{
size_t maxbelow = 0;
size_t minabove = SIZE_MAX;
- conn_t *targbelow = NULL;
- conn_t *targabove = NULL;
+ chop_conn_t *targbelow = NULL;
+ chop_conn_t *targabove = NULL;
if (desired > CHOP_MAX_DATA)
desired = CHOP_MAX_DATA;
/* Find the best fit for the desired transmission from all the
outbound connections' transmit rooms. */
- for (unordered_set<conn_t *>::iterator i = ckt->downstreams.begin();
+ for (unordered_set<chop_conn_t *>::iterator i = ckt->downstreams.begin();
i != ckt->downstreams.end(); i++) {
- chop_conn_t *conn = static_cast<chop_conn_t *>(*i);
+ chop_conn_t *conn = *i;
/* We can only use candidates that have a steg target already. */
if (conn->steg) {
/* Find the connections whose transmit rooms are closest to the
@@ -304,14 +306,13 @@ chop_pick_connection(chop_circuit_t *ckt, size_t desired, size_t *blocksize)
}
static int
-chop_send_block(conn_t *d,
+chop_send_block(chop_conn_t *dest,
chop_circuit_t *ckt,
struct evbuffer *source,
struct evbuffer *block,
uint16_t length,
uint16_t flags)
{
- chop_conn_t *dest = static_cast<chop_conn_t *>(d);
chop_header hdr;
struct evbuffer_iovec v;
uint8_t *p;
@@ -381,18 +382,17 @@ chop_send_block(conn_t *d,
}
static int
-chop_send_blocks(circuit_t *c)
+chop_send_blocks(chop_circuit_t *ckt)
{
- chop_circuit_t *ckt = static_cast<chop_circuit_t *>(c);
- struct evbuffer *xmit_pending = bufferevent_get_input(c->up_buffer);
+ struct evbuffer *xmit_pending = bufferevent_get_input(ckt->up_buffer);
struct evbuffer *block;
- conn_t *target;
+ chop_conn_t *target;
size_t avail;
size_t blocksize;
uint16_t flags;
if (!(block = evbuffer_new())) {
- log_warn(c, "allocation failure");
+ log_warn(ckt, "allocation failure");
return -1;
}
@@ -400,14 +400,14 @@ chop_send_blocks(circuit_t *c)
avail = evbuffer_get_length(xmit_pending);
flags = ckt->sent_syn ? 0 : CHOP_F_SYN;
- log_debug(c, "%lu bytes to send", (unsigned long)avail);
+ log_debug(ckt, "%lu bytes to send", (unsigned long)avail);
if (avail == 0)
break;
target = chop_pick_connection(ckt, avail, &blocksize);
if (!target) {
- log_debug(c, "no target connection available");
+ log_debug(ckt, "no target connection available");
/* this is not an error; it can happen e.g. when the server has
something to send immediately and the client hasn't spoken yet */
break;
@@ -428,15 +428,14 @@ chop_send_blocks(circuit_t *c)
evbuffer_free(block);
avail = evbuffer_get_length(xmit_pending);
if (avail)
- log_debug(c, "%lu bytes still waiting to be sent", (unsigned long)avail);
+ log_debug(ckt, "%lu bytes still waiting to be sent", (unsigned long)avail);
return 0;
}
static int
-chop_send_targeted(circuit_t *c, conn_t *target, size_t blocksize)
+chop_send_targeted(chop_circuit_t *ckt, chop_conn_t *target, size_t blocksize)
{
- chop_circuit_t *ckt = static_cast<chop_circuit_t *>(c);
- struct evbuffer *xmit_pending = bufferevent_get_input(c->up_buffer);
+ struct evbuffer *xmit_pending = bufferevent_get_input(ckt->up_buffer);
size_t avail = evbuffer_get_length(xmit_pending);
struct evbuffer *block = evbuffer_new();
uint16_t flags = 0;
@@ -467,7 +466,8 @@ chop_send_targeted(circuit_t *c, conn_t *target, size_t blocksize)
evbuffer_free(block);
avail = evbuffer_get_length(xmit_pending);
if (avail)
- log_debug(c, "%lu bytes still waiting to be sent", (unsigned long)avail);
+ log_debug(ckt, "%lu bytes still waiting to be sent",
+ (unsigned long)avail);
return 0;
} else {
@@ -510,18 +510,17 @@ chop_send_targeted(circuit_t *c, conn_t *target, size_t blocksize)
}
static int
-chop_send_chaff(circuit_t *c)
+chop_send_chaff(chop_circuit_t *ckt)
{
- chop_circuit_t *ckt = static_cast<chop_circuit_t *>(c);
size_t room;
- conn_t *target = chop_pick_connection(ckt, 1, &room);
+ chop_conn_t *target = chop_pick_connection(ckt, 1, &room);
if (!target) {
/* If we have connections and we can't send, that means we're waiting
for the server to respond. Just wait. */
return 0;
}
- return chop_send_targeted(c, target, room);
+ return chop_send_targeted(ckt, target, room);
}
static void
@@ -530,7 +529,7 @@ must_transmit_timer_cb(evutil_socket_t, short, void *arg)
chop_conn_t *conn = static_cast<chop_conn_t*>(arg);
size_t room;
- if (!conn->circuit) {
+ if (!conn->upstream) {
log_debug(conn, "must transmit, but no circuit (stale connection)");
conn_do_flush(conn);
return;
@@ -547,7 +546,7 @@ must_transmit_timer_cb(evutil_socket_t, short, void *arg)
}
log_debug(conn, "must transmit");
- chop_send_targeted(conn->circuit, conn, room - CHOP_BLOCK_OVERHD);
+ chop_send_targeted(conn->upstream, conn, room - CHOP_BLOCK_OVERHD);
}
/* Receive subroutines. */
@@ -571,9 +570,9 @@ mod32_le(uint32_t s, uint32_t t)
/** Add BLOCK to the reassembly queue at the appropriate location
and merge adjacent blocks to the extent possible. */
static int
-chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
+chop_reassemble_block(chop_circuit_t *ckt, struct evbuffer *block,
+ chop_header *hdr)
{
- chop_circuit_t *ckt = static_cast<chop_circuit_t *>(c);
chop_reassembly_elt *queue = &ckt->reassembly_queue;
chop_reassembly_elt *p, *q;
@@ -583,14 +582,14 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
contents. Doing all chaff-handling here simplifies the caller
at the expense of slightly more buffer-management overhead. */
if (!(hdr->flags & (CHOP_F_SYN|CHOP_F_FIN))) {
- log_debug(c, "discarding chaff with no flags");
+ log_debug(ckt, "discarding chaff with no flags");
evbuffer_free(block);
return 0;
}
hdr->length = 0;
evbuffer_drain(block, evbuffer_get_length(block));
- log_debug(c, "chaff with flags, treating length as 0");
+ log_debug(ckt, "chaff with flags, treating length as 0");
}
/* SYN must occur at offset zero, may not be duplicated, and if we
@@ -601,7 +600,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
(queue->next != queue &&
((queue->next->flags & CHOP_F_SYN) ||
!mod32_le(hdr->offset + hdr->length, queue->next->offset))))) {
- log_warn(c, "protocol error: inappropriate SYN block");
+ log_warn(ckt, "protocol error: inappropriate SYN block");
return -1;
}
@@ -610,7 +609,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
if ((hdr->flags & CHOP_F_FIN) && queue->prev != queue &&
((queue->prev->flags & CHOP_F_FIN) ||
!mod32_le(queue->prev->offset + queue->prev->length, hdr->offset))) {
- log_warn(c, "protocol error: inappropriate FIN block");
+ log_warn(ckt, "protocol error: inappropriate FIN block");
return -1;
}
@@ -621,7 +620,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
!mod32_le(queue->next->offset + queue->next->length, hdr->offset)) ||
((queue->prev->flags & CHOP_F_FIN) &&
!mod32_le(hdr->offset + hdr->length, queue->prev->offset)))) {
- log_warn(c, "protocol error: inappropriate normal block");
+ log_warn(ckt, "protocol error: inappropriate normal block");
return -1;
}
@@ -643,7 +642,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
/* protocol error: this block goes before 'p' but does not fit
after 'p->prev' */
- log_warn(c, "protocol error: %u byte block does not fit at offset %u",
+ log_warn(ckt, "protocol error: %u byte block does not fit at offset %u",
hdr->length, hdr->offset);
return -1;
}
@@ -654,7 +653,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
that this block goes after the last block in the list (aka p->prev). */
if (!p->data && p->prev->data &&
!mod32_lt(p->prev->offset + p->prev->length, hdr->offset)) {
- log_warn(c, "protocol error: %u byte block does not fit at offset %u "
+ log_warn(ckt, "protocol error: %u byte block does not fit at offset %u "
"(sentinel case)",
hdr->length, hdr->offset);
return -1;
@@ -674,7 +673,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
grow_back:
if (evbuffer_add_buffer(p->data, block)) {
- log_warn(c, "failed to append to existing buffer");
+ log_warn(ckt, "failed to append to existing buffer");
return -1;
}
evbuffer_free(block);
@@ -685,7 +684,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
while (p->next->data && p->offset + p->length == p->next->offset) {
q = p->next;
if (evbuffer_add_buffer(p->data, q->data)) {
- log_warn(c, "failed to merge buffers");
+ log_warn(ckt, "failed to merge buffers");
return -1;
}
p->length += q->length;
@@ -700,7 +699,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
grow_front:
if (evbuffer_prepend_buffer(p->data, block)) {
- log_warn(c, "failed to prepend to existing buffer");
+ log_warn(ckt, "failed to prepend to existing buffer");
return -1;
}
evbuffer_free(block);
@@ -712,7 +711,7 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
while (p->prev->data && p->offset == p->prev->offset + p->prev->length) {
q = p->prev;
if (evbuffer_prepend_buffer(p->data, q->data)) {
- log_warn(c, "failed to merge buffers");
+ log_warn(ckt, "failed to merge buffers");
return -1;
}
p->length += q->length;
@@ -730,31 +729,31 @@ chop_reassemble_block(circuit_t *c, struct evbuffer *block, chop_header *hdr)
/* Flush as much data toward upstream as we can. */
static int
-chop_push_to_upstream(circuit_t *c)
+chop_push_to_upstream(chop_circuit_t *ckt)
{
- chop_circuit_t *ckt = static_cast<chop_circuit_t *>(c);
/* Only the first reassembly queue entry, if any, can possibly be
ready to flush (because chop_reassemble_block ensures that there
are gaps between all queue elements). */
chop_reassembly_elt *ready = ckt->reassembly_queue.next;
if (!ready->data || ckt->recv_offset != ready->offset) {
- log_debug(c, "no data pushable to upstream yet");
+ log_debug(ckt, "no data pushable to upstream yet");
return 0;
}
if (!ckt->received_syn) {
if (!(ready->flags & CHOP_F_SYN)) {
- log_debug(c, "waiting for SYN");
+ log_debug(ckt, "waiting for SYN");
return 0;
}
- log_debug(c, "processed SYN");
+ log_debug(ckt, "processed SYN");
ckt->received_syn = true;
}
- log_debug(c, "can push %lu bytes to upstream",
+ log_debug(ckt, "can push %lu bytes to upstream",
(unsigned long)evbuffer_get_length(ready->data));
- if (evbuffer_add_buffer(bufferevent_get_output(c->up_buffer), ready->data)) {
- log_warn(c, "failure pushing data to upstream");
+ if (evbuffer_add_buffer(bufferevent_get_output(ckt->up_buffer),
+ ready->data)) {
+ log_warn(ckt, "failure pushing data to upstream");
return -1;
}
@@ -765,8 +764,8 @@ chop_push_to_upstream(circuit_t *c)
log_assert(!ckt->received_fin);
log_assert(ready->next == &ckt->reassembly_queue);
ckt->received_fin = true;
- log_debug(c, "processed FIN");
- circuit_recv_eof(c);
+ log_debug(ckt, "processed FIN");
+ circuit_recv_eof(ckt);
}
log_assert(ready->next == &ckt->reassembly_queue ||
@@ -782,12 +781,12 @@ chop_push_to_upstream(circuit_t *c)
/* Circuit handling */
static int
-chop_find_or_make_circuit(conn_t *conn, uint64_t circuit_id)
+chop_find_or_make_circuit(chop_conn_t *conn, uint64_t circuit_id)
{
chop_config_t *cfg = static_cast<chop_config_t *>(conn->cfg);
chop_circuit_table::value_type in(circuit_id, 0);
std::pair<chop_circuit_table::iterator, bool> out = cfg->circuits.insert(in);
- circuit_t *ck;
+ chop_circuit_t *ck;
if (!out.second) { // element already exists
if (!out.first->second) {
@@ -797,7 +796,7 @@ chop_find_or_make_circuit(conn_t *conn, uint64_t circuit_id)
ck = out.first->second;
log_debug(conn, "found circuit to %s", ck->up_peer);
} else {
- ck = circuit_create(cfg, 0);
+ ck = dynamic_cast<chop_circuit_t *>(circuit_create(cfg, 0));
if (!ck) {
log_warn(conn, "failed to create new circuit");
return -1;
@@ -808,7 +807,7 @@ chop_find_or_make_circuit(conn_t *conn, uint64_t circuit_id)
return -1;
}
log_debug(conn, "created new circuit to %s", ck->up_peer);
- static_cast<chop_circuit_t *>(ck)->circuit_id = circuit_id;
+ ck->circuit_id = circuit_id;
out.first->second = ck;
}
@@ -978,10 +977,10 @@ chop_circuit_t::~chop_circuit_t()
upstream_eof ? '+' : '-',
(unsigned long)downstreams.size());
- for (unordered_set<conn_t *>::iterator i = this->downstreams.begin();
+ for (unordered_set<chop_conn_t *>::iterator i = this->downstreams.begin();
i != this->downstreams.end(); i++) {
- conn_t *conn = *i;
- conn->circuit = NULL;
+ chop_conn_t *conn = *i;
+ conn->upstream = NULL;
if (evbuffer_get_length(conn_get_outbound(conn)) > 0)
conn_do_flush(conn);
else
@@ -1016,9 +1015,15 @@ chop_circuit_t::~chop_circuit_t()
}
void
-chop_circuit_t::add_downstream(conn_t *conn)
+chop_circuit_t::add_downstream(conn_t *cn)
{
+ chop_conn_t *conn = dynamic_cast<chop_conn_t *>(cn);
+ log_assert(conn);
+ log_assert(!conn->upstream);
+
+ conn->upstream = this;
this->downstreams.insert(conn);
+
log_debug(this, "added connection <%d.%d> to %s, now %lu",
this->serial, conn->serial, conn->peername,
(unsigned long)this->downstreams.size());
@@ -1027,9 +1032,15 @@ chop_circuit_t::add_downstream(conn_t *conn)
}
void
-chop_circuit_t::drop_downstream(conn_t *conn)
+chop_circuit_t::drop_downstream(conn_t *cn)
{
+ chop_conn_t *conn = dynamic_cast<chop_conn_t *>(cn);
+ log_assert(conn);
+ log_assert(conn->upstream == this);
+
+ conn->upstream = NULL;
this->downstreams.erase(conn);
+
log_debug(this, "dropped connection <%d.%d> to %s, now %lu",
this->serial, conn->serial, conn->peername,
(unsigned long)this->downstreams.size());
@@ -1078,6 +1089,8 @@ chop_conn_t::chop_conn_t()
chop_conn_t::~chop_conn_t()
{
+ if (this->upstream)
+ circuit_drop_downstream(this->upstream, this);
if (this->steg)
delete this->steg;
if (this->must_transmit_timer)
@@ -1085,6 +1098,12 @@ chop_conn_t::~chop_conn_t()
evbuffer_free(this->recv_pending);
}
+circuit_t *
+chop_conn_t::circuit() const
+{
+ return this->upstream;
+}
+
int
chop_conn_t::maybe_open_upstream()
{
@@ -1104,7 +1123,7 @@ chop_conn_t::handshake()
server can't even _connect to its upstream_ till it gets the
first packet from the client. */
if (this->cfg->mode != LSN_SIMPLE_SERVER)
- circuit_arm_flush_timer(this->circuit, 1);
+ circuit_arm_flush_timer(this->upstream, 1);
return 0;
}
@@ -1143,9 +1162,9 @@ chop_circuit_t::send()
as long as we haven't both sent and received a FIN, or we might
deadlock. */
if (this->sent_fin && this->received_fin) {
- for (unordered_set<conn_t *>::iterator i = this->downstreams.begin();
+ for (unordered_set<chop_conn_t *>::iterator i = this->downstreams.begin();
i != this->downstreams.end(); i++) {
- chop_conn_t *conn = static_cast<chop_conn_t*>(*i);
+ chop_conn_t *conn = *i;
if (conn->must_transmit_timer &&
evtimer_pending(conn->must_transmit_timer, NULL))
must_transmit_timer_cb(-1, 0, conn);
@@ -1168,7 +1187,6 @@ chop_circuit_t::send_eof()
int
chop_conn_t::recv()
{
- circuit_t *c;
chop_circuit_t *ckt;
chop_header hdr;
struct evbuffer *block;
@@ -1178,7 +1196,7 @@ chop_conn_t::recv()
if (this->steg->receive(this, this->recv_pending))
return -1;
- if (!this->circuit) {
+ if (!this->upstream) {
log_debug(this, "finding circuit");
if (chop_peek_circuit_id(this->recv_pending, &hdr)) {
log_debug(this, "not enough data to find circuit yet");
@@ -1193,7 +1211,7 @@ chop_conn_t::recv()
it's either chaff or a protocol error; either way we can just
discard it. Since we will never reply, call conn_do_flush so
the connection will be dropped as soon as we receive an EOF. */
- if (!this->circuit) {
+ if (!this->upstream) {
evbuffer_drain(this->recv_pending,
evbuffer_get_length(this->recv_pending));
conn_do_flush(this);
@@ -1201,9 +1219,8 @@ chop_conn_t::recv()
}
}
- c = this->circuit;
- ckt = static_cast<chop_circuit_t *>(c);
- log_debug(this, "circuit to %s", c->up_peer);
+ ckt = this->upstream;
+ log_debug(this, "circuit to %s", ckt->up_peer);
for (;;) {
avail = evbuffer_get_length(this->recv_pending);
@@ -1269,18 +1286,18 @@ chop_conn_t::recv()
return -1;
}
- if (chop_reassemble_block(c, block, &hdr)) {
+ if (chop_reassemble_block(ckt, block, &hdr)) {
evbuffer_free(block);
return -1;
}
}
- if (chop_push_to_upstream(c))
+ if (chop_push_to_upstream(ckt))
return -1;
/* It may have now become possible to send queued data. */
- if (evbuffer_get_length(bufferevent_get_input(c->up_buffer)))
- c->send();
+ if (evbuffer_get_length(bufferevent_get_input(ckt->up_buffer)))
+ ckt->send();
/* If we're at EOF, close all connections (sending first if
necessary). If we're the client we have to keep trying to talk
@@ -1288,9 +1305,9 @@ chop_conn_t::recv()
deadlock. */
else if (ckt->sent_fin && ckt->received_fin) {
circuit_disarm_flush_timer(ckt);
- for (unordered_set<conn_t *>::iterator i = ckt->downstreams.begin();
+ for (unordered_set<chop_conn_t *>::iterator i = ckt->downstreams.begin();
i != ckt->downstreams.end(); i++) {
- chop_conn_t *conn = static_cast<chop_conn_t*>(*i);
+ chop_conn_t *conn = *i;
if (conn->must_transmit_timer &&
evtimer_pending(conn->must_transmit_timer, NULL))
must_transmit_timer_cb(-1, 0, conn);
@@ -1312,8 +1329,8 @@ chop_conn_t::recv_eof()
We should only drop the connection from the circuit if we're no
longer sending in the opposite direction. Also, we should not
drop the connection if its must-transmit timer is still pending. */
- if (this->circuit) {
- chop_circuit_t *ckt = static_cast<chop_circuit_t *>(this->circuit);
+ if (this->upstream) {
+ chop_circuit_t *ckt = this->upstream;
if (evbuffer_get_length(conn_get_inbound(this)) > 0)
if (this->recv())
diff --git a/src/protocol/null.cc b/src/protocol/null.cc
index 27a9320..be89821 100644
--- a/src/protocol/null.cc
+++ b/src/protocol/null.cc
@@ -9,19 +9,26 @@
#include <event2/buffer.h>
namespace {
- struct null_config_t : config_t {
+ struct null_config_t : config_t
+ {
struct evutil_addrinfo *listen_addr;
struct evutil_addrinfo *target_addr;
CONFIG_DECLARE_METHODS(null);
};
- struct null_conn_t : conn_t {
+ struct null_circuit_t;
+
+ struct null_conn_t : conn_t
+ {
+ null_circuit_t *upstream;
+
CONN_DECLARE_METHODS(null);
};
- struct null_circuit_t : circuit_t {
- conn_t *downstream;
+ struct null_circuit_t : circuit_t
+ {
+ null_conn_t *downstream;
CIRCUIT_DECLARE_METHODS(null);
};
@@ -112,12 +119,13 @@ null_config_t::get_target_addrs(size_t n)
circuit_t *
null_config_t::circuit_create(size_t)
{
- circuit_t *ckt = new null_circuit_t;
+ null_circuit_t *ckt = new null_circuit_t;
ckt->cfg = this;
return ckt;
}
null_circuit_t::null_circuit_t()
+ : downstream(NULL)
{
}
@@ -126,17 +134,23 @@ null_circuit_t::~null_circuit_t()
if (downstream) {
/* break the circular reference before deallocating the
downstream connection */
- downstream->circuit = NULL;
+ downstream->upstream = NULL;
delete downstream;
}
}
/* Add a connection to this circuit. */
void
-null_circuit_t::add_downstream(conn_t *conn)
+null_circuit_t::add_downstream(conn_t *cn)
{
+ null_conn_t *conn = dynamic_cast<null_conn_t *>(cn);
+ log_assert(conn);
+ log_assert(!conn->upstream);
log_assert(!this->downstream);
+
this->downstream = conn;
+ conn->upstream = this;
+
log_debug(this, "added connection <%d.%d> to %s",
this->serial, conn->serial, conn->peername);
}
@@ -145,12 +159,18 @@ null_circuit_t::add_downstream(conn_t *conn)
protocol, it is because of a network error, and the whole circuit
should be closed. */
void
-null_circuit_t::drop_downstream(conn_t *conn)
+null_circuit_t::drop_downstream(conn_t *cn)
{
+ null_conn_t *conn = dynamic_cast<null_conn_t *>(cn);
+ log_assert(conn);
log_assert(this->downstream == conn);
+ log_assert(conn->upstream == this);
+
log_debug(this, "dropped connection <%d.%d> to %s",
this->serial, conn->serial, conn->peername);
this->downstream = NULL;
+ conn->upstream = NULL;
+
if (evbuffer_get_length(bufferevent_get_output(this->up_buffer)) > 0)
/* this may already have happened, but there's no harm in
doing it again */
@@ -190,18 +210,29 @@ null_config_t::conn_create(size_t)
}
null_conn_t::null_conn_t()
+ : upstream(NULL)
{
}
null_conn_t::~null_conn_t()
{
+ if (this->upstream)
+ circuit_drop_downstream(this->upstream, this);
+}
+
+/* Only used by connection callbacks */
+circuit_t *
+null_conn_t::circuit() const
+{
+ return upstream;
}
/** Null inbound-to-outbound connections are 1:1 */
int
null_conn_t::maybe_open_upstream()
{
- circuit_t *ckt = circuit_create(this->cfg, 0);
+ null_circuit_t *ckt = dynamic_cast<null_circuit_t *>
+ (circuit_create(this->cfg, 0));
if (!ckt)
return -1;
@@ -221,8 +252,8 @@ null_conn_t::handshake()
int
null_conn_t::recv()
{
- log_assert(this->circuit);
- return evbuffer_add_buffer(bufferevent_get_output(this->circuit->up_buffer),
+ log_assert(this->upstream);
+ return evbuffer_add_buffer(bufferevent_get_output(this->upstream->up_buffer),
conn_get_inbound(this));
}
@@ -230,12 +261,12 @@ null_conn_t::recv()
int
null_conn_t::recv_eof()
{
- if (this->circuit) {
+ if (this->upstream) {
if (evbuffer_get_length(conn_get_inbound(this)) > 0)
if (this->recv())
return -1;
- circuit_recv_eof(this->circuit);
+ circuit_recv_eof(this->upstream);
}
return 0;
}
diff --git a/src/util.cc b/src/util.cc
index 9cca1fd..7273671 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -595,10 +595,11 @@ logpfx(int severity, const char *fn, conn_t *conn)
fprintf(log_dest, "[%s] ", sev_to_string(severity));
if (log_min_sev == LOG_SEV_DEBUG && fn)
fprintf(log_dest, "%s: ", fn);
- if (conn)
- fprintf(log_dest, "<%u.%u> ",
- conn->circuit ? conn->circuit->serial : 0,
- conn->serial);
+ if (conn) {
+ circuit_t *ckt = conn->circuit();
+ unsigned int ckt_serial = ckt ? ckt->serial : 0;
+ fprintf(log_dest, "<%u.%u> ", ckt_serial, conn->serial);
+ }
}
/**** Public logging API. ****/
1
0
20 Jul '12
commit 4ca5efe9651cccaaa0e0f2272dae57cd024fea52
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Feb 27 16:46:47 2012 -0800
Remove ->cfg pointer from the generic conn_t.
---
src/connections.h | 1 -
src/protocol.h | 3 +--
src/protocol/chop.cc | 4 +++-
src/protocol/null.cc | 1 +
4 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/connections.h b/src/connections.h
index b0cac55..103e246 100644
--- a/src/connections.h
+++ b/src/connections.h
@@ -14,7 +14,6 @@
Connections are associated with circuits (and thus with upstream
socket-level connections) as quickly as possible. */
struct conn_t {
- config_t *cfg;
const char *peername;
struct bufferevent *buffer;
unsigned int serial;
diff --git a/src/protocol.h b/src/protocol.h
index d28bf19..98ad39c 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -61,8 +61,7 @@ struct config_t
/** Return an extended 'conn_t' object for a new socket using this
configuration. The 'index' argument is equal to the 'N'
argument to get_listen_addrs or get_target_addrs that retrieved
- the address to which the socket is bound. Must fill in the
- 'cfg' field of the generic structure. */
+ the address to which the socket is bound. */
virtual conn_t *conn_create(size_t index) = 0;
};
diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index 536481c..db284cb 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -72,11 +72,13 @@ static const uint8_t s2c_key[] =
/* Connections and circuits */
namespace {
+ struct chop_config_t;
struct chop_circuit_t;
typedef unordered_map<uint64_t, chop_circuit_t *> chop_circuit_table;
struct chop_conn_t : conn_t
{
+ chop_config_t *cfg;
chop_circuit_t *upstream;
steg_t *steg;
struct evbuffer *recv_pending;
@@ -783,7 +785,7 @@ chop_push_to_upstream(chop_circuit_t *ckt)
static int
chop_find_or_make_circuit(chop_conn_t *conn, uint64_t circuit_id)
{
- chop_config_t *cfg = static_cast<chop_config_t *>(conn->cfg);
+ chop_config_t *cfg = conn->cfg;
chop_circuit_table::value_type in(circuit_id, 0);
std::pair<chop_circuit_table::iterator, bool> out = cfg->circuits.insert(in);
chop_circuit_t *ck;
diff --git a/src/protocol/null.cc b/src/protocol/null.cc
index be89821..6b471a0 100644
--- a/src/protocol/null.cc
+++ b/src/protocol/null.cc
@@ -21,6 +21,7 @@ namespace {
struct null_conn_t : conn_t
{
+ null_config_t *cfg;
null_circuit_t *upstream;
CONN_DECLARE_METHODS(null);
1
0
[stegotorus/master] Remove ->cfg pointer from the generic circuit_t.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit 86875f153137994c56214d75cca8292cb33e28a8
Author: Zack Weinberg <zackw(a)cmu.edu>
Date: Mon Feb 27 17:10:33 2012 -0800
Remove ->cfg pointer from the generic circuit_t.
---
src/connections.cc | 10 ++++++++--
src/connections.h | 4 +++-
src/network.cc | 14 +++++++-------
src/protocol.h | 4 ++--
src/protocol/chop.cc | 36 +++++++++++++++++++++---------------
src/protocol/null.cc | 15 +++++++++++----
6 files changed, 52 insertions(+), 31 deletions(-)
diff --git a/src/connections.cc b/src/connections.cc
index 37eaba3..f16d71e 100644
--- a/src/connections.cc
+++ b/src/connections.cc
@@ -272,6 +272,12 @@ circuit_t::~circuit_t()
maybe_finish_shutdown();
}
+config_t *
+circuit_t::cfg() const
+{
+ return 0;
+}
+
void
circuit_close(circuit_t *ckt)
{
@@ -368,7 +374,7 @@ circuit_arm_flush_timer(circuit_t *ckt, unsigned int milliseconds)
tv.tv_usec = (milliseconds % 1000) * 1000;
if (!ckt->flush_timer)
- ckt->flush_timer = evtimer_new(ckt->cfg->base, flush_timer_cb, ckt);
+ ckt->flush_timer = evtimer_new(ckt->cfg()->base, flush_timer_cb, ckt);
evtimer_add(ckt->flush_timer, &tv);
}
@@ -390,7 +396,7 @@ circuit_arm_axe_timer(circuit_t *ckt, unsigned int milliseconds)
tv.tv_usec = (milliseconds % 1000) * 1000;
if (!ckt->axe_timer)
- ckt->axe_timer = evtimer_new(ckt->cfg->base, axe_timer_cb, ckt);
+ ckt->axe_timer = evtimer_new(ckt->cfg()->base, axe_timer_cb, ckt);
evtimer_add(ckt->axe_timer, &tv);
}
diff --git a/src/connections.h b/src/connections.h
index 103e246..099a8a6 100644
--- a/src/connections.h
+++ b/src/connections.h
@@ -146,7 +146,6 @@ void conn_transmit_soon(conn_t *conn, unsigned long timeout);
*/
struct circuit_t {
- config_t *cfg;
struct event *flush_timer;
struct event *axe_timer;
struct bufferevent *up_buffer;
@@ -161,6 +160,9 @@ struct circuit_t {
circuit_t() : connected(false), flushing(false), pending_eof(false) {}
virtual ~circuit_t();
+ /** Return the configuration that this circuit belongs to. */
+ virtual config_t *cfg() const;
+
/** Add a downstream connection to this circuit. */
virtual void add_downstream(conn_t *conn) = 0;
diff --git a/src/network.cc b/src/network.cc
index 3ecb378..3cbc1e7 100644
--- a/src/network.cc
+++ b/src/network.cc
@@ -250,7 +250,7 @@ socks_read_cb(struct bufferevent *bev, void *arg)
circuit_t *ckt = (circuit_t *)arg;
socks_state_t *socks;
enum socks_ret socks_ret;
- log_assert(ckt->cfg->mode == LSN_SOCKS_CLIENT);
+ log_assert(ckt->cfg()->mode == LSN_SOCKS_CLIENT);
log_assert(ckt->socks_state);
socks = ckt->socks_state;
@@ -639,14 +639,14 @@ circuit_open_upstream(circuit_t *ckt)
struct bufferevent *buf;
char *peername;
- addr = ckt->cfg->get_target_addrs(0);
+ addr = ckt->cfg()->get_target_addrs(0);
if (!addr) {
log_warn(ckt, "no target addresses available");
return -1;
}
- buf = bufferevent_socket_new(ckt->cfg->base, -1, BEV_OPT_CLOSE_ON_FREE);
+ buf = bufferevent_socket_new(ckt->cfg()->base, -1, BEV_OPT_CLOSE_ON_FREE);
if (!buf) {
log_warn(ckt, "unable to create outbound socket buffer");
return -1;
@@ -681,7 +681,7 @@ static bool
create_one_outbound_connection(circuit_t *ckt, struct evutil_addrinfo *addr,
size_t index, bool is_socks)
{
- config_t *cfg = ckt->cfg;
+ config_t *cfg = ckt->cfg();
char *peername;
struct bufferevent *buf;
conn_t *conn;
@@ -726,7 +726,7 @@ create_outbound_connections(circuit_t *ckt, bool is_socks)
size_t n = 0;
bool any_successes = false;
- while ((addr = ckt->cfg->get_target_addrs(n))) {
+ while ((addr = ckt->cfg()->get_target_addrs(n))) {
any_successes |= create_one_outbound_connection(ckt, addr, n, is_socks);
n++;
}
@@ -750,7 +750,7 @@ circuit_reopen_downstreams(circuit_t *ckt)
static void
create_outbound_connections_socks(circuit_t *ckt)
{
- config_t *cfg = ckt->cfg;
+ config_t *cfg = ckt->cfg();
struct bufferevent *buf = NULL;
conn_t *conn;
const char *host;
@@ -765,7 +765,7 @@ create_outbound_connections_socks(circuit_t *ckt)
/* XXXX Feed socks state through the protocol and get a connection set.
This is a stopgap. */
- if (ckt->cfg->ignore_socks_destination) {
+ if (ckt->cfg()->ignore_socks_destination) {
create_outbound_connections(ckt, true);
return;
}
diff --git a/src/protocol.h b/src/protocol.h
index 9643b1a..a0aca6a 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -54,8 +54,7 @@ struct config_t
/** Return an extended 'circuit_t' object for a new socket using
this configuration. The 'index' argument is equal to the 'N'
argument to get_listen_addrs or get_target_addrs that retrieved
- the address to which the socket is bound. Must fill in the
- 'cfg' field of the generic structure. */
+ the address to which the socket is bound. */
virtual circuit_t *circuit_create(size_t index) = 0;
/** Return an extended 'conn_t' object for a new socket using this
@@ -141,6 +140,7 @@ extern const proto_module *const supported_protos[];
#define CIRCUIT_DECLARE_METHODS(mod) \
mod##_circuit_t(); \
virtual ~mod##_circuit_t(); \
+ virtual config_t *cfg() const; \
virtual void add_downstream(conn_t *); \
virtual void drop_downstream(conn_t *); \
virtual int send(); \
diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index db284cb..832d11b 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -78,7 +78,7 @@ namespace {
struct chop_conn_t : conn_t
{
- chop_config_t *cfg;
+ chop_config_t *config;
chop_circuit_t *upstream;
steg_t *steg;
struct evbuffer *recv_pending;
@@ -94,6 +94,7 @@ namespace {
unordered_set<chop_conn_t *> downstreams;
encryptor *send_crypt;
decryptor *recv_crypt;
+ chop_config_t *config;
uint64_t circuit_id;
uint32_t send_offset;
@@ -785,9 +786,9 @@ chop_push_to_upstream(chop_circuit_t *ckt)
static int
chop_find_or_make_circuit(chop_conn_t *conn, uint64_t circuit_id)
{
- chop_config_t *cfg = conn->cfg;
chop_circuit_table::value_type in(circuit_id, 0);
- std::pair<chop_circuit_table::iterator, bool> out = cfg->circuits.insert(in);
+ std::pair<chop_circuit_table::iterator, bool> out
+ = conn->config->circuits.insert(in);
chop_circuit_t *ck;
if (!out.second) { // element already exists
@@ -798,7 +799,7 @@ chop_find_or_make_circuit(chop_conn_t *conn, uint64_t circuit_id)
ck = out.first->second;
log_debug(conn, "found circuit to %s", ck->up_peer);
} else {
- ck = dynamic_cast<chop_circuit_t *>(circuit_create(cfg, 0));
+ ck = dynamic_cast<chop_circuit_t *>(circuit_create(conn->config, 0));
if (!ck) {
log_warn(conn, "failed to create new circuit");
return -1;
@@ -943,7 +944,7 @@ circuit_t *
chop_config_t::circuit_create(size_t)
{
chop_circuit_t *ckt = new chop_circuit_t;
- ckt->cfg = this;
+ ckt->config = this;
if (this->mode == LSN_SIMPLE_SERVER) {
ckt->send_crypt = encryptor::create(s2c_key, 16);
@@ -1009,13 +1010,18 @@ chop_circuit_t::~chop_circuit_t()
message and the hidden channel closed s->c before c->s: the
circuit will get destroyed on the client side after the c->s FIN,
and the mandatory reply will be to a stale circuit. */
- chop_config_t *cfg = static_cast<chop_config_t *>(this->cfg);
- out = cfg->circuits.find(this->circuit_id);
- log_assert(out != cfg->circuits.end());
+ out = this->config->circuits.find(this->circuit_id);
+ log_assert(out != this->config->circuits.end());
log_assert(out->second == this);
out->second = NULL;
}
+config_t *
+chop_circuit_t::cfg() const
+{
+ return this->config;
+}
+
void
chop_circuit_t::add_downstream(conn_t *cn)
{
@@ -1061,7 +1067,7 @@ chop_circuit_t::drop_downstream(conn_t *cn)
circuit_do_flush(this);
else
circuit_close(this);
- } else if (this->cfg->mode == LSN_SIMPLE_SERVER) {
+ } else if (this->config->mode == LSN_SIMPLE_SERVER) {
circuit_arm_axe_timer(this, this->axe_interval());
} else {
circuit_arm_flush_timer(this, this->flush_interval());
@@ -1073,7 +1079,7 @@ conn_t *
chop_config_t::conn_create(size_t index)
{
chop_conn_t *conn = new chop_conn_t;
- conn->cfg = this;
+ conn->config = this;
conn->steg = steg_new(this->steg_targets.at(index),
this->mode != LSN_SIMPLE_SERVER);
if (!conn->steg) {
@@ -1124,7 +1130,7 @@ chop_conn_t::handshake()
instead of a 10ms timeout as in dsteg, because unlike there, the
server can't even _connect to its upstream_ till it gets the
first packet from the client. */
- if (this->cfg->mode != LSN_SIMPLE_SERVER)
+ if (this->config->mode != LSN_SIMPLE_SERVER)
circuit_arm_flush_timer(this->upstream, 1);
return 0;
}
@@ -1140,7 +1146,7 @@ chop_circuit_t::send()
bring us back here. If we're the server, we have to just
twiddle our thumbs and hope the client reconnects. */
log_debug(this, "no downstream connections");
- if (this->cfg->mode != LSN_SIMPLE_SERVER)
+ if (this->config->mode != LSN_SIMPLE_SERVER)
circuit_reopen_downstreams(this);
else
circuit_arm_axe_timer(this, this->axe_interval());
@@ -1173,7 +1179,7 @@ chop_circuit_t::send()
conn_send_eof(conn);
}
} else {
- if (this->cfg->mode != LSN_SIMPLE_SERVER)
+ if (this->config->mode != LSN_SIMPLE_SERVER)
circuit_arm_flush_timer(this, this->flush_interval());
}
return 0;
@@ -1316,7 +1322,7 @@ chop_conn_t::recv()
conn_send_eof(conn);
}
} else {
- if (ckt->cfg->mode != LSN_SIMPLE_SERVER)
+ if (ckt->config->mode != LSN_SIMPLE_SERVER)
circuit_arm_flush_timer(ckt, ckt->flush_interval());
}
@@ -1377,7 +1383,7 @@ chop_conn_t::transmit_soon(unsigned long milliseconds)
tv.tv_usec = (milliseconds % 1000) * 1000;
if (!this->must_transmit_timer)
- this->must_transmit_timer = evtimer_new(this->cfg->base,
+ this->must_transmit_timer = evtimer_new(this->config->base,
must_transmit_timer_cb, this);
evtimer_add(this->must_transmit_timer, &tv);
}
diff --git a/src/protocol/null.cc b/src/protocol/null.cc
index 6b471a0..51ea744 100644
--- a/src/protocol/null.cc
+++ b/src/protocol/null.cc
@@ -21,7 +21,7 @@ namespace {
struct null_conn_t : conn_t
{
- null_config_t *cfg;
+ null_config_t *config;
null_circuit_t *upstream;
CONN_DECLARE_METHODS(null);
@@ -29,6 +29,7 @@ namespace {
struct null_circuit_t : circuit_t
{
+ null_config_t *config;
null_conn_t *downstream;
CIRCUIT_DECLARE_METHODS(null);
@@ -121,7 +122,7 @@ circuit_t *
null_config_t::circuit_create(size_t)
{
null_circuit_t *ckt = new null_circuit_t;
- ckt->cfg = this;
+ ckt->config = this;
return ckt;
}
@@ -140,6 +141,12 @@ null_circuit_t::~null_circuit_t()
}
}
+config_t *
+null_circuit_t::cfg() const
+{
+ return this->config;
+}
+
/* Add a connection to this circuit. */
void
null_circuit_t::add_downstream(conn_t *cn)
@@ -206,7 +213,7 @@ conn_t *
null_config_t::conn_create(size_t)
{
null_conn_t *conn = new null_conn_t;
- conn->cfg = this;
+ conn->config = this;
return conn;
}
@@ -233,7 +240,7 @@ int
null_conn_t::maybe_open_upstream()
{
null_circuit_t *ckt = dynamic_cast<null_circuit_t *>
- (circuit_create(this->cfg, 0));
+ (circuit_create(this->config, 0));
if (!ckt)
return -1;
1
0
[stegotorus/master] Remove wrapper functions for steg-to-conn hint methods.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit e7f71a5aa2084c9678c2cbfd83486491e16ca85c
Author: Zack Weinberg <zackw(a)panix.com>
Date: Tue Feb 28 09:50:36 2012 -0800
Remove wrapper functions for steg-to-conn hint methods.
Also removes the distinction between cease_transmission() and
close_after_transmit(), which turned out to be unnecessary.
---
src/connections.cc | 26 --------------------------
src/connections.h | 33 ++++++---------------------------
src/protocol.h | 3 ---
src/protocol/chop.cc | 7 -------
src/steg/embed.cc | 16 ++++++++--------
src/steg/http.cc | 6 +++---
src/steg/jsSteg.cc | 5 ++---
src/steg/nosteg_rr.cc | 10 +++-------
src/steg/pdfSteg.cc | 4 ++--
src/steg/swfSteg.cc | 6 ++----
10 files changed, 26 insertions(+), 90 deletions(-)
diff --git a/src/connections.cc b/src/connections.cc
index f116231..39191b2 100644
--- a/src/connections.cc
+++ b/src/connections.cc
@@ -146,32 +146,6 @@ conn_send_eof(conn_t *dest)
} /* otherwise, it's already been done */
}
-/* Protocol methods of connections. */
-
-void
-conn_expect_close(conn_t *conn)
-{
- conn->expect_close();
-}
-
-void
-conn_cease_transmission(conn_t *conn)
-{
- conn->cease_transmission();
-}
-
-void
-conn_close_after_transmit(conn_t *conn)
-{
- conn->close_after_transmit();
-}
-
-void
-conn_transmit_soon(conn_t *conn, unsigned long timeout)
-{
- conn->transmit_soon(timeout);
-}
-
/* Circuits. */
/* The flush timer is used to ensure forward progress for protocols
diff --git a/src/connections.h b/src/connections.h
index 2b6388b..9b51ce5 100644
--- a/src/connections.h
+++ b/src/connections.h
@@ -60,8 +60,9 @@ struct conn_t {
depending on the protocol. */
virtual int recv_eof() = 0;
- /* The next four methods are for the use of steganography modules.
- If you don't use steganography modules, you can use protocol.h's
+ /* The next several conn_t methods are used by steganography modules
+ to provide hints about appropriate higher-level behavior.
+ If your protocol doesn't use steganography modules, use protocol.h's
PROTO_STEG_STUBS to define stubs that crash if called. */
/** It is an error if any further data is received from the remote
@@ -72,10 +73,6 @@ struct conn_t {
on this connection. However, the peer may still send data back. */
virtual void cease_transmission() = 0;
- /** After all pending data is transmitted, close this connection.
- (This is stronger than cease_transmission - no reply is expected.) */
- virtual void close_after_transmit() = 0;
-
/** If TIMEOUT milliseconds elapse without anything having been
transmitted on this connection, you need to make up some data
and send it. */
@@ -84,9 +81,9 @@ struct conn_t {
/** When all currently-open connections and circuits are closed, stop
the main event loop and exit the program. If 'barbaric' is true,
- forcibly close them all now, then stop the event loop. It
- is a bug to call any function that creates connections or circuits
- after conn_start_shutdown has been called. */
+ forcibly close them all now, then stop the event loop.
+ It is a bug to call any function that creates connections or
+ circuits after conn_start_shutdown has been called. */
void conn_start_shutdown(int barbaric);
/** Create a new inbound connection from a configuration and a
@@ -100,24 +97,6 @@ size_t conn_count(void);
void conn_send_eof(conn_t *conn);
void conn_do_flush(conn_t *conn);
-/* The next several conn_t methods are used by steganography modules to
- provide hints about appropriate higher-level behavior. */
-
-/** The peer is expected to close CONN without any further
- transmissions. */
-void conn_expect_close(conn_t *conn);
-
-/** Do not transmit any more data on this connection after the outbound
- queue has drained. However, the peer may still send data back. */
-void conn_cease_transmission(conn_t *conn);
-
-/** Close CONN after all pending data is transmitted. */
-void conn_close_after_transmit(conn_t *conn);
-
-/** We must transmit something on this connection within TIMEOUT
- milliseconds. */
-void conn_transmit_soon(conn_t *conn, unsigned long timeout);
-
/**
This struct holds all the state for an "upstream" connection to the
higher-level client or server that we are proxying traffic for. It
diff --git a/src/protocol.h b/src/protocol.h
index a0aca6a..4f0d6cd 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -123,7 +123,6 @@ extern const proto_module *const supported_protos[];
virtual int recv_eof(); \
virtual void expect_close(); \
virtual void cease_transmission(); \
- virtual void close_after_transmit(); \
virtual void transmit_soon(unsigned long timeout) \
/* deliberate absence of semicolon */
@@ -132,8 +131,6 @@ extern const proto_module *const supported_protos[];
{ log_abort(this, "steg stub called"); } \
void mod##_conn_t::cease_transmission() \
{ log_abort(this, "steg stub called"); } \
- void mod##_conn_t::close_after_transmit() \
- { log_abort(this, "steg stub called"); } \
void mod##_conn_t::transmit_soon(unsigned long) \
{ log_abort(this, "steg stub called"); }
diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index d7607c4..82badde 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -1366,13 +1366,6 @@ chop_conn_t::cease_transmission()
}
void
-chop_conn_t::close_after_transmit()
-{
- this->no_more_transmissions = true;
- conn_do_flush(this);
-}
-
-void
chop_conn_t::transmit_soon(unsigned long milliseconds)
{
struct timeval tv;
diff --git a/src/steg/embed.cc b/src/steg/embed.cc
index 1f14716..e2f12a0 100644
--- a/src/steg/embed.cc
+++ b/src/steg/embed.cc
@@ -166,10 +166,10 @@ int embed::transmit(struct evbuffer *source, conn_t *conn) {
// check if this trace is finished and whether we need to send again
if (advance_packet()) {
log_debug("send finished trace");
- conn_close_after_transmit(conn);
+ conn->cease_transmission();
} else if (is_outgoing()) {
log_debug("sending again in %d ms", get_pkt_time());
- conn_transmit_soon(conn, get_pkt_time());
+ conn->transmit_soon(get_pkt_time());
}
// update last time
@@ -210,23 +210,23 @@ int embed::receive(conn_t *conn, struct evbuffer *dest) {
}
}
pkt_size += data_len + 2;
-
+
// read padding
if (exp_pkt_size > pkt_size) {
size_t padding = exp_pkt_size - pkt_size;
if (evbuffer_drain(source, padding) == -1) return -1;
}
-
+
src_len -= exp_pkt_size;
pkt_size = 0;
log_debug("received packet %d of trace %d",
cur_pkt, cur_idx);
-
+
// advance packet; if done with trace, sender should close connection
if (advance_packet()) {
- conn_cease_transmission(conn);
- conn_expect_close(conn);
+ conn->cease_transmission();
+ conn->expect_close();
log_debug("received last packet in trace");
return 0;
}
@@ -234,7 +234,7 @@ int embed::receive(conn_t *conn, struct evbuffer *dest) {
if (is_outgoing()) {
log_debug("preparing to send in %d ms", get_pkt_time());
- conn_transmit_soon(conn, get_pkt_time());
+ conn->transmit_soon(get_pkt_time());
}
log_debug("remaining source length: %d", src_len);
diff --git a/src/steg/http.cc b/src/steg/http.cc
index aa57b63..302571d 100644
--- a/src/steg/http.cc
+++ b/src/steg/http.cc
@@ -369,7 +369,7 @@ http_client_cookie_transmit (http *s, struct evbuffer *source, conn_t *conn) {
evbuffer_drain(source, sbuflen);
log_debug("CLIENT TRANSMITTED payload %d\n", (int) sbuflen);
- conn_cease_transmission(conn);
+ conn->cease_transmission();
s->type = find_uri_type(buf, bufsize);
s->have_transmitted = true;
@@ -530,7 +530,7 @@ http_client_uri_transmit (http *s, struct evbuffer *source, conn_t *conn) {
evbuffer_drain(source, slen);
- conn_cease_transmission(conn);
+ conn->cease_transmission();
s->type = find_uri_type(outbuf, sizeof(outbuf));
s->have_transmitted = 1;
return 0;
@@ -694,7 +694,7 @@ http_server_receive(http *s, conn_t *conn, struct evbuffer *dest, struct evbuffe
s->have_received = 1;
s->type = type;
- conn_transmit_soon(conn, 100);
+ conn->transmit_soon(100);
return RECV_GOOD;
}
diff --git a/src/steg/jsSteg.cc b/src/steg/jsSteg.cc
index 8bc56de..335b78e 100644
--- a/src/steg/jsSteg.cc
+++ b/src/steg/jsSteg.cc
@@ -874,7 +874,7 @@ http_server_JS_transmit (steg_t*, struct evbuffer *source, conn_t *conn, unsigne
evbuffer_drain(source, sbuflen);
free(outbuf2);
- conn_close_after_transmit(conn);
+ conn->cease_transmission();
// downcast_steg(s)->have_transmitted = 1;
return 0;
}
@@ -1075,8 +1075,7 @@ http_handle_client_JS_receive(steg_t *, conn_t *conn, struct evbuffer *dest, str
log_debug("Drained source for %d char\n", response_len);
// downcast_steg(s)->have_received = 1;
- conn_expect_close(conn);
-
+ conn->expect_close();
return RECV_GOOD;
}
diff --git a/src/steg/nosteg_rr.cc b/src/steg/nosteg_rr.cc
index 3aa543d..a586d0a 100644
--- a/src/steg/nosteg_rr.cc
+++ b/src/steg/nosteg_rr.cc
@@ -80,11 +80,7 @@ nosteg_rr::transmit(struct evbuffer *source, conn_t *conn)
}
can_transmit = false;
- if (is_clientside) {
- conn_cease_transmission(conn);
- } else {
- conn_close_after_transmit(conn);
- }
+ conn->cease_transmission();
return 0;
}
@@ -104,10 +100,10 @@ nosteg_rr::receive(conn_t *conn, struct evbuffer *dest)
}
if (is_clientside) {
- conn_expect_close(conn);
+ conn->expect_close();
} else {
can_transmit = true;
- conn_transmit_soon(conn, 100);
+ conn->transmit_soon(100);
}
return 0;
diff --git a/src/steg/pdfSteg.cc b/src/steg/pdfSteg.cc
index 525e494..504c3d4 100644
--- a/src/steg/pdfSteg.cc
+++ b/src/steg/pdfSteg.cc
@@ -422,7 +422,7 @@ int http_server_PDF_transmit (steg_t*, struct evbuffer *source, conn_t *conn) {
evbuffer_drain(source, sbuflen);
- conn_close_after_transmit(conn);
+ conn->cease_transmission();
// downcast_steg(s)->have_transmitted = 1;
return 0;
}
@@ -502,7 +502,7 @@ http_handle_client_PDF_receive(steg_t *, conn_t *conn, struct evbuffer *dest, st
}
// downcast_steg(s)->have_received = 1;
- conn_expect_close(conn);
+ conn->expect_close();
return RECV_GOOD;
}
diff --git a/src/steg/swfSteg.cc b/src/steg/swfSteg.cc
index 2e118a4..d7c35ec 100644
--- a/src/steg/swfSteg.cc
+++ b/src/steg/swfSteg.cc
@@ -160,9 +160,7 @@ http_server_SWF_transmit (steg_t*, struct evbuffer *source, conn_t *conn) {
}
- // conn_cease_transmission(conn);
- conn_close_after_transmit(conn);
-
+ conn->cease_transmission();
free(inbuf);
free(outbuf);
@@ -249,6 +247,6 @@ http_handle_client_SWF_receive(steg_t *, conn_t *conn, struct evbuffer *dest, st
}
// downcast_steg(s)->have_received = 1;
- conn_expect_close(conn);
+ conn->expect_close();
return RECV_GOOD;
}
1
0
[stegotorus/master] Remove many trivial wrapper functions around conn_t/circuit_t methods.
by zwol@torproject.org 20 Jul '12
by zwol@torproject.org 20 Jul '12
20 Jul '12
commit d62e145dab0dd07a302daca5087eb0e44fa50591
Author: Zack Weinberg <zackw(a)panix.com>
Date: Tue Feb 28 08:36:42 2012 -0800
Remove many trivial wrapper functions around conn_t/circuit_t methods.
---
src/connections.cc | 78 +++++------------------------------------
src/connections.h | 43 ++++++----------------
src/network.cc | 50 +++++++++++++-------------
src/protocol/chop.cc | 18 +++++-----
src/protocol/null.cc | 12 +++---
src/steg/embed.cc | 4 +-
src/steg/http.cc | 6 ++--
src/steg/jsSteg.cc | 2 +-
src/steg/nosteg.cc | 4 +-
src/steg/nosteg_rr.cc | 4 +-
src/steg/pdfSteg.cc | 2 +-
src/steg/swfSteg.cc | 2 +-
src/test/unittest.cc | 12 +++---
src/test/unittest_transfer.cc | 24 ++++++------
14 files changed, 91 insertions(+), 170 deletions(-)
diff --git a/src/connections.cc b/src/connections.cc
index f16d71e..f116231 100644
--- a/src/connections.cc
+++ b/src/connections.cc
@@ -59,14 +59,14 @@ conn_start_shutdown(int barbaric)
v.swap(circuits);
for (unordered_set<circuit_t *>::iterator i = v.begin();
i != v.end(); i++)
- circuit_close(*i);
+ delete *i;
}
if (!connections.empty()) {
unordered_set<conn_t *> v;
v.swap(connections);
for (unordered_set<conn_t *>::iterator i = v.begin();
i != v.end(); i++)
- conn_close(*i);
+ delete *i;
}
closing_all_connections = false;
}
@@ -130,17 +130,11 @@ conn_t::circuit() const
return 0;
}
-void
-conn_close(conn_t *conn)
-{
- delete conn;
-}
-
/* Drain the transmit queue and send a TCP-level EOF indication to DEST. */
void
conn_send_eof(conn_t *dest)
{
- struct evbuffer *outbuf = conn_get_outbound(dest);
+ struct evbuffer *outbuf = dest->outbound();
if (evbuffer_get_length(outbuf)) {
log_debug(dest, "flushing out %lu bytes",
(unsigned long) evbuffer_get_length(outbuf));
@@ -154,30 +148,6 @@ conn_send_eof(conn_t *dest)
/* Protocol methods of connections. */
-int
-conn_maybe_open_upstream(conn_t *conn)
-{
- return conn->maybe_open_upstream();
-}
-
-int
-conn_handshake(conn_t *conn)
-{
- return conn->handshake();
-}
-
-int
-conn_recv(conn_t *source)
-{
- return source->recv();
-}
-
-int
-conn_recv_eof(conn_t *source)
-{
- return source->recv_eof();
-}
-
void
conn_expect_close(conn_t *conn)
{
@@ -231,7 +201,7 @@ axe_timer_cb(evutil_socket_t, short, void *arg)
evbuffer_get_length(bufferevent_get_output(ckt->up_buffer)) > 0)
circuit_do_flush(ckt);
else
- circuit_close(ckt);
+ delete ckt;
}
circuit_t *
@@ -279,12 +249,6 @@ circuit_t::cfg() const
}
void
-circuit_close(circuit_t *ckt)
-{
- delete ckt;
-}
-
-void
circuit_add_upstream(circuit_t *ckt, struct bufferevent *buf, const char *peer)
{
log_assert(!ckt->up_buffer);
@@ -297,47 +261,23 @@ circuit_add_upstream(circuit_t *ckt, struct bufferevent *buf, const char *peer)
/* circuit_open_upstream is in network.c */
void
-circuit_add_downstream(circuit_t *ckt, conn_t *down)
-{
- ckt->add_downstream(down);
-}
-
-void
-circuit_drop_downstream(circuit_t *ckt, conn_t *down)
-{
- ckt->drop_downstream(down);
-}
-
-static int
-circuit_send_raw(circuit_t *ckt)
-{
- return ckt->send();
-}
-
-void
circuit_send(circuit_t *ckt)
{
- if (circuit_send_raw(ckt)) {
+ if (ckt->send()) {
log_info(ckt, "error during transmit");
- circuit_close(ckt);
+ delete ckt;
}
}
-static int
-circuit_send_eof_raw(circuit_t *ckt)
-{
- return ckt->send_eof();
-}
-
void
circuit_send_eof(circuit_t *ckt)
{
if (ckt->socks_state) {
log_debug(ckt, "EOF during SOCKS phase");
- circuit_close(ckt);
- } else if (circuit_send_eof_raw(ckt)) {
+ delete ckt;
+ } else if (ckt->send_eof()) {
log_info(ckt, "error during transmit");
- circuit_close(ckt);
+ delete ckt;
}
}
diff --git a/src/connections.h b/src/connections.h
index 099a8a6..2b6388b 100644
--- a/src/connections.h
+++ b/src/connections.h
@@ -21,6 +21,10 @@ struct conn_t {
bool flushing : 1;
conn_t() : connected(false), flushing(false) {}
+
+ /** Close and deallocate a connection. If the connection is part of a
+ circuit, disconnect it from the circuit; this may cause the circuit
+ to close as well. */
virtual ~conn_t();
/** Return the upstream circuit for this connection, if there is one.
@@ -28,6 +32,14 @@ struct conn_t {
legitimately after the subclass destructor has run. */
virtual circuit_t *circuit() const;
+ /** Retrieve the inbound evbuffer for this connection. */
+ struct evbuffer *inbound() const
+ { return this->buffer ? bufferevent_get_input(this->buffer) : 0; }
+
+ /** Retrieve the outbound evbuffer for this connection. */
+ struct evbuffer *outbound()
+ { return this->buffer ? bufferevent_get_output(this->buffer) : 0; }
+
/** Create an upstream circuit for this connection, if it is
possible to do so without receiving data from the downstream
peer. If data must be received first, this method should do
@@ -82,36 +94,9 @@ void conn_start_shutdown(int barbaric);
conn_t *conn_create(config_t *cfg, size_t index, struct bufferevent *buf,
const char *peername);
-/** Close and deallocate a connection. If the connection is part of a
- circuit, close the other side of that circuit as well. */
-void conn_close(conn_t *conn);
-
/** Report the number of currently-open connections. */
size_t conn_count(void);
-/** Retrieve the inbound evbuffer for a connection. */
-static inline struct evbuffer *conn_get_inbound(conn_t *conn)
-{ return conn->buffer ? bufferevent_get_input(conn->buffer) : NULL; }
-
-/** Retrieve the outbound evbuffer for a connection. */
-static inline struct evbuffer *conn_get_outbound(conn_t *conn)
-{ return conn->buffer ? bufferevent_get_output(conn->buffer) : NULL; }
-
-/** Connect to upstream, if it is possible to do so without receiving
- data from the downstream peer first. */
-int conn_maybe_open_upstream(conn_t *conn);
-
-/** Transmit the protocol-specific handshake message (if any) for a
- connection. */
-int conn_handshake(conn_t *conn);
-
-/** Receive data from SOURCE, decode it, and write it to upstream. */
-int conn_recv(conn_t *source);
-
-/** No more data will be received from the peer; flush any internally
- buffered data to your upstream. */
-int conn_recv_eof(conn_t *source);
-
void conn_send_eof(conn_t *conn);
void conn_do_flush(conn_t *conn);
@@ -187,12 +172,8 @@ void circuit_add_upstream(circuit_t *ckt,
struct bufferevent *buf, const char *peer);
int circuit_open_upstream(circuit_t *ckt);
-void circuit_add_downstream(circuit_t *ckt, conn_t *down);
-void circuit_drop_downstream(circuit_t *ckt, conn_t *down);
-
void circuit_reopen_downstreams(circuit_t *ckt);
-void circuit_close(circuit_t *ckt);
void circuit_recv_eof(circuit_t *ckt);
void circuit_send(circuit_t *ckt);
diff --git a/src/network.cc b/src/network.cc
index 3cbc1e7..794e4e2 100644
--- a/src/network.cc
+++ b/src/network.cc
@@ -223,16 +223,16 @@ server_listener_cb(struct evconnlistener *, evutil_socket_t fd,
}
/* If appropriate at this point, connect to upstream. */
- if (conn_maybe_open_upstream(conn) < 0) {
+ if (conn->maybe_open_upstream() < 0) {
log_debug(conn, "error opening upstream circuit");
- conn_close(conn);
+ delete conn;
return;
}
/* Queue handshake, if any. */
- if (conn_handshake(conn) < 0) {
+ if (conn->handshake() < 0) {
log_debug(conn, "error during handshake");
- conn_close(conn);
+ delete conn;
return;
}
@@ -275,7 +275,7 @@ socks_read_cb(struct bufferevent *bev, void *arg)
if (socks_ret == SOCKS_INCOMPLETE)
return; /* need to read more data. */
else if (socks_ret == SOCKS_BROKEN)
- circuit_close(ckt); /* XXXX send socks reply */
+ delete ckt; /* XXXX send socks reply */
else if (socks_ret == SOCKS_CMD_NOT_CONNECT) {
bufferevent_enable(bev, EV_WRITE);
bufferevent_disable(bev, EV_READ);
@@ -315,9 +315,9 @@ downstream_read_cb(struct bufferevent *bev, void *arg)
log_debug(down, "%lu bytes available",
(unsigned long)evbuffer_get_length(bufferevent_get_input(bev)));
- if (conn_recv(down)) {
+ if (down->recv()) {
log_debug(down, "error during receive");
- conn_close(down);
+ delete down;
}
}
@@ -353,10 +353,10 @@ upstream_event_cb(struct bufferevent *bev, short what, void *arg)
log_debug(ckt, "acknowledging EOF upstream");
shutdown(bufferevent_getfd(bev), SHUT_RD);
} else {
- circuit_close(ckt);
+ delete ckt;
}
} else {
- circuit_close(ckt);
+ delete ckt;
}
} else {
/* We should never get BEV_EVENT_CONNECTED here.
@@ -391,16 +391,16 @@ downstream_event_cb(struct bufferevent *bev, short what, void *arg)
if (what == (BEV_EVENT_EOF|BEV_EVENT_READING)) {
/* Peer is done sending us data. */
- conn_recv_eof(conn);
+ conn->recv_eof();
if (bufferevent_get_enabled(bev) ||
evbuffer_get_length(bufferevent_get_input(bev)) > 0) {
log_debug(conn, "acknowledging EOF downstream");
shutdown(bufferevent_getfd(bev), SHUT_RD);
} else {
- conn_close(conn);
+ delete conn;
}
} else {
- conn_close(conn);
+ delete conn;
}
} else {
/* We should never get BEV_EVENT_CONNECTED here.
@@ -431,7 +431,7 @@ upstream_flush_cb(struct bufferevent *bev, void *arg)
log_debug(ckt, "sending EOF upstream");
shutdown(bufferevent_getfd(bev), SHUT_WR);
} else {
- circuit_close(ckt);
+ delete ckt;
}
}
}
@@ -455,7 +455,7 @@ downstream_flush_cb(struct bufferevent *bev, void *arg)
log_debug(conn, "sending EOF downstream");
shutdown(bufferevent_getfd(bev), SHUT_WR);
} else {
- conn_close(conn);
+ delete conn;
}
}
}
@@ -518,9 +518,9 @@ downstream_connect_cb(struct bufferevent *bev, short what, void *arg)
conn->connected = 1;
/* Queue handshake, if any. */
- if (conn_handshake(conn) < 0) {
+ if (conn->handshake() < 0) {
log_debug(conn, "error during handshake");
- conn_close(conn);
+ delete conn;
return;
}
@@ -572,7 +572,7 @@ downstream_socks_connect_cb(struct bufferevent *bev, short what, void *arg)
socks_send_reply(socks, bufferevent_get_output(ckt->up_buffer), err);
circuit_do_flush(ckt);
} else {
- circuit_close(ckt);
+ delete ckt;
}
return;
}
@@ -607,9 +607,9 @@ downstream_socks_connect_cb(struct bufferevent *bev, short what, void *arg)
conn->connected = 1;
/* Queue handshake, if any. */
- if (conn_handshake(conn)) {
+ if (conn->handshake()) {
log_debug(conn, "error during handshake");
- conn_close(conn);
+ delete conn;
return;
}
@@ -711,7 +711,7 @@ create_one_outbound_connection(circuit_t *ckt, struct evutil_addrinfo *addr,
success:
conn = conn_create(cfg, index, buf, peername);
- circuit_add_downstream(ckt, conn);
+ ckt->add_downstream(conn);
bufferevent_setcb(buf, downstream_read_cb, downstream_flush_cb,
is_socks ? downstream_socks_connect_cb
: downstream_connect_cb, conn);
@@ -733,11 +733,11 @@ create_outbound_connections(circuit_t *ckt, bool is_socks)
if (n == 0) {
log_warn(ckt, "no target addresses available");
- circuit_close(ckt);
+ delete ckt;
}
if (any_successes == 0) {
log_warn(ckt, "no outbound connections were successful");
- circuit_close(ckt);
+ delete ckt;
}
}
@@ -785,7 +785,7 @@ create_outbound_connections_socks(circuit_t *ckt)
/* we don't know the peername yet */
conn = conn_create(cfg, 0, buf, NULL);
- circuit_add_downstream(ckt, conn);
+ ckt->add_downstream(conn);
bufferevent_setcb(buf, downstream_read_cb, downstream_flush_cb,
downstream_socks_connect_cb, conn);
bufferevent_enable(buf, EV_READ|EV_WRITE);
@@ -793,7 +793,7 @@ create_outbound_connections_socks(circuit_t *ckt)
failure:
/* XXXX send socks reply */
- circuit_close(ckt);
+ delete ckt;
if (buf)
bufferevent_free(buf);
}
@@ -815,7 +815,7 @@ circuit_do_flush(circuit_t *ckt)
void
conn_do_flush(conn_t *conn)
{
- size_t remain = evbuffer_get_length(conn_get_outbound(conn));
+ size_t remain = evbuffer_get_length(conn->outbound());
conn->flushing = 1;
/* If 'remain' is already zero, we have to call the flush callback
diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index 832d11b..d7607c4 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -806,7 +806,7 @@ chop_find_or_make_circuit(chop_conn_t *conn, uint64_t circuit_id)
}
if (circuit_open_upstream(ck)) {
log_warn(conn, "failed to begin upstream connection");
- circuit_close(ck);
+ delete ck;
return -1;
}
log_debug(conn, "created new circuit to %s", ck->up_peer);
@@ -814,7 +814,7 @@ chop_find_or_make_circuit(chop_conn_t *conn, uint64_t circuit_id)
out.first->second = ck;
}
- circuit_add_downstream(ck, conn);
+ ck->add_downstream(conn);
return 0;
}
@@ -838,7 +838,7 @@ chop_config_t::~chop_config_t()
for (chop_circuit_table::iterator i = circuits.begin();
i != circuits.end(); i++)
if (i->second)
- circuit_close(i->second);
+ delete i->second;
}
bool
@@ -984,10 +984,10 @@ chop_circuit_t::~chop_circuit_t()
i != this->downstreams.end(); i++) {
chop_conn_t *conn = *i;
conn->upstream = NULL;
- if (evbuffer_get_length(conn_get_outbound(conn)) > 0)
+ if (evbuffer_get_length(conn->outbound()) > 0)
conn_do_flush(conn);
else
- conn_close(conn);
+ delete conn;
}
delete this->send_crypt;
@@ -1066,7 +1066,7 @@ chop_circuit_t::drop_downstream(conn_t *cn)
doing it again */
circuit_do_flush(this);
else
- circuit_close(this);
+ delete this;
} else if (this->config->mode == LSN_SIMPLE_SERVER) {
circuit_arm_axe_timer(this, this->axe_interval());
} else {
@@ -1098,7 +1098,7 @@ chop_conn_t::chop_conn_t()
chop_conn_t::~chop_conn_t()
{
if (this->upstream)
- circuit_drop_downstream(this->upstream, this);
+ this->upstream->drop_downstream(this);
if (this->steg)
delete this->steg;
if (this->must_transmit_timer)
@@ -1340,14 +1340,14 @@ chop_conn_t::recv_eof()
if (this->upstream) {
chop_circuit_t *ckt = this->upstream;
- if (evbuffer_get_length(conn_get_inbound(this)) > 0)
+ if (evbuffer_get_length(this->inbound()) > 0)
if (this->recv())
return -1;
if ((ckt->sent_fin || this->no_more_transmissions) &&
(!this->must_transmit_timer ||
!evtimer_pending(this->must_transmit_timer, NULL)))
- circuit_drop_downstream(ckt, this);
+ ckt->drop_downstream(this);
}
return 0;
}
diff --git a/src/protocol/null.cc b/src/protocol/null.cc
index 51ea744..989ffd4 100644
--- a/src/protocol/null.cc
+++ b/src/protocol/null.cc
@@ -184,14 +184,14 @@ null_circuit_t::drop_downstream(conn_t *cn)
doing it again */
circuit_do_flush(this);
else
- circuit_close(this);
+ delete this;
}
/* Send data from the upstream buffer. */
int
null_circuit_t::send()
{
- return evbuffer_add_buffer(conn_get_outbound(this->downstream),
+ return evbuffer_add_buffer(this->downstream->outbound(),
bufferevent_get_input(this->up_buffer));
}
@@ -225,7 +225,7 @@ null_conn_t::null_conn_t()
null_conn_t::~null_conn_t()
{
if (this->upstream)
- circuit_drop_downstream(this->upstream, this);
+ this->upstream->drop_downstream(this);
}
/* Only used by connection callbacks */
@@ -244,7 +244,7 @@ null_conn_t::maybe_open_upstream()
if (!ckt)
return -1;
- circuit_add_downstream(ckt, this);
+ ckt->add_downstream(this);
circuit_open_upstream(ckt);
return 0;
}
@@ -262,7 +262,7 @@ null_conn_t::recv()
{
log_assert(this->upstream);
return evbuffer_add_buffer(bufferevent_get_output(this->upstream->up_buffer),
- conn_get_inbound(this));
+ this->inbound());
}
/** Receive EOF from connection SOURCE */
@@ -270,7 +270,7 @@ int
null_conn_t::recv_eof()
{
if (this->upstream) {
- if (evbuffer_get_length(conn_get_inbound(this)) > 0)
+ if (evbuffer_get_length(this->inbound()) > 0)
if (this->recv())
return -1;
diff --git a/src/steg/embed.cc b/src/steg/embed.cc
index 3cac635..1f14716 100644
--- a/src/steg/embed.cc
+++ b/src/steg/embed.cc
@@ -136,7 +136,7 @@ size_t embed::transmit_room(conn_t * /* conn */) {
}
int embed::transmit(struct evbuffer *source, conn_t *conn) {
- struct evbuffer *dest = conn_get_outbound(conn);
+ struct evbuffer *dest = conn->outbound();
short src_len = evbuffer_get_length(source);
short pkt_size = get_pkt_size();
short used = src_len + 2;
@@ -178,7 +178,7 @@ int embed::transmit(struct evbuffer *source, conn_t *conn) {
}
int embed::receive(conn_t *conn, struct evbuffer *dest) {
- struct evbuffer *source = conn_get_inbound(conn);
+ struct evbuffer *source = conn->inbound();
short src_len = evbuffer_get_length(source);
short pkt_size = 0;
diff --git a/src/steg/http.cc b/src/steg/http.cc
index 9d296b5..aa57b63 100644
--- a/src/steg/http.cc
+++ b/src/steg/http.cc
@@ -257,7 +257,7 @@ http_client_cookie_transmit (http *s, struct evbuffer *source, conn_t *conn) {
presently uses the URL. And it can't be binary. */
- struct evbuffer *dest = conn_get_outbound(conn);
+ struct evbuffer *dest = conn->outbound();
size_t sbuflen = evbuffer_get_length(source);
int bufsize = 10000;
char* buf = (char*) xmalloc(bufsize);
@@ -457,7 +457,7 @@ int
http_client_uri_transmit (http *s, struct evbuffer *source, conn_t *conn) {
- struct evbuffer *dest = conn_get_outbound(conn);
+ struct evbuffer *dest = conn->outbound();
struct evbuffer_iovec *iv;
@@ -711,7 +711,7 @@ http_server_receive(http *s, conn_t *conn, struct evbuffer *dest, struct evbuffe
int
http::receive(conn_t *conn, struct evbuffer *dest)
{
- struct evbuffer *source = conn_get_inbound(conn);
+ struct evbuffer *source = conn->inbound();
// unsigned int type;
int rval = RECV_BAD;
diff --git a/src/steg/jsSteg.cc b/src/steg/jsSteg.cc
index 8cbff87..8bc56de 100644
--- a/src/steg/jsSteg.cc
+++ b/src/steg/jsSteg.cc
@@ -711,7 +711,7 @@ http_server_JS_transmit (steg_t*, struct evbuffer *source, conn_t *conn, unsigne
struct evbuffer_iovec *iv;
int nv;
- struct evbuffer *dest = conn_get_outbound(conn);
+ struct evbuffer *dest = conn->outbound();
size_t sbuflen = evbuffer_get_length(source);
char *hend, *jsTemplate = NULL, *outbuf, *outbuf2;
char data[(int) sbuflen*2];
diff --git a/src/steg/nosteg.cc b/src/steg/nosteg.cc
index 43971bb..02d2e10 100644
--- a/src/steg/nosteg.cc
+++ b/src/steg/nosteg.cc
@@ -65,7 +65,7 @@ nosteg::transmit_room(conn_t *)
int
nosteg::transmit(struct evbuffer *source, conn_t *conn)
{
- struct evbuffer *dest = conn_get_outbound(conn);
+ struct evbuffer *dest = conn->outbound();
log_debug(conn, "transmitting %lu bytes",
(unsigned long)evbuffer_get_length(source));
@@ -81,7 +81,7 @@ nosteg::transmit(struct evbuffer *source, conn_t *conn)
int
nosteg::receive(conn_t *conn, struct evbuffer *dest)
{
- struct evbuffer *source = conn_get_inbound(conn);
+ struct evbuffer *source = conn->inbound();
log_debug(conn, "receiving %lu bytes",
(unsigned long)evbuffer_get_length(source));
diff --git a/src/steg/nosteg_rr.cc b/src/steg/nosteg_rr.cc
index 3c8a5a0..3aa543d 100644
--- a/src/steg/nosteg_rr.cc
+++ b/src/steg/nosteg_rr.cc
@@ -69,7 +69,7 @@ nosteg_rr::transmit(struct evbuffer *source, conn_t *conn)
{
log_assert(can_transmit);
- struct evbuffer *dest = conn_get_outbound(conn);
+ struct evbuffer *dest = conn->outbound();
log_debug(conn, "transmitting %lu bytes",
(unsigned long)evbuffer_get_length(source));
@@ -92,7 +92,7 @@ nosteg_rr::transmit(struct evbuffer *source, conn_t *conn)
int
nosteg_rr::receive(conn_t *conn, struct evbuffer *dest)
{
- struct evbuffer *source = conn_get_inbound(conn);
+ struct evbuffer *source = conn->inbound();
log_debug(conn, "%s-side receiving %lu bytes",
is_clientside ? "client" : "server",
diff --git a/src/steg/pdfSteg.cc b/src/steg/pdfSteg.cc
index d958b29..525e494 100644
--- a/src/steg/pdfSteg.cc
+++ b/src/steg/pdfSteg.cc
@@ -298,7 +298,7 @@ pdfUnwrap (char *data, unsigned int dlen,
int http_server_PDF_transmit (steg_t*, struct evbuffer *source, conn_t *conn) {
- struct evbuffer *dest = conn_get_outbound(conn);
+ struct evbuffer *dest = conn->outbound();
size_t sbuflen = evbuffer_get_length(source);
unsigned int mpdf;
char *pdfTemplate = NULL, *hend;
diff --git a/src/steg/swfSteg.cc b/src/steg/swfSteg.cc
index 8c3bd2e..2e118a4 100644
--- a/src/steg/swfSteg.cc
+++ b/src/steg/swfSteg.cc
@@ -125,7 +125,7 @@ swf_unwrap(char* inbuf, int in_len, char* outbuf, int out_sz) {
int
http_server_SWF_transmit (steg_t*, struct evbuffer *source, conn_t *conn) {
- struct evbuffer *dest = conn_get_outbound(conn);
+ struct evbuffer *dest = conn->outbound();
size_t sbuflen = evbuffer_get_length(source);
char* inbuf;
char* outbuf;
diff --git a/src/test/unittest.cc b/src/test/unittest.cc
index 37632ac..31d237a 100644
--- a/src/test/unittest.cc
+++ b/src/test/unittest.cc
@@ -55,8 +55,8 @@ setup_proto_test_state(const struct testcase_t *tcase)
circuit_add_upstream(s->ckt_server, pairs[2][1],
xstrdup("to-harness-server"));
- circuit_add_downstream(s->ckt_client, s->conn_client);
- circuit_add_downstream(s->ckt_server, s->conn_server);
+ s->ckt_client->add_downstream(s->conn_client);
+ s->ckt_server->add_downstream(s->conn_server);
return s;
}
@@ -68,11 +68,11 @@ cleanup_proto_test_state(const struct testcase_t *, void *state)
/* We don't want to trigger circuit_*_shutdown, so dissociate the circuits
from their connections and close each separately. */
- circuit_drop_downstream(s->ckt_client, s->conn_client);
- circuit_drop_downstream(s->ckt_server, s->conn_server);
+ s->ckt_client->drop_downstream(s->conn_client);
+ s->ckt_server->drop_downstream(s->conn_server);
- conn_close(s->conn_client);
- conn_close(s->conn_server);
+ delete s->conn_client;
+ delete s->conn_server;
delete s->cfg_client;
delete s->cfg_server;
diff --git a/src/test/unittest_transfer.cc b/src/test/unittest_transfer.cc
index 520a1e4..d1a7bbf 100644
--- a/src/test/unittest_transfer.cc
+++ b/src/test/unittest_transfer.cc
@@ -22,10 +22,10 @@ test_transfer(void *state)
const struct proto_test_args *a = s->args;
/* Handshake */
- tt_int_op(0, ==, conn_handshake(s->conn_client));
- tt_int_op(0, ==, conn_recv(s->conn_server));
- tt_int_op(0, ==, conn_handshake(s->conn_server));
- tt_int_op(0, ==, conn_recv(s->conn_client));
+ tt_int_op(0, ==, s->conn_client->handshake());
+ tt_int_op(0, ==, s->conn_server->recv());
+ tt_int_op(0, ==, s->conn_server->handshake());
+ tt_int_op(0, ==, s->conn_client->recv());
/* End of Handshake */
/* client -> server */
@@ -33,14 +33,14 @@ test_transfer(void *state)
circuit_send(s->ckt_client);
tt_int_op(0, ==, evbuffer_get_length(bufferevent_get_output(s->buf_client)));
tt_int_op(a->len_c2s_on_wire, ==,
- evbuffer_get_length(conn_get_inbound(s->conn_server)));
+ evbuffer_get_length(s->conn_server->inbound()));
tt_mem_op(a->c2s_on_wire, ==,
- evbuffer_pullup(conn_get_inbound(s->conn_server),
+ evbuffer_pullup(s->conn_server->inbound(),
a->len_c2s_on_wire),
a->len_c2s_on_wire);
- conn_recv(s->conn_server);
- tt_int_op(0, ==, evbuffer_get_length(conn_get_inbound(s->conn_server)));
+ s->conn_server->recv();
+ tt_int_op(0, ==, evbuffer_get_length(s->conn_server->inbound()));
tt_int_op(SLEN(msg1), ==,
evbuffer_get_length(bufferevent_get_input(s->buf_server)));
tt_mem_op(msg1, ==,
@@ -52,14 +52,14 @@ test_transfer(void *state)
circuit_send(s->ckt_server);
tt_int_op(0, ==, evbuffer_get_length(bufferevent_get_output(s->buf_server)));
tt_int_op(a->len_s2c_on_wire, ==,
- evbuffer_get_length(conn_get_inbound(s->conn_client)));
+ evbuffer_get_length(s->conn_client->inbound()));
tt_mem_op(a->s2c_on_wire, ==,
- evbuffer_pullup(conn_get_inbound(s->conn_client),
+ evbuffer_pullup(s->conn_client->inbound(),
a->len_s2c_on_wire),
a->len_s2c_on_wire);
- conn_recv(s->conn_client);
- tt_int_op(0, ==, evbuffer_get_length(conn_get_inbound(s->conn_client)));
+ s->conn_client->recv();
+ tt_int_op(0, ==, evbuffer_get_length(s->conn_client->inbound()));
tt_int_op(SLEN(msg2), ==,
evbuffer_get_length(bufferevent_get_input(s->buf_client)));
tt_mem_op(msg2, ==,
1
0