tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

connection_or.h (5859B)


      1 /* Copyright (c) 2001 Matej Pfajfar.
      2 * Copyright (c) 2001-2004, Roger Dingledine.
      3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
      4 * Copyright (c) 2007-2021, The Tor Project, Inc. */
      5 /* See LICENSE for licensing information */
      6 
      7 /**
      8 * \file connection_or.h
      9 * \brief Header file for connection_or.c.
     10 **/
     11 
     12 #ifndef TOR_CONNECTION_OR_H
     13 #define TOR_CONNECTION_OR_H
     14 
     15 struct ed25519_public_key_t;
     16 struct ed25519_keypair_t;
     17 
     18 or_connection_t *TO_OR_CONN(connection_t *);
     19 const or_connection_t *CONST_TO_OR_CONN(const connection_t *);
     20 
     21 #include "core/or/orconn_event.h"
     22 
     23 void connection_or_clear_identity(or_connection_t *conn);
     24 void connection_or_clear_identity_map(void);
     25 void clear_broken_connection_map(int disable);
     26 
     27 int connection_or_reached_eof(or_connection_t *conn);
     28 int connection_or_process_inbuf(or_connection_t *conn);
     29 ssize_t connection_or_num_cells_writeable(or_connection_t *conn);
     30 int connection_or_flushed_some(or_connection_t *conn);
     31 int connection_or_finished_flushing(or_connection_t *conn);
     32 int connection_or_finished_connecting(or_connection_t *conn);
     33 void connection_or_about_to_close(or_connection_t *conn);
     34 int connection_or_digest_is_known_relay(const char *id_digest);
     35 void connection_or_update_token_buckets(smartlist_t *conns,
     36                                        const or_options_t *options);
     37 
     38 void connection_or_connect_failed(or_connection_t *conn,
     39                                  int reason, const char *msg);
     40 void connection_or_notify_error(or_connection_t *conn,
     41                                int reason, const char *msg);
     42 MOCK_DECL(or_connection_t *,
     43          connection_or_connect,
     44          (const tor_addr_t *addr, uint16_t port,
     45           const char *id_digest,
     46           const struct ed25519_public_key_t *ed_id,
     47           channel_tls_t *chan));
     48 
     49 void connection_or_close_normally(or_connection_t *orconn, int flush);
     50 MOCK_DECL(void,connection_or_close_for_error,
     51          (or_connection_t *orconn, int flush));
     52 
     53 void connection_or_report_broken_states(int severity, int domain);
     54 
     55 void connection_or_event_status(or_connection_t *conn,
     56                                or_conn_status_event_t tp, int reason);
     57 
     58 MOCK_DECL(int,connection_tls_start_handshake,(or_connection_t *conn,
     59                                              int receiving));
     60 int connection_tls_continue_handshake(or_connection_t *conn);
     61 void connection_or_set_canonical(or_connection_t *or_conn,
     62                                 int is_canonical);
     63 
     64 int connection_init_or_handshake_state(or_connection_t *conn,
     65                                       int started_here);
     66 void connection_or_init_conn_from_address(or_connection_t *conn,
     67                                    const tor_addr_t *addr,
     68                                    uint16_t port,
     69                                    const char *rsa_id_digest,
     70                                    const struct ed25519_public_key_t *ed_id,
     71                                    int started_here);
     72 int connection_or_client_learned_peer_id(or_connection_t *conn,
     73                              const uint8_t *rsa_peer_id,
     74                              const struct ed25519_public_key_t *ed_peer_id);
     75 const struct ed25519_public_key_t *connection_or_get_alleged_ed25519_id(
     76                              const or_connection_t *conn);
     77 time_t connection_or_client_used(or_connection_t *conn);
     78 MOCK_DECL(int, connection_or_get_num_circuits, (or_connection_t *conn));
     79 void or_handshake_state_free_(or_handshake_state_t *state);
     80 #define or_handshake_state_free(state) \
     81  FREE_AND_NULL(or_handshake_state_t, or_handshake_state_free_, (state))
     82 void or_handshake_state_record_cell(or_connection_t *conn,
     83                                    or_handshake_state_t *state,
     84                                    const cell_t *cell,
     85                                    int incoming);
     86 void or_handshake_state_record_var_cell(or_connection_t *conn,
     87                                        or_handshake_state_t *state,
     88                                        const var_cell_t *cell,
     89                                        int incoming);
     90 
     91 int connection_or_set_state_open(or_connection_t *conn);
     92 void connection_or_write_cell_to_buf(const cell_t *cell,
     93                                     or_connection_t *conn);
     94 MOCK_DECL(void,connection_or_write_var_cell_to_buf,(const var_cell_t *cell,
     95                                                   or_connection_t *conn));
     96 int connection_or_send_versions(or_connection_t *conn, int v3_plus);
     97 MOCK_DECL(int,connection_or_send_netinfo,(or_connection_t *conn));
     98 
     99 int is_or_protocol_version_known(uint16_t version);
    100 
    101 void cell_pack(packed_cell_t *dest, const cell_t *src, int wide_circ_ids);
    102 int var_cell_pack_header(const var_cell_t *cell, char *hdr_out,
    103                         int wide_circ_ids);
    104 var_cell_t *var_cell_new(uint16_t payload_len);
    105 var_cell_t *var_cell_copy(const var_cell_t *src);
    106 void var_cell_free_(var_cell_t *cell);
    107 #define var_cell_free(cell) FREE_AND_NULL(var_cell_t, var_cell_free_, (cell))
    108 
    109 /* DOCDOC */
    110 #define MIN_LINK_PROTO_FOR_WIDE_CIRC_IDS 4
    111 #define MIN_LINK_PROTO_FOR_CHANNEL_PADDING 5
    112 #define MAX_LINK_PROTO MIN_LINK_PROTO_FOR_CHANNEL_PADDING
    113 
    114 int connection_or_single_set_badness_(time_t now,
    115                                      or_connection_t *or_conn,
    116                                      int force);
    117 void connection_or_group_set_badness_(smartlist_t *group, int force);
    118 
    119 #ifdef CONNECTION_OR_PRIVATE
    120 STATIC int should_connect_to_relay(const or_connection_t *or_conn);
    121 STATIC void note_or_connect_failed(const or_connection_t *or_conn);
    122 #endif /* defined(CONNECTION_OR_PRIVATE) */
    123 
    124 /*
    125 * Call this when changing connection state, so notifications to the owning
    126 * channel can be handled.
    127 */
    128 MOCK_DECL(void, connection_or_change_state,
    129          (or_connection_t *conn, uint8_t state));
    130 
    131 #endif /* !defined(TOR_CONNECTION_OR_H) */