|
@@ -2538,6 +2538,9 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
|
|
case DIR_PURPOSE_UPLOAD_HSDESC:
|
|
|
rv = handle_response_upload_hsdesc(conn, &args);
|
|
|
break;
|
|
|
+ case DIR_PURPOSE_FETCH_HSDESC:
|
|
|
+ rv = handle_response_fetch_hsdesc_v3(conn, &args);
|
|
|
+ break;
|
|
|
default:
|
|
|
tor_assert_nonfatal_unreached();
|
|
|
rv = -1;
|
|
@@ -3082,6 +3085,58 @@ handle_response_upload_signatures(dir_connection_t *conn,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Handler function: processes a response to a request for a v3 hidden service
|
|
|
+ * descriptor.
|
|
|
+ **/
|
|
|
+STATIC int
|
|
|
+handle_response_fetch_hsdesc_v3(dir_connection_t *conn,
|
|
|
+ const response_handler_args_t *args)
|
|
|
+{
|
|
|
+ const int status_code = args->status_code;
|
|
|
+ const char *reason = args->reason;
|
|
|
+ const char *body = args->body;
|
|
|
+ const size_t body_len = args->body_len;
|
|
|
+
|
|
|
+ tor_assert(conn->hs_ident);
|
|
|
+
|
|
|
+ log_info(LD_REND,"Received v3 hsdesc (body size %d, status %d (%s))",
|
|
|
+ (int)body_len, status_code, escaped(reason));
|
|
|
+
|
|
|
+ switch (status_code) {
|
|
|
+ case 200:
|
|
|
+ /* We got something: Try storing it in the cache. */
|
|
|
+ if (hs_cache_store_as_client(body, &conn->hs_ident->identity_pk) < 0) {
|
|
|
+ log_warn(LD_REND, "Failed to store hidden service descriptor");
|
|
|
+ } else {
|
|
|
+ log_info(LD_REND, "Stored hidden service descriptor successfully.");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 404:
|
|
|
+ /* Not there. We'll retry when connection_about_to_close_connection()
|
|
|
+ * tries to clean this conn up. */
|
|
|
+ log_info(LD_REND, "Fetching hidden service v3 descriptor not found: "
|
|
|
+ "Retrying at another directory.");
|
|
|
+ /* TODO: Inform the control port */
|
|
|
+ break;
|
|
|
+ case 400:
|
|
|
+ log_warn(LD_REND, "Fetching v3 hidden service descriptor failed: "
|
|
|
+ "http status 400 (%s). Dirserver didn't like our "
|
|
|
+ "query? Retrying at another directory.",
|
|
|
+ escaped(reason));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ log_warn(LD_REND, "Fetching v3 hidden service descriptor failed: "
|
|
|
+ "http status %d (%s) response unexpected from HSDir server "
|
|
|
+ "'%s:%d'. Retrying at another directory.",
|
|
|
+ status_code, escaped(reason), TO_CONN(conn)->address,
|
|
|
+ TO_CONN(conn)->port);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Handler function: processes a response to a request for a v2 hidden service
|
|
|
* descriptor.
|