From 555a3cbfe2c800528e4144791df0684fac477491 Mon Sep 17 00:00:00 2001 From: frekky Date: Mon, 28 Sep 2015 13:01:18 +0800 Subject: [PATCH] Modified qmem for lazy mode handling; fixed some user management issues --- src/user.c | 10 ++++++---- src/user.h | 12 +++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/user.c b/src/user.c index 5bbe006..7588de4 100644 --- a/src/user.c +++ b/src/user.c @@ -85,6 +85,9 @@ init_users(in_addr_t my_ip, int netbits) } users[i].tun_ip = ip; net.s_addr = ip; + + users[i].incoming = window_buffer_init(INFRAGBUF_LEN, 10, MAX_FRAGSIZE, WINDOW_RECVING); + users[i].outgoing = window_buffer_init(OUTFRAGBUF_LEN, 10, 100, WINDOW_SENDING); /* Rest is reset on login ('V' packet) or already 0 */ } @@ -119,7 +122,7 @@ user_sending(int user) int user_active(int i) { - return users[i].active && !users[i].disabled && users[i].last_pkt + 60 > time(NULL); + return users[i].active && !users[i].disabled && difftime(time(NULL), users[i].last_pkt) < 60; } int @@ -131,7 +134,8 @@ all_users_waiting_to_send() */ { for (int i = 0; i < usercount; i++) - if (!(user_active(i) && user_sending(i))) return 0; + if (user_active(i)) + if (!user_sending(i)) return 0; return 1; } @@ -142,8 +146,6 @@ find_available_user() /* Not used at all or not used in one minute */ if (!user_active(u)) { struct tun_user *user = &users[u]; - if (user->incoming) window_buffer_destroy(user->incoming); - if (user->outgoing) window_buffer_destroy(user->outgoing); /* reset all stats */ user->active = 1; user->authenticated = 0; diff --git a/src/user.h b/src/user.h index 8d5e1f4..1acf8a9 100644 --- a/src/user.h +++ b/src/user.h @@ -31,11 +31,11 @@ struct tun_user { int authenticated_raw; int disabled; time_t last_pkt; + struct timeval dns_timeout; int seed; in_addr_t tun_ip; struct sockaddr_storage host; socklen_t hostlen; - struct query q; /* TODO: multiple incoming query storage + handling */ struct frag_buffer *incoming; struct frag_buffer *outgoing; @@ -43,15 +43,13 @@ struct tun_user { struct encoder *encoder; char downenc; int downenc_bits; + int down_compression; int fragsize; enum connection conn; int lazy; - /*unsigned char qmemping_cmc[QMEMPING_LEN * 4]; - unsigned short qmemping_type[QMEMPING_LEN]; - int qmemping_lastfilled; - unsigned char qmemdata_cmc[QMEMDATA_LEN * 4]; - unsigned short qmemdata_type[QMEMDATA_LEN]; - int qmemdata_lastfilled;*/ +#ifdef QMEM_LEN + struct query_buffer qmem; +#endif #ifdef DNSCACHE_LEN struct query dnscache_q[DNSCACHE_LEN]; char dnscache_answer[DNSCACHE_LEN][4096];