[or-cvs] [tor/master 16/38] Fix more remaining users of inbuf/outbuf to handle bufferevents instead.
nickm at torproject.org
nickm at torproject.org
Mon Sep 27 20:50:59 UTC 2010
Author: Nick Mathewson <nickm at torproject.org>
Date: Sun, 9 Aug 2009 11:40:28 -0700
Subject: Fix more remaining users of inbuf/outbuf to handle bufferevents instead.
Commit: ddcb59bb70457e203247931aaad3a3ff8b923f97
---
src/or/buffers.c | 21 +++++++++++++++++++++
src/or/buffers.h | 1 +
src/or/connection.c | 18 ++++++++++++++++++
src/or/connection.h | 4 ++++
src/or/connection_or.c | 12 +++++++++---
src/or/control.c | 13 ++++++++++++-
src/or/cpuworker.c | 4 ++--
src/or/directory.c | 4 ++--
8 files changed, 69 insertions(+), 8 deletions(-)
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 374c37c..9fde897 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -1988,6 +1988,27 @@ peek_buf_has_control0_command(buf_t *buf)
return 0;
}
+#ifdef USE_BUFFEREVENTS
+int
+peek_evbuffer_has_control0_command(struct evbuffer *buf)
+{
+ int result = 0;
+ if (evbuffer_get_length(buf) >= 4) {
+ int free_out = 0;
+ char *data = NULL;
+ size_t n = inspect_evbuffer(buf, &data, 4, &free_out);
+ uint16_t cmd;
+ tor_assert(n >= 4);
+ cmd = ntohs(get_uint16(data+2));
+ if (cmd <= 0x14)
+ result = 1;
+ if (free_out)
+ tor_free(data);
+ }
+ return result;
+}
+#endif
+
/** Return the index within <b>buf</b> at which <b>ch</b> first appears,
* or -1 if <b>ch</b> does not appear on buf. */
static off_t
diff --git a/src/or/buffers.h b/src/or/buffers.h
index ca01dc8..4f565dd 100644
--- a/src/or/buffers.h
+++ b/src/or/buffers.h
@@ -57,6 +57,7 @@ int fetch_from_evbuffer_http(struct evbuffer *buf,
char **headers_out, size_t max_headerlen,
char **body_out, size_t *body_used, size_t max_bodylen,
int force_complete);
+int peek_evbuffer_has_control0_command(struct evbuffer *buf);
#endif
void assert_buf_ok(buf_t *buf);
diff --git a/src/or/connection.c b/src/or/connection.c
index 54b9911..e6b4bc3 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -2785,6 +2785,24 @@ connection_fetch_from_buf_line(connection_t *conn, char *data,
}
}
+/** As fetch_from_buf_http, but fetches from a conncetion's input buffer_t or
+ * its bufferevent as appropriate. */
+int
+connection_fetch_from_buf_http(connection_t *conn,
+ char **headers_out, size_t max_headerlen,
+ char **body_out, size_t *body_used,
+ size_t max_bodylen, int force_complete)
+{
+ IF_HAS_BUFFEREVENT(conn, {
+ struct evbuffer *input = bufferevent_get_input(conn->bufev);
+ return fetch_from_evbuffer_http(input, headers_out, max_headerlen,
+ body_out, body_used, max_bodylen, force_complete);
+ }) ELSE_IF_NO_BUFFEREVENT {
+ return fetch_from_buf_http(conn->inbuf, headers_out, max_headerlen,
+ body_out, body_used, max_bodylen, force_complete);
+ }
+}
+
/** Return conn-\>outbuf_flushlen: how many bytes conn wants to flush
* from its outbuf. */
int
diff --git a/src/or/connection.h b/src/or/connection.h
index af21481..4d269d6 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -65,6 +65,10 @@ int connection_handle_read(connection_t *conn);
int connection_fetch_from_buf(char *string, size_t len, connection_t *conn);
int connection_fetch_from_buf_line(connection_t *conn, char *data,
size_t *data_len);
+int connection_fetch_from_buf_http(connection_t *conn,
+ char **headers_out, size_t max_headerlen,
+ char **body_out, size_t *body_used,
+ size_t max_bodylen, int force_complete);
int connection_wants_to_flush(connection_t *conn);
int connection_outbuf_too_full(connection_t *conn);
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 169f141..a2eb868 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -1253,12 +1253,18 @@ connection_or_write_var_cell_to_buf(const var_cell_t *cell,
conn->timestamp_last_added_nonpadding = approx_time();
}
-/** See whether there's a variable-length cell waiting on <b>conn</b>'s
+/** See whether there's a variable-length cell waiting on <b>or_conn</b>'s
* inbuf. Return values as for fetch_var_cell_from_buf(). */
static int
-connection_fetch_var_cell_from_buf(or_connection_t *conn, var_cell_t **out)
+connection_fetch_var_cell_from_buf(or_connection_t *or_conn, var_cell_t **out)
{
- return fetch_var_cell_from_buf(conn->_base.inbuf, out, conn->link_proto);
+ connection_t *conn = TO_CONN(or_conn);
+ IF_HAS_BUFFEREVENT(conn, {
+ struct evbuffer *input = bufferevent_get_input(conn->bufev);
+ return fetch_var_cell_from_evbuffer(input, out, or_conn->link_proto);
+ }) ELSE_IF_NO_BUFFEREVENT {
+ return fetch_var_cell_from_buf(conn->inbuf, out, or_conn->link_proto);
+ }
}
/** Process cells from <b>conn</b>'s inbuf.
diff --git a/src/or/control.c b/src/or/control.c
index ac004b5..37ebfd8 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -2753,6 +2753,17 @@ is_valid_initial_command(control_connection_t *conn, const char *cmd)
* interfaces is broken. */
#define MAX_COMMAND_LINE_LENGTH (1024*1024)
+static int
+peek_connection_has_control0_command(connection_t *conn)
+{
+ IF_HAS_BUFFEREVENT(conn, {
+ struct evbuffer *input = bufferevent_get_input(conn->bufev);
+ return peek_evbuffer_has_control0_command(input);
+ }) ELSE_IF_NO_BUFFEREVENT {
+ return peek_buf_has_control0_command(conn->inbuf);
+ }
+}
+
/** Called when data has arrived on a v1 control connection: Try to fetch
* commands from conn->inbuf, and execute them.
*/
@@ -2775,7 +2786,7 @@ connection_control_process_inbuf(control_connection_t *conn)
}
if (conn->_base.state == CONTROL_CONN_STATE_NEEDAUTH &&
- peek_buf_has_control0_command(conn->_base.inbuf)) {
+ peek_connection_has_control0_command(TO_CONN(conn))) {
/* Detect v0 commands and send a "no more v0" message. */
size_t body_len;
char buf[128];
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index a9c29d2..e5b2c71 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -144,9 +144,9 @@ connection_cpu_process_inbuf(connection_t *conn)
return 0;
if (conn->state == CPUWORKER_STATE_BUSY_ONION) {
- if (buf_datalen(conn->inbuf) < LEN_ONION_RESPONSE) /* answer available? */
+ if (connection_get_inbuf_len(conn) < LEN_ONION_RESPONSE)
return 0; /* not yet */
- tor_assert(buf_datalen(conn->inbuf) == LEN_ONION_RESPONSE);
+ tor_assert(connection_get_inbuf_len(conn) == LEN_ONION_RESPONSE);
connection_fetch_from_buf(&success,1,conn);
connection_fetch_from_buf(buf,LEN_ONION_RESPONSE-1,conn);
diff --git a/src/or/directory.c b/src/or/directory.c
index 2e9770e..284a1ad 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -1466,7 +1466,7 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
int was_compressed=0;
time_t now = time(NULL);
- switch (fetch_from_buf_http(conn->_base.inbuf,
+ switch (connection_fetch_from_buf_http(TO_CONN(conn),
&headers, MAX_HEADERS_SIZE,
&body, &body_len, MAX_DIR_DL_SIZE,
allow_partial)) {
@@ -3299,7 +3299,7 @@ directory_handle_command(dir_connection_t *conn)
tor_assert(conn);
tor_assert(conn->_base.type == CONN_TYPE_DIR);
- switch (fetch_from_buf_http(conn->_base.inbuf,
+ switch (connection_fetch_from_buf_http(TO_CONN(conn),
&headers, MAX_HEADERS_SIZE,
&body, &body_len, MAX_DIR_UL_SIZE, 0)) {
case -1: /* overflow */
--
1.7.1
More information about the tor-commits
mailing list