blob: bd31a71a0edb1239c1052dcfdcf7b9dd056d315e [file] [log] [blame]
Adrien Béraud612b55b2023-05-29 10:42:04 -04001/*
2 * Copyright (C) 2004-2023 Savoir-faire Linux Inc.
3 *
Adrien Béraudcb753622023-07-17 22:32:49 -04004 * This program is free software: you can redistribute it and/or modify
Adrien Béraud612b55b2023-05-29 10:42:04 -04005 * it under the terms of the GNU General Public License as published by
Adrien Béraudcb753622023-07-17 22:32:49 -04006 * the Free Software Foundation, either version 3 of the License, or
Adrien Béraud612b55b2023-05-29 10:42:04 -04007 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Adrien Béraudcb753622023-07-17 22:32:49 -040011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Adrien Béraud612b55b2023-05-29 10:42:04 -040012 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
Adrien Béraudcb753622023-07-17 22:32:49 -040015 * along with this program. If not, see <https://www.gnu.org/licenses/>.
Adrien Béraud612b55b2023-05-29 10:42:04 -040016 */
Adrien Béraud612b55b2023-05-29 10:42:04 -040017#include "igd.h"
Morteza Namvar5f639522023-07-04 17:08:58 -040018//#include "logger.h"
Adrien Béraud612b55b2023-05-29 10:42:04 -040019
Adrien Béraud1ae60aa2023-07-07 09:55:09 -040020namespace dhtnet {
Adrien Béraud612b55b2023-05-29 10:42:04 -040021namespace upnp {
22
23IGD::IGD(NatProtocolType proto)
24 : protocol_(proto)
25{}
26
27bool
28IGD::operator==(IGD& other) const
29{
30 return localIp_ == other.localIp_ and publicIp_ == other.publicIp_ and uid_ == other.uid_;
31}
32
33void
34IGD::setValid(bool valid)
35{
36 valid_ = valid;
37
38 if (valid) {
39 // Reset errors counter.
40 errorsCounter_ = 0;
41 } else {
Morteza Namvar5f639522023-07-04 17:08:58 -040042 // JAMI_WARN("IGD %s [%s] was disabled", toString().c_str(), getProtocolName());
Adrien Béraud612b55b2023-05-29 10:42:04 -040043 }
44}
45
46bool
47IGD::incrementErrorsCounter()
48{
49 if (not valid_)
50 return false;
51
52 if (++errorsCounter_ >= MAX_ERRORS_COUNT) {
Morteza Namvar5f639522023-07-04 17:08:58 -040053 // JAMI_WARN("IGD %s [%s] has too many errors, it will be disabled",
54 // toString().c_str(),
55 // getProtocolName());
Adrien Béraud612b55b2023-05-29 10:42:04 -040056 setValid(false);
57 return false;
58 }
59
60 return true;
61}
62
63int
64IGD::getErrorsCount() const
65{
66 return errorsCounter_.load();
67}
68
69} // namespace upnp
Sébastien Blin464bdff2023-07-19 08:02:53 -040070} // namespace dhtnet