diff options
Diffstat (limited to 'src/messenger/gnunet-service-messenger_handle.c')
-rw-r--r-- | src/messenger/gnunet-service-messenger_handle.c | 276 |
1 files changed, 168 insertions, 108 deletions
diff --git a/src/messenger/gnunet-service-messenger_handle.c b/src/messenger/gnunet-service-messenger_handle.c index ddb437b7e..8d572013e 100644 --- a/src/messenger/gnunet-service-messenger_handle.c +++ b/src/messenger/gnunet-service-messenger_handle.c | |||
@@ -40,9 +40,10 @@ struct GNUNET_MESSENGER_SrvHandle* | |||
40 | create_srv_handle (struct GNUNET_MESSENGER_Service *service, | 40 | create_srv_handle (struct GNUNET_MESSENGER_Service *service, |
41 | struct GNUNET_MQ_Handle *mq) | 41 | struct GNUNET_MQ_Handle *mq) |
42 | { | 42 | { |
43 | GNUNET_assert((service) && (mq)); | 43 | GNUNET_assert ((service) && (mq)); |
44 | 44 | ||
45 | struct GNUNET_MESSENGER_SrvHandle *handle = GNUNET_new(struct GNUNET_MESSENGER_SrvHandle); | 45 | struct GNUNET_MESSENGER_SrvHandle *handle = GNUNET_new (struct |
46 | GNUNET_MESSENGER_SrvHandle); | ||
46 | 47 | ||
47 | handle->service = service; | 48 | handle->service = service; |
48 | handle->mq = mq; | 49 | handle->mq = mq; |
@@ -55,65 +56,72 @@ create_srv_handle (struct GNUNET_MESSENGER_Service *service, | |||
55 | return handle; | 56 | return handle; |
56 | } | 57 | } |
57 | 58 | ||
59 | |||
58 | int | 60 | int |
59 | iterate_free_member_ids (void *cls, | 61 | iterate_free_member_ids (void *cls, |
60 | const struct GNUNET_HashCode *key, | 62 | const struct GNUNET_HashCode *key, |
61 | void *value) | 63 | void *value) |
62 | { | 64 | { |
63 | GNUNET_free(value); | 65 | GNUNET_free (value); |
64 | 66 | ||
65 | return GNUNET_YES; | 67 | return GNUNET_YES; |
66 | } | 68 | } |
67 | 69 | ||
70 | |||
68 | void | 71 | void |
69 | destroy_srv_handle (struct GNUNET_MESSENGER_SrvHandle *handle) | 72 | destroy_srv_handle (struct GNUNET_MESSENGER_SrvHandle *handle) |
70 | { | 73 | { |
71 | GNUNET_assert(handle); | 74 | GNUNET_assert (handle); |
72 | 75 | ||
73 | if (handle->notify) | 76 | if (handle->notify) |
74 | GNUNET_SCHEDULER_cancel(handle->notify); | 77 | GNUNET_SCHEDULER_cancel (handle->notify); |
75 | 78 | ||
76 | GNUNET_CONTAINER_multihashmap_iterate (handle->next_ids, iterate_free_member_ids, NULL); | 79 | GNUNET_CONTAINER_multihashmap_iterate (handle->next_ids, |
77 | GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_free_member_ids, NULL); | 80 | iterate_free_member_ids, NULL); |
81 | GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, | ||
82 | iterate_free_member_ids, NULL); | ||
78 | 83 | ||
79 | GNUNET_CONTAINER_multihashmap_destroy (handle->next_ids); | 84 | GNUNET_CONTAINER_multihashmap_destroy (handle->next_ids); |
80 | GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids); | 85 | GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids); |
81 | 86 | ||
82 | GNUNET_free(handle); | 87 | GNUNET_free (handle); |
83 | } | 88 | } |
84 | 89 | ||
90 | |||
85 | void | 91 | void |
86 | set_srv_handle_key (struct GNUNET_MESSENGER_SrvHandle *handle, | 92 | set_srv_handle_key (struct GNUNET_MESSENGER_SrvHandle *handle, |
87 | const struct GNUNET_IDENTITY_PublicKey *key) | 93 | const struct GNUNET_IDENTITY_PublicKey *key) |
88 | { | 94 | { |
89 | GNUNET_assert(handle); | 95 | GNUNET_assert (handle); |
90 | 96 | ||
91 | if ((handle->key) && (!key)) | 97 | if ((handle->key) && (! key)) |
92 | { | 98 | { |
93 | GNUNET_free(handle->key); | 99 | GNUNET_free (handle->key); |
94 | handle->key = NULL; | 100 | handle->key = NULL; |
95 | } | 101 | } |
96 | else if (!handle->key) | 102 | else if (! handle->key) |
97 | handle->key = GNUNET_new(struct GNUNET_IDENTITY_PublicKey); | 103 | handle->key = GNUNET_new (struct GNUNET_IDENTITY_PublicKey); |
98 | 104 | ||
99 | if (key) | 105 | if (key) |
100 | memcpy(handle->key, key, sizeof(struct GNUNET_IDENTITY_PublicKey)); | 106 | memcpy (handle->key, key, sizeof(struct GNUNET_IDENTITY_PublicKey)); |
101 | } | 107 | } |
102 | 108 | ||
109 | |||
103 | const struct GNUNET_IDENTITY_PublicKey* | 110 | const struct GNUNET_IDENTITY_PublicKey* |
104 | get_srv_handle_key (const struct GNUNET_MESSENGER_SrvHandle *handle) | 111 | get_srv_handle_key (const struct GNUNET_MESSENGER_SrvHandle *handle) |
105 | { | 112 | { |
106 | GNUNET_assert(handle); | 113 | GNUNET_assert (handle); |
107 | 114 | ||
108 | return handle->key; | 115 | return handle->key; |
109 | } | 116 | } |
110 | 117 | ||
118 | |||
111 | void | 119 | void |
112 | get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, | 120 | get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, |
113 | const char *name, | 121 | const char *name, |
114 | char **dir) | 122 | char **dir) |
115 | { | 123 | { |
116 | GNUNET_assert((handle) && (dir)); | 124 | GNUNET_assert ((handle) && (dir)); |
117 | 125 | ||
118 | if (name) | 126 | if (name) |
119 | GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities", | 127 | GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities", |
@@ -123,75 +131,88 @@ get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, | |||
123 | DIR_SEPARATOR); | 131 | DIR_SEPARATOR); |
124 | } | 132 | } |
125 | 133 | ||
134 | |||
126 | static int | 135 | static int |
127 | create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, | 136 | create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, |
128 | const struct GNUNET_HashCode *key) | 137 | const struct GNUNET_HashCode *key) |
129 | { | 138 | { |
130 | GNUNET_assert((handle) && (key)); | 139 | GNUNET_assert ((handle) && (key)); |
131 | 140 | ||
132 | struct GNUNET_ShortHashCode *random_id = GNUNET_new(struct GNUNET_ShortHashCode); | 141 | struct GNUNET_ShortHashCode *random_id = GNUNET_new (struct |
142 | GNUNET_ShortHashCode); | ||
133 | 143 | ||
134 | if (!random_id) | 144 | if (! random_id) |
135 | return GNUNET_NO; | 145 | return GNUNET_NO; |
136 | 146 | ||
137 | generate_free_member_id (random_id, NULL); | 147 | generate_free_member_id (random_id, NULL); |
138 | 148 | ||
139 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, random_id, | 149 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, |
150 | random_id, | ||
140 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
141 | { | 152 | { |
142 | GNUNET_free(random_id); | 153 | GNUNET_free (random_id); |
143 | return GNUNET_NO; | 154 | return GNUNET_NO; |
144 | } | 155 | } |
145 | 156 | ||
146 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Created a new member id (%s) for room: %s\n", GNUNET_sh2s (random_id), | 157 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
147 | GNUNET_h2s (key)); | 158 | "Created a new member id (%s) for room: %s\n", GNUNET_sh2s ( |
159 | random_id), | ||
160 | GNUNET_h2s (key)); | ||
148 | 161 | ||
149 | return GNUNET_YES; | 162 | return GNUNET_YES; |
150 | } | 163 | } |
151 | 164 | ||
165 | |||
152 | const struct GNUNET_ShortHashCode* | 166 | const struct GNUNET_ShortHashCode* |
153 | get_srv_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, | 167 | get_srv_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, |
154 | const struct GNUNET_HashCode *key) | 168 | const struct GNUNET_HashCode *key) |
155 | { | 169 | { |
156 | GNUNET_assert((handle) && (key)); | 170 | GNUNET_assert ((handle) && (key)); |
157 | 171 | ||
158 | return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key); | 172 | return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key); |
159 | } | 173 | } |
160 | 174 | ||
175 | |||
161 | int | 176 | int |
162 | change_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | 177 | change_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, |
163 | const struct GNUNET_HashCode *key, | 178 | const struct GNUNET_HashCode *key, |
164 | const struct GNUNET_ShortHashCode *unique_id) | 179 | const struct GNUNET_ShortHashCode *unique_id) |
165 | { | 180 | { |
166 | GNUNET_assert((handle) && (key) && (unique_id)); | 181 | GNUNET_assert ((handle) && (key) && (unique_id)); |
167 | 182 | ||
168 | struct GNUNET_ShortHashCode *member_id = GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key); | 183 | struct GNUNET_ShortHashCode *member_id = GNUNET_CONTAINER_multihashmap_get ( |
184 | handle->member_ids, key); | ||
169 | 185 | ||
170 | if (!member_id) | 186 | if (! member_id) |
171 | { | 187 | { |
172 | member_id = GNUNET_new(struct GNUNET_ShortHashCode); | 188 | member_id = GNUNET_new (struct GNUNET_ShortHashCode); |
173 | GNUNET_memcpy(member_id, unique_id, sizeof(*member_id)); | 189 | GNUNET_memcpy (member_id, unique_id, sizeof(*member_id)); |
174 | 190 | ||
175 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, member_id, | 191 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, |
192 | member_id, | ||
176 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 193 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
177 | { | 194 | { |
178 | GNUNET_free(member_id); | 195 | GNUNET_free (member_id); |
179 | return GNUNET_SYSERR; | 196 | return GNUNET_SYSERR; |
180 | } | 197 | } |
181 | } | 198 | } |
182 | 199 | ||
183 | if (0 == GNUNET_memcmp(unique_id, member_id)) | 200 | if (0 == GNUNET_memcmp (unique_id, member_id)) |
184 | return GNUNET_OK; | 201 | return GNUNET_OK; |
185 | 202 | ||
186 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Change a member id (%s) for room (%s).\n", GNUNET_sh2s (member_id), | 203 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
187 | GNUNET_h2s (key)); | 204 | "Change a member id (%s) for room (%s).\n", GNUNET_sh2s ( |
205 | member_id), | ||
206 | GNUNET_h2s (key)); | ||
188 | 207 | ||
189 | GNUNET_memcpy(member_id, unique_id, sizeof(*unique_id)); | 208 | GNUNET_memcpy (member_id, unique_id, sizeof(*unique_id)); |
190 | 209 | ||
191 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member id changed to (%s).\n", GNUNET_sh2s (unique_id)); | 210 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Member id changed to (%s).\n", |
211 | GNUNET_sh2s (unique_id)); | ||
192 | return GNUNET_OK; | 212 | return GNUNET_OK; |
193 | } | 213 | } |
194 | 214 | ||
215 | |||
195 | struct RoomInitializationClosure | 216 | struct RoomInitializationClosure |
196 | { | 217 | { |
197 | struct GNUNET_MESSENGER_SrvHandle *handle; | 218 | struct GNUNET_MESSENGER_SrvHandle *handle; |
@@ -206,160 +227,185 @@ find_member_session_in_room (void *cls, | |||
206 | { | 227 | { |
207 | struct RoomInitializationClosure *init = cls; | 228 | struct RoomInitializationClosure *init = cls; |
208 | 229 | ||
209 | if (!public_key) | 230 | if (! public_key) |
210 | return GNUNET_YES; | 231 | return GNUNET_YES; |
211 | 232 | ||
212 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key(init->handle); | 233 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key ( |
234 | init->handle); | ||
213 | 235 | ||
214 | if (0 != GNUNET_memcmp(pubkey, public_key)) | 236 | if (0 != GNUNET_memcmp (pubkey, public_key)) |
215 | return GNUNET_YES; | 237 | return GNUNET_YES; |
216 | 238 | ||
217 | const struct GNUNET_ShortHashCode *id = get_member_session_id(session); | 239 | const struct GNUNET_ShortHashCode *id = get_member_session_id (session); |
218 | 240 | ||
219 | if (!id) | 241 | if (! id) |
220 | { | 242 | { |
221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialitation: Missing member id!"); | 243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialitation: Missing member id!"); |
222 | return GNUNET_NO; | 244 | return GNUNET_NO; |
223 | } | 245 | } |
224 | 246 | ||
225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Initialitation: Matching member found (%s)!\n", | 247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
226 | GNUNET_sh2s(id)); | 248 | "Initialitation: Matching member found (%s)!\n", |
249 | GNUNET_sh2s (id)); | ||
227 | 250 | ||
228 | change_srv_handle_member_id(init->handle, init->key, id); | 251 | change_srv_handle_member_id (init->handle, init->key, id); |
229 | return GNUNET_NO; | 252 | return GNUNET_NO; |
230 | } | 253 | } |
231 | 254 | ||
255 | |||
232 | static void | 256 | static void |
233 | initialize_srv_handle_via_matching_member (struct GNUNET_MESSENGER_SrvHandle *handle, | 257 | initialize_srv_handle_via_matching_member (struct |
258 | GNUNET_MESSENGER_SrvHandle *handle, | ||
234 | const struct GNUNET_HashCode *key) | 259 | const struct GNUNET_HashCode *key) |
235 | { | 260 | { |
236 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room(handle->service, key); | 261 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, |
237 | if (!room) | 262 | key); |
263 | if (! room) | ||
238 | return; | 264 | return; |
239 | 265 | ||
240 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store(room); | 266 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store (room); |
241 | if (!store) | 267 | if (! store) |
242 | return; | 268 | return; |
243 | 269 | ||
244 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key(handle); | 270 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key (handle); |
245 | if ((!pubkey) || (0 == GNUNET_memcmp (pubkey, get_anonymous_public_key()))) | 271 | if ((! pubkey) || (0 == GNUNET_memcmp (pubkey, get_anonymous_public_key ()))) |
246 | return; | 272 | return; |
247 | 273 | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialize member id of handle via matching member in room!\n"); | 274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
275 | "Initialize member id of handle via matching member in room!\n"); | ||
249 | 276 | ||
250 | struct RoomInitializationClosure init; | 277 | struct RoomInitializationClosure init; |
251 | init.handle = handle; | 278 | init.handle = handle; |
252 | init.key = key; | 279 | init.key = key; |
253 | init.pubkey = pubkey; | 280 | init.pubkey = pubkey; |
254 | 281 | ||
255 | iterate_store_members(store, find_member_session_in_room, &init); | 282 | iterate_store_members (store, find_member_session_in_room, &init); |
256 | } | 283 | } |
257 | 284 | ||
285 | |||
258 | int | 286 | int |
259 | open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 287 | open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
260 | const struct GNUNET_HashCode *key) | 288 | const struct GNUNET_HashCode *key) |
261 | { | 289 | { |
262 | GNUNET_assert((handle) && (key)); | 290 | GNUNET_assert ((handle) && (key)); |
263 | 291 | ||
264 | initialize_srv_handle_via_matching_member (handle, key); | 292 | initialize_srv_handle_via_matching_member (handle, key); |
265 | 293 | ||
266 | if ((!get_srv_handle_member_id (handle, key)) && (GNUNET_YES != create_handle_member_id (handle, key))) | 294 | if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES != |
295 | create_handle_member_id ( | ||
296 | handle, key))) | ||
267 | return GNUNET_NO; | 297 | return GNUNET_NO; |
268 | 298 | ||
269 | return open_service_room (handle->service, handle, key); | 299 | return open_service_room (handle->service, handle, key); |
270 | } | 300 | } |
271 | 301 | ||
302 | |||
272 | int | 303 | int |
273 | entry_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 304 | entry_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
274 | const struct GNUNET_PeerIdentity *door, | 305 | const struct GNUNET_PeerIdentity *door, |
275 | const struct GNUNET_HashCode *key) | 306 | const struct GNUNET_HashCode *key) |
276 | { | 307 | { |
277 | GNUNET_assert((handle) && (door) && (key)); | 308 | GNUNET_assert ((handle) && (door) && (key)); |
278 | 309 | ||
279 | initialize_srv_handle_via_matching_member (handle, key); | 310 | initialize_srv_handle_via_matching_member (handle, key); |
280 | 311 | ||
281 | if ((!get_srv_handle_member_id (handle, key)) && (GNUNET_YES != create_handle_member_id (handle, key))) | 312 | if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES != |
313 | create_handle_member_id ( | ||
314 | handle, key))) | ||
282 | return GNUNET_NO; | 315 | return GNUNET_NO; |
283 | 316 | ||
284 | return entry_service_room (handle->service, handle, door, key); | 317 | return entry_service_room (handle->service, handle, door, key); |
285 | } | 318 | } |
286 | 319 | ||
320 | |||
287 | int | 321 | int |
288 | close_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 322 | close_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
289 | const struct GNUNET_HashCode *key) | 323 | const struct GNUNET_HashCode *key) |
290 | { | 324 | { |
291 | GNUNET_assert((handle) && (key)); | 325 | GNUNET_assert ((handle) && (key)); |
292 | 326 | ||
293 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->next_ids, key, iterate_free_member_ids, NULL); | 327 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->next_ids, key, |
328 | iterate_free_member_ids, NULL); | ||
294 | GNUNET_CONTAINER_multihashmap_remove_all (handle->next_ids, key); | 329 | GNUNET_CONTAINER_multihashmap_remove_all (handle->next_ids, key); |
295 | 330 | ||
296 | if ((handle->notify) && (0 == GNUNET_CONTAINER_multihashmap_size (handle->next_ids))) | 331 | if ((handle->notify) && (0 == GNUNET_CONTAINER_multihashmap_size ( |
332 | handle->next_ids))) | ||
297 | { | 333 | { |
298 | GNUNET_SCHEDULER_cancel(handle->notify); | 334 | GNUNET_SCHEDULER_cancel (handle->notify); |
299 | handle->notify = NULL; | 335 | handle->notify = NULL; |
300 | } | 336 | } |
301 | 337 | ||
302 | if (!get_srv_handle_member_id (handle, key)) | 338 | if (! get_srv_handle_member_id (handle, key)) |
303 | return GNUNET_NO; | 339 | return GNUNET_NO; |
304 | 340 | ||
305 | return close_service_room (handle->service, handle, key); | 341 | return close_service_room (handle->service, handle, key); |
306 | } | 342 | } |
307 | 343 | ||
344 | |||
308 | int | 345 | int |
309 | send_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | 346 | send_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, |
310 | const struct GNUNET_HashCode *key, | 347 | const struct GNUNET_HashCode *key, |
311 | const struct GNUNET_MESSENGER_Message *message) | 348 | const struct GNUNET_MESSENGER_Message *message) |
312 | { | 349 | { |
313 | GNUNET_assert((handle) && (key) && (message)); | 350 | GNUNET_assert ((handle) && (key) && (message)); |
314 | 351 | ||
315 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, key); | 352 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, |
353 | key); | ||
316 | 354 | ||
317 | if (!id) | 355 | if (! id) |
318 | { | 356 | { |
319 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "It is required to be a member of a room to send messages!\n"); | 357 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
358 | "It is required to be a member of a room to send messages!\n"); | ||
320 | return GNUNET_NO; | 359 | return GNUNET_NO; |
321 | } | 360 | } |
322 | 361 | ||
323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message with member id: %s\n", | 362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message with member id: %s\n", |
324 | GNUNET_sh2s (id)); | 363 | GNUNET_sh2s (id)); |
325 | 364 | ||
326 | if (0 != GNUNET_memcmp(id, &(message->header.sender_id))) | 365 | if (0 != GNUNET_memcmp (id, &(message->header.sender_id))) |
327 | { | 366 | { |
328 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Member id does not match with handle!\n"); | 367 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
368 | "Member id does not match with handle!\n"); | ||
329 | return GNUNET_NO; | 369 | return GNUNET_NO; |
330 | } | 370 | } |
331 | 371 | ||
332 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, key); | 372 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, |
373 | key); | ||
333 | 374 | ||
334 | if (!room) | 375 | if (! room) |
335 | { | 376 | { |
336 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n", GNUNET_h2s (key)); | 377 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n", |
378 | GNUNET_h2s (key)); | ||
337 | return GNUNET_NO; | 379 | return GNUNET_NO; |
338 | } | 380 | } |
339 | 381 | ||
340 | struct GNUNET_MESSENGER_Message *msg = copy_message(message); | 382 | struct GNUNET_MESSENGER_Message *msg = copy_message (message); |
341 | return send_srv_room_message (room, handle, msg); | 383 | return send_srv_room_message (room, handle, msg); |
342 | } | 384 | } |
343 | 385 | ||
386 | |||
344 | static const struct GNUNET_HashCode* | 387 | static const struct GNUNET_HashCode* |
345 | get_next_member_session_context(const struct GNUNET_MESSENGER_MemberSession *session) | 388 | get_next_member_session_context (const struct |
389 | GNUNET_MESSENGER_MemberSession *session) | ||
346 | { | 390 | { |
347 | if (session->next) | 391 | if (session->next) |
348 | return get_next_member_session_context (session->next); | 392 | return get_next_member_session_context (session->next); |
349 | else | 393 | else |
350 | return get_member_session_context(session); | 394 | return get_member_session_context (session); |
351 | } | 395 | } |
352 | 396 | ||
397 | |||
353 | static const struct GNUNET_MESSENGER_MemberSession* | 398 | static const struct GNUNET_MESSENGER_MemberSession* |
354 | get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, | 399 | get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, |
355 | struct GNUNET_MESSENGER_SrvRoom *room, | 400 | struct GNUNET_MESSENGER_SrvRoom *room, |
356 | const struct GNUNET_HashCode *key) | 401 | const struct GNUNET_HashCode *key) |
357 | { | 402 | { |
358 | GNUNET_assert((handle) && (room) && (key) && (handle->service)); | 403 | GNUNET_assert ((handle) && (room) && (key) && (handle->service)); |
359 | 404 | ||
360 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id(handle, key); | 405 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, |
406 | key); | ||
361 | 407 | ||
362 | if (!id) | 408 | if (! id) |
363 | { | 409 | { |
364 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 410 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
365 | "Handle is missing a member id for its member session! (%s)\n", | 411 | "Handle is missing a member id for its member session! (%s)\n", |
@@ -367,12 +413,12 @@ get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
367 | return NULL; | 413 | return NULL; |
368 | } | 414 | } |
369 | 415 | ||
370 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store(room); | 416 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store (room); |
371 | struct GNUNET_MESSENGER_Member *member = get_store_member(store, id); | 417 | struct GNUNET_MESSENGER_Member *member = get_store_member (store, id); |
372 | 418 | ||
373 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key(handle); | 419 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key (handle); |
374 | 420 | ||
375 | if (!pubkey) | 421 | if (! pubkey) |
376 | { | 422 | { |
377 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 423 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
378 | "Handle is missing a public key for its member session! (%s)\n", | 424 | "Handle is missing a public key for its member session! (%s)\n", |
@@ -380,9 +426,10 @@ get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
380 | return NULL; | 426 | return NULL; |
381 | } | 427 | } |
382 | 428 | ||
383 | return get_member_session(member, pubkey); | 429 | return get_member_session (member, pubkey); |
384 | } | 430 | } |
385 | 431 | ||
432 | |||
386 | void | 433 | void |
387 | notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | 434 | notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, |
388 | struct GNUNET_MESSENGER_SrvRoom *room, | 435 | struct GNUNET_MESSENGER_SrvRoom *room, |
@@ -390,13 +437,14 @@ notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
390 | const struct GNUNET_MESSENGER_Message *message, | 437 | const struct GNUNET_MESSENGER_Message *message, |
391 | const struct GNUNET_HashCode *hash) | 438 | const struct GNUNET_HashCode *hash) |
392 | { | 439 | { |
393 | GNUNET_assert((handle) && (room) && (session) && (message) && (hash)); | 440 | GNUNET_assert ((handle) && (room) && (session) && (message) && (hash)); |
394 | 441 | ||
395 | const struct GNUNET_HashCode *key = get_srv_room_key(room); | 442 | const struct GNUNET_HashCode *key = get_srv_room_key (room); |
396 | 443 | ||
397 | if ((!handle->mq) || (!get_srv_handle_member_id (handle, key))) | 444 | if ((! handle->mq) || (! get_srv_handle_member_id (handle, key))) |
398 | { | 445 | { |
399 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Notifying client about message requires membership!\n"); | 446 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
447 | "Notifying client about message requires membership!\n"); | ||
400 | return; | 448 | return; |
401 | } | 449 | } |
402 | 450 | ||
@@ -406,37 +454,40 @@ notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
406 | if (GNUNET_YES == is_peer_message (message)) | 454 | if (GNUNET_YES == is_peer_message (message)) |
407 | { | 455 | { |
408 | const struct GNUNET_PeerIdentity *identity = session->peer; | 456 | const struct GNUNET_PeerIdentity *identity = session->peer; |
409 | GNUNET_CRYPTO_hash(identity, sizeof(*identity), &sender); | 457 | GNUNET_CRYPTO_hash (identity, sizeof(*identity), &sender); |
410 | 458 | ||
411 | context = &sender; | 459 | context = &sender; |
412 | } | 460 | } |
413 | else | 461 | else |
414 | { | 462 | { |
415 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_contact_key(session->member->contact); | 463 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_contact_key ( |
416 | GNUNET_CRYPTO_hash(pubkey, sizeof(*pubkey), &sender); | 464 | session->member->contact); |
465 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &sender); | ||
417 | 466 | ||
418 | context = get_next_member_session_context (session->member); | 467 | context = get_next_member_session_context (session->member); |
419 | } | 468 | } |
420 | 469 | ||
421 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Notifying client about message: %s\n", GNUNET_h2s (hash)); | 470 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Notifying client about message: %s\n", |
471 | GNUNET_h2s (hash)); | ||
422 | 472 | ||
423 | struct GNUNET_MESSENGER_RecvMessage *msg; | 473 | struct GNUNET_MESSENGER_RecvMessage *msg; |
424 | struct GNUNET_MQ_Envelope *env; | 474 | struct GNUNET_MQ_Envelope *env; |
425 | 475 | ||
426 | uint16_t length = get_message_size (message, GNUNET_YES); | 476 | uint16_t length = get_message_size (message, GNUNET_YES); |
427 | 477 | ||
428 | env = GNUNET_MQ_msg_extra(msg, length, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE); | 478 | env = GNUNET_MQ_msg_extra (msg, length, |
479 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE); | ||
429 | 480 | ||
430 | GNUNET_memcpy(&(msg->key), key, sizeof(msg->key)); | 481 | GNUNET_memcpy (&(msg->key), key, sizeof(msg->key)); |
431 | GNUNET_memcpy(&(msg->sender), &sender, sizeof(msg->sender)); | 482 | GNUNET_memcpy (&(msg->sender), &sender, sizeof(msg->sender)); |
432 | GNUNET_memcpy(&(msg->context), context, sizeof(msg->context)); | 483 | GNUNET_memcpy (&(msg->context), context, sizeof(msg->context)); |
433 | GNUNET_memcpy(&(msg->hash), hash, sizeof(msg->hash)); | 484 | GNUNET_memcpy (&(msg->hash), hash, sizeof(msg->hash)); |
434 | 485 | ||
435 | msg->flags = (uint32_t) GNUNET_MESSENGER_FLAG_NONE; | 486 | msg->flags = (uint32_t) GNUNET_MESSENGER_FLAG_NONE; |
436 | 487 | ||
437 | if (GNUNET_YES == is_peer_message (message)) | 488 | if (GNUNET_YES == is_peer_message (message)) |
438 | msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_PEER; | 489 | msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_PEER; |
439 | else if (get_handle_member_session(handle, room, key) == session->member) | 490 | else if (get_handle_member_session (handle, room, key) == session->member) |
440 | msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_SENT; | 491 | msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_SENT; |
441 | 492 | ||
442 | char *buffer = ((char*) msg) + sizeof(*msg); | 493 | char *buffer = ((char*) msg) + sizeof(*msg); |
@@ -445,6 +496,7 @@ notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
445 | GNUNET_MQ_send (handle->mq, env); | 496 | GNUNET_MQ_send (handle->mq, env); |
446 | } | 497 | } |
447 | 498 | ||
499 | |||
448 | static int | 500 | static int |
449 | iterate_next_member_ids (void *cls, | 501 | iterate_next_member_ids (void *cls, |
450 | const struct GNUNET_HashCode *key, | 502 | const struct GNUNET_HashCode *key, |
@@ -456,10 +508,10 @@ iterate_next_member_ids (void *cls, | |||
456 | struct GNUNET_MESSENGER_MemberMessage *msg; | 508 | struct GNUNET_MESSENGER_MemberMessage *msg; |
457 | struct GNUNET_MQ_Envelope *env; | 509 | struct GNUNET_MQ_Envelope *env; |
458 | 510 | ||
459 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID); | 511 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID); |
460 | 512 | ||
461 | GNUNET_memcpy(&(msg->key), key, sizeof(*key)); | 513 | GNUNET_memcpy (&(msg->key), key, sizeof(*key)); |
462 | GNUNET_memcpy(&(msg->id), &(next->id), sizeof(next->id)); | 514 | GNUNET_memcpy (&(msg->id), &(next->id), sizeof(next->id)); |
463 | msg->reset = (uint32_t) next->reset; | 515 | msg->reset = (uint32_t) next->reset; |
464 | 516 | ||
465 | GNUNET_MQ_send (handle->mq, env); | 517 | GNUNET_MQ_send (handle->mq, env); |
@@ -468,26 +520,30 @@ iterate_next_member_ids (void *cls, | |||
468 | return GNUNET_YES; | 520 | return GNUNET_YES; |
469 | } | 521 | } |
470 | 522 | ||
523 | |||
471 | static void | 524 | static void |
472 | task_notify_srv_handle_member_id (void *cls) | 525 | task_notify_srv_handle_member_id (void *cls) |
473 | { | 526 | { |
474 | struct GNUNET_MESSENGER_SrvHandle *handle = cls; | 527 | struct GNUNET_MESSENGER_SrvHandle *handle = cls; |
475 | handle->notify = NULL; | 528 | handle->notify = NULL; |
476 | 529 | ||
477 | GNUNET_CONTAINER_multihashmap_iterate (handle->next_ids, iterate_next_member_ids, handle); | 530 | GNUNET_CONTAINER_multihashmap_iterate (handle->next_ids, |
531 | iterate_next_member_ids, handle); | ||
478 | GNUNET_CONTAINER_multihashmap_clear (handle->next_ids); | 532 | GNUNET_CONTAINER_multihashmap_clear (handle->next_ids); |
479 | } | 533 | } |
480 | 534 | ||
535 | |||
481 | void | 536 | void |
482 | notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | 537 | notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, |
483 | struct GNUNET_MESSENGER_SrvRoom *room, | 538 | struct GNUNET_MESSENGER_SrvRoom *room, |
484 | const struct GNUNET_ShortHashCode *member_id, | 539 | const struct GNUNET_ShortHashCode *member_id, |
485 | enum GNUNET_GenericReturnValue reset) | 540 | enum GNUNET_GenericReturnValue reset) |
486 | { | 541 | { |
487 | GNUNET_assert((handle) && (room) && (member_id)); | 542 | GNUNET_assert ((handle) && (room) && (member_id)); |
488 | 543 | ||
489 | struct GNUNET_MESSENGER_NextMemberId *next = GNUNET_new (struct GNUNET_MESSENGER_NextMemberId); | 544 | struct GNUNET_MESSENGER_NextMemberId *next = GNUNET_new (struct |
490 | if (!next) | 545 | GNUNET_MESSENGER_NextMemberId); |
546 | if (! next) | ||
491 | { | 547 | { |
492 | return; | 548 | return; |
493 | } | 549 | } |
@@ -495,10 +551,13 @@ notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
495 | GNUNET_memcpy (&(next->id), member_id, sizeof(next->id)); | 551 | GNUNET_memcpy (&(next->id), member_id, sizeof(next->id)); |
496 | next->reset = reset; | 552 | next->reset = reset; |
497 | 553 | ||
498 | const struct GNUNET_HashCode *key = get_srv_room_key(room); | 554 | const struct GNUNET_HashCode *key = get_srv_room_key (room); |
499 | 555 | ||
500 | struct GNUNET_MESSENGER_NextMemberId *prev = GNUNET_CONTAINER_multihashmap_get(handle->next_ids, key); | 556 | struct GNUNET_MESSENGER_NextMemberId *prev = |
501 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_put(handle->next_ids, key, next, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)) | 557 | GNUNET_CONTAINER_multihashmap_get (handle->next_ids, key); |
558 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_put (handle->next_ids, key, | ||
559 | next, | ||
560 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)) | ||
502 | { | 561 | { |
503 | return; | 562 | return; |
504 | } | 563 | } |
@@ -506,6 +565,7 @@ notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
506 | if (prev) | 565 | if (prev) |
507 | GNUNET_free (prev); | 566 | GNUNET_free (prev); |
508 | 567 | ||
509 | if (!handle->notify) | 568 | if (! handle->notify) |
510 | handle->notify = GNUNET_SCHEDULER_add_now (task_notify_srv_handle_member_id, handle); | 569 | handle->notify = GNUNET_SCHEDULER_add_now (task_notify_srv_handle_member_id, |
570 | handle); | ||
511 | } | 571 | } |