1 /* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2015, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
8 * \brief Headers for transports.c
11 #ifndef TOR_TRANSPORTS_H
12 #define TOR_TRANSPORTS_H
14 /** Represents a pluggable transport used by a bridge. */
15 typedef struct transport_t
{
16 /** SOCKS version: One of PROXY_SOCKS4, PROXY_SOCKS5. */
18 /** Name of pluggable transport protocol */
20 /** The IP address where the transport bound and is waiting for
25 /** Boolean: We are re-parsing our transport list, and we are going to remove
26 * this one if we don't find it in the list of configured transports. */
27 unsigned marked_for_removal
: 1;
28 /** Arguments for this transport that must be written to the
29 extra-info descriptor. */
30 char *extra_info_args
;
33 void mark_transport_list(void);
34 void sweep_transport_list(void);
35 MOCK_DECL(int, transport_add_from_config
,
36 (const tor_addr_t
*addr
, uint16_t port
,
37 const char *name
, int socks_ver
));
38 void transport_free(transport_t
*transport
);
40 transport_t
*transport_get_by_name(const char *name
);
42 MOCK_DECL(void, pt_kickstart_proxy
,
43 (const smartlist_t
*transport_list
, char **proxy_argv
,
46 #define pt_kickstart_client_proxy(tl, pa) \
47 pt_kickstart_proxy(tl, pa, 0)
48 #define pt_kickstart_server_proxy(tl, pa) \
49 pt_kickstart_proxy(tl, pa, 1)
51 void pt_configure_remaining_proxies(void);
53 int pt_proxies_configuration_pending(void);
55 char *pt_get_extra_info_descriptor_string(void);
57 void pt_free_all(void);
59 void pt_prepare_proxy_list_for_config_read(void);
60 void sweep_proxy_list(void);
62 smartlist_t
*get_transport_proxy_ports(void);
63 char *pt_stringify_socks_args(const smartlist_t
*socks_args
);
65 char *pt_get_socks_args_for_proxy_addrport(const tor_addr_t
*addr
,
69 /** State of the managed proxy configuration protocol. */
71 PT_PROTO_INFANT
, /* was just born */
72 PT_PROTO_LAUNCHED
, /* was just launched */
73 PT_PROTO_ACCEPTING_METHODS
, /* accepting methods */
74 PT_PROTO_CONFIGURED
, /* configured successfully */
75 PT_PROTO_COMPLETED
, /* configure and registered its transports */
76 PT_PROTO_BROKEN
, /* broke during the protocol */
77 PT_PROTO_FAILED_LAUNCH
/* failed while launching */
80 /** Structure containing information of a managed proxy. */
82 enum pt_proto_state conf_state
; /* the current configuration state */
83 char **argv
; /* the cli arguments of this proxy */
84 int conf_protocol
; /* the configuration protocol version used */
86 char *proxy_uri
; /* the outgoing proxy in TOR_PT_PROXY URI format */
87 unsigned int proxy_supported
: 1; /* the proxy honors TOR_PT_PROXY */
89 int is_server
; /* is it a server proxy? */
91 /* A pointer to the process handle of this managed proxy. */
92 process_handle_t
*process_handle
;
94 int pid
; /* The Process ID this managed proxy is using. */
96 /** Boolean: We are re-parsing our config, and we are going to
97 * remove this managed proxy if we don't find it any transport
98 * plugins that use it. */
99 unsigned int marked_for_removal
: 1;
101 /** Boolean: We got a SIGHUP while this proxy was running. We use
102 * this flag to signify that this proxy might need to be restarted
103 * so that it can listen for other transports according to the new
105 unsigned int was_around_before_config_read
: 1;
107 /* transports to-be-launched by this proxy */
108 smartlist_t
*transports_to_launch
;
110 /* The 'transports' list contains all the transports this proxy has
112 smartlist_t
*transports
;
115 STATIC
int parse_cmethod_line(const char *line
, managed_proxy_t
*mp
);
116 STATIC
int parse_smethod_line(const char *line
, managed_proxy_t
*mp
);
118 STATIC
int parse_version(const char *line
, managed_proxy_t
*mp
);
119 STATIC
void parse_env_error(const char *line
);
120 STATIC
void parse_proxy_error(const char *line
);
121 STATIC
void handle_proxy_line(const char *line
, managed_proxy_t
*mp
);
122 STATIC
char *get_transport_options_for_server_proxy(const managed_proxy_t
*mp
);
124 STATIC
void managed_proxy_destroy(managed_proxy_t
*mp
,
125 int also_terminate_process
);
127 STATIC managed_proxy_t
*managed_proxy_create(const smartlist_t
*transport_list
,
128 char **proxy_argv
, int is_server
);
130 STATIC
int configure_proxy(managed_proxy_t
*mp
);
132 STATIC
char* get_pt_proxy_uri(void);
134 STATIC
void free_execve_args(char **arg
);