aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_message_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/gnunet-service-messenger_message_send.c')
-rw-r--r--src/messenger/gnunet-service-messenger_message_send.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_message_send.c b/src/messenger/gnunet-service-messenger_message_send.c
new file mode 100644
index 000000000..86cf9b888
--- /dev/null
+++ b/src/messenger/gnunet-service-messenger_message_send.c
@@ -0,0 +1,118 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Tobias Frisch
22 * @file src/messenger/gnunet-service-messenger_message_send.c
23 * @brief GNUnet MESSENGER service
24 */
25
26#include "gnunet-service-messenger_message_send.h"
27#include "gnunet-service-messenger_message_handle.h"
28
29void
30send_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
31 struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message,
32 const struct GNUNET_HashCode *hash)
33{
34 if (!tunnel->contact_id)
35 {
36 tunnel->contact_id = GNUNET_new(struct GNUNET_ShortHashCode);
37
38 GNUNET_memcpy(tunnel->contact_id, &(message->body.info.unique_id), sizeof(struct GNUNET_ShortHashCode));
39 }
40 else
41 {
42 disconnect_tunnel (tunnel);
43 }
44}
45
46void
47send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
48 struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message,
49 const struct GNUNET_HashCode *hash)
50{
51 handle_message_join (room, tunnel, message, hash);
52
53 if (room->peer_message)
54 {
55 const struct GNUNET_MESSENGER_Message *peer_message = get_room_message (room, handle, room->peer_message,
56 GNUNET_NO);
57
58 if ((peer_message) && (tunnel))
59 {
60 forward_tunnel_message (tunnel, peer_message, room->peer_message);
61 }
62 }
63}
64
65void
66send_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
67 struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message,
68 const struct GNUNET_HashCode *hash)
69{
70 handle_message_leave (room, tunnel, message, hash);
71}
72
73void
74send_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
75 struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message,
76 const struct GNUNET_HashCode *hash)
77{
78 handle_message_name (room, tunnel, message, hash);
79}
80
81void
82send_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
83 struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message,
84 const struct GNUNET_HashCode *hash)
85{
86 handle_message_key (room, tunnel, message, hash);
87}
88
89void
90send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
91 struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message,
92 const struct GNUNET_HashCode *hash)
93{
94 if (!room->peer_message)
95 {
96 room->peer_message = GNUNET_new(struct GNUNET_HashCode);
97 }
98
99 GNUNET_memcpy(room->peer_message, hash, sizeof(struct GNUNET_HashCode));
100
101 handle_message_peer (room, tunnel, message, hash);
102}
103
104void
105send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
106 struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message,
107 const struct GNUNET_HashCode *hash)
108{
109 handle_message_id (room, tunnel, message, hash);
110}
111
112void
113send_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle,
114 struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message,
115 const struct GNUNET_HashCode *hash)
116{
117 handle_message_miss (room, tunnel, message, hash);
118}