blob: 6e5537dfa63c602423c0e4c4606845284842332d [file] [log] [blame]
Amna38768302023-08-21 11:51:56 -04001/*
Amna2f3539b2023-09-18 13:59:22 -04002 * Copyright (C) 2023 Savoir-faire Linux Inc.
Amna38768302023-08-21 11:51:56 -04003 *
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
24namespace 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
31class Dnc
32{
33public:
34 // Build a server
Amnac75ffe92024-02-08 17:23:29 -050035 Dnc(
Adrien Béraudecde63f2023-08-26 18:11:21 -040036 dht::crypto::Identity identity,
Amna2f3539b2023-09-18 13:59:22 -040037 const std::string& bootstrap,
38 const std::string& turn_host,
39 const std::string& turn_user,
40 const std::string& turn_pass,
Amna4325f0f2024-01-22 16:11:00 -050041 const std::string& turn_realm,
Amna69996232024-07-23 14:04:44 -040042 const bool anonymous,
Amna2ee14f02024-07-24 15:15:55 -040043 const bool verbose,
44 const std::map<std::string, std::vector<int>> authorized_services);
Amna38768302023-08-21 11:51:56 -040045 // Build a client
Amnac75ffe92024-02-08 17:23:29 -050046 Dnc(
Adrien Béraudecde63f2023-08-26 18:11:21 -040047 dht::crypto::Identity identity,
48 const std::string& bootstrap,
Amna38768302023-08-21 11:51:56 -040049 dht::InfoHash peer_id,
Adrien Béraudecde63f2023-08-26 18:11:21 -040050 const std::string& remote_host,
Amna2f3539b2023-09-18 13:59:22 -040051 int remote_port,
Amna4325f0f2024-01-22 16:11:00 -050052 const std::string& turn_host,
53 const std::string& turn_user,
54 const std::string& turn_pass,
Amna69996232024-07-23 14:04:44 -040055 const std::string& turn_realm,
56 const bool verbose);
Amna38768302023-08-21 11:51:56 -040057 ~Dnc();
58 void run();
59
60private:
61 std::unique_ptr<ConnectionManager> connectionManager;
62 std::shared_ptr<Logger> logger;
Amna2f3539b2023-09-18 13:59:22 -040063 std::shared_ptr<tls::CertificateStore> certStore;
64 std::shared_ptr<IceTransportFactory> iceFactory;
Amna38768302023-08-21 11:51:56 -040065 std::shared_ptr<asio::io_context> ioContext;
66 std::thread ioContextRunner;
Amna4325f0f2024-01-22 16:11:00 -050067 std::shared_ptr<tls::TrustStore> trustStore;
Amna38768302023-08-21 11:51:56 -040068
Amna38768302023-08-21 11:51:56 -040069 std::pair<std::string, std::string> parseName(const std::string_view name);
70};
71
72} // namespace dhtnet