mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
cell.c is now obsolete
svn:r133
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
|
||||
-100
@@ -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;
|
||||
}
|
||||
|
||||
+45
-24
@@ -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 */
|
||||
|
||||
+4
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user