]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add pluggable transport info to extra-info descriptors.
authorGeorge Kadianakis <desnacked@riseup.net>
Fri, 24 Feb 2012 01:51:48 +0000 (17:51 -0800)
committerGeorge Kadianakis <desnacked@riseup.net>
Tue, 3 Jul 2012 18:26:03 +0000 (21:26 +0300)
src/or/router.c
src/or/transports.c
src/or/transports.h

index 352c456f1f8a1c2df43b38331387510a943285eb..795afe2b3aba54f6c319fe3c3a583b501b1e8dbb 100644 (file)
@@ -2344,6 +2344,13 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
     }
   }
 
+  /* Add information about the pluggable transports we support. */
+  if (options->ServerTransportPlugin) {
+    char *pluggable_transports = pt_get_extra_info_descriptor_string();
+    if (pluggable_transports)
+      smartlist_add(chunks, pluggable_transports);
+  }
+
   if (should_record_bridge_info(options) && write_stats_to_extrainfo) {
     const char *bridge_stats = geoip_get_bridge_stats_extrainfo(now);
     if (bridge_stats) {
index e0492b8d6b9118b38a5a89fef9597561f6d0160c..e5a54463def6116c30652171d1989db8eba1df6e 100644 (file)
@@ -1373,6 +1373,51 @@ pt_prepare_proxy_list_for_config_read(void)
   tor_assert(unconfigured_proxies_n == 0);
 }
 
+/** Return the pluggable transport string that we should display in
+ *  our extra-info descriptor. If we shouldn't display such a string,
+ *  or we have nothing to display, return NULL. The string is
+ *  allocated on the heap and it's the responsibility of the caller to
+ *  free it. */
+char *
+pt_get_extra_info_descriptor_string(void)
+{
+  char *the_string = NULL;
+  smartlist_t *string_chunks = NULL;
+
+  if (!managed_proxy_list)
+    return NULL;
+
+  string_chunks = smartlist_new();
+
+  /* For each managed proxy, add its transports to the chunks list. */
+  SMARTLIST_FOREACH_BEGIN(managed_proxy_list,  const managed_proxy_t *, mp) {
+    if ((!mp->is_server) || (mp->conf_state != PT_PROTO_COMPLETED))
+      continue;
+
+    tor_assert(mp->transports);
+
+    SMARTLIST_FOREACH_BEGIN(mp->transports, const transport_t *, t) {
+      smartlist_add_asprintf(string_chunks,
+                             "method %s %s:%u",
+                             t->name, fmt_addr(&t->addr), t->port);
+    } SMARTLIST_FOREACH_END(t);
+
+  } SMARTLIST_FOREACH_END(mp);
+
+  if (smartlist_len(string_chunks) == 0) {
+    smartlist_free(string_chunks);
+    return NULL;
+  }
+
+  /* Join all the chunks into the final string. */
+  the_string = smartlist_join_strings(string_chunks, "\n", 1, NULL);
+
+  SMARTLIST_FOREACH(string_chunks, char *, s, tor_free(s));
+  smartlist_free(string_chunks);
+
+  return the_string;
+}
+
 /** The tor config was read.
  *  Destroy all managed proxies that were marked by a previous call to
  *  prepare_proxy_list_for_config_read() and are not used by the new
index 39f7bf4024e2f21b5e73a8fc4a32d742e1d19007..17d99dd754a43198c79876798db1c635784c44af 100644 (file)
@@ -46,6 +46,8 @@ void pt_configure_remaining_proxies(void);
 
 int pt_proxies_configuration_pending(void);
 
+char *pt_get_extra_info_descriptor_string(void);
+
 void pt_free_all(void);
 
 void pt_prepare_proxy_list_for_config_read(void);