Improve speed of category tab title updates
[amule.git] / src / DeadSourceList.h
blob0140172c980a12a264d50822b12ffa5f9637b278
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2005-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef DEADSOURCELIST_H
27 #define DEADSOURCELIST_H
30 #include <map>
32 #include "Types.h"
35 class CUpDownClient;
38 /**
39 * This class keeps track of "invalid" sources.
41 * A dead source is a source that has been evaluated as being useles
42 * which can be due to serveral reasons, such as not responding to
43 * queries. This list then allows for those sources to be ignored
44 * for an set ammount of time in order to avoid the overhead of
45 * trying to connect to them.
47 * This is important, since these sources would be removed and readded
48 * repeatedly, causing extra overhead with no gain.
50 class CDeadSourceList
52 public:
53 /**
54 * Constructor.
56 * @param isGlobal Specifies if the list is global or not, used for debugging.
58 CDeadSourceList(bool isGlobal = false);
61 /**
62 * Adds a client to the list of dead sources.
64 void AddDeadSource(const CUpDownClient* client);
66 /**
67 * Returns true if the client object is a dead source.
69 bool IsDeadSource(const CUpDownClient* client);
72 /**
73 * Returns the number of sources.
75 uint32 GetDeadSourcesCount() const;
77 private:
78 /**
79 * Removes too old entries from the list.
81 void CleanUp();
84 /**
85 * Record of dead source.
87 class CDeadSource
89 public:
90 /**
91 * Constructor.
93 * @param ID The IP/ID of the recorded client.
94 * @param Port The TCP port of the recorded client.
95 * @param ServerIP The ip of the connected server.
96 * @param KadPort The Kad port used by the client.
98 * Notes:
99 * * ID must be specified.
100 * * Either KadPort or Port must be specified.
101 * * For lowid sources, ServerIP must be specified.
104 CDeadSource(uint32 ID, uint16 Port, uint32 ServerIP, uint16 KadPort);
108 * Equality operator.
110 bool operator==(const CDeadSource& other) const;
114 * Sets the timestamp for the time where this entry will expire.
116 void SetTimeout( uint32 t );
119 * Returns the timestamp of this entry.
121 uint32 GetTimeout() const;
123 private:
124 //! The ID/IP of the client.
125 uint32 m_ID;
126 //! The TCP port of the client
127 uint16 m_Port;
128 //! The Kad port of the client.
129 uint16 m_KadPort;
130 //! The IP of the server the client is connected to.
131 uint32 m_ServerIP;
132 //! The timestamp of DOOM!
133 uint32 m_TimeStamp;
137 typedef std::multimap< uint32, CDeadSource > DeadSourceMap;
138 typedef DeadSourceMap::iterator DeadSourceIterator;
139 typedef std::pair<DeadSourceIterator, DeadSourceIterator> DeadSourcePair;
140 //! List of currently dead sources.
141 DeadSourceMap m_sources;
144 //! The timestamp of when the last cleanup was performed.
145 uint32 m_dwLastCleanUp;
146 //! Specifies if the list is global or not.
147 bool m_bGlobalList;
150 #endif
151 // File_checked_for_headers