From 267434bdeac40a2ccc2677119ddc1925b80c0c4c Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Thu, 18 Jul 2002 06:37:58 +0000 Subject: 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 --- src/or/connection_ap.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/or/connection_ap.c') diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c index 95f60445d..ce4fdcd89 100644 --- a/src/or/connection_ap.c +++ b/src/or/connection_ap.c @@ -343,14 +343,17 @@ int connection_ap_process_data_cell(cell_t *cell, connection_t *conn) { assert(conn && conn->type == CONN_TYPE_AP); - if(conn->state == AP_CONN_STATE_OPEN) { - log(LOG_DEBUG,"connection_ap_process_data_cell(): In state 'open', writing to buf."); - return connection_write_to_buf(cell->payload, cell->length, conn); + if(conn->state != AP_CONN_STATE_OPEN) { + /* we should not have gotten this cell */ + log(LOG_DEBUG,"connection_ap_process_data_cell(): Got a data cell when not in 'open' state. Closing."); + return -1; } - /* else we shouldn't have gotten this cell */ - log(LOG_DEBUG,"connection_ap_process_data_cell(): Got a data cell when not in 'open' state. Closing."); - return -1; + log(LOG_DEBUG,"connection_ap_process_data_cell(): In state 'open', writing to buf."); + + if(connection_write_to_buf(cell->payload, cell->length, conn) < 0) + return -1; + return connection_consider_sending_sendme(conn); } int connection_ap_finished_flushing(connection_t *conn) { @@ -360,7 +363,8 @@ int connection_ap_finished_flushing(connection_t *conn) { switch(conn->state) { case AP_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_ap_finished_flushing() called in unexpected state."); @@ -377,7 +381,7 @@ int connection_ap_create_listener(RSA *prkey, struct sockaddr_in *local) { } int connection_ap_handle_listener_read(connection_t *conn) { - log(LOG_NOTICE,"AP: Received a connection request. Waiting for keys."); + log(LOG_NOTICE,"AP: Received a connection request. Waiting for SS."); return connection_handle_listener_read(conn, CONN_TYPE_AP, AP_CONN_STATE_SS_WAIT); } -- cgit v1.2.3