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
36 * This class represents a list of IPs that should not be accepted
37 * as valid connection destinations nor sources. It provides an
38 * interface to query whether or not a specific IP is filtered.
40 * Currently this class can handle IPRange files in the Peer-Guardian
41 * format and the AntiP2P format, read from either text files or text
42 * files compressed with the zip compression format.
44 * This class is thread-safe.
46 class CIPFilter
: public wxEvtHandler
55 * Checks if a IP is filtered with the current list and AccessLevel.
57 * @param IP2test The IP-Address to test for.
58 * @param isServer Whether this IP belongs to a server or a client. Needed for statistical purposes only.
59 * @return True if it is filtered, false otherwise.
61 * Note: IP2Test must be in anti-host order (BE on LE platform, LE on BE platform).
63 bool IsFiltered( uint32 IP2test
, bool isServer
= false );
66 * Returns the number of banned ranges.
68 uint32
BanCount() const;
71 * Reloads the ipfilter files, discarding the current list of ranges.
76 * Starts a download of the ipfilter-list at the specified URL.
80 * Once the file has been downloaded, the ipfilter.dat file
81 * will be replaced with the new file and Reload will be called.
83 void Update(const wxString
& strURL
);
86 * This function is called when a download is completed.
88 void DownloadFinished(uint32 result
);
91 * True once initial startup has finished (stays true while reloading later).
93 bool IsReady() const { return m_ready
; }
96 * These functions are called to tell the filter to start networks once it
97 * has finished loading.
99 void StartKADWhenReady() { m_startKADWhenReady
= true; }
100 void ConnectToAnyServerWhenReady() { m_connectToAnyServerWhenReady
= true; }
103 /** Handles the result of loading the dat-files. */
104 void OnIPFilterEvent(CIPFilterEvent
&);
106 //! The URL from which the IP filter was downloaded
110 typedef std::vector
<uint32
> RangeIPs
;
112 typedef std::vector
<uint16
> RangeLengths
;
113 RangeLengths m_rangeLengths
;
114 // Name for each range. This usually stays empty for memory reasons,
115 // except if IP-Filter debugging is active.
116 typedef std::vector
<wxString
> RangeNames
;
117 RangeNames m_rangeNames
;
119 //! Mutex used to ensure thread-safety of this class
120 mutable wxMutex m_mutex
;
122 // false if loading (on startup only)
124 // flags to start networks after loading
125 bool m_startKADWhenReady
;
126 bool m_connectToAnyServerWhenReady
;
128 friend class CIPFilterEvent
;
129 friend class CIPFilterTask
;
131 DECLARE_EVENT_TABLE()
135 // File_checked_for_headers