Browse Source

Start on the PIR client side

Ian Goldberg 3 years ago
parent
commit
7cfdd82766
1 changed files with 37 additions and 1 deletions
  1. 37 1
      src/feature/hs/hs_client.c

+ 37 - 1
src/feature/hs/hs_client.c

@@ -43,6 +43,7 @@
 #include "core/or/extend_info_st.h"
 #include "core/or/origin_circuit_st.h"
 
+#include "feature/hs/hs_pirprocess.h"
 #include "lib/wallclock/approx_time.h"
 
 /* Client-side authorizations for hidden services; map of service identity
@@ -1961,9 +1962,44 @@ pirparams_clear(void)
     digestmap_free(hsdir_pir_params, pirparams_free);
 }
 
-void hs_client_pir_init(void)
+static pir_process_t pirclient;
+
+#define PIRCLIENT_REQUEST_CREATE 0x41
+#define PIRCLIENT_REQUEST_EXTRACT 0x42
+
+#define PIRCLIENT_RESPONSE_CREATE 0xBF
+#define PIRCLIENT_RESPONSE_EXTRACT 0xBE
+
+void
+hs_client_pir_init(void)
 {
     hsdir_pir_params = digestmap_new();
+    pirclient = NULL;
+}
+
+static void
+hs_client_pirclient_received(const unsigned char *hdrbuf,
+    const char *bodybuf, size_t bodylen)
+{
+    log_info(LD_REND, "PIRCLIENT response header %p type %02x body len %ld body %s",
+        (void *)hdrbuf, hdrbuf[8], bodylen, escaped(bodybuf));
+    if (hdrbuf[8] == PIRCLIENT_RESPONSE_CREATE) {
+    } else if (hdrbuf[8] == PIRCLIENT_RESPONSE_EXTRACT) {
+    }
+}
+
+static void
+hs_client_pirclient_poke(void)
+{
+    hs_pirprocess_poke(getenv("PIR_CLIENT_PATH"), "PIRCLIENT",
+        hs_client_pirclient_received, &pirclient);
+}
+
+static int
+hs_client_pirclient_send(const unsigned char *buf, size_t len)
+{
+    hs_client_pirclient_poke();
+    return hs_pirprocess_send(pirclient, buf, len);
 }
 
 /* Release all the storage held by the client subsystem. */