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

PowerDNS / pdns / 13111317048

03 Feb 2025 10:22AM UTC coverage: 64.724% (+9.5%) from 55.194%
13111317048

Pull #14724

github

web-flow
Merge cced151a0 into db18c3a17
Pull Request #14724: dnsdist: Add meson support

38354 of 90334 branches covered (42.46%)

Branch coverage included in aggregate %.

449 of 624 new or added lines in 40 files covered. (71.96%)

6809 existing lines in 147 files now uncovered.

128214 of 167016 relevant lines covered (76.77%)

4848378.55 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
{
16✔
30
  const auto& runtimeConfig = dnsdist::configuration::getCurrentRuntimeConfiguration();
16✔
31
  time_t cutOff = now + runtimeConfig.d_tlsSessionCacheSessionValidity;
16✔
32

33
  for (auto it = data->d_sessions.begin(); it != data->d_sessions.end();) {
16!
UNCOV
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;
16✔
43
}
16✔
44

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

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

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

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

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

79
  return value;
34✔
80
}
43✔
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