mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Make buffers.c independent of or.h
Also, put ext_or function in new module; it had accidentally gotten into proto_socks.c
This commit is contained in:
parent
f28e314b0d
commit
5921b465e7
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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>. */
|
||||
|
@ -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 \
|
||||
|
14
src/or/or.h
14
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. */
|
||||
|
40
src/or/proto_ext_or.c
Normal file
40
src/or/proto_ext_or.c
Normal file
@ -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;
|
||||
}
|
||||
|
17
src/or/proto_ext_or.h
Normal file
17
src/or/proto_ext_or.h
Normal file
@ -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
|
||||
|
@ -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>.
|
||||
*/
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "buffers.h"
|
||||
#include "ext_orport.h"
|
||||
#include "proto_cell.h"
|
||||
#include "proto_ext_or.h"
|
||||
#include "proto_http.h"
|
||||
#include "proto_control0.h"
|
||||
#include "proto_socks.h"
|
||||
|
Loading…
Reference in New Issue
Block a user