diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-08-08 12:23:39 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-09-05 13:57:51 -0400 |
commit | 5921b465e7764d35b3f128cf0cf096eca3226688 (patch) | |
tree | 51f77fb0284b14bad8121043b00582e050b581c0 /src/or | |
parent | f28e314b0d5a6d4c677b87378cea70dc6524546b (diff) | |
download | tor-5921b465e7764d35b3f128cf0cf096eca3226688.tar.gz tor-5921b465e7764d35b3f128cf0cf096eca3226688.zip |
Make buffers.c independent of or.h
Also, put ext_or function in new module; it had accidentally gotten
into proto_socks.c
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/buffers.c | 8 | ||||
-rw-r--r-- | src/or/buffers.h | 18 | ||||
-rw-r--r-- | src/or/ext_orport.c | 3 | ||||
-rw-r--r-- | src/or/include.am | 2 | ||||
-rw-r--r-- | src/or/or.h | 14 | ||||
-rw-r--r-- | src/or/proto_ext_or.c | 40 | ||||
-rw-r--r-- | src/or/proto_ext_or.h | 17 | ||||
-rw-r--r-- | src/or/proto_socks.c | 29 |
8 files changed, 88 insertions, 43 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 18517b999f..ee888b42a4 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -17,11 +17,17 @@ * and drained from functions in connection.c, trigged by events that are * monitored in main.c. **/ + #define BUFFERS_PRIVATE -#include "or.h" +#include "orconfig.h" +#include <stddef.h> #include "buffers.h" +#include "compat.h" +#include "compress.h" #include "util.h" +#include "torint.h" #include "torlog.h" +#include "tortls.h" #ifdef HAVE_UNISTD_H #include <unistd.h> #endif diff --git a/src/or/buffers.h b/src/or/buffers.h index e710ac64a4..35fa46593b 100644 --- a/src/or/buffers.h +++ b/src/or/buffers.h @@ -12,8 +12,17 @@ #ifndef TOR_BUFFERS_H #define TOR_BUFFERS_H +#include "compat.h" +#include "compat.h" +#include "torint.h" #include "testsupport.h" +typedef struct buf_t buf_t; + +struct tor_tls_t; +struct tor_compress_state_t; +struct ext_or_cmd_t; + buf_t *buf_new(void); buf_t *buf_new_with_capacity(size_t size); size_t buf_get_default_chunk_size(const buf_t *buf); @@ -30,13 +39,14 @@ size_t buf_get_total_allocation(void); int read_to_buf(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof, int *socket_error); -int read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf); +int read_to_buf_tls(struct tor_tls_t *tls, size_t at_most, buf_t *buf); int flush_buf(tor_socket_t s, buf_t *buf, size_t sz, size_t *buf_flushlen); -int flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen); +int flush_buf_tls(struct tor_tls_t *tls, buf_t *buf, size_t sz, + size_t *buf_flushlen); int write_to_buf(const char *string, size_t string_len, buf_t *buf); -int write_to_buf_compress(buf_t *buf, tor_compress_state_t *state, +int write_to_buf_compress(buf_t *buf, struct tor_compress_state_t *state, const char *data, size_t data_len, int done); int move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen); void peek_from_buf(char *string, size_t string_len, const buf_t *buf); @@ -47,8 +57,6 @@ int fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len); #define PEEK_BUF_STARTSWITH_MAX 16 int peek_buf_startswith(const buf_t *buf, const char *cmd); -int fetch_ext_or_command_from_buf(buf_t *buf, ext_or_cmd_t **out); - int buf_set_to_copy(buf_t **output, const buf_t *input); diff --git a/src/or/ext_orport.c b/src/or/ext_orport.c index 01dc06ce13..83dc13ecfe 100644 --- a/src/or/ext_orport.c +++ b/src/or/ext_orport.c @@ -23,8 +23,9 @@ #include "ext_orport.h" #include "control.h" #include "config.h" -#include "util.h" #include "main.h" +#include "proto_ext_or.h" +#include "util.h" /** Allocate and return a structure capable of holding an Extended * ORPort message of body length <b>len</b>. */ diff --git a/src/or/include.am b/src/or/include.am index caea04197b..fe860339fa 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -81,6 +81,7 @@ LIBTOR_A_SOURCES = \ src/or/protover.c \ src/or/proto_cell.c \ src/or/proto_control0.c \ + src/or/proto_ext_or.c \ src/or/proto_http.c \ src/or/proto_socks.c \ src/or/policies.c \ @@ -221,6 +222,7 @@ ORHEADERS = \ src/or/protover.h \ src/or/proto_cell.h \ src/or/proto_control0.h \ + src/or/proto_ext_or.h \ src/or/proto_http.h \ src/or/proto_socks.h \ src/or/reasons.h \ diff --git a/src/or/or.h b/src/or/or.h index 5d55094a02..11d3bb31cc 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1179,11 +1179,8 @@ typedef struct { uint16_t length; /**< How long is the payload body? */ } relay_header_t; -typedef struct buf_t buf_t; typedef struct socks_request_t socks_request_t; -#define buf_t buf_t - typedef struct entry_port_cfg_t { /* Client port types (socks, dns, trans, natd) only: */ uint8_t isolation_flags; /**< Zero or more isolation flags */ @@ -1243,6 +1240,8 @@ typedef struct server_port_cfg_t { #define CONTROL_CONNECTION_MAGIC 0x8abc765du #define LISTENER_CONNECTION_MAGIC 0x1a1ac741u +struct buf_t; + /** Description of a connection to another host or process, and associated * data. * @@ -1314,8 +1313,9 @@ typedef struct connection_t { struct event *read_event; /**< Libevent event structure. */ struct event *write_event; /**< Libevent event structure. */ - buf_t *inbuf; /**< Buffer holding data read over this connection. */ - buf_t *outbuf; /**< Buffer holding data to write over this connection. */ + struct buf_t *inbuf; /**< Buffer holding data read over this connection. */ + struct buf_t *outbuf; /**< Buffer holding data to write over this + * connection. */ size_t outbuf_flushlen; /**< How much data should we try to flush from the * outbuf? */ time_t timestamp_lastread; /**< When was the last time libevent said we could @@ -1722,11 +1722,11 @@ typedef struct entry_connection_t { /** For AP connections only: buffer for data that we have sent * optimistically, which we might need to re-send if we have to * retry this connection. */ - buf_t *pending_optimistic_data; + struct buf_t *pending_optimistic_data; /* For AP connections only: buffer for data that we previously sent * optimistically which we are currently re-sending as we retry this * connection. */ - buf_t *sending_optimistic_data; + struct buf_t *sending_optimistic_data; /** If this is a DNSPort connection, this field holds the pending DNS * request that we're going to try to answer. */ diff --git a/src/or/proto_ext_or.c b/src/or/proto_ext_or.c new file mode 100644 index 0000000000..d7f8cab1bd --- /dev/null +++ b/src/or/proto_ext_or.c @@ -0,0 +1,40 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "or.h" +#include "buffers.h" +#include "ext_orport.h" +#include "proto_ext_or.h" + +/** The size of the header of an Extended ORPort message: 2 bytes for + * COMMAND, 2 bytes for BODYLEN */ +#define EXT_OR_CMD_HEADER_SIZE 4 + +/** Read <b>buf</b>, which should contain an Extended ORPort message + * from a transport proxy. If well-formed, create and populate + * <b>out</b> with the Extended ORport message. Return 0 if the + * buffer was incomplete, 1 if it was well-formed and -1 if we + * encountered an error while parsing it. */ +int +fetch_ext_or_command_from_buf(buf_t *buf, ext_or_cmd_t **out) +{ + char hdr[EXT_OR_CMD_HEADER_SIZE]; + uint16_t len; + + if (buf_datalen(buf) < EXT_OR_CMD_HEADER_SIZE) + return 0; + peek_from_buf(hdr, sizeof(hdr), buf); + len = ntohs(get_uint16(hdr+2)); + if (buf_datalen(buf) < (unsigned)len + EXT_OR_CMD_HEADER_SIZE) + return 0; + *out = ext_or_cmd_new(len); + (*out)->cmd = ntohs(get_uint16(hdr)); + (*out)->len = len; + buf_remove_from_front(buf, EXT_OR_CMD_HEADER_SIZE); + fetch_from_buf((*out)->body, len, buf); + return 1; +} + diff --git a/src/or/proto_ext_or.h b/src/or/proto_ext_or.h new file mode 100644 index 0000000000..2ef185356c --- /dev/null +++ b/src/or/proto_ext_or.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#ifndef TOR_PROTO_EXT_OR_H +#define TOR_PROTO_EXT_OR_H + +struct buf_t; +struct ext_or_cmt_t; + +int fetch_ext_or_command_from_buf(struct buf_t *buf, + struct ext_or_cmd_t **out); + +#endif + diff --git a/src/or/proto_socks.c b/src/or/proto_socks.c index 7c7431caea..f153658bb0 100644 --- a/src/or/proto_socks.c +++ b/src/or/proto_socks.c @@ -140,35 +140,6 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, return res; } -/** The size of the header of an Extended ORPort message: 2 bytes for - * COMMAND, 2 bytes for BODYLEN */ -#define EXT_OR_CMD_HEADER_SIZE 4 - -/** Read <b>buf</b>, which should contain an Extended ORPort message - * from a transport proxy. If well-formed, create and populate - * <b>out</b> with the Extended ORport message. Return 0 if the - * buffer was incomplete, 1 if it was well-formed and -1 if we - * encountered an error while parsing it. */ -int -fetch_ext_or_command_from_buf(buf_t *buf, ext_or_cmd_t **out) -{ - char hdr[EXT_OR_CMD_HEADER_SIZE]; - uint16_t len; - - if (buf_datalen(buf) < EXT_OR_CMD_HEADER_SIZE) - return 0; - peek_from_buf(hdr, sizeof(hdr), buf); - len = ntohs(get_uint16(hdr+2)); - if (buf_datalen(buf) < (unsigned)len + EXT_OR_CMD_HEADER_SIZE) - return 0; - *out = ext_or_cmd_new(len); - (*out)->cmd = ntohs(get_uint16(hdr)); - (*out)->len = len; - buf_remove_from_front(buf, EXT_OR_CMD_HEADER_SIZE); - fetch_from_buf((*out)->body, len, buf); - return 1; -} - /** Create a SOCKS5 reply message with <b>reason</b> in its REP field and * have Tor send it as error response to <b>req</b>. */ |