Line data Source code
1 : /*
2 : * Copyright (C) 2004-2026 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 "jamidht/auth_channel_handler.h"
18 : #include "archive_account_manager.h"
19 :
20 : #include <opendht/thread_pool.h>
21 :
22 : namespace jami {
23 :
24 672 : AuthChannelHandler::AuthChannelHandler(const std::shared_ptr<JamiAccount>& acc, dhtnet::ConnectionManager& cm)
25 : : ChannelHandlerInterface()
26 672 : , account_(acc)
27 672 : , connectionManager_(cm)
28 672 : {}
29 :
30 1344 : AuthChannelHandler::~AuthChannelHandler() {}
31 :
32 : // deprecated
33 : void
34 5 : AuthChannelHandler::connect(const DeviceId& deviceId,
35 : const std::string& name,
36 : ConnectCb&& cb,
37 : const std::string& /*connectionType*/,
38 : bool /*forceNewConnection*/)
39 : {
40 20 : JAMI_DEBUG("[AuthChannel {}] connecting to name = {}", deviceId.toString(), name);
41 5 : connectionManager_.connectDevice(deviceId, name, std::move(cb));
42 10 : }
43 :
44 : bool
45 0 : AuthChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert, const std::string& name)
46 : {
47 0 : JAMI_DEBUG("[AuthChannel] New auth channel requested for `{}`.", cert->getId().toString());
48 0 : auto acc = account_.lock();
49 0 : if (!cert || !cert->issuer || !acc)
50 0 : return false;
51 :
52 0 : JAMI_DEBUG("[AuthChannel] New auth channel requested with name = `{}`.", name);
53 :
54 0 : if (auto acc = account_.lock())
55 0 : return true;
56 :
57 0 : return false;
58 0 : }
59 :
60 : void
61 4 : AuthChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& cert,
62 : const std::string& deviceId,
63 : std::shared_ptr<dhtnet::ChannelSocket> /*channel*/)
64 : {
65 16 : JAMI_DEBUG("[AuthChannel] Auth channel with {}/{} ready.", cert->getId().toString(), deviceId);
66 4 : }
67 :
68 : } // namespace jami
|