Commit 92b4fd26 authored by 's avatar
Browse files

Changes to limit tracker logging. Also added a define in

src/trackflib/log.h in order to enable/disable logging which is 
by default disabled.


git-svn-id: file:///home/svn/mapi/trunk@652 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent c41a177c
......@@ -314,9 +314,9 @@ static int dc_process(mapidflib_function_instance_t *instance,
new->daddr = daddr;
new->sp = sp;
new->dp = dp;
#ifdef __TRACKFLIB_LOGGING__
write_to_log("DC++", dc_strings[i], iph->protocol, source, sp, dest, dp, p_b, len);
#endif
// printf("DC++ %s %d \n\n",dc_strings[i], iph->protocol);
for(temp = dclist[hashval]->head; temp != NULL; temp = temp->next)
......
......@@ -421,9 +421,10 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
new->sp = sp;
new->dp = dp;
gettimeofday(&(new->last_timestamp), NULL);
#ifdef __TRACKFLIB_LOGGING__
write_to_log("eDonkey", "03020070720100000", iph->protocol, source, sp, dest, dp, p, len);
#endif
for(temp = edonkeylist[hashval]->head; temp != NULL; temp = temp->next) {
if(new->protocol == temp->protocol && (
(new->saddr == temp->saddr && new->daddr == temp->daddr && new->sp == temp->sp && new->dp == temp->dp)
......@@ -490,9 +491,9 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
new->sp = sp;
new->dp = dp;
gettimeofday(&(new->last_timestamp), NULL);
#ifdef __TRACKFLIB_LOGGING__
write_to_log("eDonkey", "No String match", iph->protocol, source, sp, dest, dp, p, len);
#endif
for(temp = edonkeylist[hashval]->head; temp != NULL; temp = temp->next)
{
if(new->protocol == temp->protocol && (
......
......@@ -268,7 +268,9 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
new->sp = sp;
new->dp = dp;
#ifdef __TRACKFLIB_LOGGING__
write_to_log("GNUTELLA", gnutella_strings[i], iph->protocol, source, sp, dest, dp, pkt, len);
#endif
/*
fprintf(fp, "%d---%s:%d -> ", new->protocol, inet_ntoa(source), sp);
fprintf(fp, " %s:%d\t", inet_ntoa(dest), dp);
......
......@@ -265,9 +265,9 @@ static int irc_process(mapidflib_function_instance_t *instance,
new->daddr = daddr;
new->sp = sp;
new->dp = dp;
#ifdef __TRACKFLIB_LOGGING__
write_to_log("IRC", irc_strings[i], iph->protocol, source, sp, dest, dp, p_b, len);
#endif
for(temp = irclist[hashval]->head; temp != NULL; temp = temp->next)
{
......
......@@ -23,6 +23,11 @@ char *get_protocol(int proto);
void renew_log_file(void);
void init_log(void);
// keep onlu last 2 log files in order to debug
char *filename_prev;
char *filename_pprev;
char *filename_cur;
char *get_protocol(int proto) {
if(proto == 6)
return "TCP";
......@@ -34,6 +39,9 @@ char *get_protocol(int proto) {
void init_log()
{
filename_pprev = NULL;
filename_prev = NULL;
filename_cur = NULL;
renew_log_file();
pthread_mutex_init(&log_mutex, NULL);
}
......@@ -45,6 +53,15 @@ void renew_log_file(void)
char filename[50] = "\0";
char *tim = NULL;
DIR *dir = NULL;
char buf[100];
if(filename_pprev != NULL) {
sprintf(buf, "rm %s", filename_pprev);
system(buf);
free(filename_pprev);
}
filename_pprev = filename_prev;
filename_prev = filename_cur;
if(fp != NULL) {
fclose(fp);
......@@ -61,13 +78,14 @@ void renew_log_file(void)
tim[i] = '\0';
if((dir = opendir("log")) == NULL) { // TODO: check all error cases.
system("mkdir log");
if((dir = opendir("/usr/local/mapi/log")) == NULL) { // TODO: check all error cases.
system("mkdir /usr/local/mapi/log");
}
else
closedir(dir);
sprintf(filename, "log/%s.log", tim);
sprintf(filename, "/usr/local/mapi/log/%s.log", tim);
filename_cur = strdup(filename);
fp = fopen(filename, "w");
}
......
#ifndef __TRACKER_LOG__
#define __TRACKER_LOG__
//#define __TRACKFLIB_LOGGING__
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
......
......@@ -324,8 +324,9 @@ static int torrent_process(mapidflib_function_instance_t *instance,
new->sp = sp;
new->dp = dp;
new->byte_counter = 0;
#ifdef __TRACKFLIB_LOGGING__
write_to_log("BitTorrent", torrent_strings[i], iph->protocol, source, sp, dest, dp, p, len);
#endif
/*
if(sp == 22 || dp == 22) {
printf("tcp len: %d %d %d\n", tcph->doff * 4, iph->tot_len ,pkt_head->wlen );
......
......@@ -3,6 +3,7 @@
#define ETHERTYPE_8021Q 0x8100
#define EDONKEY_COLOR 1
#define TORRENT_COLOR 2
#define GNUTELLA_COLOR 3
......
......@@ -207,9 +207,9 @@ static int trackftp_process(mapidflib_function_instance_t *instance,
new->daddr = daddr;
new->sp = sp;
new->dp = dp;
#ifdef __TRACKFLIB_LOGGING__
write_to_log("FTP", "No string", iph->protocol, source, sp, dest, dp, p, len);
#endif
for(temp = cntlist[hashval]->head; temp != NULL; temp = temp->next) {
if(new->protocol == temp->protocol && (
(new->saddr == temp->saddr && new->daddr == temp->daddr && new->sp == temp->sp && new->dp == temp->dp)
......@@ -278,9 +278,9 @@ static int trackftp_process(mapidflib_function_instance_t *instance,
new->daddr = daddr;
new->sp = sp;
new->dp = dp;
#ifdef __TRACKFLIB_LOGGING__
write_to_log("FTP_PASV", "No string", iph->protocol, source, sp, dest, dp, p, len);
#endif
for(temp2 = ftplist[hashval]->head; temp2 != NULL; temp2 = temp2->next) {
if(new->protocol == temp2->protocol && (
(new->saddr == temp2->saddr && new->daddr == temp2->daddr && new->sp == temp2->sp && new->dp == temp2->dp)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment