Skip to content

Commit

Permalink
Make interval in which FTL stores queries in the long term database e…
Browse files Browse the repository at this point in the history
…asily adjustable via the config file.

Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Dec 12, 2017
1 parent 888bda2 commit 06b9e02
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 1 addition & 4 deletions FTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
// Default -60 (one minute before a full hour)
#define GCdelay (-60)

// How often do we dump into FTL's database?
// Default: 60 (once per minute)
#define DBinterval 60

// Static structs
typedef struct {
const char* conf;
Expand Down Expand Up @@ -125,6 +121,7 @@ typedef struct {
int maxDBdays;
bool resolveIPv6;
bool resolveIPv4;
int DBinterval;
} ConfigStruct;

// Dynamic structs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Possible settings (**the option shown first is the default**):
- `MAXDBDAYS=365` (How long should queries be stored in the database? Setting this to `0` disables the database altogether)
- `RESOLVE_IPV6=yes|no` (Should `FTL` try to resolve IPv6 addresses to host names?)
- `RESOLVE_IPV4=yes|no` (Should `FTL` try to resolve IPv4 addresses to host names?)
- `DBINTERVAL=1.0` (How often do we store queries in FTL's database [minutes]?)

### Implemented keywords (starting with `>`, subject to change):

Expand Down
20 changes: 20 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ void read_FTLconf(void)
else
logg(" RESOLVE_IPV4: Don\'t resolve IPv4 addresses");

// DBINTERVAL
// How often do we store queries in FTL's database [minutes]?
// this value can be a floating point number, e.g. "DBINTERVAL=0.5"
// defaults to: 1 (once per minute)
config.DBinterval = 1;
buffer = parse_FTLconf(fp, "DBINTERVAL");

float fvalue = 0;
if(buffer != NULL && sscanf(buffer, "%f", &fvalue))
// check if the read value is
// - larger than 0.1min (6sec), and
// - smaller than 43200 (once a month)
if(fvalue >= 0.1 && fvalue <= 43200.0)
config.DBinterval = (int)(60.*fvalue);

if(config.DBinterval == 60)
logg(" DBINTERVAL: saving to DB file every minute");
else
logg(" DBINTERVAL: saving to DB file every %i seconds", config.DBinterval);

logg("Finished config file parsing");

if(conflinebuffer != NULL)
Expand Down
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main (int argc, char* argv[]) {
if(((time(NULL) - GCdelay)%GCinterval) == 0)
runGCthread = true;

if(database && ((time(NULL)%DBinterval) == 0))
if(database && ((time(NULL)%config.DBinterval) == 0))
runDBthread = true;

// Garbadge collect in regular interval, but don't do it if the threadlocks is set
Expand Down Expand Up @@ -134,7 +134,7 @@ int main (int argc, char* argv[]) {
}

// Avoid immediate re-run of DB thread
while(((time(NULL)%DBinterval) == 0))
while(((time(NULL)%config.DBinterval) == 0))
sleepms(100);
}

Expand Down

0 comments on commit 06b9e02

Please sign in to comment.