transports.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. /**
  6. * \file transports.h
  7. * \brief Headers for transports.c
  8. **/
  9. #ifndef TOR_TRANSPORTS_H
  10. #define TOR_TRANSPORTS_H
  11. /** Represents a pluggable transport used by a bridge. */
  12. typedef struct transport_t {
  13. /** SOCKS version: One of PROXY_SOCKS4, PROXY_SOCKS5. */
  14. int socks_version;
  15. /** Name of pluggable transport protocol */
  16. char *name;
  17. /** The IP address where the transport bound and is waiting for
  18. * connections. */
  19. tor_addr_t addr;
  20. /** Port of proxy */
  21. uint16_t port;
  22. /** Boolean: We are re-parsing our transport list, and we are going to remove
  23. * this one if we don't find it in the list of configured transports. */
  24. unsigned marked_for_removal : 1;
  25. /** Arguments for this transport that must be written to the
  26. extra-info descriptor. */
  27. char *extra_info_args;
  28. } transport_t;
  29. void mark_transport_list(void);
  30. void sweep_transport_list(void);
  31. MOCK_DECL(int, transport_add_from_config,
  32. (const tor_addr_t *addr, uint16_t port,
  33. const char *name, int socks_ver));
  34. void transport_free_(transport_t *transport);
  35. #define transport_free(tr) FREE_AND_NULL(transport_t, transport_free_, (tr))
  36. MOCK_DECL(transport_t*, transport_get_by_name, (const char *name));
  37. MOCK_DECL(void, pt_kickstart_proxy,
  38. (const smartlist_t *transport_list, char **proxy_argv,
  39. int is_server));
  40. #define pt_kickstart_client_proxy(tl, pa) \
  41. pt_kickstart_proxy(tl, pa, 0)
  42. #define pt_kickstart_server_proxy(tl, pa) \
  43. pt_kickstart_proxy(tl, pa, 1)
  44. void pt_configure_remaining_proxies(void);
  45. int pt_proxies_configuration_pending(void);
  46. char *pt_get_extra_info_descriptor_string(void);
  47. void pt_free_all(void);
  48. void pt_prepare_proxy_list_for_config_read(void);
  49. void sweep_proxy_list(void);
  50. smartlist_t *get_transport_proxy_ports(void);
  51. char *pt_stringify_socks_args(const smartlist_t *socks_args);
  52. char *pt_get_socks_args_for_proxy_addrport(const tor_addr_t *addr,
  53. uint16_t port);
  54. char *tor_escape_str_for_pt_args(const char *string,
  55. const char *chars_to_escape);
  56. #ifdef PT_PRIVATE
  57. /** State of the managed proxy configuration protocol. */
  58. enum pt_proto_state {
  59. PT_PROTO_INFANT, /* was just born */
  60. PT_PROTO_LAUNCHED, /* was just launched */
  61. PT_PROTO_ACCEPTING_METHODS, /* accepting methods */
  62. PT_PROTO_CONFIGURED, /* configured successfully */
  63. PT_PROTO_COMPLETED, /* configure and registered its transports */
  64. PT_PROTO_BROKEN, /* broke during the protocol */
  65. PT_PROTO_FAILED_LAUNCH /* failed while launching */
  66. };
  67. struct process_handle_t;
  68. /** Structure containing information of a managed proxy. */
  69. typedef struct {
  70. enum pt_proto_state conf_state; /* the current configuration state */
  71. char **argv; /* the cli arguments of this proxy */
  72. int conf_protocol; /* the configuration protocol version used */
  73. char *proxy_uri; /* the outgoing proxy in TOR_PT_PROXY URI format */
  74. unsigned int proxy_supported : 1; /* the proxy honors TOR_PT_PROXY */
  75. int is_server; /* is it a server proxy? */
  76. /* A pointer to the process handle of this managed proxy. */
  77. struct process_handle_t *process_handle;
  78. int pid; /* The Process ID this managed proxy is using. */
  79. /** Boolean: We are re-parsing our config, and we are going to
  80. * remove this managed proxy if we don't find it any transport
  81. * plugins that use it. */
  82. unsigned int marked_for_removal : 1;
  83. /** Boolean: We got a SIGHUP while this proxy was running. We use
  84. * this flag to signify that this proxy might need to be restarted
  85. * so that it can listen for other transports according to the new
  86. * torrc. */
  87. unsigned int was_around_before_config_read : 1;
  88. /* transports to-be-launched by this proxy */
  89. smartlist_t *transports_to_launch;
  90. /* The 'transports' list contains all the transports this proxy has
  91. launched. */
  92. smartlist_t *transports;
  93. } managed_proxy_t;
  94. STATIC transport_t *transport_new(const tor_addr_t *addr, uint16_t port,
  95. const char *name, int socks_ver,
  96. const char *extra_info_args);
  97. STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp);
  98. STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp);
  99. STATIC int parse_version(const char *line, managed_proxy_t *mp);
  100. STATIC void parse_env_error(const char *line);
  101. STATIC void parse_proxy_error(const char *line);
  102. STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
  103. STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
  104. STATIC void managed_proxy_destroy(managed_proxy_t *mp,
  105. int also_terminate_process);
  106. STATIC managed_proxy_t *managed_proxy_create(const smartlist_t *transport_list,
  107. char **proxy_argv, int is_server);
  108. STATIC int configure_proxy(managed_proxy_t *mp);
  109. STATIC char* get_pt_proxy_uri(void);
  110. STATIC void free_execve_args(char **arg);
  111. #endif /* defined(PT_PRIVATE) */
  112. #endif /* !defined(TOR_TRANSPORTS_H) */