Ring Daemon
Loading...
Searching...
No Matches
auth_channel_handler.cpp
Go to the documentation of this file.
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 */
19
20#include <opendht/thread_pool.h>
21
22namespace jami {
23
24AuthChannelHandler::AuthChannelHandler(const std::shared_ptr<JamiAccount>& acc, dhtnet::ConnectionManager& cm)
26 , account_(acc)
27 , connectionManager_(cm)
28{}
29
31
32// deprecated
33void
35 const std::string& name,
36 ConnectCb&& cb,
37 const std::string& /*connectionType*/,
38 bool /*forceNewConnection*/)
39{
40 JAMI_DEBUG("[AuthChannel {}] connecting to name = {}", deviceId.toString(), name);
41 connectionManager_.connectDevice(deviceId, name, std::move(cb));
42}
43
44void
45AuthChannelHandler::connect(const dht::InfoHash& infoHash, const std::string& channelPath, ConnectCallbackLegacy&& cb)
46{
47 JAMI_DEBUG("[AuthChannel {}] connecting to channelPath = {}", infoHash.toString(), channelPath);
48 connectionManager_.connectDevice(infoHash, channelPath, std::move(cb));
49}
50
51bool
52AuthChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert, const std::string& name)
53{
54 JAMI_DEBUG("[AuthChannel] New auth channel requested for `{}`.", cert->getId().toString());
55 auto acc = account_.lock();
56 if (!cert || !cert->issuer || !acc)
57 return false;
58
59 JAMI_DEBUG("[AuthChannel] New auth channel requested with name = `{}`.", name);
60
61 if (auto acc = account_.lock())
62 return true;
63
64 return false;
65}
66
67void
68AuthChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& cert,
69 const std::string& deviceId,
70 std::shared_ptr<dhtnet::ChannelSocket> /*channel*/)
71{
72 JAMI_DEBUG("[AuthChannel] Auth channel with {}/{} ready.", cert->getId().toString(), deviceId);
73}
74
75} // namespace jami
AuthChannelHandler(const std::shared_ptr< JamiAccount > &acc, dhtnet::ConnectionManager &cm)
void connect(const DeviceId &deviceId, const std::string &name, ConnectCb &&cb, const std::string &connectionType="", bool forceNewConnection=false) override
Ask for a new sync channel.
bool onRequest(const std::shared_ptr< dht::crypto::Certificate > &peer, const std::string &name) override
Determine if we accept or not the sync request.
void onReady(const std::shared_ptr< dht::crypto::Certificate > &peer, const std::string &name, std::shared_ptr< dhtnet::ChannelSocket > channel) override
Launch sync process.
A Channel handler is used to make the link between JamiAccount and ConnectionManager Its role is to m...
#define JAMI_DEBUG(formatstr,...)
Definition logger.h:238
std::function< void(std::shared_ptr< dhtnet::ChannelSocket >, const DeviceId &)> ConnectCb
dht::PkId DeviceId
void emitSignal(Args... args)
Definition jami_signal.h:64
std::function< void(std::shared_ptr< dhtnet::ChannelSocket >, const dht::InfoHash &)> ConnectCallbackLegacy