summaryrefslogtreecommitdiffstats
path: root/src/lib/d2srv/d2_tsig_key.cc
blob: 75dc5277a4e25366f105dba60febde9d3c4df98b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

/// Defines the logger used by the top-level component of kea-dhcp-ddns.

#include <config.h>

#include <d2srv/d2_stats.h>
#include <d2srv/d2_tsig_key.h>
#include <stats/stats_mgr.h>

using namespace isc::dns;
using namespace isc::stats;
using namespace std;

namespace isc {
namespace d2 {

D2TsigKey::D2TsigKey(const std::string& key_spec) : TSIGKey(key_spec) {
    initStats();
}

D2TsigKey::D2TsigKey(const Name& key_name, const Name& algorithm_name,
                     const void* secret, size_t secret_len, size_t digestbits)
    : TSIGKey(key_name, algorithm_name, secret, secret_len, digestbits) {
    initStats();
}

D2TsigKey::~D2TsigKey() {
    removeStats();
}

void
D2TsigKey::initStats() {
    StatsMgr& stats_mgr = StatsMgr::instance();
    const string& kname = getKeyName().toText();
    for (const auto& name : D2Stats::key) {
        const string& sname = StatsMgr::generateName("key", kname, name);
        stats_mgr.setValue(sname, static_cast<int64_t>(0));
    }
}

void
D2TsigKey::removeStats() {
    StatsMgr& stats_mgr = StatsMgr::instance();
    const string& kname = getKeyName().toText();
    for (const auto& name : D2Stats::key) {
        string sname = StatsMgr::generateName("key", kname, name);
        stats_mgr.del(sname);
    }
}

void
D2TsigKey::resetStats() {
    StatsMgr& stats_mgr = StatsMgr::instance();
    const string& kname = getKeyName().toText();
    for (const auto& name : D2Stats::key) {
        string sname = StatsMgr::generateName("key", kname, name);
        stats_mgr.reset(sname);
    }
}

TSIGContextPtr
D2TsigKey::createContext() {
    return (TSIGContextPtr(new TSIGContext(*this)));
}

} // namespace d2
} // namespace isc