From: Bjoern Sikora Date: Wed, 6 Oct 2010 14:22:49 +0000 (+0200) Subject: Expire old entries in LastUpdates of each service. X-Git-Tag: v1.1~80 X-Git-Url: http://developer.intra2net.com/git/?p=bpdyndnsd;a=commitdiff_plain;h=fc61394289fcba0f1136c6986625f67be4a705a0 Expire old entries in LastUpdates of each service. --- diff --git a/src/service.cpp b/src/service.cpp index 0a6a29e..0294615 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -235,7 +235,7 @@ void Service::update(const string& ip, const time_t current_time) if ( perform_update(ip) == 0 ) { // if update was successful, we need to set the Lastupdated and ActualIP base member. - LastUpdates.push_front(current_time); + set_last_update(current_time); ActualIP = ip; Log->print_update_service_successful(get_service_name()); } @@ -249,6 +249,43 @@ void Service::update(const string& ip, const time_t current_time) /** +* Sets the given time into the LastUpdates member and deletes expired entries. +* @param _timeout Value to set into LastUpdates. +*/ +void Service::set_last_update(const time_t current_time) +{ + // Insert value into the list. + LastUpdates.push_front(current_time); + + // Check for expired entries: + + // MaxUpdatesWithinInterval given in service config, then use this to check for expired entries. + if ( MaxUpdatesWithinInterval > 0 ) + { + // Delete the oldest entry if there are more than MaxUpdatesWithinInterval+1 entries in the list. + if (LastUpdates.size() > (MaxUpdatesWithinInterval+1)) + LastUpdates.pop_back(); + return; + } + // UpdateInterval given in service config, then use this to check for expired entries. + else if ( UpdateInterval > 0 ) + { + // Delete the oldest entry if it's older than current_time - UpdateInterval(minutes) + 1. + if ( (current_time - ((time_t)UpdateInterval*60) + 1) > LastUpdates.back() ) + LastUpdates.pop_back(); + return; + } + // Neither MaxUpdatesWithinInterval nor UpdateInterval are given, so keep fix number of 10 entries. + else + { + if ( LastUpdates.size() > 10 ) + LastUpdates.pop_back(); + return; + } +} + + +/** * Setter for member Timeout. * @param _timeout Value to set Timeout to. */ diff --git a/src/service.hpp b/src/service.hpp index dcec4b9..3b460e2 100644 --- a/src/service.hpp +++ b/src/service.hpp @@ -70,6 +70,8 @@ public: bool update_allowed(const time_t current_time); + void set_last_update(const time_t current_time); + int get_update_interval()const; void set_update_interval(const int _update_interval);