Ring Daemon
Loading...
Searching...
No Matches
conversation_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 */
18
19namespace jami {
20
21ConversationChannelHandler::ConversationChannelHandler(const std::shared_ptr<JamiAccount>& acc,
22 dhtnet::ConnectionManager& cm)
24 , account_(acc)
25 , connectionManager_(cm)
26{}
27
29
30void
32 const std::string& channelName,
33 ConnectCb&& cb,
34 const std::string& /*connectionType*/,
35 bool /*forceNewConnection*/)
36{
37 connectionManager_.connectDevice(deviceId, "git://" + deviceId.toString() + "/" + channelName, std::move(cb));
38}
39
40bool
41ConversationChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert, const std::string& name)
42{
43 auto acc = account_.lock();
44 if (!cert || !cert->issuer || !acc)
45 return false;
46 // Pre-check before acceptance. Sometimes, another device can start a conversation
47 // which is still not synced. So, here we decline channel's request in this case
48 // to avoid the other device to want to sync with us if we are not ready.
49 auto sep = name.find_last_of('/');
50 auto conversationId = name.substr(sep + 1);
51
52 if (auto acc = account_.lock()) {
53 if (auto convModule = acc->convModule(true)) {
54 auto res = !convModule->isBanned(conversationId, cert->issuer->getId().toString());
55 if (!res) {
56 JAMI_WARNING("[Account {}] Received ConversationChannel request for '{}' but user {} is banned",
57 acc->getAccountID(),
58 name,
59 cert->issuer->getId().toString());
60 } else {
61 res &= !convModule->isBanned(conversationId, cert->getLongId().toString());
62 if (!res) {
63 JAMI_WARNING("[Account {}] Received ConversationChannel request for '{}' but device {} is banned",
64 acc->getAccountID(),
65 name,
66 cert->getLongId().toString());
67 }
68 }
69 return res;
70 } else {
71 JAMI_ERROR("Received ConversationChannel request but conversation module is unavailable");
72 }
73 }
74 return false;
75}
76
77void
78ConversationChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&,
79 const std::string&,
80 std::shared_ptr<dhtnet::ChannelSocket>)
81{}
82
83} // namespace jami
A Channel handler is used to make the link between JamiAccount and ConnectionManager Its role is to m...
ConversationChannelHandler(const std::shared_ptr< JamiAccount > &acc, dhtnet::ConnectionManager &cm)
bool onRequest(const std::shared_ptr< dht::crypto::Certificate > &peer, const std::string &name) override
Determine if we accept or not the git request.
void connect(const DeviceId &deviceId, const std::string &name, ConnectCb &&cb, const std::string &connectionType="", bool forceNewConnection=false) override
Ask for a new git channel.
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.
#define JAMI_ERROR(formatstr,...)
Definition logger.h:243
#define JAMI_WARNING(formatstr,...)
Definition logger.h:242
std::function< void(std::shared_ptr< dhtnet::ChannelSocket >, const DeviceId &)> ConnectCb
dht::PkId DeviceId
void emitSignal(Args... args)
Definition jami_signal.h:64