diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-01-19 22:47:48 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-01-19 22:47:48 +0000 |
commit | 1eddb28f82c7b8a23b9552e8bbd460a485d0341e (patch) | |
tree | fab016ce6b73bbdac04b5a799fd18dba00914822 /src/or/directory.c | |
parent | 69fa5be7b624fcda98c7d2e7e8f678f8ee592404 (diff) | |
download | tor-1eddb28f82c7b8a23b9552e8bbd460a485d0341e.tar.gz tor-1eddb28f82c7b8a23b9552e8bbd460a485d0341e.zip |
Add unittests for compression detection. Make all rendezvous descriptors "plausible".
svn:r3375
Diffstat (limited to 'src/or/directory.c')
-rw-r--r-- | src/or/directory.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index 881c85e20a..4aedbf8b6f 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -48,7 +48,7 @@ directory_send_command(connection_t *conn, const char *platform, int purpose, const char *resource, const char *payload, size_t payload_len); static int directory_handle_command(connection_t *conn); -static int body_is_plausible(const char *body, size_t body_len); +static int body_is_plausible(const char *body, size_t body_len, int purpose); /********* START VARIABLES **********/ @@ -552,21 +552,25 @@ parse_http_response(const char *headers, int *code, time_t *date, * running-list or directory opening. This is a sign of possible compression. **/ static int -body_is_plausible(const char *body, size_t len) +body_is_plausible(const char *body, size_t len, int purpose) { int i; if (len < 32) return 0; - if (!strcmpstart(body,"router") || - !strcmpstart(body,"signed-directory") || - !strcmpstart(body,"network-status") || - !strcmpstart(body,"running-routers")) + if (purpose != DIR_PURPOSE_FETCH_RENDDESC) { + if (!strcmpstart(body,"router") || + !strcmpstart(body,"signed-directory") || + !strcmpstart(body,"network-status") || + !strcmpstart(body,"running-routers")) + return 1; + for (i=0;i<32;++i) { + if (!isprint(body[i]) && !isspace(body[i])) + return 0; + } + return 1; + } else { return 1; - for (i=0;i<32;++i) { - if (!isprint(body[i]) && !isspace(body[i])) - return 0; } - return 1; } /** We are a client, and we've finished reading the server's @@ -618,7 +622,7 @@ connection_dir_client_reached_eof(connection_t *conn) } } - plausible = body_is_plausible(body, body_len); + plausible = body_is_plausible(body, body_len, conn->purpose); if (compression || !plausible) { char *new_body = NULL; size_t new_len = 0; @@ -628,7 +632,7 @@ connection_dir_client_reached_eof(connection_t *conn) const char *description1, *description2; if (compression == ZLIB_METHOD) description1 = "as deflated"; - else if (compression = GZIP_METHOD) + else if (compression == GZIP_METHOD) description1 = "as gzipped"; else if (compression == 0) description1 = "as uncompressed"; |