00001 #ifndef SEQUENCE_TRACKER_CLASS 00002 #define SEQUENCE_TRACKER_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : sequence_tracker * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * Tracks sequence numbers coming from a collection of hosts. These are * 00012 * presumably attached to network packets. The intention is to record if * 00013 * we've already seen a packet or not. When hosts have not communicated for * 00014 * a while, they are removed from tracking. Also, when enough time has * 00015 * elapsed for a sequence number, we consider that we've heard everything * 00016 * we're going to before that sequence number; hence, any prior sequence * 00017 * numbers are considered already received. * 00018 * * 00019 ******************************************************************************* 00020 * Copyright (c) 2002-$now By Author. This program is free software; you can * 00021 * redistribute it and/or modify it under the terms of the GNU General Public * 00022 * License as published by the Free Software Foundation; either version 2 of * 00023 * the License or (at your option) any later version. This is online at: * 00024 * http://www.fsf.org/copyleft/gpl.html * 00025 * Please send any updates to: fred@gruntose.com * 00026 \*****************************************************************************/ 00027 00028 #include "sockets_dll.h" 00029 00030 #include <basis/object_base.h> 00031 00032 // forward. 00033 class host_history; 00034 class machine_uid; 00035 class time_stamp; 00036 00037 class SOCKETS_CLASS_STYLE sequence_tracker : public virtual object_base 00038 { 00039 public: 00040 sequence_tracker(int coalesce_time, int silence_time); 00041 // tracks the sequence numbers from a set of hosts. the "coalesce_time" is 00042 // the interval that we wait before considering all prior sequence numbers 00043 // to have been received. the "silence_time" is the time interval a host 00044 // is allowed to be silent before being eliminated. all measurements are 00045 // in milliseconds. 00046 00047 ~sequence_tracker(); 00048 00049 IMPLEMENT_CLASS_NAME("sequence_tracker"); 00050 00051 void add_pair(const machine_uid &host, int sequence); 00052 // adds a hostname/sequence# pair as being received "now". 00053 00054 bool have_seen(const machine_uid &host, int sequence); 00055 // returns true if the "host" and "sequence" have already been seen in 00056 // a previous transmission. 00057 00058 void clean_up(); 00059 // this must be invoked periodically to allow the clearing of outdated 00060 // information. once a second seems frequent enough. 00061 00062 istring text_form(bool verbose = false) const; 00063 // provides a dump of the information held in the tracker. 00064 00065 private: 00066 int _coalesce_time; // sequences older than this get coalesced. 00067 int _silence_time; // hosts silent for longer than this get canned. 00068 host_history *_hosts; // the overall record of sequence activity per host. 00069 mutex *_lock; // protects from multi-threaded access. 00070 }; 00071 00072 #endif 00073
1.5.1