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

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

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

62.86
/pdns/dnsdistdist/dnsdist-session-cache.cc
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
#include "dnsdist-session-cache.hh"
23

24
#include "dnsdist-configuration.hh"
25

26
TLSSessionCache g_sessionCache;
27

28
void TLSSessionCache::cleanup(time_t now, LockGuardedHolder<TLSSessionCache::CacheData>& data)
29
{
18✔
30
  const auto& runtimeConfig = dnsdist::configuration::getCurrentRuntimeConfiguration();
18✔
31
  time_t cutOff = now + runtimeConfig.d_tlsSessionCacheSessionValidity;
18✔
32

33
  for (auto it = data->d_sessions.begin(); it != data->d_sessions.end();) {
18!
34
    if (it->second.d_lastUsed > cutOff || it->second.d_sessions.size() == 0) {
×
35
      it = data->d_sessions.erase(it);
×
36
    }
×
37
    else {
×
38
      ++it;
×
39
    }
×
40
  }
×
41

42
  data->d_nextCleanup = now + runtimeConfig.d_tlsSessionCacheCleanupDelay;
18✔
43
}
18✔
44

45
void TLSSessionCache::putSessions(const boost::uuids::uuid& backendID, time_t now, std::vector<std::unique_ptr<TLSSession>>&& sessions)
46
{
59✔
47
  auto data = d_data.lock();
59✔
48
  if (data->d_nextCleanup == 0 || now > data->d_nextCleanup) {
59!
49
    cleanup(now, data);
18✔
50
  }
18✔
51

52
  const auto& runtimeConfig = dnsdist::configuration::getCurrentRuntimeConfiguration();
59✔
53
  for (auto& session : sessions) {
81✔
54
    auto& entry = data->d_sessions[backendID];
81✔
55
    if (entry.d_sessions.size() >= runtimeConfig.d_tlsSessionCacheMaxSessionsPerBackend) {
81!
56
      entry.d_sessions.pop_back();
×
57
    }
×
58
    entry.d_sessions.push_front(std::move(session));
81✔
59
  }
81✔
60
}
59✔
61

62
std::unique_ptr<TLSSession> TLSSessionCache::getSession(const boost::uuids::uuid& backendID, time_t now)
63
{
383✔
64
  auto data = d_data.lock();
383✔
65
  auto it = data->d_sessions.find(backendID);
383✔
66
  if (it == data->d_sessions.end()) {
383✔
67
    return nullptr;
288✔
68
  }
288✔
69

70
  auto& entry = it->second;
95✔
71
  if (entry.d_sessions.size() == 0) {
95✔
72
    return nullptr;
28✔
73
  }
28✔
74

75
  entry.d_lastUsed = now;
67✔
76
  auto value = std::move(entry.d_sessions.front());
67✔
77
  entry.d_sessions.pop_front();
67✔
78

79
  return value;
67✔
80
}
95✔
81

82
size_t TLSSessionCache::getSize()
83
{
×
84
  size_t count = 0;
×
85
  auto data = d_data.lock();
×
86
  for (const auto& backend : data->d_sessions) {
×
87
    count += backend.second.d_sessions.size();
×
88
  }
×
89
  return count;
×
90
}
×
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