Changeset 1459

Show
Ignore:
Timestamp:
07/12/05 12:16:07 (3 years ago)
Author:
madcat
Message:

guarding.p2p ipfilter format support.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hydranode/include/hn/ipfilter.h

    r859 r1459  
    3333 * filtering ip addresses. 
    3434 */ 
    35 class IpFilterBase { 
     35class DLLEXPORT IpFilterBase { 
    3636public: 
    3737        IpFilterBase(); 
     
    4848}; 
    4949 
    50 class IpFilter : public IpFilterBase { 
     50class DLLEXPORT IpFilter : public IpFilterBase { 
    5151public: 
    5252        IpFilter(); 
     
    6060        void parseMldonkeyLine(const std::string &buf); 
    6161        void parseMuleLine(const std::string &buf); 
     62        void parseGuardianLine(const std::string &buf); 
     63 
    6264        ParseFunc getParseFunc(const std::string &buf); 
    6365        std::auto_ptr<RangeList<Range<uint32_t> > > m_list; 
  • hydranode/src/ipfilter.cpp

    r1440 r1459  
    5555 
    5656        ParseFunc parseFunc = getParseFunc(buf); 
     57        if (!parseFunc) { 
     58                throw std::runtime_error("unknown ipfilter format"); 
     59        } 
     60         
    5761        ifs.seekg(0); 
     62        m_list->clear(); 
    5863 
    5964        uint32_t line = 0; 
     
    8893        logMsg(fmt % s1 % m_list->size()); 
    8994} 
    90 IpFilter::ParseFunc IpFilter::getParseFunc(const std::string &buf) try { 
    91         CHECK_THROW(buf.size() >= 4); 
    92         boost::lexical_cast<uint32_t>(buf.substr(0, 3)); 
    93         logDebug("eMule format IPFilter detected."); 
    94         return boost::bind(&IpFilter::parseMuleLine, this, _b1); 
    95 } catch (boost::bad_lexical_cast&) { 
    96         logDebug("MLDonkey format IPFilter detected."); 
    97         return boost::bind(&IpFilter::parseMldonkeyLine, this, _b1); 
     95 
     96IpFilter::ParseFunc IpFilter::getParseFunc(const std::string &buf) { 
     97        try { 
     98                CHECK_THROW(buf.size() >= 4); 
     99                parseMuleLine(buf); 
     100                logDebug("eMule format IPFilter detected."); 
     101                return boost::bind(&IpFilter::parseMuleLine, this, _b1); 
     102        } catch (...) {} 
     103 
     104        try { 
     105                parseMldonkeyLine(buf); 
     106                logDebug("MLDonkey format IPFilter detected."); 
     107                return boost::bind(&IpFilter::parseMldonkeyLine, this, _b1); 
     108        } catch (...) {} 
     109 
     110        try { 
     111                parseGuardianLine(buf); 
     112                logDebug("GuardianP2P format IPFilter detected."); 
     113                return boost::bind(&IpFilter::parseGuardianLine, this, _b1); 
     114        } catch (...) {} 
     115 
     116        return 0; 
    98117} 
    99118 
     
    135154} 
    136155 
     156void IpFilter::parseGuardianLine(const std::string &buf) { 
     157        if (buf[0] == '#') { 
     158                return; 
     159        } 
     160 
     161        size_t i = buf.find_first_of(','); 
     162        if (i == std::string::npos) { 
     163                throw ParseError("Expected ',' token."); 
     164        } 
     165        if (parse(buf.substr(0, i).c_str(), parse_one >> '-' >> parse_two).full) { 
     166                m_list->push(one, two); 
     167        } else { 
     168                throw ParseError("unknown error"); 
     169        } 
     170} 
     171 
    137172bool IpFilter::isAllowed(uint32_t ip) { 
    138173        return !m_list->contains(SWAP32_ON_LE(ip));