Modified qmem for lazy mode handling; fixed some user management issues

This commit is contained in:
frekky 2015-09-28 13:01:18 +08:00
parent bd9966836e
commit 555a3cbfe2
2 changed files with 11 additions and 11 deletions

View File

@ -85,6 +85,9 @@ init_users(in_addr_t my_ip, int netbits)
} }
users[i].tun_ip = ip; users[i].tun_ip = ip;
net.s_addr = 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 */ /* Rest is reset on login ('V' packet) or already 0 */
} }
@ -119,7 +122,7 @@ user_sending(int user)
int int
user_active(int i) 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 int
@ -131,7 +134,8 @@ all_users_waiting_to_send()
*/ */
{ {
for (int i = 0; i < usercount; i++) 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; return 1;
} }
@ -142,8 +146,6 @@ find_available_user()
/* Not used at all or not used in one minute */ /* Not used at all or not used in one minute */
if (!user_active(u)) { if (!user_active(u)) {
struct tun_user *user = &users[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 */ /* reset all stats */
user->active = 1; user->active = 1;
user->authenticated = 0; user->authenticated = 0;

View File

@ -31,11 +31,11 @@ struct tun_user {
int authenticated_raw; int authenticated_raw;
int disabled; int disabled;
time_t last_pkt; time_t last_pkt;
struct timeval dns_timeout;
int seed; int seed;
in_addr_t tun_ip; in_addr_t tun_ip;
struct sockaddr_storage host; struct sockaddr_storage host;
socklen_t hostlen; socklen_t hostlen;
struct query q;
/* TODO: multiple incoming query storage + handling */ /* TODO: multiple incoming query storage + handling */
struct frag_buffer *incoming; struct frag_buffer *incoming;
struct frag_buffer *outgoing; struct frag_buffer *outgoing;
@ -43,15 +43,13 @@ struct tun_user {
struct encoder *encoder; struct encoder *encoder;
char downenc; char downenc;
int downenc_bits; int downenc_bits;
int down_compression;
int fragsize; int fragsize;
enum connection conn; enum connection conn;
int lazy; int lazy;
/*unsigned char qmemping_cmc[QMEMPING_LEN * 4]; #ifdef QMEM_LEN
unsigned short qmemping_type[QMEMPING_LEN]; struct query_buffer qmem;
int qmemping_lastfilled; #endif
unsigned char qmemdata_cmc[QMEMDATA_LEN * 4];
unsigned short qmemdata_type[QMEMDATA_LEN];
int qmemdata_lastfilled;*/
#ifdef DNSCACHE_LEN #ifdef DNSCACHE_LEN
struct query dnscache_q[DNSCACHE_LEN]; struct query dnscache_q[DNSCACHE_LEN];
char dnscache_answer[DNSCACHE_LEN][4096]; char dnscache_answer[DNSCACHE_LEN][4096];