• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 18679017918

21 Oct 2025 09:15AM UTC coverage: 69.743% (+2.0%) from 67.713%
18679017918

Pull #16307

github

web-flow
Merge ba88af487 into da98764c6
Pull Request #16307: rec: explicit disabling/enabling of tls-gnutls for full and least configs and packages

26192 of 45526 branches covered (57.53%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 1 file covered. (100.0%)

2282 existing lines in 57 files now uncovered.

86265 of 115719 relevant lines covered (74.55%)

4323875.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.57
/pdns/remote_logger.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
#pragma once
23
#ifdef HAVE_CONFIG_H
24
#include "config.h"
25
#endif
26

27
#include <atomic>
28
#include <queue>
29
#include <thread>
30

31
#include "iputils.hh"
32
#include "circular_buffer.hh"
33
#include "lock.hh"
34
#include "sstuff.hh"
35

36
/* Writes can be submitted and they are atomically accepted. Either the whole write
37
   ends up in the buffer or nothing ends up in the buffer.
38
   In case nothing ends up in the buffer, an exception is thrown.
39
   Similarly, EOF leads to this treatment
40

41
   The filedescriptor can be in non-blocking mode.
42

43
   This class is not threadsafe.
44
*/
45

46
class CircularWriteBuffer
47
{
48
public:
49
  explicit CircularWriteBuffer(size_t size) : d_buffer(size)
29✔
50
  {
29✔
51
  }
29✔
52

53
  bool hasRoomFor(const std::string& str) const;
54
  bool write(const std::string& str);
55
  bool flush(int fd);
56
private:
57
  boost::circular_buffer<char> d_buffer;
58
};
59

60
class RemoteLoggerInterface
61
{
62
public:
63
  enum class Result : uint8_t { Queued, PipeFull, TooLarge, OtherError };
64
  static const std::string& toErrorString(Result r);
65

66

UNCOV
67
  virtual ~RemoteLoggerInterface() {};
×
68
  virtual Result queueData(const std::string& data) = 0;
69
  [[nodiscard]] virtual std::string address() const = 0;
70
  [[nodiscard]] virtual std::string toString() = 0;
71
  [[nodiscard]] virtual std::string name() const = 0;
UNCOV
72
  bool logQueries(void) const { return d_logQueries; }
×
UNCOV
73
  bool logResponses(void) const { return d_logResponses; }
×
UNCOV
74
  bool logNODs(void) const { return d_logNODs; }
×
UNCOV
75
  bool logUDRs(void) const { return d_logUDRs; }
×
UNCOV
76
  void setLogQueries(bool flag) { d_logQueries = flag; }
×
UNCOV
77
  void setLogResponses(bool flag) { d_logResponses = flag; }
×
UNCOV
78
  void setLogNODs(bool flag) { d_logNODs = flag; }
×
UNCOV
79
  void setLogUDRs(bool flag) { d_logUDRs = flag; }
×
80

81
  struct Stats
82
  {
83
    uint64_t d_queued{};
84
    uint64_t d_pipeFull{};
85
    uint64_t d_tooLarge{};
86
    uint64_t d_otherError{};
87

88
    Stats& operator += (const Stats& rhs)
89
    {
×
90
      d_queued += rhs.d_queued;
×
91
      d_pipeFull += rhs.d_pipeFull;
×
92
      d_tooLarge += rhs.d_tooLarge;
×
93
      d_otherError += rhs.d_otherError;
×
94
      return *this;
×
95
    }
×
96
  };
97

98
  [[nodiscard]] virtual Stats getStats() = 0;
99

100
private:
101
  bool d_logQueries{true};
102
  bool d_logResponses{true};
103
  bool d_logNODs{true};
104
  bool d_logUDRs{false};
105
};
106

107
/* Thread safe. Will connect asynchronously on request.
108
   Runs a reconnection thread that also periodicall flushes.
109
   Note that the buffer only runs as long as there is a connection.
110
   If there is no connection we don't buffer a thing
111
*/
112
class RemoteLogger : public RemoteLoggerInterface
113
{
114
public:
115
  RemoteLogger(const ComboAddress& remote, uint16_t timeout=2,
116
               uint64_t maxQueuedBytes=100000,
117
               uint8_t reconnectWaitTime=1,
118
               bool asyncConnect=false);
119
  ~RemoteLogger();
120

121
  std::string address() const override
122
  {
×
123
    return d_remote.toStringWithPort();
×
124
  }
×
125

126
  [[nodiscard]] Result queueData(const std::string& data) override;
127
  [[nodiscard]] std::string name() const override
128
  {
×
129
    return "protobuf";
×
130
  }
×
131
  [[nodiscard]] std::string toString() override
132
  {
×
133
    auto runtime = d_runtime.lock();
×
134
    return d_remote.toStringWithPort() + " (" + std::to_string(runtime->d_stats.d_queued) + " processed, " + std::to_string(runtime->d_stats.d_pipeFull + runtime->d_stats.d_tooLarge + runtime->d_stats.d_otherError) + " dropped)";
×
135
  }
×
136

137
  [[nodiscard]] RemoteLoggerInterface::Stats getStats() override
138
  {
×
139
    return d_runtime.lock()->d_stats;
×
140
  }
×
141

142
  void stop()
143
  {
×
144
    d_exiting = true;
×
145
  }
×
146

147
private:
148
  bool reconnect();
149
  void maintenanceThread();
150

151
  struct RuntimeData
152
  {
153
    CircularWriteBuffer d_writer;
154
    std::unique_ptr<Socket> d_socket{nullptr};
155
    RemoteLoggerInterface::Stats d_stats{};
156
  };
157

158
  ComboAddress d_remote;
159
  uint16_t d_timeout;
160
  uint8_t d_reconnectWaitTime;
161
  std::atomic<bool> d_exiting{false};
162
  bool d_asyncConnect{false};
163

164
  LockGuarded<RuntimeData> d_runtime;
165
  std::thread d_thread;
166
};
167

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc