aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-07-21 15:08:00 -0400
committerAlexander Færøy <ahf@torproject.org>2020-07-29 13:33:35 +0000
commit3cb9a9b8ce7aeff0931d2b3f57bb2de0ba793669 (patch)
treebd1fc5e74c78a051d1d9036fdfc786fa65a4c92d /src/lib
parente8497bfaa70ef7ce8c48bc2c5464d6fddb8fcff1 (diff)
downloadtor-3cb9a9b8ce7aeff0931d2b3f57bb2de0ba793669.tar.gz
tor-3cb9a9b8ce7aeff0931d2b3f57bb2de0ba793669.zip
Remove the connection_t.outbuf_flushlen field
This was once used for rate-limiting, but now it's only for accounting. It hasn't served a useful purpose in a long time. Closes ticket 33097.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/buf/buffers.c13
-rw-r--r--src/lib/buf/buffers.h2
-rw-r--r--src/lib/net/buffers_net.c33
-rw-r--r--src/lib/net/buffers_net.h6
-rw-r--r--src/lib/process/process_unix.c2
-rw-r--r--src/lib/tls/buffers_tls.c24
-rw-r--r--src/lib/tls/buffers_tls.h2
7 files changed, 33 insertions, 49 deletions
diff --git a/src/lib/buf/buffers.c b/src/lib/buf/buffers.c
index 95b384bf06..aa0af69072 100644
--- a/src/lib/buf/buffers.c
+++ b/src/lib/buf/buffers.c
@@ -685,17 +685,20 @@ buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
}
/** Moves all data from <b>buf_in</b> to <b>buf_out</b>, without copying.
+ * Return the number of bytes that were moved.
*/
-void
+size_t
buf_move_all(buf_t *buf_out, buf_t *buf_in)
{
tor_assert(buf_out);
if (!buf_in)
- return;
+ return 0;
if (BUG(buf_out->datalen > BUF_MAX_LEN || buf_in->datalen > BUF_MAX_LEN))
- return;
+ return 0;
if (BUG(buf_out->datalen > BUF_MAX_LEN - buf_in->datalen))
- return;
+ return 0;
+
+ size_t n_bytes_moved = buf_in->datalen;
if (buf_out->head == NULL) {
buf_out->head = buf_in->head;
@@ -708,6 +711,8 @@ buf_move_all(buf_t *buf_out, buf_t *buf_in)
buf_out->datalen += buf_in->datalen;
buf_in->head = buf_in->tail = NULL;
buf_in->datalen = 0;
+
+ return n_bytes_moved;
}
/** Internal structure: represents a position in a buffer. */
diff --git a/src/lib/buf/buffers.h b/src/lib/buf/buffers.h
index d8a77feb72..1361a02eba 100644
--- a/src/lib/buf/buffers.h
+++ b/src/lib/buf/buffers.h
@@ -46,7 +46,7 @@ void buf_add_printf(buf_t *buf, const char *format, ...)
void buf_add_vprintf(buf_t *buf, const char *format, va_list args)
CHECK_PRINTF(2, 0);
int buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen);
-void buf_move_all(buf_t *buf_out, buf_t *buf_in);
+size_t buf_move_all(buf_t *buf_out, buf_t *buf_in);
void buf_peek(const buf_t *buf, char *string, size_t string_len);
void buf_drain(buf_t *buf, size_t n);
int buf_get_bytes(buf_t *buf, char *string, size_t string_len);
diff --git a/src/lib/net/buffers_net.c b/src/lib/net/buffers_net.c
index 4dbf491e1a..4a0eb3bf16 100644
--- a/src/lib/net/buffers_net.c
+++ b/src/lib/net/buffers_net.c
@@ -137,13 +137,12 @@ buf_read_from_fd(buf_t *buf, int fd, size_t at_most,
}
/** Helper for buf_flush_to_socket(): try to write <b>sz</b> bytes from chunk
- * <b>chunk</b> of buffer <b>buf</b> onto file descriptor <b>fd</b>. On
- * success, deduct the bytes written from *<b>buf_flushlen</b>. Return the
- * number of bytes written on success, 0 on blocking, -1 on failure.
+ * <b>chunk</b> of buffer <b>buf</b> onto file descriptor <b>fd</b>. Return
+ * the number of bytes written on success, 0 on blocking, -1 on failure.
*/
static inline int
flush_chunk(tor_socket_t fd, buf_t *buf, chunk_t *chunk, size_t sz,
- size_t *buf_flushlen, bool is_socket)
+ bool is_socket)
{
ssize_t write_result;
@@ -168,7 +167,6 @@ flush_chunk(tor_socket_t fd, buf_t *buf, chunk_t *chunk, size_t sz,
log_debug(LD_NET,"write() would block, returning.");
return 0;
} else {
- *buf_flushlen -= write_result;
buf_drain(buf, write_result);
tor_assert(write_result <= BUF_MAX_LEN);
return (int)write_result;
@@ -176,27 +174,22 @@ flush_chunk(tor_socket_t fd, buf_t *buf, chunk_t *chunk, size_t sz,
}
/** Write data from <b>buf</b> to the file descriptor <b>fd</b>. Write at most
- * <b>sz</b> bytes, decrement *<b>buf_flushlen</b> by
- * the number of bytes actually written, and remove the written bytes
+ * <b>sz</b> bytes, and remove the written bytes
* from the buffer. Return the number of bytes written on success,
* -1 on failure. Return 0 if write() would block.
*/
static int
buf_flush_to_fd(buf_t *buf, int fd, size_t sz,
- size_t *buf_flushlen, bool is_socket)
+ bool is_socket)
{
/* XXXX It's stupid to overload the return values for these functions:
* "error status" and "number of bytes flushed" are not mutually exclusive.
*/
int r;
size_t flushed = 0;
- tor_assert(buf_flushlen);
tor_assert(SOCKET_OK(fd));
- if (BUG(*buf_flushlen > buf->datalen)) {
- *buf_flushlen = buf->datalen;
- }
- if (BUG(sz > *buf_flushlen)) {
- sz = *buf_flushlen;
+ if (BUG(sz > buf->datalen)) {
+ sz = buf->datalen;
}
check();
@@ -208,7 +201,7 @@ buf_flush_to_fd(buf_t *buf, int fd, size_t sz,
else
flushlen0 = buf->head->datalen;
- r = flush_chunk(fd, buf, buf->head, flushlen0, buf_flushlen, is_socket);
+ r = flush_chunk(fd, buf, buf->head, flushlen0, is_socket);
check();
if (r < 0)
return r;
@@ -228,10 +221,9 @@ buf_flush_to_fd(buf_t *buf, int fd, size_t sz,
* -1 on failure. Return 0 if write() would block.
*/
int
-buf_flush_to_socket(buf_t *buf, tor_socket_t s, size_t sz,
- size_t *buf_flushlen)
+buf_flush_to_socket(buf_t *buf, tor_socket_t s, size_t sz)
{
- return buf_flush_to_fd(buf, s, sz, buf_flushlen, true);
+ return buf_flush_to_fd(buf, s, sz, true);
}
/** Read from socket <b>s</b>, writing onto end of <b>buf</b>. Read at most
@@ -254,10 +246,9 @@ buf_read_from_socket(buf_t *buf, tor_socket_t s, size_t at_most,
* -1 on failure. Return 0 if write() would block.
*/
int
-buf_flush_to_pipe(buf_t *buf, int fd, size_t sz,
- size_t *buf_flushlen)
+buf_flush_to_pipe(buf_t *buf, int fd, size_t sz)
{
- return buf_flush_to_fd(buf, fd, sz, buf_flushlen, false);
+ return buf_flush_to_fd(buf, fd, sz, false);
}
/** Read from pipe <b>fd</b>, writing onto end of <b>buf</b>. Read at most
diff --git a/src/lib/net/buffers_net.h b/src/lib/net/buffers_net.h
index a45c23a273..556575c3dc 100644
--- a/src/lib/net/buffers_net.h
+++ b/src/lib/net/buffers_net.h
@@ -21,14 +21,12 @@ int buf_read_from_socket(struct buf_t *buf, tor_socket_t s, size_t at_most,
int *reached_eof,
int *socket_error);
-int buf_flush_to_socket(struct buf_t *buf, tor_socket_t s, size_t sz,
- size_t *buf_flushlen);
+int buf_flush_to_socket(struct buf_t *buf, tor_socket_t s, size_t sz);
int buf_read_from_pipe(struct buf_t *buf, int fd, size_t at_most,
int *reached_eof,
int *socket_error);
-int buf_flush_to_pipe(struct buf_t *buf, int fd, size_t sz,
- size_t *buf_flushlen);
+int buf_flush_to_pipe(struct buf_t *buf, int fd, size_t sz);
#endif /* !defined(TOR_BUFFERS_NET_H) */
diff --git a/src/lib/process/process_unix.c b/src/lib/process/process_unix.c
index 2b47e1874d..82b2630a5d 100644
--- a/src/lib/process/process_unix.c
+++ b/src/lib/process/process_unix.c
@@ -418,7 +418,7 @@ process_unix_write(process_t *process, buf_t *buffer)
/* We have data to write and the kernel have told us to write it. */
return buf_flush_to_pipe(buffer,
process_get_unix_process(process)->stdin_handle.fd,
- max_to_write, &buffer_flush_len);
+ max_to_write);
}
/** Read data from the given process's standard output and put it into
diff --git a/src/lib/tls/buffers_tls.c b/src/lib/tls/buffers_tls.c
index 1b99467d2b..de0e9cb4ef 100644
--- a/src/lib/tls/buffers_tls.c
+++ b/src/lib/tls/buffers_tls.c
@@ -106,8 +106,7 @@ buf_read_from_tls(buf_t *buf, tor_tls_t *tls, size_t at_most)
* written on success, and a TOR_TLS error code on failure or blocking.
*/
static inline int
-flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk,
- size_t sz, size_t *buf_flushlen)
+flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk, size_t sz)
{
int r;
size_t forced;
@@ -126,13 +125,9 @@ flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk,
r = tor_tls_write(tls, data, sz);
if (r < 0)
return r;
- if (*buf_flushlen > (size_t)r)
- *buf_flushlen -= r;
- else
- *buf_flushlen = 0;
buf_drain(buf, r);
- log_debug(LD_NET,"flushed %d bytes, %d ready to flush, %d remain.",
- r,(int)*buf_flushlen,(int)buf->datalen);
+ log_debug(LD_NET,"flushed %d bytes, %d remain.",
+ r,(int)buf->datalen);
return r;
}
@@ -140,18 +135,13 @@ flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk,
* more than <b>flushlen</b> bytes.
*/
int
-buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen,
- size_t *buf_flushlen)
+buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen)
{
int r;
size_t flushed = 0;
ssize_t sz;
- tor_assert(buf_flushlen);
- IF_BUG_ONCE(*buf_flushlen > buf->datalen) {
- *buf_flushlen = buf->datalen;
- }
- IF_BUG_ONCE(flushlen > *buf_flushlen) {
- flushlen = *buf_flushlen;
+ IF_BUG_ONCE(flushlen > buf->datalen) {
+ flushlen = buf->datalen;
}
sz = (ssize_t) flushlen;
@@ -170,7 +160,7 @@ buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen,
flushlen0 = 0;
}
- r = flush_chunk_tls(tls, buf, buf->head, flushlen0, buf_flushlen);
+ r = flush_chunk_tls(tls, buf, buf->head, flushlen0);
if (r < 0)
return r;
flushed += r;
diff --git a/src/lib/tls/buffers_tls.h b/src/lib/tls/buffers_tls.h
index 587426801d..ed391cefbd 100644
--- a/src/lib/tls/buffers_tls.h
+++ b/src/lib/tls/buffers_tls.h
@@ -18,6 +18,6 @@ struct tor_tls_t;
int buf_read_from_tls(struct buf_t *buf,
struct tor_tls_t *tls, size_t at_most);
int buf_flush_to_tls(struct buf_t *buf, struct tor_tls_t *tls,
- size_t sz, size_t *buf_flushlen);
+ size_t sz);
#endif /* !defined(TOR_BUFFERS_TLS_H) */