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.c98
1 files changed, 61 insertions, 37 deletions
diff --git a/src/messenger/gnunet-service-messenger_service.c b/src/messenger/gnunet-service-messenger_service.c
index 2f4d7bf80..b72bbd201 100644
--- a/src/messenger/gnunet-service-messenger_service.c
+++ b/src/messenger/gnunet-service-messenger_service.c
@@ -41,37 +41,43 @@ callback_shutdown_service (void *cls)
41 } 41 }
42} 42}
43 43
44
44struct GNUNET_MESSENGER_Service* 45struct GNUNET_MESSENGER_Service*
45create_service (const struct GNUNET_CONFIGURATION_Handle *config, 46create_service (const struct GNUNET_CONFIGURATION_Handle *config,
46 struct GNUNET_SERVICE_Handle *service_handle) 47 struct GNUNET_SERVICE_Handle *service_handle)
47{ 48{
48 GNUNET_assert((config) && (service_handle)); 49 GNUNET_assert ((config) && (service_handle));
49 50
50 struct GNUNET_MESSENGER_Service *service = GNUNET_new(struct GNUNET_MESSENGER_Service); 51 struct GNUNET_MESSENGER_Service *service = GNUNET_new (struct
52 GNUNET_MESSENGER_Service);
51 53
52 service->config = config; 54 service->config = config;
53 service->service = service_handle; 55 service->service = service_handle;
54 56
55 service->shutdown = GNUNET_SCHEDULER_add_shutdown (&callback_shutdown_service, service); 57 service->shutdown = GNUNET_SCHEDULER_add_shutdown (&callback_shutdown_service,
58 service);
56 59
57 service->peer = NULL; 60 service->peer = NULL;
58 service->dir = NULL; 61 service->dir = NULL;
59 62
60 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (service->config, 63 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (service->config,
61 GNUNET_MESSENGER_SERVICE_NAME, 64 GNUNET_MESSENGER_SERVICE_NAME,
62 "MESSENGER_DIR", &(service->dir))) 65 "MESSENGER_DIR",
66 &(service->dir)))
63 { 67 {
64 if (service->dir) 68 if (service->dir)
65 GNUNET_free(service->dir); 69 GNUNET_free (service->dir);
66 70
67 service->dir = NULL; 71 service->dir = NULL;
68 } 72 }
69 else 73 else
70 { 74 {
71 if ((GNUNET_YES != GNUNET_DISK_directory_test (service->dir, GNUNET_YES)) && (GNUNET_OK 75 if ((GNUNET_YES != GNUNET_DISK_directory_test (service->dir, GNUNET_YES)) &&
72 != GNUNET_DISK_directory_create (service->dir))) 76 (GNUNET_OK
77 !=
78 GNUNET_DISK_directory_create (service->dir)))
73 { 79 {
74 GNUNET_free(service->dir); 80 GNUNET_free (service->dir);
75 81
76 service->dir = NULL; 82 service->dir = NULL;
77 } 83 }
@@ -88,6 +94,7 @@ create_service (const struct GNUNET_CONFIGURATION_Handle *config,
88 return service; 94 return service;
89} 95}
90 96
97
91static int 98static int
92iterate_destroy_rooms (void *cls, 99iterate_destroy_rooms (void *cls,
93 const struct GNUNET_HashCode *key, 100 const struct GNUNET_HashCode *key,
@@ -98,10 +105,11 @@ iterate_destroy_rooms (void *cls,
98 return GNUNET_YES; 105 return GNUNET_YES;
99} 106}
100 107
108
101void 109void
102destroy_service (struct GNUNET_MESSENGER_Service *service) 110destroy_service (struct GNUNET_MESSENGER_Service *service)
103{ 111{
104 GNUNET_assert(service); 112 GNUNET_assert (service);
105 113
106 if (service->shutdown) 114 if (service->shutdown)
107 { 115 {
@@ -112,7 +120,8 @@ destroy_service (struct GNUNET_MESSENGER_Service *service)
112 120
113 clear_list_handles (&(service->handles)); 121 clear_list_handles (&(service->handles));
114 122
115 GNUNET_CONTAINER_multihashmap_iterate (service->rooms, iterate_destroy_rooms, NULL); 123 GNUNET_CONTAINER_multihashmap_iterate (service->rooms, iterate_destroy_rooms,
124 NULL);
116 GNUNET_CONTAINER_multihashmap_destroy (service->rooms); 125 GNUNET_CONTAINER_multihashmap_destroy (service->rooms);
117 126
118 clear_contact_store (get_service_contact_store (service)); 127 clear_contact_store (get_service_contact_store (service));
@@ -126,36 +135,38 @@ destroy_service (struct GNUNET_MESSENGER_Service *service)
126 135
127 if (service->dir) 136 if (service->dir)
128 { 137 {
129 GNUNET_free(service->dir); 138 GNUNET_free (service->dir);
130 139
131 service->dir = NULL; 140 service->dir = NULL;
132 } 141 }
133 142
134 if (service->peer) 143 if (service->peer)
135 { 144 {
136 GNUNET_free(service->peer); 145 GNUNET_free (service->peer);
137 146
138 service->peer = NULL; 147 service->peer = NULL;
139 } 148 }
140 149
141 GNUNET_SERVICE_shutdown (service->service); 150 GNUNET_SERVICE_shutdown (service->service);
142 151
143 GNUNET_free(service); 152 GNUNET_free (service);
144} 153}
145 154
155
146struct GNUNET_MESSENGER_ContactStore* 156struct GNUNET_MESSENGER_ContactStore*
147get_service_contact_store (struct GNUNET_MESSENGER_Service *service) 157get_service_contact_store (struct GNUNET_MESSENGER_Service *service)
148{ 158{
149 GNUNET_assert(service); 159 GNUNET_assert (service);
150 160
151 return &(service->contact_store); 161 return &(service->contact_store);
152} 162}
153 163
164
154struct GNUNET_MESSENGER_SrvHandle* 165struct GNUNET_MESSENGER_SrvHandle*
155add_service_handle (struct GNUNET_MESSENGER_Service *service, 166add_service_handle (struct GNUNET_MESSENGER_Service *service,
156 struct GNUNET_MQ_Handle *mq) 167 struct GNUNET_MQ_Handle *mq)
157{ 168{
158 GNUNET_assert((service) && (mq)); 169 GNUNET_assert ((service) && (mq));
159 170
160 struct GNUNET_MESSENGER_SrvHandle *handle = create_srv_handle (service, mq); 171 struct GNUNET_MESSENGER_SrvHandle *handle = create_srv_handle (service, mq);
161 172
@@ -167,58 +178,62 @@ add_service_handle (struct GNUNET_MESSENGER_Service *service,
167 return handle; 178 return handle;
168} 179}
169 180
181
170void 182void
171remove_service_handle (struct GNUNET_MESSENGER_Service *service, 183remove_service_handle (struct GNUNET_MESSENGER_Service *service,
172 struct GNUNET_MESSENGER_SrvHandle *handle) 184 struct GNUNET_MESSENGER_SrvHandle *handle)
173{ 185{
174 GNUNET_assert((service) && (handle)); 186 GNUNET_assert ((service) && (handle));
175 187
176 if (!handle) 188 if (! handle)
177 return; 189 return;
178 190
179 if (GNUNET_YES == remove_list_handle (&(service->handles), handle)) 191 if (GNUNET_YES == remove_list_handle (&(service->handles), handle))
180 destroy_srv_handle (handle); 192 destroy_srv_handle (handle);
181} 193}
182 194
195
183int 196int
184get_service_peer_identity (struct GNUNET_MESSENGER_Service *service, 197get_service_peer_identity (struct GNUNET_MESSENGER_Service *service,
185 struct GNUNET_PeerIdentity *peer) 198 struct GNUNET_PeerIdentity *peer)
186{ 199{
187 GNUNET_assert((service) && (peer)); 200 GNUNET_assert ((service) && (peer));
188 201
189 if (service->peer) 202 if (service->peer)
190 { 203 {
191 GNUNET_memcpy(peer, service->peer, sizeof(struct GNUNET_PeerIdentity)); 204 GNUNET_memcpy (peer, service->peer, sizeof(struct GNUNET_PeerIdentity));
192 return GNUNET_OK; 205 return GNUNET_OK;
193 } 206 }
194 207
195 int result = GNUNET_CRYPTO_get_peer_identity(service->config, peer); 208 int result = GNUNET_CRYPTO_get_peer_identity (service->config, peer);
196 209
197 if (GNUNET_OK != result) 210 if (GNUNET_OK != result)
198 return result; 211 return result;
199 212
200 if (!service->peer) 213 if (! service->peer)
201 service->peer = GNUNET_new(struct GNUNET_PeerIdentity); 214 service->peer = GNUNET_new (struct GNUNET_PeerIdentity);
202 215
203 GNUNET_memcpy(service->peer, peer, sizeof(struct GNUNET_PeerIdentity)); 216 GNUNET_memcpy (service->peer, peer, sizeof(struct GNUNET_PeerIdentity));
204 return result; 217 return result;
205} 218}
206 219
220
207struct GNUNET_MESSENGER_SrvRoom* 221struct GNUNET_MESSENGER_SrvRoom*
208get_service_room (const struct GNUNET_MESSENGER_Service *service, 222get_service_room (const struct GNUNET_MESSENGER_Service *service,
209 const struct GNUNET_HashCode *key) 223 const struct GNUNET_HashCode *key)
210{ 224{
211 GNUNET_assert((service) && (key)); 225 GNUNET_assert ((service) && (key));
212 226
213 return GNUNET_CONTAINER_multihashmap_get (service->rooms, key); 227 return GNUNET_CONTAINER_multihashmap_get (service->rooms, key);
214} 228}
215 229
230
216int 231int
217open_service_room (struct GNUNET_MESSENGER_Service *service, 232open_service_room (struct GNUNET_MESSENGER_Service *service,
218 struct GNUNET_MESSENGER_SrvHandle *handle, 233 struct GNUNET_MESSENGER_SrvHandle *handle,
219 const struct GNUNET_HashCode *key) 234 const struct GNUNET_HashCode *key)
220{ 235{
221 GNUNET_assert((service) && (handle) && (key)); 236 GNUNET_assert ((service) && (handle) && (key));
222 237
223 struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); 238 struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
224 239
@@ -237,13 +252,14 @@ open_service_room (struct GNUNET_MESSENGER_Service *service,
237 return GNUNET_NO; 252 return GNUNET_NO;
238} 253}
239 254
255
240int 256int
241entry_service_room (struct GNUNET_MESSENGER_Service *service, 257entry_service_room (struct GNUNET_MESSENGER_Service *service,
242 struct GNUNET_MESSENGER_SrvHandle *handle, 258 struct GNUNET_MESSENGER_SrvHandle *handle,
243 const struct GNUNET_PeerIdentity *door, 259 const struct GNUNET_PeerIdentity *door,
244 const struct GNUNET_HashCode *key) 260 const struct GNUNET_HashCode *key)
245{ 261{
246 GNUNET_assert((service) && (handle) && (door) && (key)); 262 GNUNET_assert ((service) && (handle) && (door) && (key));
247 263
248 struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); 264 struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
249 265
@@ -272,31 +288,38 @@ entry_service_room (struct GNUNET_MESSENGER_Service *service,
272 288
273} 289}
274 290
291
275int 292int
276close_service_room (struct GNUNET_MESSENGER_Service *service, 293close_service_room (struct GNUNET_MESSENGER_Service *service,
277 struct GNUNET_MESSENGER_SrvHandle *handle, 294 struct GNUNET_MESSENGER_SrvHandle *handle,
278 const struct GNUNET_HashCode *key) 295 const struct GNUNET_HashCode *key)
279{ 296{
280 GNUNET_assert((service) && (handle) && (key)); 297 GNUNET_assert ((service) && (handle) && (key));
281 298
282 struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); 299 struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
283 300
284 if (!room) 301 if (! room)
285 return GNUNET_NO; 302 return GNUNET_NO;
286 303
287 const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, key); 304 const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle,
305 key);
288 306
289 GNUNET_assert(id); 307 GNUNET_assert (id);
290 308
291 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (handle->member_ids, key, id)) 309 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (handle->member_ids,
310 key, id))
292 return GNUNET_NO; 311 return GNUNET_NO;
293 312
294 struct GNUNET_MESSENGER_SrvHandle *member_handle = (struct GNUNET_MESSENGER_SrvHandle*) find_list_handle_by_member ( 313 struct GNUNET_MESSENGER_SrvHandle *member_handle = (struct
295 &(service->handles), key); 314 GNUNET_MESSENGER_SrvHandle
315 *)
316 find_list_handle_by_member (
317 &(service->handles), key);
296 318
297 if (!member_handle) 319 if (! member_handle)
298 { 320 {
299 if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key, room)) 321 if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key,
322 room))
300 { 323 {
301 destroy_srv_room (room, GNUNET_YES); 324 destroy_srv_room (room, GNUNET_YES);
302 return GNUNET_YES; 325 return GNUNET_YES;
@@ -311,6 +334,7 @@ close_service_room (struct GNUNET_MESSENGER_Service *service,
311 return GNUNET_YES; 334 return GNUNET_YES;
312} 335}
313 336
337
314void 338void
315handle_service_message (struct GNUNET_MESSENGER_Service *service, 339handle_service_message (struct GNUNET_MESSENGER_Service *service,
316 struct GNUNET_MESSENGER_SrvRoom *room, 340 struct GNUNET_MESSENGER_SrvRoom *room,
@@ -318,7 +342,7 @@ handle_service_message (struct GNUNET_MESSENGER_Service *service,
318 const struct GNUNET_MESSENGER_Message *message, 342 const struct GNUNET_MESSENGER_Message *message,
319 const struct GNUNET_HashCode *hash) 343 const struct GNUNET_HashCode *hash)
320{ 344{
321 GNUNET_assert((service) && (room) && (session) && (message) && (hash)); 345 GNUNET_assert ((service) && (room) && (session) && (message) && (hash));
322 346
323 struct GNUNET_MESSENGER_ListHandle *element = service->handles.head; 347 struct GNUNET_MESSENGER_ListHandle *element = service->handles.head;
324 348