From: bert hubert Date: Tue, 19 Jan 2016 14:44:33 +0000 (+0100) Subject: add an efficient ComboAddress set (loads around a million IP addresses per second) X-Git-Tag: dnsdist-1.0.0-alpha2~53^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=08dcccd6c5bd3559c8017ea5a462d6752e0f845f;p=pdns add an efficient ComboAddress set (loads around a million IP addresses per second) --- diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index c1312abf3..b701cf4ba 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -5,6 +5,7 @@ #include "syncres.hh" #include "namespaces.hh" #include "rec_channel.hh" +#include #if !defined(HAVE_LUA) RecursorLua4::RecursorLua4(const std::string &fname) @@ -193,6 +194,32 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_lw->registerFunction("getPort", [](const ComboAddress& ca) { return ntohs(ca.sin4.sin_port); } ); d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); }); + typedef std::unordered_set cas_t; + d_lw->writeFunction("newCAS", []{ return cas_t(); }); + + + d_lw->registerFunction > >)>("add", + [](cas_t& cas, const boost::variant > >& in) + { + try { + if(auto s = boost::get(&in)) { + cas.insert(ComboAddress(*s)); + } + else if(auto v = boost::get > >(&in)) { + for(const auto& s : *v) + cas.insert(ComboAddress(s.second)); + } + else + cas.insert(boost::get(in)); + } + catch(std::exception& e) { theL() <registerFunction("check",[](const cas_t& cas, const ComboAddress&ca) { + return (bool)cas.count(ca); + }); + + d_lw->registerFunction("equal", [](const ComboAddress& lhs, const ComboAddress& rhs) { return ComboAddress::addressOnlyEqual()(lhs, rhs); @@ -224,6 +251,7 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_lw->registerFunction("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = shared_ptr(DNSRecordContent::mastermake(dr.d_type, 1, newContent)); }); d_lw->registerFunction("addAnswer", &DNSQuestion::addAnswer); + d_lw->registerFunction("addRecord", &DNSQuestion::addRecord); d_lw->registerFunction("getRecords", &DNSQuestion::getRecords); d_lw->registerFunction("setRecords", &DNSQuestion::setRecords); @@ -242,7 +270,7 @@ RecursorLua4::RecursorLua4(const std::string& fname) else smn.add(boost::get(in)); } - catch(std::exception& e) { cerr<registerFunction("check",(bool (SuffixMatchNode::*)(const DNSName&) const) &SuffixMatchNode::check);