aboutsummaryrefslogtreecommitdiff
path: root/src/messenger
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-04-02 20:02:54 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-04-02 20:02:54 +0200
commite95235a5f71aa40dea29a02cd8d4d1625add7d39 (patch)
tree45bbc8ec52f557501976249c07dfdb59b0287575 /src/messenger
parent7317fe5b9910cf5b15038fe0806d0539423f9d51 (diff)
downloadgnunet-e95235a5f71aa40dea29a02cd8d4d1625add7d39.tar.gz
gnunet-e95235a5f71aa40dea29a02cd8d4d1625add7d39.zip
-implement messenger key update, fix ego store operations
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/messenger')
-rw-r--r--src/messenger/gnunet-service-messenger_ego_store.c175
-rw-r--r--src/messenger/gnunet-service-messenger_ego_store.h57
-rw-r--r--src/messenger/gnunet-service-messenger_handle.c56
3 files changed, 231 insertions, 57 deletions
diff --git a/src/messenger/gnunet-service-messenger_ego_store.c b/src/messenger/gnunet-service-messenger_ego_store.c
index c460ac1c7..bcc301e95 100644
--- a/src/messenger/gnunet-service-messenger_ego_store.c
+++ b/src/messenger/gnunet-service-messenger_ego_store.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--2022 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
@@ -33,14 +33,21 @@ callback_update_ego (void *cls,
33 void **ctx, 33 void **ctx,
34 const char *identifier) 34 const char *identifier)
35{ 35{
36 if ((!ego) || (!identifier)) 36 if ((!ctx) || (!identifier))
37 return; 37 return;
38 38
39 struct GNUNET_MESSENGER_EgoStore *store = cls; 39 struct GNUNET_MESSENGER_EgoStore *store = cls;
40 40
41 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New ego in use: '%s'\n", identifier); 41 if (ego)
42 42 {
43 update_store_ego (store, identifier, GNUNET_IDENTITY_ego_get_private_key (ego)); 43 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New ego in use: '%s'\n", identifier);
44 update_store_ego (store, identifier, GNUNET_IDENTITY_ego_get_private_key (ego));
45 }
46 else
47 {
48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego got deleted: '%s'\n", identifier);
49 delete_store_ego (store, identifier);
50 }
44} 51}
45 52
46void 53void
@@ -52,6 +59,7 @@ init_ego_store(struct GNUNET_MESSENGER_EgoStore *store,
52 store->cfg = config; 59 store->cfg = config;
53 store->identity = GNUNET_IDENTITY_connect (config, &callback_update_ego, store); 60 store->identity = GNUNET_IDENTITY_connect (config, &callback_update_ego, store);
54 store->egos = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); 61 store->egos = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
62 store->handles = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
55 63
56 store->lu_start = NULL; 64 store->lu_start = NULL;
57 store->lu_end = NULL; 65 store->lu_end = NULL;
@@ -60,7 +68,6 @@ init_ego_store(struct GNUNET_MESSENGER_EgoStore *store,
60 store->op_end = NULL; 68 store->op_end = NULL;
61} 69}
62 70
63
64static int 71static int
65iterate_destroy_egos (void *cls, 72iterate_destroy_egos (void *cls,
66 const struct GNUNET_HashCode *key, 73 const struct GNUNET_HashCode *key,
@@ -109,6 +116,8 @@ clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store)
109 GNUNET_CONTAINER_multihashmap_iterate (store->egos, iterate_destroy_egos, NULL); 116 GNUNET_CONTAINER_multihashmap_iterate (store->egos, iterate_destroy_egos, NULL);
110 GNUNET_CONTAINER_multihashmap_destroy (store->egos); 117 GNUNET_CONTAINER_multihashmap_destroy (store->egos);
111 118
119 GNUNET_CONTAINER_multihashmap_destroy (store->handles);
120
112 if (store->identity) 121 if (store->identity)
113 { 122 {
114 GNUNET_IDENTITY_disconnect (store->identity); 123 GNUNET_IDENTITY_disconnect (store->identity);
@@ -117,6 +126,16 @@ clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store)
117 } 126 }
118} 127}
119 128
129static int
130iterate_create_ego (void *cls,
131 const struct GNUNET_HashCode *key,
132 void *value)
133{
134 struct GNUNET_MESSENGER_SrvHandle *handle = value;
135 set_handle_ego (handle, (struct GNUNET_MESSENGER_Ego*) cls);
136 return GNUNET_YES;
137}
138
120static void 139static void
121callback_ego_create (void *cls, 140callback_ego_create (void *cls,
122 const struct GNUNET_IDENTITY_PrivateKey *key, 141 const struct GNUNET_IDENTITY_PrivateKey *key,
@@ -125,21 +144,22 @@ callback_ego_create (void *cls,
125 struct GNUNET_MESSENGER_EgoOperation *element = cls; 144 struct GNUNET_MESSENGER_EgoOperation *element = cls;
126 struct GNUNET_MESSENGER_EgoStore *store = element->store; 145 struct GNUNET_MESSENGER_EgoStore *store = element->store;
127 146
128 GNUNET_assert(element->identifier); 147 GNUNET_assert (element->identifier);
129 148
130 if (emsg) 149 if (emsg)
131 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); 150 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
132 151
133 if (key) 152 if (key)
134 { 153 {
135 struct GNUNET_MESSENGER_SrvHandle *handle = element->handle;
136
137 struct GNUNET_MESSENGER_Ego *msg_ego = update_store_ego (store, element->identifier, key); 154 struct GNUNET_MESSENGER_Ego *msg_ego = update_store_ego (store, element->identifier, key);
138 155
139 set_handle_ego (handle, msg_ego); 156 struct GNUNET_HashCode hash;
157 GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash);
158
159 GNUNET_CONTAINER_multihashmap_get_multiple (store->handles, &hash, iterate_create_ego, msg_ego);
140 } 160 }
141 else 161 else
142 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Creating ego failed!\n"); 162 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating ego failed!\n");
143 163
144 GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element); 164 GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element);
145 GNUNET_free (element->identifier); 165 GNUNET_free (element->identifier);
@@ -148,15 +168,16 @@ callback_ego_create (void *cls,
148 168
149void 169void
150create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, 170create_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
151 const char *identifier, 171 const char *identifier)
152 void *handle)
153{ 172{
154 GNUNET_assert ((store) && (identifier)); 173 GNUNET_assert ((store) && (identifier));
155 174
175 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store create ego: %s\n", identifier);
176
156 struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation); 177 struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation);
157 178
158 element->store = store; 179 element->store = store;
159 element->handle = handle; 180 element->cls = NULL;
160 181
161 element->identifier = GNUNET_strdup (identifier); 182 element->identifier = GNUNET_strdup (identifier);
162 183
@@ -166,6 +187,38 @@ create_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
166 GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element); 187 GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element);
167} 188}
168 189
190void
191bind_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
192 const char *identifier,
193 void *handle)
194{
195 GNUNET_assert ((store) && (identifier) && (handle));
196
197 struct GNUNET_HashCode hash;
198 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
199
200 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(store->handles, &hash, handle))
201 return;
202
203 GNUNET_CONTAINER_multihashmap_put(store->handles, &hash, handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
204}
205
206void
207unbind_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
208 const char *identifier,
209 void *handle)
210{
211 GNUNET_assert ((store) && (identifier) && (handle));
212
213 struct GNUNET_HashCode hash;
214 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
215
216 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains_value(store->handles, &hash, handle))
217 return;
218
219 GNUNET_CONTAINER_multihashmap_remove(store->handles, &hash, handle);
220}
221
169static void 222static void
170callback_ego_lookup (void *cls, 223callback_ego_lookup (void *cls,
171 struct GNUNET_IDENTITY_Ego *ego) 224 struct GNUNET_IDENTITY_Ego *ego)
@@ -173,7 +226,7 @@ callback_ego_lookup (void *cls,
173 struct GNUNET_MESSENGER_EgoLookup *element = cls; 226 struct GNUNET_MESSENGER_EgoLookup *element = cls;
174 struct GNUNET_MESSENGER_EgoStore *store = element->store; 227 struct GNUNET_MESSENGER_EgoStore *store = element->store;
175 228
176 GNUNET_assert(element->identifier); 229 GNUNET_assert (element->identifier);
177 230
178 struct GNUNET_MESSENGER_Ego *msg_ego; 231 struct GNUNET_MESSENGER_Ego *msg_ego;
179 232
@@ -200,6 +253,8 @@ lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store,
200{ 253{
201 GNUNET_assert (store); 254 GNUNET_assert (store);
202 255
256 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store lookup ego: %s\n", identifier);
257
203 if (!identifier) 258 if (!identifier)
204 { 259 {
205 lookup(cls, identifier, NULL); 260 lookup(cls, identifier, NULL);
@@ -231,12 +286,14 @@ lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store,
231} 286}
232 287
233struct GNUNET_MESSENGER_Ego* 288struct GNUNET_MESSENGER_Ego*
234update_store_ego(struct GNUNET_MESSENGER_EgoStore *store, 289update_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
235 const char *identifier, 290 const char *identifier,
236 const struct GNUNET_IDENTITY_PrivateKey *key) 291 const struct GNUNET_IDENTITY_PrivateKey *key)
237{ 292{
238 GNUNET_assert ((store) && (identifier) && (key)); 293 GNUNET_assert ((store) && (identifier) && (key));
239 294
295 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store update ego: %s\n", identifier);
296
240 struct GNUNET_HashCode hash; 297 struct GNUNET_HashCode hash;
241 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); 298 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
242 299
@@ -256,6 +313,29 @@ update_store_ego(struct GNUNET_MESSENGER_EgoStore *store,
256 return ego; 313 return ego;
257} 314}
258 315
316void
317delete_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
318 const char *identifier)
319{
320 GNUNET_assert ((store) && (identifier));
321
322 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store delete ego: %s\n", identifier);
323
324 struct GNUNET_HashCode hash;
325 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
326
327 struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
328
329 if (ego)
330 {
331 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Ego is not stored!\n");
332 return;
333 }
334
335 GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, ego);
336 GNUNET_free(ego);
337}
338
259static void 339static void
260callback_ego_rename (void *cls, 340callback_ego_rename (void *cls,
261 const char *emsg) 341 const char *emsg)
@@ -263,19 +343,24 @@ callback_ego_rename (void *cls,
263 struct GNUNET_MESSENGER_EgoOperation *element = cls; 343 struct GNUNET_MESSENGER_EgoOperation *element = cls;
264 struct GNUNET_MESSENGER_EgoStore *store = element->store; 344 struct GNUNET_MESSENGER_EgoStore *store = element->store;
265 345
266 GNUNET_assert(element->identifier); 346 GNUNET_assert (element->identifier);
267 347
268 if (emsg) 348 if (emsg)
269 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); 349 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
270 350
271 struct GNUNET_HashCode hash; 351 struct GNUNET_HashCode hash;
272 GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash); 352 GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash);
273 353
274 struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash); 354 struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
275 355
356 if (!ego)
357 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Ego is not stored!\n");
358
359 char *identifier = (char*) element->cls;
360
276 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, ego)) 361 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, ego))
277 { 362 {
278 GNUNET_CRYPTO_hash ((char*) element->handle, strlen ((char*) element->handle), &hash); 363 GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
279 364
280 GNUNET_CONTAINER_multihashmap_put (store->egos, &hash, ego, 365 GNUNET_CONTAINER_multihashmap_put (store->egos, &hash, ego,
281 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 366 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
@@ -283,7 +368,7 @@ callback_ego_rename (void *cls,
283 else 368 else
284 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Renaming ego failed!\n"); 369 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Renaming ego failed!\n");
285 370
286 GNUNET_free (element->handle); 371 GNUNET_free (identifier);
287 372
288 GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element); 373 GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element);
289 GNUNET_free (element->identifier); 374 GNUNET_free (element->identifier);
@@ -297,10 +382,12 @@ rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
297{ 382{
298 GNUNET_assert ((store) && (old_identifier) && (new_identifier)); 383 GNUNET_assert ((store) && (old_identifier) && (new_identifier));
299 384
385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store rename ego: %s -> %s\n", old_identifier, new_identifier);
386
300 struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation); 387 struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation);
301 388
302 element->store = store; 389 element->store = store;
303 element->handle = GNUNET_strdup (new_identifier); 390 element->cls = GNUNET_strdup (new_identifier);
304 391
305 element->identifier = GNUNET_strdup (old_identifier); 392 element->identifier = GNUNET_strdup (old_identifier);
306 393
@@ -308,3 +395,43 @@ rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
308 395
309 GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element); 396 GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element);
310} 397}
398
399
400static void
401callback_ego_delete (void *cls,
402 const char *emsg)
403{
404 struct GNUNET_MESSENGER_EgoOperation *element = cls;
405 struct GNUNET_MESSENGER_EgoStore *store = element->store;
406
407 GNUNET_assert (element->identifier);
408
409 if (emsg)
410 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
411
412 create_store_ego (store, element->identifier);
413
414 GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element);
415 GNUNET_free (element->identifier);
416 GNUNET_free (element);
417}
418
419void
420renew_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
421 const char *identifier)
422{
423 GNUNET_assert ((store) && (identifier));
424
425 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store renew ego: %s\n", identifier);
426
427 struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation);
428
429 element->store = store;
430 element->cls = NULL;
431
432 element->identifier = GNUNET_strdup (identifier);
433
434 element->operation = GNUNET_IDENTITY_delete(store->identity, identifier, callback_ego_delete, element);
435
436 GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element);
437}
diff --git a/src/messenger/gnunet-service-messenger_ego_store.h b/src/messenger/gnunet-service-messenger_ego_store.h
index 4222a4e91..4ed2bbf6d 100644
--- a/src/messenger/gnunet-service-messenger_ego_store.h
+++ b/src/messenger/gnunet-service-messenger_ego_store.h
@@ -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--2022 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
@@ -62,7 +62,8 @@ struct GNUNET_MESSENGER_EgoOperation
62 struct GNUNET_IDENTITY_Operation *operation; 62 struct GNUNET_IDENTITY_Operation *operation;
63 63
64 struct GNUNET_MESSENGER_EgoStore *store; 64 struct GNUNET_MESSENGER_EgoStore *store;
65 void *handle; 65
66 void *cls;
66 67
67 char *identifier; 68 char *identifier;
68}; 69};
@@ -73,6 +74,7 @@ struct GNUNET_MESSENGER_EgoStore
73 74
74 struct GNUNET_IDENTITY_Handle *identity; 75 struct GNUNET_IDENTITY_Handle *identity;
75 struct GNUNET_CONTAINER_MultiHashMap *egos; 76 struct GNUNET_CONTAINER_MultiHashMap *egos;
77 struct GNUNET_CONTAINER_MultiHashMap *handles;
76 78
77 struct GNUNET_MESSENGER_EgoLookup *lu_start; 79 struct GNUNET_MESSENGER_EgoLookup *lu_start;
78 struct GNUNET_MESSENGER_EgoLookup *lu_end; 80 struct GNUNET_MESSENGER_EgoLookup *lu_end;
@@ -101,15 +103,38 @@ clear_ego_store (struct GNUNET_MESSENGER_EgoStore *store);
101 103
102/** 104/**
103 * Creates a new EGO which will be registered to a <i>store</i> under 105 * Creates a new EGO which will be registered to a <i>store</i> under
104 * a specific <i>identifier</i>. A given <i>handle</i> will be informed 106 * a specific <i>identifier</i>.
105 * about the creation and changes its EGO accordingly.
106 * 107 *
107 * @param[in/out] store EGO-store 108 * @param[in/out] store EGO-store
108 * @param[in] identifier Identifier string 109 * @param[in] identifier Identifier string
109 * @param[in/out] handle Handle or NULL
110 */ 110 */
111void 111void
112create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, 112create_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
113 const char *identifier);
114
115/**
116 * Binds an EGO which was registered to a <i>store</i> under
117 * a specific <i>identifier</i> to a given <i>handle</i>
118 *
119 * @param[in/out] store EGO-store
120 * @param[in] identifier Identifier string
121 * @param[in/out] handle Handle
122 */
123void
124bind_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
125 const char *identifier,
126 void *handle);
127
128/**
129 * Binds an EGO which was registered to a <i>store</i> under
130 * a specific <i>identifier</i> to a given <i>handle</i>
131 *
132 * @param[in/out] store EGO-store
133 * @param[in] identifier Identifier string
134 * @param[in/out] handle Handle
135 */
136void
137unbind_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
113 const char *identifier, 138 const char *identifier,
114 void *handle); 139 void *handle);
115 140
@@ -143,6 +168,17 @@ update_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
143 const struct GNUNET_IDENTITY_PrivateKey *key); 168 const struct GNUNET_IDENTITY_PrivateKey *key);
144 169
145/** 170/**
171 * Deletes the registration of an EGO in a <i>store</i> under
172 * a specific <i>identifier</i>.
173 *
174 * @param[in/out] store EGO-store
175 * @param[in] identifier Identifier string
176 */
177void
178delete_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
179 const char *identifier);
180
181/**
146 * Updates the location of a registered EGO in a <i>store</i> to 182 * Updates the location of a registered EGO in a <i>store</i> to
147 * a different one under a specific <i>new_identifier<i> replacing 183 * a different one under a specific <i>new_identifier<i> replacing
148 * its old one. 184 * its old one.
@@ -156,4 +192,15 @@ rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
156 const char *old_identifier, 192 const char *old_identifier,
157 const char *new_identifier); 193 const char *new_identifier);
158 194
195/**
196 * Replaces the registered EGO in a <i>store</i> under a specific
197 * <i>identifier</i> with a newly created one.
198 *
199 * @param[in/out] store EGO-store
200 * @param[in] identifier Identifier string
201 */
202void
203renew_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
204 const char *identifier);
205
159#endif //GNUNET_SERVICE_MESSENGER_EGO_STORE_H 206#endif //GNUNET_SERVICE_MESSENGER_EGO_STORE_H
diff --git a/src/messenger/gnunet-service-messenger_handle.c b/src/messenger/gnunet-service-messenger_handle.c
index 341bb7251..218482e45 100644
--- a/src/messenger/gnunet-service-messenger_handle.c
+++ b/src/messenger/gnunet-service-messenger_handle.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--2022 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
@@ -68,7 +68,13 @@ destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
68 save_handle_configuration (handle); 68 save_handle_configuration (handle);
69 69
70 if (handle->name) 70 if (handle->name)
71 {
72 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
73
74 unbind_store_ego(store, handle->name, handle);
75
71 GNUNET_free(handle->name); 76 GNUNET_free(handle->name);
77 }
72 78
73 GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_free_member_ids, NULL); 79 GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_free_member_ids, NULL);
74 GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids); 80 GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids);
@@ -317,24 +323,26 @@ callback_update_handle (void *cls,
317{ 323{
318 struct GNUNET_MESSENGER_SrvHandle *handle = cls; 324 struct GNUNET_MESSENGER_SrvHandle *handle = cls;
319 325
320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating handle...\n"); 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating handle...\n");
321 327
322 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service); 328 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
323 329
330 bind_store_ego(store, handle->name, handle);
331
324 if (!ego) 332 if (!ego)
325 create_store_ego(store, handle->name, handle); 333 create_store_ego (store, handle->name);
326 else 334 else
327 change_handle_ego (handle, ego); 335 renew_store_ego (store, handle->name);
328} 336}
329 337
330void 338void
331update_handle (struct GNUNET_MESSENGER_SrvHandle *handle) 339update_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
332{ 340{
333 GNUNET_assert(handle); 341 GNUNET_assert (handle);
334 342
335 if (!handle->name) 343 if (!handle->name)
336 { 344 {
337 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating handle failed: Name is required!\n"); 345 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Updating handle failed: Name is required!\n");
338 return; 346 return;
339 } 347 }
340 348
@@ -360,46 +368,38 @@ callback_set_handle_name (void *cls,
360 368
361 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service); 369 struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
362 370
363 int rename_ego_in_store = handle->ego? GNUNET_YES : GNUNET_NO;
364
365 char *old_dir; 371 char *old_dir;
366 get_handle_data_subdir (handle, handle->name, &old_dir); 372 get_handle_data_subdir (handle, handle->name, &old_dir);
367 373
368 char *new_dir; 374 char *new_dir;
369 get_handle_data_subdir (handle, name, &new_dir); 375 get_handle_data_subdir (handle, name, &new_dir);
370 376
371 int result = 0; 377 if ((GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO)) &&
378 (GNUNET_OK != GNUNET_DISK_directory_remove(new_dir)))
379 goto free_dirs;
372 380
373 if (GNUNET_YES == GNUNET_DISK_directory_test (old_dir, GNUNET_YES)) 381 if (GNUNET_YES == GNUNET_DISK_directory_test (old_dir, GNUNET_YES))
374 { 382 {
375 GNUNET_DISK_directory_create_for_file (new_dir); 383 GNUNET_DISK_directory_create_for_file (new_dir);
376 384
377 result = rename (old_dir, new_dir); 385 if (0 != rename (old_dir, new_dir))
386 goto free_dirs;
378 } 387 }
379 else if (GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO))
380 result = -1;
381
382 if (0 == result)
383 {
384 struct GNUNET_MESSENGER_MessageHandle msg_handle;
385 388
386 msg_handle.handle = handle; 389 if (handle->ego)
387 msg_handle.message = create_message_name (name); 390 rename_store_ego(store, handle->name, name);
388
389 GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_send_message, &msg_handle);
390 391
391 destroy_message (msg_handle.message); 392 struct GNUNET_MESSENGER_MessageHandle msg_handle;
393 msg_handle.handle = handle;
394 msg_handle.message = create_message_name (name);
392 395
393 change_handle_name (handle, name); 396 GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_send_message, &msg_handle);
394 } 397 destroy_message (msg_handle.message);
395 else 398 change_handle_name (handle, name);
396 rename_ego_in_store = GNUNET_NO;
397 399
400free_dirs:
398 GNUNET_free(old_dir); 401 GNUNET_free(old_dir);
399 GNUNET_free(new_dir); 402 GNUNET_free(new_dir);
400
401 if (GNUNET_YES == rename_ego_in_store)
402 rename_store_ego(store, handle->name, name);
403} 403}
404 404
405void 405void