blob: 0c8c7c1cb84d3925ac7327f2ed9dc3dda21c2a90 [file] [log] [blame]
Amna38768302023-08-21 11:51:56 -04001/*
2 * Copyright (C) 2004-2023 Savoir-faire Linux Inc.
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
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
35 Dnc(dht::crypto::Identity identity,
36 const std::string& bootstrap_ip_add,
37 const std::string& bootstrap_port);
38 // Build a client
39 Dnc(dht::crypto::Identity identity,
40 const std::string& bootstrap_ip_add,
41 const std::string& bootstrap_port,
42 dht::InfoHash peer_id,
43 int port,
44 const std::string& ip_add);
45 ~Dnc();
46 void run();
47
48private:
49 std::unique_ptr<ConnectionManager> connectionManager;
50 std::shared_ptr<Logger> logger;
51 tls::CertificateStore certStore;
52 IceTransportFactory iceFactory;
53 std::shared_ptr<asio::io_context> ioContext;
54 std::thread ioContextRunner;
55
56 std::shared_ptr<asio::posix::stream_descriptor> stdinDescriptor;
57
58 std::pair<std::string, std::string> parseName(const std::string_view name);
59};
60
61} // namespace dhtnet