Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2023 Savoir-faire Linux Inc. |
| 3 | * |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 4 | * This program is free software: you can redistribute it and/or modify |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 5 | * it under the terms of the GNU General Public License as published by |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 6 | * the Free Software Foundation, either version 3 of the License, or |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 7 | * (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éraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 16 | */ |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 17 | #include "igd.h" |
Morteza Namvar | 5f63952 | 2023-07-04 17:08:58 -0400 | [diff] [blame] | 18 | //#include "logger.h" |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 19 | |
Adrien Béraud | 1ae60aa | 2023-07-07 09:55:09 -0400 | [diff] [blame] | 20 | namespace dhtnet { |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 21 | namespace upnp { |
| 22 | |
| 23 | IGD::IGD(NatProtocolType proto) |
| 24 | : protocol_(proto) |
| 25 | {} |
| 26 | |
| 27 | bool |
| 28 | IGD::operator==(IGD& other) const |
| 29 | { |
| 30 | return localIp_ == other.localIp_ and publicIp_ == other.publicIp_ and uid_ == other.uid_; |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | IGD::setValid(bool valid) |
| 35 | { |
| 36 | valid_ = valid; |
| 37 | |
| 38 | if (valid) { |
| 39 | // Reset errors counter. |
| 40 | errorsCounter_ = 0; |
| 41 | } else { |
Morteza Namvar | 5f63952 | 2023-07-04 17:08:58 -0400 | [diff] [blame] | 42 | // JAMI_WARN("IGD %s [%s] was disabled", toString().c_str(), getProtocolName()); |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | bool |
| 47 | IGD::incrementErrorsCounter() |
| 48 | { |
| 49 | if (not valid_) |
| 50 | return false; |
| 51 | |
| 52 | if (++errorsCounter_ >= MAX_ERRORS_COUNT) { |
Morteza Namvar | 5f63952 | 2023-07-04 17:08:58 -0400 | [diff] [blame] | 53 | // JAMI_WARN("IGD %s [%s] has too many errors, it will be disabled", |
| 54 | // toString().c_str(), |
| 55 | // getProtocolName()); |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 56 | setValid(false); |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | int |
| 64 | IGD::getErrorsCount() const |
| 65 | { |
| 66 | return errorsCounter_.load(); |
| 67 | } |
| 68 | |
| 69 | } // namespace upnp |
Sébastien Blin | 464bdff | 2023-07-19 08:02:53 -0400 | [diff] [blame] | 70 | } // namespace dhtnet |