Tor  0.4.8.0-alpha-dev
hs_metrics.h
Go to the documentation of this file.
1 /* Copyright (c) 2020-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * @file hs_metrics.h
6  * @brief Header for feature/hs/hs_metrics.c
7  **/
8 
9 #ifndef TOR_FEATURE_HS_HS_METRICS_H
10 #define TOR_FEATURE_HS_HS_METRICS_H
11 
14 
15 #define HS_METRICS_ENTRY_PRIVATE
17 #include "feature/hs/hs_service.h"
18 
19 /* Init and Free. */
22 
23 /* Accessors. */
25 
26 /* Metrics Update. */
27 void hs_metrics_update_by_ident(const hs_metrics_key_t key,
28  const ed25519_public_key_t *ident_pk,
29  const uint16_t port, const char *reason,
30  int64_t n, int64_t obs);
31 void hs_metrics_update_by_service(const hs_metrics_key_t key,
32  const hs_service_t *service,
33  uint16_t port, const char *reason,
34  int64_t n, int64_t obs);
35 
36 /** New introducion request received. */
37 #define hs_metrics_new_introduction(s) \
38  hs_metrics_update_by_service(HS_METRICS_NUM_INTRODUCTIONS, (s), 0, NULL, 1, \
39  0)
40 
41 /** Introducion request rejected. */
42 #define hs_metrics_reject_intro_req(s, reason) \
43  hs_metrics_update_by_service(HS_METRICS_NUM_REJECTED_INTRO_REQ, (s), 0, \
44  (reason), 1, 0)
45 
46 /** Number of bytes written to the application from the service. */
47 #define hs_metrics_app_write_bytes(i, port, n) \
48  hs_metrics_update_by_ident(HS_METRICS_APP_WRITE_BYTES, (i), (port), NULL, \
49  (n), 0)
50 
51 /** Number of bytes read from the application to the service. */
52 #define hs_metrics_app_read_bytes(i, port, n) \
53  hs_metrics_update_by_ident(HS_METRICS_APP_READ_BYTES, (i), (port), NULL, \
54  (n), 0)
55 
56 /** Newly established rendezvous. This is called as soon as the circuit purpose
57  * is REND_JOINED which is when the RENDEZVOUS2 cell is sent. */
58 #define hs_metrics_new_established_rdv(s) \
59  hs_metrics_update_by_service(HS_METRICS_NUM_ESTABLISHED_RDV, (s), 0, NULL, \
60  1, 0)
61 
62 /** New rendezvous circuit failure. */
63 #define hs_metrics_failed_rdv(i, reason) \
64  hs_metrics_update_by_ident(HS_METRICS_NUM_FAILED_RDV, (i), 0, (reason), 1, 0)
65 
66 /** Established rendezvous closed. This is called when the circuit in
67  * REND_JOINED state is marked for close. */
68 #define hs_metrics_close_established_rdv(i) \
69  hs_metrics_update_by_ident(HS_METRICS_NUM_ESTABLISHED_RDV, (i), 0, NULL, \
70  -1, 0)
71 
72 /** New rendezvous circuit being launched. */
73 #define hs_metrics_new_rdv(i) \
74  hs_metrics_update_by_ident(HS_METRICS_NUM_RDV, (i), 0, NULL, 1, 0)
75 
76 /** New introduction circuit has been established. This is called when the
77  * INTRO_ESTABLISHED has been received by the service. */
78 #define hs_metrics_new_established_intro(s) \
79  hs_metrics_update_by_service(HS_METRICS_NUM_ESTABLISHED_INTRO, (s), 0, \
80  NULL, 1, 0)
81 
82 /** Established introduction circuit closes. This is called when
83  * INTRO_ESTABLISHED circuit is marked for close. */
84 #define hs_metrics_close_established_intro(i) \
85  hs_metrics_update_by_ident(HS_METRICS_NUM_ESTABLISHED_INTRO, (i), 0, NULL, \
86  -1, 0)
87 
88 /** Record an introduction circuit build time duration. This is called
89  * when the INTRO_ESTABLISHED has been received by the service. */
90 #define hs_metrics_intro_circ_build_time(s, obs) \
91  hs_metrics_update_by_service(HS_METRICS_INTRO_CIRC_BUILD_TIME, (s), 0, \
92  NULL, 1, obs)
93 
94 /** Record a rendezvous circuit build time duration. This is called as soon as
95  * the circuit purpose is REND_JOINED which is when the RENDEZVOUS2 cell is
96  * sent. */
97 #define hs_metrics_rdv_circ_build_time(s, obs) \
98  hs_metrics_update_by_service(HS_METRICS_REND_CIRC_BUILD_TIME, (s), 0, NULL, \
99  1, obs)
100 
101 #endif /* !defined(TOR_FEATURE_HS_HS_METRICS_H) */
Header for crypto_ed25519.c.
void hs_metrics_update_by_service(const hs_metrics_key_t key, const hs_service_t *service, uint16_t port, const char *reason, int64_t n, int64_t obs)
Definition: hs_metrics.c:146
void hs_metrics_service_free(hs_service_t *service)
Definition: hs_metrics.c:244
void hs_metrics_service_init(hs_service_t *service)
Definition: hs_metrics.c:226
void hs_metrics_update_by_ident(const hs_metrics_key_t key, const ed25519_public_key_t *ident_pk, const uint16_t port, const char *reason, int64_t n, int64_t obs)
Definition: hs_metrics.c:190
const smartlist_t * hs_metrics_get_stores(void)
Definition: hs_metrics.c:213
Header for feature/hs/hs_metrics_entry.c.
Header file containing service data for the HS subsystem.
Header for smartlist.c.