aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_message_recv.c
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2020-11-01 22:57:28 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-03-06 01:30:37 +0100
commit2925310d67483aca6e055e1ce0593c6463cd6c72 (patch)
tree2cc8aacafc25563cdccde2eee9a90f9ca257d405 /src/messenger/gnunet-service-messenger_message_recv.c
parent82b864a64679b0a735201724907cdf2b7e4e16c3 (diff)
downloadgnunet-2925310d67483aca6e055e1ce0593c6463cd6c72.tar.gz
gnunet-2925310d67483aca6e055e1ce0593c6463cd6c72.zip
-added core functionality of the messenger service
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> formatting messenger code Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -completed core functionality of messenger service Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -code cleanup and reuse Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> +added structure to memberships of rooms Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -implemented member permission checks and deletion of messages Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -moved solving requests out of updating last messages (also forward before update) Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -reduced complexity of permisson check and changed load/save of rooms Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -added save/load for accessed keys and basement peers of a room Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -implemented save/load for members with their history and session Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -abstracted management of egos and contacts Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fix warning Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -abstracted management of members Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fixed and adjusted test case Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -separated handling of direct and anonymous contacts Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -messenger added member-sessions which fix multiple edge cases, also additional cleanup Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -updated docs and fixed memory leak Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -changed info messages and added protocol version exchange Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -adjusted client api to use contacts from sessions Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -added more logging and fixed wrong session usage Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -adjusted comm0 test case and removed adding members from checking messages Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fixed test-case for peer exchange Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -getting multiple peers connected in test-case with cadet Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fixed wrong assert and added tunnel version check -simplified handling and forwarding Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fixed merging last messages and cycling info messages Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -automated adding sessions and members Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -corrected use of identity keys and signatures Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -adding local joining on entering external room Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fixed test-case comm0 Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -added more test-cases with generic setup Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fixed multiple simultaneous channels blocking each other Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -making test-cases more precise Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -added check of members in test-cases, reduced merge messages Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -unified delayed operations: requests, deletions and merges Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -finished handling of operations Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fixed member session historystorage, added request permission check and padding for transmission Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -improved padding and removed automatic recursive requests Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -implemented filter for sending messages and added private messages to API level Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -wrong setups fixed with proper ego lookups Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -fixed problem with anonymous ego and changed to discrete-level padding Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -added links to replace deleted messages, added local deletion and fixed anonymous id changing Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> -added session completion and removal through completion process Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/messenger/gnunet-service-messenger_message_recv.c')
-rw-r--r--src/messenger/gnunet-service-messenger_message_recv.c206
1 files changed, 70 insertions, 136 deletions
diff --git a/src/messenger/gnunet-service-messenger_message_recv.c b/src/messenger/gnunet-service-messenger_message_recv.c
index aa28a36ea..8aab805d2 100644
--- a/src/messenger/gnunet-service-messenger_message_recv.c
+++ b/src/messenger/gnunet-service-messenger_message_recv.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2020 GNUnet e.V. 3 Copyright (C) 2020--2021 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -24,137 +24,64 @@
24 */ 24 */
25 25
26#include "gnunet-service-messenger_message_recv.h" 26#include "gnunet-service-messenger_message_recv.h"
27#include "gnunet-service-messenger_message_handle.h"
28 27
29void 28#include "gnunet-service-messenger_operation.h"
30recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
31 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
32{
33 int conflict = GNUNET_CONTAINER_multishortmap_contains (room->members, &(message->body.info.unique_id));
34
35 if (GNUNET_NO == conflict)
36 {
37 struct GNUNET_MESSENGER_Message *sync_message = create_message_id (&(message->body.info.unique_id));
38 struct GNUNET_HashCode sync_hash;
39
40 send_room_message_ext (room, room->host, sync_message, &sync_hash, tunnel);
41 destroy_message (sync_message);
42
43 switch_room_member_id (room, get_room_host_id (room), &(message->body.info.unique_id), NULL);
44
45 change_room_host_id (room, &(message->body.info.unique_id));
46 }
47
48 if (!tunnel->contact_id)
49 tunnel->contact_id = GNUNET_new(struct GNUNET_ShortHashCode);
50
51 GNUNET_memcpy(tunnel->contact_id, &(message->header.sender_id), sizeof(struct GNUNET_ShortHashCode));
52
53 struct GNUNET_ShortHashCode original_id;
54
55 if (GNUNET_YES == conflict)
56 {
57 GNUNET_memcpy(&original_id, get_room_host_id (room), sizeof(struct GNUNET_ShortHashCode));
58
59 change_room_host_id (room, &(message->body.info.unique_id));
60 }
61
62 {
63 struct GNUNET_MESSENGER_Message *join_message = create_message_join (room->host->ego);
64 struct GNUNET_HashCode join_hash;
65
66 send_tunnel_message (tunnel, room->host, join_message, &join_hash);
67 destroy_message (join_message);
68 }
69
70 if ((GNUNET_YES == conflict) && (0 != GNUNET_memcmp(&original_id, get_room_host_id (room))))
71 {
72 struct GNUNET_MESSENGER_Message *sync_message = create_message_id (&original_id);
73 struct GNUNET_HashCode sync_hash;
74
75 send_tunnel_message (tunnel, room->host, sync_message, &sync_hash);
76 destroy_message (sync_message);
77 }
78}
79
80struct GNUNET_MESSENGER_MemberInfoSpread
81{
82 struct GNUNET_MESSENGER_SrvRoom *room;
83 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
84};
85 29
86static int 30static int
87iterate_send_member_infos (void *cls, const struct GNUNET_ShortHashCode *key, void *value) 31iterate_forward_members (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key,
32 struct GNUNET_MESSENGER_MemberSession *session)
88{ 33{
89 struct GNUNET_MESSENGER_MemberInfo *info = value; 34 struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
90 struct GNUNET_MESSENGER_MemberInfoSpread *spread = cls; 35 struct GNUNET_MESSENGER_SrvRoom *room = tunnel->room;
91 36
92 struct GNUNET_MESSENGER_ListMessage *element = info->session_messages.head; 37 struct GNUNET_MESSENGER_ListMessage *element;
93 38
94 while (element) 39 for (element = session->messages.head; element; element = element->next)
95 { 40 forward_tunnel_message(tunnel, get_room_message(room, NULL, &(element->hash), GNUNET_NO), &(element->hash));
96 const struct GNUNET_MESSENGER_Message *message = get_room_message (spread->room, spread->room->host,
97 &(element->hash), GNUNET_NO);
98
99 if (message)
100 forward_tunnel_message (spread->tunnel, message, &(element->hash));
101
102 element = element->next;
103 }
104 41
105 return GNUNET_YES; 42 return GNUNET_YES;
106} 43}
107 44
108void 45int
109recv_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 46recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
110 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 47 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
111{ 48{
112 const struct GNUNET_MESSENGER_Message *info_msg = get_room_message (room, room->host, &(message->header.previous), 49 const uint32_t version = get_tunnel_messenger_version(tunnel);
113 GNUNET_NO);
114 50
115 if ((info_msg) && (0 == GNUNET_memcmp(&(info_msg->header.sender_id), get_room_host_id (room))) 51 if (GNUNET_OK != update_tunnel_messenger_version(tunnel, message->body.info.messenger_version))
116 && (GNUNET_MESSENGER_KIND_INFO == info_msg->header.kind))
117 { 52 {
118 struct GNUNET_MESSENGER_MemberInfoSpread spread; 53 disconnect_tunnel(tunnel);
54 return GNUNET_NO;
55 }
119 56
120 spread.room = room; 57 if (version == get_tunnel_messenger_version(tunnel))
58 return GNUNET_NO;
121 59
122 if ((tunnel) && (tunnel->contact_id) && (0 == GNUNET_memcmp(tunnel->contact_id, &(message->header.sender_id)))) 60 if (room->host)
123 spread.tunnel = tunnel; 61 {
124 else 62 const struct GNUNET_MESSENGER_Ego *ego = get_handle_ego(room->host);
125 spread.tunnel = find_room_tunnel_to (room, &(message->header.sender_id));
126 63
127 if (spread.tunnel) 64 send_tunnel_message (tunnel, room->host, create_message_info(ego));
128 GNUNET_CONTAINER_multishortmap_iterate (room->member_infos, iterate_send_member_infos, &spread);
129 } 65 }
130 66
131 handle_message_join (room, tunnel, message, hash); 67 struct GNUNET_PeerIdentity peer;
132} 68 get_tunnel_peer_identity(tunnel, &peer);
133 69
134void 70 if (GNUNET_YES != contains_list_tunnels(&(room->basement), &peer))
135recv_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 71 {
136 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 72 struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
137{
138 handle_message_leave (room, tunnel, message, hash);
139}
140 73
141void 74 iterate_store_members(member_store, iterate_forward_members, tunnel);
142recv_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 75 }
143 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
144{
145 handle_message_name (room, tunnel, message, hash);
146}
147 76
148void 77 check_room_peer_status(room, tunnel);
149recv_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 78
150 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 79 return GNUNET_NO;
151{
152 handle_message_key (room, tunnel, message, hash);
153} 80}
154 81
155void 82int
156recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 83recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
157 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 84 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
158{ 85{
159 struct GNUNET_PeerIdentity peer; 86 struct GNUNET_PeerIdentity peer;
160 GNUNET_PEER_resolve (tunnel->peer, &peer); 87 GNUNET_PEER_resolve (tunnel->peer, &peer);
@@ -164,41 +91,48 @@ recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE
164 if (!tunnel->peer_message) 91 if (!tunnel->peer_message)
165 tunnel->peer_message = GNUNET_new(struct GNUNET_HashCode); 92 tunnel->peer_message = GNUNET_new(struct GNUNET_HashCode);
166 93
167 GNUNET_memcpy(tunnel->peer_message, hash, sizeof(struct GNUNET_HashCode)); 94 GNUNET_memcpy(tunnel->peer_message, &hash, sizeof(hash));
168
169 if (!tunnel->contact_id)
170 tunnel->contact_id = GNUNET_new(struct GNUNET_ShortHashCode);
171
172 GNUNET_memcpy(tunnel->contact_id, &(message->header.sender_id), sizeof(struct GNUNET_ShortHashCode));
173 } 95 }
174 96
175 handle_message_peer (room, tunnel, message, hash); 97 return GNUNET_YES;
176} 98}
177 99
178void 100int
179recv_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 101recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
180 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 102 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
181{ 103{
182 if ((tunnel->contact_id) && (0 == GNUNET_memcmp(tunnel->contact_id, &(message->header.sender_id)))) 104 const struct GNUNET_MESSENGER_Message *msg = get_room_message (
183 GNUNET_memcpy(tunnel->contact_id, &(message->body.id.id), sizeof(struct GNUNET_ShortHashCode)); 105 room, NULL, &(message->body.request.hash), GNUNET_NO
106 );
184 107
185 handle_message_id (room, tunnel, message, hash); 108 if (!msg)
186} 109 {
110 struct GNUNET_MESSENGER_OperationStore *operation_store = get_room_operation_store(room);
187 111
188void 112 use_store_operation(
189recv_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 113 operation_store,
190 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 114 &(message->body.request.hash),
191{ 115 GNUNET_MESSENGER_OP_REQUEST,
192 handle_message_miss (room, tunnel, message, hash); 116 GNUNET_MESSENGER_REQUEST_DELAY
193} 117 );
194 118
195void 119 return GNUNET_YES;
196recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 120 }
197 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 121
198{ 122 struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
199 const struct GNUNET_MESSENGER_Message *msg = get_room_message (room, room->host, &(message->body.request.hash), 123 struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
200 GNUNET_NO); 124
125 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Callback for message (%s)\n", GNUNET_h2s (hash));
126
127 if (!member)
128 return GNUNET_NO;
129
130 struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, hash);
131
132 if ((!session) || (GNUNET_YES != check_member_session_history(session, hash, GNUNET_NO)))
133 return GNUNET_NO;
134
135 forward_tunnel_message (tunnel, msg, &(message->body.request.hash));
201 136
202 if (msg) 137 return GNUNET_NO;
203 forward_tunnel_message (tunnel, msg, &(message->body.request.hash));
204} 138}