diff options
Diffstat (limited to 'src/messenger/gnunet-service-messenger_message_handle.c')
-rw-r--r-- | src/messenger/gnunet-service-messenger_message_handle.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/src/messenger/gnunet-service-messenger_message_handle.c b/src/messenger/gnunet-service-messenger_message_handle.c new file mode 100644 index 000000000..1652435c8 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_handle.c | |||
@@ -0,0 +1,130 @@ | |||
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_handle.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_message_handle.h" | ||
27 | |||
28 | void | ||
29 | handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
30 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
31 | { | ||
32 | struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id)); | ||
33 | |||
34 | if (!contact) | ||
35 | add_room_contact (room, &(message->header.sender_id), &(message->body.join.key)); | ||
36 | |||
37 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
38 | |||
39 | if (!info) | ||
40 | { | ||
41 | info = GNUNET_new(struct GNUNET_MESSENGER_MemberInfo); | ||
42 | |||
43 | info->access = GNUNET_MESSENGER_MEMBER_UNKNOWN; | ||
44 | init_list_messages (&(info->session_messages)); | ||
45 | } | ||
46 | else | ||
47 | clear_list_messages (&(info->session_messages)); | ||
48 | |||
49 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_put (room->member_infos, &(message->header.sender_id), info, | ||
50 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
51 | add_to_list_messages (&(info->session_messages), hash); | ||
52 | } | ||
53 | |||
54 | void | ||
55 | handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
56 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
57 | { | ||
58 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
59 | |||
60 | if (info) | ||
61 | clear_list_messages (&(info->session_messages)); | ||
62 | } | ||
63 | |||
64 | void | ||
65 | handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
66 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
67 | { | ||
68 | struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id)); | ||
69 | |||
70 | if (contact) | ||
71 | set_contact_name (contact, message->body.name.name); | ||
72 | |||
73 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
74 | |||
75 | if (info) | ||
76 | add_to_list_messages (&(info->session_messages), hash); | ||
77 | } | ||
78 | |||
79 | void | ||
80 | handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
81 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
82 | { | ||
83 | struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id)); | ||
84 | |||
85 | if (contact) | ||
86 | swap_service_contact_by_pubkey (room->service, contact, &(message->body.key.key)); | ||
87 | |||
88 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
89 | |||
90 | if (info) | ||
91 | add_to_list_messages (&(info->session_messages), hash); | ||
92 | } | ||
93 | |||
94 | void | ||
95 | handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
96 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
97 | { | ||
98 | if (GNUNET_NO == contains_list_tunnels (&(room->basement), &(message->body.peer.peer))) | ||
99 | add_to_list_tunnels (&(room->basement), &(message->body.peer.peer)); | ||
100 | |||
101 | if (room->peer_message) | ||
102 | rebuild_room_basement_structure (room); | ||
103 | } | ||
104 | |||
105 | void | ||
106 | handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
107 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
108 | { | ||
109 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
110 | |||
111 | if (info) | ||
112 | add_to_list_messages (&(info->session_messages), hash); | ||
113 | |||
114 | switch_room_member_id (room, &(message->header.sender_id), &(message->body.id.id), hash); | ||
115 | } | ||
116 | |||
117 | void | ||
118 | handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
119 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
120 | { | ||
121 | struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels (&(room->basement), &(message->body.peer.peer), NULL); | ||
122 | |||
123 | if (!element) | ||
124 | return; | ||
125 | |||
126 | remove_from_list_tunnels (&(room->basement), element); | ||
127 | |||
128 | if (room->peer_message) | ||
129 | rebuild_room_basement_structure (room); | ||
130 | } | ||