2 // This file is part of the aMule Project.
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 )
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
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.
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
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.
56 * @param isGlobal Specifies if the list is global or not, used for debugging.
58 CDeadSourceList(bool isGlobal
= false);
62 * Adds a client to the list of dead sources.
64 void AddDeadSource(const CUpDownClient
* client
);
67 * Returns true if the client object is a dead source.
69 bool IsDeadSource(const CUpDownClient
* client
);
73 * Returns the number of sources.
75 uint32
GetDeadSourcesCount() const;
79 * Removes too old entries from the list.
85 * Record of dead source.
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.
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
);
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;
124 //! The ID/IP of the client.
126 //! The TCP port of the client
128 //! The Kad port of the client.
130 //! The IP of the server the client is connected to.
132 //! The timestamp of DOOM!
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.
151 // File_checked_for_headers