]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_dns.cpp
Make connect class debug logging more complete and consistent.
[user/henk/code/inspircd.git] / src / coremods / core_dns.cpp
index 002686bc276157eb5b2ef91c8371dce2c88017b5..11c2c823c890b785641c22459b7734ad21c94ff6 100644 (file)
@@ -1,8 +1,10 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2013 Adam <Adam@anope.org>
- *   Copyright (C) 2003-2013 Anope Team <team@anope.org>
+ *   Copyright (C) 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2015, 2017-2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2013, 2015-2016 Adam <Adam@anope.org>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
@@ -36,7 +38,7 @@ namespace DNS
 
 using namespace DNS;
 
-/** A full packet sent or recieved to/from the nameserver
+/** A full packet sent or received to/from the nameserver
  */
 class Packet : public Query
 {
@@ -538,6 +540,25 @@ class MyManager : public Manager, public Timer, public EventHandler
                }
        }
 
+       std::string GetTypeStr(QueryType qt) CXX11_OVERRIDE
+       {
+               switch (qt)
+               {
+                       case QUERY_A:
+                               return "A";
+                       case QUERY_AAAA:
+                               return "AAAA";
+                       case QUERY_CNAME:
+                               return "CNAME";
+                       case QUERY_PTR:
+                               return "PTR";
+                       case QUERY_TXT:
+                               return "TXT";
+                       default:
+                               return "UNKNOWN";
+               }
+       }
+
        void OnEventHandlerError(int errcode) CXX11_OVERRIDE
        {
                ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "UDP socket got an error event");
@@ -661,28 +682,34 @@ class MyManager : public Manager, public Timer, public EventHandler
 
        bool Tick(time_t now) CXX11_OVERRIDE
        {
-               ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "cache: purging DNS cache");
-
+               unsigned long expired = 0;
                for (cache_map::iterator it = this->cache.begin(); it != this->cache.end(); )
                {
                        const Query& query = it->second;
                        if (IsExpired(query, now))
+                       {
+                               expired++;
                                this->cache.erase(it++);
+                       }
                        else
                                ++it;
                }
+
+               if (expired)
+                       ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "cache: purged %lu expired DNS entries", expired);
+
                return true;
        }
 
        void Rehash(const std::string& dnsserver, std::string sourceaddr, unsigned int sourceport)
        {
-               if (this->GetFd() > -1)
+               if (this->HasFd())
                {
                        SocketEngine::Shutdown(this, 2);
                        SocketEngine::Close(this);
 
-                       /* Remove expired entries from the cache */
-                       this->Tick(ServerInstance->Time());
+                       // Remove all entries from the cache.
+                       cache.clear();
                }
 
                irc::sockets::aptosa(dnsserver, DNS::PORT, myserver);
@@ -842,7 +869,7 @@ class ModuleDNS : public Module
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("DNS support", VF_CORE|VF_VENDOR);
+               return Version("Provides support for DNS lookups", VF_CORE|VF_VENDOR);
        }
 };