aboutsummaryrefslogtreecommitdiff
path: root/src/or/connection_ap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/connection_ap.c')
-rw-r--r--src/or/connection_ap.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c
index ec8c05f0a..4cb97affe 100644
--- a/src/or/connection_ap.c
+++ b/src/or/connection_ap.c
@@ -108,6 +108,10 @@ int ap_handshake_process_socks(connection_t *conn) {
conn->next_stream = circ->p_conn;
circ->p_conn = conn;
+ assert(circ->cpath && circ->cpath->prev);
+ assert(circ->cpath->prev->state == CPATH_STATE_OPEN);
+ conn->cpath_layer = circ->cpath->prev;
+
if(ap_handshake_send_begin(conn, circ) < 0) {
circuit_close(circ);
return -1;
@@ -118,23 +122,24 @@ int ap_handshake_process_socks(connection_t *conn) {
int ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ) {
cell_t cell;
- uint16_t stream_id;
memset(&cell, 0, sizeof(cell_t));
/* deliver the dest_addr in a relay cell */
cell.command = CELL_RELAY;
cell.aci = circ->n_aci;
SET_CELL_RELAY_COMMAND(cell, RELAY_COMMAND_BEGIN);
- if (CRYPTO_PSEUDO_RAND_INT(stream_id))
+ if(crypto_pseudo_rand(STREAM_ID_SIZE, ap_conn->stream_id) < 0)
return -1;
- SET_CELL_STREAM_ID(cell, stream_id);
/* FIXME check for collisions */
- ap_conn->stream_id = stream_id;
-
- snprintf(cell.payload+4, CELL_PAYLOAD_SIZE-4, "%s:%d", ap_conn->dest_addr, ap_conn->dest_port);
- cell.length = strlen(cell.payload+RELAY_HEADER_SIZE)+1+RELAY_HEADER_SIZE;
- log(LOG_DEBUG,"ap_handshake_send_begin(): Sending relay cell to begin stream %d.", ap_conn->stream_id);
- if(circuit_deliver_relay_cell_from_edge(&cell, circ, EDGE_AP) < 0) {
+ SET_CELL_STREAM_ID(cell, ZERO_STREAM);
+
+ memcpy(cell.payload+RELAY_HEADER_SIZE, ap_conn->stream_id, STREAM_ID_SIZE);
+ cell.length =
+ snprintf(cell.payload+RELAY_HEADER_SIZE+STREAM_ID_SIZE, CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE-STREAM_ID_SIZE,
+ "%s:%d", ap_conn->dest_addr, ap_conn->dest_port) +
+ 1 + STREAM_ID_SIZE + RELAY_HEADER_SIZE;
+ log(LOG_DEBUG,"ap_handshake_send_begin(): Sending relay cell (id %d) to begin stream %d.", *(int *)(cell.payload+1),*(int *)ap_conn->stream_id);
+ if(circuit_deliver_relay_cell_from_edge(&cell, circ, EDGE_AP, ap_conn->cpath_layer) < 0) {
log(LOG_DEBUG,"ap_handshake_send_begin(): failed to deliver begin cell. Closing.");
return -1;
}