mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Refactoring: Remove 'addresstype' from connection_ap_handle_onion().
It's all v3 now. Preparation for fixing CID 1473232.
This commit is contained in:
parent
c0a2330314
commit
32fc8a116a
@ -1929,13 +1929,12 @@ connection_ap_handshake_rewrite(entry_connection_t *conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** We just received a SOCKS request in <b>conn</b> to an onion address of type
|
/** We just received a SOCKS request in <b>conn</b> to a v3 onion. Start
|
||||||
* <b>addresstype</b>. Start connecting to the onion service. */
|
* connecting to the onion service. */
|
||||||
static int
|
static int
|
||||||
connection_ap_handle_onion(entry_connection_t *conn,
|
connection_ap_handle_onion(entry_connection_t *conn,
|
||||||
socks_request_t *socks,
|
socks_request_t *socks,
|
||||||
origin_circuit_t *circ,
|
origin_circuit_t *circ)
|
||||||
hostname_type_t addresstype)
|
|
||||||
{
|
{
|
||||||
time_t now = approx_time();
|
time_t now = approx_time();
|
||||||
connection_t *base_conn = ENTRY_TO_CONN(conn);
|
connection_t *base_conn = ENTRY_TO_CONN(conn);
|
||||||
@ -1978,38 +1977,36 @@ connection_ap_handle_onion(entry_connection_t *conn,
|
|||||||
int rend_cache_lookup_result = -ENOENT;
|
int rend_cache_lookup_result = -ENOENT;
|
||||||
int descriptor_is_usable = 0;
|
int descriptor_is_usable = 0;
|
||||||
|
|
||||||
if (addresstype == ONION_V3_HOSTNAME) {
|
const hs_descriptor_t *cached_desc = NULL;
|
||||||
const hs_descriptor_t *cached_desc = NULL;
|
int retval;
|
||||||
int retval;
|
/* Create HS conn identifier with HS pubkey */
|
||||||
/* Create HS conn identifier with HS pubkey */
|
hs_ident_edge_conn_t *hs_conn_ident =
|
||||||
hs_ident_edge_conn_t *hs_conn_ident =
|
tor_malloc_zero(sizeof(hs_ident_edge_conn_t));
|
||||||
tor_malloc_zero(sizeof(hs_ident_edge_conn_t));
|
|
||||||
|
|
||||||
retval = hs_parse_address(socks->address, &hs_conn_ident->identity_pk,
|
retval = hs_parse_address(socks->address, &hs_conn_ident->identity_pk,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
log_warn(LD_GENERAL, "failed to parse hs address");
|
log_warn(LD_GENERAL, "failed to parse hs address");
|
||||||
tor_free(hs_conn_ident);
|
tor_free(hs_conn_ident);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ENTRY_TO_EDGE_CONN(conn)->hs_ident = hs_conn_ident;
|
ENTRY_TO_EDGE_CONN(conn)->hs_ident = hs_conn_ident;
|
||||||
|
|
||||||
onion_address = socks->address;
|
onion_address = socks->address;
|
||||||
|
|
||||||
/* Check the v3 desc cache */
|
/* Check the v3 desc cache */
|
||||||
cached_desc = hs_cache_lookup_as_client(&hs_conn_ident->identity_pk);
|
cached_desc = hs_cache_lookup_as_client(&hs_conn_ident->identity_pk);
|
||||||
if (cached_desc) {
|
if (cached_desc) {
|
||||||
rend_cache_lookup_result = 0;
|
rend_cache_lookup_result = 0;
|
||||||
descriptor_is_usable =
|
descriptor_is_usable =
|
||||||
hs_client_any_intro_points_usable(&hs_conn_ident->identity_pk,
|
hs_client_any_intro_points_usable(&hs_conn_ident->identity_pk,
|
||||||
cached_desc);
|
cached_desc);
|
||||||
log_info(LD_GENERAL, "Found %s descriptor in cache for %s. %s.",
|
log_info(LD_GENERAL, "Found %s descriptor in cache for %s. %s.",
|
||||||
(descriptor_is_usable) ? "usable" : "unusable",
|
(descriptor_is_usable) ? "usable" : "unusable",
|
||||||
safe_str_client(onion_address),
|
safe_str_client(onion_address),
|
||||||
(descriptor_is_usable) ? "Not fetching." : "Refetching.");
|
(descriptor_is_usable) ? "Not fetching." : "Refetching.");
|
||||||
} else {
|
} else {
|
||||||
rend_cache_lookup_result = -ENOENT;
|
rend_cache_lookup_result = -ENOENT;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lookup the given onion address. If invalid, stop right now.
|
/* Lookup the given onion address. If invalid, stop right now.
|
||||||
@ -2048,27 +2045,25 @@ connection_ap_handle_onion(entry_connection_t *conn,
|
|||||||
edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(conn);
|
edge_connection_t *edge_conn = ENTRY_TO_EDGE_CONN(conn);
|
||||||
connection_ap_mark_as_non_pending_circuit(conn);
|
connection_ap_mark_as_non_pending_circuit(conn);
|
||||||
base_conn->state = AP_CONN_STATE_RENDDESC_WAIT;
|
base_conn->state = AP_CONN_STATE_RENDDESC_WAIT;
|
||||||
if (addresstype == ONION_V3_HOSTNAME) {
|
tor_assert(edge_conn->hs_ident);
|
||||||
tor_assert(edge_conn->hs_ident);
|
/* Attempt to fetch the hsv3 descriptor. Check the retval to see how it
|
||||||
/* Attempt to fetch the hsv3 descriptor. Check the retval to see how it
|
* went and act accordingly. */
|
||||||
* went and act accordingly. */
|
int ret = hs_client_refetch_hsdesc(&edge_conn->hs_ident->identity_pk);
|
||||||
int ret = hs_client_refetch_hsdesc(&edge_conn->hs_ident->identity_pk);
|
switch (ret) {
|
||||||
switch (ret) {
|
case HS_CLIENT_FETCH_MISSING_INFO:
|
||||||
case HS_CLIENT_FETCH_MISSING_INFO:
|
/* Keeping the connection in descriptor wait state is fine because
|
||||||
/* Keeping the connection in descriptor wait state is fine because
|
* once we get enough dirinfo or a new live consensus, the HS client
|
||||||
* once we get enough dirinfo or a new live consensus, the HS client
|
* subsystem is notified and every connection in that state will
|
||||||
* subsystem is notified and every connection in that state will
|
* trigger a fetch for the service key. */
|
||||||
* trigger a fetch for the service key. */
|
case HS_CLIENT_FETCH_LAUNCHED:
|
||||||
case HS_CLIENT_FETCH_LAUNCHED:
|
case HS_CLIENT_FETCH_PENDING:
|
||||||
case HS_CLIENT_FETCH_PENDING:
|
case HS_CLIENT_FETCH_HAVE_DESC:
|
||||||
case HS_CLIENT_FETCH_HAVE_DESC:
|
return 0;
|
||||||
return 0;
|
case HS_CLIENT_FETCH_ERROR:
|
||||||
case HS_CLIENT_FETCH_ERROR:
|
case HS_CLIENT_FETCH_NO_HSDIRS:
|
||||||
case HS_CLIENT_FETCH_NO_HSDIRS:
|
case HS_CLIENT_FETCH_NOT_ALLOWED:
|
||||||
case HS_CLIENT_FETCH_NOT_ALLOWED:
|
/* Can't proceed further and better close the SOCKS request. */
|
||||||
/* Can't proceed further and better close the SOCKS request. */
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2515,7 +2510,7 @@ connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
|
|||||||
/* If we get here, it's a request for a .onion address! */
|
/* If we get here, it's a request for a .onion address! */
|
||||||
tor_assert(addresstype == ONION_V3_HOSTNAME);
|
tor_assert(addresstype == ONION_V3_HOSTNAME);
|
||||||
tor_assert(!automap);
|
tor_assert(!automap);
|
||||||
return connection_ap_handle_onion(conn, socks, circ, addresstype);
|
return connection_ap_handle_onion(conn, socks, circ);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; /* unreached but keeps the compiler happy */
|
return 0; /* unreached but keeps the compiler happy */
|
||||||
|
Loading…
Reference in New Issue
Block a user