commit 86875f153137994c56214d75cca8292cb33e28a8 Author: Zack Weinberg zackw@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;
tor-commits@lists.torproject.org