Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timeout parameter #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion redsocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static parser_entry redsocks_entries[] =
{ .key = "listenq", .type = pt_uint16 },
{ .key = "min_accept_backoff", .type = pt_uint16 },
{ .key = "max_accept_backoff", .type = pt_uint16 },
{ .key = "timeout", .type = pt_uint16 },
{ }
};

Expand Down Expand Up @@ -124,6 +125,7 @@ static int redsocks_onenter(parser_section *section)
instance->config.listenq = SOMAXCONN;
instance->config.min_backoff_ms = 100;
instance->config.max_backoff_ms = 60000;
instance->config.timeout = 0;

for (parser_entry *entry = &section->entries[0]; entry->key; entry++)
entry->addr =
Expand All @@ -137,6 +139,7 @@ static int redsocks_onenter(parser_section *section)
(strcmp(entry->key, "listenq") == 0) ? (void*)&instance->config.listenq :
(strcmp(entry->key, "min_accept_backoff") == 0) ? (void*)&instance->config.min_backoff_ms :
(strcmp(entry->key, "max_accept_backoff") == 0) ? (void*)&instance->config.max_backoff_ms :
(strcmp(entry->key, "timeout") == 0) ? (void*)&instance->config.timeout :
NULL;
section->data = instance;
return 0;
Expand Down Expand Up @@ -572,7 +575,14 @@ void redsocks_connect_relay(redsocks_client *client)
if (!client->relay) {
redsocks_log_errno(client, LOG_ERR, "red_connect_relay");
redsocks_drop_client(client);
}
}
else {
if (client->timeout > 0) {
redsocks_log_error(client, LOG_INFO, "settimeout");
bufferevent_settimeout(client->relay, client->timeout,client->timeout);
}
}

}

static void redsocks_accept_backoff(int fd, short what, void *_arg)
Expand Down Expand Up @@ -685,6 +695,7 @@ static void redsocks_accept_client(int fd, short what, void *_arg)

redsocks_touch_client(client);

client->timeout=self->config.timeout;
client->client = bufferevent_new(client_fd, NULL, NULL, redsocks_event_error, client);
if (!client->client) {
log_errno(LOG_ERR, "bufferevent_new");
Expand Down
2 changes: 2 additions & 0 deletions redsocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct redsocks_config_t {
uint16_t min_backoff_ms;
uint16_t max_backoff_ms; // backoff capped by 65 seconds is enough :)
uint16_t listenq;
uint16_t timeout;
} redsocks_config;

struct tracked_event {
Expand Down Expand Up @@ -61,6 +62,7 @@ typedef struct redsocks_client_t {
unsigned short relay_evshut;
time_t first_event;
time_t last_event;
uint16_t timeout;
} redsocks_client;


Expand Down