aboutsummaryrefslogtreecommitdiff
path: root/src/feature/dirauth/bwauth.h
blob: 4507728458a0da0fa0842c4d4d2f4ac4e399f9fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Copyright (c) 2001 Matej Pfajfar.
 * Copyright (c) 2001-2004, Roger Dingledine.
 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
 * Copyright (c) 2007-2019, The Tor Project, Inc. */
/* See LICENSE for licensing information */

/**
 * \file bwauth.h
 * \brief Header file for bwauth.c
 **/

#ifndef TOR_BWAUTH_H
#define TOR_BWAUTH_H

/** Maximum allowable length of bandwidth headers in a bandwidth file */
#define MAX_BW_FILE_HEADER_COUNT_IN_VOTE 50

/** Terminatore that separates bandwidth file headers from bandwidth file
 * relay lines */
#define BW_FILE_HEADERS_TERMINATOR "=====\n"

int dirserv_read_measured_bandwidths(const char *from_file,
                                     smartlist_t *routerstatuses,
                                     smartlist_t *bw_file_headers);

int dirserv_query_measured_bw_cache_kb(const char *node_id,
                                       long *bw_out,
                                       time_t *as_of_out);
void dirserv_clear_measured_bw_cache(void);
int dirserv_has_measured_bw(const char *node_id);
int dirserv_get_measured_bw_cache_size(void);
void dirserv_count_measured_bws(const smartlist_t *routers);
int dirserv_get_last_n_measured_bws(void);

uint32_t dirserv_get_credible_bandwidth_kb(const routerinfo_t *ri);

#ifdef BWAUTH_PRIVATE
typedef struct measured_bw_line_t {
  char node_id[DIGEST_LEN];
  char node_hex[MAX_HEX_NICKNAME_LEN+1];
  long int bw_kb;
} measured_bw_line_t;

/* Put the MAX_MEASUREMENT_AGE #define here so unit tests can see it */
#define MAX_MEASUREMENT_AGE (3*24*60*60) /* 3 days */

STATIC int measured_bw_line_parse(measured_bw_line_t *out, const char *line,
                                  int line_is_after_headers);

STATIC int measured_bw_line_apply(measured_bw_line_t *parsed_line,
                           smartlist_t *routerstatuses);

STATIC void dirserv_cache_measured_bw(const measured_bw_line_t *parsed_line,
                               time_t as_of);
STATIC void dirserv_expire_measured_bw_cache(time_t now);
#endif /* defined(BWAUTH_PRIVATE) */

#endif