[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor] 01/07: Log state transitions for Pluggable Transports



This is an automated email from the git hooks/post-receive script.

dgoulet pushed a commit to branch main
in repository tor.

commit 5118a8003b2679d30c7a3cc7207d50af985b9434
Author: Alexander Færøy <ahf@xxxxxxxxxxxxxx>
AuthorDate: Fri Sep 24 14:43:24 2021 +0200

    Log state transitions for Pluggable Transports
    
    This patch makes Tor log state transitions within the PT layer at the
    info log-level. This should make it easier to figure out if Tor ends up
    in a strange state.
    
    See: tpo/core/tor#33669
---
 src/feature/client/transports.c | 66 ++++++++++++++++++++++++++++++++++-------
 src/feature/client/transports.h |  2 ++
 2 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/src/feature/client/transports.c b/src/feature/client/transports.c
index 167beb96c6..c5d7df479d 100644
--- a/src/feature/client/transports.c
+++ b/src/feature/client/transports.c
@@ -541,7 +541,7 @@ proxy_prepare_for_restart(managed_proxy_t *mp)
   mp->proxy_supported = 0;
 
   /* flag it as an infant proxy so that it gets launched on next tick */
-  mp->conf_state = PT_PROTO_INFANT;
+  managed_proxy_set_state(mp, PT_PROTO_INFANT);
   unconfigured_proxies_n++;
 }
 
@@ -578,7 +578,7 @@ launch_managed_proxy(managed_proxy_t *mp)
   log_info(LD_CONFIG,
            "Managed proxy at '%s' has spawned with PID '%" PRIu64 "'.",
            mp->argv[0], process_get_pid(mp->process));
-  mp->conf_state = PT_PROTO_LAUNCHED;
+  managed_proxy_set_state(mp, PT_PROTO_LAUNCHED);
 
   return 0;
 }
@@ -648,7 +648,7 @@ configure_proxy(managed_proxy_t *mp)
   /* if we haven't launched the proxy yet, do it now */
   if (mp->conf_state == PT_PROTO_INFANT) {
     if (launch_managed_proxy(mp) < 0) { /* launch fail */
-      mp->conf_state = PT_PROTO_FAILED_LAUNCH;
+      managed_proxy_set_state(mp, PT_PROTO_FAILED_LAUNCH);
       handle_finished_proxy(mp);
     }
     return 0;
@@ -810,8 +810,12 @@ handle_finished_proxy(managed_proxy_t *mp)
       managed_proxy_destroy(mp, 1); /* annihilate it. */
       break;
     }
-    register_proxy(mp); /* register its transports */
-    mp->conf_state = PT_PROTO_COMPLETED; /* and mark it as completed. */
+
+    /* register its transports */
+    register_proxy(mp);
+
+    /* and mark it as completed. */
+    managed_proxy_set_state(mp, PT_PROTO_COMPLETED);
     break;
   case PT_PROTO_INFANT:
   case PT_PROTO_LAUNCHED:
@@ -881,7 +885,7 @@ handle_proxy_line(const char *line, managed_proxy_t *mp)
       goto err;
 
     tor_assert(mp->conf_protocol != 0);
-    mp->conf_state = PT_PROTO_ACCEPTING_METHODS;
+    managed_proxy_set_state(mp, PT_PROTO_ACCEPTING_METHODS);
     return;
   } else if (!strcmpstart(line, PROTO_CMETHODS_DONE)) {
     if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
@@ -889,7 +893,7 @@ handle_proxy_line(const char *line, managed_proxy_t *mp)
 
     handle_methods_done(mp);
 
-    mp->conf_state = PT_PROTO_CONFIGURED;
+    managed_proxy_set_state(mp, PT_PROTO_CONFIGURED);
     return;
   } else if (!strcmpstart(line, PROTO_SMETHODS_DONE)) {
     if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
@@ -897,7 +901,7 @@ handle_proxy_line(const char *line, managed_proxy_t *mp)
 
     handle_methods_done(mp);
 
-    mp->conf_state = PT_PROTO_CONFIGURED;
+    managed_proxy_set_state(mp, PT_PROTO_CONFIGURED);
     return;
   } else if (!strcmpstart(line, PROTO_CMETHOD_ERROR)) {
     if (mp->conf_state != PT_PROTO_ACCEPTING_METHODS)
@@ -960,7 +964,7 @@ handle_proxy_line(const char *line, managed_proxy_t *mp)
   return;
 
  err:
-  mp->conf_state = PT_PROTO_BROKEN;
+  managed_proxy_set_state(mp, PT_PROTO_BROKEN);
   log_warn(LD_CONFIG, "Managed proxy at '%s' failed the configuration protocol"
            " and will be destroyed.", mp->argv[0]);
 }
@@ -1521,7 +1525,7 @@ managed_proxy_create(const smartlist_t *with_transport_list,
                      char **proxy_argv, int is_server)
 {
   managed_proxy_t *mp = tor_malloc_zero(sizeof(managed_proxy_t));
-  mp->conf_state = PT_PROTO_INFANT;
+  managed_proxy_set_state(mp, PT_PROTO_INFANT);
   mp->is_server = is_server;
   mp->argv = proxy_argv;
   mp->transports = smartlist_new();
@@ -2015,3 +2019,45 @@ managed_proxy_outbound_address(const or_options_t *options, sa_family_t family)
   /* The user have not specified a preference for outgoing connections. */
   return NULL;
 }
+
+STATIC const char *
+managed_proxy_state_to_string(enum pt_proto_state state)
+{
+  switch (state) {
+  case PT_PROTO_INFANT:
+    return "Infant";
+  case PT_PROTO_LAUNCHED:
+    return "Launched";
+  case PT_PROTO_ACCEPTING_METHODS:
+    return "Accepting methods";
+  case PT_PROTO_CONFIGURED:
+    return "Configured";
+  case PT_PROTO_COMPLETED:
+    return "Completed";
+  case PT_PROTO_BROKEN:
+    return "Broken";
+  case PT_PROTO_FAILED_LAUNCH:
+    return "Failed to launch";
+  }
+
+  /* LCOV_EXCL_START */
+  tor_assert_unreached();
+  return NULL;
+  /* LCOV_EXCL_STOP */
+}
+
+/** Set the internal state of the given <b>mp</b> to the given <b>new_state</b>
+ * value. */
+STATIC void
+managed_proxy_set_state(managed_proxy_t *mp, enum pt_proto_state new_state)
+{
+  if (mp->conf_state == new_state)
+    return;
+
+  tor_log(LOG_INFO, LD_PT, "Managed proxy \"%s\" changed state: %s -> %s",
+          mp->argv[0],
+          managed_proxy_state_to_string(mp->conf_state),
+          managed_proxy_state_to_string(new_state));
+
+  mp->conf_state = new_state;
+}
diff --git a/src/feature/client/transports.h b/src/feature/client/transports.h
index 3f08beadba..535689537c 100644
--- a/src/feature/client/transports.h
+++ b/src/feature/client/transports.h
@@ -153,6 +153,8 @@ STATIC int managed_proxy_severity_parse(const char *);
 STATIC const tor_addr_t *managed_proxy_outbound_address(const or_options_t *,
                                                         sa_family_t);
 
+STATIC const char *managed_proxy_state_to_string(enum pt_proto_state);
+STATIC void managed_proxy_set_state(managed_proxy_t *, enum pt_proto_state);
 #endif /* defined(PT_PRIVATE) */
 
 #endif /* !defined(TOR_TRANSPORTS_H) */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits