From f24519e4b9aeb39cbed50283936b86220c199e81 Mon Sep 17 00:00:00 2001 From: Nick Mathewson <nickm@torproject.org> Date: Tue, 6 Apr 2004 22:05:49 +0000 Subject: Set correct address and port mappings on outgoing rendezvous connections svn:r1513 --- src/or/rendservice.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/or/rendservice.c') diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 40a15aa6c..be7ddcb1e 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -735,6 +735,41 @@ int rend_services_init(void) { return 0; } +/* This is a beginning rendezvous stream. Look up conn->port, + * and assign the actual conn->addr and conn->port. Return -1 + * if failure, or 0 for success. + */ +int +rend_service_set_connection_addr_port(connection_t *conn, circuit_t *circ) +{ + rend_service_t *service; + int i; + rend_service_port_config_t *p; + char hexid[9]; + + assert(circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED); + hex_encode(circ->rend_pk_digest, 4, hexid); + service = rend_service_get_by_pk_digest(circ->rend_pk_digest); + if (!service) { + log_fn(LOG_WARN, "Couldn't find any service associated with pk %s on rendezvous circuit %d; closing", + hexid, circ->n_circ_id); + circuit_mark_for_close(circ); + connection_mark_for_close(conn, 0/*XXX*/); + } + for (i = 0; i < smartlist_len(service->ports); ++i) { + p = smartlist_get(service->ports, i); + if (conn->port == p->virtual_port) { + conn->addr = p->real_address; + conn->port = p->real_port; + return 0; + } + } + log_fn(LOG_WARN, "No virtual port mapping exists for port %d on service %s", + conn->port, hexid); + connection_mark_for_close(conn, 0/*XXX*/); + return -1; +} + /* Local Variables: mode:c -- cgit v1.2.3