/* Copyright 2001 Matej Pfajfar. * Copyright 2001-2004 Roger Dingledine. * Copyright 2004-2005 Roger Dingledine, Nick Mathewson. */ /* See LICENSE for licensing information */ /* $Id$ */ /** * \file or.h * \brief Master header file for Tor-specific functionality. **/ #ifndef __OR_H #define __OR_H #define OR_H_ID "$Id$" #include "orconfig.h" #ifdef MS_WINDOWS #define WIN32_WINNT 0x400 #define _WIN32_WINNT 0x400 #define WIN32_LEAN_AND_MEAN #endif #include #include #include #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_SIGNAL_H #include #endif #ifdef HAVE_NETDB_H #include #endif #ifdef HAVE_CTYPE_H #include #endif #include "../common/torint.h" #ifdef HAVE_INTTYPES_H #include #endif #ifdef HAVE_SYS_PARAM_H #include /* FreeBSD needs this to know what version it is */ #endif #ifdef HAVE_SYS_LIMITS_H #include #endif #ifdef HAVE_MACHINE_LIMITS_H #ifndef __FreeBSD__ /* FreeBSD has a bug where it complains that this file is obsolete, and I should migrate to using sys/limits. It complains even when I include both. */ #include #endif #endif #ifdef HAVE_SYS_TYPES_H #include /* Must be included before sys/stat.h for Ultrix */ #endif #ifdef HAVE_SYS_WAIT_H #include #endif #ifdef HAVE_SYS_FCNTL_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_SYS_IOCTL_H #include #endif #ifdef HAVE_SYS_SOCKET_H #include #endif #ifdef HAVE_SYS_TIME_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_NETINET_IN_H #include #endif #ifdef HAVE_ARPA_INET_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_ASSERT_H #include #endif #ifdef HAVE_TIME_H #include #endif /** Upper bound on maximum simultaneous connections; can be lowered by * config file. */ #define MAXCONNECTIONS 15000 #ifdef MS_WINDOWS /* No, we don't need to redefine FD_SETSIZE before including winsock: * we use libevent now, and libevent handles the select() stuff. Yes, * some documents imply that we need to redefine anyway if we're using * select() anywhere in our application or in anything it links to: these * documents are either the holy texts of a cargo cult of network * programmers, or more likely a simplification of what's going on for * people who haven't read winsock[2].c for themselves. */ #if (_MSC_VER <= 1300) #include #else #include #include #endif #endif #ifdef MS_WINDOWS #include #include #include #include #define snprintf _snprintf #endif #ifdef HAVE_EVENT_H #include #else #error "Tor requires libevent to build." #endif #include "../common/crypto.h" #include "../common/tortls.h" #include "../common/log.h" #include "../common/compat.h" #include "../common/container.h" #include "../common/util.h" #include "../common/torgzip.h" /* These signals are defined to help control_signal_act work. * XXXX Move into compat.h ? */ #ifndef SIGHUP #define SIGHUP 1 #endif #ifndef SIGINT #define SIGINT 2 #endif #ifndef SIGUSR1 #define SIGUSR1 10 #endif #ifndef SIGUSR2 #define SIGUSR2 12 #endif #ifndef SIGTERM #define SIGTERM 15 #endif #if (SIZEOF_CELL_T != 0) /* On Irix, stdlib.h defines a cell_t type, so we need to make sure * that our stuff always calls cell_t something different. */ #define cell_t tor_cell_t #endif #define DEFAULT_BANDWIDTH_OP (1024 * 1000) #define MAX_NICKNAME_LEN 19 /* Hex digest plus dollar sign. */ #define MAX_HEX_NICKNAME_LEN (HEX_DIGEST_LEN+1) /** Maximum size, in bytes, for resized buffers. */ #define MAX_BUF_SIZE ((1<<24)-1) #define MAX_DIR_SIZE MAX_BUF_SIZE /* For http parsing */ #define MAX_HEADERS_SIZE 50000 #define MAX_BODY_SIZE 500000 #ifdef TOR_PERF /** How long do we keep DNS cache entries before purging them? */ #define MAX_DNS_ENTRY_AGE (150*60) #else #define MAX_DNS_ENTRY_AGE (30*60) #endif /** How often do we rotate onion keys? */ #define MIN_ONION_KEY_LIFETIME (7*24*60*60) /* once a week */ /** How often do we rotate TLS contexts? */ #define MAX_SSL_KEY_LIFETIME (120*60) /** How old do we allow a router to get before removing it, either * from the descriptor list (for dirservers) or the router list (for others)? * In seconds. */ #define ROUTER_MAX_AGE (60*60*24) typedef enum { CIRC_ID_TYPE_LOWER=0, CIRC_ID_TYPE_HIGHER=1 } circ_id_type_t; #define _CONN_TYPE_MIN 3 /** Type for sockets listening for OR connections. */ #define CONN_TYPE_OR_LISTENER 3 /** A bidirectional TLS connection transmitting a sequence of cells. * May be from an OR to an OR, or from an OP to an OR. */ #define CONN_TYPE_OR 4 /** A TCP connection from an onion router to a stream's destination. */ #define CONN_TYPE_EXIT 5 /** Type for sockets listening for SOCKS connections. */ #define CONN_TYPE_AP_LISTENER 6 /** A SOCKS proxy connection from the user application to the onion * proxy. */ #define CONN_TYPE_AP 7 /** Type for sockets listening for HTTP connections to the directory server. */ #define CONN_TYPE_DIR_LISTENER 8 /** Type for HTTP connections to the directory server. */ #define CONN_TYPE_DIR 9 /** Connection from the main process to a DNS worker process. */ #define CONN_TYPE_DNSWORKER 10 /** Connection from the main process to a CPU worker process. */ #define CONN_TYPE_CPUWORKER 11 /** Type for listenting for connections from user interface process */ #define CONN_TYPE_CONTROL_LISTENER 12 /** Type for connections from user interface process */ #define CONN_TYPE_CONTROL 13 #define _CONN_TYPE_MAX 13 #define CONN_IS_EDGE(x) ((x)->type == CONN_TYPE_EXIT || (x)->type == CONN_TYPE_AP) /** State for any listener connection. */ #define LISTENER_STATE_READY 0 #define _DNSWORKER_STATE_MIN 1 /** State for a connection to a dnsworker process that's idle. */ #define DNSWORKER_STATE_IDLE 1 /** State for a connection to a dnsworker process that's resolving a hostname. */ #define DNSWORKER_STATE_BUSY 2 #define _DNSWORKER_STATE_MAX 2 #define _CPUWORKER_STATE_MIN 1 /** State for a connection to a cpuworker process that's idle. */ #define CPUWORKER_STATE_IDLE 1 /** State for a connection to a cpuworker process that's processing a * handshake. */ #define CPUWORKER_STATE_BUSY_ONION 2 #define _CPUWORKER_STATE_MAX 2 #define CPUWORKER_TASK_ONION CPUWORKER_STATE_BUSY_ONION #define _OR_CONN_STATE_MIN 1 /** State for a connection to an OR: waiting for connect() to finish. */ #define OR_CONN_STATE_CONNECTING 1 /** State for a connection to an OR: waiting for proxy command to flush. */ #define OR_CONN_STATE_PROXY_FLUSHING 2 /** State for a connection to an OR: waiting for proxy response. */ #define OR_CONN_STATE_PROXY_READING 3 /** State for a connection to an OR: SSL is handshaking, not done yet. */ #define OR_CONN_STATE_HANDSHAKING 4 /** State for a connection to an OR: Ready to send/receive cells. */ #define OR_CONN_STATE_OPEN 5 #define _OR_CONN_STATE_MAX 5 #define _EXIT_CONN_STATE_MIN 1 /** State for an exit connection: waiting for response from dns farm. */ #define EXIT_CONN_STATE_RESOLVING 1 /** State for an exit connection: waiting for connect() to finish. */ #define EXIT_CONN_STATE_CONNECTING 2 /** State for an exit connection: open and ready to transmit data. */ #define EXIT_CONN_STATE_OPEN 3 /** State for an exit connection: waiting to be removed. */ #define EXIT_CONN_STATE_RESOLVEFAILED 4 #define _EXIT_CONN_STATE_MAX 4 /* the AP state values must be disjoint from the EXIT state values */ #define _AP_CONN_STATE_MIN 5 /** State for a SOCKS connection: waiting for SOCKS request. */ #define AP_CONN_STATE_SOCKS_WAIT 5 /** State for a SOCKS connection: got a y.onion URL; waiting to receive * rendezvous rescriptor. */ #define AP_CONN_STATE_RENDDESC_WAIT 6 /** The controller will attach this connection to a circuit; it isn't our * job to do so. */ #define AP_CONN_STATE_CONTROLLER_WAIT 7 /** State for a SOCKS connection: waiting for a completed circuit. */ #define AP_CONN_STATE_CIRCUIT_WAIT 8 /** State for a SOCKS connection: sent BEGIN, waiting for CONNECTED. */ #define AP_CONN_STATE_CONNECT_WAIT 9 /** State for a SOCKS connection: send RESOLVE, waiting for RESOLVED. */ #define AP_CONN_STATE_RESOLVE_WAIT 10 /** State for a SOCKS connection: ready to send and receive. */ #define AP_CONN_STATE_OPEN 11 #define _AP_CONN_STATE_MAX 11 #define _DIR_CONN_STATE_MIN 1 /** State for connection to directory server: waiting for connect(). */ #define DIR_CONN_STATE_CONNECTING 1 /** State for connection to directory server: sending HTTP request. */ #define DIR_CONN_STATE_CLIENT_SENDING 2 /** State for connection to directory server: reading HTTP response. */ #define DIR_CONN_STATE_CLIENT_READING 3 /** State for connection at directory server: waiting for HTTP request. */ #define DIR_CONN_STATE_SERVER_COMMAND_WAIT 4 /** State for connection at directory server: sending HTTP response. */ #define DIR_CONN_STATE_SERVER_WRITING 5 #define _DIR_CONN_STATE_MAX 5 #define _CONTROL_CONN_STATE_MIN 1 #define CONTROL_CONN_STATE_OPEN_V0 1 #define CONTROL_CONN_STATE_OPEN_V1 2 #define CONTROL_CONN_STATE_NEEDAUTH_V0 3 #define CONTROL_CONN_STATE_NEEDAUTH_V1 4 #define _CONTROL_CONN_STATE_MAX 4 #define _DIR_PURPOSE_MIN 1 /** Purpose for connection to directory server: download a directory. */ #define DIR_PURPOSE_FETCH_DIR 1 /** Purpose for connection to directory server: download just the list * of running routers. */ #define DIR_PURPOSE_FETCH_RUNNING_LIST 2 /** Purpose for connection to directory server: download a rendezvous * descriptor. */ #define DIR_PURPOSE_FETCH_RENDDESC 3 /** Purpose for connection to directory server: set after a rendezvous * descriptor is downloaded. */ #define DIR_PURPOSE_HAS_FETCHED_RENDDESC 4 /** A connection to a directory server: download one or more network-status * objects */ #define DIR_PURPOSE_FETCH_NETWORKSTATUS 5 /** A connection to a directory server: download one or more server * descriptors. */ #define DIR_PURPOSE_FETCH_SERVERDESC 6 /** Purpose for connection to directory server: upload a server descriptor. */ #define DIR_PURPOSE_UPLOAD_DIR 7 /** Purpose for connection to directory server: upload a rendezvous * descriptor. */ #define DIR_PURPOSE_UPLOAD_RENDDESC 8 /** Purpose for connection at a directory server. */ #define DIR_PURPOSE_SERVER 9 #define _DIR_PURPOSE_MAX 9 #define _EXIT_PURPOSE_MIN 1 #define EXIT_PURPOSE_CONNECT 1 #define EXIT_PURPOSE_RESOLVE 2 #define _EXIT_PURPOSE_MAX 2 /** Circuit state: I'm the OP, still haven't done all my handshakes. */ #define CIRCUIT_STATE_BUILDING 0 /** Circuit state: Waiting to process the onionskin. */ #define CIRCUIT_STATE_ONIONSKIN_PENDING 1 /** Circuit state: I'd like to deliver a create, but my n_conn is still connecting. */ #define CIRCUIT_STATE_OR_WAIT 2 /** Circuit state: onionskin(s) processed, ready to send/receive cells. */ #define CIRCUIT_STATE_OPEN 3 #define _CIRCUIT_PURPOSE_MIN 1 /* these circuits were initiated elsewhere */ #define _CIRCUIT_PURPOSE_OR_MIN 1 /** OR-side circuit purpose: normal circuit, at OR. */ #define CIRCUIT_PURPOSE_OR 1 /** OR-side circuit purpose: At OR, from Bob, waiting for intro from Alices. */ #define CIRCUIT_PURPOSE_INTRO_POINT 2 /** OR-side circuit purpose: At OR, from Alice, waiting for Bob. */ #define CIRCUIT_PURPOSE_REND_POINT_WAITING 3 /** OR-side circuit purpose: At OR, both circuits have this purpose. */ #define CIRCUIT_PURPOSE_REND_ESTABLISHED 4 #define _CIRCUIT_PURPOSE_OR_MAX 4 /* these circuits originate at this node */ /* here's how circ client-side purposes work: * normal circuits are C_GENERAL. * circuits that are c_introducing are either on their way to * becoming open, or they are open and waiting for a * suitable rendcirc before they send the intro. * circuits that are c_introduce_ack_wait have sent the intro, * but haven't gotten a response yet. * circuits that are c_establish_rend are either on their way * to becoming open, or they are open and have sent the * establish_rendezvous cell but haven't received an ack. * circuits that are c_rend_ready are open and have received a * rend ack, but haven't heard from bob yet. if they have a * buildstate->pending_final_cpath then they're expecting a * cell from bob, else they're not. * circuits that are c_rend_ready_intro_acked are open, and * some intro circ has sent its intro and received an ack. * circuits that are c_rend_joined are open, have heard from * bob, and are talking to him. */ /** Client-side circuit purpose: Normal circuit, with cpath. */ #define CIRCUIT_PURPOSE_C_GENERAL 5 /** Client-side circuit purpose: at Alice, connecting to intro point. */ #define CIRCUIT_PURPOSE_C_INTRODUCING 6 /** Client-side circuit purpose: at Alice, sent INTRODUCE1 to intro point, waiting for ACK/NAK. */ #define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT 7 /** Client-side circuit purpose: at Alice, introduced and acked, closing. */ #define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED 8 /** Client-side circuit purpose: at Alice, waiting for ack. */ #define CIRCUIT_PURPOSE_C_ESTABLISH_REND 9 /** Client-side circuit purpose: at Alice, waiting for Bob. */ #define CIRCUIT_PURPOSE_C_REND_READY 10 /** Client-side circuit purpose: at Alice, waiting for Bob, INTRODUCE * has been acknowledged. */ #define CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED 11 /** Client-side circuit purpose: at Alice, rendezvous established. */ #define CIRCUIT_PURPOSE_C_REND_JOINED 12 /** Hidden-service-side circuit purpose: at Bob, waiting for introductions. */ #define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO 13 /** Hidden-service-side circuit purpose: at Bob, successfully established * intro. */ #define CIRCUIT_PURPOSE_S_INTRO 14 /** Hidden-service-side circuit purpose: at Bob, connecting to rend point. */ #define CIRCUIT_PURPOSE_S_CONNECT_REND 15 /** Hidden-service-side circuit purpose: at Bob, rendezvous established. */ #define CIRCUIT_PURPOSE_S_REND_JOINED 16 /** A testing circuit; not meant to be used for actual traffic. */ #define CIRCUIT_PURPOSE_TESTING 17 #define _CIRCUIT_PURPOSE_MAX 17 /** True iff the circuit purpose p is for a circuit at the OP * that this OP has originated. */ #define CIRCUIT_PURPOSE_IS_ORIGIN(p) ((p)>_CIRCUIT_PURPOSE_OR_MAX) #define CIRCUIT_IS_ORIGIN(c) (CIRCUIT_PURPOSE_IS_ORIGIN((c)->purpose)) #define RELAY_COMMAND_BEGIN 1 #define RELAY_COMMAND_DATA 2 #define RELAY_COMMAND_END 3 #define RELAY_COMMAND_CONNECTED 4 #define RELAY_COMMAND_SENDME 5 #define RELAY_COMMAND_EXTEND 6 #define RELAY_COMMAND_EXTENDED 7 #define RELAY_COMMAND_TRUNCATE 8 #define RELAY_COMMAND_TRUNCATED 9 #define RELAY_COMMAND_DROP 10 #define RELAY_COMMAND_RESOLVE 11 #define RELAY_COMMAND_RESOLVED 12 #define RELAY_COMMAND_ESTABLISH_INTRO 32 #define RELAY_COMMAND_ESTABLISH_RENDEZVOUS 33 #define RELAY_COMMAND_INTRODUCE1 34 #define RELAY_COMMAND_INTRODUCE2 35 #define RELAY_COMMAND_RENDEZVOUS1 36 #define RELAY_COMMAND_RENDEZVOUS2 37 #define RELAY_COMMAND_INTRO_ESTABLISHED 38 #define RELAY_COMMAND_RENDEZVOUS_ESTABLISHED 39 #define RELAY_COMMAND_INTRODUCE_ACK 40 #define END_STREAM_REASON_MISC 1 #define END_STREAM_REASON_RESOLVEFAILED 2 #define END_STREAM_REASON_CONNECTREFUSED 3 #define END_STREAM_REASON_EXITPOLICY 4 #define END_STREAM_REASON_DESTROY 5 #define END_STREAM_REASON_DONE 6 #define END_STREAM_REASON_TIMEOUT 7 /* 8 is unallocated. */ #define END_STREAM_REASON_HIBERNATING 9 #define END_STREAM_REASON_INTERNAL 10 #define END_STREAM_REASON_RESOURCELIMIT 11 #define END_STREAM_REASON_CONNRESET 12 #define END_STREAM_REASON_TORPROTOCOL 13 /* These high-numbered end reasons are not part of the official spec, * and are not intended to be put in relay end cells. They are here * to be more informative when sending back socks replies to the * application. */ #define END_STREAM_REASON_ALREADY_SOCKS_REPLIED 256 #define END_STREAM_REASON_CANT_ATTACH 257 #define END_STREAM_REASON_NET_UNREACHABLE 258 #define RESOLVED_TYPE_HOSTNAME 0 #define RESOLVED_TYPE_IPV4 4 #define RESOLVED_TYPE_IPV6 6 #define RESOLVED_TYPE_ERROR_TRANSIENT 0xF0 #define RESOLVED_TYPE_ERROR 0xF1 /** Length of 'y' portion of 'y.onion' URL. */ #define REND_SERVICE_ID_LEN 16 #define CELL_DIRECTION_IN 1 #define CELL_DIRECTION_OUT 2 #ifdef TOR_PERF #define CIRCWINDOW_START 10000 #define CIRCWINDOW_INCREMENT 1000 #define STREAMWINDOW_START 5000 #define STREAMWINDOW_INCREMENT 500 #else #define CIRCWINDOW_START 1000 #define CIRCWINDOW_INCREMENT 100 #define STREAMWINDOW_START 500 #define STREAMWINDOW_INCREMENT 50 #endif /* cell commands */ #define CELL_PADDING 0 #define CELL_CREATE 1 #define CELL_CREATED 2 #define CELL_RELAY 3 #define CELL_DESTROY 4 #define CELL_CREATE_FAST 5 #define CELL_CREATED_FAST 6 /* people behind fascist firewalls use only these ports */ #define REQUIRED_FIREWALL_DIRPORT 80 #define REQUIRED_FIREWALL_ORPORT 443 /* legal characters in a nickname */ #define LEGAL_NICKNAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" /** Name to use in client TLS certificates if no nickname is given.*/ #define DEFAULT_CLIENT_NICKNAME "client" #define SOCKS4_NETWORK_LEN 8 typedef enum { SOCKS5_SUCCEEDED = 0x00, SOCKS5_GENERAL_ERROR = 0x01, SOCKS5_NOT_ALLOWED = 0x02, SOCKS5_NET_UNREACHABLE = 0x03, SOCKS5_HOST_UNREACHABLE = 0x04, SOCKS5_CONNECTION_REFUSED = 0x05, SOCKS5_TTL_EXPIRED = 0x06, SOCKS5_COMMAND_NOT_SUPPORTED = 0x07, SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED = 0x08, } socks5_reply_status_t; /* * Relay payload: * Relay command [1 byte] * Recognized [2 bytes] * Stream ID [2 bytes] * Partial SHA-1 [4 bytes] * Length [2 bytes] * Relay payload [498 bytes] */ #define CELL_PAYLOAD_SIZE 509 #define CELL_NETWORK_SIZE 512 #define RELAY_HEADER_SIZE (1+2+2+4+2) #define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE) /** Parsed onion routing cell. All communication from OP-to-OR, or from * OR-to-OR, is via cells. */ typedef struct { uint16_t circ_id; /**< Circuit which received the cell. */ uint8_t command; /**< Type of the cell: one of PADDING, CREATE, RELAY, * or DESTROY. */ char payload[CELL_PAYLOAD_SIZE]; /**< Cell body. */ } cell_t; /** Beginning of a RELAY cell payload. */ typedef struct { uint8_t command; /**< The end-to-end relay command. */ uint16_t recognized; /**< Used to tell whether cell is for us. */ uint16_t stream_id; /**< Which stream is this cell associated with? */ char integrity[4]; /**< Used to tell whether cell is corrupted. */ uint16_t length; /**< How long is the payload body? */ } relay_header_t; typedef struct buf_t buf_t; typedef struct socks_request_t socks_request_t; #define CONNECTION_MAGIC 0x7C3C304Eu /** Description of a connection to another host or process, and associated * data. * * A connection is named based on what it's connected to -- an "OR * connection" has an onion router on the other end, an "OP connection" * (nearly obsolete) has an onion proxy on the other end, an "exit * connection" has a website or other server on the other end, and an * "AP connection" has an application proxy (and thus a user) on the * other end. * * Every connection has a type and a state. Connections never change * their type, but can go through many state changes in their lifetime. * * Every connection has two associated input and output buffers. * Listeners don't use them. For non-listener connections, incoming * data is appended to conn->inbuf, and outgoing data is taken from * conn->outbuf. Connections differ primarily in the functions called * to fill and drain these buffers. */ struct connection_t { uint32_t magic; /**< For memory debugging: must equal CONNECTION_MAGIC. */ uint8_t type; /**< What kind of connection is this? */ uint8_t state; /**< Current state of this connection. */ uint8_t purpose; /**< Only used for DIR types currently. */ uint8_t wants_to_read; /**< Boolean: should we start reading again once * the bandwidth throttler allows it? */ uint8_t wants_to_write; /**< Boolean: should we start writing again once * the bandwidth throttler allows reads? */ int s; /**< Our socket; -1 if this connection is closed. */ int poll_index; /* XXXX rename. */ struct event *read_event; /**< libevent event structure. */ struct event *write_event; /**< libevent event structure. */ int marked_for_close; /**< Boolean: should we close this conn on the next * iteration of the main loop? */ const char *marked_for_close_file; /**< For debugging: in which file were * we marked for close? */ int hold_open_until_flushed; /**< Despite this connection's being marked * for close, do we flush it before closing it? */ buf_t *inbuf; /**< Buffer holding data read over this connection. */ int inbuf_reached_eof; /**< Boolean: did read() return 0 on this conn? */ time_t timestamp_lastread; /**< When was the last time poll() said we could read? */ buf_t *outbuf; /**< Buffer holding data to write over this connection. */ size_t outbuf_flushlen; /**< How much data should we try to flush from the * outbuf? */ time_t timestamp_lastwritten; /**< When was the last time poll() said we could write? */ time_t timestamp_created; /**< When was this connection_t created? */ time_t timestamp_lastempty; /**< When was the outbuf last completely empty?*/ uint32_t addr; /**< IP of the other side of the connection; used to identify * routers, along with port. */ uint16_t port; /**< If non-zero, port on the other end * of the connection. */ char *address; /**< FQDN (or IP) of the guy on the other end. * strdup into this, because free_connection frees it. */ crypto_pk_env_t *identity_pkey; /**< Public RSA key for the other side's * signing key. */ char identity_digest[DIGEST_LEN]; /**< Hash of identity_pkey */ char *nickname; /**< Nickname of OR on other side (if any). */ /** Nickname of planned exit node -- used with .exit support. */ char *chosen_exit_name; /* Used only by OR connections: */ tor_tls *tls; /**< TLS connection state (OR only.) */ uint16_t next_circ_id; /**< Which circ_id do we try to use next on * this connection? This is always in the * range 0..1<<15-1. (OR only.)*/ /* bandwidth and receiver_bucket only used by ORs in OPEN state: */ int bandwidth; /**< Connection bandwidth. (OPEN ORs only.) */ int receiver_bucket; /**< When this hits 0, stop receiving. Every second we * add 'bandwidth' to this, capping it at 10*bandwidth. * (OPEN ORs only) */ circ_id_type_t circ_id_type; /**< When we send CREATE cells along this * connection, which half of the space should * we use? */ /* Used only by DIR and AP connections: */ char rend_query[REND_SERVICE_ID_LEN+1]; /**< What rendezvous service are we * querying for? (DIR/AP only) */ /* Used only by edge connections: */ uint16_t stream_id; struct connection_t *next_stream; /**< Points to the next stream at this * edge, if any (Edge only). */ struct crypt_path_t *cpath_layer; /**< A pointer to which node in the circ * this conn exits at. (Edge only.) */ int package_window; /**< How many more relay cells can i send into the * circuit? (Edge only.) */ int deliver_window; /**< How many more relay cells can end at me? (Edge * only.) */ int done_sending; /**< For half-open connections; not used currently. */ int done_receiving; /**< For half-open connections; not used currently. */ char has_sent_end; /**< For debugging: set once we've set the stream end, and check in circuit_about_to_close_connection(). */ struct circuit_t *on_circuit; /**< The circuit (if any) that this edge * connection is using. */ /* Used only by AP connections */ socks_request_t *socks_request; /**< SOCKS structure describing request (AP * only.) */ /** Quasi-global identifier for this connection; used for control.c */ /* XXXX NM This can get re-used after 2**32 circuits. */ uint32_t global_identifier; /* Used only by control connections */ uint32_t event_mask; uint32_t incoming_cmd_len; uint32_t incoming_cmd_cur_len; char *incoming_cmd; /* Used only by control v0 connections */ uint16_t incoming_cmd_type; }; typedef struct connection_t connection_t; typedef enum { ADDR_POLICY_ACCEPT=1, ADDR_POLICY_REJECT=2, } addr_policy_action_t; /** A linked list of policy rules */ typedef struct addr_policy_t { addr_policy_action_t policy_type; /**< What to do when the policy matches.*/ char *string; /**< String representation of this rule. */ uint32_t addr; /**< Base address to accept or reject. */ uint32_t msk; /**< Accept/reject all addresses a such that * a & msk == addr & msk . */ uint16_t prt_min; /**< Lowest port number to accept/reject. */ uint16_t prt_max; /**< Highest port number to accept/reject. */ struct addr_policy_t *next; /**< Next rule in list. */ } addr_policy_t; /** A cached_dir_t represents a cacheable directory object, along with its * compressed form. */ typedef struct cached_dir_t { char *dir; /**< Contents of this object */ char *dir_z; /**< Compressed contents of this object. */ size_t dir_len; /**< Length of dir */ size_t dir_z_len; /**< Length of dir_z */ time_t published; /**< When was this object published */ } cached_dir_t; /** Information about another onion router in the network. */ typedef struct { char *signed_descriptor; /**< The original signed descriptor for this router*/ size_t signed_descriptor_len; /**< The length of signed_descriptor */ char signed_descriptor_digest[DIGEST_LEN]; /**< The digest of the signed descriptor. */ char *address; /**< Location of OR: either a hostname or an IP address. */ char *nickname; /**< Human-readable OR name. */ uint32_t addr; /**< IPv4 address of OR, in host order. */ uint16_t or_port; /**< Port for OR-to-OR and OP-to-OR connections. */ uint16_t dir_port; /**< Port for HTTP directory connections. */ time_t published_on; /**< When was the information in this routerinfo_t * published? */ crypto_pk_env_t *onion_pkey; /**< Public RSA key for onions. */ crypto_pk_env_t *identity_pkey; /**< Public RSA key for signing. */ char identity_digest[DIGEST_LEN]; /**< Digest of identity key */ char *platform; /**< What software/operating system is this OR using? */ /* link info */ uint32_t bandwidthrate; /**< How many bytes does this OR add to its token * bucket per second? */ uint32_t bandwidthburst; /**< How large is this OR's token bucket? */ /** How many bytes/s is this router known to handle? */ uint32_t bandwidthcapacity; addr_policy_t *exit_policy; /**< What streams will this OR permit * to exit? */ long uptime; /**< How many seconds the router claims to have been up */ uint8_t is_hibernating; /**< Whether the router claims to be hibernating */ smartlist_t *declared_family; /**< Nicknames of router which this router * claims are its family. */ char *contact_info; /**< Declared contact info for this router. */ /* local info */ int is_running; /**< As far as we know, is this OR currently running? */ time_t status_set_at; /**< When did we last update is_running? */ int is_verified; /**< Has a trusted dirserver validated this OR? * (For Authdir: Have we validated this OR?) */ /* The below items are used only by authdirservers for * reachability testing. */ /** When was the last time we could reach this OR? */ time_t last_reachable; /** When did we start testing reachability for this OR? */ time_t testing_since; /** How many times has a descriptor been posted and we believed * this router to be unreachable? We only actually warn on the third. */ int num_unreachable_notifications; } routerinfo_t; /** Contents of a running-routers list */ typedef struct running_routers_t { time_t published_on; /**< When was the list marked as published? */ /** Which ORs are on the list? Entries may be prefixed with ! and $. */ smartlist_t *running_routers; } running_routers_t; /** Contents of a single per-router entry in a network status object. */ typedef struct routerstatus_t { time_t published_on; /**< When was this router published? */ char nickname[MAX_NICKNAME_LEN+1]; /**