Changeset 3001
- Timestamp:
- 06/04/06 09:11:45 (3 years ago)
- Files:
-
- hydranode/hncore/hydranode.cpp (modified) (4 diffs)
- hydranode/hncore/hydranode.h (modified) (4 diffs)
- hydranode/hncore/ipfilter.cpp (modified) (1 diff)
- hydranode/hncore/ipfilter.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hydranode/hncore/hydranode.cpp
r2990 r3001 259 259 boost::format("Incoming files directory: %s") % incDir.string() 260 260 ); 261 262 Prefs::instance().valueChanged.connect( 263 boost::bind(&Hydranode::configChanged, this, _1, _2) 264 ); 261 265 } 262 266 … … 296 300 (void)SchedBase::instance().init(); 297 301 (void)DNS::ResolverThread::instance(); 302 SchedBase::instance().isAllowed.connect( 303 boost::bind(&IpFilter::isAllowed, &m_ipFilter, _1) 304 ); 298 305 299 306 std::string fName= Prefs::instance().read<std::string>("/IPFilter", ""); … … 304 311 } 305 312 313 // this triggers Config::valueChanged signal, which is handled by 314 // Hydranode::configChanged and (re)loads the filter. 306 315 Prefs::instance().write<std::string>("/IPFilter", fName); 307 308 IpFilter *flt = new IpFilter; // Note: this isn't deleted anywhere atm309 310 if (!boost::filesystem::path(fName).is_complete()) {311 fName = (getConfigDir()/fName).native_file_string();312 }313 if (fName.size()) try {314 flt->load(fName);315 SchedBase::instance().isAllowed.connect(316 boost::bind(&IpFilter::isAllowed, flt, _1)317 );318 } catch (std::exception &e) {319 logError(320 boost::format("Failed to load IPFilter: %s") % e.what()321 );322 delete flt;323 }324 316 } 325 317 … … 718 710 return m_lastTotalDown + SchedBase::instance().getTotalDownstream(); 719 711 } 712 713 void Hydranode::configChanged(const std::string &key, const std::string &val) { 714 if (key == "IPFilter") { 715 if (!val.size()) { 716 m_ipFilter.clear(); 717 return; 718 } 719 std::string fName = val; 720 if (!boost::filesystem::path(fName).is_complete()) { 721 fName = (getConfigDir()/fName).native_file_string(); 722 } 723 if (fName.size()) try { 724 m_ipFilter.clear(); 725 m_ipFilter.load(fName); 726 } catch (std::exception &e) { 727 logError( 728 boost::format("Failed to load IPFilter: %s") 729 % e.what() 730 ); 731 } 732 } 733 } hydranode/hncore/hydranode.h
r2799 r3001 100 100 #include <hnbase/object.h> // Object 101 101 #include <hnbase/config.h> // Config 102 #include <hncore/ipfilter.h> // IpFilter 102 103 #include <boost/filesystem/path.hpp> // getConfigDir() return val 103 104 … … 250 251 * @returns Application runtime (session), in milliseconds. 251 252 */ 252 uint64_t getRuntime() const { 253 return EventMain::instance().getTick() - getStartTime(); 253 uint64_t getRuntime() const { 254 return EventMain::instance().getTick() - getStartTime(); 254 255 } 255 256 … … 283 284 ); 284 285 286 /** 287 * Signal handler for configuration changes on runtime 288 */ 289 void configChanged(const std::string &key, const std::string &val); 290 285 291 //! Keeps track if we are running. 286 292 bool m_running; … … 297 303 //! configuration file that stores statistics data 298 304 Config m_stats; 305 306 //! IP filter blacklist 307 IpFilter m_ipFilter; 299 308 300 309 //! Modules to auto-load on startup (filled from commandline) hydranode/hncore/ipfilter.cpp
r2613 r3001 185 185 return !m_list->contains(Range32(SWAP32_ON_LE(ip))); 186 186 } 187 188 void IpFilter::clear() { 189 m_list->clear(); 190 logMsg("Ip filter cleared."); 191 } hydranode/hncore/ipfilter.h
r2613 r3001 55 55 virtual bool isAllowed(uint32_t ip); 56 56 void load(const std::string &file); 57 void clear(); 57 58 private: 58 59 typedef std::runtime_error ParseError;
