aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c10
-rw-r--r--src/or/connection.c24
-rw-r--r--src/or/or.h6
3 files changed, 19 insertions, 21 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 1e1f76ce66..8654d54b53 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -147,7 +147,7 @@ static config_var_t _option_vars[] = {
VAR("ClientOnly", BOOL, ClientOnly, "0"),
VAR("ConnLimit", UINT, ConnLimit, "1000"),
VAR("ConstrainedSockets", BOOL, ConstrainedSockets, "0"),
- VAR("ConstrainedSockSize", UINT, ConstrainedSockSize, "8192"),
+ VAR("ConstrainedSockSize", MEMUNIT, ConstrainedSockSize, "8192"),
VAR("ContactInfo", STRING, ContactInfo, NULL),
VAR("ControlListenAddress",LINELIST, ControlListenAddress, NULL),
VAR("ControlPort", UINT, ControlPort, "0"),
@@ -2935,13 +2935,13 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->ConstrainedSockets) {
/* If the user wants to constrain socket buffer use, make sure the desired
* limit is between MIN|MAX_TCPSOCK_BUFFER in k increments. */
- if (options->ConstrainedSockSize < MIN_TCPSOCK_BUFFER ||
- options->ConstrainedSockSize > MAX_TCPSOCK_BUFFER ||
- options->ConstrainedSockSize % 1024 ) {
+ if (options->ConstrainedSockSize < MIN_CONSTRAINED_TCP_BUFFER ||
+ options->ConstrainedSockSize > MAX_CONSTRAINED_TCP_BUFFER ||
+ options->ConstrainedSockSize % 1024) {
r = tor_snprintf(buf, sizeof(buf),
"ConstrainedSockSize is invalid. Must be a value between %d and %d "
"in 1024 byte increments.",
- MIN_TCPSOCK_BUFFER, MAX_TCPSOCK_BUFFER);
+ MIN_CONSTRAINED_TCP_BUFFER, MAX_CONSTRAINED_TCP_BUFFER);
*msg = tor_strdup(r >= 0 ? buf : "internal error");
return -1;
}
diff --git a/src/or/connection.c b/src/or/connection.c
index e66a252674..4c555fc460 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -926,9 +926,8 @@ connection_handle_listener_read(connection_t *conn, int new_type)
set_socket_nonblocking(news);
- if (options->ConstrainedSockets) {
- set_constrained_socket_buffers (news, options->ConstrainedSockSize);
- }
+ if (options->ConstrainedSockets)
+ set_constrained_socket_buffers(news, (int)options->ConstrainedSockSize);
tor_assert(((struct sockaddr*)addrbuf)->sa_family == conn->socket_family);
@@ -1103,9 +1102,8 @@ connection_connect(connection_t *conn, const char *address,
set_socket_nonblocking(s);
- if (options->ConstrainedSockets) {
- set_constrained_socket_buffers (s, options->ConstrainedSockSize);
- }
+ if (options->ConstrainedSockets)
+ set_constrained_socket_buffers(s, (int)options->ConstrainedSockSize);
memset(&dest_addr,0,sizeof(dest_addr));
dest_addr.sin_family = AF_INET;
@@ -2561,17 +2559,17 @@ client_check_address_changed(int sock)
static void
set_constrained_socket_buffers(int sock, int size)
{
- if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (const char *)&size, sizeof(size)) < 0) {
+ void *sz = (void*)&size;
+ if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, sz, sizeof(size)) < 0) {
int e = tor_socket_errno(sock);
- log_warn(LD_NET, "setsockopt() to constrain send buffer to %d bytes failed: %s",
- size, tor_socket_strerror(e));
+ log_warn(LD_NET, "setsockopt() to constrain send "
+ "buffer to %d bytes failed: %s", size, tor_socket_strerror(e));
}
- if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (const char *)&size, sizeof(size)) < 0) {
+ if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, sz, sizeof(size)) < 0) {
int e = tor_socket_errno(sock);
- log_warn(LD_NET, "setsockopt() to constrain recv buffer to %d bytes failed: %s",
- size, tor_socket_strerror(e));
+ log_warn(LD_NET, "setsockopt() to constrain recv "
+ "buffer to %d bytes failed: %s", size, tor_socket_strerror(e));
}
- return;
}
/** Process new bytes that have arrived on conn-\>inbuf.
diff --git a/src/or/or.h b/src/or/or.h
index f97302152e..03b2d97e77 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1749,8 +1749,8 @@ typedef struct exit_redirect_t {
} exit_redirect_t;
/* limits for TCP send and recv buffer size used for constrained sockets */
-#define MIN_TCPSOCK_BUFFER 2048
-#define MAX_TCPSOCK_BUFFER 262144 /* 256k */
+#define MIN_CONSTRAINED_TCP_BUFFER 2048
+#define MAX_CONSTRAINED_TCP_BUFFER 262144 /* 256k */
/** A linked list of lines in a config file. */
typedef struct config_line_t {
@@ -1894,7 +1894,7 @@ typedef struct {
config_line_t *ReachableDirAddresses; /**< IP:ports for Dir conns. */
int ConstrainedSockets; /**< Shrink xmit and recv socket buffers. */
- int ConstrainedSockSize; /**< Size of constrained buffers. */
+ uint64_t ConstrainedSockSize; /**< Size of constrained buffers. */
/** Application ports that require all nodes in circ to have sufficient
* uptime. */