Fix compilation with wxWidgets 2.8.12
[amule.git] / src / IPFilter.h
blob78b6958dc73158a84721f6d81f967375d4c6e524
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 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.
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 IPFILTER_H
27 #define IPFILTER_H
29 #include <wx/event.h> // Needed for wxEvent
31 #include "Types.h" // Needed for uint8, uint16 and uint32
33 class CIPFilterEvent;
35 /**
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
48 public:
49 /**
50 * Constructor.
52 CIPFilter();
54 /**
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 );
65 /**
66 * Returns the number of banned ranges.
68 uint32 BanCount() const;
70 /**
71 * Reloads the ipfilter files, discarding the current list of ranges.
73 void Reload();
75 /**
76 * Starts a download of the ipfilter-list at the specified URL.
78 * @param A valid 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);
85 /**
86 * This function is called when a download is completed.
88 void DownloadFinished(uint32 result);
90 /**
91 * True once initial startup has finished (stays true while reloading later).
93 bool IsReady() const { return m_ready; }
95 /**
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; }
102 private:
103 /** Handles the result of loading the dat-files. */
104 void OnIPFilterEvent(CIPFilterEvent&);
106 //! The URL from which the IP filter was downloaded
107 wxString m_URL;
109 // The IP ranges
110 typedef std::vector<uint32> RangeIPs;
111 RangeIPs m_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<std::string> 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)
123 bool m_ready;
124 // flags to start networks after loading
125 bool m_startKADWhenReady;
126 bool m_connectToAnyServerWhenReady;
127 // should update be performed after filter is loaded ?
128 bool m_updateAfterLoading;
130 friend class CIPFilterEvent;
131 friend class CIPFilterTask;
133 DECLARE_EVENT_TABLE()
136 #endif
137 // File_checked_for_headers