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

[tor-commits] [tor/master] Change EVENT_TRANSPORT_LOG to EVENT_PT_LOG.



commit ec2ae3ed8b542950dc774223607f14f524375a50
Author: Alexander Færøy <ahf@xxxxxxxxxxxxxx>
Date:   Thu Nov 29 16:42:56 2018 +0100

    Change EVENT_TRANSPORT_LOG to EVENT_PT_LOG.
    
    This patch changes our EVENT_TRANSPORT_LOG event to be EVENT_PT_LOG. The
    new message includes the path to the PT executable instead of the
    transport name, since one PT binary can include multiple transport they
    sometimes might need to log messages that are not specific to a given
    transport.
    
    See: https://bugs.torproject.org/28179
---
 src/feature/client/transports.c | 33 ++++++++++-----------------------
 src/feature/client/transports.h |  2 +-
 src/feature/control/control.c   | 10 +++++-----
 src/feature/control/control.h   |  5 ++---
 src/test/test_pt.c              |  6 +++---
 5 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/src/feature/client/transports.c b/src/feature/client/transports.c
index e3cc67941..df7991846 100644
--- a/src/feature/client/transports.c
+++ b/src/feature/client/transports.c
@@ -910,7 +910,7 @@ handle_proxy_line(const char *line, managed_proxy_t *mp)
     parse_proxy_error(line);
     goto err;
   } else if (!strcmpstart(line, PROTO_LOG)) {
-    parse_log_line(line);
+    parse_log_line(line, mp);
     return;
   }
 
@@ -1135,40 +1135,27 @@ parse_proxy_error(const char *line)
 
 /** Parses a LOG <b>line</b> and emit log events accordingly. */
 STATIC void
-parse_log_line(const char *line)
+parse_log_line(const char *line, managed_proxy_t *mp)
 {
-  smartlist_t *items = smartlist_new();
+  tor_assert(line);
+  tor_assert(mp);
 
   if (strlen(line) < (strlen(PROTO_LOG) + 1)) {
     log_warn(LD_PT, "Managed proxy sent us a %s line "
-                    "with missing arguments.", PROTO_LOG);
-    goto done;
-  }
-
-  const char *arguments = line + strlen(PROTO_LOG) + 1;
-
-  /* The format is 'LOG <transport> <message>'. We accept empty messages. */
-  smartlist_split_string(items, arguments, NULL,
-                         SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
-
-  if (smartlist_len(items) < 2) {
-    log_warn(LD_PT, "Managed proxy sent us a %s line "
-                    "with too few arguments.", PROTO_LOG);
+                    "with missing argument.", PROTO_LOG);
     goto done;
   }
 
-  const char *transport_name = smartlist_get(items, 0);
-  const char *message = smartlist_get(items, 1);
+  const char *message = line + strlen(PROTO_LOG) + 1;
 
-  log_info(LD_PT, "Managed proxy transport \"%s\" says: %s",
-           transport_name, message);
+  log_info(LD_PT, "Managed proxy \"%s\" says: %s",
+           mp->argv[0], message);
 
   /* Emit control port event. */
-  control_event_transport_log(transport_name, message);
+  control_event_pt_log(mp->argv[0], message);
 
  done:
-  SMARTLIST_FOREACH(items, char *, s, tor_free(s));
-  smartlist_free(items);
+  return;
 }
 
 /** Return a newly allocated string that tor should place in
diff --git a/src/feature/client/transports.h b/src/feature/client/transports.h
index ba8cbf710..88735a721 100644
--- a/src/feature/client/transports.h
+++ b/src/feature/client/transports.h
@@ -128,7 +128,7 @@ STATIC int parse_version(const char *line, managed_proxy_t *mp);
 STATIC void parse_env_error(const char *line);
 STATIC void parse_proxy_error(const char *line);
 STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
-STATIC void parse_log_line(const char *line);
+STATIC void parse_log_line(const char *line, managed_proxy_t *mp);
 STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
 
 STATIC void managed_proxy_destroy(managed_proxy_t *mp,
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index b6505a85d..ebda51781 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -7395,14 +7395,14 @@ control_event_transport_launched(const char *mode, const char *transport_name,
                      mode, transport_name, fmt_addr(addr), port);
 }
 
-/** A pluggable transport called <b>transport_name</b> has emitted a log
+/** A pluggable transport called <b>pt_name</b> has emitted a log
  * message found in <b>message</b>. */
 void
-control_event_transport_log(const char *transport_name, const char *message)
+control_event_pt_log(const char *pt_name, const char *message)
 {
-  send_control_event(EVENT_TRANSPORT_LOG,
-                     "650 TRANSPORT_LOG %s %s\r\n",
-                     transport_name,
+  send_control_event(EVENT_PT_LOG,
+                     "650 PT_LOG %s %s\r\n",
+                     pt_name,
                      message);
 }
 
diff --git a/src/feature/control/control.h b/src/feature/control/control.h
index eb2b5676e..c554c3253 100644
--- a/src/feature/control/control.h
+++ b/src/feature/control/control.h
@@ -205,8 +205,7 @@ void control_event_clients_seen(const char *controller_str);
 void control_event_transport_launched(const char *mode,
                                       const char *transport_name,
                                       tor_addr_t *addr, uint16_t port);
-void control_event_transport_log(const char *transport_name,
-                                 const char *message);
+void control_event_pt_log(const char *pt_name, const char *message);
 const char *rend_auth_type_to_string(rend_auth_type_t auth_type);
 MOCK_DECL(const char *, node_describe_longname_by_id,(const char *id_digest));
 void control_event_hs_descriptor_requested(const char *onion_address,
@@ -295,7 +294,7 @@ void control_free_all(void);
 #define EVENT_HS_DESC                 0x0021
 #define EVENT_HS_DESC_CONTENT         0x0022
 #define EVENT_NETWORK_LIVENESS        0x0023
-#define EVENT_TRANSPORT_LOG           0x0024
+#define EVENT_PT_LOG                  0x0024
 #define EVENT_MAX_                    0x0024
 
 /* sizeof(control_connection_t.event_mask) in bits, currently a uint64_t */
diff --git a/src/test/test_pt.c b/src/test/test_pt.c
index b5572ef80..8fcdd5c1e 100644
--- a/src/test/test_pt.c
+++ b/src/test/test_pt.c
@@ -310,7 +310,7 @@ process_read_stdout_replacement(process_t *process, buf_t *buffer)
   } else if (times_called <= 6) {
     buf_add_string(buffer, "SMETHODS DONE\n");
   } else if (times_called <= 7) {
-    buf_add_string(buffer, "LOG mock3 Oh noes, something bad happened. "
+    buf_add_string(buffer, "LOG Oh noes, something bad happened. "
                            "What do we do!?\n");
   }
 
@@ -417,10 +417,10 @@ test_pt_configure_proxy(void *arg)
   process_notify_event_stdout(mp->process);
 
   tt_int_op(controlevent_n, OP_EQ, 6);
-  tt_int_op(controlevent_event, OP_EQ, EVENT_TRANSPORT_LOG);
+  tt_int_op(controlevent_event, OP_EQ, EVENT_PT_LOG);
   tt_int_op(smartlist_len(controlevent_msgs), OP_EQ, 6);
   tt_str_op(smartlist_get(controlevent_msgs, 5), OP_EQ,
-            "650 TRANSPORT_LOG mock3 Oh noes, something bad happened. "
+            "650 PT_LOG <testcase> Oh noes, something bad happened. "
             "What do we do!?\r\n");
 
   { /* check that the transport info were saved properly in the tor state */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits