]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/signingpipe.hh
Update rules-actions.rst
[thirdparty/pdns.git] / pdns / signingpipe.hh
CommitLineData
12471842
PL
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 */
8e9b7d99
BH
22#ifndef PDNS_SIGNINGPIPE
23#define PDNS_SIGNINGPIPE
a2aaa807 24#include <stdio.h>
07019b51
RG
25#include <thread>
26#include <vector>
27
8e9b7d99
BH
28#include "dnsseckeeper.hh"
29#include "dns.hh"
8e9b7d99 30
bab008e2 31void writeLStringToSocket(int fd, const string& msg);
a6ef6f7a
BH
32bool readLStringFromSocket(int fd, string& msg);
33
90ba52e0 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
8e9b7d99
BH
36 */
37
38class ChunkedSigningPipe
39{
40public:
90ba52e0 41 typedef vector<DNSZoneRecord> rrset_t;
a2aaa807 42 typedef rrset_t chunk_t; // for now
8e9b7d99 43
f6c19c4f
CHB
44 ChunkedSigningPipe(const ChunkedSigningPipe&) = delete;
45 void operator=(const ChunkedSigningPipe&) = delete;
e3200e07 46 ChunkedSigningPipe(const DNSName& signerName, bool mustSign, unsigned int numWorkers=3);
8267bd2c 47 ~ChunkedSigningPipe();
90ba52e0 48 bool submit(const DNSZoneRecord& rr);
8e9b7d99 49 chunk_t getChunk(bool final=false);
e3200e07 50 unsigned int getReady() const;
b4afbd54 51
c3064e57 52 std::atomic<unsigned long> d_signed;
e3200e07
RG
53 unsigned int d_queued;
54 unsigned int d_outstanding;
55
8e9b7d99
BH
56private:
57 void flushToSign();
a2f3b9ec 58 void dedupRRSet();
a2aaa807 59 void sendRRSetToWorker(); // dispatch RRSET to worker
8d59e8ce 60 void addSignedToChunks(chunk_t* signedChunk);
a6ef6f7a
BH
61 pair<vector<int>, vector<int> > waitForRW(bool rd, bool wr, int seconds);
62
07019b51
RG
63 static void* helperWorker(ChunkedSigningPipe* csp, int fd);
64 void worker(int fd);
b4afbd54
PL
65
66 unsigned int d_numworkers;
e3200e07 67 unsigned int d_submitted;
b4afbd54 68
a2aaa807 69 rrset_t* d_rrsetToSign;
90ba52e0 70 std::deque< std::vector<DNSZoneRecord> > d_chunks;
561434a6 71 DNSName d_signer;
8267bd2c 72
a2aaa807
BH
73 chunk_t::size_type d_maxchunkrecords;
74
a6ef6f7a
BH
75 std::vector<int> d_sockets;
76 std::set<int> d_eof;
e3200e07
RG
77 std::map<int,int> d_outstandings;
78
07019b51 79 vector<std::thread> d_threads;
8267bd2c 80 bool d_mustSign;
a6ef6f7a 81 bool d_final;
8e9b7d99
BH
82};
83
84#endif