tor  0.4.2.0-alpha-dev
transports.h
Go to the documentation of this file.
1 /* Copyright (c) 2003-2004, Roger Dingledine
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
11 #ifndef TOR_TRANSPORTS_H
12 #define TOR_TRANSPORTS_H
13 
14 #include "lib/process/process.h"
15 
17 typedef struct transport_t {
21  char *name;
26  uint16_t port;
29  unsigned marked_for_removal : 1;
33 } transport_t;
34 
35 void mark_transport_list(void);
36 void sweep_transport_list(void);
37 MOCK_DECL(int, transport_add_from_config,
38  (const tor_addr_t *addr, uint16_t port,
39  const char *name, int socks_ver));
40 void transport_free_(transport_t *transport);
41 #define transport_free(tr) FREE_AND_NULL(transport_t, transport_free_, (tr))
42 
43 MOCK_DECL(transport_t*, transport_get_by_name, (const char *name));
44 
45 MOCK_DECL(void, pt_kickstart_proxy,
46  (const smartlist_t *transport_list, char **proxy_argv,
47  int is_server));
48 
49 #define pt_kickstart_client_proxy(tl, pa) \
50  pt_kickstart_proxy(tl, pa, 0)
51 #define pt_kickstart_server_proxy(tl, pa) \
52  pt_kickstart_proxy(tl, pa, 1)
53 
55 
57 
59 
60 void pt_free_all(void);
61 
63 void sweep_proxy_list(void);
64 
66 char *pt_stringify_socks_args(const smartlist_t *socks_args);
67 
69  uint16_t port);
70 
71 char *tor_escape_str_for_pt_args(const char *string,
72  const char *chars_to_escape);
73 
74 #ifdef PT_PRIVATE
75 
76 enum pt_proto_state {
77  PT_PROTO_INFANT, /* was just born */
78  PT_PROTO_LAUNCHED, /* was just launched */
79  PT_PROTO_ACCEPTING_METHODS, /* accepting methods */
80  PT_PROTO_CONFIGURED, /* configured successfully */
81  PT_PROTO_COMPLETED, /* configure and registered its transports */
82  PT_PROTO_BROKEN, /* broke during the protocol */
83  PT_PROTO_FAILED_LAUNCH /* failed while launching */
84 };
85 
86 struct process_t;
87 
89 typedef struct {
90  enum pt_proto_state conf_state; /* the current configuration state */
91  char **argv; /* the cli arguments of this proxy */
92  int conf_protocol; /* the configuration protocol version used */
93 
94  char *proxy_uri; /* the outgoing proxy in TOR_PT_PROXY URI format */
95  unsigned int proxy_supported : 1; /* the proxy honors TOR_PT_PROXY */
96 
97  int is_server; /* is it a server proxy? */
98 
99  /* A pointer to the process of this managed proxy. */
100  struct process_t *process;
101 
105  unsigned int marked_for_removal : 1;
106 
111  unsigned int was_around_before_config_read : 1;
112 
113  /* transports to-be-launched by this proxy */
114  smartlist_t *transports_to_launch;
115 
116  /* The 'transports' list contains all the transports this proxy has
117  launched. */
118  smartlist_t *transports;
119 } managed_proxy_t;
120 
121 STATIC transport_t *transport_new(const tor_addr_t *addr, uint16_t port,
122  const char *name, int socks_ver,
123  const char *extra_info_args);
124 STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp);
125 STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp);
126 
127 STATIC int parse_version(const char *line, managed_proxy_t *mp);
128 STATIC void parse_env_error(const char *line);
129 STATIC void parse_proxy_error(const char *line);
130 STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
131 STATIC void parse_log_line(const char *line, managed_proxy_t *mp);
132 STATIC void parse_status_line(const char *line, managed_proxy_t *mp);
133 STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
134 
135 STATIC void managed_proxy_destroy(managed_proxy_t *mp,
136  int also_terminate_process);
137 
138 STATIC managed_proxy_t *managed_proxy_create(const smartlist_t *transport_list,
139  char **proxy_argv, int is_server);
140 
141 STATIC int configure_proxy(managed_proxy_t *mp);
142 
143 STATIC char* get_pt_proxy_uri(void);
144 
145 STATIC void free_execve_args(char **arg);
146 
147 STATIC void managed_proxy_stdout_callback(process_t *, const char *, size_t);
148 STATIC void managed_proxy_stderr_callback(process_t *, const char *, size_t);
149 STATIC bool managed_proxy_exit_callback(process_t *, process_exit_code_t);
150 
151 STATIC int managed_proxy_severity_parse(const char *);
152 
153 #endif /* defined(PT_PRIVATE) */
154 
155 #endif /* !defined(TOR_TRANSPORTS_H) */
void pt_prepare_proxy_list_for_config_read(void)
Definition: transports.c:1556
uint16_t port
Definition: transports.h:26
void pt_free_all(void)
Definition: transports.c:1754
STATIC void free_execve_args(char **arg)
Definition: transports.c:1541
STATIC void managed_proxy_destroy(managed_proxy_t *mp, int also_terminate_process)
Definition: transports.c:693
STATIC void managed_proxy_stdout_callback(process_t *process, const char *line, size_t size)
Definition: transports.c:1818
char * pt_stringify_socks_args(const smartlist_t *socks_args)
Definition: transports.c:1686
STATIC void parse_log_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1152
struct transport_t transport_t
char * name
Definition: transports.h:21
STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:830
STATIC void parse_proxy_error(const char *line)
Definition: transports.c:1137
STATIC transport_t * transport_new(const tor_addr_t *addr, uint16_t port, const char *name, int socks_ver, const char *extra_info_args)
Definition: transports.c:146
STATIC int parse_version(const char *line, managed_proxy_t *mp)
Definition: transports.c:958
char * extra_info_args
Definition: transports.h:32
unsigned marked_for_removal
Definition: transports.h:29
STATIC void parse_status_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1218
char * pt_get_extra_info_descriptor_string(void)
Definition: transports.c:1619
void pt_configure_remaining_proxies(void)
Definition: transports.c:564
char * tor_escape_str_for_pt_args(const char *string, const char *chars_to_escape)
Definition: transports.c:1780
void mark_transport_list(void)
Definition: transports.c:177
void sweep_transport_list(void)
Definition: transports.c:188
void sweep_proxy_list(void)
Definition: transports.c:1738
STATIC void parse_env_error(const char *line)
Definition: transports.c:942
Header for process.c.
STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1118
STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1128
smartlist_t * get_transport_proxy_ports(void)
Definition: transports.c:1589
int pt_proxies_configuration_pending(void)
Definition: transports.c:371
STATIC int managed_proxy_severity_parse(const char *severity)
Definition: transports.c:1883
STATIC bool managed_proxy_exit_callback(process_t *process, process_exit_code_t exit_code)
Definition: transports.c:1866
static smartlist_t * transport_list
Definition: transports.c:140
STATIC char * get_pt_proxy_uri(void)
Definition: transports.c:731
STATIC void managed_proxy_stderr_callback(process_t *process, const char *line, size_t size)
Definition: transports.c:1844
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
tor_addr_t addr
Definition: transports.h:24
STATIC managed_proxy_t * managed_proxy_create(const smartlist_t *with_transport_list, char **proxy_argv, int is_server)
Definition: transports.c:1459
void transport_free_(transport_t *transport)
Definition: transports.c:164
int socks_version
Definition: transports.h:19
char * pt_get_socks_args_for_proxy_addrport(const tor_addr_t *addr, uint16_t port)
Definition: transports.c:1722
STATIC char * get_transport_options_for_server_proxy(const managed_proxy_t *mp)
Definition: transports.c:1269
STATIC int configure_proxy(managed_proxy_t *mp)
Definition: transports.c:621