diff options
Diffstat (limited to 'src/messenger/gnunet-messenger.c')
-rw-r--r-- | src/messenger/gnunet-messenger.c | 63 |
1 files changed, 54 insertions, 9 deletions
diff --git a/src/messenger/gnunet-messenger.c b/src/messenger/gnunet-messenger.c index 9444fa12d..0fa706319 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--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2023 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 |
@@ -29,6 +29,7 @@ | |||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_messenger_service.h" | 30 | #include "gnunet_messenger_service.h" |
31 | 31 | ||
32 | const struct GNUNET_CONFIGURATION_Handle *config; | ||
32 | struct GNUNET_MESSENGER_Handle *messenger; | 33 | struct GNUNET_MESSENGER_Handle *messenger; |
33 | 34 | ||
34 | /** | 35 | /** |
@@ -54,6 +55,8 @@ on_message (void *cls, | |||
54 | if (!sender_name) | 55 | if (!sender_name) |
55 | sender_name = "anonymous"; | 56 | sender_name = "anonymous"; |
56 | 57 | ||
58 | printf ("[%s ->", GNUNET_h2s(&(message->header.previous))); | ||
59 | printf (" %s]", GNUNET_h2s(hash)); | ||
57 | printf ("[%s] ", GNUNET_sh2s(&(message->header.sender_id))); | 60 | printf ("[%s] ", GNUNET_sh2s(&(message->header.sender_id))); |
58 | 61 | ||
59 | if (flags & GNUNET_MESSENGER_FLAG_PRIVATE) | 62 | if (flags & GNUNET_MESSENGER_FLAG_PRIVATE) |
@@ -97,9 +100,26 @@ on_message (void *cls, | |||
97 | break; | 100 | break; |
98 | } | 101 | } |
99 | } | 102 | } |
103 | |||
104 | if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) && (flags & GNUNET_MESSENGER_FLAG_SENT)) | ||
105 | { | ||
106 | const char* name = GNUNET_MESSENGER_get_name (messenger); | ||
107 | |||
108 | if (!name) | ||
109 | return; | ||
110 | |||
111 | struct GNUNET_MESSENGER_Message response; | ||
112 | response.header.kind = GNUNET_MESSENGER_KIND_NAME; | ||
113 | response.body.name.name = GNUNET_strdup (name); | ||
114 | |||
115 | GNUNET_MESSENGER_send_message (room, &response, NULL); | ||
116 | |||
117 | GNUNET_free (response.body.name.name); | ||
118 | } | ||
100 | } | 119 | } |
101 | 120 | ||
102 | struct GNUNET_SCHEDULER_Task *read_task; | 121 | struct GNUNET_SCHEDULER_Task *read_task; |
122 | struct GNUNET_IDENTITY_EgoLookup *ego_lookup; | ||
103 | 123 | ||
104 | /** | 124 | /** |
105 | * Task to shut down this application. | 125 | * Task to shut down this application. |
@@ -119,6 +139,9 @@ shutdown_hook (void *cls) | |||
119 | 139 | ||
120 | if (messenger) | 140 | if (messenger) |
121 | GNUNET_MESSENGER_disconnect (messenger); | 141 | GNUNET_MESSENGER_disconnect (messenger); |
142 | |||
143 | if (ego_lookup) | ||
144 | GNUNET_IDENTITY_ego_lookup_cancel (ego_lookup); | ||
122 | } | 145 | } |
123 | 146 | ||
124 | static void | 147 | static void |
@@ -276,18 +299,26 @@ on_identity (void *cls, | |||
276 | GNUNET_SCHEDULER_shutdown (); | 299 | GNUNET_SCHEDULER_shutdown (); |
277 | else | 300 | else |
278 | { | 301 | { |
279 | struct GNUNET_MESSENGER_Message message; | ||
280 | message.header.kind = GNUNET_MESSENGER_KIND_NAME; | ||
281 | message.body.name.name = GNUNET_strdup(name); | ||
282 | |||
283 | GNUNET_MESSENGER_send_message (room, &message, NULL); | ||
284 | GNUNET_free(message.body.name.name); | ||
285 | |||
286 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), GNUNET_SCHEDULER_PRIORITY_IDLE, idle, | 302 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), GNUNET_SCHEDULER_PRIORITY_IDLE, idle, |
287 | room); | 303 | room); |
288 | } | 304 | } |
289 | } | 305 | } |
290 | 306 | ||
307 | static void | ||
308 | on_ego_lookup (void *cls, | ||
309 | struct GNUNET_IDENTITY_Ego *ego) | ||
310 | { | ||
311 | ego_lookup = NULL; | ||
312 | |||
313 | const struct GNUNET_IDENTITY_PrivateKey *key; | ||
314 | key = ego ? GNUNET_IDENTITY_ego_get_private_key (ego) : NULL; | ||
315 | |||
316 | messenger = GNUNET_MESSENGER_connect (config, ego_name, key, &on_message, NULL); | ||
317 | |||
318 | on_identity (NULL, messenger); | ||
319 | } | ||
320 | |||
321 | |||
291 | /** | 322 | /** |
292 | * Main function that will be run by the scheduler. | 323 | * Main function that will be run by the scheduler. |
293 | * | 324 | * |
@@ -302,9 +333,23 @@ run (void *cls, | |||
302 | const char *cfgfile, | 333 | const char *cfgfile, |
303 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 334 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
304 | { | 335 | { |
305 | messenger = GNUNET_MESSENGER_connect (cfg, ego_name, &on_identity, NULL, &on_message, NULL); | 336 | config = cfg; |
337 | |||
338 | if (ego_name) | ||
339 | { | ||
340 | ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &on_ego_lookup, NULL); | ||
341 | messenger = NULL; | ||
342 | } | ||
343 | else | ||
344 | { | ||
345 | ego_lookup = NULL; | ||
346 | messenger = GNUNET_MESSENGER_connect (cfg, NULL, NULL, &on_message, NULL); | ||
347 | } | ||
306 | 348 | ||
307 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_hook, NULL); | 349 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_hook, NULL); |
350 | |||
351 | if (messenger) | ||
352 | on_identity (NULL, messenger); | ||
308 | } | 353 | } |
309 | 354 | ||
310 | /** | 355 | /** |