Compare commits

..

2 Commits

Author SHA1 Message Date
trinity-1686a
f72d508ecc typo 2024-03-23 14:14:04 +01:00
trinity-1686a
3549e8af1f count transmitted bytes as we go instead of at connection teardown 2024-03-23 14:12:23 +01:00
6 changed files with 18 additions and 54 deletions

View File

@ -3640,9 +3640,13 @@ record_num_bytes_transferred_impl(connection_t *conn,
{ {
/* Count bytes of answering direct and tunneled directory requests */ /* Count bytes of answering direct and tunneled directory requests */
if (conn->type == CONN_TYPE_DIR && conn->purpose == DIR_PURPOSE_SERVER) { 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_connection_t *dir_conn = TO_DIR_CONN(conn);
dir_conn->num_read += num_read; stats_increment_dir_bytes_read_and_written(num_read,
dir_conn->num_written += num_written; num_written, dir_conn->hs_request);
} }
/* Linked connections and internal IPs aren't counted for statistics or /* Linked connections and internal IPs aren't counted for statistics or

View File

@ -139,14 +139,11 @@ static uint64_t stats_n_bytes_read = 0;
/** How many bytes have we written since we started the process? */ /** How many bytes have we written since we started the process? */
static uint64_t stats_n_bytes_written = 0; static uint64_t stats_n_bytes_written = 0;
/** How many bytes have we read for directory purpose since we started the /** 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; static uint64_t stats_n_dir_bytes_read = 0;
/** How many bytes have we written for directory purpose since we started the /** 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; 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 /** How many bytes have we written for hs directory purpose since we started
* the process? */ * the process? */
static uint64_t stats_n_hsdir_bytes_written = 0; static uint64_t stats_n_hsdir_bytes_written = 0;
@ -491,15 +488,12 @@ 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 * Return the amount of directory traffic read, in bytes, over the life of this
* process. * process.
*/ */
MOCK_IMPL(uint64_t, uint64_t
get_dir_bytes_read,(bool hs)) get_dir_bytes_read(void)
{ {
if (hs)
return stats_n_hsdir_bytes_read;
else
return stats_n_dir_bytes_read; 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 * Return the amount of directory traffic read, in bytes, over the life of this
* process. * process.
*/ */
MOCK_IMPL(uint64_t, uint64_t
get_dir_bytes_written,(bool hs)) get_dir_bytes_written(bool hs)
{ {
if (hs) if (hs)
return stats_n_hsdir_bytes_written; return stats_n_hsdir_bytes_written;
@ -523,11 +517,10 @@ get_dir_bytes_written,(bool hs))
void void
stats_increment_dir_bytes_read_and_written(uint64_t r, uint64_t w, bool hs) stats_increment_dir_bytes_read_and_written(uint64_t r, uint64_t w, bool hs)
{ {
stats_n_dir_bytes_read += r;
if (hs) { if (hs) {
stats_n_hsdir_bytes_read += r;
stats_n_hsdir_bytes_written += w; stats_n_hsdir_bytes_written += w;
} else { } else {
stats_n_dir_bytes_read += r;
stats_n_dir_bytes_written += w; stats_n_dir_bytes_written += w;
} }
} }

View File

@ -28,8 +28,8 @@ int connection_is_on_closeable_list(connection_t *conn);
MOCK_DECL(smartlist_t *, get_connection_array, (void)); MOCK_DECL(smartlist_t *, get_connection_array, (void));
MOCK_DECL(uint64_t,get_bytes_read,(void)); MOCK_DECL(uint64_t,get_bytes_read,(void));
MOCK_DECL(uint64_t,get_bytes_written,(void)); MOCK_DECL(uint64_t,get_bytes_written,(void));
MOCK_DECL(uint64_t,get_dir_bytes_read,(bool hs)); uint64_t get_dir_bytes_read(void);
MOCK_DECL(uint64_t,get_dir_bytes_written,(bool hs)); uint64_t get_dir_bytes_written(bool hs);
void stats_increment_bytes_read_and_written(uint64_t r, uint64_t w); void stats_increment_bytes_read_and_written(uint64_t r, uint64_t w);
void stats_increment_dir_bytes_read_and_written(uint64_t r, void stats_increment_dir_bytes_read_and_written(uint64_t r,
uint64_t w, bool hs); uint64_t w, bool hs);

View File

@ -62,17 +62,6 @@ struct dir_connection_t {
* needs this for the incoming side, so it's moved here. */ * needs this for the incoming side, so it's moved here. */
uint64_t dirreq_id; 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 #ifdef MEASUREMENTS_21206
/** Number of RELAY_DATA cells received. */ /** Number of RELAY_DATA cells received. */
uint32_t data_cells_received; uint32_t data_cells_received;

View File

@ -11,13 +11,11 @@
#include "core/or/connection_edge.h" #include "core/or/connection_edge.h"
#include "core/or/connection_or.h" #include "core/or/connection_or.h"
#include "core/or/channeltls.h" #include "core/or/channeltls.h"
#include "core/mainloop/mainloop.h"
#include "feature/dircache/dircache.h" #include "feature/dircache/dircache.h"
#include "feature/dircache/dirserv.h" #include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h" #include "feature/dirclient/dirclient.h"
#include "feature/dircommon/directory.h" #include "feature/dircommon/directory.h"
#include "feature/dircommon/fp_pair.h" #include "feature/dircommon/fp_pair.h"
#include "feature/stats/bwhist.h"
#include "feature/stats/geoip_stats.h" #include "feature/stats/geoip_stats.h"
#include "lib/compress/compress.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); 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); connection_dir_client_refetch_hsdesc_if_needed(dir_conn);
} }

View File

@ -419,9 +419,7 @@ fill_traffic_directory_values(void)
the_store, rentry->type, rentry->name, rentry->help, 0, NULL); the_store, rentry->type, rentry->name, rentry->help, 0, NULL);
metrics_store_entry_add_label(sentry, metrics_store_entry_add_label(sentry,
metrics_format_label("direction", "read")); metrics_format_label("direction", "read"));
metrics_store_entry_add_label(sentry, metrics_store_entry_update(sentry, get_dir_bytes_read());
metrics_format_label("kind", "directory"));
metrics_store_entry_update(sentry, get_dir_bytes_read(false));
sentry = metrics_store_add(the_store, rentry->type, rentry->name, sentry = metrics_store_add(the_store, rentry->type, rentry->name,
rentry->help, 0, NULL); rentry->help, 0, NULL);
@ -431,14 +429,6 @@ fill_traffic_directory_values(void)
metrics_format_label("kind", "directory")); metrics_format_label("kind", "directory"));
metrics_store_entry_update(sentry, get_dir_bytes_written(false)); 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, sentry = metrics_store_add(the_store, rentry->type, rentry->name,
rentry->help, 0, NULL); rentry->help, 0, NULL);
metrics_store_entry_add_label(sentry, metrics_store_entry_add_label(sentry,