aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
Diffstat (limited to 'src/or')
-rw-r--r--src/or/Makefile.am4
-rw-r--r--src/or/buffers.c124
-rw-r--r--src/or/connection.c88
-rw-r--r--src/or/connection_edge.c14
-rw-r--r--src/or/or.h42
-rw-r--r--src/or/test.c72
6 files changed, 3 insertions, 341 deletions
diff --git a/src/or/Makefile.am b/src/or/Makefile.am
index 9c937ae0a..4eed574c9 100644
--- a/src/or/Makefile.am
+++ b/src/or/Makefile.am
@@ -9,14 +9,14 @@ or_SOURCES = buffers.c circuit.c command.c connection.c \
onion.c routers.c directory.c dns.c connection_edge.c \
main.c tor_main.c
-or_LDADD = ../common/libor.a -lz
+or_LDADD = ../common/libor.a
test_SOURCES = buffers.c circuit.c command.c connection.c \
connection_exit.c connection_ap.c connection_or.c config.c \
onion.c routers.c directory.c dns.c connection_edge.c \
main.c test.c
-test_LDADD = ../common/libor.a -lz
+test_LDADD = ../common/libor.a
noinst_HEADERS = or.h tree.h
diff --git a/src/or/buffers.c b/src/or/buffers.c
index ec0022f14..1bac63e26 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -76,7 +76,6 @@ int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, i
// log(LOG_DEBUG,"read_to_buf(): Read %d bytes. %d on inbuf.",read_result, *buf_datalen);
return read_result;
}
-
}
int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen) {
@@ -131,129 +130,6 @@ int write_to_buf(char *string, int string_len,
*buf_datalen += string_len;
// log(LOG_DEBUG,"write_to_buf(): added %d bytes to buf (now %d total).",string_len, *buf_datalen);
return *buf_datalen;
-
-}
-
-z_stream *zstream_new(int compression)
-{
- z_stream* stream;
- stream = tor_malloc(sizeof(z_stream));
- memset(stream, 0, sizeof(z_stream));
- if (compression) {
- if (deflateInit(stream, Z_DEFAULT_COMPRESSION) != Z_OK) {
- log(LOG_ERR, "Error initializing zlib: %s", stream->msg);
- free(stream);
- return NULL;
- }
- } else {
- if (inflateInit(stream) != Z_OK) {
- log(LOG_ERR, "Error initializing zlib: %s", stream->msg);
- free(stream);
- return NULL;
- }
- }
- return stream;
-}
-
-z_compression *compression_new()
-{
- return (z_compression *) zstream_new(1);
-}
-
-z_decompression *decompression_new()
-{
- return (z_compression *) zstream_new(0);
-}
-
-void compression_free(z_stream *stream)
-{
- int r;
- r = deflateEnd(stream);
- if (r != Z_OK)
- log(LOG_ERR, "while closing compression: %d (%s)", r, stream->msg);
- free(stream);
-}
-
-void decompression_free(z_stream *stream)
-{
- int r;
- r = inflateEnd(stream);
- if (r != Z_OK)
- log(LOG_ERR, "while closing decompression: %d (%s)", r, stream->msg);
- free(stream);
-}
-
-int compress_from_buf(char *string, int string_len,
- char **buf_in, int *buflen_in, int *buf_datalen_in,
- z_stream *zstream, int flush) {
- int err;
-
- if (!*buf_datalen_in)
- return 0;
-
- zstream->next_in = *buf_in;
- zstream->avail_in = *buf_datalen_in;
- zstream->next_out = string;
- zstream->avail_out = string_len;
-
- err = deflate(zstream, flush);
-
- switch (err)
- {
- case Z_OK:
- case Z_STREAM_END:
- log(LOG_DEBUG, "Compressed (%d/%d); filled (%d/%d).",
- *buf_datalen_in-zstream->avail_in, *buf_datalen_in,
- string_len-zstream->avail_out, string_len);
- memmove(*buf_in, zstream->next_in, zstream->avail_in);
- *buf_datalen_in = zstream->avail_in;
- return string_len - zstream->avail_out;
- case Z_STREAM_ERROR:
- case Z_BUF_ERROR:
- log(LOG_ERR, "Error processing compression: %s", zstream->msg);
- return -1;
- default:
- log(LOG_ERR, "Unknown return value from deflate: %d", err);
- return -1;
- }
-}
-
-int decompress_buf_to_buf(char **buf_in, int *buflen_in, int *buf_datalen_in,
- char **buf_out, int *buflen_out, int *buf_datalen_out,
- z_stream *zstream, int flush)
-{
- int err;
-
- zstream->next_in = *buf_in;
- zstream->avail_in = *buf_datalen_in;
- zstream->next_out = *buf_out + *buf_datalen_out;
- zstream->avail_out = *buflen_out - *buf_datalen_out;
-
- if (!zstream->avail_in && !zstream->avail_out)
- return 0;
-
- err = inflate(zstream, flush);
-
- switch (err)
- {
- case Z_OK:
- case Z_STREAM_END:
- log(LOG_DEBUG, "Uncompressed (%d/%d); filled (%d/%d)",
- *buf_datalen_in-zstream->avail_in, *buf_datalen_in,
- (*buflen_out-*buf_datalen_out)-zstream->avail_out,
- (*buflen_out-*buf_datalen_out) );
- memmove(*buf_in, zstream->next_in, zstream->avail_in);
- *buf_datalen_in = zstream->avail_in;
- *buf_datalen_out = *buflen_out - zstream->avail_out;
- return 1;
- case Z_STREAM_ERROR:
- case Z_BUF_ERROR:
- log(LOG_ERR, "Error processing compression: %s", zstream->msg);
- return 1;
- default:
- log(LOG_ERR, "Unknown return value from deflate: %d", err);
- return -1;
- }
}
int fetch_from_buf(char *string, int string_len,
diff --git a/src/or/connection.c b/src/or/connection.c
index 665357e8f..26ee19527 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -98,18 +98,6 @@ connection_t *connection_new(int type) {
return NULL;
}
}
-#ifdef USE_ZLIB
- if (type == CONN_TYPE_AP || type == CONN_TYPE_EXIT) {
- if (buf_new(&conn->z_outbuf, &conn->z_outbuflen, &conn->z_outbuf_datalen) < 0)
- return NULL;
- if (! (conn->compression = compression_new()))
- return NULL;
- if (! (conn->decompression = decompression_new()))
- return NULL;
- } else {
- conn->compression = conn->decompression = NULL;
- }
-#endif
conn->done_sending = conn->done_receiving = 0;
return conn;
}
@@ -141,13 +129,6 @@ void connection_free(connection_t *conn) {
if(conn->type == CONN_TYPE_OR) {
directory_set_dirty();
}
-#ifdef USE_ZLIB
- if (conn->compression) {
- decompression_free(conn->decompression);
- compression_free(conn->compression);
- buf_free(conn->z_outbuf);
- }
-#endif
free(conn);
}
@@ -322,58 +303,6 @@ int connection_fetch_from_buf(char *string, int len, connection_t *conn) {
return fetch_from_buf(string, len, &conn->inbuf, &conn->inbuflen, &conn->inbuf_datalen);
}
-#ifdef USE_ZLIB
-int connection_compress_from_buf(char *string, int len, connection_t *conn,
- int flush) {
- return compress_from_buf(string, len,
- &conn->inbuf, &conn->inbuflen, &conn->inbuf_datalen,
- conn->compression, flush);
-}
-
-int connection_decompress_to_buf(char *string, int len, connection_t *conn,
- int flush) {
- int n;
- struct timeval now;
-
- assert(conn);
-
- if (len) {
- if (write_to_buf(string, len,
- &conn->z_outbuf, &conn->z_outbuflen, &conn->z_outbuf_datalen) < 0)
- return -1;
- }
-
- /* If we have more that 10 payloads worth of data waiting in outbuf,
- * don't uncompress any more; queue this data in z_outbuf.
- *
- * This check should may be different.
- */
- if (connection_outbuf_too_full(conn))
- return 0;
-
- n = decompress_buf_to_buf(
- &conn->z_outbuf, &conn->z_outbuflen, &conn->z_outbuf_datalen,
- &conn->outbuf, &conn->outbuflen, &conn->outbuf_datalen,
- conn->decompression, flush);
-
- if (n < 0)
- return -1;
-
- my_gettimeofday(&now,NULL);
-
- if(!n)
- return 0;
-
- if(conn->marked_for_close)
- return 0;
-
- conn->timestamp_lastwritten = now.tv_sec;
- conn->outbuf_flushlen += n;
-
- return n;
-}
-#endif
-
int connection_find_on_inbuf(char *string, int len, connection_t *conn) {
return find_on_inbuf(string, len, conn->inbuf, conn->inbuf_datalen);
}
@@ -625,7 +554,7 @@ int connection_process_inbuf(connection_t *conn) {
}
int connection_package_raw_inbuf(connection_t *conn) {
- int amount_to_process, len;
+ int amount_to_process;
cell_t cell;
circuit_t *circ;
@@ -643,20 +572,6 @@ repeat_connection_package_raw_inbuf:
/* Initialize the cell with 0's */
memset(&cell, 0, sizeof(cell_t));
-#ifdef USE_ZLIB
- /* This compression logic is not necessarily optimal:
- * 1) Maybe we should try to read as much as we can onto the inbuf before
- * compressing.
- * 2)
- */
- len = connection_compress_from_buf(cell.payload+RELAY_HEADER_SIZE,
- CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE,
- conn, Z_SYNC_FLUSH);
- if (len < 0)
- return -1;
-
- cell.length = len;
-#else
if(amount_to_process > CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE) {
cell.length = CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE;
} else {
@@ -666,7 +581,6 @@ repeat_connection_package_raw_inbuf:
if(connection_fetch_from_buf(cell.payload+RELAY_HEADER_SIZE,
cell.length, conn) < 0)
return -1;
-#endif
circ = circuit_get_by_conn(conn);
if(!circ) {
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index ea5ae61ac..166ed4f83 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -156,21 +156,11 @@ int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection
return -1; /* somebody's breaking protocol. kill the whole circuit. */
}
-#ifdef USE_ZLIB
- if(connection_decompress_to_buf(cell->payload + RELAY_HEADER_SIZE,
- cell->length - RELAY_HEADER_SIZE,
- conn, Z_SYNC_FLUSH) < 0) {
- log(LOG_INFO,"connection_edge_process_relay_cell(): write to buf failed. Marking for close.");
- conn->marked_for_close = 1;
- return 0;
- }
-#else
if(connection_write_to_buf(cell->payload + RELAY_HEADER_SIZE,
cell->length - RELAY_HEADER_SIZE, conn) < 0) {
conn->marked_for_close = 1;
return 0;
}
-#endif
if(connection_consider_sending_sendme(conn, edge_type) < 0)
conn->marked_for_close = 1;
return 0;
@@ -296,10 +286,6 @@ int connection_edge_finished_flushing(connection_t *conn) {
case AP_CONN_STATE_OPEN:
case EXIT_CONN_STATE_OPEN:
connection_stop_writing(conn);
-#ifdef USE_ZLIB
- if (connection_decompress_to_buf(NULL, 0, conn, Z_SYNC_FLUSH) < 0)
- return 0;
-#endif
return connection_consider_sending_sendme(conn, conn->type);
default:
log(LOG_DEBUG,"Bug: connection_edge_finished_flushing() called in unexpected state.");
diff --git a/src/or/or.h b/src/or/or.h
index e69eb52e0..80392bcf1 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -37,11 +37,6 @@
#include <assert.h>
#include <time.h>
-#define free_func zlib_free_func
-#include <zlib.h>
-#undef free_func
-
-
#include "../common/crypto.h"
#include "../common/log.h"
#include "../common/ss.h"
@@ -167,9 +162,6 @@
/* legal characters in a filename */
#define CONFIG_LEGAL_FILENAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/"
-typedef z_stream z_compression;
-typedef z_stream z_decompression;
-
struct config_line {
char *key;
char *value;
@@ -259,14 +251,6 @@ struct connection_t {
int deliver_window;
int done_sending;
int done_receiving;
-#ifdef USE_ZLIB
- char *z_outbuf;
- int z_outbuflen;
- int z_outbuf_datalen;
-
- z_stream *compression;
- z_stream *decompression;
-#endif
/* Used by ap: */
char socks_version;
@@ -441,25 +425,6 @@ int fetch_from_buf(char *string, int string_len,
* then memmove buf back (that is, remove them from buf)
*/
-z_compression* compression_new();
-z_decompression* decompression_new();
-void compression_free(z_compression *);
-void decompression_free(z_decompression *);
-
-int compress_from_buf(char *string, int string_len,
- char **buf_in, int *buflen_in, int *buf_datalen_in,
- z_compression *compression, int flush);
- /* read and compress as many characters as possible from buf, writing up to
- * string_len of them onto string, then memmove buf back. Return number of
- * characters written.
- */
-
-int decompress_buf_to_buf(char **buf_in, int *buflen_in, int *buf_datalen_in,
- char **buf_out, int *buflen_out, int *buf_datalen_out,
- z_decompression *decompression, int flush);
- /* XXX document this NM
- */
-
int find_on_inbuf(char *string, int string_len,
char *buf, int buf_datalen);
/* find first instance of needle 'string' on haystack 'buf'. return how
@@ -571,13 +536,6 @@ int connection_read_to_buf(connection_t *conn);
int connection_fetch_from_buf(char *string, int len, connection_t *conn);
-#ifdef USE_ZLIB
-int connection_compress_from_buf(char *string, int len, connection_t *conn,
- int flush);
-int connection_decompress_to_buf(char *string, int len, connection_t *conn,
- int flush);
-#endif
-
int connection_outbuf_too_full(connection_t *conn);
int connection_find_on_inbuf(char *string, int len, connection_t *conn);
int connection_wants_to_flush(connection_t *conn);
diff --git a/src/or/test.c b/src/or/test.c
index e337deb60..bde058ffd 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -24,12 +24,7 @@ test_buffers() {
char *buf;
int buflen, buf_datalen;
- char *buf2;
- int buf2len, buf2_datalen;
-
int s, i, j, eof;
- z_compression *comp;
- z_decompression *decomp;
/****
* buf_new
@@ -159,74 +154,7 @@ test_buffers() {
****/
/* XXXX Needs tests. */
-
- /***
- * compress_from_buf (simple)
- ***/
- buf_datalen = 0;
- comp = compression_new();
- for (i = 0; i < 20; ++i) {
- write_to_buf("Hello world. ", 14, &buf, &buflen, &buf_datalen);
- }
- i = compress_from_buf(str, 256, &buf, &buflen, &buf_datalen, comp,
- Z_SYNC_FLUSH);
- test_eq(buf_datalen, 0);
- /*
- for (j = 0; j <i ; ++j) {
- printf("%x '%c'\n", ((int) str[j])&0xff, str[j]);
- }
- */
- /* Now try decompressing. */
- decomp = decompression_new();
- if (buf_new(&buf2, &buf2len, &buf2_datalen))
- test_fail();
- buf_datalen = 0;
- test_eq(i, write_to_buf(str, i, &buf, &buflen, &buf_datalen));
- j = decompress_buf_to_buf(&buf, &buflen, &buf_datalen,
- &buf2, &buf2len, &buf2_datalen,
- decomp, Z_SYNC_FLUSH);
- test_eq(buf2_datalen, 14*20);
- for (i = 0; i < 20; ++i) {
- test_memeq(buf2+(14*i), "Hello world. ", 14);
- }
-
- /* Now compress more, into less room. */
- for (i = 0; i < 20; ++i) {
- write_to_buf("Hello wxrlx. ", 14, &buf, &buflen, &buf_datalen);
- }
- i = compress_from_buf(str, 8, &buf, &buflen, &buf_datalen, comp,
- Z_SYNC_FLUSH);
- test_eq(buf_datalen, 0);
- test_eq(i, 8);
- memset(str+8,0,248);
- j = compress_from_buf(str+8, 248, &buf, &buflen, &buf_datalen, comp,
- Z_SYNC_FLUSH);
- /* test_eq(j, 2); XXXX This breaks, see below. */
-
- buf2_datalen=buf_datalen=0;
- write_to_buf(str, i+j, &buf, &buflen, &buf_datalen);
- memset(buf2, 0, buf2len);
- j = decompress_buf_to_buf(&buf, &buflen, &buf_datalen,
- &buf2, &buf2len, &buf2_datalen,
- decomp, Z_SYNC_FLUSH);
- test_eq(buf2_datalen, 14*20);
- for (i = 0; i < 20; ++i) {
- test_memeq(buf2+(14*i), "Hello wxrlx. ", 14);
- }
-
- /* This situation is a bit messy. We need to refactor our use of
- * zlib until the above code works. Here's the problem: The zlib
- * documentation claims that we should reinvoke deflate immediately
- * when the outbuf buffer is full and we get Z_OK, without adjusting
- * the input at all. This implies that we need to tie a buffer to a
- * compression or decompression object.
- */
-
- compression_free(comp);
- decompression_free(decomp);
-
buf_free(buf);
- buf_free(buf2);
}
void