Ring Daemon 16.0.0
Loading...
Searching...
No Matches
swarm_channel_handler.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 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
19
20namespace jami {
21
22SwarmChannelHandler::SwarmChannelHandler(const std::shared_ptr<JamiAccount>& acc,
23 dhtnet::ConnectionManager& cm)
25 , account_(acc)
26 , connectionManager_(cm)
27{}
28
30
31void
33 const std::string& conversationId,
34 ConnectCb&& cb,
35 const std::string& connectionType,
37{
38#ifdef LIBJAMI_TEST
40 return;
41#endif
42 connectionManager_.connectDevice(deviceId, fmt::format("swarm://{}", conversationId), cb);
43}
44
45bool
46SwarmChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert,
47 const std::string& name)
48{
49#ifdef LIBJAMI_TEST
51 return false;
52#endif
53 auto acc = account_.lock();
54 if (!cert || !cert->issuer || !acc)
55 return false;
56
57 auto sep = name.find_last_of('/');
58 auto conversationId = name.substr(sep + 1);
59 if (auto acc = account_.lock())
60 if (auto convModule = acc->convModule(true)) {
61 auto res = !convModule->isBanned(conversationId, cert->issuer->getId().toString());
62 res &= !convModule->isBanned(conversationId, cert->getLongId().toString());
63 return res;
64 }
65 return false;
66}
67
68void
69SwarmChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&,
70 const std::string& uri,
71 std::shared_ptr<dhtnet::ChannelSocket> socket)
72{
73 auto sep = uri.find_last_of('/');
74 auto conversationId = uri.substr(sep + 1);
75 if (auto acc = account_.lock()) {
76 if (auto convModule = acc->convModule(true)) {
77 convModule->addSwarmChannel(conversationId, socket);
78 }
79 }
80}
81} // namespace jami
A Channel handler is used to make the link between JamiAccount and ConnectionManager Its role is to m...
void onReady(const std::shared_ptr< dht::crypto::Certificate > &peer, const std::string &name, std::shared_ptr< dhtnet::ChannelSocket > channel) override
TODO, this needs to extract gitservers from JamiAccount.
void connect(const NodeId &nodeId, const std::string &name, ConnectCb &&cb, const std::string &connectionType="", bool forceNewConnection=false) override
Ask for a new git channel.
bool onRequest(const std::shared_ptr< dht::crypto::Certificate > &peer, const std::string &name) override
Determine if we accept or not the git request.
SwarmChannelHandler(const std::shared_ptr< JamiAccount > &acc, dhtnet::ConnectionManager &cm)
std::function< void(std::shared_ptr< dhtnet::ChannelSocket >, const DeviceId &)> ConnectCb
dht::PkId DeviceId
void emitSignal(Args... args)
Definition ring_signal.h:64