Loading src/or/config.c +2 −0 Original line number Diff line number Diff line Loading @@ -212,6 +212,8 @@ static config_var_t _option_vars[] = { VAR("RecommendedClientVersions", LINELIST, RecommendedClientVersions, NULL), VAR("RecommendedServerVersions", LINELIST, RecommendedServerVersions, NULL), VAR("RedirectExit", LINELIST, RedirectExit, NULL), VAR("RelayBandwidthBurst", MEMUNIT, RelayBandwidthBurst, "0"), VAR("RelayBandwidthRate", MEMUNIT, RelayBandwidthRate, "0"), VAR("RendExcludeNodes", STRING, RendExcludeNodes, NULL), VAR("RendNodes", STRING, RendNodes, NULL), VAR("RendPostPeriod", INTERVAL, RendPostPeriod, "1 hour"), Loading src/or/connection.c +5 −6 Original line number Diff line number Diff line Loading @@ -1043,10 +1043,8 @@ static void connection_read_bucket_decrement(connection_t *conn, int num_read) { global_read_bucket -= num_read; //tor_assert(global_read_bucket >= 0); if (connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) { conn->receiver_bucket -= num_read; //tor_assert(conn->receiver_bucket >= 0); } } Loading @@ -1071,8 +1069,7 @@ connection_consider_empty_buckets(connection_t *conn) } } /** Initialize the global read bucket to options->BandwidthBurst, * and current_time to the current time. */ /** Initialize the global read bucket to options->BandwidthBurst. */ void connection_bucket_init(void) { Loading Loading @@ -1110,7 +1107,9 @@ connection_bucket_refill(struct timeval *now) conn = carray[i]; if (connection_receiver_bucket_should_increase(conn)) { conn->receiver_bucket = conn->bandwidth; conn->receiver_bucket += conn->bandwidthrate; if (conn->receiver_bucket > conn->bandwidthburst) conn->receiver_bucket = conn->bandwidthburst; //log_fn(LOG_DEBUG,"Receiver bucket %d now %d.", i, // conn->receiver_bucket); } Loading Loading @@ -1147,7 +1146,7 @@ connection_receiver_bucket_should_increase(connection_t *conn) if (conn->state != OR_CONN_STATE_OPEN) return 0; /* only open connections play the rate limiting game */ if (conn->receiver_bucket >= conn->bandwidth) if (conn->receiver_bucket >= conn->bandwidthburst) return 0; return 1; Loading src/or/connection_or.c +23 −40 Original line number Diff line number Diff line Loading @@ -314,11 +314,8 @@ connection_or_finished_connecting(connection_t *conn) static void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router) { or_options_t *options = get_options(); conn->addr = router->addr; conn->port = router->or_port; conn->receiver_bucket = conn->bandwidth = (int)options->BandwidthBurst; connection_or_set_identity_digest(conn, router->cache_info.identity_digest); conn->nickname = tor_strdup(router->nickname); tor_free(conn->address); Loading @@ -331,19 +328,19 @@ connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router) static void connection_or_init_conn_from_address(connection_t *conn, uint32_t addr, uint16_t port, const char *id_digest) const char *id_digest, int started_here) { const char *n; or_options_t *options = get_options(); routerinfo_t *r = router_get_by_digest(id_digest); conn->bandwidthrate = (int)options->BandwidthRate; conn->receiver_bucket = conn->bandwidthburst = (int)options->BandwidthBurst; if (r) { connection_or_init_conn_from_router(conn,r); return; } } else { const char *n; conn->addr = addr; conn->port = port; /* This next part isn't really right, but it's good enough for now. */ conn->receiver_bucket = conn->bandwidth = (int)options->BandwidthBurst; connection_or_set_identity_digest(conn, id_digest); /* If we're an authoritative directory server, we may know a * nickname for this router. */ Loading @@ -359,6 +356,7 @@ connection_or_init_conn_from_address(connection_t *conn, tor_free(conn->address); conn->address = tor_dup_addr(addr); } } /** Return the best connection of type OR with the * digest <b>digest</b> that we have, or NULL if we have none. Loading Loading @@ -443,7 +441,7 @@ connection_or_connect(uint32_t addr, uint16_t port, const char *id_digest) conn = connection_new(CONN_TYPE_OR); /* set up conn so it's got all the data we need to remember */ connection_or_init_conn_from_address(conn, addr, port, id_digest); connection_or_init_conn_from_address(conn, addr, port, id_digest, 1); conn->state = OR_CONN_STATE_CONNECTING; control_event_or_conn_status(conn, OR_CONN_EVENT_LAUNCHED); Loading Loading @@ -658,8 +656,6 @@ connection_or_check_valid_handshake(connection_t *conn, char *digest_rcvd) * If he initiated the connection, make sure he's not already connected, * then initialize conn from the information in router. * * If I'm not a server, set bandwidth to the default OP bandwidth. * * If all is successful, call circuit_n_conn_done() to handle events * that have been pending on the tls handshake completion. Also set the * directory to be dirty (only matters if I'm an authdirserver). Loading @@ -675,17 +671,8 @@ connection_tls_finish_handshake(connection_t *conn) return -1; if (!started_here) { #if 0 connection_t *c; if ((c=connection_or_get_by_identity_digest(digest_rcvd))) { log_debug(LD_OR, "Router '%s' is already connected on fd %d. Dropping fd %d.", c->nickname, c->s, conn->s); return -1; } #endif connection_or_init_conn_from_address(conn,conn->addr,conn->port, digest_rcvd); digest_rcvd, 0); /* Annotate that we received a TLS connection. * (Todo: only actually consider ourselves reachable if there Loading @@ -701,10 +688,6 @@ connection_tls_finish_handshake(connection_t *conn) router_orport_found_reachable(); } if (!server_mode(get_options())) { /* If I'm an OP... */ conn->receiver_bucket = conn->bandwidth = DEFAULT_BANDWIDTH_OP; } directory_set_dirty(); conn->state = OR_CONN_STATE_OPEN; control_event_or_conn_status(conn, OR_CONN_EVENT_CONNECTED); Loading src/or/or.h +9 −5 Original line number Diff line number Diff line Loading @@ -149,7 +149,6 @@ #define cell_t tor_cell_t #endif #define DEFAULT_BANDWIDTH_OP (1024 * 1000) #define MAX_NICKNAME_LEN 19 /* Hex digest plus dollar sign. */ #define MAX_HEX_NICKNAME_LEN (HEX_DIGEST_LEN+1) Loading Loading @@ -666,11 +665,12 @@ struct connection_t { /* Used only by OR connections: */ tor_tls_t *tls; /**< TLS connection state (OR only.) */ /* bandwidth and receiver_bucket only used by ORs in OPEN state: */ int bandwidth; /**< Connection bandwidth. (OPEN ORs only.) */ /* bandwidth* and receiver_bucket only used by ORs in OPEN state: */ int bandwidthrate; /**< Bytes/s added to the bucket. (OPEN ORs only.) */ int bandwidthburst; /**< Max bucket size for this conn. (OPEN ORs only.) */ int receiver_bucket; /**< When this hits 0, stop receiving. Every second we * add 'bandwidth' to this, capping it at 10*bandwidth. * (OPEN ORs only) * add 'bandwidthrate' to this, capping it at * bandwidthburst. (OPEN ORs only) */ circ_id_type_t circ_id_type; /**< When we send CREATE cells along this * connection, which half of the space should Loading Loading @@ -1320,6 +1320,10 @@ typedef struct { * to use in a second? */ uint64_t MaxAdvertisedBandwidth; /**< How much bandwidth are we willing to * tell people we have? */ uint64_t RelayBandwidthRate; /**< How much bandwidth, on average, are we * willing to use for all relayed conns? */ uint64_t RelayBandwidthBurst; /**< How much bandwidth, at maximum, will we * use in a second for all relayed conns? */ int NumCpus; /**< How many CPUs should we try to use? */ int RunTesting; /**< If true, create testing circuits to measure how well the * other ORs are running. */ Loading Loading
src/or/config.c +2 −0 Original line number Diff line number Diff line Loading @@ -212,6 +212,8 @@ static config_var_t _option_vars[] = { VAR("RecommendedClientVersions", LINELIST, RecommendedClientVersions, NULL), VAR("RecommendedServerVersions", LINELIST, RecommendedServerVersions, NULL), VAR("RedirectExit", LINELIST, RedirectExit, NULL), VAR("RelayBandwidthBurst", MEMUNIT, RelayBandwidthBurst, "0"), VAR("RelayBandwidthRate", MEMUNIT, RelayBandwidthRate, "0"), VAR("RendExcludeNodes", STRING, RendExcludeNodes, NULL), VAR("RendNodes", STRING, RendNodes, NULL), VAR("RendPostPeriod", INTERVAL, RendPostPeriod, "1 hour"), Loading
src/or/connection.c +5 −6 Original line number Diff line number Diff line Loading @@ -1043,10 +1043,8 @@ static void connection_read_bucket_decrement(connection_t *conn, int num_read) { global_read_bucket -= num_read; //tor_assert(global_read_bucket >= 0); if (connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) { conn->receiver_bucket -= num_read; //tor_assert(conn->receiver_bucket >= 0); } } Loading @@ -1071,8 +1069,7 @@ connection_consider_empty_buckets(connection_t *conn) } } /** Initialize the global read bucket to options->BandwidthBurst, * and current_time to the current time. */ /** Initialize the global read bucket to options->BandwidthBurst. */ void connection_bucket_init(void) { Loading Loading @@ -1110,7 +1107,9 @@ connection_bucket_refill(struct timeval *now) conn = carray[i]; if (connection_receiver_bucket_should_increase(conn)) { conn->receiver_bucket = conn->bandwidth; conn->receiver_bucket += conn->bandwidthrate; if (conn->receiver_bucket > conn->bandwidthburst) conn->receiver_bucket = conn->bandwidthburst; //log_fn(LOG_DEBUG,"Receiver bucket %d now %d.", i, // conn->receiver_bucket); } Loading Loading @@ -1147,7 +1146,7 @@ connection_receiver_bucket_should_increase(connection_t *conn) if (conn->state != OR_CONN_STATE_OPEN) return 0; /* only open connections play the rate limiting game */ if (conn->receiver_bucket >= conn->bandwidth) if (conn->receiver_bucket >= conn->bandwidthburst) return 0; return 1; Loading
src/or/connection_or.c +23 −40 Original line number Diff line number Diff line Loading @@ -314,11 +314,8 @@ connection_or_finished_connecting(connection_t *conn) static void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router) { or_options_t *options = get_options(); conn->addr = router->addr; conn->port = router->or_port; conn->receiver_bucket = conn->bandwidth = (int)options->BandwidthBurst; connection_or_set_identity_digest(conn, router->cache_info.identity_digest); conn->nickname = tor_strdup(router->nickname); tor_free(conn->address); Loading @@ -331,19 +328,19 @@ connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router) static void connection_or_init_conn_from_address(connection_t *conn, uint32_t addr, uint16_t port, const char *id_digest) const char *id_digest, int started_here) { const char *n; or_options_t *options = get_options(); routerinfo_t *r = router_get_by_digest(id_digest); conn->bandwidthrate = (int)options->BandwidthRate; conn->receiver_bucket = conn->bandwidthburst = (int)options->BandwidthBurst; if (r) { connection_or_init_conn_from_router(conn,r); return; } } else { const char *n; conn->addr = addr; conn->port = port; /* This next part isn't really right, but it's good enough for now. */ conn->receiver_bucket = conn->bandwidth = (int)options->BandwidthBurst; connection_or_set_identity_digest(conn, id_digest); /* If we're an authoritative directory server, we may know a * nickname for this router. */ Loading @@ -359,6 +356,7 @@ connection_or_init_conn_from_address(connection_t *conn, tor_free(conn->address); conn->address = tor_dup_addr(addr); } } /** Return the best connection of type OR with the * digest <b>digest</b> that we have, or NULL if we have none. Loading Loading @@ -443,7 +441,7 @@ connection_or_connect(uint32_t addr, uint16_t port, const char *id_digest) conn = connection_new(CONN_TYPE_OR); /* set up conn so it's got all the data we need to remember */ connection_or_init_conn_from_address(conn, addr, port, id_digest); connection_or_init_conn_from_address(conn, addr, port, id_digest, 1); conn->state = OR_CONN_STATE_CONNECTING; control_event_or_conn_status(conn, OR_CONN_EVENT_LAUNCHED); Loading Loading @@ -658,8 +656,6 @@ connection_or_check_valid_handshake(connection_t *conn, char *digest_rcvd) * If he initiated the connection, make sure he's not already connected, * then initialize conn from the information in router. * * If I'm not a server, set bandwidth to the default OP bandwidth. * * If all is successful, call circuit_n_conn_done() to handle events * that have been pending on the tls handshake completion. Also set the * directory to be dirty (only matters if I'm an authdirserver). Loading @@ -675,17 +671,8 @@ connection_tls_finish_handshake(connection_t *conn) return -1; if (!started_here) { #if 0 connection_t *c; if ((c=connection_or_get_by_identity_digest(digest_rcvd))) { log_debug(LD_OR, "Router '%s' is already connected on fd %d. Dropping fd %d.", c->nickname, c->s, conn->s); return -1; } #endif connection_or_init_conn_from_address(conn,conn->addr,conn->port, digest_rcvd); digest_rcvd, 0); /* Annotate that we received a TLS connection. * (Todo: only actually consider ourselves reachable if there Loading @@ -701,10 +688,6 @@ connection_tls_finish_handshake(connection_t *conn) router_orport_found_reachable(); } if (!server_mode(get_options())) { /* If I'm an OP... */ conn->receiver_bucket = conn->bandwidth = DEFAULT_BANDWIDTH_OP; } directory_set_dirty(); conn->state = OR_CONN_STATE_OPEN; control_event_or_conn_status(conn, OR_CONN_EVENT_CONNECTED); Loading
src/or/or.h +9 −5 Original line number Diff line number Diff line Loading @@ -149,7 +149,6 @@ #define cell_t tor_cell_t #endif #define DEFAULT_BANDWIDTH_OP (1024 * 1000) #define MAX_NICKNAME_LEN 19 /* Hex digest plus dollar sign. */ #define MAX_HEX_NICKNAME_LEN (HEX_DIGEST_LEN+1) Loading Loading @@ -666,11 +665,12 @@ struct connection_t { /* Used only by OR connections: */ tor_tls_t *tls; /**< TLS connection state (OR only.) */ /* bandwidth and receiver_bucket only used by ORs in OPEN state: */ int bandwidth; /**< Connection bandwidth. (OPEN ORs only.) */ /* bandwidth* and receiver_bucket only used by ORs in OPEN state: */ int bandwidthrate; /**< Bytes/s added to the bucket. (OPEN ORs only.) */ int bandwidthburst; /**< Max bucket size for this conn. (OPEN ORs only.) */ int receiver_bucket; /**< When this hits 0, stop receiving. Every second we * add 'bandwidth' to this, capping it at 10*bandwidth. * (OPEN ORs only) * add 'bandwidthrate' to this, capping it at * bandwidthburst. (OPEN ORs only) */ circ_id_type_t circ_id_type; /**< When we send CREATE cells along this * connection, which half of the space should Loading Loading @@ -1320,6 +1320,10 @@ typedef struct { * to use in a second? */ uint64_t MaxAdvertisedBandwidth; /**< How much bandwidth are we willing to * tell people we have? */ uint64_t RelayBandwidthRate; /**< How much bandwidth, on average, are we * willing to use for all relayed conns? */ uint64_t RelayBandwidthBurst; /**< How much bandwidth, at maximum, will we * use in a second for all relayed conns? */ int NumCpus; /**< How many CPUs should we try to use? */ int RunTesting; /**< If true, create testing circuits to measure how well the * other ORs are running. */ Loading