|
@@ -1966,11 +1966,6 @@ pirparams_clear(void)
|
|
|
digestmap_free(hsdir_pir_params, pirparams_free);
|
|
|
}
|
|
|
|
|
|
-typedef struct {
|
|
|
- void (*callback)(dir_connection_t *, int, const directory_request_t *);
|
|
|
- dir_connection_t *conn;
|
|
|
-} HSClientPIRCallback;
|
|
|
-
|
|
|
static pir_process_t pirclient;
|
|
|
|
|
|
#define PIRCLIENT_REQUEST_CREATE 0x41
|
|
@@ -1993,32 +1988,34 @@ hs_client_pirclient_received(const unsigned char *hdrbuf,
|
|
|
log_info(LD_REND, "PIRCLIENT response header %p type %02x body len %ld",
|
|
|
(void *)hdrbuf, hdrbuf[8], bodylen);
|
|
|
if (hdrbuf[8] == PIRCLIENT_RESPONSE_CREATE && bodylen > 8) {
|
|
|
- HSClientPIRCallback *cb;
|
|
|
- memmove(&cb, hdrbuf, sizeof(cb));
|
|
|
- /* PIRONION TODO: As with the server, it's possible the conn
|
|
|
- * contained in this structure might have closed on us. In the
|
|
|
- * future, hook the callback that closes a dir_connection_t. */
|
|
|
- const node_t *node = node_get_by_id(cb->conn->identity_digest);
|
|
|
- if (!node) goto createerr;
|
|
|
+ dir_connection_t *conn;
|
|
|
+ uint64_t reqid;
|
|
|
+ memmove(&reqid, hdrbuf, sizeof(reqid));
|
|
|
+ conn = hs_pirprocess_lookup_reqid(reqid);
|
|
|
+ if (!conn) {
|
|
|
+ /* The dir_connection_t has closed between the time we
|
|
|
+ * started the PIR query creation and now (when we are ready
|
|
|
+ * to send it). */
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const node_t *node = node_get_by_id(conn->identity_digest);
|
|
|
+ if (!node) return;
|
|
|
const routerstatus_t *rstat = node->rs;
|
|
|
- if (!rstat) goto createerr;
|
|
|
+ if (!rstat) return;
|
|
|
directory_request_t *req =
|
|
|
directory_request_new(DIR_PURPOSE_FETCH_HSDESC);
|
|
|
directory_request_set_routerstatus(req, rstat);
|
|
|
directory_request_set_indirection(req, DIRIND_ANONYMOUS);
|
|
|
- directory_request_set_resource(req, cb->conn->requested_resource);
|
|
|
+ directory_request_set_resource(req, conn->requested_resource);
|
|
|
directory_request_set_payload(req, bodybuf+8, bodylen-8);
|
|
|
- directory_request_fetch_set_hs_ident(req, cb->conn->hs_ident);
|
|
|
- memmove(cb->conn->pirclient_queryid, bodybuf, 8);
|
|
|
+ directory_request_fetch_set_hs_ident(req, conn->hs_ident);
|
|
|
+ memmove(conn->pirclient_queryid, bodybuf, 8);
|
|
|
log_info(LD_REND, "PIRCLIENT Refetching %s from %s",
|
|
|
- cb->conn->requested_resource,
|
|
|
+ conn->requested_resource,
|
|
|
safe_str_client(routerstatus_describe(rstat)));
|
|
|
- (cb->callback)(cb->conn, 0, req);
|
|
|
+ connection_dir_client_directory_send_command(conn, 0, req);
|
|
|
directory_request_free(req);
|
|
|
-
|
|
|
- createerr:
|
|
|
- tor_free(cb);
|
|
|
- return;
|
|
|
+ hs_pirprocess_dealloc_reqid(conn);
|
|
|
} else if (hdrbuf[8] == PIRCLIENT_RESPONSE_EXTRACT) {
|
|
|
connection_dir_client_conninfo_t conninfo;
|
|
|
memmove(&conninfo, hdrbuf, sizeof(conninfo));
|
|
@@ -2047,27 +2044,22 @@ hs_client_pirclient_send(const unsigned char *buf, size_t len)
|
|
|
}
|
|
|
|
|
|
/* Initiate the creation of a PIR request by the pirclient process.
|
|
|
- * When it is done, call back the callback function with the given
|
|
|
- * parameters, and a new req having req->payload filled in with the
|
|
|
- * PIR request. */
|
|
|
+ * When it is done, call connection_dir_client_directory_send_command
|
|
|
+ * with the given conn, and a new req having req->payload filled in with
|
|
|
+ * the PIR request. */
|
|
|
void
|
|
|
-hs_client_pir_create(
|
|
|
- void (*callback)(dir_connection_t *, int, const directory_request_t *),
|
|
|
- dir_connection_t *conn)
|
|
|
+hs_client_pir_create(dir_connection_t *conn)
|
|
|
{
|
|
|
HSClientPIRParams *pirparams =
|
|
|
hs_client_pirparams_lookup(conn->identity_digest);
|
|
|
- HSClientPIRCallback *cb;
|
|
|
unsigned char hdr[PIRPROCESS_HDR_SIZE];
|
|
|
size_t bodylen;
|
|
|
char resource[32];
|
|
|
+ uint64_t reqid;
|
|
|
|
|
|
if (pirparams == NULL) return;
|
|
|
- cb = tor_malloc_zero(sizeof(HSClientPIRCallback));
|
|
|
- if (cb == NULL) return;
|
|
|
- cb->callback = callback;
|
|
|
- cb->conn = conn;
|
|
|
- memmove(hdr, (const char *)(&cb), sizeof(cb));
|
|
|
+ reqid = hs_pirprocess_alloc_reqid(conn);
|
|
|
+ memmove(hdr, &reqid, sizeof(reqid));
|
|
|
hdr[8] = PIRCLIENT_REQUEST_CREATE;
|
|
|
bodylen = 32 + pirparams->size;
|
|
|
*(uint32_t*)(hdr+9) = htonl(bodylen);
|