]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: reformat communicator.hh and communicator.cc
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Mon, 18 Dec 2023 13:43:22 +0000 (14:43 +0100)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Thu, 18 Jan 2024 15:23:31 +0000 (16:23 +0100)
.not-formatted
pdns/communicator.cc
pdns/communicator.hh

index 0bd94aae3a20352d6e24f7e724e52e9c6c4b4000..a899bfcadb911225d8327f07cb5fb34f1602da28 100644 (file)
@@ -26,8 +26,6 @@
 ./pdns/cdb.hh
 ./pdns/comfun.cc
 ./pdns/comment.hh
-./pdns/communicator.cc
-./pdns/communicator.hh
 ./pdns/dbdnsseckeeper.cc
 ./pdns/delaypipe.cc
 ./pdns/delaypipe.hh
index 2f43db2873f553242a761de3ff9cd6ab711aaaf3..8834e3a667ca2dc22615763d0cd7b293e1dccd7d 100644 (file)
@@ -43,7 +43,7 @@
 void CommunicatorClass::retrievalLoopThread()
 {
   setThreadName("pdns/comm-retre");
-  for(;;) {
+  for (;;) {
     d_suck_sem.wait();
     SuckRequest sr;
     {
@@ -53,8 +53,8 @@ void CommunicatorClass::retrievalLoopThread()
       }
 
       auto firstItem = data->d_suckdomains.begin();
-        
-      sr=*firstItem;
+
+      sr = *firstItem;
       data->d_suckdomains.erase(firstItem);
       if (data->d_suckdomains.empty()) {
         data->d_sorthelper = 0;
@@ -64,17 +64,17 @@ void CommunicatorClass::retrievalLoopThread()
   }
 }
 
-void CommunicatorClass::loadArgsIntoSet(const char *listname, set<string> &listset)
+void CommunicatorClass::loadArgsIntoSet(const char* listname, set<string>& listset)
 {
   vector<string> parts;
   stringtok(parts, ::arg()[listname], ", \t");
-  for (const auto & part : parts) {
+  for (const auto& part : parts) {
     try {
       ComboAddress caIp(part, 53);
       listset.insert(caIp.toStringWithPort());
     }
-    catch(PDNSException &e) {
-      g_log<<Logger::Error<<"Unparseable IP in "<<listname<<". Error: "<<e.reason<<endl;
+    catch (PDNSException& e) {
+      g_log << Logger::Error << "Unparseable IP in " << listname << ". Error: " << e.reason << endl;
       _exit(1);
     }
   }
@@ -83,18 +83,18 @@ void CommunicatorClass::loadArgsIntoSet(const char *listname, set<string> &lists
 void CommunicatorClass::go()
 {
   try {
-    PacketHandler::s_allowNotifyFrom.toMasks(::arg()["allow-notify-from"] );
+    PacketHandler::s_allowNotifyFrom.toMasks(::arg()["allow-notify-from"]);
   }
-  catch(PDNSException &e) {
-    g_log<<Logger::Error<<"Unparseable IP in allow-notify-from. Error: "<<e.reason<<endl;
+  catch (PDNSException& e) {
+    g_log << Logger::Error << "Unparseable IP in allow-notify-from. Error: " << e.reason << endl;
     _exit(1);
   }
 
-  std::thread mainT([this](){mainloop();});
+  std::thread mainT([this]() { mainloop(); });
   mainT.detach();
 
-  for(int n=0; n < ::arg().asNum("retrieval-threads", 1); ++n) {
-    std::thread retrieve([this](){retrievalLoopThread();});
+  for (int n = 0; n < ::arg().asNum("retrieval-threads", 1); ++n) {
+    std::thread retrieve([this]() { retrievalLoopThread(); });
     retrieve.detach();
   }
 
@@ -108,8 +108,8 @@ void CommunicatorClass::go()
   try {
     d_onlyNotify.toMasks(::arg()["only-notify"]);
   }
-  catch(PDNSException &e) {
-    g_log<<Logger::Error<<"Unparseable IP in only-notify. Error: "<<e.reason<<endl;
+  catch (PDNSException& e) {
+    g_log << Logger::Error << "Unparseable IP in only-notify. Error: " << e.reason << endl;
     _exit(1);
   }
 
@@ -122,7 +122,7 @@ void CommunicatorClass::mainloop()
 {
   try {
     setThreadName("pdns/comm-main");
-    signal(SIGPIPE,SIG_IGN);
+    signal(SIGPIPE, SIG_IGN);
     g_log << Logger::Warning << "Primary/secondary communicator launching" << endl;
 
     d_tickinterval = ::arg().asNum("xfr-cycle-interval");
@@ -133,17 +133,17 @@ void CommunicatorClass::mainloop()
 
     makeNotifySockets();
 
-    for(;;) {
+    for (;;) {
       secondaryRefresh(&P);
       primaryUpdateCheck(&P);
       doNotifications(&P); // this processes any notification acknowledgements and actually send out our own notifications
 
       next = time(nullptr) + d_tickinterval;
 
-      while(time(nullptr) < next) {
-        rc=d_any_sem.tryWait();
+      while (time(nullptr) < next) {
+        rc = d_any_sem.tryWait();
 
-        if(rc) {
+        if (rc) {
           bool extraSecondaryRefresh = false;
           Utility::sleep(1);
           {
@@ -166,17 +166,16 @@ void CommunicatorClass::mainloop()
       }
     }
   }
-  catch(PDNSException &ae) {
-    g_log<<Logger::Error<<"Exiting because communicator thread died with error: "<<ae.reason<<endl;
+  catch (PDNSException& ae) {
+    g_log << Logger::Error << "Exiting because communicator thread died with error: " << ae.reason << endl;
     Utility::sleep(1);
     _exit(1);
   }
-  catch(std::exception &e) {
-    g_log<<Logger::Error<<"Exiting because communicator thread died with STL error: "<<e.what()<<endl;
+  catch (std::exception& e) {
+    g_log << Logger::Error << "Exiting because communicator thread died with STL error: " << e.what() << endl;
     _exit(1);
   }
-  catch( ... )
-  {
+  catch (...) {
     g_log << Logger::Error << "Exiting because communicator caught unknown exception." << endl;
     _exit(1);
   }
index fcb13dd4f90f29e037f1709be0ce033bac09676e..3e06d5359d9f60f42fea2a58a9f4e77e8b4d3a1f 100644 (file)
@@ -46,7 +46,14 @@ struct SuckRequest
   DNSName domain;
   ComboAddress primary;
   bool force;
-  enum RequestPriority : uint8_t { PdnsControl, Api, Notify, SerialRefresh, SignaturesRefresh };
+  enum RequestPriority : uint8_t
+  {
+    PdnsControl,
+    Api,
+    Notify,
+    SerialRefresh,
+    SignaturesRefresh
+  };
   std::pair<RequestPriority, uint64_t> priorityAndOrder;
   bool operator<(const SuckRequest& b) const
   {
@@ -54,30 +61,31 @@ struct SuckRequest
   }
 };
 
-struct IDTag{};
+struct IDTag
+{
+};
 
 typedef multi_index_container<
   SuckRequest,
   indexed_by<
-    ordered_unique<member<SuckRequest,std::pair<SuckRequest::RequestPriority,uint64_t>,&SuckRequest::priorityAndOrder>>,
-    ordered_unique<tag<IDTag>, identity<SuckRequest> >
-  >
-> UniQueue;
+    ordered_unique<member<SuckRequest, std::pair<SuckRequest::RequestPriority, uint64_t>, &SuckRequest::priorityAndOrder>>,
+    ordered_unique<tag<IDTag>, identity<SuckRequest>>>>
+  UniQueue;
 typedef UniQueue::index<IDTag>::type domains_by_name_t;
 
 class NotificationQueue
 {
 public:
-  void add(const DNSName &domain, const string &ip, time_t delay = 0)
+  void add(const DNSName& domain, const string& ip, time_t delay = 0)
   {
     const ComboAddress caIp(ip);
 
     NotificationRequest nr;
-    nr.domain   = domain;
-    nr.ip       = caIp.toStringWithPort();
+    nr.domain = domain;
+    nr.ip = caIp.toStringWithPort();
     nr.attempts = 0;
-    nr.id       = dns_random_uint16();
-    nr.next     = time(nullptr) + delay;
+    nr.id = dns_random_uint16();
+    nr.next = time(nullptr) + delay;
 
     d_nqueue.push_back(nr);
   }
@@ -94,19 +102,19 @@ public:
     return false;
   }
 
-  bool getOne(DNSName &domain, string &ip, uint16_t *id, bool &purged)
+  bool getOne(DNSName& domain, string& ip, uint16_t* id, bool& purged)
   {
-    for(d_nqueue_t::iterator i=d_nqueue.begin();i!=d_nqueue.end();++i)
-      if(i->next <= time(0)) {
+    for (d_nqueue_t::iterator i = d_nqueue.begin(); i != d_nqueue.end(); ++i)
+      if (i->next <= time(0)) {
         i->attempts++;
-        purged=false;
-        i->next=time(0)+1+(1<<i->attempts);
-        domain=i->domain;
-        ip=i->ip;
-        *id=i->id;
-        purged=false;
-        if(i->attempts>4) {
-          purged=true;
+        purged = false;
+        i->next = time(0) + 1 + (1 << i->attempts);
+        domain = i->domain;
+        ip = i->ip;
+        *id = i->id;
+        purged = false;
+        if (i->attempts > 4) {
+          purged = true;
           d_nqueue.erase(i);
         }
         return true;
@@ -116,10 +124,10 @@ public:
 
   time_t earliest()
   {
-    time_t early=std::numeric_limits<time_t>::max() - 1;
-    for(d_nqueue_t::const_iterator i=d_nqueue.begin();i!=d_nqueue.end();++i)
-      early=min(early,i->next);
-    return early-time(0);
+    time_t early = std::numeric_limits<time_t>::max() - 1;
+    for (d_nqueue_t::const_iterator i = d_nqueue.begin(); i != d_nqueue.end(); ++i)
+      early = min(early, i->next);
+    return early - time(0);
   }
 
   void dump();
@@ -136,7 +144,6 @@ private:
 
   typedef std::list<NotificationRequest> d_nqueue_t;
   d_nqueue_t d_nqueue;
-
 };
 
 struct ZoneStatus;
@@ -149,36 +156,36 @@ class CommunicatorClass
 public:
   CommunicatorClass()
   {
-    d_tickinterval=60;
+    d_tickinterval = 60;
     d_secondarieschanged = true;
     d_nsock4 = -1;
     d_nsock6 = -1;
     d_preventSelfNotification = false;
   }
-  time_t doNotifications(PacketHandler *P);
+  time_t doNotifications(PacketHandlerP);
   void go();
 
-
-  void drillHole(const DNSName &domain, const string &ip);
-  bool justNotified(const DNSName &domain, const string &ip);
+  void drillHole(const DNSName& domain, const string& ip);
+  bool justNotified(const DNSName& domain, const string& ip);
   void addSuckRequest(const DNSName& domain, const ComboAddress& primary, SuckRequest::RequestPriority, bool force = false);
   void addSecondaryCheckRequest(const DomainInfo& di, const ComboAddress& remote);
   void addTryAutoPrimaryRequest(const DNSPacket& p);
-  void notify(const DNSName &domain, const string &ip);
+  void notify(const DNSName& domain, const string& ip);
   void mainloop();
   void retrievalLoopThread();
-  void sendNotification(int sock, const DNSName &domain, const ComboAddress& remote, uint16_t id, UeberBackend* B);
-  bool notifyDomain(const DNSName &domain, UeberBackend* B);
-  vector<pair<DNSName, ComboAddress> > getSuckRequests();
+  void sendNotification(int sock, const DNSNamedomain, const ComboAddress& remote, uint16_t id, UeberBackend* B);
+  bool notifyDomain(const DNSNamedomain, UeberBackend* B);
+  vector<pair<DNSName, ComboAddress>> getSuckRequests();
   size_t getSuckRequestsWaiting();
+
 private:
-  void loadArgsIntoSet(const char *listname, set<string> &listset);
+  void loadArgsIntoSet(const char* listname, set<string>& listset);
   void makeNotifySockets();
   void queueNotifyDomain(const DomainInfo& di, UeberBackend* B);
   int d_nsock4, d_nsock6;
-  LockGuarded<map<pair<DNSName,string>,time_t>> d_holes;
+  LockGuarded<map<pair<DNSName, string>, time_t>> d_holes;
 
-  void suck(const DNSName &domain, const ComboAddress& remote, bool force=false);
+  void suck(const DNSName& domain, const ComboAddress& remote, bool force = false);
   void ixfrSuck(const DNSName& domain, const TSIGTriplet& tt, const ComboAddress& laddr, const ComboAddress& remote, ZoneStatus& zs, vector<DNSRecord>* axfr);
 
   void secondaryRefresh(PacketHandler* P);
@@ -204,8 +211,10 @@ private:
     set<DNSName> d_inprogress;
 
     set<DomainInfo> d_tocheck;
-    struct cmp {
-      bool operator()(const DNSPacket& a, const DNSPacket& b) const {
+    struct cmp
+    {
+      bool operator()(const DNSPacket& a, const DNSPacket& b) const
+      {
         return a.qdomain < b.qdomain;
       };
     };
@@ -222,7 +231,8 @@ private:
 
   struct RemoveSentinel
   {
-    explicit RemoveSentinel(const DNSName& dn, CommunicatorClass* cc) : d_dn(dn), d_cc(cc)
+    explicit RemoveSentinel(const DNSName& dn, CommunicatorClass* cc) :
+      d_dn(dn), d_cc(cc)
     {}
 
     ~RemoveSentinel()
@@ -230,31 +240,30 @@ private:
       try {
         d_cc->d_data.lock()->d_inprogress.erase(d_dn);
       }
-      catch(...) {
+      catch (...) {
       }
     }
     DNSName d_dn;
     CommunicatorClass* d_cc;
-};
-
+  };
 };
 
 // class that one day might be more than a function to help you get IP addresses for a nameserver
 class FindNS
 {
 public:
-  vector<string> lookup(const DNSName &name, UeberBackend *b)
+  vector<string> lookup(const DNSName& name, UeberBackend* b)
   {
     vector<string> addresses;
 
     this->resolve_name(&addresses, name);
 
-    if(b) {
-        b->lookup(QType(QType::ANY),name,-1);
-        DNSZoneRecord rr;
-        while(b->get(rr))
-          if(rr.dr.d_type == QType::A || rr.dr.d_type==QType::AAAA)
-            addresses.push_back(rr.dr.getContent()->getZoneRepresentation());   // SOL if you have a CNAME for an NS
+    if (b) {
+      b->lookup(QType(QType::ANY), name, -1);
+      DNSZoneRecord rr;
+      while (b->get(rr))
+        if (rr.dr.d_type == QType::A || rr.dr.d_type == QType::AAAA)
+          addresses.push_back(rr.dr.getContent()->getZoneRepresentation()); // SOL if you have a CNAME for an NS
     }
     return addresses;
   }
@@ -266,18 +275,18 @@ private:
     struct addrinfo hints;
     memset(&hints, 0, sizeof(hints));
     hints.ai_socktype = SOCK_DGRAM; // otherwise we get everything in triplicate (!)
-    for(int n = 0; n < 2; ++n) {
+    for (int n = 0; n < 2; ++n) {
       hints.ai_family = n ? AF_INET : AF_INET6;
       ComboAddress remote;
       remote.sin4.sin_family = AF_INET6;
-      if(!getaddrinfo(name.toString().c_str(), 0, &hints, &res)) {
+      if (!getaddrinfo(name.toString().c_str(), 0, &hints, &res)) {
         struct addrinfo* address = res;
         do {
           if (address->ai_addrlen <= sizeof(remote)) {
             remote.setSockaddr(address->ai_addr, address->ai_addrlen);
             addresses->push_back(remote.toString());
           }
-        } while((address = address->ai_next));
+        } while ((address = address->ai_next));
         freeaddrinfo(res);
       }
     }