aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/gnunet-service-messenger_service.c')
-rw-r--r--src/messenger/gnunet-service-messenger_service.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/messenger/gnunet-service-messenger_service.c b/src/messenger/gnunet-service-messenger_service.c
index 8dfc258c1..2f4d7bf80 100644
--- a/src/messenger/gnunet-service-messenger_service.c
+++ b/src/messenger/gnunet-service-messenger_service.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--2022 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
@@ -25,8 +25,8 @@
25 25
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-messenger_service.h" 27#include "gnunet-service-messenger_service.h"
28#include "gnunet-service-messenger_message_kind.h"
29#include "gnunet-service-messenger.h" 28#include "gnunet-service-messenger.h"
29#include "messenger_api_message_kind.h"
30 30
31static void 31static void
32callback_shutdown_service (void *cls) 32callback_shutdown_service (void *cls)
@@ -54,6 +54,7 @@ create_service (const struct GNUNET_CONFIGURATION_Handle *config,
54 54
55 service->shutdown = GNUNET_SCHEDULER_add_shutdown (&callback_shutdown_service, service); 55 service->shutdown = GNUNET_SCHEDULER_add_shutdown (&callback_shutdown_service, service);
56 56
57 service->peer = NULL;
57 service->dir = NULL; 58 service->dir = NULL;
58 59
59 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (service->config, 60 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (service->config,
@@ -78,13 +79,11 @@ create_service (const struct GNUNET_CONFIGURATION_Handle *config,
78 79
79 service->cadet = GNUNET_CADET_connect (service->config); 80 service->cadet = GNUNET_CADET_connect (service->config);
80 81
81 init_ego_store(get_service_ego_store(service), service->config);
82
83 init_list_handles (&(service->handles)); 82 init_list_handles (&(service->handles));
84 83
85 service->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); 84 service->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
86 85
87 init_contact_store(get_service_contact_store(service)); 86 init_contact_store (get_service_contact_store (service));
88 87
89 return service; 88 return service;
90} 89}
@@ -111,13 +110,12 @@ destroy_service (struct GNUNET_MESSENGER_Service *service)
111 service->shutdown = NULL; 110 service->shutdown = NULL;
112 } 111 }
113 112
114 clear_ego_store(get_service_ego_store(service));
115 clear_list_handles (&(service->handles)); 113 clear_list_handles (&(service->handles));
116 114
117 GNUNET_CONTAINER_multihashmap_iterate (service->rooms, iterate_destroy_rooms, NULL); 115 GNUNET_CONTAINER_multihashmap_iterate (service->rooms, iterate_destroy_rooms, NULL);
118 GNUNET_CONTAINER_multihashmap_destroy (service->rooms); 116 GNUNET_CONTAINER_multihashmap_destroy (service->rooms);
119 117
120 clear_contact_store(get_service_contact_store(service)); 118 clear_contact_store (get_service_contact_store (service));
121 119
122 if (service->cadet) 120 if (service->cadet)
123 { 121 {
@@ -133,17 +131,16 @@ destroy_service (struct GNUNET_MESSENGER_Service *service)
133 service->dir = NULL; 131 service->dir = NULL;
134 } 132 }
135 133
136 GNUNET_SERVICE_shutdown (service->service); 134 if (service->peer)
135 {
136 GNUNET_free(service->peer);
137 137
138 GNUNET_free(service); 138 service->peer = NULL;
139} 139 }
140 140
141struct GNUNET_MESSENGER_EgoStore* 141 GNUNET_SERVICE_shutdown (service->service);
142get_service_ego_store (struct GNUNET_MESSENGER_Service *service)
143{
144 GNUNET_assert(service);
145 142
146 return &(service->ego_store); 143 GNUNET_free(service);
147} 144}
148 145
149struct GNUNET_MESSENGER_ContactStore* 146struct GNUNET_MESSENGER_ContactStore*
@@ -184,12 +181,27 @@ remove_service_handle (struct GNUNET_MESSENGER_Service *service,
184} 181}
185 182
186int 183int
187get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, 184get_service_peer_identity (struct GNUNET_MESSENGER_Service *service,
188 struct GNUNET_PeerIdentity *peer) 185 struct GNUNET_PeerIdentity *peer)
189{ 186{
190 GNUNET_assert((service) && (peer)); 187 GNUNET_assert((service) && (peer));
191 188
192 return GNUNET_CRYPTO_get_peer_identity (service->config, peer); 189 if (service->peer)
190 {
191 GNUNET_memcpy(peer, service->peer, sizeof(struct GNUNET_PeerIdentity));
192 return GNUNET_OK;
193 }
194
195 int result = GNUNET_CRYPTO_get_peer_identity(service->config, peer);
196
197 if (GNUNET_OK != result)
198 return result;
199
200 if (!service->peer)
201 service->peer = GNUNET_new(struct GNUNET_PeerIdentity);
202
203 GNUNET_memcpy(service->peer, peer, sizeof(struct GNUNET_PeerIdentity));
204 return result;
193} 205}
194 206
195struct GNUNET_MESSENGER_SrvRoom* 207struct GNUNET_MESSENGER_SrvRoom*
@@ -272,8 +284,6 @@ close_service_room (struct GNUNET_MESSENGER_Service *service,
272 if (!room) 284 if (!room)
273 return GNUNET_NO; 285 return GNUNET_NO;
274 286
275 send_srv_room_message (room, handle, create_message_leave ());
276
277 const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, key); 287 const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, key);
278 288
279 GNUNET_assert(id); 289 GNUNET_assert(id);
@@ -304,7 +314,7 @@ close_service_room (struct GNUNET_MESSENGER_Service *service,
304void 314void
305handle_service_message (struct GNUNET_MESSENGER_Service *service, 315handle_service_message (struct GNUNET_MESSENGER_Service *service,
306 struct GNUNET_MESSENGER_SrvRoom *room, 316 struct GNUNET_MESSENGER_SrvRoom *room,
307 const struct GNUNET_MESSENGER_MemberSession *session, 317 const struct GNUNET_MESSENGER_SenderSession *session,
308 const struct GNUNET_MESSENGER_Message *message, 318 const struct GNUNET_MESSENGER_Message *message,
309 const struct GNUNET_HashCode *hash) 319 const struct GNUNET_HashCode *hash)
310{ 320{