hs_metrics.h (5130B)
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 12 #include "lib/container/smartlist.h" 13 #include "lib/crypt_ops/crypto_ed25519.h" 14 15 #define HS_METRICS_ENTRY_PRIVATE 16 #include "feature/hs/hs_metrics_entry.h" 17 #include "feature/hs/hs_service.h" 18 19 /* Init and Free. */ 20 void hs_metrics_service_init(hs_service_t *service); 21 void hs_metrics_service_free(hs_service_t *service); 22 23 /* Accessors. */ 24 const smartlist_t *hs_metrics_get_stores(void); 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, bool reset); 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, bool reset); 35 36 /** New introducion request received. */ 37 #define hs_metrics_new_introduction(s) \ 38 hs_metrics_update_by_service(HS_METRICS_NUM_INTRODUCTIONS, (s), \ 39 0, NULL, 1, 0, false) 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, false) 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, false) 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), \ 54 (port), NULL, (n), 0, false) 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), \ 60 0, NULL, 1, 0, false) 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), \ 65 0, (reason), 1, 0, false) 66 67 /** Established rendezvous closed. This is called when the circuit in 68 * REND_JOINED state is marked for close. */ 69 #define hs_metrics_close_established_rdv(i) \ 70 hs_metrics_update_by_ident(HS_METRICS_NUM_ESTABLISHED_RDV, (i), \ 71 0, NULL, -1, 0, false) 72 73 /** New rendezvous circuit being launched. */ 74 #define hs_metrics_new_rdv(i) \ 75 hs_metrics_update_by_ident(HS_METRICS_NUM_RDV, (i), 0, NULL, 1, 0, false) 76 77 /** Update depth of rendezvous pqueue any time new work is enqueued. */ 78 #define hs_metrics_pow_pqueue_rdv(s, n) \ 79 hs_metrics_update_by_service(HS_METRICS_POW_NUM_PQUEUE_RDV, (s), 0, \ 80 NULL, (n), 0, true) 81 82 /** Update the suggested effort we include in proof-of-work state */ 83 #define hs_metrics_pow_suggested_effort(s, n) \ 84 hs_metrics_update_by_service(HS_METRICS_POW_SUGGESTED_EFFORT, (s), 0, \ 85 NULL, (n), 0, true) 86 87 /** New introduction circuit has been established. This is called when the 88 * INTRO_ESTABLISHED has been received by the service. */ 89 #define hs_metrics_new_established_intro(s) \ 90 hs_metrics_update_by_service(HS_METRICS_NUM_ESTABLISHED_INTRO, (s), 0, \ 91 NULL, 1, 0, false) 92 93 /** Established introduction circuit closes. This is called when 94 * INTRO_ESTABLISHED circuit is marked for close. */ 95 #define hs_metrics_close_established_intro(i) \ 96 hs_metrics_update_by_ident(HS_METRICS_NUM_ESTABLISHED_INTRO, (i), 0, NULL, \ 97 -1, 0, false) 98 99 /** Record an introduction circuit build time duration. This is called 100 * when the INTRO_ESTABLISHED has been received by the service. */ 101 #define hs_metrics_intro_circ_build_time(s, obs) \ 102 hs_metrics_update_by_service(HS_METRICS_INTRO_CIRC_BUILD_TIME, (s), 0, \ 103 NULL, 1, obs, false) 104 105 /** Record a rendezvous circuit build time duration. This is called as soon as 106 * the circuit purpose is REND_JOINED which is when the RENDEZVOUS2 cell is 107 * sent. */ 108 #define hs_metrics_rdv_circ_build_time(s, obs) \ 109 hs_metrics_update_by_service(HS_METRICS_REND_CIRC_BUILD_TIME, (s), 0, NULL, \ 110 1, obs, false) 111 112 #endif /* !defined(TOR_FEATURE_HS_HS_METRICS_H) */