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