mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 20:33:31 +01:00
Use connection_mark_and_flush consistently.
This commit is contained in:
parent
5710d99f00
commit
a0c1c2ac01
@ -34,15 +34,21 @@ void _connection_mark_for_close(connection_t *conn,int line, const char *file);
|
|||||||
#define connection_mark_for_close(c) \
|
#define connection_mark_for_close(c) \
|
||||||
_connection_mark_for_close((c), __LINE__, _SHORT_FILE_)
|
_connection_mark_for_close((c), __LINE__, _SHORT_FILE_)
|
||||||
|
|
||||||
#define connection_mark_and_flush(c) \
|
/**
|
||||||
|
* Mark 'c' for close, but try to hold it open until all the data is written.
|
||||||
|
*/
|
||||||
|
#define _connection_mark_and_flush(c,line,file) \
|
||||||
do { \
|
do { \
|
||||||
connection_t *tmp_conn_ = (c); \
|
connection_t *tmp_conn_ = (c); \
|
||||||
_connection_mark_for_close(tmp_conn_, __LINE__, _SHORT_FILE_); \
|
_connection_mark_for_close(tmp_conn_, (line), (file)); \
|
||||||
tmp_conn_->hold_open_until_flushed = 1; \
|
tmp_conn_->hold_open_until_flushed = 1; \
|
||||||
IF_HAS_BUFFEREVENT(tmp_conn_, \
|
IF_HAS_BUFFEREVENT(tmp_conn_, \
|
||||||
connection_start_writing(tmp_conn_)); \
|
connection_start_writing(tmp_conn_)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define connection_mark_and_flush(c) \
|
||||||
|
_connection_mark_and_flush((c), __LINE__, _SHORT_FILE_)
|
||||||
|
|
||||||
void connection_expire_held_open(void);
|
void connection_expire_held_open(void);
|
||||||
|
|
||||||
int connection_connect(connection_t *conn, const char *address,
|
int connection_connect(connection_t *conn, const char *address,
|
||||||
|
@ -90,9 +90,8 @@ _connection_mark_unattached_ap(edge_connection_t *conn, int endreason,
|
|||||||
conn->socks_request->has_finished = 1;
|
conn->socks_request->has_finished = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_connection_mark_for_close(TO_CONN(conn), line, file);
|
_connection_mark_and_flush(TO_CONN(conn), line, file);
|
||||||
conn->_base.hold_open_until_flushed = 1;
|
|
||||||
IF_HAS_BUFFEREVENT(TO_CONN(conn), connection_start_writing(TO_CONN(conn)));
|
|
||||||
conn->end_reason = endreason;
|
conn->end_reason = endreason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2798,8 +2798,8 @@ connection_control_process_inbuf(control_connection_t *conn)
|
|||||||
body_len = 2+strlen(buf+6)+2; /* code, msg, nul. */
|
body_len = 2+strlen(buf+6)+2; /* code, msg, nul. */
|
||||||
set_uint16(buf+0, htons(body_len));
|
set_uint16(buf+0, htons(body_len));
|
||||||
connection_write_to_buf(buf, 4+body_len, TO_CONN(conn));
|
connection_write_to_buf(buf, 4+body_len, TO_CONN(conn));
|
||||||
connection_mark_for_close(TO_CONN(conn));
|
|
||||||
conn->_base.hold_open_until_flushed = 1;
|
connection_mark_and_flush(TO_CONN(conn));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2820,8 +2820,7 @@ connection_control_process_inbuf(control_connection_t *conn)
|
|||||||
if (data_len + conn->incoming_cmd_cur_len > MAX_COMMAND_LINE_LENGTH) {
|
if (data_len + conn->incoming_cmd_cur_len > MAX_COMMAND_LINE_LENGTH) {
|
||||||
connection_write_str_to_buf("500 Line too long.\r\n", conn);
|
connection_write_str_to_buf("500 Line too long.\r\n", conn);
|
||||||
connection_stop_reading(TO_CONN(conn));
|
connection_stop_reading(TO_CONN(conn));
|
||||||
connection_mark_for_close(TO_CONN(conn));
|
connection_mark_and_flush(TO_CONN(conn));
|
||||||
conn->_base.hold_open_until_flushed = 1;
|
|
||||||
}
|
}
|
||||||
while (conn->incoming_cmd_len < data_len+conn->incoming_cmd_cur_len)
|
while (conn->incoming_cmd_len < data_len+conn->incoming_cmd_cur_len)
|
||||||
conn->incoming_cmd_len *= 2;
|
conn->incoming_cmd_len *= 2;
|
||||||
@ -2880,8 +2879,7 @@ connection_control_process_inbuf(control_connection_t *conn)
|
|||||||
/* Otherwise, Quit is always valid. */
|
/* Otherwise, Quit is always valid. */
|
||||||
if (!strcasecmp(conn->incoming_cmd, "QUIT")) {
|
if (!strcasecmp(conn->incoming_cmd, "QUIT")) {
|
||||||
connection_write_str_to_buf("250 closing connection\r\n", conn);
|
connection_write_str_to_buf("250 closing connection\r\n", conn);
|
||||||
connection_mark_for_close(TO_CONN(conn));
|
connection_mark_and_flush(TO_CONN(conn));
|
||||||
conn->_base.hold_open_until_flushed = 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,8 +949,7 @@ run_connection_housekeeping(int i, time_t now)
|
|||||||
connection_or_connect_failed(TO_OR_CONN(conn),
|
connection_or_connect_failed(TO_OR_CONN(conn),
|
||||||
END_OR_CONN_REASON_TIMEOUT,
|
END_OR_CONN_REASON_TIMEOUT,
|
||||||
"Tor gave up on the connection");
|
"Tor gave up on the connection");
|
||||||
connection_mark_for_close(conn);
|
connection_mark_and_flush(conn);
|
||||||
conn->hold_open_until_flushed = 1;
|
|
||||||
} else if (!connection_state_is_open(conn)) {
|
} else if (!connection_state_is_open(conn)) {
|
||||||
if (past_keepalive) {
|
if (past_keepalive) {
|
||||||
/* We never managed to actually get this connection open and happy. */
|
/* We never managed to actually get this connection open and happy. */
|
||||||
|
@ -3216,13 +3216,13 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
|
|||||||
/* Make sure that we haven't already got this exact descriptor. */
|
/* Make sure that we haven't already got this exact descriptor. */
|
||||||
if (sdmap_get(routerlist->desc_digest_map,
|
if (sdmap_get(routerlist->desc_digest_map,
|
||||||
router->cache_info.signed_descriptor_digest)) {
|
router->cache_info.signed_descriptor_digest)) {
|
||||||
/* If we have this descriptor already and the new descriptor is a bridge
|
/* If we have this descriptor already but the new descriptor is a bridge
|
||||||
* descriptor, replace it. If we had a bridge descriptor before and the
|
* descriptor, replace it. If we had a bridge descriptor before and the
|
||||||
* new one is not a bridge descriptor, don't replace it. */
|
* new one is not a bridge descriptor, don't replace it. */
|
||||||
tor_assert(old_router);
|
const int had_as_bridge = old_router &&
|
||||||
if (! (routerinfo_is_a_configured_bridge(router) &&
|
old_router->purpose == ROUTER_PURPOSE_BRIDGE;
|
||||||
(router->purpose == ROUTER_PURPOSE_BRIDGE ||
|
if (! routerinfo_is_a_configured_bridge(router) ||
|
||||||
old_router->purpose != ROUTER_PURPOSE_BRIDGE))) {
|
(router->purpose != ROUTER_PURPOSE_BRIDGE && had_as_bridge)) {
|
||||||
log_info(LD_DIR,
|
log_info(LD_DIR,
|
||||||
"Dropping descriptor that we already have for router '%s'",
|
"Dropping descriptor that we already have for router '%s'",
|
||||||
router->nickname);
|
router->nickname);
|
||||||
|
Loading…
Reference in New Issue
Block a user