bugfix: make onion proxies actually obey their requested bandwidth

svn:r229
This commit is contained in:
Roger Dingledine 2003-04-08 22:31:48 +00:00
parent c2fa6f5c7d
commit 833f165d68
3 changed files with 7 additions and 4 deletions

View File

@ -349,6 +349,7 @@ int connection_read_to_buf(connection_t *conn) {
&conn->inbuf_datalen, &conn->inbuf_reached_eof); &conn->inbuf_datalen, &conn->inbuf_reached_eof);
// log(LOG_DEBUG,"connection_read_to_buf(): read_to_buf returned %d.",read_result); // log(LOG_DEBUG,"connection_read_to_buf(): read_to_buf returned %d.",read_result);
if(read_result >= 0 && connection_speaks_cells(conn)) { if(read_result >= 0 && connection_speaks_cells(conn)) {
// log(LOG_DEBUG,"connection_read_to_buf(): Read %d, bucket now %d.",read_result,conn->receiver_bucket);
conn->receiver_bucket -= read_result; conn->receiver_bucket -= read_result;
if(conn->receiver_bucket <= 0) { if(conn->receiver_bucket <= 0) {
@ -483,6 +484,7 @@ void connection_increment_receiver_bucket (connection_t *conn) {
if(connection_receiver_bucket_should_increase(conn)) { if(connection_receiver_bucket_should_increase(conn)) {
/* yes, the receiver_bucket can become overfull here. But not by much. */ /* yes, the receiver_bucket can become overfull here. But not by much. */
conn->receiver_bucket += conn->bandwidth*1.1; conn->receiver_bucket += conn->bandwidth*1.1;
// log(LOG_DEBUG,"connection_increment_receiver_bucket(): Bucket now %d.",conn->receiver_bucket);
if(connection_state_is_open(conn)) { if(connection_state_is_open(conn)) {
/* if we're in state 'open', then start reading again */ /* if we're in state 'open', then start reading again */
connection_start_reading(conn); connection_start_reading(conn);

View File

@ -64,6 +64,7 @@ int op_handshake_process_keys(connection_t *conn) {
log(LOG_DEBUG,"Successfully decrypted keys from new OP."); log(LOG_DEBUG,"Successfully decrypted keys from new OP.");
conn->bandwidth = ntohl(*((uint32_t *)auth_plain)); conn->bandwidth = ntohl(*((uint32_t *)auth_plain));
log(LOG_DEBUG,"op_handshake_process_keys(): Bandwidth %d requested.",conn->bandwidth);
crypto_cipher_set_key(conn->b_crypto, auth_plain+4); crypto_cipher_set_key(conn->b_crypto, auth_plain+4);
crypto_cipher_set_key(conn->f_crypto, auth_plain+20); crypto_cipher_set_key(conn->f_crypto, auth_plain+20);

View File

@ -266,14 +266,14 @@ connection_t *connection_or_connect_as_op(routerinfo_t *router) {
} }
int or_handshake_op_send_keys(connection_t *conn) { int or_handshake_op_send_keys(connection_t *conn) {
//int x;
uint32_t bandwidth = DEFAULT_BANDWIDTH_OP;
unsigned char message[36]; /* bandwidth(32bits), forward key(128bits), backward key(128bits) */ unsigned char message[36]; /* bandwidth(32bits), forward key(128bits), backward key(128bits) */
unsigned char cipher[128]; unsigned char cipher[128];
int retval; int retval;
assert(conn && conn->type == CONN_TYPE_OR); assert(conn && conn->type == CONN_TYPE_OR);
conn->bandwidth = DEFAULT_BANDWIDTH_OP;
/* generate random keys */ /* generate random keys */
if(crypto_cipher_generate_key(conn->f_crypto) || if(crypto_cipher_generate_key(conn->f_crypto) ||
crypto_cipher_generate_key(conn->b_crypto)) { crypto_cipher_generate_key(conn->b_crypto)) {
@ -282,7 +282,7 @@ int or_handshake_op_send_keys(connection_t *conn) {
} }
log(LOG_DEBUG,"or_handshake_op_send_keys() : Generated 3DES keys."); log(LOG_DEBUG,"or_handshake_op_send_keys() : Generated 3DES keys.");
/* compose the message */ /* compose the message */
*(uint32_t *)message = htonl(bandwidth); *(uint32_t *)message = htonl(conn->bandwidth);
memcpy((void *)(message + 4), (void *)conn->f_crypto->key, 16); memcpy((void *)(message + 4), (void *)conn->f_crypto->key, 16);
memcpy((void *)(message + 20), (void *)conn->b_crypto->key, 16); memcpy((void *)(message + 20), (void *)conn->b_crypto->key, 16);