aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2002-10-03 02:17:41 +0000
committerRoger Dingledine <arma@torproject.org>2002-10-03 02:17:41 +0000
commit74787aa2d4845501b5ccd72dec46eaaa4c45a664 (patch)
tree8be0eeb5be7c874bf9f3ef83a5cc6650fe0c4a06 /src
parentbf53852a002f3a0b323ebf67354f2d7a1e4039e6 (diff)
downloadtor-74787aa2d4845501b5ccd72dec46eaaa4c45a664.tar
tor-74787aa2d4845501b5ccd72dec46eaaa4c45a664.tar.gz
cell.c is now obsolete
svn:r133
Diffstat (limited to 'src')
-rw-r--r--src/or/Makefile.am2
-rw-r--r--src/or/cell.c100
-rw-r--r--src/or/command.c69
-rw-r--r--src/or/config.c5
4 files changed, 50 insertions, 126 deletions
diff --git a/src/or/Makefile.am b/src/or/Makefile.am
index 44127d873..8fdd4e4d8 100644
--- a/src/or/Makefile.am
+++ b/src/or/Makefile.am
@@ -7,7 +7,7 @@ bin_PROGRAMS = or
or_LDADD = -L../common -lor
-or_SOURCES = buffers.c cell.c circuit.c command.c connection.c \
+or_SOURCES = buffers.c circuit.c command.c connection.c \
connection_exit.c connection_ap.c connection_op.c connection_or.c config.c \
main.c onion.c routers.c directory.c
diff --git a/src/or/cell.c b/src/or/cell.c
deleted file mode 100644
index 3b457fcca..000000000
--- a/src/or/cell.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
-/* See LICENSE for licensing information */
-/* $Id$ */
-
-#include "or.h"
-
-static cell_t *new_create_cell(uint16_t aci, unsigned char length, unsigned char *buf)
-{
- cell_t *c = NULL;
- int retval;
-
- if ((aci) && (buf) && (length <= CELL_PAYLOAD_SIZE)) /* valid parameters */
- {
- c = (cell_t *)malloc(sizeof(cell_t));
- if (!c) /* malloc() error */
- return NULL;
-
- c->command = CELL_CREATE;
- c->aci = aci;
- c->length = length;
- c->seq = 0;
-
- memcpy((void *)c->payload, (void *)buf, length);
- retval = crypto_pseudo_rand(CELL_PAYLOAD_SIZE-length, (unsigned char *)(c->payload+length));
- if (retval) /* RAND_pseudo_bytes() error */
- {
- free((void *)c);
- return NULL;
- } /* RAND_pseudo_bytes() error */
-
- return c;
- } /* valid parameters */
- else /* invalid parameters */
- return NULL;
-}
-
-int pack_create(uint16_t aci, unsigned char *onion, uint32_t onionlen, unsigned char **cellbuf, unsigned int *cellbuflen)
-{
- cell_t *c;
- unsigned char *buf;
- unsigned int buflen;
- unsigned int cells;
- unsigned int dataleft;
- unsigned int i;
-
- assert(aci && onion && onionlen && cellbuf && cellbuflen);
-
- /* copy the onion into a buffer, prepend with onion length */
- buflen = onionlen+4;
- buf = (unsigned char *)malloc(buflen);
- if (!buf) /* malloc() error */
- return -1;
-
- log(LOG_DEBUG,"pack_create() : Setting onion length to %u.",onionlen);
- *(uint32_t*)buf = htonl(onionlen);
- memcpy((void *)(buf+4),(void *)onion,onionlen);
-
- /* calculate number of cells required */
- if (buflen%CELL_PAYLOAD_SIZE == 0)
- cells = buflen/CELL_PAYLOAD_SIZE;
- else
- cells = buflen/CELL_PAYLOAD_SIZE+1;
-
- /* allocate memory for the cells */
- *cellbuflen = cells * sizeof(cell_t);
- *cellbuf = malloc(*cellbuflen);
- if (!*cellbuf) /* malloc() error */
- return -1;
-
- log(LOG_DEBUG,"pack_create() : Allocated memory for %u cells.",cells);
-
- /* create cells one by one */
- dataleft = buflen;
- for(i=0; i<cells; i++)
- {
- log(LOG_DEBUG,"pack_create() : Packing %u bytes of data.",dataleft);
- if (dataleft >= CELL_PAYLOAD_SIZE)
- {
- c = new_create_cell(aci,CELL_PAYLOAD_SIZE,buf+i*CELL_PAYLOAD_SIZE);
- dataleft -= CELL_PAYLOAD_SIZE;
- }
- else
- c = new_create_cell(aci,dataleft,buf+i*CELL_PAYLOAD_SIZE);
-
- if (!c) /* cell creation failed */
- {
- free((void *)*cellbuf);
- return -1;
- } /* cell creation failed */
-
- log(LOG_DEBUG,"pack_create() : new_create_cell succeeded; copying the cell into output buffer");
- /* cell has been created, now copy into buffer */
- memcpy((void *)(*cellbuf+i*sizeof(cell_t)),(void *)c,sizeof(cell_t));
- free((void *)c);
- }
-
- free(buf);
- return 0;
-}
-
diff --git a/src/or/command.c b/src/or/command.c
index bbcb6d23f..43474bf87 100644
--- a/src/or/command.c
+++ b/src/or/command.c
@@ -31,13 +31,50 @@ void command_process_cell(cell_t *cell, connection_t *conn) {
}
}
+/* helper function for command_process_create_cell */
+static int deliver_onion_to_conn(aci_t aci, unsigned char *onion, uint32_t onionlen, connection_t *conn) {
+ char *buf;
+ int buflen, dataleft;
+ cell_t cell;
+
+ assert(aci && onion && onionlen);
+
+ buflen = onionlen+4;
+ buf = malloc(buflen);
+ if(!buf)
+ return -1;
+
+ log(LOG_DEBUG,"deliver_onion_to_conn(): Setting onion length to %u.",onionlen);
+ *(uint32_t*)buf = htonl(onionlen);
+ memcpy((void *)(buf+4),(void *)onion,onionlen);
+
+ dataleft = buflen;
+ while(dataleft > 0) {
+ memset(&cell,0,sizeof(cell_t));
+ cell.command = CELL_CREATE;
+ cell.aci = aci;
+ if(dataleft >= CELL_PAYLOAD_SIZE)
+ cell.length = CELL_PAYLOAD_SIZE;
+ else
+ cell.length = dataleft;
+ memcpy(cell.payload, buf+buflen-dataleft, cell.length);
+ dataleft -= cell.length;
+
+ log(LOG_DEBUG,"deliver_onion_to_conn(): Delivering create cell, payload %d bytes.",cell.length);
+ if(connection_write_cell_to_buf(&cell, conn) < 0) {
+ log(LOG_DEBUG,"deliver_onion_to_conn(): Could not buffer new create cells. Closing.");
+ free(buf);
+ return -1;
+ }
+ }
+ free(buf);
+ return 0;
+}
+
void command_process_create_cell(cell_t *cell, connection_t *conn) {
circuit_t *circ;
connection_t *n_conn;
- unsigned char *cellbuf; /* array of cells */
- int cellbuflen; /* size of cellbuf in bytes */
- cell_t *tmpcell; /* pointer to an arbitrary cell */
- int retval, i;
+ int retval;
circ = circuit_get_by_aci_conn(cell->aci, conn);
@@ -122,30 +159,14 @@ void command_process_create_cell(cell_t *cell, connection_t *conn) {
pad_onion(circ->onion,circ->onionlen, sizeof(onion_layer_t));
log(LOG_DEBUG,"command_process_create_cell(): Padded the onion with random data.");
- retval = pack_create(circ->n_aci, circ->onion, circ->onionlen, &cellbuf, &cellbuflen);
+ retval = deliver_onion_to_conn(circ->n_aci, circ->onion, circ->onionlen, n_conn);
+// retval = pack_create(circ->n_aci, circ->onion, circ->onionlen, &cellbuf, &cellbuflen);
free((void *)circ->onion);
circ->onion = NULL;
- if (retval == -1) /* pack_create() error */
- {
- log(LOG_DEBUG,"command_process_create_cell(): Could not pack the onion into CREATE cells. Closing the connection.");
+ if (retval == -1) {
+ log(LOG_DEBUG,"command_process_create_cell(): Could not deliver the onion to next conn. Closing.");
circuit_close(circ);
- return;
- }
- log(LOG_DEBUG,"command_process_create_cell(): Onion packed into CREATE cells. Buffering the cells.");
- /* queue the create cells for transmission to the next hop */
- tmpcell = (cell_t *)cellbuf;
- for (i=0;i<cellbuflen/sizeof(cell_t);i++)
- {
- retval = connection_write_cell_to_buf(tmpcell, n_conn);
- if (retval == -1) /* buffering failed, drop the connection */
- {
- log(LOG_DEBUG,"command_process_create_cell(): Could not buffer new create cells. Closing.");
- circuit_close(circ);
- return;
- }
- tmpcell++;
}
- free((void *)cellbuf);
return;
} else { /* this is destined for an exit */
diff --git a/src/or/config.c b/src/or/config.c
index af0fab8a6..37811f37a 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -10,7 +10,10 @@
*/
#include "or.h"
-#include <string.h>
+
+#ifndef POPT_TABLEEND /* handle popt 1.6 before 1.6.2 */
+#define POPT_TABLEEND { NULL, '\0', 0, 0, 0, NULL, NULL }
+#endif
const char *
basename(const char *filename)