Fixed bug #1: Excessive send queue bug (corruption of the offset variable).
Low priority messages are not relayed if soft limit send queue is reached. Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
This commit is contained in:
parent
4797d5ee90
commit
58e2982675
14
src/hub.c
14
src/hub.c
@ -50,6 +50,13 @@ int hub_handle_message(struct user* u, const char* line, size_t length)
|
|||||||
so we ignore them. */
|
so we ignore them. */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ADC_CMD_EMSG:
|
||||||
|
case ADC_CMD_DMSG:
|
||||||
|
case ADC_CMD_BMSG:
|
||||||
|
case ADC_CMD_FMSG:
|
||||||
|
ret = hub_handle_chat_message(u, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
case ADC_CMD_BSCH:
|
case ADC_CMD_BSCH:
|
||||||
case ADC_CMD_DSCH:
|
case ADC_CMD_DSCH:
|
||||||
case ADC_CMD_ESCH:
|
case ADC_CMD_ESCH:
|
||||||
@ -57,18 +64,13 @@ int hub_handle_message(struct user* u, const char* line, size_t length)
|
|||||||
case ADC_CMD_DRES:
|
case ADC_CMD_DRES:
|
||||||
case ADC_CMD_DRCM:
|
case ADC_CMD_DRCM:
|
||||||
case ADC_CMD_DCTM:
|
case ADC_CMD_DCTM:
|
||||||
|
cmd->priority = -1;
|
||||||
if (u->hub->config->chat_only && u->credentials < cred_operator)
|
if (u->hub->config->chat_only && u->credentials < cred_operator)
|
||||||
{
|
{
|
||||||
/* These below aren't allowed in chat only hubs */
|
/* These below aren't allowed in chat only hubs */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ADC_CMD_EMSG:
|
|
||||||
case ADC_CMD_DMSG:
|
|
||||||
case ADC_CMD_BMSG:
|
|
||||||
case ADC_CMD_FMSG:
|
|
||||||
ret = hub_handle_chat_message(u, cmd); break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (user_is_logged_in(u))
|
if (user_is_logged_in(u))
|
||||||
{
|
{
|
||||||
|
@ -769,6 +769,8 @@ int hub_handle_info(struct user* user, const struct adc_message* cmd_unmodified)
|
|||||||
struct adc_message* cmd = adc_msg_copy(cmd_unmodified); /* FIXME: Have a small memory leak here! */
|
struct adc_message* cmd = adc_msg_copy(cmd_unmodified); /* FIXME: Have a small memory leak here! */
|
||||||
if (!cmd) return -1; /* OOM */
|
if (!cmd) return -1; /* OOM */
|
||||||
|
|
||||||
|
cmd->priority = 1;
|
||||||
|
|
||||||
hub_handle_info_common(user, cmd);
|
hub_handle_info_common(user, cmd);
|
||||||
|
|
||||||
/* If user is logging in, perform more checks,
|
/* If user is logging in, perform more checks,
|
||||||
|
@ -147,7 +147,6 @@ void net_on_read(int fd, short ev, void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEBUG_SENDQ
|
|
||||||
|
|
||||||
void net_on_write(int fd, short ev, void *arg)
|
void net_on_write(int fd, short ev, void *arg)
|
||||||
{
|
{
|
||||||
@ -176,15 +175,17 @@ void net_on_write(int fd, short ev, void *arg)
|
|||||||
if (ret == length)
|
if (ret == length)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_SENDQ
|
#ifdef DEBUG_SENDQ
|
||||||
hub_log(log_error, "SENDQ: sent=%d bytes/%d (all), send_queue_size=%d, offset=%d\n", ret, (int) msg->length, user->send_queue_size, user->send_queue_offset);
|
hub_log(log_error, "SENDQ: sent=%d bytes/%d (all), send_queue_size=%d, offset=%d", ret, (int) msg->length, user->send_queue_size, user->send_queue_offset);
|
||||||
#endif
|
#endif
|
||||||
user->send_queue_size -= ret;
|
user->send_queue_size -= ret;
|
||||||
user->send_queue_offset = 0;
|
user->send_queue_offset = 0;
|
||||||
|
|
||||||
|
#ifdef DEBUG_SENDQ
|
||||||
if ((user->send_queue_size < 0) || (user->send_queue_offset < 0))
|
if ((user->send_queue_size < 0) || (user->send_queue_offset < 0))
|
||||||
{
|
{
|
||||||
hub_log(log_error, "INVALID: send_queue_size=%d, send_queue_offset=%d", user->send_queue_size, user->send_queue_offset);
|
hub_log(log_error, "INVALID: send_queue_size=%d, send_queue_offset=%d", user->send_queue_size, user->send_queue_offset);
|
||||||
}
|
}
|
||||||
|
#endif DEBUG_SENDQ
|
||||||
|
|
||||||
list_remove(user->send_queue, msg);
|
list_remove(user->send_queue, msg);
|
||||||
|
|
||||||
@ -202,16 +203,17 @@ void net_on_write(int fd, short ev, void *arg)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_SENDQ
|
#ifdef DEBUG_SENDQ
|
||||||
hub_log(log_error, "SENDQ: sent=%d bytes/%d (part), send_queue_size=%d, offset=%d\n", ret, (int) msg->length, user->send_queue_size, user->send_queue_offset);
|
hub_log(log_error, "SENDQ: sent=%d bytes/%d (part), send_queue_size=%d, offset=%d", ret, (int) msg->length, user->send_queue_size, user->send_queue_offset);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
user->send_queue_size -= ret;
|
user->send_queue_size -= ret;
|
||||||
user->send_queue_offset += ret;
|
user->send_queue_offset += ret;
|
||||||
|
|
||||||
|
#ifdef DEBUG_SENDQ
|
||||||
if ((user->send_queue_size < 0) || (user->send_queue_offset < 0) || (user->send_queue_offset > msg->length))
|
if ((user->send_queue_size < 0) || (user->send_queue_offset < 0) || (user->send_queue_offset > msg->length))
|
||||||
{
|
{
|
||||||
hub_log(log_error, "INVALID: send_queue_size=%d, send_queue_offset=%d", user->send_queue_size, user->send_queue_offset);
|
hub_log(log_error, "INVALID: send_queue_size=%d, send_queue_offset=%d", user->send_queue_size, user->send_queue_offset);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
src/route.c
20
src/route.c
@ -64,7 +64,9 @@ static void queue_command(struct user* user, struct adc_message* msg__, int offs
|
|||||||
struct adc_message* msg = adc_msg_incref(msg__);
|
struct adc_message* msg = adc_msg_incref(msg__);
|
||||||
list_append(user->send_queue, msg);
|
list_append(user->send_queue, msg);
|
||||||
|
|
||||||
hub_log(log_trace, "queue_command(), user=%p, msg=%p (%zu), offset=%d", user, msg, msg->references, offset);
|
#ifdef DEBUG_SENDQ
|
||||||
|
hub_log(log_trace, "SENDQ: user=%p, msg=%p (%zu), offset=%d, length=%d, total_length=%d", user, msg, msg->references, offset, msg->length, user->send_queue_size);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (offset > 0)
|
if (offset > 0)
|
||||||
{
|
{
|
||||||
@ -75,16 +77,25 @@ static void queue_command(struct user* user, struct adc_message* msg__, int offs
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
user->send_queue_size += msg->length;
|
user->send_queue_size += msg->length;
|
||||||
user->send_queue_offset = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #define ALWAYS_QUEUE_MESSAGES
|
// #define ALWAYS_QUEUE_MESSAGES
|
||||||
static size_t get_max_send_queue(struct hub_info* hub)
|
static size_t get_max_send_queue(struct hub_info* hub)
|
||||||
{
|
{
|
||||||
return MAX(hub->config->max_send_buffer, (hub->config->max_recv_buffer * hub_get_user_count(hub)));
|
/* TODO: More dynamic send queue limit, for instance:
|
||||||
|
* return MAX(hub->config->max_send_buffer, (hub->config->max_recv_buffer * hub_get_user_count(hub)));
|
||||||
|
*/
|
||||||
|
return hub->config->max_send_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t get_max_send_queue_soft(struct hub_info* hub)
|
||||||
|
{
|
||||||
|
return hub->config->max_send_buffer_soft;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @return 1 if send queue is OK.
|
* @return 1 if send queue is OK.
|
||||||
* -1 if send queue is overflowed
|
* -1 if send queue is overflowed
|
||||||
@ -98,6 +109,9 @@ static int check_send_queue(struct user* user, struct adc_message* msg)
|
|||||||
if ((user->send_queue_size + msg->length) > get_max_send_queue(user->hub))
|
if ((user->send_queue_size + msg->length) > get_max_send_queue(user->hub))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (user->send_queue_size > get_max_send_queue_soft(user->hub) && msg->priority < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user