Move edge-only flags from connection_t to edge_connection_t.

svn:r17643
This commit is contained in:
Nick Mathewson 2008-12-17 14:59:28 +00:00
parent 26632d59dd
commit 7678ac5193
9 changed files with 91 additions and 75 deletions

View File

@ -67,6 +67,9 @@ Changes in version 0.2.1.9-alpha - 200?-??-??
o Code simplifications and refactoring:
- Rename the confusing or_is_obsolete field to the more appropriate
is_bad_for_new_circs, and move it to or_connection_t where it belongs.
- Move edge-only flags from connection_t to edge_connection_t: not
only is this better coding, but on machines of plausible alignment,
it should save 4-8 bytes per connection_t. "Every little bit helps."
Changes in version 0.2.1.8-alpha - 2008-12-08

View File

@ -1096,7 +1096,7 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line,
/* The client will see a DESTROY, and infer that the connections
* are closing because the circuit is getting torn down. No need
* to send an end cell. */
conn->_base.edge_has_sent_end = 1;
conn->edge_has_sent_end = 1;
conn->end_reason = END_STREAM_REASON_DESTROY;
conn->end_reason |= END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED;
connection_mark_for_close(TO_CONN(conn));

View File

@ -1087,13 +1087,13 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
/* XXXX021 Duplicates checks in connection_ap_handshake_attach_circuit
* XXXX021 Fix this, then backport it? */
routerinfo_t *router = router_get_by_nickname(conn->chosen_exit_name, 1);
int opt = conn->_base.chosen_exit_optional;
int opt = conn->chosen_exit_optional;
if (router && !connection_ap_can_use_exit(conn, router)) {
log_fn(opt ? LOG_INFO : LOG_WARN, LD_APP,
"Requested exit point '%s' would refuse request. %s.",
conn->chosen_exit_name, opt ? "Trying others" : "Closing");
if (opt) {
conn->_base.chosen_exit_optional = 0;
conn->chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name);
/* Try again. */
return circuit_get_open_circ_or_launch(conn,
@ -1142,7 +1142,7 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_GENERAL) {
if (conn->chosen_exit_name) {
routerinfo_t *r;
int opt = conn->_base.chosen_exit_optional;
int opt = conn->chosen_exit_optional;
r = router_get_by_nickname(conn->chosen_exit_name, 1);
if (r) {
extend_info = extend_info_from_router(r);
@ -1175,7 +1175,7 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
"Requested exit point '%s' is not known. %s.",
conn->chosen_exit_name, opt ? "Trying others" : "Closing");
if (opt) {
conn->_base.chosen_exit_optional = 0;
conn->chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name);
return 0;
}
@ -1394,7 +1394,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn)
if (conn->chosen_exit_name) {
routerinfo_t *router = router_get_by_nickname(conn->chosen_exit_name, 1);
int opt = conn->_base.chosen_exit_optional;
int opt = conn->chosen_exit_optional;
if (!router && !want_onehop) {
/* We ran into this warning when trying to extend a circuit to a
* hidden service directory for which we didn't have a router
@ -1405,7 +1405,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn)
"Requested exit point '%s' is not known. %s.",
conn->chosen_exit_name, opt ? "Trying others" : "Closing");
if (opt) {
conn->_base.chosen_exit_optional = 0;
conn->chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name);
return 0;
}
@ -1416,7 +1416,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn)
"Requested exit point '%s' would refuse request. %s.",
conn->chosen_exit_name, opt ? "Trying others" : "Closing");
if (opt) {
conn->_base.chosen_exit_optional = 0;
conn->chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name);
return 0;
}

View File

@ -511,7 +511,8 @@ connection_about_to_close_connection(connection_t *conn)
tor_assert(conn->marked_for_close);
if (CONN_IS_EDGE(conn)) {
if (!conn->edge_has_sent_end) {
edge_conn = TO_EDGE_CONN(conn);
if (!edge_conn->edge_has_sent_end) {
log_warn(LD_BUG, "(Harmless.) Edge connection (marked at %s:%d) "
"hasn't sent end yet?",
conn->marked_for_close_file, conn->marked_for_close);
@ -2986,7 +2987,7 @@ assert_connection_ok(connection_t *conn, time_t now)
if (conn->outbuf_flushlen > 0) {
tor_assert(connection_is_writing(conn) || conn->write_blocked_on_bw ||
conn->edge_blocked_on_circ);
(CONN_IS_EDGE(conn) && TO_EDGE_CONN(conn)->edge_blocked_on_circ));
}
if (conn->hold_open_until_flushed)
@ -3001,11 +3002,6 @@ assert_connection_ok(connection_t *conn, time_t now)
assert_buf_ok(conn->outbuf);
}
if (conn->chosen_exit_optional || conn->chosen_exit_retries) {
tor_assert(conn->type == CONN_TYPE_AP);
tor_assert((TO_EDGE_CONN(conn))->chosen_exit_name);
}
if (conn->type == CONN_TYPE_OR) {
or_connection_t *or_conn = TO_OR_CONN(conn);
if (conn->state == OR_CONN_STATE_OPEN) {
@ -3025,6 +3021,11 @@ assert_connection_ok(connection_t *conn, time_t now)
if (CONN_IS_EDGE(conn)) {
edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
if (edge_conn->chosen_exit_optional || edge_conn->chosen_exit_retries) {
tor_assert(conn->type == CONN_TYPE_AP);
tor_assert(edge_conn->chosen_exit_name);
}
/* XXX unchecked: package window, deliver window. */
if (conn->type == CONN_TYPE_AP) {

View File

@ -50,7 +50,7 @@ _connection_mark_unattached_ap(edge_connection_t *conn, int endreason,
int line, const char *file)
{
tor_assert(conn->_base.type == CONN_TYPE_AP);
conn->_base.edge_has_sent_end = 1; /* no circ yet */
conn->edge_has_sent_end = 1; /* no circ yet */
if (conn->_base.marked_for_close) {
/* This call will warn as appropriate. */
@ -171,7 +171,7 @@ connection_edge_destroy(circid_t circ_id, edge_connection_t *conn)
conn->end_reason |= END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED;
} else {
/* closing the circuit, nothing to send an END to */
conn->_base.edge_has_sent_end = 1;
conn->edge_has_sent_end = 1;
conn->end_reason = END_STREAM_REASON_DESTROY;
conn->end_reason |= END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED;
connection_mark_for_close(TO_CONN(conn));
@ -219,7 +219,7 @@ connection_edge_end(edge_connection_t *conn, uint8_t reason)
size_t payload_len=1;
circuit_t *circ;
if (conn->_base.edge_has_sent_end) {
if (conn->edge_has_sent_end) {
log_warn(LD_BUG,"(Harmless.) Calling connection_edge_end (reason %d) "
"on an already ended stream?", reason);
tor_fragile_assert();
@ -265,7 +265,7 @@ connection_edge_end(edge_connection_t *conn, uint8_t reason)
conn->_base.s);
}
conn->_base.edge_has_sent_end = 1;
conn->edge_has_sent_end = 1;
conn->end_reason = reason;
return 0;
}
@ -465,7 +465,7 @@ connection_ap_expire_beginning(void)
/* send an end down the circuit */
connection_edge_end(conn, END_STREAM_REASON_TIMEOUT);
/* un-mark it as ending, since we're going to reuse it */
conn->_base.edge_has_sent_end = 0;
conn->edge_has_sent_end = 0;
conn->end_reason = 0;
/* kludge to make us not try this circuit again, yet to allow
* current streams on it to survive if they can: make it
@ -560,32 +560,32 @@ circuit_discard_optional_exit_enclaves(extend_info_t *info)
routerinfo_t *r1, *r2;
smartlist_t *conns = get_connection_array();
SMARTLIST_FOREACH(conns, connection_t *, conn,
{
SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
if (conn->marked_for_close ||
conn->type != CONN_TYPE_AP ||
conn->state != AP_CONN_STATE_CIRCUIT_WAIT ||
(!conn->chosen_exit_optional &&
!conn->chosen_exit_retries))
conn->state != AP_CONN_STATE_CIRCUIT_WAIT)
continue;
edge_conn = TO_EDGE_CONN(conn);
if (!edge_conn->chosen_exit_optional &&
!edge_conn->chosen_exit_retries)
continue;
r1 = router_get_by_nickname(edge_conn->chosen_exit_name, 0);
r2 = router_get_by_nickname(info->nickname, 0);
if (!r1 || !r2 || r1 != r2)
continue;
tor_assert(edge_conn->socks_request);
if (conn->chosen_exit_optional) {
if (edge_conn->chosen_exit_optional) {
log_info(LD_APP, "Giving up on enclave exit '%s' for destination %s.",
safe_str(edge_conn->chosen_exit_name),
escaped_safe_str(edge_conn->socks_request->address));
conn->chosen_exit_optional = 0;
edge_conn->chosen_exit_optional = 0;
tor_free(edge_conn->chosen_exit_name); /* clears it */
/* if this port is dangerous, warn or reject it now that we don't
* think it'll be using an enclave. */
consider_plaintext_ports(edge_conn, edge_conn->socks_request->port);
}
if (conn->chosen_exit_retries) {
if (--conn->chosen_exit_retries == 0) { /* give up! */
if (edge_conn->chosen_exit_retries) {
if (--edge_conn->chosen_exit_retries == 0) { /* give up! */
clear_trackexithost_mappings(edge_conn->chosen_exit_name);
tor_free(edge_conn->chosen_exit_name); /* clears it */
/* if this port is dangerous, warn or reject it now that we don't
@ -593,7 +593,7 @@ circuit_discard_optional_exit_enclaves(extend_info_t *info)
consider_plaintext_ports(edge_conn, edge_conn->socks_request->port);
}
}
});
} SMARTLIST_FOREACH_END(conn);
}
/** The AP connection <b>conn</b> has just failed while attaching or
@ -1503,7 +1503,7 @@ connection_ap_handshake_rewrite_and_attach(edge_connection_t *conn,
/* DOCDOC */
#define TRACKHOSTEXITS_RETRIES 5
if (remapped_to_exit) /* 5 tries before it expires the addressmap */
TO_CONN(conn)->chosen_exit_retries = TRACKHOSTEXITS_RETRIES;
conn->chosen_exit_retries = TRACKHOSTEXITS_RETRIES;
*s = 0;
} else {
log_warn(LD_APP,"Malformed exit address '%s.exit'. Refusing.",
@ -1592,7 +1592,7 @@ connection_ap_handshake_rewrite_and_attach(edge_connection_t *conn,
routers with this nickname */
conn->chosen_exit_name =
tor_strdup(hex_str(r->cache_info.identity_digest, DIGEST_LEN));
conn->_base.chosen_exit_optional = 1;
conn->chosen_exit_optional = 1;
}
}

View File

@ -2318,7 +2318,7 @@ handle_control_attachstream(control_connection_t *conn, uint32_t len,
circuit_t *tmpcirc = circuit_get_by_edge_conn(ap_conn);
connection_edge_end(ap_conn, END_STREAM_REASON_TIMEOUT);
/* Un-mark it as ending, since we're going to reuse it. */
ap_conn->_base.edge_has_sent_end = 0;
ap_conn->edge_has_sent_end = 0;
ap_conn->end_reason = 0;
if (tmpcirc)
circuit_detach_stream(tmpcirc,ap_conn);

View File

@ -502,7 +502,7 @@ conn_write_callback(int fd, short events, void *_conn)
edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
if (!edge_conn->end_reason)
edge_conn->end_reason = END_STREAM_REASON_INTERNAL;
conn->edge_has_sent_end = 1;
edge_conn->edge_has_sent_end = 1;
}
connection_close_immediate(conn); /* So we don't try to flush. */
connection_mark_for_close(conn);

View File

@ -223,6 +223,7 @@ typedef enum {
/* !!!! If _CONN_TYPE_MAX is ever over 15, we must grow the type field in
* connection_t. */
/** True iff <b>x</b> is an edge connection. */
#define CONN_IS_EDGE(x) \
((x)->type == CONN_TYPE_EXIT || (x)->type == CONN_TYPE_AP)
@ -354,17 +355,17 @@ typedef enum {
#define DIR_PURPOSE_UPLOAD_VOTE 10
/** A connection to a directory server: upload a v3 consensus signature */
#define DIR_PURPOSE_UPLOAD_SIGNATURES 11
/** A connection to a directory server: download one or more network-status
* objects [XXX wtf, these are all the same comment] */
/** A connection to a directory server: download one or more v3 networkstatus
* votes. */
#define DIR_PURPOSE_FETCH_STATUS_VOTE 12
/** A connection to a directory server: download one or more network-status
* objects */
/** A connection to a directory server: download a v3 detached signatures
* object for a consensus. */
#define DIR_PURPOSE_FETCH_DETACHED_SIGNATURES 13
/** A connection to a directory server: download one or more network-status
* objects */
/** A connection to a directory server: download a v3 networkstatus
* consensus. */,
#define DIR_PURPOSE_FETCH_CONSENSUS 14
/** A connection to a directory server: download one or more network-status
* objects */
/** A connection to a directory server: download one or more directory
* authority certificates. */
#define DIR_PURPOSE_FETCH_CERTIFICATE 15
/** Purpose for connection at a directory server. */
@ -377,6 +378,8 @@ typedef enum {
#define DIR_PURPOSE_FETCH_RENDDESC_V2 18
#define _DIR_PURPOSE_MAX 18
/** True iff <b>p</b> is a purpose corresponding to uploading data to a
* directory server. */
#define DIR_PURPOSE_IS_UPLOAD(p) \
((p)==DIR_PURPOSE_UPLOAD_DIR || \
(p)==DIR_PURPOSE_UPLOAD_RENDDESC || \
@ -480,15 +483,20 @@ typedef enum {
/** True iff the circuit purpose <b>p</b> is for a circuit that
* originated at this node. */
#define CIRCUIT_PURPOSE_IS_ORIGIN(p) ((p)>_CIRCUIT_PURPOSE_OR_MAX)
/** True iff the circuit purpose <b>p</b> is for a circuit that originated
* here to serve as a client. (Hidden services don't count here.) */
#define CIRCUIT_PURPOSE_IS_CLIENT(p) \
((p)> _CIRCUIT_PURPOSE_OR_MAX && \
(p)<=_CIRCUIT_PURPOSE_C_MAX)
/** True iff the circuit_t <b>c</b> is actually an origin_circuit_t. */
#define CIRCUIT_IS_ORIGIN(c) (CIRCUIT_PURPOSE_IS_ORIGIN((c)->purpose))
/** How many circuits do we want simultaneously in-progress to handle
* a given stream? */
#define MIN_CIRCUITS_HANDLING_STREAM 2
/* These RELAY_COMMAND constants define values for relay cell commands, and
* must match those defined in tor-spec.txt. */
#define RELAY_COMMAND_BEGIN 1
#define RELAY_COMMAND_DATA 2
#define RELAY_COMMAND_END 3
@ -513,7 +521,7 @@ typedef enum {
#define RELAY_COMMAND_RENDEZVOUS_ESTABLISHED 39
#define RELAY_COMMAND_INTRODUCE_ACK 40
/* Reasons why an OR connection is closed */
/* Reasons why an OR connection is closed. */
#define END_OR_CONN_REASON_DONE 1
#define END_OR_CONN_REASON_REFUSED 2 /* connection refused */
#define END_OR_CONN_REASON_OR_IDENTITY 3
@ -525,7 +533,7 @@ typedef enum {
#define END_OR_CONN_REASON_MISC 9
/* Reasons why we (or a remote OR) might close a stream. See tor-spec.txt for
* documentation of these. */
* documentation of these. The values must match. */
#define END_STREAM_REASON_MISC 1
#define END_STREAM_REASON_RESOLVEFAILED 2
#define END_STREAM_REASON_CONNECTREFUSED 3
@ -897,21 +905,6 @@ typedef struct connection_t {
* before closing it? */
unsigned int inbuf_reached_eof:1; /**< Boolean: did read() return 0 on this
* conn? */
unsigned int edge_has_sent_end:1; /**< For debugging; only used on edge
* connections. Set once we've set the stream end,
* and check in connection_about_to_close_connection().
*/
/** Edge connections only: true if we've blocked reading until the
* circuit has fewer queued cells. */
unsigned int edge_blocked_on_circ:1;
/** For AP connections only. If 1, and we fail to reach the chosen exit,
* stop requiring it. */
unsigned int chosen_exit_optional:1;
/** For AP connections only. If non-zero, this exit node was picked as
* a result of the TrackHostExit, and the value decrements every time
* we fail to complete a circuit to our chosen exit -- if it reaches
* zero, abandon the associated mapaddress. */
unsigned int chosen_exit_retries:3;
/** Set to 1 when we're inside connection_flushed_some to keep us from
* calling connection_handle_write() recursively. */
unsigned int in_flushed_some:1;
@ -1103,6 +1096,22 @@ typedef struct edge_connection_t {
* itself rather than BEGIN (either via onehop or via a whole circuit). */
unsigned int use_begindir:1;
unsigned int edge_has_sent_end:1; /**< For debugging; only used on edge
* connections. Set once we've set the stream end,
* and check in connection_about_to_close_connection().
*/
/** True iff we've blocked reading until the circuit has fewer queued
* cells. */
unsigned int edge_blocked_on_circ:1;
/** For AP connections only. If 1, and we fail to reach the chosen exit,
* stop requiring it. */
unsigned int chosen_exit_optional:1;
/** For AP connections only. If non-zero, this exit node was picked as
* a result of the TrackHostExit, and the value decrements every time
* we fail to complete a circuit to our chosen exit -- if it reaches
* zero, abandon the associated mapaddress. */
unsigned int chosen_exit_retries:3;
/** If this is a DNSPort connection, this field holds the pending DNS
* request that we're going to try to answer. */
struct evdns_server_request *dns_server_request;
@ -1261,7 +1270,7 @@ typedef enum {
SAVED_IN_JOURNAL
} saved_location_t;
/** Enumeration: what kind of downlaod schedule are we using for a given
/** Enumeration: what kind of download schedule are we using for a given
* object? */
typedef enum {
DL_SCHED_GENERIC = 0,
@ -1319,7 +1328,8 @@ typedef struct signed_descriptor_t {
* status, so far as we know." */
time_t last_listed_as_valid_until;
#ifdef TRACK_SERVED_TIME
/** DOCDOC */
/** The last time we served anybody this descriptor. Used for internal
* testing to see whether we're holding on to descriptors too long. */
time_t last_served_at; /*XXXX021 remove if not useful. */
#endif
/* If true, we do not ever try to save this object in the cache. */
@ -1570,7 +1580,9 @@ typedef struct networkstatus_voter_info_t {
uint16_t or_port; /**< OR port of this voter */
char *contact; /**< Contact information for this voter. */
char vote_digest[DIGEST_LEN]; /**< Digest of this voter's vote, as signed. */
char legacy_id_digest[DIGEST_LEN]; /**< From vote only. DOCDOC */
/** Digest of this voter's "legacy" identity key, if any. In vote only; for
* consensuses, we treat legacy keys as additional signers. */
char legacy_id_digest[DIGEST_LEN];
/* Nothing from here on is signed. */
char signing_key_digest[DIGEST_LEN]; /**< Declared digest of signing key

View File

@ -565,7 +565,7 @@ connection_edge_send_command(edge_connection_t *fromconn,
connection_mark_unattached_ap(fromconn, END_STREAM_REASON_INTERNAL);
} else {
log_info(LD_EXIT,"no circ. Closing conn.");
fromconn->_base.edge_has_sent_end = 1; /* no circ to send to */
fromconn->edge_has_sent_end = 1; /* no circ to send to */
fromconn->end_reason = END_STREAM_REASON_INTERNAL;
connection_mark_for_close(TO_CONN(fromconn));
}
@ -653,10 +653,10 @@ connection_ap_process_end_not_open(
NULL)) {
control_event_stream_status(conn, STREAM_EVENT_REMAP, 0);
}
if (conn->_base.chosen_exit_optional ||
conn->_base.chosen_exit_retries) {
if (conn->chosen_exit_optional ||
conn->chosen_exit_retries) {
/* stop wanting a specific exit */
conn->_base.chosen_exit_optional = 0;
conn->chosen_exit_optional = 0;
/* A non-zero chosen_exit_retries can happen if we set a
* TrackHostExits for this address under a port that the exit
* relay allows, but then try the same address with a different
@ -664,7 +664,7 @@ connection_ap_process_end_not_open(
* the mapping, since it is probably still wanted on the
* original port. But now we give away to the exit relay that
* we probably have a TrackHostExits on it. So be it. */
conn->_base.chosen_exit_retries = 0;
conn->chosen_exit_retries = 0;
tor_free(conn->chosen_exit_name); /* clears it */
}
if (connection_ap_detach_retriable(conn, circ, control_reason) >= 0)
@ -672,7 +672,7 @@ connection_ap_process_end_not_open(
/* else, conn will get closed below */
break;
case END_STREAM_REASON_CONNECTREFUSED:
if (!conn->_base.chosen_exit_optional)
if (!conn->chosen_exit_optional)
break; /* break means it'll close, below */
/* Else fall through: expire this circuit, clear the
* chosen_exit_name field, and try again. */
@ -686,9 +686,9 @@ connection_ap_process_end_not_open(
tor_assert(circ->_base.timestamp_dirty);
circ->_base.timestamp_dirty -= get_options()->MaxCircuitDirtiness;
if (conn->_base.chosen_exit_optional) {
if (conn->chosen_exit_optional) {
/* stop wanting a specific exit */
conn->_base.chosen_exit_optional = 0;
conn->chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name); /* clears it */
}
if (connection_ap_detach_retriable(conn, circ, control_reason) >= 0)
@ -709,9 +709,9 @@ connection_ap_process_end_not_open(
if (exitrouter) {
policies_set_router_exitpolicy_to_reject_all(exitrouter);
}
if (conn->_base.chosen_exit_optional) {
if (conn->chosen_exit_optional) {
/* stop wanting a specific exit */
conn->_base.chosen_exit_optional = 0;
conn->chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name); /* clears it */
}
if (connection_ap_detach_retriable(conn, circ, control_reason) >= 0)
@ -766,7 +766,7 @@ connection_edge_process_relay_cell_not_open(
layer_hint);
} else {
/* we just got an 'end', don't need to send one */
conn->_base.edge_has_sent_end = 1;
conn->edge_has_sent_end = 1;
conn->end_reason = *(cell->payload+RELAY_HEADER_SIZE) |
END_STREAM_REASON_FLAG_REMOTE;
connection_mark_for_close(TO_CONN(conn));
@ -1016,7 +1016,7 @@ connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ,
log_warn(LD_BUG,
"open stream hasn't sent socks answer yet? Closing.");
/* We just *got* an end; no reason to send one. */
conn->_base.edge_has_sent_end = 1;
conn->edge_has_sent_end = 1;
if (!conn->end_reason)
conn->end_reason = reason | END_STREAM_REASON_FLAG_REMOTE;
if (!conn->_base.marked_for_close) {
@ -1716,7 +1716,7 @@ set_streams_blocked_on_circ(circuit_t *circ, or_connection_t *orconn,
for (; edge; edge = edge->next_stream) {
connection_t *conn = TO_CONN(edge);
conn->edge_blocked_on_circ = block;
edge->edge_blocked_on_circ = block;
if (!conn->read_event) {
/* This connection is a placeholder for something; probably a DNS