[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r9048: Round stored/transmitted values for bandwidth usage. This mi (in tor/trunk: . src/or)
- To: or-cvs@xxxxxxxxxxxxx
- Subject: [or-cvs] r9048: Round stored/transmitted values for bandwidth usage. This mi (in tor/trunk: . src/or)
- From: nickm@xxxxxxxx
- Date: Thu, 7 Dec 2006 15:11:39 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Thu, 07 Dec 2006 15:11:46 -0500
- Reply-to: or-talk@xxxxxxxxxxxxx
- Sender: owner-or-cvs@xxxxxxxxxxxxx
Author: nickm
Date: 2006-12-07 15:11:36 -0500 (Thu, 07 Dec 2006)
New Revision: 9048
Modified:
tor/trunk/
tor/trunk/ChangeLog
tor/trunk/src/or/hibernate.c
tor/trunk/src/or/rephist.c
Log:
r11469@Kushana: nickm | 2006-12-07 15:11:04 -0500
Round stored/transmitted values for bandwidth usage. This might make some attacks work less well. This might well be voodoo, but it gives me a warm fuzzy feeling.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r11469] on c95137ef-5f19-0410-b913-86e773d04f59
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2006-12-07 20:11:30 UTC (rev 9047)
+++ tor/trunk/ChangeLog 2006-12-07 20:11:36 UTC (rev 9048)
@@ -23,6 +23,8 @@
- Clients do not store bandwidth history in their state files. (This
shouldn't be an exploitable security issue, but it's better to be
safe.)
+ - When generating bandwidth history, round down to the nearest 1k. When
+ storing accounting data, round up to the nearest 1k.
o Controller bugfixes:
- Report the circuit number correctly in STREAM CLOSED events. (Bug
Modified: tor/trunk/src/or/hibernate.c
===================================================================
--- tor/trunk/src/or/hibernate.c 2006-12-07 20:11:30 UTC (rev 9047)
+++ tor/trunk/src/or/hibernate.c 2006-12-07 20:11:36 UTC (rev 9048)
@@ -530,6 +530,7 @@
}
}
+#define ROUND_UP(x) (((x) + 0x3ff) & ~0x3ff)
#define BW_ACCOUNTING_VERSION 1
/** Save all our bandwidth tracking information to disk. Return 0 on
* success, -1 on failure. */
@@ -561,8 +562,8 @@
BW_ACCOUNTING_VERSION,
time1,
time2,
- U64_PRINTF_ARG(n_bytes_read_in_interval),
- U64_PRINTF_ARG(n_bytes_written_in_interval),
+ U64_PRINTF_ARG(ROUND_UP(n_bytes_read_in_interval)),
+ U64_PRINTF_ARG(ROUND_UP(n_bytes_written_in_interval)),
(unsigned long)n_seconds_active_in_interval,
(unsigned long)expected_bandwidth_usage);
tor_snprintf(fname, sizeof(fname), "%s/bw_accounting",
@@ -571,14 +572,16 @@
/* Now update the state */
state->AccountingIntervalStart = interval_start_time;
- state->AccountingBytesReadInInterval = n_bytes_read_in_interval;
- state->AccountingBytesWrittenInInterval = n_bytes_written_in_interval;
+ state->AccountingBytesReadInInterval = ROUND_UP(n_bytes_read_in_interval);
+ state->AccountingBytesWrittenInInterval =
+ ROUND_UP(n_bytes_written_in_interval);
state->AccountingSecondsActive = n_seconds_active_in_interval;
state->AccountingExpectedUsage = expected_bandwidth_usage;
or_state_mark_dirty(state, 60);
return r;
}
+#undef ROUND_UP
/** Read stored accounting information from disk. Return 0 on success;
* return -1 and change nothing on failure. */
Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c 2006-12-07 20:11:30 UTC (rev 9047)
+++ tor/trunk/src/or/rephist.c 2006-12-07 20:11:36 UTC (rev 9048)
@@ -596,13 +596,14 @@
}
for (n=0; n<b->num_maxes_set; ++n,++i) {
+ uint64_t total;
while (i >= NUM_TOTALS) i -= NUM_TOTALS;
+ /* Round the bandwidth used down to the nearest 1k. */
+ total = b->totals[i] & ~0x3ff;
if (n==(b->num_maxes_set-1))
- tor_snprintf(cp, len-(cp-buf), U64_FORMAT,
- U64_PRINTF_ARG(b->totals[i]));
+ tor_snprintf(cp, len-(cp-buf), U64_FORMAT, U64_PRINTF_ARG(total));
else
- tor_snprintf(cp, len-(cp-buf), U64_FORMAT",",
- U64_PRINTF_ARG(b->totals[i]));
+ tor_snprintf(cp, len-(cp-buf), U64_FORMAT",", U64_PRINTF_ARG(total));
cp += strlen(cp);
}
return cp-buf;