From cff10910ad08237e2345627672716c97b8cda949 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Sun, 1 Dec 2019 13:16:28 +0100 Subject: [PATCH] Issue 72: Improve ghost user detection uhub has the ability to disconnect a 'ghost' user, e.g. if a user reconnects then uhub will kick the existing user if it is still there. However, this could also be triggered abusively by having two "tabs" or windows connect at the same time from the same client. The process of connecting a new client is rather expensive because it triggers a lot of updates on all connections. With this change, uhub will only attempt to disconnect the existing client if it is marked with the "flag_choke" flag, which indicates that messages must be dropped simply because the client is not accepting data fast enough. This will cause the new connection to fail because the user is already logged in. This can be further improved by adding a timestamp for when the connection previously was provable working. Which is possibly a better and more reliable way of detecting ghost users. --- src/core/inf.c | 16 +++++++++++++--- src/core/route.c | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/core/inf.c b/src/core/inf.c index 85c57a7..b7cfff3 100644 --- a/src/core/inf.c +++ b/src/core/inf.c @@ -337,9 +337,19 @@ static int check_logged_in(struct hub_info* hub, struct hub_user* user, struct a { if (lookup1 == lookup2) { - LOG_DEBUG("check_logged_in: exact same user is logged in: %s", user->id.nick); - hub_disconnect_user(hub, lookup1, quit_ghost_timeout); - return 0; + if (user_flag_get(lookup1, flag_choke)) + { + LOG_DEBUG("check_logged_in: exact same user is already logged in, but likely ghost: %s", user->id.nick); + + // Old user unable to swallow data. + // Disconnect the existing user, and allow new user to enter. + hub_disconnect_user(hub, lookup1, quit_ghost_timeout); + } + else + { + LOG_DEBUG("check_logged_in: exact same user is already logged in: %s", user->id.nick); + return status_msg_inf_error_cid_taken; + } } else { diff --git a/src/core/route.c b/src/core/route.c index 0ff8998..4a52bb1 100644 --- a/src/core/route.c +++ b/src/core/route.c @@ -82,16 +82,19 @@ static int check_send_queue(struct hub_info* hub, struct hub_user* user, struct if ((user->send_queue->size + msg->length) > get_max_send_queue(hub)) { + user_flag_set(user, flag_choke); LOG_WARN("send queue overflowed, message discarded."); return -1; } if (user->send_queue->size > get_max_send_queue_soft(hub)) { + user_flag_set(user, flag_choke); LOG_WARN("send queue soft overflowed."); return 0; } + user_flag_unset(user, flag_choke); return 1; }