]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/signingpipe.hh
Merge pull request #8223 from PowerDNS/omoerbeek-patch-1
[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 <stdio.h>
25 #include <thread>
26 #include <vector>
27
28 #include "dnsseckeeper.hh"
29 #include "dns.hh"
30
31 void writeLStringToSocket(int fd, const string& msg);
32 bool readLStringFromSocket(int fd, string& msg);
33
34 /** input: DNSZoneRecords ordered in qname,qtype (we emit a signature chunk on a break)
35 * output: "chunks" of those very same DNSZoneRecords, interleaved with signatures
36 */
37
38 class ChunkedSigningPipe
39 {
40 public:
41 typedef vector<DNSZoneRecord> rrset_t;
42 typedef rrset_t chunk_t; // for now
43
44 ChunkedSigningPipe(const ChunkedSigningPipe&) = delete;
45 void operator=(const ChunkedSigningPipe&) = delete;
46 ChunkedSigningPipe(const DNSName& signerName, bool mustSign, unsigned int numWorkers=3);
47 ~ChunkedSigningPipe();
48 bool submit(const DNSZoneRecord& rr);
49 chunk_t getChunk(bool final=false);
50 unsigned int getReady() const;
51
52 std::atomic<unsigned long> d_signed;
53 unsigned int d_queued;
54 unsigned int d_outstanding;
55
56 private:
57 void flushToSign();
58 void dedupRRSet();
59 void sendRRSetToWorker(); // dispatch RRSET to worker
60 void addSignedToChunks(chunk_t* signedChunk);
61 pair<vector<int>, vector<int> > waitForRW(bool rd, bool wr, int seconds);
62
63 static void* helperWorker(ChunkedSigningPipe* csp, int fd);
64 void worker(int fd);
65
66 unsigned int d_numworkers;
67 unsigned int d_submitted;
68
69 rrset_t* d_rrsetToSign;
70 std::deque< std::vector<DNSZoneRecord> > d_chunks;
71 DNSName d_signer;
72
73 chunk_t::size_type d_maxchunkrecords;
74
75 std::vector<int> d_sockets;
76 std::set<int> d_eof;
77 std::map<int,int> d_outstandings;
78
79 vector<std::thread> d_threads;
80 bool d_mustSign;
81 bool d_final;
82 };
83
84 #endif