blob: 0e2ac9012aef6127550e5c8da60f32b26b92983b [file] [log] [blame]
Adrien BĂ©raud612b55b2023-05-29 10:42:04 -04001/*
2 * Copyright (C) 2004-2023 Savoir-faire Linux Inc.
3 *
4 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
5 * Author: Eden Abitbol <eden.abitbol@savoirfairelinux.com>
6 * Author: Mohamed Chibani <mohamed.chibani@savoirfairelinux.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
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
23#include "igd.h"
24#include "logger.h"
25
26namespace jami {
27namespace upnp {
28
29IGD::IGD(NatProtocolType proto)
30 : protocol_(proto)
31{}
32
33bool
34IGD::operator==(IGD& other) const
35{
36 return localIp_ == other.localIp_ and publicIp_ == other.publicIp_ and uid_ == other.uid_;
37}
38
39void
40IGD::setValid(bool valid)
41{
42 valid_ = valid;
43
44 if (valid) {
45 // Reset errors counter.
46 errorsCounter_ = 0;
47 } else {
48 JAMI_WARN("IGD %s [%s] was disabled", toString().c_str(), getProtocolName());
49 }
50}
51
52bool
53IGD::incrementErrorsCounter()
54{
55 if (not valid_)
56 return false;
57
58 if (++errorsCounter_ >= MAX_ERRORS_COUNT) {
59 JAMI_WARN("IGD %s [%s] has too many errors, it will be disabled",
60 toString().c_str(),
61 getProtocolName());
62 setValid(false);
63 return false;
64 }
65
66 return true;
67}
68
69int
70IGD::getErrorsCount() const
71{
72 return errorsCounter_.load();
73}
74
75} // namespace upnp
76} // namespace jami