Ring Daemon 16.0.0
Loading...
Searching...
No Matches
message_channel_handler.h
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#pragma once
18
20#include "jamidht/jamiaccount.h"
21#include <dhtnet/connectionmanager.h>
22
23namespace jami {
24
29{
30public:
31 using OnMessage = std::function<void(const std::shared_ptr<dht::crypto::Certificate>&, std::string&, const std::string&)>;
32 using OnPeerStateChanged = std::function<void(const std::string&, bool)>;
35
44 void connect(const DeviceId& deviceId,
45 const std::string&,
46 ConnectCb&& cb,
47 const std::string& connectionType,
48 bool forceNewConnection = false) override;
49
50 std::shared_ptr<dhtnet::ChannelSocket> getChannel(const std::string& peer,
51 const DeviceId& deviceId) const;
52 std::vector<std::shared_ptr<dhtnet::ChannelSocket>> getChannels(const std::string& peer) const;
53
60 bool onRequest(const std::shared_ptr<dht::crypto::Certificate>& peer,
61 const std::string& name) override;
62
69 void onReady(const std::shared_ptr<dht::crypto::Certificate>& peer,
70 const std::string& name,
71 std::shared_ptr<dhtnet::ChannelSocket> channel) override;
72
73 void closeChannel(const std::string& peer, const DeviceId& device, const std::shared_ptr<dhtnet::ChannelSocket>& conn);
74
75 struct Message
76 {
77 uint64_t id {0}; /* Message ID */
78 std::string t; /* Message type */
79 std::string c; /* Message content */
80 std::unique_ptr<ConversationRequest> req; /* Conversation request */
81 MSGPACK_DEFINE_MAP(id, t, c, req)
82 };
83
84 static bool sendMessage(const std::shared_ptr<dhtnet::ChannelSocket>&, const Message& message);
85
86private:
87 struct Impl;
88 std::shared_ptr<Impl> pimpl_;
89};
90
91} // namespace jami
A Channel handler is used to make the link between JamiAccount and ConnectionManager Its role is to m...
Manages channels for exchanging messages between peers.
static bool sendMessage(const std::shared_ptr< dhtnet::ChannelSocket > &, const Message &message)
std::vector< std::shared_ptr< dhtnet::ChannelSocket > > getChannels(const std::string &peer) const
void closeChannel(const std::string &peer, const DeviceId &device, const std::shared_ptr< dhtnet::ChannelSocket > &conn)
std::shared_ptr< dhtnet::ChannelSocket > getChannel(const std::string &peer, const DeviceId &deviceId) const
std::function< void(const std::string &, bool)> OnPeerStateChanged
std::function< void(const std::shared_ptr< dht::crypto::Certificate > &, std::string &, const std::string &)> OnMessage
bool onRequest(const std::shared_ptr< dht::crypto::Certificate > &peer, const std::string &name) override
Determine if we accept or not the message request.
void onReady(const std::shared_ptr< dht::crypto::Certificate > &peer, const std::string &name, std::shared_ptr< dhtnet::ChannelSocket > channel) override
Launch message process.
void connect(const DeviceId &deviceId, const std::string &, ConnectCb &&cb, const std::string &connectionType, bool forceNewConnection=false) override
Ask for a new message channel.
std::function< void(std::shared_ptr< dhtnet::ChannelSocket >, const DeviceId &)> ConnectCb
dht::PkId DeviceId
void emitSignal(Args... args)
Definition ring_signal.h:64
std::unique_ptr< ConversationRequest > req