diff options
author | Roger Dingledine <arma@torproject.org> | 2002-07-16 01:12:15 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2002-07-16 01:12:15 +0000 |
commit | 117cbeeaaf30cdbbfe79dbe92fe47ab6a531bd8a (patch) | |
tree | 7d8b9fdb5277299ac2e67135b077a88edd666aa5 /src/or/or.h | |
parent | ffc545311b9c1142b6ed59482cb811f6388e1932 (diff) | |
download | tor-117cbeeaaf30cdbbfe79dbe92fe47ab6a531bd8a.tar.gz tor-117cbeeaaf30cdbbfe79dbe92fe47ab6a531bd8a.zip |
Implemented link padding and receiver token buckets
Each socket reads at most 'bandwidth' bytes per second sustained, but
can handle bursts of up to 10*bandwidth bytes.
Cells are now sent out at evenly-spaced intervals, with padding sent
out otherwise. Set Linkpadding=0 in the rc file to send cells as soon
as they're available (and to never send padding cells).
Added license/copyrights statements at the top of most files.
router->min and router->max have been merged into a single 'bandwidth'
value. We should make the routerinfo_t reflect this (want to do that,
Mat?)
As the bandwidth increases, and we want to stop sleeping more and more
frequently to send a single cell, cpu usage goes up. At 128kB/s we're
pretty much calling poll with a timeout of 1ms or even 0ms. The current
code takes a timeout of 0-9ms and makes it 10ms. prepare_for_poll()
handles everything that should have happened in the past, so as long as
our buffers don't get too full in that 10ms, we're ok.
Speaking of too full, if you run three servers at 100kB/s with -l debug,
it spends too much time printing debugging messages to be able to keep
up with the cells. The outbuf ultimately fills up and it kills that
connection. If you run with -l err, it works fine up through 500kB/s and
probably beyond. Down the road we'll want to teach it to recognize when
an outbuf is getting full, and back off.
svn:r50
Diffstat (limited to 'src/or/or.h')
-rw-r--r-- | src/or/or.h | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/src/or/or.h b/src/or/or.h index c65195049f..1db2e5462e 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2002 Roger Dingledine. See LICENSE for licensing information */ +/* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */ +/* See LICENSE for licensing information */ /* $Id$ */ #ifndef __OR_H @@ -38,8 +39,8 @@ #define MAXCONNECTIONS 200 /* upper bound on max connections. can be overridden by config file */ -#define MAX_BUF_SIZE (64*1024) -#define DEFAULT_BANDWIDTH_OP 1 +#define MAX_BUF_SIZE (640*1024) +#define DEFAULT_BANDWIDTH_OP 1024 #define ACI_TYPE_LOWER 0 #define ACI_TYPE_HIGHER 1 @@ -130,16 +131,19 @@ typedef struct int inbuf_reached_eof; char *outbuf; - size_t outbuflen; - size_t outbuf_datalen; + size_t outbuflen; /* how many bytes are allocated for the outbuf? */ + size_t outbuf_flushlen; /* how much data should we try to flush from the outbuf? */ + size_t outbuf_datalen; /* how much data is there total on the outbuf? */ // uint16_t aci; /* anonymous connection identifier */ /* used by OR and OP: */ uint32_t bandwidth; /* connection bandwidth */ - int window_sent; /* how many cells can i still send? */ - int window_received; /* how many cells do i still expect to receive? */ + int receiver_bucket; /* when this hits 0, stop receiving. Every second we + * add 'bandwidth' to this, capping it at 10*bandwidth. + */ + struct timeval send_timeval; /* for determining when to send the next cell */ /* link encryption */ unsigned char f_session_key[8]; @@ -169,9 +173,11 @@ typedef struct RSA *prkey; struct sockaddr_in local; - /* link info */ +#if 0 /* obsolete, we now use conn->bandwidth */ + /* link info */ uint32_t min; uint32_t max; +#endif char *address; /* strdup into this, because free_connection frees it */ RSA *pkey; /* public RSA key for the other side */ @@ -295,7 +301,8 @@ typedef struct int APPort; int MaxConn; int TrafficShaping; - int GlobalRole; + int LinkPadding; + int Role; int loglevel; } or_options_t; @@ -303,24 +310,16 @@ typedef struct /* all the function prototypes go here */ -/********************************* args.c ***************************/ - -/* print help*/ -void print_usage(); - -/* get command-line arguments */ -int getargs(int argc,char *argv[], char *args,char **conf_filename, int *loglevel); - /********************************* buffers.c ***************************/ int buf_new(char **buf, size_t *buflen, size_t *buf_datalen); void buf_free(char *buf); -int read_to_buf(int s, char **buf, size_t *buflen, size_t *buf_datalen, int *reached_eof); +int read_to_buf(int s, int at_most, char **buf, size_t *buflen, size_t *buf_datalen, int *reached_eof); /* grab from s, put onto buf, return how many bytes read */ -int flush_buf(int s, char **buf, size_t *buflen, size_t *buf_datalen); +int flush_buf(int s, char **buf, size_t *buflen, size_t *buf_flushlen, size_t *buf_datalen); /* push from buf onto s * then memmove to front of buf * return -1 or how many bytes remain on the buf */ @@ -384,6 +383,8 @@ int getoptions(int argc, char **argv, or_options_t *options); /********************************* connection.c ***************************/ +int tv_cmp(struct timeval *a, struct timeval *b); + connection_t *connection_new(int type); void connection_free(connection_t *conn); @@ -404,6 +405,16 @@ int connection_fetch_from_buf(char *string, int len, connection_t *conn); int connection_flush_buf(connection_t *conn); int connection_write_to_buf(char *string, int len, connection_t *conn); +void connection_send_cell(connection_t *conn); + +int connection_receiver_bucket_should_increase(connection_t *conn); +void connection_increment_receiver_bucket (connection_t *conn); + +void connection_increment_send_timeval(connection_t *conn); +void connection_init_timeval(connection_t *conn); + +int connection_state_is_open(connection_t *conn); + int connection_send_destroy(aci_t aci, connection_t *conn); int connection_encrypt_cell_header(cell_t *cellp, connection_t *conn); int connection_write_cell_to_buf(cell_t *cellp, connection_t *conn); @@ -500,12 +511,15 @@ routerinfo_t *router_get_first_in_route(unsigned int *route, size_t routelen); connection_t *connect_to_router_as_op(routerinfo_t *router); void connection_watch_events(connection_t *conn, short events); +void connection_stop_reading(connection_t *conn); +void connection_start_reading(connection_t *conn); void check_conn_read(int i); void check_conn_marked(int i); void check_conn_write(int i); -void check_conn_hup(int i); +int prepare_for_poll(int *timeout); +void increment_receiver_buckets(void); int do_main_loop(void); |