Commit 32d30efd authored by 's avatar
Browse files

changed tracke_list to a hash table


git-svn-id: file:///home/svn/mapi/trunk@396 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent f041236e
...@@ -49,6 +49,8 @@ struct list{ ...@@ -49,6 +49,8 @@ struct list{
struct filters *tail; struct filters *tail;
}; };
#define HASHTABLESIZE 101
char *dc_strings[42]={"$MyNick","$Lock","$Direction","$Key","$ConnectToMe","$Get","$Send|","$HubName","$ValidateNick", char *dc_strings[42]={"$MyNick","$Lock","$Direction","$Key","$ConnectToMe","$Get","$Send|","$HubName","$ValidateNick",
"$ValidateDenide","$GetPass","$MyPass","$LogedIn","$BadPass","$Hello","$MyINFO $ALL","$GetINFO","$GetListLen", "$ValidateDenide","$GetPass","$MyPass","$LogedIn","$BadPass","$Hello","$MyINFO $ALL","$GetINFO","$GetListLen",
"$ListLen","$MaxedOut","$Error","$FileLength","$Canceled","$SR","$Ping","$Hello","$Version","$GetNickList", "$ListLen","$MaxedOut","$Error","$FileLength","$Canceled","$SR","$Ping","$Hello","$Version","$GetNickList",
...@@ -60,7 +62,7 @@ int isDc(mapidflib_function_instance_t *, unsigned char *, int ); ...@@ -60,7 +62,7 @@ int isDc(mapidflib_function_instance_t *, unsigned char *, int );
struct mapid_dc { struct mapid_dc {
int *shift[42]; int *shift[42];
int *skip[42]; int *skip[42];
struct list *dclist; struct list **dclist;
}; };
static int dc_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd) static int dc_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd)
...@@ -68,10 +70,13 @@ static int dc_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd) ...@@ -68,10 +70,13 @@ static int dc_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd)
int i=0; int i=0;
instance->internal_data = malloc(sizeof(struct mapid_dc)); instance->internal_data = malloc(sizeof(struct mapid_dc));
((struct mapid_dc*)instance->internal_data)->dclist = (struct list*)malloc(sizeof(struct list)); ((struct mapid_dc*)instance->internal_data)->dclist = (struct list**)malloc(sizeof(struct list*)*HASHTABLESIZE);
((struct mapid_dc*)instance->internal_data)->dclist->head = NULL; memset(((struct mapid_dc*)instance->internal_data)->dclist, 0, (sizeof(struct list*)*HASHTABLESIZE));
((struct mapid_dc*)instance->internal_data)->dclist->head = NULL; for(i = 0; i < HASHTABLESIZE; i++) {
((struct mapid_dc*)instance->internal_data)->dclist[i] = (struct list*)malloc(sizeof(struct list));
((struct mapid_dc*)instance->internal_data)->dclist[i]->head = NULL;
((struct mapid_dc*)instance->internal_data)->dclist[i]->tail = NULL;
}
for(i=0;i<42;i++) { for(i=0;i<42;i++) {
((struct mapid_dc*)instance->internal_data)->shift[i] = make_shift(dc_strings[i],strlen(dc_strings[i])); ((struct mapid_dc*)instance->internal_data)->shift[i] = make_shift(dc_strings[i],strlen(dc_strings[i]));
((struct mapid_dc*)instance->internal_data)->skip[i] = make_skip(dc_strings[i], strlen(dc_strings[i])); ((struct mapid_dc*)instance->internal_data)->skip[i] = make_skip(dc_strings[i], strlen(dc_strings[i]));
...@@ -106,7 +111,7 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -106,7 +111,7 @@ static int dc_process(mapidflib_function_instance_t *instance,
unsigned char *p = NULL; unsigned char *p = NULL;
struct timeval ts; struct timeval ts;
struct list *dclist = ((struct mapid_dc*)instance->internal_data)->dclist; struct list **dclist = ((struct mapid_dc*)instance->internal_data)->dclist;
uint16_t ethertype; uint16_t ethertype;
struct ether_header *ep = NULL; struct ether_header *ep = NULL;
struct iphdr *iph = NULL; struct iphdr *iph = NULL;
...@@ -116,6 +121,8 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -116,6 +121,8 @@ static int dc_process(mapidflib_function_instance_t *instance,
unsigned int saddr, daddr; unsigned int saddr, daddr;
uint16_t sp, dp; uint16_t sp, dp;
unsigned int hashval = 0;
p = pkt; p = pkt;
...@@ -140,6 +147,8 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -140,6 +147,8 @@ static int dc_process(mapidflib_function_instance_t *instance,
p += iph->ihl * 4; p += iph->ihl * 4;
hashval = saddr % HASHTABLESIZE;
if(iph->protocol == 6) // TCP if(iph->protocol == 6) // TCP
{ {
tcph = (struct tcphdr *)p; tcph = (struct tcphdr *)p;
...@@ -161,7 +170,7 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -161,7 +170,7 @@ static int dc_process(mapidflib_function_instance_t *instance,
gettimeofday(&ts, NULL); gettimeofday(&ts, NULL);
for(temp = dclist->head, prev = dclist->head; temp != NULL; prev = temp, temp = temp->next) for(temp = dclist[hashval]->head, prev = dclist[hashval]->head; temp != NULL; prev = temp, temp = temp->next)
{ {
if(temp->protocol == iph->protocol && if(temp->protocol == iph->protocol &&
( (
...@@ -173,8 +182,8 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -173,8 +182,8 @@ static int dc_process(mapidflib_function_instance_t *instance,
gettimeofday(&(temp->ts), NULL); gettimeofday(&(temp->ts), NULL);
if(iph->protocol == 6 && tcph->fin) { if(iph->protocol == 6 && tcph->fin) {
if(temp == dclist->head){ if(temp == dclist[hashval]->head){
dclist->head = temp->next; dclist[hashval]->head = temp->next;
} }
else { else {
prev->next = temp->next; prev->next = temp->next;
...@@ -186,8 +195,8 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -186,8 +195,8 @@ static int dc_process(mapidflib_function_instance_t *instance,
return 1; return 1;
} }
else if(ts.tv_sec - temp->ts.tv_sec > 1) { else if(ts.tv_sec - temp->ts.tv_sec > 1) {
if(temp == dclist->head){ if(temp == dclist[hashval]->head){
dclist->head = temp->next; dclist[hashval]->head = temp->next;
} }
else { else {
prev->next = temp->next; prev->next = temp->next;
...@@ -238,7 +247,9 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -238,7 +247,9 @@ static int dc_process(mapidflib_function_instance_t *instance,
new->sp = sp; new->sp = sp;
new->dp = dp; new->dp = dp;
for(temp = dclist->head; temp != NULL; temp = temp->next) hashval = new->saddr % HASHTABLESIZE;
for(temp = dclist[hashval]->head; temp != NULL; temp = temp->next)
{ {
if(new->protocol == temp->protocol && ( if(new->protocol == temp->protocol && (
(new->saddr == temp->saddr && new->daddr == temp->daddr && new->sp == temp->sp && new->dp == temp->dp) (new->saddr == temp->saddr && new->daddr == temp->daddr && new->sp == temp->sp && new->dp == temp->dp)
...@@ -251,8 +262,8 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -251,8 +262,8 @@ static int dc_process(mapidflib_function_instance_t *instance,
} }
} }
new->next = dclist->head; new->next = dclist[hashval]->head;
dclist->head = new; dclist[hashval]->head = new;
return 1; return 1;
} }
...@@ -263,16 +274,18 @@ static int dc_process(mapidflib_function_instance_t *instance, ...@@ -263,16 +274,18 @@ static int dc_process(mapidflib_function_instance_t *instance,
static int dc_cleanup(mapidflib_function_instance_t *instance) static int dc_cleanup(mapidflib_function_instance_t *instance)
{ {
struct filters *temp = NULL, *tmp = NULL; struct filters *temp = NULL, *tmp = NULL;
int i = 0;
if(instance->internal_data != NULL){
temp = ((struct mapid_dc*)instance->internal_data)->dclist->head;
while(temp != NULL) if(instance->internal_data != NULL){
{ for(i = 0; i < HASHTABLESIZE; i++) {
tmp = temp; temp = ((struct mapid_dc*)instance->internal_data)->dclist[i]->head;
temp = temp->next;
free(tmp); while(temp != NULL) {
} tmp = temp;
temp = temp->next;
free(tmp);
}
}
free(((struct mapid_dc*)instance->internal_data)->dclist); free(((struct mapid_dc*)instance->internal_data)->dclist);
free(instance->internal_data); free(instance->internal_data);
} }
......
...@@ -44,13 +44,13 @@ struct list{ ...@@ -44,13 +44,13 @@ struct list{
struct filters *tail; struct filters *tail;
}; };
#define HASHTABLESIZE 101
int isEdonkey(int, char); int isEdonkey(int, char);
unsigned int getSize(char *); unsigned int getSize(char *);
struct mapid_edonkey { struct mapid_edonkey {
// int *shift[42]; struct list **edonkeylist;
// int *skip[42];
struct list *edonkeylist;
}; };
struct edonkey_header struct edonkey_header
...@@ -62,10 +62,16 @@ struct edonkey_header ...@@ -62,10 +62,16 @@ struct edonkey_header
static int edonkey_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd) static int edonkey_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd)
{ {
int i = 0;
instance->internal_data = malloc(sizeof(struct mapid_edonkey)); instance->internal_data = malloc(sizeof(struct mapid_edonkey));
((struct mapid_edonkey*)instance->internal_data)->edonkeylist = (struct list*)malloc(sizeof(struct list)); ((struct mapid_edonkey*)instance->internal_data)->edonkeylist = (struct list**)malloc(sizeof(struct list*)*HASHTABLESIZE);
((struct mapid_edonkey*)instance->internal_data)->edonkeylist->head = NULL; memset(((struct mapid_edonkey*)instance->internal_data)->edonkeylist, 0, (sizeof(struct list*)*HASHTABLESIZE));
((struct mapid_edonkey*)instance->internal_data)->edonkeylist->head = NULL; for(i = 0; i < HASHTABLESIZE; i++) {
((struct mapid_edonkey*)instance->internal_data)->edonkeylist[i] = (struct list*)malloc(sizeof(struct list));
((struct mapid_edonkey*)instance->internal_data)->edonkeylist[i]->head = NULL;
((struct mapid_edonkey*)instance->internal_data)->edonkeylist[i]->tail = NULL;
}
return 0; return 0;
} }
...@@ -230,7 +236,7 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -230,7 +236,7 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
struct filters *temp = NULL, *prev = NULL, *new = NULL; struct filters *temp = NULL, *prev = NULL, *new = NULL;
unsigned char *p = NULL; unsigned char *p = NULL;
struct list *edonkeylist = ((struct mapid_edonkey*)instance->internal_data)->edonkeylist; struct list **edonkeylist = ((struct mapid_edonkey*)instance->internal_data)->edonkeylist;
uint16_t ethertype; uint16_t ethertype;
struct ether_header *ep = NULL; struct ether_header *ep = NULL;
struct iphdr *iph = NULL; struct iphdr *iph = NULL;
...@@ -245,6 +251,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -245,6 +251,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
uint16_t sp, dp; uint16_t sp, dp;
unsigned int hashval = 0;
p = pkt; p = pkt;
// lay the Ethernet header struct over the packet data // lay the Ethernet header struct over the packet data
...@@ -269,6 +277,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -269,6 +277,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
p += iph->ihl * 4; p += iph->ihl * 4;
hashval = saddr % HASHTABLESIZE;
if(iph->protocol == 6) // TCP if(iph->protocol == 6) // TCP
{ {
...@@ -293,7 +303,7 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -293,7 +303,7 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
gettimeofday(&ts, NULL); gettimeofday(&ts, NULL);
for(temp = edonkeylist->head, prev = edonkeylist->head; temp != NULL; prev = temp, temp = temp->next) for(temp = edonkeylist[hashval]->head, prev = edonkeylist[hashval]->head; temp != NULL; prev = temp, temp = temp->next)
{ {
if(temp->protocol == iph->protocol && if(temp->protocol == iph->protocol &&
( (
...@@ -305,8 +315,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -305,8 +315,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
gettimeofday(&(temp->last_timestamp), NULL); gettimeofday(&(temp->last_timestamp), NULL);
if(iph->protocol == 6 && tcph->fin) { if(iph->protocol == 6 && tcph->fin) {
if(temp == edonkeylist->head) { if(temp == edonkeylist[hashval]->head) {
edonkeylist->head = temp->next; edonkeylist[hashval]->head = temp->next;
} }
else { else {
prev->next = temp->next; prev->next = temp->next;
...@@ -318,8 +328,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -318,8 +328,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
return 1; return 1;
} }
else if(ts.tv_sec - temp->last_timestamp.tv_sec > 1) { else if(ts.tv_sec - temp->last_timestamp.tv_sec > 1) {
if(temp == edonkeylist->head) { if(temp == edonkeylist[hashval]->head) {
edonkeylist->head = temp->next; edonkeylist[hashval]->head = temp->next;
} }
else { else {
prev->next = temp->next; prev->next = temp->next;
...@@ -383,8 +393,9 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -383,8 +393,9 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
new->dp = dp; new->dp = dp;
gettimeofday(&(new->last_timestamp), NULL); gettimeofday(&(new->last_timestamp), NULL);
/* hashval = new->saddr % HASHTABLESIZE;
for(temp = edonkeylist->head; temp != NULL; temp = temp->next)
for(temp = edonkeylist[hashval]->head; temp != NULL; temp = temp->next)
{ {
if(new->protocol == temp->protocol && ( if(new->protocol == temp->protocol && (
(new->saddr == temp->saddr && new->daddr == temp->daddr && new->sp == temp->sp && new->dp == temp->dp) (new->saddr == temp->saddr && new->daddr == temp->daddr && new->sp == temp->sp && new->dp == temp->dp)
...@@ -396,9 +407,9 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -396,9 +407,9 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
return 1; return 1;
} }
} }
*/
new->next = edonkeylist->head; new->next = edonkeylist[hashval]->head;
edonkeylist->head = new; edonkeylist[hashval]->head = new;
return 1; return 1;
} }
...@@ -406,18 +417,22 @@ static int edonkey_process(mapidflib_function_instance_t *instance, ...@@ -406,18 +417,22 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
static int edonkey_cleanup(mapidflib_function_instance_t *instance) static int edonkey_cleanup(mapidflib_function_instance_t *instance)
{ {
struct filters *temp = NULL, *tmp = NULL; struct filters *temp = NULL, *tmp = NULL;
int i = 0;
if(instance->internal_data != NULL){ if(instance->internal_data != NULL){
temp = ((struct mapid_edonkey*)instance->internal_data)->edonkeylist->head;
while(temp != NULL) for(i = 0; i < HASHTABLESIZE; i++) {
{ temp = ((struct mapid_edonkey*)instance->internal_data)->edonkeylist[i]->head;
tmp = temp;
temp = temp->next; while(temp != NULL) {
free(tmp); tmp = temp;
} temp = temp->next;
free(((struct mapid_edonkey*)instance->internal_data)->edonkeylist); free(tmp);
free(instance->internal_data); }
}
free(((struct mapid_edonkey*)instance->internal_data)->edonkeylist);
free(instance->internal_data);
} }
return 0; return 0;
} }
......
...@@ -57,7 +57,6 @@ struct mapid_gnutella { ...@@ -57,7 +57,6 @@ struct mapid_gnutella {
int *shift[7]; int *shift[7];
int *skip[7]; int *skip[7];
struct list **gnulist; struct list **gnulist;
struct list *top_ten;
}; };
int isGnutella(mapidflib_function_instance_t *, unsigned char *, int ); int isGnutella(mapidflib_function_instance_t *, unsigned char *, int );
...@@ -74,10 +73,6 @@ static int gnutella_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in ...@@ -74,10 +73,6 @@ static int gnutella_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in
((struct mapid_gnutella*)instance->internal_data)->gnulist[i]->head = NULL; ((struct mapid_gnutella*)instance->internal_data)->gnulist[i]->head = NULL;
((struct mapid_gnutella*)instance->internal_data)->gnulist[i]->tail = NULL; ((struct mapid_gnutella*)instance->internal_data)->gnulist[i]->tail = NULL;
} }
((struct mapid_gnutella*)instance->internal_data)->top_ten = (struct list*)malloc(sizeof(struct list));
((struct mapid_gnutella*)instance->internal_data)->top_ten->head = NULL;
((struct mapid_gnutella*)instance->internal_data)->top_ten->tail = NULL;
for(i=0;i<7;i++) { for(i=0;i<7;i++) {
((struct mapid_gnutella*)instance->internal_data)->shift[i] = make_shift(gnutella_strings[i],strlen(gnutella_strings[i])); ((struct mapid_gnutella*)instance->internal_data)->shift[i] = make_shift(gnutella_strings[i],strlen(gnutella_strings[i]));
((struct mapid_gnutella*)instance->internal_data)->skip[i] = make_skip(gnutella_strings[i], strlen(gnutella_strings[i])); ((struct mapid_gnutella*)instance->internal_data)->skip[i] = make_skip(gnutella_strings[i], strlen(gnutella_strings[i]));
...@@ -260,16 +255,7 @@ static int gnutella_cleanup(mapidflib_function_instance_t *instance) ...@@ -260,16 +255,7 @@ static int gnutella_cleanup(mapidflib_function_instance_t *instance)
} }
} }
temp = ((struct mapid_gnutella*)instance->internal_data)->top_ten->head;
while(temp != NULL) {
tmp = temp;
temp = temp->next;
free(tmp);
}
free(((struct mapid_gnutella*)instance->internal_data)->gnulist); free(((struct mapid_gnutella*)instance->internal_data)->gnulist);
free(((struct mapid_gnutella*)instance->internal_data)->top_ten);
free(instance->internal_data); free(instance->internal_data);
} }
return 0; return 0;
......
...@@ -49,6 +49,8 @@ struct list{ ...@@ -49,6 +49,8 @@ struct list{
struct filters *tail; struct filters *tail;
}; };
#define HASHTABLESIZE 101
char *torrent_strings[3]={"BitTorrent protocol","GET /scrape?info_hash=","GET /announce?info_hash="}; char *torrent_strings[3]={"BitTorrent protocol","GET /scrape?info_hash=","GET /announce?info_hash="};
int isTorrent(mapidflib_function_instance_t *, unsigned char *, int ); int isTorrent(mapidflib_function_instance_t *, unsigned char *, int );
...@@ -56,7 +58,7 @@ int isTorrent(mapidflib_function_instance_t *, unsigned char *, int ); ...@@ -56,7 +58,7 @@ int isTorrent(mapidflib_function_instance_t *, unsigned char *, int );
struct mapid_torrent { struct mapid_torrent {
int *shift[3]; int *shift[3];
int *skip[3]; int *skip[3];
struct list *torlist; struct list **torlist;
}; };
static int torrent_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd) static int torrent_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd)
...@@ -64,10 +66,12 @@ static int torrent_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int ...@@ -64,10 +66,12 @@ static int torrent_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int
int i=0; int i=0;
instance->internal_data = malloc(sizeof(struct mapid_torrent)); instance->internal_data = malloc(sizeof(struct mapid_torrent));
((struct mapid_torrent*)instance->internal_data)->torlist = (struct list*)malloc(sizeof(struct list)); ((struct mapid_torrent*)instance->internal_data)->torlist = (struct list**)malloc(sizeof(struct list*)*HASHTABLESIZE);
((struct mapid_torrent*)instance->internal_data)->torlist->head = NULL; for(i = 0; i < HASHTABLESIZE; i++) {
((struct mapid_torrent*)instance->internal_data)->torlist->head = NULL; ((struct mapid_torrent*)instance->internal_data)->torlist[i] = (struct list*)malloc(sizeof(struct list));
((struct mapid_torrent*)instance->internal_data)->torlist[i]->head = NULL;
((struct mapid_torrent*)instance->internal_data)->torlist[i]->tail = NULL;
}
for(i=0;i<3;i++) { for(i=0;i<3;i++) {
((struct mapid_torrent*)instance->internal_data)->shift[i] = make_shift(torrent_strings[i],strlen(torrent_strings[i])); ((struct mapid_torrent*)instance->internal_data)->shift[i] = make_shift(torrent_strings[i],strlen(torrent_strings[i]));
((struct mapid_torrent*)instance->internal_data)->skip[i] = make_skip(torrent_strings[i], strlen(torrent_strings[i])); ((struct mapid_torrent*)instance->internal_data)->skip[i] = make_skip(torrent_strings[i], strlen(torrent_strings[i]));
...@@ -103,7 +107,7 @@ static int torrent_process(mapidflib_function_instance_t *instance, ...@@ -103,7 +107,7 @@ static int torrent_process(mapidflib_function_instance_t *instance,
unsigned char *p = NULL; unsigned char *p = NULL;
struct timeval ts; struct timeval ts;
struct list *torlist = ((struct mapid_torrent*)instance->internal_data)->torlist; struct list **torlist = ((struct mapid_torrent*)instance->internal_data)->torlist;
uint16_t ethertype; uint16_t ethertype;
struct ether_header *ep = NULL; struct ether_header *ep = NULL;
struct iphdr *iph = NULL; struct iphdr *iph = NULL;
...@@ -114,6 +118,8 @@ static int torrent_process(mapidflib_function_instance_t *instance, ...@@ -114,6 +118,8 @@ static int torrent_process(mapidflib_function_instance_t *instance,
uint16_t sp, dp; uint16_t sp, dp;
unsigned int hashval = 0;
p = pkt; p = pkt;
// lay the Ethernet header struct over the packet data // lay the Ethernet header struct over the packet data
...@@ -136,7 +142,8 @@ static int torrent_process(mapidflib_function_instance_t *instance, ...@@ -136,7 +142,8 @@ static int torrent_process(mapidflib_function_instance_t *instance,
p += iph->ihl * 4; p += iph->ihl * 4;
hashval = saddr % HASHTABLESIZE;
if(iph->protocol == 6) // TCP if(iph->protocol == 6) // TCP
{ {
tcph = (struct tcphdr *)p; tcph = (struct tcphdr *)p;
...@@ -160,7 +167,7 @@ static int torrent_process(mapidflib_function_instance_t *instance, ...@@ -160,7 +167,7 @@ static int torrent_process(mapidflib_function_instance_t *instance,
gettimeofday(&ts, NULL); gettimeofday(&ts, NULL);
for(temp = torlist->head, prev = torlist->head; temp != NULL; prev = temp, temp = temp->next) for(temp = torlist[hashval]->head, prev = torlist[hashval]->head; temp != NULL; prev = temp, temp = temp->next)
{ {
if(temp->protocol == iph->protocol && if(temp->protocol == iph->protocol &&
( (
...@@ -172,8 +179,8 @@ static int torrent_process(mapidflib_function_instance_t *instance, ...@@ -172,8 +179,8 @@ static int torrent_process(mapidflib_function_instance_t *instance,
gettimeofday(&(temp->ts), NULL); gettimeofday(&(temp->ts), NULL);
if(iph->protocol == 6 && tcph->fin) { if(iph->protocol == 6 && tcph->fin) {
if(temp == torlist->head) { if(temp == torlist[hashval]->head) {
torlist->head = temp->next; torlist[hashval]->head = temp->next;
} }
else { else {
prev->next = temp->next; prev->next = temp->next;
...@@ -185,8 +192,8 @@ static int torrent_process(mapidflib_function_instance_t *instance, ...@@ -185,8 +192,8 @@ static int torrent_process(mapidflib_function_instance_t *instance,
return 1; return 1;
} }
else if(ts.tv_sec - temp->ts.tv_sec > 1) { else if(ts.tv_sec - temp->ts.tv_sec > 1) {
if(temp == torlist->head) { if(temp == torlist[hashval]->head) {
torlist->head = temp->next; torlist[hashval]->head = temp->next;
} }
else { else {
prev->next = temp->next; prev->next = temp->next;
...@@ -215,7 +222,9 @@ static int torrent_process(mapidflib_function_instance_t *instance, ...@@ -215,7 +222,9 @@ static int torrent_process(mapidflib_function_instance_t *instance,
new->sp = sp; new->sp = sp;
new->dp = dp; new->dp = dp;
for(temp = torlist->head; temp != NULL; temp = temp->next) hashval = new->saddr % HASHTABLESIZE;
for(temp = torlist[hashval]->head; temp != NULL; temp = temp->next)
{ {
if(new->protocol == temp->protocol && ( if(new->protocol == temp->protocol && (
(new->saddr == temp->saddr && new->daddr == temp->daddr && new->sp == temp->sp && new->dp == temp->dp) (new->saddr == temp->saddr && new->daddr == temp->daddr && new->sp == temp->sp && new->dp == temp->dp)
...@@ -228,8 +237,8 @@ static int torrent_process(mapidflib_function_instance_t *instance, ...@@ -228,8 +237,8 @@ static int torrent_process(mapidflib_function_instance_t *instance,
} }
} }
new->next = torlist->head; new->next = torlist[hashval]->head;
torlist->head = new; torlist[hashval]->head = new;