aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-messenger.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-messenger.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-messenger.c')
-rw-r--r--src/messenger/gnunet-messenger.c132
1 files changed, 76 insertions, 56 deletions
diff --git a/src/messenger/gnunet-messenger.c b/src/messenger/gnunet-messenger.c
index 579e5c3ad..737bb83c8 100644
--- a/src/messenger/gnunet-messenger.c
+++ b/src/messenger/gnunet-messenger.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
@@ -34,29 +34,38 @@ struct GNUNET_MESSENGER_Handle *messenger;
34/** 34/**
35 * Function called whenever a message is received or sent. 35 * Function called whenever a message is received or sent.
36 * 36 *
37 * @param cls Closure 37 * @param[in/out] cls Closure
38 * @param room Room 38 * @param[in] room Room
39 * @param message Message 39 * @param[in] sender Sender of message
40 * @param hash Hash of message 40 * @param[in] message Message
41 * @param[in] hash Hash of message
42 * @param[in] flags Flags of message
41 */ 43 */
42void 44void
43on_message (void *cls, const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, 45on_message (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender,
44 const struct GNUNET_HashCode *hash) 46 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash,
47 enum GNUNET_MESSENGER_MessageFlags flags)
45{ 48{
46 struct GNUNET_MESSENGER_Contact *sender = GNUNET_MESSENGER_get_member (room, &(message->header.sender_id));
47
48 const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender); 49 const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender);
49 50
50 if (!sender_name) 51 if (!sender_name)
51 sender_name = "anonymous"; 52 sender_name = "anonymous";
52 53
54 printf ("[%s] ", GNUNET_sh2s(&(message->header.sender_id)));
55
56 if (flags & GNUNET_MESSENGER_FLAG_PRIVATE)
57 printf ("*");
58
53 switch (message->header.kind) 59 switch (message->header.kind)
54 { 60 {
55 case GNUNET_MESSENGER_KIND_JOIN: 61 case GNUNET_MESSENGER_KIND_JOIN:
56 { 62 {
57 printf ("* '%s' joined the room! [ %u %u %u %u ]\n", sender_name, message->body.join.key.ecdsa_key.q_y[0], 63 printf ("* '%s' joined the room!\n", sender_name);
58 message->body.join.key.ecdsa_key.q_y[1], message->body.join.key.ecdsa_key.q_y[2], 64 break;
59 message->body.join.key.ecdsa_key.q_y[3]); 65 }
66 case GNUNET_MESSENGER_KIND_NAME:
67 {
68 printf ("* '%s' gets renamed to '%s'\n", sender_name, message->body.name.name);
60 break; 69 break;
61 } 70 }
62 case GNUNET_MESSENGER_KIND_LEAVE: 71 case GNUNET_MESSENGER_KIND_LEAVE:
@@ -76,6 +85,7 @@ on_message (void *cls, const struct GNUNET_MESSENGER_Room *room, const struct GN
76 } 85 }
77 default: 86 default:
78 { 87 {
88 printf ("~ message: %s\n", GNUNET_MESSENGER_name_of_kind(message->header.kind));
79 break; 89 break;
80 } 90 }
81 } 91 }
@@ -86,7 +96,7 @@ struct GNUNET_SCHEDULER_Task *read_task;
86/** 96/**
87 * Task to shut down this application. 97 * Task to shut down this application.
88 * 98 *
89 * @param cls Closure 99 * @param[in/out] cls Closure
90 */ 100 */
91static void 101static void
92shutdown_hook (void *cls) 102shutdown_hook (void *cls)
@@ -108,10 +118,24 @@ listen_stdio (void *cls);
108 118
109#define MAX_BUFFER_SIZE 60000 119#define MAX_BUFFER_SIZE 60000
110 120
121static int
122iterate_send_private_message (void *cls, struct GNUNET_MESSENGER_Room *room,
123 const struct GNUNET_MESSENGER_Contact *contact)
124{
125 struct GNUNET_MESSENGER_Message *message = cls;
126
127 if (GNUNET_MESSENGER_contact_get_key(contact))
128 GNUNET_MESSENGER_send_message (room, message, contact);
129
130 return GNUNET_YES;
131}
132
133int private_mode;
134
111/** 135/**
112 * Task run in stdio mode, after some data is available at stdin. 136 * Task run in stdio mode, after some data is available at stdin.
113 * 137 *
114 * @param cls Closure 138 * @param[in/out] cls Closure
115 */ 139 */
116static void 140static void
117read_stdio (void *cls) 141read_stdio (void *cls)
@@ -140,7 +164,10 @@ read_stdio (void *cls)
140 message.header.kind = GNUNET_MESSENGER_KIND_TEXT; 164 message.header.kind = GNUNET_MESSENGER_KIND_TEXT;
141 message.body.text.text = buffer; 165 message.body.text.text = buffer;
142 166
143 GNUNET_MESSENGER_send_message (room, &message); 167 if (GNUNET_YES == private_mode)
168 GNUNET_MESSENGER_iterate_members(room, iterate_send_private_message, &message);
169 else
170 GNUNET_MESSENGER_send_message (room, &message, NULL);
144 171
145 read_task = GNUNET_SCHEDULER_add_now (listen_stdio, cls); 172 read_task = GNUNET_SCHEDULER_add_now (listen_stdio, cls);
146} 173}
@@ -148,7 +175,7 @@ read_stdio (void *cls)
148/** 175/**
149 * Wait for input on STDIO and send it out over the #ch. 176 * Wait for input on STDIO and send it out over the #ch.
150 * 177 *
151 * @param cls Closure 178 * @param[in/out] cls Closure
152 */ 179 */
153static void 180static void
154listen_stdio (void *cls) 181listen_stdio (void *cls)
@@ -160,10 +187,8 @@ listen_stdio (void *cls)
160 GNUNET_NETWORK_fdset_set_native (rs, 0); 187 GNUNET_NETWORK_fdset_set_native (rs, 0);
161 188
162 read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 189 read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
163 GNUNET_TIME_UNIT_FOREVER_REL, 190 GNUNET_TIME_UNIT_FOREVER_REL, rs,
164 rs, 191 NULL, &read_stdio, cls);
165 NULL,
166 &read_stdio, cls);
167 192
168 GNUNET_NETWORK_fdset_destroy (rs); 193 GNUNET_NETWORK_fdset_destroy (rs);
169} 194}
@@ -171,7 +196,7 @@ listen_stdio (void *cls)
171/** 196/**
172 * Initial task to startup application. 197 * Initial task to startup application.
173 * 198 *
174 * @param cls Closure 199 * @param[in/out] cls Closure
175 */ 200 */
176static void 201static void
177idle (void *cls) 202idle (void *cls)
@@ -192,8 +217,8 @@ struct GNUNET_SCHEDULER_Task *shutdown_task;
192/** 217/**
193 * Function called when an identity is retrieved. 218 * Function called when an identity is retrieved.
194 * 219 *
195 * @param cls Closure 220 * @param[in/out] cls Closure
196 * @param handle Handle of messenger service 221 * @param[in/out] handle Handle of messenger service
197 */ 222 */
198static void 223static void
199on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) 224on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle)
@@ -230,7 +255,7 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle)
230 { 255 {
231 printf ("* You try to entry a room...\n"); 256 printf ("* You try to entry a room...\n");
232 257
233 room = GNUNET_MESSENGER_entry_room (messenger, door, &key); 258 room = GNUNET_MESSENGER_enter_room (messenger, door, &key);
234 } 259 }
235 else 260 else
236 { 261 {
@@ -246,17 +271,26 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle)
246 if (!room) 271 if (!room)
247 GNUNET_SCHEDULER_shutdown (); 272 GNUNET_SCHEDULER_shutdown ();
248 else 273 else
274 {
275 struct GNUNET_MESSENGER_Message message;
276 message.header.kind = GNUNET_MESSENGER_KIND_NAME;
277 message.body.name.name = GNUNET_strdup(name);
278
279 GNUNET_MESSENGER_send_message (room, &message, NULL);
280 GNUNET_free(message.body.name.name);
281
249 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), GNUNET_SCHEDULER_PRIORITY_IDLE, idle, 282 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), GNUNET_SCHEDULER_PRIORITY_IDLE, idle,
250 room); 283 room);
284 }
251} 285}
252 286
253/** 287/**
254 * Main function that will be run by the scheduler. 288 * Main function that will be run by the scheduler.
255 * 289 *
256 * @param cls closure 290 * @param[in/out] cls closure
257 * @param args remaining command-line arguments 291 * @param[in] args remaining command-line arguments
258 * @param cfgfile name of the configuration file used (for saving, can be NULL!) 292 * @param[in] cfgfile name of the configuration file used (for saving, can be NULL!)
259 * @param cfg configuration 293 * @param[in] cfg configuration
260 */ 294 */
261static void 295static void
262run (void *cls, char *const*args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 296run (void *cls, char *const*args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -269,38 +303,24 @@ run (void *cls, char *const*args, const char *cfgfile, const struct GNUNET_CONFI
269/** 303/**
270 * The main function to obtain messenger information. 304 * The main function to obtain messenger information.
271 * 305 *
272 * @param argc number of arguments from the command line 306 * @param[in] argc number of arguments from the command line
273 * @param argv command line arguments 307 * @param[in] argv command line arguments
274 * @return 0 ok, 1 on error 308 * @return #EXIT_SUCCESS ok, #EXIT_FAILURE on error
275 */ 309 */
276int 310int
277main (int argc, char **argv) 311main (int argc, char **argv)
278{ 312{
279 const char *description = "Open and connect to rooms using the MESSENGER to chat."; 313 const char *description = "Open and connect to rooms using the MESSENGER to chat.";
280 314
281 struct GNUNET_GETOPT_CommandLineOption options[] = { 315 struct GNUNET_GETOPT_CommandLineOption options[] =
282 GNUNET_GETOPT_option_string ('d', 316 {
283 "door", 317 GNUNET_GETOPT_option_string ('d', "door", "PEERIDENTITY", "peer identity to entry into the room", &door_id),
284 "PEERIDENTITY", 318 GNUNET_GETOPT_option_string ('e', "ego", "IDENTITY", "identity to use for messaging", &ego_name),
285 "peer identity to entry into the room", 319 GNUNET_GETOPT_option_string ('r', "room", "ROOMKEY", "key of the room to connect to", &room_key),
286 &door_id), 320 GNUNET_GETOPT_option_flag ('p', "private", "flag to enable private mode", &private_mode),
287 GNUNET_GETOPT_option_string ('e', 321 GNUNET_GETOPT_OPTION_END
288 "ego", 322 };
289 "IDENTITY", 323
290 "identity to use for messaging", 324 return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-messenger\0", gettext_noop(description), options, &run,
291 &ego_name), 325 NULL) ? EXIT_SUCCESS : EXIT_FAILURE);
292 GNUNET_GETOPT_option_string ('r',
293 "room",
294 "ROOMKEY",
295 "key of the room to connect to",
296 &room_key),
297 GNUNET_GETOPT_OPTION_END };
298
299 return (GNUNET_OK == GNUNET_PROGRAM_run (argc,
300 argv,
301 "gnunet-messenger\0",
302 gettext_noop(description),
303 options,
304 &run,
305 NULL) ? EXIT_SUCCESS : EXIT_FAILURE);
306} 326}