2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
27 #include "dnsseckeeper.hh"
30 void writeLStringToSocket(int fd, const string& msg);
31 bool readLStringFromSocket(int fd, string& msg);
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
37 class ChunkedSigningPipe
40 typedef vector<DNSZoneRecord> rrset_t;
41 typedef rrset_t chunk_t; // for now
43 ChunkedSigningPipe(const ChunkedSigningPipe&) = delete;
44 void operator=(const ChunkedSigningPipe&) = delete;
45 ChunkedSigningPipe(const DNSName& signerName, bool mustSign, unsigned int numWorkers=3);
46 ~ChunkedSigningPipe();
47 bool submit(const DNSZoneRecord& rr);
48 chunk_t getChunk(bool final=false);
49 unsigned int getReady() const;
51 std::atomic<unsigned long> d_signed;
52 unsigned int d_queued;
53 unsigned int d_outstanding;
58 void sendRRSetToWorker(); // dispatch RRSET to worker
59 void addSignedToChunks(std::unique_ptr<chunk_t>& signedChunk);
60 pair<vector<int>, vector<int> > waitForRW(bool rd, bool wr, int seconds);
62 static void* helperWorker(ChunkedSigningPipe* csp, int fd);
65 unsigned int d_numworkers;
66 unsigned int d_submitted;
68 std::unique_ptr<rrset_t> d_rrsetToSign;
69 std::deque< std::vector<DNSZoneRecord> > d_chunks;
72 chunk_t::size_type d_maxchunkrecords;
74 std::vector<int> d_sockets;
76 std::map<int,int> d_outstandings;
78 vector<std::thread> d_threads;