2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 PowerDNS.COM BV
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef PDNS_COMMUNICATOR_HH
20 #define PDNS_COMMUNICATOR_HH
24 #include <semaphore.h>
35 #include "packethandler.hh"
45 class NotificationQueue
48 void add(const string &domain, const string &ip)
50 NotificationRequest nr;
54 nr.id = Utility::random()%0xffff;
57 d_nqueue.push_back(nr);
60 bool removeIf(const string &remote, u_int16_t id, const string &domain)
62 for(d_nqueue_t::iterator i=d_nqueue.begin();i!=d_nqueue.end();++i) {
63 cout<<i->id<<" "<<id<<endl;
64 cout<<i->ip<<" "<<remote<<endl;
65 cout<<i->domain<<" "<<domain<<endl;
67 if(i->id==id && i->ip==remote && i->domain==domain) {
75 bool getOne(string &domain, string &ip, u_int16_t *id, bool &purged)
77 for(d_nqueue_t::iterator i=d_nqueue.begin();i!=d_nqueue.end();++i)
78 if(i->next <= time(0)) {
81 i->next=time(0)+1+(1<<i->attempts);
97 time_t early=1<<31-1; // y2038 problem lurking here :-)
98 for(d_nqueue_t::const_iterator i=d_nqueue.begin();i!=d_nqueue.end();++i)
99 early=min(early,i->next);
100 return early-time(0);
104 struct NotificationRequest
113 typedef list<NotificationRequest>d_nqueue_t;
118 /** this class contains a thread that communicates with other nameserver and does housekeeping.
119 Initially, it is notified only of zones that need to be pulled in because they have been updated. */
121 class CommunicatorClass
126 pthread_mutex_init(&d_lock,0);
127 pthread_mutex_init(&d_holelock,0);
128 // sem_init(&d_suck_sem,0,0);
129 // sem_init(&d_any_sem,0,0);
132 int doNotifications();
136 pthread_create(&tid,0,&launchhelper,this);
139 void drillHole(const string &domain, const string &ip);
140 bool justNotified(const string &domain, const string &ip);
141 void addSuckRequest(const string &domain, const string &master);
142 void notify(const string &domain, const string &ip);
144 static void *launchhelper(void *p)
146 static_cast<CommunicatorClass *>(p)->mainloop();
149 bool notifyDomain(const string &domain);
151 void makeNotifySocket();
152 void queueNotifyDomain(const string &domain, DNSBackend *B);
154 map<pair<string,string>,time_t>d_holes;
155 pthread_mutex_t d_holelock;
156 void suck(const string &domain, const string &remote);
157 void slaveRefresh(PacketHandler *P);
158 void masterUpdateCheck(PacketHandler *P);
159 pthread_mutex_t d_lock;
160 queue<SuckRequest> d_suckdomains;
161 Semaphore d_suck_sem;
164 NotificationQueue d_nq;