]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/signingpipe.hh
Merge branch 'feature/pdnsutil-export-zone-ds-showZone' of https://github.com/horazon...
[thirdparty/pdns.git] / pdns / signingpipe.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 #ifndef PDNS_SIGNINGPIPE
23 #define PDNS_SIGNINGPIPE
24 #include <vector>
25 #include <pthread.h>
26 #include <stdio.h>
27 #include "dnsseckeeper.hh"
28 #include "dns.hh"
29
30 void writeLStringToSocket(int fd, const string& msg);
31 bool readLStringFromSocket(int fd, string& msg);
32
33 /** input: DNSZoneRecords ordered in qname,qtype (we emit a signature chunk on a break)
34 * output: "chunks" of those very same DNSZoneRecords, interleaved with signatures
35 */
36
37 class ChunkedSigningPipe
38 {
39 public:
40 typedef vector<DNSZoneRecord> rrset_t;
41 typedef rrset_t chunk_t; // for now
42
43 ChunkedSigningPipe(const DNSName& signerName, bool mustSign, /* FIXME servers is unused? */ const string& servers=string(), unsigned int numWorkers=3);
44 ~ChunkedSigningPipe();
45 bool submit(const DNSZoneRecord& rr);
46 chunk_t getChunk(bool final=false);
47
48 std::atomic<unsigned long> d_signed;
49 int d_queued;
50 int d_outstanding;
51 unsigned int getReady();
52 private:
53 void flushToSign();
54 void dedupRRSet();
55 void sendRRSetToWorker(); // dispatch RRSET to worker
56 void addSignedToChunks(chunk_t* signedChunk);
57 pair<vector<int>, vector<int> > waitForRW(bool rd, bool wr, int seconds);
58
59 void worker(int n, int fd);
60
61 static void* helperWorker(void* p);
62
63 unsigned int d_numworkers;
64 int d_submitted;
65
66 rrset_t* d_rrsetToSign;
67 std::deque< std::vector<DNSZoneRecord> > d_chunks;
68 DNSName d_signer;
69
70 chunk_t::size_type d_maxchunkrecords;
71
72 std::vector<int> d_sockets;
73 std::set<int> d_eof;
74 vector<pthread_t> d_tids;
75 bool d_mustSign;
76 bool d_final;
77 };
78
79 #endif