aboutsummaryrefslogtreecommitdiff
path: root/src/or/connection_exit.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2002-07-18 06:37:58 +0000
committerRoger Dingledine <arma@torproject.org>2002-07-18 06:37:58 +0000
commit267434bdeac40a2ccc2677119ddc1925b80c0c4c (patch)
tree27ce149ec317584dddb923f8e7fd4544baf59d15 /src/or/connection_exit.c
parentccdef66b68a2f61dfe600fddafaf270537928fac (diff)
downloadtor-267434bdeac40a2ccc2677119ddc1925b80c0c4c.tar
tor-267434bdeac40a2ccc2677119ddc1925b80c0c4c.tar.gz
Implemented congestion control
Servers are allowed to send 100 cells initially, and can't send more until they receive a 'sendme' cell from that direction, indicating that they can send 10 more cells. As it currently stands, the exit node quickly runs out of window, and sends bursts of 10 whenever a sendme cell gets to him. This is much much much faster (and more flexible) than the old "give each circuit 1 kB/s and hope nothing overflows" approach. Also divided out the connection_watch_events into stop_reading, start_writing, etc. That way we can control them separately. svn:r54
Diffstat (limited to 'src/or/connection_exit.c')
-rw-r--r--src/or/connection_exit.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/or/connection_exit.c b/src/or/connection_exit.c
index 00e4ec14b..c2ebca567 100644
--- a/src/or/connection_exit.c
+++ b/src/or/connection_exit.c
@@ -50,12 +50,14 @@ int connection_exit_finished_flushing(connection_t *conn) {
conn->address,ntohs(conn->port));
conn->state = EXIT_CONN_STATE_OPEN;
- connection_flush_buf(conn); /* in case there are any queued data cells */
- connection_watch_events(conn, POLLIN);
+ if(connection_wants_to_flush(conn)) /* in case there are any queued data cells */
+ connection_start_writing(conn);
+ connection_start_reading(conn);
return 0;
case EXIT_CONN_STATE_OPEN:
/* FIXME down the road, we'll clear out circuits that are pending to close */
- connection_watch_events(conn, POLLIN);
+ connection_stop_writing(conn);
+ connection_consider_sending_sendme(conn);
return 0;
default:
log(LOG_DEBUG,"Bug: connection_exit_finished_flushing() called in unexpected state.");
@@ -101,7 +103,7 @@ int connection_exit_process_data_cell(cell_t *cell, connection_t *conn) {
return -1;
}
memcpy(&conn->addr, rent->h_addr,rent->h_length);
- log(LOG_DEBUG,"connection_exit_process_data_cell(): addr %s resolves to %d.",cell->payload,conn->addr);
+ log(LOG_DEBUG,"connection_exit_process_data_cell(): addr is %s.",cell->payload);
} else if (!conn->port) { /* this cell contains the dest port */
if(!memchr(cell->payload,'\0',cell->length)) {
log(LOG_DEBUG,"connection_exit_process_data_cell(): dest_port cell has no \\0. Closing.");
@@ -139,7 +141,6 @@ int connection_exit_process_data_cell(cell_t *cell, connection_t *conn) {
connection_set_poll_socket(conn);
conn->state = EXIT_CONN_STATE_CONNECTING;
- /* i think only pollout is needed, but i'm curious if pollin ever gets caught -RD */
log(LOG_DEBUG,"connection_exit_process_data_cell(): connect in progress, socket %d.",s);
connection_watch_events(conn, POLLOUT | POLLIN);
return 0;
@@ -161,11 +162,12 @@ int connection_exit_process_data_cell(cell_t *cell, connection_t *conn) {
return 0;
case EXIT_CONN_STATE_CONNECTING:
log(LOG_DEBUG,"connection_exit_process_data_cell(): Data receiving while connecting. Queueing.");
- /* this sets us to POLLOUT | POLLIN, which is ok because we need to keep listening for
- * writable for connect() to finish */
- return connection_write_to_buf(cell->payload, cell->length, conn);
+ /* we stay listening for writable, so connect() can finish */
+ /* fall through to the next state -- write the cell and consider sending back a sendme */
case EXIT_CONN_STATE_OPEN:
- return connection_write_to_buf(cell->payload, cell->length, conn);
+ if(connection_write_to_buf(cell->payload, cell->length, conn) < 0)
+ return -1;
+ return connection_consider_sending_sendme(conn);
}
return 0;