diff -ruN ./0.9/config.h ./0.9.1/config.h --- ./0.9/config.h Wed Jun 5 14:29:02 2002 +++ ./0.9.1/config.h Fri Jun 21 16:16:57 2002 @@ -1,2 +1,7 @@ +/* + * part of Cheetah, written by Jirka Kosina + */ + + #define TCP_PORT 8080 -#define VERSION "0.9" +#define VERSION "0.9.1" diff -ruN ./0.9/configuration.h ./0.9.1/configuration.h --- ./0.9/configuration.h Fri May 10 16:21:54 2002 +++ ./0.9.1/configuration.h Fri Jun 21 16:17:05 2002 @@ -1,3 +1,7 @@ +/* + * part of Cheetah, written by Jirka Kosina + */ + #ifndef __CONFIGURE_H__ #define __CONFIGURE_H__ diff -ruN ./0.9/connection.c ./0.9.1/connection.c --- ./0.9/connection.c Thu Jun 20 10:38:42 2002 +++ ./0.9.1/connection.c Sat Jun 22 19:59:08 2002 @@ -448,7 +448,6 @@ * this way, to be more readable and obvious */ N = connection->server_id; - fprintf(stderr,"gSc: %d gVc: %d\n",got_S_cookie, got_V_cookie); if ( (got_V_cookie && !got_S_cookie) || (!got_V_cookie && !got_S_cookie) || (got_S_cookie && !got_V_cookie)){ /* we need to create new item - only setting of first_visit_flag @@ -479,7 +478,6 @@ DEBUG("got_S_cookie && got_V_cookie\n"); tmp_item = get_item(N, S_cookie, connection->ip_addr); if (!tmp_item){ - fprintf(stderr,"Got S cookie, but no data found. Acting as if received only V cookie.\n"); connection->do_set_cookie = 1; connection->set_cookie = get_identifier( connection->server_id, time(NULL)); @@ -487,7 +485,6 @@ (char *)strdup(connection->ip_addr)); } else{ /* not neccesary ;) */ - DEBUG("adjusting item I got\n"); tmp_item->last_request = time(NULL); tmp_item->request_count++; if (tmp_item->request_count < 0) tmp_item->request_count--; diff -ruN ./0.9/connection.h ./0.9.1/connection.h --- ./0.9/connection.h Thu Jun 20 10:38:52 2002 +++ ./0.9.1/connection.h Sat Jun 22 19:19:59 2002 @@ -20,18 +20,22 @@ #include "errors.h" #include "rmd160.h" -#define MAX_REQUEST_PROCESSING_TIME 30 -#define MAX_SERVER_ID 16386 -#define MAX_SERVER_ID 16 -#define MAX_SERVER_ID_LENGTH 5 -#define MAX_STRING_ARG_LENGTH 256 -#define SESSION_TIMEOUT 30*60 +#define MAX_REQUEST_PROCESSING_TIME 30 /* time after which connection timeouts */ +#define MAX_SERVER_ID 16 /* maximum id of server */ +#define MAX_SERVER_ID_LENGTH 5 /* maximum id length (?) */ +#define MAX_STRING_ARG_LENGTH 256 +#define SESSION_TIMEOUT 20 /* time after which "session" expires */ #define DOMAIN_NAME "dummy.domain.cz" -#define PTR_BLOCKSIZE 32 -#define LOG_BUFFER_ITEMS 3 +#define PTR_BLOCKSIZE 32 /* how much allocate in advance */ +#define LOG_BUFFER_ITEMS 3 /* how much events buffer before writing + * to logfile + */ +#define PERIODICAL_CHECK 10 /* how often schedule looking for expired + * sessions + */ #define LOG_FILENAME "CHEETAH.LOG" -/* item struct is a round-liked list, allocated PT_BLOCKSIZE +/* item struct is a round-liked list, allocated PTR_BLOCKSIZE * nodes in advance. items[i] allocated in init_item_struct() * is not to be deleted (delete function not yet implemented) * there must always be at least one structure for each server_id diff -ruN ./0.9/jikos_cheetah.c ./0.9.1/jikos_cheetah.c --- ./0.9/jikos_cheetah.c Thu Jun 20 10:39:18 2002 +++ ./0.9.1/jikos_cheetah.c Sat Jun 22 20:06:00 2002 @@ -13,6 +13,11 @@ extern sig_atomic_t alrm_pending; +extern item_struct *items[MAX_SERVER_ID+1]; +extern void add_to_log(int type, char *ipaddr, int server_id, int first_visit_flag, + int timestamp_1, int timestamp_2, int request_count); + + int socket_ready_to_read (int socket) { @@ -29,6 +34,71 @@ return FD_ISSET (socket, &readfds); } +void log_expiration(int id, item_struct *p) +{ + fprintf(stderr,"Deleting expired %d\n",id); + add_to_log(1, p->ip_addr, id, p->first_request, p->first_visit_flag, + p->last_request, p->request_count); +} + +/* we walk through the whole list of entries, and those, which are too + * old (curtime - last_request > SESSION_TIMEOUT) are removed (and + * proper info is written to log + */ +void clear_expired_entries(void) +{ + int i,complete; + item_struct *tmp, *prev, *next; + time_t curtime; + + for (i=1; inext == items[i]) complete = 1; + if ( ((long long)curtime - (long long)tmp->last_request) + >SESSION_TIMEOUT + && tmp->last_request){ + log_expiration(i, tmp); + prev = tmp->prev; + next = tmp->next; + if (tmp != items[i] ){ + /* this entry has expired, and it isn't + * the first item of the array */ + tmp->prev->next = tmp->next; + tmp->next->prev = tmp->prev; + if (tmp->identifier) free(tmp->identifier); + if (tmp->ip_addr) free(tmp->ip_addr); + free (tmp); + tmp = next; + /* tmp should never be unused node, so no + * change to number_free array is needed + * (the same with first_free pointer into + * this array + */ + } else { + /* it has expired && it is the first item of + * the array + * deleting it is certainly a bad idea + */ + tmp->id = 0; + tmp->first_request = 0; + tmp->last_request = 0; + tmp->request_count = 0; + tmp->first_visit_flag = 0; + if (tmp->identifier) free(tmp->identifier); + tmp->identifier = (char *)strdup("\0"); + if (tmp->ip_addr) free(tmp->ip_addr); + tmp->ip_addr = (char *)strdup("\0"); + } + } else { + tmp = tmp->next; + } + } + } +} + jikos_cheetah_ptr jikos_cheetah_new (void) { jikos_cheetah_ptr new_jikos_cheetah; @@ -60,8 +130,13 @@ /* here potential pending alarms should be handled */ if ((int)alrm_pending == 1){ alrm_pending = 0; - alarm(10); - fprintf(stderr, "Budik handled\n"); + /* during the expiration, no more alarms are generated + * (clearing is not reentrant, it would require massive + * locking, which is not needed + */ + clear_expired_entries(); + alarm(PERIODICAL_CHECK); +/* fprintf(stderr, "Budik handled\n");*/ } if ((ret = socket_ready_to_read (jikos_cheetah->server_socket)) > 0) { diff -ruN ./0.9/macros.h ./0.9.1/macros.h --- ./0.9/macros.h Thu Jun 20 10:39:47 2002 +++ ./0.9.1/macros.h Sat Jun 22 20:01:45 2002 @@ -5,12 +5,10 @@ #ifndef __MACROS_H__ #define __MACROS_H__ -/* from Nachos' libs */ #define ASSERT(x) do{ if(!(x)){printf("Error: Assertion failed: %s (%s:%d)\n",\ #x, __FILE__, __LINE__);} }while(0); #define ABS(X) ((X)>0?(X):(-X)) #define MAX(X,Y) (X>Y?X:Y) - #endif diff -ruN ./0.9/main.c ./0.9.1/main.c --- ./0.9/main.c Thu Jun 20 10:39:54 2002 +++ ./0.9.1/main.c Sat Jun 22 20:02:32 2002 @@ -74,15 +74,18 @@ if (!q) { first = tmp; prev = tmp; + tmp->prev = items[i]; + } if(q) { prev->next = tmp; - prev->next->prev = prev; + tmp->prev = prev; prev = tmp; } } prev->next = items[i]; items[i]->next = first; + items[i]->prev = prev; first_free[i] = items[i]; number_free[i] = PTR_BLOCKSIZE+1; } @@ -96,7 +99,7 @@ void alrm(int dummy) { - fprintf(stderr,"budik\n"); +/* fprintf(stderr,"budik\n");*/ alrm_pending = 1; } @@ -113,7 +116,7 @@ init_log_struct(); /* next alarm will be scheduled after this one is handled */ - alarm(10); + alarm(PERIODICAL_CHECK); s1 = (struct sigaction *)malloc(sizeof(struct sigaction)); s2 = (struct sigaction *)malloc(sizeof(struct sigaction));