[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] play with connection_edge_send_command
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
connection_edge.c or.h
Log Message:
play with connection_edge_send_command
maybe more robust now
Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- connection_edge.c 22 Oct 2003 07:55:44 -0000 1.43
+++ connection_edge.c 22 Oct 2003 09:08:10 -0000 1.44
@@ -13,8 +13,7 @@
int replylen, char success);
static int connection_exit_begin_conn(cell_t *cell, circuit_t *circ);
-static void connection_edge_consider_sending_sendme(connection_t *conn,
- int edge_type);
+static void connection_edge_consider_sending_sendme(connection_t *conn);
int connection_edge_process_inbuf(connection_t *conn) {
@@ -112,15 +111,15 @@
conn->has_sent_end = 1;
}
-void connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int relay_command,
- void *payload, int payload_len, crypt_path_t *cpath_layer) {
+int connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int relay_command,
+ void *payload, int payload_len, crypt_path_t *cpath_layer) {
cell_t cell;
int cell_direction;
int is_control_cell=0;
if(!circ) {
log_fn(LOG_WARN,"no circ. Closing.");
- return;
+ return 0;
}
if(!fromconn || relay_command == RELAY_COMMAND_BEGIN) /* XXX more */
@@ -153,7 +152,9 @@
if(circuit_deliver_relay_cell(&cell, circ, cell_direction, cpath_layer) < 0) {
log_fn(LOG_WARN,"circuit_deliver_relay_cell failed. Closing.");
circuit_close(circ);
+ return -1;
}
+ return 0;
}
/* an incoming relay cell has arrived. return -1 if you want to tear down the
@@ -231,7 +232,7 @@
stats_n_data_bytes_received += (cell->length - RELAY_HEADER_SIZE);
connection_write_to_buf(cell->payload + RELAY_HEADER_SIZE,
cell->length - RELAY_HEADER_SIZE, conn);
- connection_edge_consider_sending_sendme(conn, edge_type);
+ connection_edge_consider_sending_sendme(conn);
return 0;
case RELAY_COMMAND_END:
if(!conn) {
@@ -372,13 +373,14 @@
if(connection_wants_to_flush(conn)) /* in case there are any queued relay cells */
connection_start_writing(conn);
/* deliver a 'connected' relay cell back through the circuit. */
- connection_edge_send_command(conn, circuit_get_by_conn(conn), RELAY_COMMAND_CONNECTED,
- NULL, 0, conn->cpath_layer);
+ if(connection_edge_send_command(conn, circuit_get_by_conn(conn),
+ RELAY_COMMAND_CONNECTED, NULL, 0, conn->cpath_layer) < 0)
+ return 0; /* circuit is closed, don't continue */
return connection_process_inbuf(conn); /* in case the server has written anything */
case AP_CONN_STATE_OPEN:
case EXIT_CONN_STATE_OPEN:
connection_stop_writing(conn);
- connection_edge_consider_sending_sendme(conn, conn->type);
+ connection_edge_consider_sending_sendme(conn);
return 0;
case AP_CONN_STATE_SOCKS_WAIT:
connection_stop_writing(conn);
@@ -438,8 +440,9 @@
log_fn(LOG_DEBUG,"(%d) Packaging %d bytes (%d waiting).",conn->s,length,
(int)buf_datalen(conn->inbuf));
- connection_edge_send_command(conn, circ, RELAY_COMMAND_DATA,
- payload, length, conn->cpath_layer);
+ if(connection_edge_send_command(conn, circ, RELAY_COMMAND_DATA,
+ payload, length, conn->cpath_layer) < 0)
+ return 0; /* circuit is closed, don't continue */
if(conn->type == CONN_TYPE_EXIT) {
assert(circ->package_window > 0);
@@ -462,38 +465,27 @@
goto repeat_connection_edge_package_raw_inbuf;
}
-static void connection_edge_consider_sending_sendme(connection_t *conn, int edge_type) {
+static void connection_edge_consider_sending_sendme(connection_t *conn) {
circuit_t *circ;
- cell_t cell;
if(connection_outbuf_too_full(conn))
return;
circ = circuit_get_by_conn(conn);
if(!circ) {
- /* this can legitimately happen if the destroy has already arrived and torn down the circuit */
+ /* this can legitimately happen if the destroy has already
+ * arrived and torn down the circuit */
log_fn(LOG_INFO,"No circuit associated with conn. Skipping.");
return;
}
- memset(&cell, 0, sizeof(cell_t));
- cell.command = CELL_RELAY;
- SET_CELL_RELAY_COMMAND(cell, RELAY_COMMAND_SENDME);
- SET_CELL_STREAM_ID(cell, conn->stream_id);
- cell.length += RELAY_HEADER_SIZE;
-
- if(edge_type == EDGE_EXIT)
- cell.aci = circ->p_aci;
- else
- cell.aci = circ->n_aci;
-
while(conn->deliver_window < STREAMWINDOW_START - STREAMWINDOW_INCREMENT) {
log_fn(LOG_DEBUG,"Outbuf %d, Queueing stream sendme.", conn->outbuf_flushlen);
conn->deliver_window += STREAMWINDOW_INCREMENT;
- if(circuit_deliver_relay_cell(&cell, circ, CELL_DIRECTION(edge_type), conn->cpath_layer) < 0) {
- log_fn(LOG_WARN,"circuit_deliver_relay_cell failed. Closing.");
- circuit_close(circ);
- return;
+ if(connection_edge_send_command(conn, circ, RELAY_COMMAND_SENDME,
+ NULL, 0, conn->cpath_layer) < 0) {
+ log_fn(LOG_WARN,"connection_edge_send_command failed. Returning.");
+ return; /* the circuit's closed, don't continue */
}
}
}
@@ -569,8 +561,9 @@
log_fn(LOG_DEBUG,"Sending relay cell to begin stream %d.",*(int *)ap_conn->stream_id);
- connection_edge_send_command(ap_conn, circ, RELAY_COMMAND_BEGIN,
- payload, payload_len, ap_conn->cpath_layer);
+ if(connection_edge_send_command(ap_conn, circ, RELAY_COMMAND_BEGIN,
+ payload, payload_len, ap_conn->cpath_layer) < 0)
+ return 0; /* circuit is closed, don't continue */
ap_conn->package_window = STREAMWINDOW_START;
ap_conn->deliver_window = STREAMWINDOW_START;
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -d -r1.172 -r1.173
--- or.h 22 Oct 2003 07:55:44 -0000 1.172
+++ or.h 22 Oct 2003 09:08:10 -0000 1.173
@@ -592,8 +592,8 @@
int connection_edge_process_inbuf(connection_t *conn);
void connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer);
-void connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int relay_command,
- void *payload, int payload_len, crypt_path_t *cpath_layer);
+int connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int relay_command,
+ void *payload, int payload_len, crypt_path_t *cpath_layer);
int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection_t *conn,
int edge_type, crypt_path_t *layer_hint);