2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-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
29 #include <wx/event.h> // Needed for wxEvent
31 #include "Types.h" // Needed for uint8, uint16 and uint32
32 #include "RangeMap.h" // Needed for CRangeMap
39 * This class represents a list of IPs that should not be accepted
40 * as valid connection destinations nor sources. It provides an
41 * interface to query whether or not a specific IP is filtered.
43 * Currently this class can handle IPRange files in the Peer-Guardian
44 * format and the AntiP2P format, read from either text files or text
45 * files compressed with the zip compression format.
47 * This class is thread-safe.
49 class CIPFilter
: public wxEvtHandler
58 * Checks if a IP is filtered with the current list and AccessLevel.
60 * @param IP2test The IP-Address to test for.
61 * @param isServer Whether this IP belongs to a server or a client. Needed for statistical purposes only.
62 * @return True if it is filtered, false otherwise.
64 * Note: IP2Test must be in anti-host order (BE on LE platform, LE on BE platform).
66 bool IsFiltered( uint32 IP2test
, bool isServer
= false );
70 * Returns the number of banned ranges.
72 uint32
BanCount() const;
75 * Reloads the ipfilter files, discarding the current list of ranges.
80 * Starts a download of the ipfilter-list at the specified URL.
84 * Once the file has been downloaded, the ipfilter.dat file
85 * will be replaced with the new file and Reload will be called.
87 void Update(const wxString
& strURL
);
90 * This function is called when a download is completed.
92 void DownloadFinished(uint32 result
);
95 /** Handles the result of loading the dat-files. */
96 void OnIPFilterEvent(CIPFilterEvent
&);
99 * This structure is used to contain the range-data in the rangemap.
103 bool operator==( const rangeObject
& other
) const {
104 return AccessLevel
== other
.AccessLevel
;
107 // Since descriptions are only used for debugging messages, there
108 // is no need to keep them in memory when running a non-debug build.
110 //! Contains the user-description of the range.
111 wxString Description
;
114 //! The AccessLevel for this filter.
119 //! The is the type of map used to store the IPs.
120 typedef CRangeMap
<rangeObject
, uint32
> IPMap
;
122 //! The map of IP-ranges
125 //! Mutex used to ensure thread-safety of this class
126 mutable wxMutex m_mutex
;
128 friend class CIPFilterEvent
;
129 friend class CIPFilterTask
;
131 DECLARE_EVENT_TABLE()
135 // File_checked_for_headers