Browse Source

Adding REASON field to HS_DESC FAILED controller event.

rl1987 9 years ago
parent
commit
0db96d023b
4 changed files with 36 additions and 18 deletions
  1. 19 6
      src/or/control.c
  2. 4 2
      src/or/control.h
  3. 7 6
      src/or/directory.c
  4. 6 4
      src/test/test_hs.c

+ 19 - 6
src/or/control.c

@@ -5096,20 +5096,30 @@ control_event_hs_descriptor_requested(const rend_data_t *rend_query,
 void
 control_event_hs_descriptor_receive_end(const char *action,
                                         const rend_data_t *rend_query,
-                                        const char *id_digest)
+                                        const char *id_digest,
+                                        const char *reason)
 {
+  char *reason_field = NULL;
+
   if (!action || !rend_query || !id_digest) {
     log_warn(LD_BUG, "Called with action==%p, rend_query==%p, "
              "id_digest==%p", action, rend_query, id_digest);
     return;
   }
 
+  if (reason) {
+    tor_asprintf(&reason_field, " REASON=%s", reason);
+  }
+
   send_control_event(EVENT_HS_DESC, ALL_FORMATS,
-                     "650 HS_DESC %s %s %s %s\r\n",
+                     "650 HS_DESC %s %s %s %s%s\r\n",
                      action,
                      rend_query->onion_address,
                      rend_auth_type_to_string(rend_query->auth_type),
-                     node_describe_longname_by_id(id_digest));
+                     node_describe_longname_by_id(id_digest),
+                     reason_field ? reason_field : "");
+
+  tor_free(reason_field);
 }
 
 /** send HS_DESC RECEIVED event
@@ -5125,7 +5135,8 @@ control_event_hs_descriptor_received(const rend_data_t *rend_query,
              rend_query, id_digest);
     return;
   }
-  control_event_hs_descriptor_receive_end("RECEIVED", rend_query, id_digest);
+  control_event_hs_descriptor_receive_end("RECEIVED", rend_query,
+                                          id_digest, NULL);
 }
 
 /** send HS_DESC FAILED event
@@ -5134,14 +5145,16 @@ control_event_hs_descriptor_received(const rend_data_t *rend_query,
  */
 void
 control_event_hs_descriptor_failed(const rend_data_t *rend_query,
-                                   const char *id_digest)
+                                   const char *id_digest,
+                                   const char *reason)
 {
   if (!rend_query || !id_digest) {
     log_warn(LD_BUG, "Called with rend_query==%p, id_digest==%p",
              rend_query, id_digest);
     return;
   }
-  control_event_hs_descriptor_receive_end("FAILED", rend_query, id_digest);
+  control_event_hs_descriptor_receive_end("FAILED", rend_query,
+                                          id_digest, reason);
 }
 
 /** Free any leftover allocated memory of the control.c subsystem. */

+ 4 - 2
src/or/control.h

@@ -108,11 +108,13 @@ void control_event_hs_descriptor_requested(const rend_data_t *rend_query,
                                            const char *hs_dir);
 void control_event_hs_descriptor_receive_end(const char *action,
                                         const rend_data_t *rend_query,
-                                        const char *hs_dir);
+                                        const char *hs_dir,
+                                        const char *reason);
 void control_event_hs_descriptor_received(const rend_data_t *rend_query,
                                           const char *hs_dir);
 void control_event_hs_descriptor_failed(const rend_data_t *rend_query,
-                                        const char *hs_dir);
+                                        const char *hs_dir,
+                                        const char *reason);
 
 void control_free_all(void);
 

+ 7 - 6
src/or/directory.c

@@ -2073,9 +2073,10 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
   }
 
   if (conn->base_.purpose == DIR_PURPOSE_FETCH_RENDDESC_V2) {
-    #define SEND_HS_DESC_FAILED_EVENT() ( \
+    #define SEND_HS_DESC_FAILED_EVENT(reason) ( \
       control_event_hs_descriptor_failed(conn->rend_data, \
-                                         conn->identity_digest) )
+                                         conn->identity_digest, \
+                                         reason) )
     tor_assert(conn->rend_data);
     log_info(LD_REND,"Received rendezvous descriptor (size %d, status %d "
              "(%s))",
@@ -2090,7 +2091,7 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
                      "Retrying at another directory.");
             /* We'll retry when connection_about_to_close_connection()
              * cleans this dir conn up. */
-            SEND_HS_DESC_FAILED_EVENT();
+            SEND_HS_DESC_FAILED_EVENT("BAD_DESC");
             break;
           case RCS_OKAY:
           default:
@@ -2109,14 +2110,14 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
          * connection_about_to_close_connection() cleans this conn up. */
         log_info(LD_REND,"Fetching v2 rendezvous descriptor failed: "
                          "Retrying at another directory.");
-        SEND_HS_DESC_FAILED_EVENT();
+        SEND_HS_DESC_FAILED_EVENT("NOT_FOUND");
         break;
       case 400:
         log_warn(LD_REND, "Fetching v2 rendezvous descriptor failed: "
                  "http status 400 (%s). Dirserver didn't like our "
                  "v2 rendezvous query? Retrying at another directory.",
                  escaped(reason));
-        SEND_HS_DESC_FAILED_EVENT();
+        SEND_HS_DESC_FAILED_EVENT("QUERY_REJECTED");
         break;
       default:
         log_warn(LD_REND, "Fetching v2 rendezvous descriptor failed: "
@@ -2125,7 +2126,7 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
                  "Retrying at another directory.",
                  status_code, escaped(reason), conn->base_.address,
                  conn->base_.port);
-        SEND_HS_DESC_FAILED_EVENT();
+        SEND_HS_DESC_FAILED_EVENT("UNEXPECTED");
         break;
     }
   }

+ 6 - 4
src/test/test_hs.c

@@ -99,18 +99,20 @@ test_hs_desc_event(void *arg)
 
   /* test failed event */
   rend_query.auth_type = 2;
-  control_event_hs_descriptor_failed(&rend_query, HSDIR_NONE_EXIST_ID);
+  control_event_hs_descriptor_failed(&rend_query, HSDIR_NONE_EXIST_ID,
+                                     "QUERY_REJECTED");
   expected_msg = "650 HS_DESC FAILED "STR_HS_ADDR" STEALTH_AUTH "\
-                  STR_HSDIR_NONE_EXIST_LONGNAME"\r\n";
+                  STR_HSDIR_NONE_EXIST_LONGNAME" REASON=QUERY_REJECTED\r\n";
   tt_assert(received_msg);
   tt_str_op(received_msg,OP_EQ, expected_msg);
   tor_free(received_msg);
 
   /* test invalid auth type */
   rend_query.auth_type = 999;
-  control_event_hs_descriptor_failed(&rend_query, HSDIR_EXIST_ID);
+  control_event_hs_descriptor_failed(&rend_query, HSDIR_EXIST_ID,
+                                     "QUERY_REJECTED");
   expected_msg = "650 HS_DESC FAILED "STR_HS_ADDR" UNKNOWN "\
-                  STR_HSDIR_EXIST_LONGNAME"\r\n";
+                  STR_HSDIR_EXIST_LONGNAME" REASON=QUERY_REJECTED\r\n";
   tt_assert(received_msg);
   tt_str_op(received_msg,OP_EQ, expected_msg);
   tor_free(received_msg);