In routerlist_assert_ok(), check r2 before taking &(r2->cache_info)
[tor.git] / src / or / connection_edge.h
blob3c0e30a9735d2ae62d9c85b5f2b52f8542628df6
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-2013, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file connection_edge.h
9 * \brief Header file for connection_edge.c.
10 **/
12 #ifndef TOR_CONNECTION_EDGE_H
13 #define TOR_CONNECTION_EDGE_H
15 #include "testsupport.h"
17 #define connection_mark_unattached_ap(conn, endreason) \
18 connection_mark_unattached_ap_((conn), (endreason), __LINE__, SHORT_FILE__)
20 MOCK_DECL(void,connection_mark_unattached_ap_,
21 (entry_connection_t *conn, int endreason,
22 int line, const char *file));
23 int connection_edge_reached_eof(edge_connection_t *conn);
24 int connection_edge_process_inbuf(edge_connection_t *conn,
25 int package_partial);
26 int connection_edge_destroy(circid_t circ_id, edge_connection_t *conn);
27 int connection_edge_end(edge_connection_t *conn, uint8_t reason);
28 int connection_edge_end_errno(edge_connection_t *conn);
29 int connection_edge_flushed_some(edge_connection_t *conn);
30 int connection_edge_finished_flushing(edge_connection_t *conn);
31 int connection_edge_finished_connecting(edge_connection_t *conn);
33 void connection_ap_about_to_close(entry_connection_t *edge_conn);
34 void connection_exit_about_to_close(edge_connection_t *edge_conn);
36 int connection_ap_handshake_send_begin(entry_connection_t *ap_conn);
37 int connection_ap_handshake_send_resolve(entry_connection_t *ap_conn);
39 entry_connection_t *connection_ap_make_link(connection_t *partner,
40 char *address, uint16_t port,
41 const char *digest,
42 int session_group,
43 int isolation_flags,
44 int use_begindir, int want_onehop);
45 void connection_ap_handshake_socks_reply(entry_connection_t *conn, char *reply,
46 size_t replylen,
47 int endreason);
48 MOCK_DECL(void,connection_ap_handshake_socks_resolved,
49 (entry_connection_t *conn,
50 int answer_type,
51 size_t answer_len,
52 const uint8_t *answer,
53 int ttl,
54 time_t expires));
55 void connection_ap_handshake_socks_resolved_addr(entry_connection_t *conn,
56 const tor_addr_t *answer,
57 int ttl,
58 time_t expires);
60 int connection_exit_begin_conn(cell_t *cell, circuit_t *circ);
61 int connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ);
62 void connection_exit_connect(edge_connection_t *conn);
63 int connection_edge_is_rendezvous_stream(edge_connection_t *conn);
64 int connection_ap_can_use_exit(const entry_connection_t *conn,
65 const node_t *exit);
66 void connection_ap_expire_beginning(void);
67 void connection_ap_attach_pending(void);
68 void connection_ap_fail_onehop(const char *failed_digest,
69 cpath_build_state_t *build_state);
70 void circuit_discard_optional_exit_enclaves(extend_info_t *info);
71 int connection_ap_detach_retriable(entry_connection_t *conn,
72 origin_circuit_t *circ,
73 int reason);
74 int connection_ap_process_transparent(entry_connection_t *conn);
76 int address_is_invalid_destination(const char *address, int client);
78 int connection_ap_rewrite_and_attach_if_allowed(entry_connection_t *conn,
79 origin_circuit_t *circ,
80 crypt_path_t *cpath);
81 int connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
82 origin_circuit_t *circ,
83 crypt_path_t *cpath);
85 /** Possible return values for parse_extended_hostname. */
86 typedef enum hostname_type_t {
87 NORMAL_HOSTNAME, ONION_HOSTNAME, EXIT_HOSTNAME, BAD_HOSTNAME
88 } hostname_type_t;
89 hostname_type_t parse_extended_hostname(char *address);
91 #if defined(HAVE_NET_IF_H) && defined(HAVE_NET_PFVAR_H)
92 int get_pf_socket(void);
93 #endif
95 int connection_edge_compatible_with_circuit(const entry_connection_t *conn,
96 const origin_circuit_t *circ);
97 int connection_edge_update_circuit_isolation(const entry_connection_t *conn,
98 origin_circuit_t *circ,
99 int dry_run);
100 void circuit_clear_isolation(origin_circuit_t *circ);
101 streamid_t get_unique_stream_id_by_circ(origin_circuit_t *circ);
103 /** @name Begin-cell flags
105 * These flags are used in RELAY_BEGIN cells to change the default behavior
106 * of the cell.
108 * @{
110 /** When this flag is set, the client is willing to get connected to IPv6
111 * addresses */
112 #define BEGIN_FLAG_IPV6_OK (1u<<0)
113 /** When this flag is set, the client DOES NOT support connecting to IPv4
114 * addresses. (The sense of this flag is inverted from IPV6_OK, so that the
115 * old default behavior of Tor is equivalent to having all flags set to 0.)
117 #define BEGIN_FLAG_IPV4_NOT_OK (1u<<1)
118 /** When this flag is set, if we find both an IPv4 and an IPv6 address,
119 * we use the IPv6 address. Otherwise we use the IPv4 address. */
120 #define BEGIN_FLAG_IPV6_PREFERRED (1u<<2)
121 /**@}*/
123 #ifdef CONNECTION_EDGE_PRIVATE
125 /** A parsed BEGIN or BEGIN_DIR cell */
126 typedef struct begin_cell_t {
127 /** The address the client has asked us to connect to, or NULL if this is
128 * a BEGIN_DIR cell*/
129 char *address;
130 /** The flags specified in the BEGIN cell's body. One or more of
131 * BEGIN_FLAG_*. */
132 uint32_t flags;
133 /** The client's requested port. */
134 uint16_t port;
135 /** The client's requested Stream ID */
136 uint16_t stream_id;
137 /** True iff this is a BEGIN_DIR cell. */
138 unsigned is_begindir : 1;
139 } begin_cell_t;
141 STATIC int begin_cell_parse(const cell_t *cell, begin_cell_t *bcell,
142 uint8_t *end_reason_out);
143 STATIC int connected_cell_format_payload(uint8_t *payload_out,
144 const tor_addr_t *addr,
145 uint32_t ttl);
146 #endif
148 #endif