Changeset 3001

Show
Ignore:
Timestamp:
06/04/06 09:11:45 (3 years ago)
Author:
madcat
Message:

Reacts to IPFilter config value changes on runtime, allowing reloading IPFilter on runtime (ticket #277)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hydranode/hncore/hydranode.cpp

    r2990 r3001  
    259259                boost::format("Incoming files directory:  %s") % incDir.string() 
    260260        ); 
     261 
     262        Prefs::instance().valueChanged.connect( 
     263                boost::bind(&Hydranode::configChanged, this, _1, _2) 
     264        ); 
    261265} 
    262266 
     
    296300        (void)SchedBase::instance().init(); 
    297301        (void)DNS::ResolverThread::instance(); 
     302        SchedBase::instance().isAllowed.connect( 
     303                boost::bind(&IpFilter::isAllowed, &m_ipFilter, _1) 
     304        ); 
    298305 
    299306        std::string fName= Prefs::instance().read<std::string>("/IPFilter", ""); 
     
    304311        } 
    305312 
     313        // this triggers Config::valueChanged signal, which is handled by 
     314        // Hydranode::configChanged and (re)loads the filter. 
    306315        Prefs::instance().write<std::string>("/IPFilter", fName); 
    307  
    308         IpFilter *flt = new IpFilter; // Note: this isn't deleted anywhere atm 
    309  
    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         } 
    324316} 
    325317 
     
    718710        return m_lastTotalDown + SchedBase::instance().getTotalDownstream(); 
    719711} 
     712 
     713void 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  
    100100#include <hnbase/object.h>                       // Object 
    101101#include <hnbase/config.h>                       // Config 
     102#include <hncore/ipfilter.h>                     // IpFilter 
    102103#include <boost/filesystem/path.hpp>             // getConfigDir() return val 
    103104 
     
    250251         * @returns Application runtime (session), in milliseconds. 
    251252         */ 
    252         uint64_t getRuntime() const {  
    253                 return EventMain::instance().getTick() - getStartTime();  
     253        uint64_t getRuntime() const { 
     254                return EventMain::instance().getTick() - getStartTime(); 
    254255        } 
    255256 
     
    283284        ); 
    284285 
     286        /** 
     287         * Signal handler for configuration changes on runtime 
     288         */ 
     289        void configChanged(const std::string &key, const std::string &val); 
     290 
    285291        //! Keeps track if we are running. 
    286292        bool m_running; 
     
    297303        //! configuration file that stores statistics data 
    298304        Config m_stats; 
     305 
     306        //! IP filter blacklist 
     307        IpFilter m_ipFilter; 
    299308 
    300309        //! Modules to auto-load on startup (filled from commandline) 
  • hydranode/hncore/ipfilter.cpp

    r2613 r3001  
    185185        return !m_list->contains(Range32(SWAP32_ON_LE(ip))); 
    186186} 
     187 
     188void IpFilter::clear() { 
     189        m_list->clear(); 
     190        logMsg("Ip filter cleared."); 
     191} 
  • hydranode/hncore/ipfilter.h

    r2613 r3001  
    5555        virtual bool isAllowed(uint32_t ip); 
    5656        void load(const std::string &file); 
     57        void clear(); 
    5758private: 
    5859        typedef std::runtime_error ParseError;