Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 1 | /* |
| 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" |
Morteza Namvar | 5f63952 | 2023-07-04 17:08:58 -0400 | [diff] [blame] | 24 | //#include "logger.h" |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 25 | |
| 26 | namespace jami { |
| 27 | namespace upnp { |
| 28 | |
| 29 | IGD::IGD(NatProtocolType proto) |
| 30 | : protocol_(proto) |
| 31 | {} |
| 32 | |
| 33 | bool |
| 34 | IGD::operator==(IGD& other) const |
| 35 | { |
| 36 | return localIp_ == other.localIp_ and publicIp_ == other.publicIp_ and uid_ == other.uid_; |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | IGD::setValid(bool valid) |
| 41 | { |
| 42 | valid_ = valid; |
| 43 | |
| 44 | if (valid) { |
| 45 | // Reset errors counter. |
| 46 | errorsCounter_ = 0; |
| 47 | } else { |
Morteza Namvar | 5f63952 | 2023-07-04 17:08:58 -0400 | [diff] [blame] | 48 | // JAMI_WARN("IGD %s [%s] was disabled", toString().c_str(), getProtocolName()); |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
| 52 | bool |
| 53 | IGD::incrementErrorsCounter() |
| 54 | { |
| 55 | if (not valid_) |
| 56 | return false; |
| 57 | |
| 58 | if (++errorsCounter_ >= MAX_ERRORS_COUNT) { |
Morteza Namvar | 5f63952 | 2023-07-04 17:08:58 -0400 | [diff] [blame] | 59 | // JAMI_WARN("IGD %s [%s] has too many errors, it will be disabled", |
| 60 | // toString().c_str(), |
| 61 | // getProtocolName()); |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 62 | setValid(false); |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | int |
| 70 | IGD::getErrorsCount() const |
| 71 | { |
| 72 | return errorsCounter_.load(); |
| 73 | } |
| 74 | |
| 75 | } // namespace upnp |
| 76 | } // namespace jami |