mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-02 16:43:32 +01:00
count transmitted bytes as we go instead of at connection teardown
This commit is contained in:
parent
ec5eb9470f
commit
3549e8af1f
@ -3640,9 +3640,13 @@ record_num_bytes_transferred_impl(connection_t *conn,
|
||||
{
|
||||
/* Count bytes of answering direct and tunneled directory requests */
|
||||
if (conn->type == CONN_TYPE_DIR && conn->purpose == DIR_PURPOSE_SERVER) {
|
||||
if (num_read > 0)
|
||||
bwhist_note_dir_bytes_read(num_read, now);
|
||||
if (num_written > 0)
|
||||
bwhist_note_dir_bytes_written(num_written, now);
|
||||
dir_connection_t *dir_conn = TO_DIR_CONN(conn);
|
||||
dir_conn->num_read += num_read;
|
||||
dir_conn->num_written += num_written;
|
||||
stats_increment_dir_bytes_read_and_written(num_read,
|
||||
num_written, dir_conn->hs_request);
|
||||
}
|
||||
|
||||
/* Linked connections and internal IPs aren't counted for statistics or
|
||||
|
@ -139,14 +139,11 @@ static uint64_t stats_n_bytes_read = 0;
|
||||
/** How many bytes have we written since we started the process? */
|
||||
static uint64_t stats_n_bytes_written = 0;
|
||||
/** How many bytes have we read for directory purpose since we started the
|
||||
* process? */
|
||||
* process? Includes hsdir connections */
|
||||
static uint64_t stats_n_dir_bytes_read = 0;
|
||||
/** How many bytes have we written for directory purpose since we started the
|
||||
* process? */
|
||||
* process? Does not include hsdir connections */
|
||||
static uint64_t stats_n_dir_bytes_written = 0;
|
||||
/** How many bytes have we read for hs directory purpose since we started the
|
||||
* process? */
|
||||
static uint64_t stats_n_hsdir_bytes_read = 0;
|
||||
/** How many bytes have we written for hs directory purpose since we started
|
||||
* the process? */
|
||||
static uint64_t stats_n_hsdir_bytes_written = 0;
|
||||
@ -494,12 +491,9 @@ stats_increment_bytes_read_and_written(uint64_t r, uint64_t w)
|
||||
* Return the amount of directory raffic read, in bytes, over the life of this
|
||||
* process.
|
||||
*/
|
||||
MOCK_IMPL(uint64_t,
|
||||
get_dir_bytes_read,(bool hs))
|
||||
uint64_t
|
||||
get_dir_bytes_read(void)
|
||||
{
|
||||
if (hs)
|
||||
return stats_n_hsdir_bytes_read;
|
||||
else
|
||||
return stats_n_dir_bytes_read;
|
||||
}
|
||||
|
||||
@ -507,8 +501,8 @@ get_dir_bytes_read,(bool hs))
|
||||
* Return the amount of directory traffic read, in bytes, over the life of this
|
||||
* process.
|
||||
*/
|
||||
MOCK_IMPL(uint64_t,
|
||||
get_dir_bytes_written,(bool hs))
|
||||
uint64_t
|
||||
get_dir_bytes_written(bool hs)
|
||||
{
|
||||
if (hs)
|
||||
return stats_n_hsdir_bytes_written;
|
||||
@ -523,11 +517,10 @@ get_dir_bytes_written,(bool hs))
|
||||
void
|
||||
stats_increment_dir_bytes_read_and_written(uint64_t r, uint64_t w, bool hs)
|
||||
{
|
||||
stats_n_dir_bytes_read += r;
|
||||
if (hs) {
|
||||
stats_n_hsdir_bytes_read += r;
|
||||
stats_n_hsdir_bytes_written += w;
|
||||
} else {
|
||||
stats_n_dir_bytes_read += r;
|
||||
stats_n_dir_bytes_written += w;
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ int connection_is_on_closeable_list(connection_t *conn);
|
||||
MOCK_DECL(smartlist_t *, get_connection_array, (void));
|
||||
MOCK_DECL(uint64_t,get_bytes_read,(void));
|
||||
MOCK_DECL(uint64_t,get_bytes_written,(void));
|
||||
MOCK_DECL(uint64_t,get_dir_bytes_read,(bool hs));
|
||||
MOCK_DECL(uint64_t,get_dir_bytes_written,(bool hs));
|
||||
uint64_t get_dir_bytes_read(void);
|
||||
uint64_t get_dir_bytes_written(bool hs);
|
||||
void stats_increment_bytes_read_and_written(uint64_t r, uint64_t w);
|
||||
void stats_increment_dir_bytes_read_and_written(uint64_t r,
|
||||
uint64_t w, bool hs);
|
||||
|
@ -62,17 +62,6 @@ struct dir_connection_t {
|
||||
* needs this for the incoming side, so it's moved here. */
|
||||
uint64_t dirreq_id;
|
||||
|
||||
/** Number of bytes read on this connection. We track this here, and update
|
||||
* global statistics on connection tear down so that we can differentiate
|
||||
* between normal directory and hidden-service related request.
|
||||
**/
|
||||
size_t num_read;
|
||||
/** Number of bytes written on this connection. We track this here, and
|
||||
* update global statistics on connection tear down so that we can
|
||||
* differentiate between normal directory and hidden-service related request.
|
||||
**/
|
||||
size_t num_written;
|
||||
|
||||
#ifdef MEASUREMENTS_21206
|
||||
/** Number of RELAY_DATA cells received. */
|
||||
uint32_t data_cells_received;
|
||||
|
@ -11,13 +11,11 @@
|
||||
#include "core/or/connection_edge.h"
|
||||
#include "core/or/connection_or.h"
|
||||
#include "core/or/channeltls.h"
|
||||
#include "core/mainloop/mainloop.h"
|
||||
#include "feature/dircache/dircache.h"
|
||||
#include "feature/dircache/dirserv.h"
|
||||
#include "feature/dirclient/dirclient.h"
|
||||
#include "feature/dircommon/directory.h"
|
||||
#include "feature/dircommon/fp_pair.h"
|
||||
#include "feature/stats/bwhist.h"
|
||||
#include "feature/stats/geoip_stats.h"
|
||||
#include "lib/compress/compress.h"
|
||||
|
||||
@ -494,16 +492,6 @@ connection_dir_about_to_close(dir_connection_t *dir_conn)
|
||||
connection_dir_client_request_failed(dir_conn);
|
||||
}
|
||||
|
||||
if (!dir_conn->hs_request) {
|
||||
const time_t now = approx_time();
|
||||
if (dir_conn->num_read > 0)
|
||||
bwhist_note_dir_bytes_read(dir_conn->num_read, now);
|
||||
if (dir_conn->num_written > 0)
|
||||
bwhist_note_dir_bytes_written(dir_conn->num_written, now);
|
||||
}
|
||||
stats_increment_dir_bytes_read_and_written(dir_conn->num_read,
|
||||
dir_conn->num_written, dir_conn->hs_request);
|
||||
|
||||
connection_dir_client_refetch_hsdesc_if_needed(dir_conn);
|
||||
}
|
||||
|
||||
|
@ -419,9 +419,7 @@ fill_traffic_directory_values(void)
|
||||
the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
|
||||
metrics_store_entry_add_label(sentry,
|
||||
metrics_format_label("direction", "read"));
|
||||
metrics_store_entry_add_label(sentry,
|
||||
metrics_format_label("kind", "directory"));
|
||||
metrics_store_entry_update(sentry, get_dir_bytes_read(false));
|
||||
metrics_store_entry_update(sentry, get_dir_bytes_read());
|
||||
|
||||
sentry = metrics_store_add(the_store, rentry->type, rentry->name,
|
||||
rentry->help, 0, NULL);
|
||||
@ -431,14 +429,6 @@ fill_traffic_directory_values(void)
|
||||
metrics_format_label("kind", "directory"));
|
||||
metrics_store_entry_update(sentry, get_dir_bytes_written(false));
|
||||
|
||||
sentry = metrics_store_add(
|
||||
the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
|
||||
metrics_store_entry_add_label(sentry,
|
||||
metrics_format_label("direction", "read"));
|
||||
metrics_store_entry_add_label(sentry,
|
||||
metrics_format_label("kind", "hsdir"));
|
||||
metrics_store_entry_update(sentry, get_dir_bytes_read(true));
|
||||
|
||||
sentry = metrics_store_add(the_store, rentry->type, rentry->name,
|
||||
rentry->help, 0, NULL);
|
||||
metrics_store_entry_add_label(sentry,
|
||||
|
Loading…
Reference in New Issue
Block a user