+SecurityIPResolver::SecurityIPResolver(Module* me, SpanningTreeUtilities* U, DNS::Manager *mgr, const std::string &hostname, Link* x, DNS::QueryType qt)
+ : DNS::Request(mgr, me, hostname, qt), MyLink(x), Utils(U), mine(me), host(hostname), query(qt)
+{
+}
+
+void SecurityIPResolver::OnLookupComplete(const DNS::Query *r)
+{
+ const DNS::ResourceRecord &ans_record = r->answers[0];
+
+ for (std::vector<reference<Link> >::iterator i = Utils->LinkBlocks.begin(); i != Utils->LinkBlocks.end(); ++i)
+ {
+ Link* L = *i;
+ if (L->IPAddr == host)
+ {
+ Utils->ValidIPs.push_back(ans_record.rdata);
+ break;
+ }
+ }
+}
+
+void SecurityIPResolver::OnError(const DNS::Query *r)
+{
+ if (query == DNS::QUERY_AAAA)
+ {
+ SecurityIPResolver* res = new SecurityIPResolver(mine, Utils, this->manager, host, MyLink, DNS::QUERY_A);
+ try
+ {
+ this->manager->Process(res);
+ return;
+ }
+ catch (DNS::Exception &)
+ {
+ delete res;
+ }
+ }
+ ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Could not resolve IP associated with Link '%s': %s",
+ MyLink->Name.c_str(), this->manager->GetErrorStr(r->error).c_str());
+}
+
+CacheRefreshTimer::CacheRefreshTimer(SpanningTreeUtilities* Util)
+ : Timer(3600, ServerInstance->Time(), true), Utils(Util)
+{
+}
+
+bool CacheRefreshTimer::Tick(time_t TIME)
+{
+ Utils->RefreshIPCache();
+ return true;
+}