Amna | 3876830 | 2023-08-21 11:51:56 -0400 | [diff] [blame] | 1 | /* |
Amna | 2f3539b | 2023-09-18 13:59:22 -0400 | [diff] [blame] | 2 | * Copyright (C) 2023 Savoir-faire Linux Inc. |
Amna | 3876830 | 2023-08-21 11:51:56 -0400 | [diff] [blame] | 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 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 |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | #include "connectionmanager.h" |
| 18 | #include "multiplexed_socket.h" |
| 19 | #include "ice_transport_factory.h" |
| 20 | #include "certstore.h" |
| 21 | |
| 22 | #include <asio.hpp> |
| 23 | |
| 24 | namespace dhtnet { |
| 25 | /** |
| 26 | * Attempt to retrieve the identity from the .ssh directory, and if none is found, generate a new |
| 27 | * certification. |
| 28 | * @return dht::crypto::Identity |
| 29 | */ |
| 30 | |
| 31 | class Dnc |
| 32 | { |
| 33 | public: |
| 34 | // Build a server |
Amna | c75ffe9 | 2024-02-08 17:23:29 -0500 | [diff] [blame] | 35 | Dnc( |
Adrien Béraud | ecde63f | 2023-08-26 18:11:21 -0400 | [diff] [blame] | 36 | dht::crypto::Identity identity, |
Amna | 2f3539b | 2023-09-18 13:59:22 -0400 | [diff] [blame] | 37 | const std::string& bootstrap, |
| 38 | const std::string& turn_host, |
| 39 | const std::string& turn_user, |
| 40 | const std::string& turn_pass, |
Amna | 4325f0f | 2024-01-22 16:11:00 -0500 | [diff] [blame] | 41 | const std::string& turn_realm, |
Amna | 6999623 | 2024-07-23 14:04:44 -0400 | [diff] [blame] | 42 | const bool anonymous, |
Amna | 2ee14f0 | 2024-07-24 15:15:55 -0400 | [diff] [blame] | 43 | const bool verbose, |
Amna | 45db776 | 2024-07-24 18:33:48 -0400 | [diff] [blame] | 44 | const std::map<std::string, std::vector<int>> authorized_services, |
| 45 | const bool enable_upnp); |
Amna | 3876830 | 2023-08-21 11:51:56 -0400 | [diff] [blame] | 46 | // Build a client |
Amna | c75ffe9 | 2024-02-08 17:23:29 -0500 | [diff] [blame] | 47 | Dnc( |
Adrien Béraud | ecde63f | 2023-08-26 18:11:21 -0400 | [diff] [blame] | 48 | dht::crypto::Identity identity, |
| 49 | const std::string& bootstrap, |
Amna | 3876830 | 2023-08-21 11:51:56 -0400 | [diff] [blame] | 50 | dht::InfoHash peer_id, |
Adrien Béraud | ecde63f | 2023-08-26 18:11:21 -0400 | [diff] [blame] | 51 | const std::string& remote_host, |
Amna | 2f3539b | 2023-09-18 13:59:22 -0400 | [diff] [blame] | 52 | int remote_port, |
Amna | 4325f0f | 2024-01-22 16:11:00 -0500 | [diff] [blame] | 53 | const std::string& turn_host, |
| 54 | const std::string& turn_user, |
| 55 | const std::string& turn_pass, |
Amna | 6999623 | 2024-07-23 14:04:44 -0400 | [diff] [blame] | 56 | const std::string& turn_realm, |
Amna | 45db776 | 2024-07-24 18:33:48 -0400 | [diff] [blame] | 57 | const bool verbose, |
| 58 | const bool enable_upnp); |
Amna | 3876830 | 2023-08-21 11:51:56 -0400 | [diff] [blame] | 59 | ~Dnc(); |
| 60 | void run(); |
| 61 | |
| 62 | private: |
| 63 | std::unique_ptr<ConnectionManager> connectionManager; |
| 64 | std::shared_ptr<Logger> logger; |
Amna | 2f3539b | 2023-09-18 13:59:22 -0400 | [diff] [blame] | 65 | std::shared_ptr<tls::CertificateStore> certStore; |
| 66 | std::shared_ptr<IceTransportFactory> iceFactory; |
Amna | 3876830 | 2023-08-21 11:51:56 -0400 | [diff] [blame] | 67 | std::shared_ptr<asio::io_context> ioContext; |
| 68 | std::thread ioContextRunner; |
Amna | 4325f0f | 2024-01-22 16:11:00 -0500 | [diff] [blame] | 69 | std::shared_ptr<tls::TrustStore> trustStore; |
Amna | 3876830 | 2023-08-21 11:51:56 -0400 | [diff] [blame] | 70 | |
Amna | 3876830 | 2023-08-21 11:51:56 -0400 | [diff] [blame] | 71 | std::pair<std::string, std::string> parseName(const std::string_view name); |
| 72 | }; |
| 73 | |
| 74 | } // namespace dhtnet |