[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[or-cvs] new link padding scheme
Update of /home/or/cvsroot/src/or
In directory moria.seul.org:/home/arma/work/onion/cvs/src/or
Modified Files:
connection.c main.c
Log Message:
new link padding scheme
we're now much more robust when bandwidth varies: instead of forcing a
fixed bandwidth on the link, we instead use what the link will give us,
up to our bandwidth.
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- connection.c 16 Jul 2002 02:12:58 -0000 1.7
+++ connection.c 16 Jul 2002 18:24:12 -0000 1.8
@@ -364,6 +364,10 @@
void connection_send_cell(connection_t *conn) {
cell_t cell;
+ int bytes_in_full_flushlen;
+
+ /* this function only gets called if options.LinkPadding is 1 */
+ assert(options.LinkPadding == 1);
assert(conn);
@@ -385,7 +389,17 @@
}
#endif
-#if 1 /* experimental code, that sends padding cells too. 'probably' works :) */
+ connection_increment_send_timeval(conn); /* update when we'll send the next cell */
+
+ bytes_in_full_flushlen = conn->bandwidth / 100; /* 10ms worth */
+ if(bytes_in_full_flushlen < 10*sizeof(cell_t))
+ bytes_in_full_flushlen = 10*sizeof(cell_t); /* but at least 10 cells worth */
+
+ if(conn->outbuf_flushlen > bytes_in_full_flushlen - sizeof(cell_t)) {
+ /* if we would exceed bytes_in_full_flushlen by adding a new cell */
+ return;
+ }
+
if(conn->outbuf_datalen - conn->outbuf_flushlen < sizeof(cell_t)) {
/* we need to queue a padding cell first */
memset(&cell,0,sizeof(cell_t));
@@ -395,9 +409,7 @@
conn->outbuf_flushlen += sizeof(cell_t); /* instruct it to send a cell */
connection_watch_events(conn, POLLOUT | POLLIN);
-#endif
- connection_increment_send_timeval(conn); /* update when we'll send the next cell */
}
void connection_increment_send_timeval(connection_t *conn) {
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- main.c 16 Jul 2002 02:12:58 -0000 1.11
+++ main.c 16 Jul 2002 18:24:12 -0000 1.12
@@ -344,10 +344,10 @@
if(!connection_state_is_open(tmpconn))
continue; /* only conns in state 'open' have a valid send_timeval */
while(tv_cmp(&tmpconn->send_timeval,&now) <= 0) { /* send_timeval has already passed, let it send a cell */
- log(LOG_DEBUG,"prepare_for_poll(): doing backlogged connection_send_cell on socket %d (%d ms old)",tmpconn->s,
- (now.tv_sec - tmpconn->send_timeval.tv_sec)*1000 +
- (now.tv_usec - tmpconn->send_timeval.tv_usec)/1000
- );
+// log(LOG_DEBUG,"prepare_for_poll(): doing backlogged connection_send_cell on socket %d (%d ms old)",tmpconn->s,
+// (now.tv_sec - tmpconn->send_timeval.tv_sec)*1000 +
+// (now.tv_usec - tmpconn->send_timeval.tv_usec)/1000
+// );
connection_send_cell(tmpconn);
}
if(!conn || tv_cmp(&tmpconn->send_timeval, &soonest) < 0) { /* this is the best choice so far */
@@ -424,11 +424,13 @@
/* poll until we have an event, or it's time to do something */
poll_result = poll(poll_array, nfds, timeout);
+#if 0 /* let catch() handle things like ^c, and otherwise don't worry about it */
if(poll_result < 0) {
log(LOG_ERR,"do_main_loop(): poll failed.");
if(errno != EINTR) /* let the program survive things like ^z */
return -1;
}
+#endif
if(poll_result > 0) { /* we have at least one connection to deal with */
/* do all the reads first, so we can detect closed sockets */