aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-05-04 22:16:24 +0200
committerChristian Grothoff <christian@grothoff.org>2019-05-04 22:16:24 +0200
commit80f480c752fd8dfa1be51d78fce314d9f0650b50 (patch)
tree459c21a3fde3b5f66194ac9960632de53586c5f0 /src/core
parent3d2a951fa12546c09809f0a4d7e789ef8e971b03 (diff)
downloadgnunet-80f480c752fd8dfa1be51d78fce314d9f0650b50.tar.gz
gnunet-80f480c752fd8dfa1be51d78fce314d9f0650b50.zip
simplify MQ logic to always carry the same kinds of flags, and extend transport API to pass them to (TNG) service
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.h33
-rw-r--r--src/core/core_api.c266
-rw-r--r--src/core/gnunet-service-core.c527
-rw-r--r--src/core/gnunet-service-core.h21
-rw-r--r--src/core/gnunet-service-core_sessions.c285
-rw-r--r--src/core/gnunet-service-core_sessions.h7
-rw-r--r--src/core/test_core_api.c207
7 files changed, 542 insertions, 804 deletions
diff --git a/src/core/core.h b/src/core/core.h
index bc9638706..95d506fbd 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -42,23 +42,23 @@
42 * for handlers that were specifically registered are always 42 * for handlers that were specifically registered are always
43 * transmitted to the client. 43 * transmitted to the client.
44 */ 44 */
45#define GNUNET_CORE_OPTION_NOTHING 0 45#define GNUNET_CORE_OPTION_NOTHING 0
46 46
47/** 47/**
48 * Client cares about connectivity changes. 48 * Client cares about connectivity changes.
49 */ 49 */
50#define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE 4 50#define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE 4
51 51
52/** 52/**
53 * Client wants all inbound messages in full. 53 * Client wants all inbound messages in full.
54 */ 54 */
55#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND 8 55#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND 8
56 56
57/** 57/**
58 * Client just wants the 4-byte message headers of 58 * Client just wants the 4-byte message headers of
59 * all inbound messages. 59 * all inbound messages.
60 */ 60 */
61#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND 16 61#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND 16
62 62
63/** 63/**
64 * Client wants all outbound messages in full. 64 * Client wants all outbound messages in full.
@@ -69,7 +69,7 @@
69 * Client just wants the 4-byte message headers of 69 * Client just wants the 4-byte message headers of
70 * all outbound messages. 70 * all outbound messages.
71 */ 71 */
72#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND 64 72#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND 64
73 73
74 74
75GNUNET_NETWORK_STRUCT_BEGIN 75GNUNET_NETWORK_STRUCT_BEGIN
@@ -92,7 +92,6 @@ struct InitMessage
92 * Options, see GNUNET_CORE_OPTION_ values. 92 * Options, see GNUNET_CORE_OPTION_ values.
93 */ 93 */
94 uint32_t options GNUNET_PACKED; 94 uint32_t options GNUNET_PACKED;
95
96}; 95};
97 96
98 97
@@ -117,7 +116,6 @@ struct InitReplyMessage
117 * Public key of the local peer. 116 * Public key of the local peer.
118 */ 117 */
119 struct GNUNET_PeerIdentity my_identity; 118 struct GNUNET_PeerIdentity my_identity;
120
121}; 119};
122 120
123 121
@@ -141,7 +139,6 @@ struct ConnectNotifyMessage
141 * Identity of the connecting peer. 139 * Identity of the connecting peer.
142 */ 140 */
143 struct GNUNET_PeerIdentity peer; 141 struct GNUNET_PeerIdentity peer;
144
145}; 142};
146 143
147 144
@@ -165,7 +162,6 @@ struct DisconnectNotifyMessage
165 * Identity of the connecting peer. 162 * Identity of the connecting peer.
166 */ 163 */
167 struct GNUNET_PeerIdentity peer; 164 struct GNUNET_PeerIdentity peer;
168
169}; 165};
170 166
171 167
@@ -236,7 +232,6 @@ struct SendMessageRequest
236 * Counter for this peer to match SMRs to replies. 232 * Counter for this peer to match SMRs to replies.
237 */ 233 */
238 uint16_t smr_id GNUNET_PACKED; 234 uint16_t smr_id GNUNET_PACKED;
239
240}; 235};
241 236
242 237
@@ -269,7 +264,6 @@ struct SendMessageReady
269 * Identity of the intended target. 264 * Identity of the intended target.
270 */ 265 */
271 struct GNUNET_PeerIdentity peer; 266 struct GNUNET_PeerIdentity peer;
272
273}; 267};
274 268
275 269
@@ -285,7 +279,8 @@ struct SendMessage
285 struct GNUNET_MessageHeader header; 279 struct GNUNET_MessageHeader header;
286 280
287 /** 281 /**
288 * How important is this message? 282 * How important is this message? Contains a
283 * `enum GNUNET_MQ_PriorityPreferences` in NBO.
289 */ 284 */
290 uint32_t priority GNUNET_PACKED; 285 uint32_t priority GNUNET_PACKED;
291 286
@@ -299,17 +294,6 @@ struct SendMessage
299 * Identity of the intended receiver. 294 * Identity of the intended receiver.
300 */ 295 */
301 struct GNUNET_PeerIdentity peer; 296 struct GNUNET_PeerIdentity peer;
302
303 /**
304 * #GNUNET_YES if corking is allowed, #GNUNET_NO if not.
305 */
306 uint32_t cork GNUNET_PACKED;
307
308 /**
309 * Always 0.
310 */
311 uint32_t reserved GNUNET_PACKED;
312
313}; 297};
314 298
315 299
@@ -338,7 +322,6 @@ struct MonitorNotifyMessage
338 * How long will we stay in this state (if nothing else happens)? 322 * How long will we stay in this state (if nothing else happens)?
339 */ 323 */
340 struct GNUNET_TIME_AbsoluteNBO timeout; 324 struct GNUNET_TIME_AbsoluteNBO timeout;
341
342}; 325};
343 326
344 327
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 6adaadabf..6381d9097 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -29,7 +29,7 @@
29#include "gnunet_core_service.h" 29#include "gnunet_core_service.h"
30#include "core.h" 30#include "core.h"
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "core-api",__VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "core-api", __VA_ARGS__)
33 33
34 34
35/** 35/**
@@ -69,7 +69,6 @@ struct PeerRecord
69 * SendMessageRequest ID generator for this peer. 69 * SendMessageRequest ID generator for this peer.
70 */ 70 */
71 uint16_t smr_id_gen; 71 uint16_t smr_id_gen;
72
73}; 72};
74 73
75 74
@@ -144,7 +143,6 @@ struct GNUNET_CORE_Handle
144 * Did we ever get INIT? 143 * Did we ever get INIT?
145 */ 144 */
146 int have_init; 145 int have_init;
147
148}; 146};
149 147
150 148
@@ -170,8 +168,7 @@ reconnect_task (void *cls)
170 struct GNUNET_CORE_Handle *h = cls; 168 struct GNUNET_CORE_Handle *h = cls;
171 169
172 h->reconnect_task = NULL; 170 h->reconnect_task = NULL;
173 LOG (GNUNET_ERROR_TYPE_DEBUG, 171 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n");
174 "Connecting to CORE service after delay\n");
175 reconnect (h); 172 reconnect (h);
176} 173}
177 174
@@ -187,7 +184,7 @@ reconnect_task (void *cls)
187 */ 184 */
188static int 185static int
189disconnect_and_free_peer_entry (void *cls, 186disconnect_and_free_peer_entry (void *cls,
190 const struct GNUNET_PeerIdentity *key, 187 const struct GNUNET_PeerIdentity *key,
191 void *value) 188 void *value)
192{ 189{
193 struct GNUNET_CORE_Handle *h = cls; 190 struct GNUNET_CORE_Handle *h = cls;
@@ -195,13 +192,9 @@ disconnect_and_free_peer_entry (void *cls,
195 192
196 GNUNET_assert (pr->h == h); 193 GNUNET_assert (pr->h == h);
197 if (NULL != h->disconnects) 194 if (NULL != h->disconnects)
198 h->disconnects (h->cls, 195 h->disconnects (h->cls, &pr->peer, pr->client_cls);
199 &pr->peer,
200 pr->client_cls);
201 GNUNET_assert (GNUNET_YES == 196 GNUNET_assert (GNUNET_YES ==
202 GNUNET_CONTAINER_multipeermap_remove (h->peers, 197 GNUNET_CONTAINER_multipeermap_remove (h->peers, key, pr));
203 key,
204 pr));
205 GNUNET_MQ_destroy (pr->mq); 198 GNUNET_MQ_destroy (pr->mq);
206 GNUNET_assert (NULL == pr->mq); 199 GNUNET_assert (NULL == pr->mq);
207 if (NULL != pr->env) 200 if (NULL != pr->env)
@@ -231,9 +224,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
231 } 224 }
232 GNUNET_assert (NULL == h->reconnect_task); 225 GNUNET_assert (NULL == h->reconnect_task);
233 h->reconnect_task = 226 h->reconnect_task =
234 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, 227 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_task, h);
235 &reconnect_task,
236 h);
237 GNUNET_CONTAINER_multipeermap_iterate (h->peers, 228 GNUNET_CONTAINER_multipeermap_iterate (h->peers,
238 &disconnect_and_free_peer_entry, 229 &disconnect_and_free_peer_entry,
239 h); 230 h);
@@ -249,39 +240,16 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
249 * @param error error code 240 * @param error error code
250 */ 241 */
251static void 242static void
252handle_mq_error (void *cls, 243handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
253 enum GNUNET_MQ_Error error)
254{ 244{
255 struct GNUNET_CORE_Handle *h = cls; 245 struct GNUNET_CORE_Handle *h = cls;
256 246
257 LOG (GNUNET_ERROR_TYPE_DEBUG, 247 LOG (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %d\n", error);
258 "MQ ERROR: %d\n",
259 error);
260 reconnect_later (h); 248 reconnect_later (h);
261} 249}
262 250
263 251
264/** 252/**
265 * Inquire with CORE what options should be set for a message
266 * so that it is transmitted with the given @a priority and
267 * the given @a cork value.
268 *
269 * @param cork desired corking
270 * @param priority desired message priority
271 * @param[out] flags set to `flags` value for #GNUNET_MQ_set_options()
272 * @return `extra` argument to give to #GNUNET_MQ_set_options()
273 */
274const void *
275GNUNET_CORE_get_mq_options (int cork,
276 enum GNUNET_CORE_Priority priority,
277 uint64_t *flags)
278{
279 *flags = ((uint64_t) priority) + (((uint64_t) cork) << 32);
280 return NULL;
281}
282
283
284/**
285 * Implement sending functionality of a message queue for 253 * Implement sending functionality of a message queue for
286 * us sending messages to a peer. 254 * us sending messages to a peer.
287 * 255 *
@@ -291,8 +259,8 @@ GNUNET_CORE_get_mq_options (int cork,
291 */ 259 */
292static void 260static void
293core_mq_send_impl (struct GNUNET_MQ_Handle *mq, 261core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
294 const struct GNUNET_MessageHeader *msg, 262 const struct GNUNET_MessageHeader *msg,
295 void *impl_state) 263 void *impl_state)
296{ 264{
297 struct PeerRecord *pr = impl_state; 265 struct PeerRecord *pr = impl_state;
298 struct GNUNET_CORE_Handle *h = pr->h; 266 struct GNUNET_CORE_Handle *h = pr->h;
@@ -300,9 +268,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
300 struct SendMessage *sm; 268 struct SendMessage *sm;
301 struct GNUNET_MQ_Envelope *env; 269 struct GNUNET_MQ_Envelope *env;
302 uint16_t msize; 270 uint16_t msize;
303 uint64_t flags; 271 enum GNUNET_MQ_PriorityPreferences flags;
304 int cork;
305 enum GNUNET_CORE_Priority priority;
306 272
307 if (NULL == h->mq) 273 if (NULL == h->mq)
308 { 274 {
@@ -313,11 +279,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
313 GNUNET_assert (NULL == pr->env); 279 GNUNET_assert (NULL == pr->env);
314 /* extract options from envelope */ 280 /* extract options from envelope */
315 env = GNUNET_MQ_get_current_envelope (mq); 281 env = GNUNET_MQ_get_current_envelope (mq);
316 GNUNET_break (NULL == 282 flags = GNUNET_MQ_env_get_options (env);
317 GNUNET_MQ_env_get_options (env,
318 &flags));
319 cork = (int) (flags >> 32);
320 priority = (uint32_t) flags;
321 283
322 /* check message size for sanity */ 284 /* check message size for sanity */
323 msize = ntohs (msg->size); 285 msize = ntohs (msg->size);
@@ -333,28 +295,20 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
333 "Asking core for transmission of %u bytes to `%s'\n", 295 "Asking core for transmission of %u bytes to `%s'\n",
334 (unsigned int) msize, 296 (unsigned int) msize,
335 GNUNET_i2s (&pr->peer)); 297 GNUNET_i2s (&pr->peer));
336 env = GNUNET_MQ_msg (smr, 298 env = GNUNET_MQ_msg (smr, GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST);
337 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST); 299 smr->priority = htonl ((uint32_t) flags);
338 smr->priority = htonl ((uint32_t) priority);
339 smr->peer = pr->peer; 300 smr->peer = pr->peer;
340 smr->reserved = htonl (0);
341 smr->size = htons (msize); 301 smr->size = htons (msize);
342 smr->smr_id = htons (++pr->smr_id_gen); 302 smr->smr_id = htons (++pr->smr_id_gen);
343 GNUNET_MQ_send (h->mq, 303 GNUNET_MQ_send (h->mq, env);
344 env);
345 304
346 /* prepare message with actual transmission data */ 305 /* prepare message with actual transmission data */
347 pr->env = GNUNET_MQ_msg_nested_mh (sm, 306 pr->env = GNUNET_MQ_msg_nested_mh (sm, GNUNET_MESSAGE_TYPE_CORE_SEND, msg);
348 GNUNET_MESSAGE_TYPE_CORE_SEND, 307 sm->priority = htonl ((uint32_t) flags);
349 msg);
350 sm->priority = htonl ((uint32_t) priority);
351 sm->peer = pr->peer; 308 sm->peer = pr->peer;
352 sm->cork = htonl ((uint32_t) cork);
353 sm->reserved = htonl (0);
354 LOG (GNUNET_ERROR_TYPE_DEBUG, 309 LOG (GNUNET_ERROR_TYPE_DEBUG,
355 "Calling get_message with buffer of %u bytes (%s)\n", 310 "Calling get_message with buffer of %u bytes\n",
356 (unsigned int) msize, 311 (unsigned int) msize);
357 cork ? "corked" : "uncorked");
358} 312}
359 313
360 314
@@ -366,8 +320,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
366 * @param impl_state state of the implementation 320 * @param impl_state state of the implementation
367 */ 321 */
368static void 322static void
369core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, 323core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
370 void *impl_state)
371{ 324{
372 struct PeerRecord *pr = impl_state; 325 struct PeerRecord *pr = impl_state;
373 326
@@ -384,8 +337,7 @@ core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq,
384 * @param impl_state state specific to the implementation 337 * @param impl_state state specific to the implementation
385 */ 338 */
386static void 339static void
387core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, 340core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
388 void *impl_state)
389{ 341{
390 struct PeerRecord *pr = impl_state; 342 struct PeerRecord *pr = impl_state;
391 343
@@ -404,8 +356,7 @@ core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq,
404 * @param error error code 356 * @param error error code
405 */ 357 */
406static void 358static void
407core_mq_error_handler (void *cls, 359core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
408 enum GNUNET_MQ_Error error)
409{ 360{
410 /* struct PeerRecord *pr = cls; */ 361 /* struct PeerRecord *pr = cls; */
411 362
@@ -423,41 +374,30 @@ core_mq_error_handler (void *cls,
423 */ 374 */
424static void 375static void
425connect_peer (struct GNUNET_CORE_Handle *h, 376connect_peer (struct GNUNET_CORE_Handle *h,
426 const struct GNUNET_PeerIdentity *peer) 377 const struct GNUNET_PeerIdentity *peer)
427{ 378{
428 struct PeerRecord *pr; 379 struct PeerRecord *pr;
429 uint64_t flags;
430 const void *extra;
431 380
432 pr = GNUNET_new (struct PeerRecord); 381 pr = GNUNET_new (struct PeerRecord);
433 pr->peer = *peer; 382 pr->peer = *peer;
434 pr->h = h; 383 pr->h = h;
435 GNUNET_assert (GNUNET_YES == 384 GNUNET_assert (GNUNET_YES ==
436 GNUNET_CONTAINER_multipeermap_put (h->peers, 385 GNUNET_CONTAINER_multipeermap_put (
437 &pr->peer, 386 h->peers,
438 pr, 387 &pr->peer,
439 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 388 pr,
389 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
440 pr->mq = GNUNET_MQ_queue_for_callbacks (&core_mq_send_impl, 390 pr->mq = GNUNET_MQ_queue_for_callbacks (&core_mq_send_impl,
441 &core_mq_destroy_impl, 391 &core_mq_destroy_impl,
442 &core_mq_cancel_impl, 392 &core_mq_cancel_impl,
443 pr, 393 pr,
444 h->handlers, 394 h->handlers,
445 &core_mq_error_handler, 395 &core_mq_error_handler,
446 pr); 396 pr);
447 /* get our default options */
448 extra = GNUNET_CORE_get_mq_options (GNUNET_NO,
449 GNUNET_CORE_PRIO_BEST_EFFORT,
450 &flags);
451 GNUNET_MQ_set_options (pr->mq,
452 flags,
453 extra);
454 if (NULL != h->connects) 397 if (NULL != h->connects)
455 { 398 {
456 pr->client_cls = h->connects (h->cls, 399 pr->client_cls = h->connects (h->cls, &pr->peer, pr->mq);
457 &pr->peer, 400 GNUNET_MQ_set_handlers_closure (pr->mq, pr->client_cls);
458 pr->mq);
459 GNUNET_MQ_set_handlers_closure (pr->mq,
460 pr->client_cls);
461 } 401 }
462} 402}
463 403
@@ -471,8 +411,7 @@ connect_peer (struct GNUNET_CORE_Handle *h,
471 * @param m the init reply 411 * @param m the init reply
472 */ 412 */
473static void 413static void
474handle_init_reply (void *cls, 414handle_init_reply (void *cls, const struct InitReplyMessage *m)
475 const struct InitReplyMessage *m)
476{ 415{
477 struct GNUNET_CORE_Handle *h = cls; 416 struct GNUNET_CORE_Handle *h = cls;
478 GNUNET_CORE_StartupCallback init; 417 GNUNET_CORE_StartupCallback init;
@@ -488,8 +427,7 @@ handle_init_reply (void *cls,
488 "Connected to core service of peer `%s'.\n", 427 "Connected to core service of peer `%s'.\n",
489 GNUNET_i2s (&h->me)); 428 GNUNET_i2s (&h->me));
490 h->have_init = GNUNET_YES; 429 h->have_init = GNUNET_YES;
491 init (h->cls, 430 init (h->cls, &h->me);
492 &h->me);
493 } 431 }
494 else 432 else
495 { 433 {
@@ -508,8 +446,7 @@ handle_init_reply (void *cls,
508 } 446 }
509 } 447 }
510 /* fake 'connect to self' */ 448 /* fake 'connect to self' */
511 connect_peer (h, 449 connect_peer (h, &h->me);
512 &h->me);
513} 450}
514 451
515 452
@@ -521,8 +458,7 @@ handle_init_reply (void *cls,
521 * @param cnm the connect message 458 * @param cnm the connect message
522 */ 459 */
523static void 460static void
524handle_connect_notify (void *cls, 461handle_connect_notify (void *cls, const struct ConnectNotifyMessage *cnm)
525 const struct ConnectNotifyMessage *cnm)
526{ 462{
527 struct GNUNET_CORE_Handle *h = cls; 463 struct GNUNET_CORE_Handle *h = cls;
528 struct PeerRecord *pr; 464 struct PeerRecord *pr;
@@ -530,24 +466,20 @@ handle_connect_notify (void *cls,
530 LOG (GNUNET_ERROR_TYPE_DEBUG, 466 LOG (GNUNET_ERROR_TYPE_DEBUG,
531 "Received notification about connection from `%s'.\n", 467 "Received notification about connection from `%s'.\n",
532 GNUNET_i2s (&cnm->peer)); 468 GNUNET_i2s (&cnm->peer));
533 if (0 == memcmp (&h->me, 469 if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity)))
534 &cnm->peer,
535 sizeof (struct GNUNET_PeerIdentity)))
536 { 470 {
537 /* connect to self!? */ 471 /* connect to self!? */
538 GNUNET_break (0); 472 GNUNET_break (0);
539 return; 473 return;
540 } 474 }
541 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 475 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &cnm->peer);
542 &cnm->peer);
543 if (NULL != pr) 476 if (NULL != pr)
544 { 477 {
545 GNUNET_break (0); 478 GNUNET_break (0);
546 reconnect_later (h); 479 reconnect_later (h);
547 return; 480 return;
548 } 481 }
549 connect_peer (h, 482 connect_peer (h, &cnm->peer);
550 &cnm->peer);
551} 483}
552 484
553 485
@@ -559,15 +491,12 @@ handle_connect_notify (void *cls,
559 * @param dnm message about the disconnect event 491 * @param dnm message about the disconnect event
560 */ 492 */
561static void 493static void
562handle_disconnect_notify (void *cls, 494handle_disconnect_notify (void *cls, const struct DisconnectNotifyMessage *dnm)
563 const struct DisconnectNotifyMessage *dnm)
564{ 495{
565 struct GNUNET_CORE_Handle *h = cls; 496 struct GNUNET_CORE_Handle *h = cls;
566 struct PeerRecord *pr; 497 struct PeerRecord *pr;
567 498
568 if (0 == memcmp (&h->me, 499 if (0 == memcmp (&h->me, &dnm->peer, sizeof (struct GNUNET_PeerIdentity)))
569 &dnm->peer,
570 sizeof (struct GNUNET_PeerIdentity)))
571 { 500 {
572 /* disconnect from self!? */ 501 /* disconnect from self!? */
573 GNUNET_break (0); 502 GNUNET_break (0);
@@ -577,17 +506,14 @@ handle_disconnect_notify (void *cls,
577 LOG (GNUNET_ERROR_TYPE_DEBUG, 506 LOG (GNUNET_ERROR_TYPE_DEBUG,
578 "Received notification about disconnect from `%s'.\n", 507 "Received notification about disconnect from `%s'.\n",
579 GNUNET_i2s (&dnm->peer)); 508 GNUNET_i2s (&dnm->peer));
580 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 509 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &dnm->peer);
581 &dnm->peer);
582 if (NULL == pr) 510 if (NULL == pr)
583 { 511 {
584 GNUNET_break (0); 512 GNUNET_break (0);
585 reconnect_later (h); 513 reconnect_later (h);
586 return; 514 return;
587 } 515 }
588 disconnect_and_free_peer_entry (h, 516 disconnect_and_free_peer_entry (h, &pr->peer, pr);
589 &pr->peer,
590 pr);
591} 517}
592 518
593 519
@@ -599,8 +525,7 @@ handle_disconnect_notify (void *cls,
599 * @return #GNUNET_OK if the message is well-formed 525 * @return #GNUNET_OK if the message is well-formed
600 */ 526 */
601static int 527static int
602check_notify_inbound (void *cls, 528check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
603 const struct NotifyTrafficMessage *ntm)
604{ 529{
605 uint16_t msize; 530 uint16_t msize;
606 const struct GNUNET_MessageHeader *em; 531 const struct GNUNET_MessageHeader *em;
@@ -629,8 +554,7 @@ check_notify_inbound (void *cls,
629 * @param ntm the message we got from CORE. 554 * @param ntm the message we got from CORE.
630 */ 555 */
631static void 556static void
632handle_notify_inbound (void *cls, 557handle_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
633 const struct NotifyTrafficMessage *ntm)
634{ 558{
635 struct GNUNET_CORE_Handle *h = cls; 559 struct GNUNET_CORE_Handle *h = cls;
636 const struct GNUNET_MessageHeader *em; 560 const struct GNUNET_MessageHeader *em;
@@ -640,16 +564,14 @@ handle_notify_inbound (void *cls,
640 "Received inbound message from `%s'.\n", 564 "Received inbound message from `%s'.\n",
641 GNUNET_i2s (&ntm->peer)); 565 GNUNET_i2s (&ntm->peer));
642 em = (const struct GNUNET_MessageHeader *) &ntm[1]; 566 em = (const struct GNUNET_MessageHeader *) &ntm[1];
643 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 567 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &ntm->peer);
644 &ntm->peer);
645 if (NULL == pr) 568 if (NULL == pr)
646 { 569 {
647 GNUNET_break (0); 570 GNUNET_break (0);
648 reconnect_later (h); 571 reconnect_later (h);
649 return; 572 return;
650 } 573 }
651 GNUNET_MQ_inject_message (pr->mq, 574 GNUNET_MQ_inject_message (pr->mq, em);
652 em);
653} 575}
654 576
655 577
@@ -662,14 +584,12 @@ handle_notify_inbound (void *cls,
662 * @param smr the message we got 584 * @param smr the message we got
663 */ 585 */
664static void 586static void
665handle_send_ready (void *cls, 587handle_send_ready (void *cls, const struct SendMessageReady *smr)
666 const struct SendMessageReady *smr)
667{ 588{
668 struct GNUNET_CORE_Handle *h = cls; 589 struct GNUNET_CORE_Handle *h = cls;
669 struct PeerRecord *pr; 590 struct PeerRecord *pr;
670 591
671 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 592 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &smr->peer);
672 &smr->peer);
673 if (NULL == pr) 593 if (NULL == pr)
674 { 594 {
675 GNUNET_break (0); 595 GNUNET_break (0);
@@ -693,8 +613,7 @@ handle_send_ready (void *cls,
693 } 613 }
694 614
695 /* ok, all good, send message out! */ 615 /* ok, all good, send message out! */
696 GNUNET_MQ_send (h->mq, 616 GNUNET_MQ_send (h->mq, pr->env);
697 pr->env);
698 pr->env = NULL; 617 pr->env = NULL;
699 GNUNET_MQ_impl_send_continue (pr->mq); 618 GNUNET_MQ_impl_send_continue (pr->mq);
700} 619}
@@ -709,39 +628,34 @@ handle_send_ready (void *cls,
709static void 628static void
710reconnect (struct GNUNET_CORE_Handle *h) 629reconnect (struct GNUNET_CORE_Handle *h)
711{ 630{
712 struct GNUNET_MQ_MessageHandler handlers[] = { 631 struct GNUNET_MQ_MessageHandler handlers[] =
713 GNUNET_MQ_hd_fixed_size (init_reply, 632 {GNUNET_MQ_hd_fixed_size (init_reply,
714 GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY, 633 GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY,
715 struct InitReplyMessage, 634 struct InitReplyMessage,
716 h), 635 h),
717 GNUNET_MQ_hd_fixed_size (connect_notify, 636 GNUNET_MQ_hd_fixed_size (connect_notify,
718 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT, 637 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT,
719 struct ConnectNotifyMessage, 638 struct ConnectNotifyMessage,
720 h), 639 h),
721 GNUNET_MQ_hd_fixed_size (disconnect_notify, 640 GNUNET_MQ_hd_fixed_size (disconnect_notify,
722 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT, 641 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT,
723 struct DisconnectNotifyMessage, 642 struct DisconnectNotifyMessage,
724 h), 643 h),
725 GNUNET_MQ_hd_var_size (notify_inbound, 644 GNUNET_MQ_hd_var_size (notify_inbound,
726 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND, 645 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND,
727 struct NotifyTrafficMessage, 646 struct NotifyTrafficMessage,
728 h), 647 h),
729 GNUNET_MQ_hd_fixed_size (send_ready, 648 GNUNET_MQ_hd_fixed_size (send_ready,
730 GNUNET_MESSAGE_TYPE_CORE_SEND_READY, 649 GNUNET_MESSAGE_TYPE_CORE_SEND_READY,
731 struct SendMessageReady, 650 struct SendMessageReady,
732 h), 651 h),
733 GNUNET_MQ_handler_end () 652 GNUNET_MQ_handler_end ()};
734 };
735 struct InitMessage *init; 653 struct InitMessage *init;
736 struct GNUNET_MQ_Envelope *env; 654 struct GNUNET_MQ_Envelope *env;
737 uint16_t *ts; 655 uint16_t *ts;
738 656
739 GNUNET_assert (NULL == h->mq); 657 GNUNET_assert (NULL == h->mq);
740 h->mq = GNUNET_CLIENT_connect (h->cfg, 658 h->mq = GNUNET_CLIENT_connect (h->cfg, "core", handlers, &handle_mq_error, h);
741 "core",
742 handlers,
743 &handle_mq_error,
744 h);
745 if (NULL == h->mq) 659 if (NULL == h->mq)
746 { 660 {
747 reconnect_later (h); 661 reconnect_later (h);
@@ -750,14 +664,12 @@ reconnect (struct GNUNET_CORE_Handle *h)
750 env = GNUNET_MQ_msg_extra (init, 664 env = GNUNET_MQ_msg_extra (init,
751 sizeof (uint16_t) * h->hcnt, 665 sizeof (uint16_t) * h->hcnt,
752 GNUNET_MESSAGE_TYPE_CORE_INIT); 666 GNUNET_MESSAGE_TYPE_CORE_INIT);
753 LOG (GNUNET_ERROR_TYPE_INFO, 667 LOG (GNUNET_ERROR_TYPE_INFO, "(Re)connecting to CORE service\n");
754 "(Re)connecting to CORE service\n");
755 init->options = htonl (0); 668 init->options = htonl (0);
756 ts = (uint16_t *) &init[1]; 669 ts = (uint16_t *) &init[1];
757 for (unsigned int hpos = 0; hpos < h->hcnt; hpos++) 670 for (unsigned int hpos = 0; hpos < h->hcnt; hpos++)
758 ts[hpos] = htons (h->handlers[hpos].type); 671 ts[hpos] = htons (h->handlers[hpos].type);
759 GNUNET_MQ_send (h->mq, 672 GNUNET_MQ_send (h->mq, env);
760 env);
761} 673}
762 674
763 675
@@ -791,15 +703,13 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
791 h->init = init; 703 h->init = init;
792 h->connects = connects; 704 h->connects = connects;
793 h->disconnects = disconnects; 705 h->disconnects = disconnects;
794 h->peers = GNUNET_CONTAINER_multipeermap_create (128, 706 h->peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
795 GNUNET_NO);
796 h->handlers = GNUNET_MQ_copy_handlers (handlers); 707 h->handlers = GNUNET_MQ_copy_handlers (handlers);
797 h->hcnt = GNUNET_MQ_count_handlers (handlers); 708 h->hcnt = GNUNET_MQ_count_handlers (handlers);
798 GNUNET_assert (h->hcnt < 709 GNUNET_assert (h->hcnt <
799 (GNUNET_MAX_MESSAGE_SIZE - 710 (GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InitMessage)) /
800 sizeof (struct InitMessage)) / sizeof (uint16_t)); 711 sizeof (uint16_t));
801 LOG (GNUNET_ERROR_TYPE_DEBUG, 712 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n");
802 "Connecting to CORE service\n");
803 reconnect (h); 713 reconnect (h);
804 if (NULL == h->mq) 714 if (NULL == h->mq)
805 { 715 {
@@ -818,8 +728,7 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
818void 728void
819GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) 729GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
820{ 730{
821 LOG (GNUNET_ERROR_TYPE_DEBUG, 731 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n");
822 "Disconnecting from CORE service\n");
823 GNUNET_CONTAINER_multipeermap_iterate (handle->peers, 732 GNUNET_CONTAINER_multipeermap_iterate (handle->peers,
824 &disconnect_and_free_peer_entry, 733 &disconnect_and_free_peer_entry,
825 handle); 734 handle);
@@ -849,12 +758,11 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
849 */ 758 */
850struct GNUNET_MQ_Handle * 759struct GNUNET_MQ_Handle *
851GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h, 760GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h,
852 const struct GNUNET_PeerIdentity *pid) 761 const struct GNUNET_PeerIdentity *pid)
853{ 762{
854 struct PeerRecord *pr; 763 struct PeerRecord *pr;
855 764
856 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, 765 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, pid);
857 pid);
858 if (NULL == pr) 766 if (NULL == pr)
859 return NULL; 767 return NULL;
860 return pr->mq; 768 return pr->mq;
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index e26bb4d5c..740707ce1 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -107,7 +107,6 @@ struct GSC_Client
107 * specifically cares about. Size of the @e types array. 107 * specifically cares about. Size of the @e types array.
108 */ 108 */
109 unsigned int tcnt; 109 unsigned int tcnt;
110
111}; 110};
112 111
113 112
@@ -150,12 +149,10 @@ static struct GSC_Client *client_tail;
150 * @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not. 149 * @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not.
151 */ 150 */
152static int 151static int
153type_match (uint16_t type, 152type_match (uint16_t type, struct GSC_Client *c)
154 struct GSC_Client *c)
155{ 153{
156 if ( (0 == c->tcnt) && 154 if ((0 == c->tcnt) && (0 != c->options))
157 (0 != c->options) ) 155 return GNUNET_YES; /* peer without handlers and inbound/outbond
158 return GNUNET_YES; /* peer without handlers and inbound/outbond
159 callbacks matches ALL */ 156 callbacks matches ALL */
160 if (NULL == c->types) 157 if (NULL == c->types)
161 return GNUNET_NO; 158 return GNUNET_NO;
@@ -174,8 +171,7 @@ type_match (uint16_t type,
174 * @return #GNUNET_OK if @a im is well-formed 171 * @return #GNUNET_OK if @a im is well-formed
175 */ 172 */
176static int 173static int
177check_client_init (void *cls, 174check_client_init (void *cls, const struct InitMessage *im)
178 const struct InitMessage *im)
179{ 175{
180 return GNUNET_OK; 176 return GNUNET_OK;
181} 177}
@@ -188,8 +184,7 @@ check_client_init (void *cls,
188 * @param im the `struct InitMessage` 184 * @param im the `struct InitMessage`
189 */ 185 */
190static void 186static void
191handle_client_init (void *cls, 187handle_client_init (void *cls, const struct InitMessage *im)
192 const struct InitMessage *im)
193{ 188{
194 struct GSC_Client *c = cls; 189 struct GSC_Client *c = cls;
195 struct GNUNET_MQ_Envelope *env; 190 struct GNUNET_MQ_Envelope *env;
@@ -206,24 +201,23 @@ handle_client_init (void *cls,
206 all_client_options |= c->options; 201 all_client_options |= c->options;
207 c->types = GNUNET_malloc (msize); 202 c->types = GNUNET_malloc (msize);
208 GNUNET_assert (GNUNET_YES == 203 GNUNET_assert (GNUNET_YES ==
209 GNUNET_CONTAINER_multipeermap_put (c->connectmap, 204 GNUNET_CONTAINER_multipeermap_put (
210 &GSC_my_identity, 205 c->connectmap,
211 NULL, 206 &GSC_my_identity,
212 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 207 NULL,
208 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
213 for (unsigned int i = 0; i < c->tcnt; i++) 209 for (unsigned int i = 0; i < c->tcnt; i++)
214 c->types[i] = ntohs (types[i]); 210 c->types[i] = ntohs (types[i]);
215 GSC_TYPEMAP_add (c->types, 211 GSC_TYPEMAP_add (c->types, c->tcnt);
216 c->tcnt); 212 GNUNET_log (
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 213 GNUNET_ERROR_TYPE_DEBUG,
218 "Client connecting to core service is interested in %u message types\n", 214 "Client connecting to core service is interested in %u message types\n",
219 (unsigned int) c->tcnt); 215 (unsigned int) c->tcnt);
220 /* send init reply message */ 216 /* send init reply message */
221 env = GNUNET_MQ_msg (irm, 217 env = GNUNET_MQ_msg (irm, GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
222 GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
223 irm->reserved = htonl (0); 218 irm->reserved = htonl (0);
224 irm->my_identity = GSC_my_identity; 219 irm->my_identity = GSC_my_identity;
225 GNUNET_MQ_send (c->mq, 220 GNUNET_MQ_send (c->mq, env);
226 env);
227 GSC_SESSIONS_notify_client_about_sessions (c); 221 GSC_SESSIONS_notify_client_about_sessions (c);
228 GNUNET_SERVICE_client_continue (c->client); 222 GNUNET_SERVICE_client_continue (c->client);
229} 223}
@@ -245,11 +239,11 @@ void
245GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car, 239GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car,
246 int drop_client) 240 int drop_client)
247{ 241{
248 GNUNET_assert (GNUNET_YES == 242 GNUNET_assert (
249 GNUNET_CONTAINER_multipeermap_remove (car-> 243 GNUNET_YES ==
250 client_handle->requests, 244 GNUNET_CONTAINER_multipeermap_remove (car->client_handle->requests,
251 &car->target, 245 &car->target,
252 car)); 246 car));
253 if (GNUNET_YES == drop_client) 247 if (GNUNET_YES == drop_client)
254 GNUNET_SERVICE_client_drop (car->client_handle->client); 248 GNUNET_SERVICE_client_drop (car->client_handle->client);
255 GNUNET_free (car); 249 GNUNET_free (car);
@@ -274,38 +268,31 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
274 268
275 c = car->client_handle; 269 c = car->client_handle;
276 if (GNUNET_YES != 270 if (GNUNET_YES !=
277 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, 271 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, &car->target))
278 &car->target))
279 { 272 {
280 /* connection has gone down since, drop request */ 273 /* connection has gone down since, drop request */
281 GNUNET_assert (0 != 274 GNUNET_assert (0 != memcmp (&car->target,
282 memcmp (&car->target, 275 &GSC_my_identity,
283 &GSC_my_identity, 276 sizeof (struct GNUNET_PeerIdentity)));
284 sizeof (struct GNUNET_PeerIdentity)));
285 GSC_SESSIONS_dequeue_request (car); 277 GSC_SESSIONS_dequeue_request (car);
286 GSC_CLIENTS_reject_request (car, 278 GSC_CLIENTS_reject_request (car, GNUNET_NO);
287 GNUNET_NO);
288 return; 279 return;
289 } 280 }
290 delay = GNUNET_TIME_absolute_get_duration (car->received_time); 281 delay = GNUNET_TIME_absolute_get_duration (car->received_time);
291 left = GNUNET_TIME_absolute_get_duration (car->deadline); 282 left = GNUNET_TIME_absolute_get_duration (car->deadline);
292 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 283 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
293 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 284 GNUNET_log (
294 "Client waited %s for permission to transmit to `%s'%s (priority %u)\n", 285 GNUNET_ERROR_TYPE_WARNING,
295 GNUNET_STRINGS_relative_time_to_string (delay, 286 "Client waited %s for permission to transmit to `%s'%s (priority %u)\n",
296 GNUNET_YES), 287 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
297 GNUNET_i2s (&car->target), 288 GNUNET_i2s (&car->target),
298 (0 == left.rel_value_us) 289 (0 == left.rel_value_us) ? " (past deadline)" : "",
299 ? " (past deadline)" 290 car->priority);
300 : "", 291 env = GNUNET_MQ_msg (smr, GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
301 car->priority);
302 env = GNUNET_MQ_msg (smr,
303 GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
304 smr->size = htons (car->msize); 292 smr->size = htons (car->msize);
305 smr->smr_id = car->smr_id; 293 smr->smr_id = car->smr_id;
306 smr->peer = car->target; 294 smr->peer = car->target;
307 GNUNET_MQ_send (c->mq, 295 GNUNET_MQ_send (c->mq, env);
308 env);
309} 296}
310 297
311 298
@@ -316,51 +303,47 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
316 * @param req the `struct SendMessageRequest` 303 * @param req the `struct SendMessageRequest`
317 */ 304 */
318static void 305static void
319handle_client_send_request (void *cls, 306handle_client_send_request (void *cls, const struct SendMessageRequest *req)
320 const struct SendMessageRequest *req)
321{ 307{
322 struct GSC_Client *c = cls; 308 struct GSC_Client *c = cls;
323 struct GSC_ClientActiveRequest *car; 309 struct GSC_ClientActiveRequest *car;
324 int is_loopback; 310 int is_loopback;
325 311
326 if (NULL == c->requests) 312 if (NULL == c->requests)
327 c->requests = GNUNET_CONTAINER_multipeermap_create (16, 313 c->requests = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
328 GNUNET_NO);
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
330 "Client asked for transmission to `%s'\n", 315 "Client asked for transmission to `%s'\n",
331 GNUNET_i2s (&req->peer)); 316 GNUNET_i2s (&req->peer));
332 is_loopback = 317 is_loopback = (0 == memcmp (&req->peer,
333 (0 == 318 &GSC_my_identity,
334 memcmp (&req->peer, 319 sizeof (struct GNUNET_PeerIdentity)));
335 &GSC_my_identity,
336 sizeof (struct GNUNET_PeerIdentity)));
337 if ((! is_loopback) && 320 if ((! is_loopback) &&
338 (GNUNET_YES != 321 (GNUNET_YES !=
339 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, 322 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, &req->peer)))
340 &req->peer)))
341 { 323 {
342 /* neighbour must have disconnected since request was issued, 324 /* neighbour must have disconnected since request was issued,
343 * ignore (client will realize it once it processes the 325 * ignore (client will realize it once it processes the
344 * disconnect notification) */ 326 * disconnect notification) */
345 GNUNET_STATISTICS_update (GSC_stats, 327 GNUNET_STATISTICS_update (GSC_stats,
346 gettext_noop 328 gettext_noop (
347 ("# send requests dropped (disconnected)"), 1, 329 "# send requests dropped (disconnected)"),
330 1,
348 GNUNET_NO); 331 GNUNET_NO);
349 GNUNET_SERVICE_client_continue (c->client); 332 GNUNET_SERVICE_client_continue (c->client);
350 return; 333 return;
351 } 334 }
352 335
353 car = GNUNET_CONTAINER_multipeermap_get (c->requests, 336 car = GNUNET_CONTAINER_multipeermap_get (c->requests, &req->peer);
354 &req->peer);
355 if (NULL == car) 337 if (NULL == car)
356 { 338 {
357 /* create new entry */ 339 /* create new entry */
358 car = GNUNET_new (struct GSC_ClientActiveRequest); 340 car = GNUNET_new (struct GSC_ClientActiveRequest);
359 GNUNET_assert (GNUNET_OK == 341 GNUNET_assert (GNUNET_OK ==
360 GNUNET_CONTAINER_multipeermap_put (c->requests, 342 GNUNET_CONTAINER_multipeermap_put (
361 &req->peer, 343 c->requests,
362 car, 344 &req->peer,
363 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 345 car,
346 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
364 car->client_handle = c; 347 car->client_handle = c;
365 } 348 }
366 else 349 else
@@ -368,8 +351,9 @@ handle_client_send_request (void *cls,
368 /* dequeue and recycle memory from pending request, there can only 351 /* dequeue and recycle memory from pending request, there can only
369 be at most one per client and peer */ 352 be at most one per client and peer */
370 GNUNET_STATISTICS_update (GSC_stats, 353 GNUNET_STATISTICS_update (GSC_stats,
371 gettext_noop ("# dequeuing CAR (duplicate request)"), 354 gettext_noop (
372 1, 355 "# dequeuing CAR (duplicate request)"),
356 1,
373 GNUNET_NO); 357 GNUNET_NO);
374 GSC_SESSIONS_dequeue_request (car); 358 GSC_SESSIONS_dequeue_request (car);
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -379,7 +363,7 @@ handle_client_send_request (void *cls,
379 car->target = req->peer; 363 car->target = req->peer;
380 car->received_time = GNUNET_TIME_absolute_get (); 364 car->received_time = GNUNET_TIME_absolute_get ();
381 car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline); 365 car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline);
382 car->priority = (enum GNUNET_CORE_Priority) ntohl (req->priority); 366 car->priority = (enum GNUNET_MQ_PriorityPreferences) ntohl (req->priority);
383 car->msize = ntohs (req->size); 367 car->msize = ntohs (req->size);
384 car->smr_id = req->smr_id; 368 car->smr_id = req->smr_id;
385 car->was_solicited = GNUNET_NO; 369 car->was_solicited = GNUNET_NO;
@@ -408,13 +392,7 @@ struct TokenizerContext
408 /** 392 /**
409 * How important is this message. 393 * How important is this message.
410 */ 394 */
411 enum GNUNET_CORE_Priority priority; 395 enum GNUNET_MQ_PriorityPreferences priority;
412
413 /**
414 * Is corking allowed (set only once we have the real message).
415 */
416 int cork;
417
418}; 396};
419 397
420 398
@@ -431,65 +409,57 @@ struct TokenizerContext
431 * #GNUNET_SYSERR to stop further processing with error 409 * #GNUNET_SYSERR to stop further processing with error
432 */ 410 */
433static int 411static int
434tokenized_cb (void *cls, 412tokenized_cb (void *cls, const struct GNUNET_MessageHeader *message)
435 const struct GNUNET_MessageHeader *message)
436{ 413{
437 struct TokenizerContext *tc = cls; 414 struct TokenizerContext *tc = cls;
438 struct GSC_ClientActiveRequest *car = tc->car; 415 struct GSC_ClientActiveRequest *car = tc->car;
439 char buf[92]; 416 char buf[92];
440 417
441 GNUNET_snprintf (buf, 418 GNUNET_snprintf (buf,
442 sizeof (buf), 419 sizeof (buf),
443 gettext_noop ("# bytes of messages of type %u received"), 420 gettext_noop ("# bytes of messages of type %u received"),
444 (unsigned int) ntohs (message->type)); 421 (unsigned int) ntohs (message->type));
445 GNUNET_STATISTICS_update (GSC_stats, 422 GNUNET_STATISTICS_update (GSC_stats, buf, ntohs (message->size), GNUNET_NO);
446 buf, 423 if (0 == memcmp (&car->target,
447 ntohs (message->size), 424 &GSC_my_identity,
448 GNUNET_NO); 425 sizeof (struct GNUNET_PeerIdentity)))
449 if (0 ==
450 memcmp (&car->target,
451 &GSC_my_identity,
452 sizeof (struct GNUNET_PeerIdentity)))
453 { 426 {
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
455 "Delivering message of type %u to myself\n", 428 "Delivering message of type %u to myself\n",
456 ntohs (message->type)); 429 ntohs (message->type));
457 GSC_CLIENTS_deliver_message (&GSC_my_identity, 430 GSC_CLIENTS_deliver_message (&GSC_my_identity,
458 message, 431 message,
459 ntohs (message->size), 432 ntohs (message->size),
460 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); 433 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
461 GSC_CLIENTS_deliver_message (&GSC_my_identity, 434 GSC_CLIENTS_deliver_message (&GSC_my_identity,
462 message, 435 message,
463 sizeof (struct GNUNET_MessageHeader), 436 sizeof (struct GNUNET_MessageHeader),
464 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); 437 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
465 GSC_CLIENTS_deliver_message (&GSC_my_identity, 438 GSC_CLIENTS_deliver_message (&GSC_my_identity,
466 message, 439 message,
467 ntohs (message->size), 440 ntohs (message->size),
468 GNUNET_CORE_OPTION_SEND_FULL_INBOUND); 441 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
469 GSC_CLIENTS_deliver_message (&GSC_my_identity, 442 GSC_CLIENTS_deliver_message (&GSC_my_identity,
470 message, 443 message,
471 sizeof (struct GNUNET_MessageHeader), 444 sizeof (struct GNUNET_MessageHeader),
472 GNUNET_CORE_OPTION_SEND_HDR_INBOUND); 445 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
473 } 446 }
474 else 447 else
475 { 448 {
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
477 "Delivering message of type %u and size %u to %s\n", 450 "Delivering message of type %u and size %u to %s\n",
478 ntohs (message->type), 451 ntohs (message->type),
479 ntohs (message->size), 452 ntohs (message->size),
480 GNUNET_i2s (&car->target)); 453 GNUNET_i2s (&car->target));
481 GSC_CLIENTS_deliver_message (&car->target, 454 GSC_CLIENTS_deliver_message (&car->target,
482 message, 455 message,
483 ntohs (message->size), 456 ntohs (message->size),
484 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); 457 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
485 GSC_CLIENTS_deliver_message (&car->target, 458 GSC_CLIENTS_deliver_message (&car->target,
486 message, 459 message,
487 sizeof (struct GNUNET_MessageHeader), 460 sizeof (struct GNUNET_MessageHeader),
488 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); 461 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
489 GSC_SESSIONS_transmit (car, 462 GSC_SESSIONS_transmit (car, message, tc->priority);
490 message,
491 tc->cork,
492 tc->priority);
493 } 463 }
494 return GNUNET_OK; 464 return GNUNET_OK;
495} 465}
@@ -503,8 +473,7 @@ tokenized_cb (void *cls,
503 * @return #GNUNET_OK if @a sm is well-formed 473 * @return #GNUNET_OK if @a sm is well-formed
504 */ 474 */
505static int 475static int
506check_client_send (void *cls, 476check_client_send (void *cls, const struct SendMessage *sm)
507 const struct SendMessage *sm)
508{ 477{
509 return GNUNET_OK; 478 return GNUNET_OK;
510} 479}
@@ -517,8 +486,7 @@ check_client_send (void *cls,
517 * @param sm the `struct SendMessage` 486 * @param sm the `struct SendMessage`
518 */ 487 */
519static void 488static void
520handle_client_send (void *cls, 489handle_client_send (void *cls, const struct SendMessage *sm)
521 const struct SendMessage *sm)
522{ 490{
523 struct GSC_Client *c = cls; 491 struct GSC_Client *c = cls;
524 struct TokenizerContext tc; 492 struct TokenizerContext tc;
@@ -527,9 +495,7 @@ handle_client_send (void *cls,
527 struct GNUNET_MessageStreamTokenizer *mst; 495 struct GNUNET_MessageStreamTokenizer *mst;
528 496
529 msize = ntohs (sm->header.size) - sizeof (struct SendMessage); 497 msize = ntohs (sm->header.size) - sizeof (struct SendMessage);
530 GNUNET_break (0 == ntohl (sm->reserved)); 498 tc.car = GNUNET_CONTAINER_multipeermap_get (c->requests, &sm->peer);
531 tc.car = GNUNET_CONTAINER_multipeermap_get (c->requests,
532 &sm->peer);
533 if (NULL == tc.car) 499 if (NULL == tc.car)
534 { 500 {
535 /* Must have been that we first approved the request, then got disconnected 501 /* Must have been that we first approved the request, then got disconnected
@@ -538,43 +504,37 @@ handle_client_send (void *cls,
538 * might also now be *again* connected. So this can happen (but should be 504 * might also now be *again* connected. So this can happen (but should be
539 * rare). If it does happen, the message is discarded. */ 505 * rare). If it does happen, the message is discarded. */
540 GNUNET_STATISTICS_update (GSC_stats, 506 GNUNET_STATISTICS_update (GSC_stats,
541 gettext_noop ("# messages discarded (session disconnected)"), 507 gettext_noop (
508 "# messages discarded (session disconnected)"),
542 1, 509 1,
543 GNUNET_NO); 510 GNUNET_NO);
544 GNUNET_SERVICE_client_continue (c->client); 511 GNUNET_SERVICE_client_continue (c->client);
545 return; 512 return;
546 } 513 }
547 delay = GNUNET_TIME_absolute_get_duration (tc.car->received_time); 514 delay = GNUNET_TIME_absolute_get_duration (tc.car->received_time);
548 tc.cork = ntohl (sm->cork); 515 tc.priority = (enum GNUNET_MQ_PriorityPreferences) ntohl (sm->priority);
549 tc.priority = (enum GNUNET_CORE_Priority) ntohl (sm->priority);
550 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 516 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
551 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 517 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
552 "Client waited %s for transmission of %u bytes to `%s'%s\n", 518 "Client waited %s for transmission of %u bytes to `%s'\n",
553 GNUNET_STRINGS_relative_time_to_string (delay, 519 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
554 GNUNET_YES),
555 msize, 520 msize,
556 GNUNET_i2s (&sm->peer), 521 GNUNET_i2s (&sm->peer));
557 tc.cork ? " (cork)" : " (uncorked)");
558 else 522 else
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 "Client waited %s for transmission of %u bytes to `%s'%s\n", 524 "Client waited %s for transmission of %u bytes to `%s'\n",
561 GNUNET_STRINGS_relative_time_to_string (delay, 525 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
562 GNUNET_YES),
563 msize, 526 msize,
564 GNUNET_i2s (&sm->peer), 527 GNUNET_i2s (&sm->peer));
565 tc.cork ? " (cork)" : " (uncorked)");
566 528
567 GNUNET_assert (GNUNET_YES == 529 GNUNET_assert (
568 GNUNET_CONTAINER_multipeermap_remove (c->requests, 530 GNUNET_YES ==
569 &sm->peer, 531 GNUNET_CONTAINER_multipeermap_remove (c->requests, &sm->peer, tc.car));
570 tc.car)); 532 mst = GNUNET_MST_create (&tokenized_cb, &tc);
571 mst = GNUNET_MST_create (&tokenized_cb,
572 &tc);
573 GNUNET_MST_from_buffer (mst, 533 GNUNET_MST_from_buffer (mst,
574 (const char *) &sm[1], 534 (const char *) &sm[1],
575 msize, 535 msize,
576 GNUNET_YES, 536 GNUNET_YES,
577 GNUNET_NO); 537 GNUNET_NO);
578 GNUNET_MST_destroy (mst); 538 GNUNET_MST_destroy (mst);
579 GSC_SESSIONS_dequeue_request (tc.car); 539 GSC_SESSIONS_dequeue_request (tc.car);
580 GNUNET_free (tc.car); 540 GNUNET_free (tc.car);
@@ -592,16 +552,16 @@ handle_client_send (void *cls,
592 */ 552 */
593static int 553static int
594destroy_active_client_request (void *cls, 554destroy_active_client_request (void *cls,
595 const struct GNUNET_PeerIdentity *key, 555 const struct GNUNET_PeerIdentity *key,
596 void *value) 556 void *value)
597{ 557{
598 struct GSC_ClientActiveRequest *car = value; 558 struct GSC_ClientActiveRequest *car = value;
599 559
600 GNUNET_assert (GNUNET_YES == 560 GNUNET_assert (
601 GNUNET_CONTAINER_multipeermap_remove (car-> 561 GNUNET_YES ==
602 client_handle->requests, 562 GNUNET_CONTAINER_multipeermap_remove (car->client_handle->requests,
603 &car->target, 563 &car->target,
604 car)); 564 car));
605 GSC_SESSIONS_dequeue_request (car); 565 GSC_SESSIONS_dequeue_request (car);
606 GNUNET_free (car); 566 GNUNET_free (car);
607 return GNUNET_YES; 567 return GNUNET_YES;
@@ -618,19 +578,16 @@ destroy_active_client_request (void *cls,
618 */ 578 */
619static void * 579static void *
620client_connect_cb (void *cls, 580client_connect_cb (void *cls,
621 struct GNUNET_SERVICE_Client *client, 581 struct GNUNET_SERVICE_Client *client,
622 struct GNUNET_MQ_Handle *mq) 582 struct GNUNET_MQ_Handle *mq)
623{ 583{
624 struct GSC_Client *c; 584 struct GSC_Client *c;
625 585
626 c = GNUNET_new (struct GSC_Client); 586 c = GNUNET_new (struct GSC_Client);
627 c->client = client; 587 c->client = client;
628 c->mq = mq; 588 c->mq = mq;
629 c->connectmap = GNUNET_CONTAINER_multipeermap_create (16, 589 c->connectmap = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
630 GNUNET_NO); 590 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c);
631 GNUNET_CONTAINER_DLL_insert (client_head,
632 client_tail,
633 c);
634 return c; 591 return c;
635} 592}
636 593
@@ -644,17 +601,15 @@ client_connect_cb (void *cls,
644 */ 601 */
645static void 602static void
646client_disconnect_cb (void *cls, 603client_disconnect_cb (void *cls,
647 struct GNUNET_SERVICE_Client *client, 604 struct GNUNET_SERVICE_Client *client,
648 void *app_ctx) 605 void *app_ctx)
649{ 606{
650 struct GSC_Client *c = app_ctx; 607 struct GSC_Client *c = app_ctx;
651 608
652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
653 "Client %p has disconnected from core service.\n", 610 "Client %p has disconnected from core service.\n",
654 client); 611 client);
655 GNUNET_CONTAINER_DLL_remove (client_head, 612 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c);
656 client_tail,
657 c);
658 if (NULL != c->requests) 613 if (NULL != c->requests)
659 { 614 {
660 GNUNET_CONTAINER_multipeermap_iterate (c->requests, 615 GNUNET_CONTAINER_multipeermap_iterate (c->requests,
@@ -666,15 +621,14 @@ client_disconnect_cb (void *cls,
666 c->connectmap = NULL; 621 c->connectmap = NULL;
667 if (NULL != c->types) 622 if (NULL != c->types)
668 { 623 {
669 GSC_TYPEMAP_remove (c->types, 624 GSC_TYPEMAP_remove (c->types, c->tcnt);
670 c->tcnt);
671 GNUNET_free (c->types); 625 GNUNET_free (c->types);
672 } 626 }
673 GNUNET_free (c); 627 GNUNET_free (c);
674 628
675 /* recalculate 'all_client_options' */ 629 /* recalculate 'all_client_options' */
676 all_client_options = 0; 630 all_client_options = 0;
677 for (c = client_head; NULL != c ; c = c->next) 631 for (c = client_head; NULL != c; c = c->next)
678 all_client_options |= c->options; 632 all_client_options |= c->options;
679} 633}
680 634
@@ -690,10 +644,11 @@ client_disconnect_cb (void *cls,
690 * @param tmap_new updated type map for the neighbour, NULL for disconnect 644 * @param tmap_new updated type map for the neighbour, NULL for disconnect
691 */ 645 */
692void 646void
693GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, 647GSC_CLIENTS_notify_client_about_neighbour (
694 const struct GNUNET_PeerIdentity *neighbour, 648 struct GSC_Client *client,
695 const struct GSC_TypeMap *tmap_old, 649 const struct GNUNET_PeerIdentity *neighbour,
696 const struct GSC_TypeMap *tmap_new) 650 const struct GSC_TypeMap *tmap_old,
651 const struct GSC_TypeMap *tmap_new)
697{ 652{
698 struct GNUNET_MQ_Envelope *env; 653 struct GNUNET_MQ_Envelope *env;
699 int old_match; 654 int old_match;
@@ -701,12 +656,8 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
701 656
702 if (GNUNET_YES != client->got_init) 657 if (GNUNET_YES != client->got_init)
703 return; 658 return;
704 old_match = GSC_TYPEMAP_test_match (tmap_old, 659 old_match = GSC_TYPEMAP_test_match (tmap_old, client->types, client->tcnt);
705 client->types, 660 new_match = GSC_TYPEMAP_test_match (tmap_new, client->types, client->tcnt);
706 client->tcnt);
707 new_match = GSC_TYPEMAP_test_match (tmap_new,
708 client->types,
709 client->tcnt);
710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
711 "Notifying client about neighbour %s (%d/%d)\n", 662 "Notifying client about neighbour %s (%d/%d)\n",
712 GNUNET_i2s (neighbour), 663 GNUNET_i2s (neighbour),
@@ -714,55 +665,52 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
714 new_match); 665 new_match);
715 if (old_match == new_match) 666 if (old_match == new_match)
716 { 667 {
717 GNUNET_assert (old_match == 668 GNUNET_assert (
718 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, 669 old_match ==
719 neighbour)); 670 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour));
720 return; /* no change */ 671 return; /* no change */
721 } 672 }
722 if (GNUNET_NO == old_match) 673 if (GNUNET_NO == old_match)
723 { 674 {
724 struct ConnectNotifyMessage *cnm; 675 struct ConnectNotifyMessage *cnm;
725 676
726 /* send connect */ 677 /* send connect */
727 GNUNET_assert (GNUNET_NO == 678 GNUNET_assert (
728 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, 679 GNUNET_NO ==
729 neighbour)); 680 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour));
730 GNUNET_assert (GNUNET_YES == 681 GNUNET_assert (GNUNET_YES ==
731 GNUNET_CONTAINER_multipeermap_put (client->connectmap, 682 GNUNET_CONTAINER_multipeermap_put (
732 neighbour, 683 client->connectmap,
733 NULL, 684 neighbour,
734 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 685 NULL,
735 env = GNUNET_MQ_msg (cnm, 686 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
736 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 687 env = GNUNET_MQ_msg (cnm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
737 cnm->reserved = htonl (0); 688 cnm->reserved = htonl (0);
738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
739 "Sending NOTIFY_CONNECT message about peer %s to client.\n", 690 "Sending NOTIFY_CONNECT message about peer %s to client.\n",
740 GNUNET_i2s (neighbour)); 691 GNUNET_i2s (neighbour));
741 cnm->peer = *neighbour; 692 cnm->peer = *neighbour;
742 GNUNET_MQ_send (client->mq, 693 GNUNET_MQ_send (client->mq, env);
743 env);
744 } 694 }
745 else 695 else
746 { 696 {
747 struct DisconnectNotifyMessage *dcm; 697 struct DisconnectNotifyMessage *dcm;
748 698
749 /* send disconnect */ 699 /* send disconnect */
750 GNUNET_assert (GNUNET_YES == 700 GNUNET_assert (
751 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, 701 GNUNET_YES ==
752 neighbour)); 702 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour));
753 GNUNET_assert (GNUNET_YES == 703 GNUNET_assert (GNUNET_YES ==
754 GNUNET_CONTAINER_multipeermap_remove (client->connectmap, 704 GNUNET_CONTAINER_multipeermap_remove (client->connectmap,
755 neighbour, 705 neighbour,
756 NULL)); 706 NULL));
757 env = GNUNET_MQ_msg (dcm, 707 env = GNUNET_MQ_msg (dcm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
758 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
759 dcm->reserved = htonl (0); 708 dcm->reserved = htonl (0);
760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
761 "Sending NOTIFY_DISCONNECT message about peer %s to client.\n", 710 "Sending NOTIFY_DISCONNECT message about peer %s to client.\n",
762 GNUNET_i2s (neighbour)); 711 GNUNET_i2s (neighbour));
763 dcm->peer = *neighbour; 712 dcm->peer = *neighbour;
764 GNUNET_MQ_send (client->mq, 713 GNUNET_MQ_send (client->mq, env);
765 env);
766 } 714 }
767} 715}
768 716
@@ -777,17 +725,18 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
777 * @param tmap_new updated type map for the neighbour, NULL for disconnect 725 * @param tmap_new updated type map for the neighbour, NULL for disconnect
778 */ 726 */
779void 727void
780GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, 728GSC_CLIENTS_notify_clients_about_neighbour (
781 const struct GSC_TypeMap *tmap_old, 729 const struct GNUNET_PeerIdentity *neighbour,
782 const struct GSC_TypeMap *tmap_new) 730 const struct GSC_TypeMap *tmap_old,
731 const struct GSC_TypeMap *tmap_new)
783{ 732{
784 struct GSC_Client *c; 733 struct GSC_Client *c;
785 734
786 for (c = client_head; NULL != c; c = c->next) 735 for (c = client_head; NULL != c; c = c->next)
787 GSC_CLIENTS_notify_client_about_neighbour (c, 736 GSC_CLIENTS_notify_client_about_neighbour (c,
788 neighbour, 737 neighbour,
789 tmap_old, 738 tmap_old,
790 tmap_new); 739 tmap_new);
791} 740}
792 741
793 742
@@ -815,15 +764,14 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
815 GNUNET_break (0); 764 GNUNET_break (0);
816 return; 765 return;
817 } 766 }
818 if (! ( (0 != (all_client_options & options)) || 767 if (! ((0 != (all_client_options & options)) ||
819 (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) )) 768 (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND))))
820 return; /* no client cares about this message notification */ 769 return; /* no client cares about this message notification */
821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
822 "Core service passes message from `%s' of type %u to client.\n", 771 "Core service passes message from `%s' of type %u to client.\n",
823 GNUNET_i2s (sender), 772 GNUNET_i2s (sender),
824 (unsigned int) ntohs (msg->type)); 773 (unsigned int) ntohs (msg->type));
825 GSC_SESSIONS_add_to_typemap (sender, 774 GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type));
826 ntohs (msg->type));
827 775
828 for (struct GSC_Client *c = client_head; NULL != c; c = c->next) 776 for (struct GSC_Client *c = client_head; NULL != c; c = c->next)
829 { 777 {
@@ -833,18 +781,17 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
833 unsigned int qlen; 781 unsigned int qlen;
834 int tm; 782 int tm;
835 783
836 tm = type_match (ntohs (msg->type), 784 tm = type_match (ntohs (msg->type), c);
837 c); 785 if (! ((0 != (c->options & options)) ||
838 if (! ( (0 != (c->options & options)) || 786 ((0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
839 ( (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && 787 (GNUNET_YES == tm))))
840 (GNUNET_YES == tm) ) ) ) 788 continue; /* neither options nor type match permit the message */
841 continue; /* neither options nor type match permit the message */ 789 if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) &&
842 if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) && 790 ((0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
843 ( (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || 791 (GNUNET_YES == tm)))
844 (GNUNET_YES == tm) ) )
845 continue; 792 continue;
846 if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) && 793 if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) &&
847 (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)) ) 794 (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)))
848 continue; 795 continue;
849 796
850 /* Drop messages if: 797 /* Drop messages if:
@@ -862,54 +809,50 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
862 (ACK, queries) which may be cummulative or highly redundant, 809 (ACK, queries) which may be cummulative or highly redundant,
863 and cheap to drop than data traffic. */ 810 and cheap to drop than data traffic. */
864 qlen = GNUNET_MQ_get_length (c->mq); 811 qlen = GNUNET_MQ_get_length (c->mq);
865 if ( (qlen >= HARD_MAX_QUEUE) || 812 if ((qlen >= HARD_MAX_QUEUE) ||
866 ( (qlen > SOFT_MAX_QUEUE) && 813 ((qlen > SOFT_MAX_QUEUE) &&
867 ( (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 814 ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
868 ntohs (msg->size)) ) < 815 ntohs (msg->size))) <
869 (qlen - SOFT_MAX_QUEUE) * 0x8000 / 816 (qlen - SOFT_MAX_QUEUE) * 0x8000 /
870 (HARD_MAX_QUEUE - SOFT_MAX_QUEUE) ) ) ) 817 (HARD_MAX_QUEUE - SOFT_MAX_QUEUE))))
871 { 818 {
872 char buf[1024]; 819 char buf[1024];
873 820
874 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 821 GNUNET_log (
875 "Dropping decrypted message of type %u as client is too busy (queue full)\n", 822 GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
876 (unsigned int) ntohs (msg->type)); 823 "Dropping decrypted message of type %u as client is too busy (queue full)\n",
824 (unsigned int) ntohs (msg->type));
877 GNUNET_snprintf (buf, 825 GNUNET_snprintf (buf,
878 sizeof (buf), 826 sizeof (buf),
879 gettext_noop ("# messages of type %u discarded (client busy)"), 827 gettext_noop (
828 "# messages of type %u discarded (client busy)"),
880 (unsigned int) ntohs (msg->type)); 829 (unsigned int) ntohs (msg->type));
881 GNUNET_STATISTICS_update (GSC_stats, 830 GNUNET_STATISTICS_update (GSC_stats, buf, 1, GNUNET_NO);
882 buf,
883 1,
884 GNUNET_NO);
885 continue; 831 continue;
886 } 832 }
887 833
888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 834 GNUNET_log (
889 "Sending %u message with %u bytes to client interested in messages of type %u.\n", 835 GNUNET_ERROR_TYPE_DEBUG,
890 options, 836 "Sending %u message with %u bytes to client interested in messages of type %u.\n",
891 ntohs (msg->size), 837 options,
892 (unsigned int) ntohs (msg->type)); 838 ntohs (msg->size),
839 (unsigned int) ntohs (msg->type));
893 840
894 if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_INBOUND))) 841 if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
842 GNUNET_CORE_OPTION_SEND_HDR_INBOUND)))
895 mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND; 843 mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND;
896 else 844 else
897 mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND; 845 mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND;
898 env = GNUNET_MQ_msg_extra (ntm, 846 env = GNUNET_MQ_msg_extra (ntm, msize, mtype);
899 msize,
900 mtype);
901 ntm->peer = *sender; 847 ntm->peer = *sender;
902 GNUNET_memcpy (&ntm[1], 848 GNUNET_memcpy (&ntm[1], msg, msize);
903 msg, 849
904 msize); 850 GNUNET_assert (
905 851 (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
906 GNUNET_assert ( (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || 852 (GNUNET_YES != tm) ||
907 (GNUNET_YES != tm) || 853 (GNUNET_YES ==
908 (GNUNET_YES == 854 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, sender)));
909 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, 855 GNUNET_MQ_send (c->mq, env);
910 sender)) );
911 GNUNET_MQ_send (c->mq,
912 env);
913 } 856 }
914} 857}
915 858
@@ -925,8 +868,7 @@ shutdown_task (void *cls)
925{ 868{
926 struct GSC_Client *c; 869 struct GSC_Client *c;
927 870
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 871 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n");
929 "Core service shutting down.\n");
930 while (NULL != (c = client_head)) 872 while (NULL != (c = client_head))
931 GNUNET_SERVICE_client_drop (c->client); 873 GNUNET_SERVICE_client_drop (c->client);
932 GSC_SESSIONS_done (); 874 GSC_SESSIONS_done ();
@@ -934,8 +876,7 @@ shutdown_task (void *cls)
934 GSC_TYPEMAP_done (); 876 GSC_TYPEMAP_done ();
935 if (NULL != GSC_stats) 877 if (NULL != GSC_stats)
936 { 878 {
937 GNUNET_STATISTICS_destroy (GSC_stats, 879 GNUNET_STATISTICS_destroy (GSC_stats, GNUNET_NO);
938 GNUNET_NO);
939 GSC_stats = NULL; 880 GSC_stats = NULL;
940 } 881 }
941 GSC_cfg = NULL; 882 GSC_cfg = NULL;
@@ -953,7 +894,7 @@ shutdown_task (void *cls)
953 */ 894 */
954static void 895static void
955handle_client_monitor_peers (void *cls, 896handle_client_monitor_peers (void *cls,
956 const struct GNUNET_MessageHeader *message) 897 const struct GNUNET_MessageHeader *message)
957{ 898{
958 struct GSC_Client *c = cls; 899 struct GSC_Client *c = cls;
959 900
@@ -978,21 +919,19 @@ run (void *cls,
978 char *keyfile; 919 char *keyfile;
979 920
980 GSC_cfg = c; 921 GSC_cfg = c;
981 if (GNUNET_OK != 922 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GSC_cfg,
982 GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, 923 "PEER",
983 "PEER", 924 "PRIVATE_KEY",
984 "PRIVATE_KEY", 925 &keyfile))
985 &keyfile))
986 { 926 {
987 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 927 GNUNET_log (
988 _("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); 928 GNUNET_ERROR_TYPE_ERROR,
929 _ ("Core service is lacking HOSTKEY configuration setting. Exiting.\n"));
989 GNUNET_SCHEDULER_shutdown (); 930 GNUNET_SCHEDULER_shutdown ();
990 return; 931 return;
991 } 932 }
992 GSC_stats = GNUNET_STATISTICS_create ("core", 933 GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
993 GSC_cfg); 934 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
994 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
995 NULL);
996 GNUNET_SERVICE_suspend (service); 935 GNUNET_SERVICE_suspend (service);
997 GSC_TYPEMAP_init (); 936 GSC_TYPEMAP_init ();
998 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); 937 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
@@ -1006,7 +945,7 @@ run (void *cls,
1006 GSC_SESSIONS_init (); 945 GSC_SESSIONS_init ();
1007 GNUNET_SERVICE_resume (service); 946 GNUNET_SERVICE_resume (service);
1008 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 947 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1009 _("Core service of `%s' ready.\n"), 948 _ ("Core service of `%s' ready.\n"),
1010 GNUNET_i2s (&GSC_my_identity)); 949 GNUNET_i2s (&GSC_my_identity));
1011} 950}
1012 951
@@ -1014,30 +953,30 @@ run (void *cls,
1014/** 953/**
1015 * Define "main" method using service macro. 954 * Define "main" method using service macro.
1016 */ 955 */
1017GNUNET_SERVICE_MAIN 956GNUNET_SERVICE_MAIN (
1018("core", 957 "core",
1019 GNUNET_SERVICE_OPTION_NONE, 958 GNUNET_SERVICE_OPTION_NONE,
1020 &run, 959 &run,
1021 &client_connect_cb, 960 &client_connect_cb,
1022 &client_disconnect_cb, 961 &client_disconnect_cb,
1023 NULL, 962 NULL,
1024 GNUNET_MQ_hd_var_size (client_init, 963 GNUNET_MQ_hd_var_size (client_init,
1025 GNUNET_MESSAGE_TYPE_CORE_INIT, 964 GNUNET_MESSAGE_TYPE_CORE_INIT,
1026 struct InitMessage, 965 struct InitMessage,
1027 NULL), 966 NULL),
1028 GNUNET_MQ_hd_fixed_size (client_monitor_peers, 967 GNUNET_MQ_hd_fixed_size (client_monitor_peers,
1029 GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS, 968 GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS,
1030 struct GNUNET_MessageHeader, 969 struct GNUNET_MessageHeader,
1031 NULL), 970 NULL),
1032 GNUNET_MQ_hd_fixed_size (client_send_request, 971 GNUNET_MQ_hd_fixed_size (client_send_request,
1033 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST, 972 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST,
1034 struct SendMessageRequest, 973 struct SendMessageRequest,
1035 NULL), 974 NULL),
1036 GNUNET_MQ_hd_var_size (client_send, 975 GNUNET_MQ_hd_var_size (client_send,
1037 GNUNET_MESSAGE_TYPE_CORE_SEND, 976 GNUNET_MESSAGE_TYPE_CORE_SEND,
1038 struct SendMessage, 977 struct SendMessage,
1039 NULL), 978 NULL),
1040 GNUNET_MQ_handler_end ()); 979 GNUNET_MQ_handler_end ());
1041 980
1042 981
1043/* end of gnunet-service-core.c */ 982/* end of gnunet-service-core.c */
diff --git a/src/core/gnunet-service-core.h b/src/core/gnunet-service-core.h
index 00461c5ab..154596933 100644
--- a/src/core/gnunet-service-core.h
+++ b/src/core/gnunet-service-core.h
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -81,7 +81,7 @@ struct GSC_ClientActiveRequest
81 /** 81 /**
82 * How important is this request. 82 * How important is this request.
83 */ 83 */
84 enum GNUNET_CORE_Priority priority; 84 enum GNUNET_MQ_PriorityPreferences priority;
85 85
86 /** 86 /**
87 * Has this request been solicited yet? 87 * Has this request been solicited yet?
@@ -97,7 +97,6 @@ struct GSC_ClientActiveRequest
97 * Unique request ID (in big endian). 97 * Unique request ID (in big endian).
98 */ 98 */
99 uint16_t smr_id; 99 uint16_t smr_id;
100
101}; 100};
102 101
103 102
@@ -140,10 +139,11 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car,
140 * @param tmap_new updated type map for the neighbour, NULL for disconnect 139 * @param tmap_new updated type map for the neighbour, NULL for disconnect
141 */ 140 */
142void 141void
143GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, 142GSC_CLIENTS_notify_client_about_neighbour (
144 const struct GNUNET_PeerIdentity *neighbour, 143 struct GSC_Client *client,
145 const struct GSC_TypeMap *tmap_old, 144 const struct GNUNET_PeerIdentity *neighbour,
146 const struct GSC_TypeMap *tmap_new); 145 const struct GSC_TypeMap *tmap_old,
146 const struct GSC_TypeMap *tmap_new);
147 147
148 148
149/** 149/**
@@ -174,9 +174,10 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
174 * @param tmap_new updated type map for the neighbour, NULL for disconnect 174 * @param tmap_new updated type map for the neighbour, NULL for disconnect
175 */ 175 */
176void 176void
177GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, 177GSC_CLIENTS_notify_clients_about_neighbour (
178 const struct GSC_TypeMap *tmap_old, 178 const struct GNUNET_PeerIdentity *neighbour,
179 const struct GSC_TypeMap *tmap_new); 179 const struct GSC_TypeMap *tmap_old,
180 const struct GSC_TypeMap *tmap_new);
180 181
181 182
182/** 183/**
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index 4f678c784..8ff61ec20 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -59,7 +59,7 @@ struct SessionMessageEntry
59 /** 59 /**
60 * How important is this message. 60 * How important is this message.
61 */ 61 */
62 enum GNUNET_CORE_Priority priority; 62 enum GNUNET_MQ_PriorityPreferences priority;
63 63
64 /** 64 /**
65 * Flag set to #GNUNET_YES if this is a typemap message. 65 * Flag set to #GNUNET_YES if this is a typemap message.
@@ -84,7 +84,6 @@ struct SessionMessageEntry
84 * MessageEntry` itself!) 84 * MessageEntry` itself!)
85 */ 85 */
86 size_t size; 86 size_t size;
87
88}; 87};
89 88
90 89
@@ -177,7 +176,6 @@ struct TypeMapConfirmationMessage
177 * Hash of the (decompressed) type map that was received. 176 * Hash of the (decompressed) type map that was received.
178 */ 177 */
179 struct GNUNET_HashCode tm_hash; 178 struct GNUNET_HashCode tm_hash;
180
181}; 179};
182 180
183GNUNET_NETWORK_STRUCT_END 181GNUNET_NETWORK_STRUCT_END
@@ -201,8 +199,7 @@ find_session (const struct GNUNET_PeerIdentity *peer)
201{ 199{
202 if (NULL == sessions) 200 if (NULL == sessions)
203 return NULL; 201 return NULL;
204 return GNUNET_CONTAINER_multipeermap_get (sessions, 202 return GNUNET_CONTAINER_multipeermap_get (sessions, peer);
205 peer);
206} 203}
207 204
208 205
@@ -233,15 +230,13 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
233 while (NULL != (car = session->active_client_request_head)) 230 while (NULL != (car = session->active_client_request_head))
234 { 231 {
235 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 232 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head,
236 session->active_client_request_tail, car); 233 session->active_client_request_tail,
237 GSC_CLIENTS_reject_request (car, 234 car);
238 GNUNET_NO); 235 GSC_CLIENTS_reject_request (car, GNUNET_NO);
239 } 236 }
240 while (NULL != (sme = session->sme_head)) 237 while (NULL != (sme = session->sme_head))
241 { 238 {
242 GNUNET_CONTAINER_DLL_remove (session->sme_head, 239 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
243 session->sme_tail,
244 sme);
245 GNUNET_free (sme); 240 GNUNET_free (sme);
246 } 241 }
247 if (NULL != session->typemap_task) 242 if (NULL != session->typemap_task)
@@ -251,13 +246,12 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
251 } 246 }
252 GSC_CLIENTS_notify_clients_about_neighbour (session->peer, 247 GSC_CLIENTS_notify_clients_about_neighbour (session->peer,
253 session->tmap, 248 session->tmap,
254 NULL); 249 NULL);
255 GNUNET_assert (GNUNET_YES == 250 GNUNET_assert (
256 GNUNET_CONTAINER_multipeermap_remove (sessions, 251 GNUNET_YES ==
257 session->peer, 252 GNUNET_CONTAINER_multipeermap_remove (sessions, session->peer, session));
258 session));
259 GNUNET_STATISTICS_set (GSC_stats, 253 GNUNET_STATISTICS_set (GSC_stats,
260 gettext_noop ("# peers connected"), 254 gettext_noop ("# peers connected"),
261 GNUNET_CONTAINER_multipeermap_size (sessions), 255 GNUNET_CONTAINER_multipeermap_size (sessions),
262 GNUNET_NO); 256 GNUNET_NO);
263 GSC_TYPEMAP_destroy (session->tmap); 257 GSC_TYPEMAP_destroy (session->tmap);
@@ -286,20 +280,15 @@ transmit_typemap_task (void *cls)
286 delay = session->typemap_delay; 280 delay = session->typemap_delay;
287 /* randomize a bit to avoid spont. sync */ 281 /* randomize a bit to avoid spont. sync */
288 delay.rel_value_us += 282 delay.rel_value_us +=
289 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 283 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000);
290 1000 * 1000);
291 session->typemap_task = 284 session->typemap_task =
292 GNUNET_SCHEDULER_add_delayed (delay, 285 GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session);
293 &transmit_typemap_task,
294 session);
295 GNUNET_STATISTICS_update (GSC_stats, 286 GNUNET_STATISTICS_update (GSC_stats,
296 gettext_noop ("# type map refreshes sent"), 287 gettext_noop ("# type map refreshes sent"),
297 1, 288 1,
298 GNUNET_NO); 289 GNUNET_NO);
299 hdr = GSC_TYPEMAP_compute_type_map_message (); 290 hdr = GSC_TYPEMAP_compute_type_map_message ();
300 GSC_KX_encrypt_and_transmit (session->kx, 291 GSC_KX_encrypt_and_transmit (session->kx, hdr, ntohs (hdr->size));
301 hdr,
302 ntohs (hdr->size));
303 GNUNET_free (hdr); 292 GNUNET_free (hdr);
304} 293}
305 294
@@ -315,10 +304,9 @@ start_typemap_task (struct Session *session)
315 if (NULL != session->typemap_task) 304 if (NULL != session->typemap_task)
316 GNUNET_SCHEDULER_cancel (session->typemap_task); 305 GNUNET_SCHEDULER_cancel (session->typemap_task);
317 session->typemap_delay = GNUNET_TIME_UNIT_SECONDS; 306 session->typemap_delay = GNUNET_TIME_UNIT_SECONDS;
318 session->typemap_task = 307 session->typemap_task = GNUNET_SCHEDULER_add_delayed (session->typemap_delay,
319 GNUNET_SCHEDULER_add_delayed (session->typemap_delay, 308 &transmit_typemap_task,
320 &transmit_typemap_task, 309 session);
321 session);
322} 310}
323 311
324 312
@@ -342,17 +330,16 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
342 session->peer = peer; 330 session->peer = peer;
343 session->kx = kx; 331 session->kx = kx;
344 GNUNET_assert (GNUNET_OK == 332 GNUNET_assert (GNUNET_OK ==
345 GNUNET_CONTAINER_multipeermap_put (sessions, 333 GNUNET_CONTAINER_multipeermap_put (
346 session->peer, 334 sessions,
347 session, 335 session->peer,
348 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 336 session,
337 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
349 GNUNET_STATISTICS_set (GSC_stats, 338 GNUNET_STATISTICS_set (GSC_stats,
350 gettext_noop ("# peers connected"), 339 gettext_noop ("# peers connected"),
351 GNUNET_CONTAINER_multipeermap_size (sessions), 340 GNUNET_CONTAINER_multipeermap_size (sessions),
352 GNUNET_NO); 341 GNUNET_NO);
353 GSC_CLIENTS_notify_clients_about_neighbour (peer, 342 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, session->tmap);
354 NULL,
355 session->tmap);
356 start_typemap_task (session); 343 start_typemap_task (session);
357} 344}
358 345
@@ -406,15 +393,15 @@ GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer,
406 return; 393 return;
407 } 394 }
408 cmsg = (const struct TypeMapConfirmationMessage *) msg; 395 cmsg = (const struct TypeMapConfirmationMessage *) msg;
409 if (GNUNET_YES != 396 if (GNUNET_YES != GSC_TYPEMAP_check_hash (&cmsg->tm_hash))
410 GSC_TYPEMAP_check_hash (&cmsg->tm_hash))
411 { 397 {
412 /* our typemap has changed in the meantime, do not 398 /* our typemap has changed in the meantime, do not
413 accept confirmation */ 399 accept confirmation */
414 GNUNET_STATISTICS_update (GSC_stats, 400 GNUNET_STATISTICS_update (GSC_stats,
415 gettext_noop 401 gettext_noop (
416 ("# outdated typemap confirmations received"), 402 "# outdated typemap confirmations received"),
417 1, GNUNET_NO); 403 1,
404 GNUNET_NO);
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "Got outdated typemap confirmated from peer `%s'\n", 406 "Got outdated typemap confirmated from peer `%s'\n",
420 GNUNET_i2s (session->peer)); 407 GNUNET_i2s (session->peer));
@@ -429,9 +416,10 @@ GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer,
429 session->typemap_task = NULL; 416 session->typemap_task = NULL;
430 } 417 }
431 GNUNET_STATISTICS_update (GSC_stats, 418 GNUNET_STATISTICS_update (GSC_stats,
432 gettext_noop 419 gettext_noop (
433 ("# valid typemap confirmations received"), 420 "# valid typemap confirmations received"),
434 1, GNUNET_NO); 421 1,
422 GNUNET_NO);
435} 423}
436 424
437 425
@@ -453,7 +441,7 @@ notify_client_about_session (void *cls,
453 441
454 GSC_CLIENTS_notify_client_about_neighbour (client, 442 GSC_CLIENTS_notify_client_about_neighbour (client,
455 session->peer, 443 session->peer,
456 NULL, /* old TMAP: none */ 444 NULL, /* old TMAP: none */
457 session->tmap); 445 session->tmap);
458 return GNUNET_OK; 446 return GNUNET_OK;
459} 447}
@@ -503,16 +491,14 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car)
503 { 491 {
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "Dropped client request for transmission (am disconnected)\n"); 493 "Dropped client request for transmission (am disconnected)\n");
506 GNUNET_break (0); /* should have been rejected earlier */ 494 GNUNET_break (0); /* should have been rejected earlier */
507 GSC_CLIENTS_reject_request (car, 495 GSC_CLIENTS_reject_request (car, GNUNET_NO);
508 GNUNET_NO);
509 return; 496 return;
510 } 497 }
511 if (car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 498 if (car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
512 { 499 {
513 GNUNET_break (0); 500 GNUNET_break (0);
514 GSC_CLIENTS_reject_request (car, 501 GSC_CLIENTS_reject_request (car, GNUNET_YES);
515 GNUNET_YES);
516 return; 502 return;
517 } 503 }
518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -535,10 +521,9 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car)
535{ 521{
536 struct Session *session; 522 struct Session *session;
537 523
538 if (0 == 524 if (0 == memcmp (&car->target,
539 memcmp (&car->target, 525 &GSC_my_identity,
540 &GSC_my_identity, 526 sizeof (struct GNUNET_PeerIdentity)))
541 sizeof (struct GNUNET_PeerIdentity)))
542 return; 527 return;
543 session = find_session (&car->target); 528 session = find_session (&car->target);
544 GNUNET_assert (NULL != session); 529 GNUNET_assert (NULL != session);
@@ -560,21 +545,20 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car)
560 * @param msize how many bytes do we have already 545 * @param msize how many bytes do we have already
561 */ 546 */
562static void 547static void
563solicit_messages (struct Session *session, 548solicit_messages (struct Session *session, size_t msize)
564 size_t msize)
565{ 549{
566 struct GSC_ClientActiveRequest *car; 550 struct GSC_ClientActiveRequest *car;
567 struct GSC_ClientActiveRequest *nxt; 551 struct GSC_ClientActiveRequest *nxt;
568 size_t so_size; 552 size_t so_size;
569 enum GNUNET_CORE_Priority pmax; 553 enum GNUNET_MQ_PriorityPreferences pmax;
570 554
571 so_size = msize; 555 so_size = msize;
572 pmax = GNUNET_CORE_PRIO_BACKGROUND; 556 pmax = GNUNET_MQ_PRIO_BACKGROUND;
573 for (car = session->active_client_request_head; NULL != car; car = car->next) 557 for (car = session->active_client_request_head; NULL != car; car = car->next)
574 { 558 {
575 if (GNUNET_YES == car->was_solicited) 559 if (GNUNET_YES == car->was_solicited)
576 continue; 560 continue;
577 pmax = GNUNET_MAX (pmax, car->priority); 561 pmax = GNUNET_MAX (pmax, car->priority & GNUNET_MQ_PRIORITY_MASK);
578 } 562 }
579 nxt = session->active_client_request_head; 563 nxt = session->active_client_request_head;
580 while (NULL != (car = nxt)) 564 while (NULL != (car = nxt))
@@ -631,11 +615,11 @@ try_transmission (struct Session *session)
631 size_t msize; 615 size_t msize;
632 struct GNUNET_TIME_Absolute now; 616 struct GNUNET_TIME_Absolute now;
633 struct GNUNET_TIME_Absolute min_deadline; 617 struct GNUNET_TIME_Absolute min_deadline;
634 enum GNUNET_CORE_Priority maxp; 618 enum GNUNET_MQ_PriorityPreferences maxp;
635 enum GNUNET_CORE_Priority maxpc; 619 enum GNUNET_MQ_PriorityPreferences maxpc;
636 struct GSC_ClientActiveRequest *car; 620 struct GSC_ClientActiveRequest *car;
637 int excess; 621 int excess;
638 622
639 msize = 0; 623 msize = 0;
640 min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS; 624 min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
641 /* if the peer has excess bandwidth, background traffic is allowed, 625 /* if the peer has excess bandwidth, background traffic is allowed,
@@ -649,9 +633,9 @@ try_transmission (struct Session *session)
649 } 633 }
650 excess = GSC_NEIGHBOURS_check_excess_bandwidth (session->kx); 634 excess = GSC_NEIGHBOURS_check_excess_bandwidth (session->kx);
651 if (GNUNET_YES == excess) 635 if (GNUNET_YES == excess)
652 maxp = GNUNET_CORE_PRIO_BACKGROUND; 636 maxp = GNUNET_MQ_PRIO_BACKGROUND;
653 else 637 else
654 maxp = GNUNET_CORE_PRIO_BEST_EFFORT; 638 maxp = GNUNET_MQ_PRIO_BEST_EFFORT;
655 /* determine highest priority of 'ready' messages we already solicited from clients */ 639 /* determine highest priority of 'ready' messages we already solicited from clients */
656 pos = session->sme_head; 640 pos = session->sme_head;
657 while ((NULL != pos) && 641 while ((NULL != pos) &&
@@ -659,32 +643,33 @@ try_transmission (struct Session *session)
659 { 643 {
660 GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); 644 GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
661 msize += pos->size; 645 msize += pos->size;
662 maxp = GNUNET_MAX (maxp, pos->priority); 646 maxp = GNUNET_MAX (maxp, pos->priority & GNUNET_MQ_PRIORITY_MASK);
663 min_deadline = GNUNET_TIME_absolute_min (min_deadline, 647 min_deadline = GNUNET_TIME_absolute_min (min_deadline, pos->deadline);
664 pos->deadline);
665 pos = pos->next; 648 pos = pos->next;
666 } 649 }
667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 650 GNUNET_log (
668 "Calculating transmission set with %u priority (%s) and %s earliest deadline\n", 651 GNUNET_ERROR_TYPE_DEBUG,
669 maxp, 652 "Calculating transmission set with %u priority (%s) and %s earliest deadline\n",
670 (GNUNET_YES == excess) ? "excess bandwidth" : "limited bandwidth", 653 maxp,
671 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (min_deadline), 654 (GNUNET_YES == excess) ? "excess bandwidth" : "limited bandwidth",
672 GNUNET_YES)); 655 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
673 656 min_deadline),
674 if (maxp < GNUNET_CORE_PRIO_CRITICAL_CONTROL) 657 GNUNET_YES));
658
659 if (maxp < GNUNET_MQ_PRIO_CRITICAL_CONTROL)
675 { 660 {
676 /* if highest already solicited priority from clients is not critical, 661 /* if highest already solicited priority from clients is not critical,
677 check if there are higher-priority messages to be solicited from clients */ 662 check if there are higher-priority messages to be solicited from clients */
678 if (GNUNET_YES == excess) 663 if (GNUNET_YES == excess)
679 maxpc = GNUNET_CORE_PRIO_BACKGROUND; 664 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
680 else 665 else
681 maxpc = GNUNET_CORE_PRIO_BEST_EFFORT; 666 maxpc = GNUNET_MQ_PRIO_BEST_EFFORT;
682 for (car = session->active_client_request_head; NULL != car; car = car->next) 667 for (car = session->active_client_request_head; NULL != car;
668 car = car->next)
683 { 669 {
684 if (GNUNET_YES == car->was_solicited) 670 if (GNUNET_YES == car->was_solicited)
685 continue; 671 continue;
686 maxpc = GNUNET_MAX (maxpc, 672 maxpc = GNUNET_MAX (maxpc, car->priority & GNUNET_MQ_PRIORITY_MASK);
687 car->priority);
688 } 673 }
689 if (maxpc > maxp) 674 if (maxpc > maxp)
690 { 675 {
@@ -703,41 +688,40 @@ try_transmission (struct Session *session)
703 { 688 {
704 /* never solicit more, we have critical messages to process */ 689 /* never solicit more, we have critical messages to process */
705 excess = GNUNET_NO; 690 excess = GNUNET_NO;
706 maxpc = GNUNET_CORE_PRIO_BACKGROUND; 691 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
707 } 692 }
708 now = GNUNET_TIME_absolute_get (); 693 now = GNUNET_TIME_absolute_get ();
709 if ( ( (GNUNET_YES == excess) || 694 if (((GNUNET_YES == excess) || (maxpc >= GNUNET_MQ_PRIO_BEST_EFFORT)) &&
710 (maxpc >= GNUNET_CORE_PRIO_BEST_EFFORT) ) && 695 ((0 == msize) ||
711 ( (0 == msize) || 696 ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
712 ( (msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) && 697 (min_deadline.abs_value_us > now.abs_value_us))))
713 (min_deadline.abs_value_us > now.abs_value_us))) )
714 { 698 {
715 /* not enough ready yet (tiny message & cork possible), or no messages at all, 699 /* not enough ready yet (tiny message & cork possible), or no messages at all,
716 and either excess bandwidth or best-effort or higher message waiting at 700 and either excess bandwidth or best-effort or higher message waiting at
717 client; in this case, we try to solicit more */ 701 client; in this case, we try to solicit more */
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 702 GNUNET_log (
719 "Soliciting messages (excess %d, maxpc %d, message size %u, deadline %s)\n", 703 GNUNET_ERROR_TYPE_DEBUG,
720 excess, 704 "Soliciting messages (excess %d, maxpc %d, message size %u, deadline %s)\n",
721 maxpc, 705 excess,
722 (unsigned int) msize, 706 maxpc,
723 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (min_deadline), 707 (unsigned int) msize,
724 GNUNET_YES)); 708 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
725 solicit_messages (session, 709 min_deadline),
726 msize); 710 GNUNET_YES));
711 solicit_messages (session, msize);
727 if (msize > 0) 712 if (msize > 0)
728 { 713 {
729 /* if there is data to send, just not yet, make sure we do transmit 714 /* if there is data to send, just not yet, make sure we do transmit
730 * it once the deadline is reached */ 715 * it once the deadline is reached */
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732 "Corking until %s\n", 717 "Corking until %s\n",
733 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (min_deadline), 718 GNUNET_STRINGS_relative_time_to_string (
734 GNUNET_YES)); 719 GNUNET_TIME_absolute_get_remaining (min_deadline),
720 GNUNET_YES));
735 if (NULL != session->cork_task) 721 if (NULL != session->cork_task)
736 GNUNET_SCHEDULER_cancel (session->cork_task); 722 GNUNET_SCHEDULER_cancel (session->cork_task);
737 session->cork_task 723 session->cork_task =
738 = GNUNET_SCHEDULER_add_at (min_deadline, 724 GNUNET_SCHEDULER_add_at (min_deadline, &pop_cork_task, session);
739 &pop_cork_task,
740 session);
741 } 725 }
742 else 726 else
743 { 727 {
@@ -753,26 +737,21 @@ try_transmission (struct Session *session)
753 { 737 {
754 static unsigned long long total_bytes; 738 static unsigned long long total_bytes;
755 static unsigned int total_msgs; 739 static unsigned int total_msgs;
756 char pbuf[msize]; /* plaintext */ 740 char pbuf[msize]; /* plaintext */
757 size_t used; 741 size_t used;
758 742
759 used = 0; 743 used = 0;
760 while ( (NULL != (pos = session->sme_head)) && 744 while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize))
761 (used + pos->size <= msize) )
762 { 745 {
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
764 "Adding message of type %d (%d/%d) to payload for %s\n", 747 "Adding message of type %d (%d/%d) to payload for %s\n",
765 ntohs (((const struct GNUNET_MessageHeader *)&pos[1])->type), 748 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type),
766 pos->is_typemap, 749 pos->is_typemap,
767 pos->is_typemap_confirm, 750 pos->is_typemap_confirm,
768 GNUNET_i2s (session->peer)); 751 GNUNET_i2s (session->peer));
769 GNUNET_memcpy (&pbuf[used], 752 GNUNET_memcpy (&pbuf[used], &pos[1], pos->size);
770 &pos[1],
771 pos->size);
772 used += pos->size; 753 used += pos->size;
773 GNUNET_CONTAINER_DLL_remove (session->sme_head, 754 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, pos);
774 session->sme_tail,
775 pos);
776 GNUNET_free (pos); 755 GNUNET_free (pos);
777 } 756 }
778 /* compute average payload size */ 757 /* compute average payload size */
@@ -789,9 +768,7 @@ try_transmission (struct Session *session)
789 total_bytes / total_msgs, 768 total_bytes / total_msgs,
790 GNUNET_NO); 769 GNUNET_NO);
791 /* now actually transmit... */ 770 /* now actually transmit... */
792 GSC_KX_encrypt_and_transmit (session->kx, 771 GSC_KX_encrypt_and_transmit (session->kx, pbuf, used);
793 pbuf,
794 used);
795 } 772 }
796} 773}
797 774
@@ -823,23 +800,17 @@ do_restart_typemap_message (void *cls,
823 { 800 {
824 if (GNUNET_YES == sme->is_typemap) 801 if (GNUNET_YES == sme->is_typemap)
825 { 802 {
826 GNUNET_CONTAINER_DLL_remove (session->sme_head, 803 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
827 session->sme_tail,
828 sme);
829 GNUNET_free (sme); 804 GNUNET_free (sme);
830 break; 805 break;
831 } 806 }
832 } 807 }
833 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size); 808 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size);
834 sme->is_typemap = GNUNET_YES; 809 sme->is_typemap = GNUNET_YES;
835 GNUNET_memcpy (&sme[1], 810 GNUNET_memcpy (&sme[1], hdr, size);
836 hdr,
837 size);
838 sme->size = size; 811 sme->size = size;
839 sme->priority = GNUNET_CORE_PRIO_CRITICAL_CONTROL; 812 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL;
840 GNUNET_CONTAINER_DLL_insert (session->sme_head, 813 GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme);
841 session->sme_tail,
842 sme);
843 try_transmission (session); 814 try_transmission (session);
844 start_typemap_task (session); 815 start_typemap_task (session);
845 return GNUNET_OK; 816 return GNUNET_OK;
@@ -876,8 +847,8 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
876 struct Session *session; 847 struct Session *session;
877 848
878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
879 "Transport solicits for %s\n", 850 "Transport solicits for %s\n",
880 GNUNET_i2s (pid)); 851 GNUNET_i2s (pid));
881 session = find_session (pid); 852 session = find_session (pid);
882 if (NULL == session) 853 if (NULL == session)
883 return; 854 return;
@@ -891,14 +862,12 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
891 * @param car original request that was queued and then solicited; 862 * @param car original request that was queued and then solicited;
892 * this handle will now be 'owned' by the SESSIONS subsystem 863 * this handle will now be 'owned' by the SESSIONS subsystem
893 * @param msg message to transmit 864 * @param msg message to transmit
894 * @param cork is corking allowed?
895 * @param priority how important is this message 865 * @param priority how important is this message
896 */ 866 */
897void 867void
898GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 868GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
899 const struct GNUNET_MessageHeader *msg, 869 const struct GNUNET_MessageHeader *msg,
900 int cork, 870 enum GNUNET_MQ_PriorityPreferences priority)
901 enum GNUNET_CORE_Priority priority)
902{ 871{
903 struct Session *session; 872 struct Session *session;
904 struct SessionMessageEntry *sme; 873 struct SessionMessageEntry *sme;
@@ -910,21 +879,18 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
910 return; 879 return;
911 msize = ntohs (msg->size); 880 msize = ntohs (msg->size);
912 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + msize); 881 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + msize);
913 GNUNET_memcpy (&sme[1], 882 GNUNET_memcpy (&sme[1], msg, msize);
914 msg,
915 msize);
916 sme->size = msize; 883 sme->size = msize;
917 sme->priority = priority; 884 sme->priority = priority;
918 if (GNUNET_YES == cork) 885 if (0 != (GNUNET_MQ_PREF_CORK_ALLOWED & priority))
919 { 886 {
920 sme->deadline = 887 sme->deadline =
921 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY); 888 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY);
922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
923 "Mesage corked, delaying transmission\n"); 890 "Mesage corked, delaying transmission\n");
924 } 891 }
925 pos = session->sme_head; 892 pos = session->sme_head;
926 while ( (NULL != pos) && 893 while ((NULL != pos) && (pos->priority >= sme->priority))
927 (pos->priority >= sme->priority) )
928 pos = pos->next; 894 pos = pos->next;
929 if (NULL == pos) 895 if (NULL == pos)
930 GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, 896 GNUNET_CONTAINER_DLL_insert_tail (session->sme_head,
@@ -959,7 +925,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
959 if (NULL == nmap) 925 if (NULL == nmap)
960 { 926 {
961 GNUNET_break_op (0); 927 GNUNET_break_op (0);
962 return; /* malformed */ 928 return; /* malformed */
963 } 929 }
964 session = find_session (peer); 930 session = find_session (peer);
965 if (NULL == session) 931 if (NULL == session)
@@ -975,9 +941,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
975 { 941 {
976 if (GNUNET_YES == sme->is_typemap_confirm) 942 if (GNUNET_YES == sme->is_typemap_confirm)
977 { 943 {
978 GNUNET_CONTAINER_DLL_remove (session->sme_head, 944 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
979 session->sme_tail,
980 sme);
981 GNUNET_free (sme); 945 GNUNET_free (sme);
982 break; 946 break;
983 } 947 }
@@ -986,21 +950,16 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
986 sizeof (struct TypeMapConfirmationMessage)); 950 sizeof (struct TypeMapConfirmationMessage));
987 sme->deadline = GNUNET_TIME_absolute_get (); 951 sme->deadline = GNUNET_TIME_absolute_get ();
988 sme->size = sizeof (struct TypeMapConfirmationMessage); 952 sme->size = sizeof (struct TypeMapConfirmationMessage);
989 sme->priority = GNUNET_CORE_PRIO_CRITICAL_CONTROL; 953 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL;
990 sme->is_typemap_confirm = GNUNET_YES; 954 sme->is_typemap_confirm = GNUNET_YES;
991 tmc = (struct TypeMapConfirmationMessage *) &sme[1]; 955 tmc = (struct TypeMapConfirmationMessage *) &sme[1];
992 tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage)); 956 tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage));
993 tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP); 957 tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP);
994 tmc->reserved = htonl (0); 958 tmc->reserved = htonl (0);
995 GSC_TYPEMAP_hash (nmap, 959 GSC_TYPEMAP_hash (nmap, &tmc->tm_hash);
996 &tmc->tm_hash); 960 GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme);
997 GNUNET_CONTAINER_DLL_insert (session->sme_head,
998 session->sme_tail,
999 sme);
1000 try_transmission (session); 961 try_transmission (session);
1001 GSC_CLIENTS_notify_clients_about_neighbour (peer, 962 GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap);
1002 session->tmap,
1003 nmap);
1004 GSC_TYPEMAP_destroy (session->tmap); 963 GSC_TYPEMAP_destroy (session->tmap);
1005 session->tmap = nmap; 964 session->tmap = nmap;
1006} 965}
@@ -1021,21 +980,14 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
1021 struct Session *session; 980 struct Session *session;
1022 struct GSC_TypeMap *nmap; 981 struct GSC_TypeMap *nmap;
1023 982
1024 if (0 == memcmp (peer, 983 if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
1025 &GSC_my_identity,
1026 sizeof (struct GNUNET_PeerIdentity)))
1027 return; 984 return;
1028 session = find_session (peer); 985 session = find_session (peer);
1029 GNUNET_assert (NULL != session); 986 GNUNET_assert (NULL != session);
1030 if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, 987 if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1))
1031 &type, 1)) 988 return; /* already in it */
1032 return; /* already in it */ 989 nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1);
1033 nmap = GSC_TYPEMAP_extend (session->tmap, 990 GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap);
1034 &type,
1035 1);
1036 GSC_CLIENTS_notify_clients_about_neighbour (peer,
1037 session->tmap,
1038 nmap);
1039 GSC_TYPEMAP_destroy (session->tmap); 991 GSC_TYPEMAP_destroy (session->tmap);
1040 session->tmap = nmap; 992 session->tmap = nmap;
1041} 993}
@@ -1047,8 +999,7 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
1047void 999void
1048GSC_SESSIONS_init () 1000GSC_SESSIONS_init ()
1049{ 1001{
1050 sessions = GNUNET_CONTAINER_multipeermap_create (128, 1002 sessions = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
1051 GNUNET_YES);
1052} 1003}
1053 1004
1054 1005
@@ -1083,7 +1034,7 @@ GSC_SESSIONS_done ()
1083 { 1034 {
1084 GNUNET_CONTAINER_multipeermap_iterate (sessions, 1035 GNUNET_CONTAINER_multipeermap_iterate (sessions,
1085 &free_session_helper, 1036 &free_session_helper,
1086 NULL); 1037 NULL);
1087 GNUNET_CONTAINER_multipeermap_destroy (sessions); 1038 GNUNET_CONTAINER_multipeermap_destroy (sessions);
1088 sessions = NULL; 1039 sessions = NULL;
1089 } 1040 }
diff --git a/src/core/gnunet-service-core_sessions.h b/src/core/gnunet-service-core_sessions.h
index 9f5070d57..e92ce0962 100644
--- a/src/core/gnunet-service-core_sessions.h
+++ b/src/core/gnunet-service-core_sessions.h
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -114,14 +114,12 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car);
114 * @param car original request that was queued and then solicited, 114 * @param car original request that was queued and then solicited,
115 * ownership does not change (dequeue will be called soon). 115 * ownership does not change (dequeue will be called soon).
116 * @param msg message to transmit 116 * @param msg message to transmit
117 * @param cork is corking allowed?
118 * @param priority how important is this message 117 * @param priority how important is this message
119 */ 118 */
120void 119void
121GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 120GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
122 const struct GNUNET_MessageHeader *msg, 121 const struct GNUNET_MessageHeader *msg,
123 int cork, 122 enum GNUNET_MQ_PriorityPreferences priority);
124 enum GNUNET_CORE_Priority priority);
125 123
126 124
127/** 125/**
@@ -182,5 +180,4 @@ void
182GSC_SESSIONS_done (void); 180GSC_SESSIONS_done (void);
183 181
184 182
185
186#endif 183#endif
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index 0cf88a324..1e268c3a6 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -54,7 +54,16 @@ static struct GNUNET_SCHEDULER_Task *err_task;
54 54
55static int ok; 55static int ok;
56 56
57#define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 57#define OKPP \
58 do \
59 { \
60 ok++; \
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, \
62 "Now at stage %u at %s:%u\n", \
63 ok, \
64 __FILE__, \
65 __LINE__); \
66 } while (0)
58 67
59 68
60static void 69static void
@@ -67,8 +76,7 @@ offer_hello_done (void *cls)
67 76
68 77
69static void 78static void
70process_hello (void *cls, 79process_hello (void *cls, const struct GNUNET_MessageHeader *message)
71 const struct GNUNET_MessageHeader *message)
72{ 80{
73 struct PeerContext *p = cls; 81 struct PeerContext *p = cls;
74 82
@@ -76,14 +84,11 @@ process_hello (void *cls,
76 "Received (my) HELLO from transport service\n"); 84 "Received (my) HELLO from transport service\n");
77 GNUNET_assert (message != NULL); 85 GNUNET_assert (message != NULL);
78 if ((p == &p1) && (NULL == p2.oh)) 86 if ((p == &p1) && (NULL == p2.oh))
79 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message, 87 p2.oh =
80 &offer_hello_done, 88 GNUNET_TRANSPORT_offer_hello (p2.cfg, message, &offer_hello_done, &p2);
81 &p2);
82 if ((p == &p2) && (NULL == p1.oh)) 89 if ((p == &p2) && (NULL == p1.oh))
83 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, 90 p1.oh =
84 message, 91 GNUNET_TRANSPORT_offer_hello (p1.cfg, message, &offer_hello_done, &p1);
85 &offer_hello_done,
86 &p1);
87} 92}
88 93
89 94
@@ -131,9 +136,7 @@ terminate_task (void *cls)
131static void 136static void
132terminate_task_error (void *cls) 137terminate_task_error (void *cls)
133{ 138{
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ENDING ANGRILY %u\n", ok);
135 "ENDING ANGRILY %u\n",
136 ok);
137 GNUNET_break (0); 140 GNUNET_break (0);
138 terminate_peer (&p1); 141 terminate_peer (&p1);
139 terminate_peer (&p2); 142 terminate_peer (&p2);
@@ -144,15 +147,13 @@ terminate_task_error (void *cls)
144static void * 147static void *
145connect_notify (void *cls, 148connect_notify (void *cls,
146 const struct GNUNET_PeerIdentity *peer, 149 const struct GNUNET_PeerIdentity *peer,
147 struct GNUNET_MQ_Handle *mq) 150 struct GNUNET_MQ_Handle *mq)
148{ 151{
149 struct PeerContext *pc = cls; 152 struct PeerContext *pc = cls;
150 struct GNUNET_MQ_Envelope *env; 153 struct GNUNET_MQ_Envelope *env;
151 struct GNUNET_MessageHeader *msg; 154 struct GNUNET_MessageHeader *msg;
152 155
153 if (0 == memcmp (&pc->id, 156 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
154 peer,
155 sizeof (struct GNUNET_PeerIdentity)))
156 return (void *) peer; 157 return (void *) peer;
157 GNUNET_assert (pc->connect_status == 0); 158 GNUNET_assert (pc->connect_status == 0);
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -161,26 +162,18 @@ connect_notify (void *cls,
161 pc->connect_status = 1; 162 pc->connect_status = 1;
162 if (pc == &p1) 163 if (pc == &p1)
163 { 164 {
164 uint64_t flags;
165 const void *extra;
166
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
168 "Asking core (1) for transmission to peer `%s'\n", 166 "Asking core (1) for transmission to peer `%s'\n",
169 GNUNET_i2s (&p2.id)); 167 GNUNET_i2s (&p2.id));
170 env = GNUNET_MQ_msg (msg, 168 env = GNUNET_MQ_msg (msg, MTYPE);
171 MTYPE);
172 /* enable corking for this test */ 169 /* enable corking for this test */
173 extra = GNUNET_CORE_get_mq_options (GNUNET_YES,
174 GNUNET_CORE_PRIO_BEST_EFFORT,
175 &flags);
176 GNUNET_MQ_env_set_options (env, 170 GNUNET_MQ_env_set_options (env,
177 flags, 171 GNUNET_MQ_PRIO_BEST_EFFORT |
178 extra); 172 GNUNET_MQ_PREF_CORK_ALLOWED);
179 /* now actually transmit message */ 173 /* now actually transmit message */
180 GNUNET_assert (ok == 4); 174 GNUNET_assert (ok == 4);
181 OKPP; 175 OKPP;
182 GNUNET_MQ_send (mq, 176 GNUNET_MQ_send (mq, env);
183 env);
184 } 177 }
185 return (void *) peer; 178 return (void *) peer;
186} 179}
@@ -188,25 +181,22 @@ connect_notify (void *cls,
188 181
189static void 182static void
190disconnect_notify (void *cls, 183disconnect_notify (void *cls,
191 const struct GNUNET_PeerIdentity *peer, 184 const struct GNUNET_PeerIdentity *peer,
192 void *internal_cls) 185 void *internal_cls)
193{ 186{
194 struct PeerContext *pc = cls; 187 struct PeerContext *pc = cls;
195 188
196 if (0 == memcmp (&pc->id, 189 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
197 peer,
198 sizeof (struct GNUNET_PeerIdentity)))
199 return; 190 return;
200 pc->connect_status = 0; 191 pc->connect_status = 0;
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
202 "Encrypted connection to `%s' cut\n", 193 "Encrypted connection to `%s' cut\n",
203 GNUNET_i2s (peer)); 194 GNUNET_i2s (peer));
204} 195}
205 196
206 197
207static void 198static void
208handle_test (void *cls, 199handle_test (void *cls, const struct GNUNET_MessageHeader *message)
209 const struct GNUNET_MessageHeader *message)
210{ 200{
211 const struct GNUNET_PeerIdentity *peer = cls; 201 const struct GNUNET_PeerIdentity *peer = cls;
212 202
@@ -216,23 +206,17 @@ handle_test (void *cls,
216 GNUNET_assert (ok == 5); 206 GNUNET_assert (ok == 5);
217 OKPP; 207 OKPP;
218 GNUNET_SCHEDULER_cancel (err_task); 208 GNUNET_SCHEDULER_cancel (err_task);
219 err_task = GNUNET_SCHEDULER_add_now (&terminate_task, 209 err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
220 NULL);
221} 210}
222 211
223 212
224static void 213static void
225init_notify (void *cls, 214init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity)
226 const struct GNUNET_PeerIdentity *my_identity)
227{ 215{
228 struct PeerContext *p = cls; 216 struct PeerContext *p = cls;
229 struct GNUNET_MQ_MessageHandler handlers[] = { 217 struct GNUNET_MQ_MessageHandler handlers[] =
230 GNUNET_MQ_hd_fixed_size (test, 218 {GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL),
231 MTYPE, 219 GNUNET_MQ_handler_end ()};
232 struct GNUNET_MessageHeader,
233 NULL),
234 GNUNET_MQ_handler_end ()
235 };
236 220
237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
238 "Core connection to `%s' established\n", 222 "Core connection to `%s' established\n",
@@ -244,50 +228,46 @@ init_notify (void *cls,
244 OKPP; 228 OKPP;
245 /* connect p2 */ 229 /* connect p2 */
246 p2.ch = GNUNET_CORE_connect (p2.cfg, 230 p2.ch = GNUNET_CORE_connect (p2.cfg,
247 &p2, 231 &p2,
248 &init_notify, 232 &init_notify,
249 &connect_notify, 233 &connect_notify,
250 &disconnect_notify, 234 &disconnect_notify,
251 handlers); 235 handlers);
252 } 236 }
253 else 237 else
254 { 238 {
255 GNUNET_assert (ok == 3); 239 GNUNET_assert (ok == 3);
256 OKPP; 240 OKPP;
257 GNUNET_assert (cls == &p2); 241 GNUNET_assert (cls == &p2);
258 p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, 242 p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, &p2.id, 1);
259 &p2.id,
260 1);
261 } 243 }
262} 244}
263 245
264 246
265static void 247static void
266setup_peer (struct PeerContext *p, 248setup_peer (struct PeerContext *p, const char *cfgname)
267 const char *cfgname)
268{ 249{
269 char *binary; 250 char *binary;
270 251
271 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 252 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
272 p->cfg = GNUNET_CONFIGURATION_create (); 253 p->cfg = GNUNET_CONFIGURATION_create ();
273 p->arm_proc = 254 p->arm_proc = GNUNET_OS_start_process (GNUNET_YES,
274 GNUNET_OS_start_process (GNUNET_YES, 255 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
275 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 256 NULL,
276 NULL, NULL, NULL, 257 NULL,
277 binary, 258 NULL,
278 "gnunet-service-arm", 259 binary,
279 "-c", 260 "gnunet-service-arm",
280 cfgname, 261 "-c",
281 NULL); 262 cfgname,
282 GNUNET_assert (GNUNET_OK == 263 NULL);
283 GNUNET_CONFIGURATION_load (p->cfg, 264 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
284 cfgname));
285 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 265 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
286 GNUNET_assert (NULL != p->ats); 266 GNUNET_assert (NULL != p->ats);
287 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 267 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
288 GNUNET_TRANSPORT_AC_ANY, 268 GNUNET_TRANSPORT_AC_ANY,
289 &process_hello, 269 &process_hello,
290 p); 270 p);
291 GNUNET_free (binary); 271 GNUNET_free (binary);
292} 272}
293 273
@@ -298,47 +278,36 @@ run (void *cls,
298 const char *cfgfile, 278 const char *cfgfile,
299 const struct GNUNET_CONFIGURATION_Handle *cfg) 279 const struct GNUNET_CONFIGURATION_Handle *cfg)
300{ 280{
301 struct GNUNET_MQ_MessageHandler handlers[] = { 281 struct GNUNET_MQ_MessageHandler handlers[] =
302 GNUNET_MQ_hd_fixed_size (test, 282 {GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL),
303 MTYPE, 283 GNUNET_MQ_handler_end ()};
304 struct GNUNET_MessageHeader,
305 NULL),
306 GNUNET_MQ_handler_end ()
307 };
308 284
309 GNUNET_assert (ok == 1); 285 GNUNET_assert (ok == 1);
310 OKPP; 286 OKPP;
311 setup_peer (&p1, 287 setup_peer (&p1, "test_core_api_peer1.conf");
312 "test_core_api_peer1.conf"); 288 setup_peer (&p2, "test_core_api_peer2.conf");
313 setup_peer (&p2, 289 err_task = GNUNET_SCHEDULER_add_delayed (
314 "test_core_api_peer2.conf"); 290 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300),
315 err_task = 291 &terminate_task_error,
316 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 292 NULL);
317 (GNUNET_TIME_UNIT_SECONDS, 300), 293 p1.ch = GNUNET_CORE_connect (p1.cfg,
318 &terminate_task_error, NULL); 294 &p1,
319 p1.ch = 295 &init_notify,
320 GNUNET_CORE_connect (p1.cfg, 296 &connect_notify,
321 &p1, 297 &disconnect_notify,
322 &init_notify, 298 handlers);
323 &connect_notify,
324 &disconnect_notify,
325 handlers);
326} 299}
327 300
328 301
329static void 302static void
330stop_arm (struct PeerContext *p) 303stop_arm (struct PeerContext *p)
331{ 304{
332 if (0 != GNUNET_OS_process_kill (p->arm_proc, 305 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
333 GNUNET_TERM_SIG)) 306 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
334 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 307 if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc))
335 "kill"); 308 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
336 if (GNUNET_OK !=
337 GNUNET_OS_process_wait (p->arm_proc))
338 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
339 "waitpid");
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "ARM process %u stopped\n", 310 "ARM process %u stopped\n",
342 GNUNET_OS_process_get_pid (p->arm_proc)); 311 GNUNET_OS_process_get_pid (p->arm_proc));
343 GNUNET_OS_process_destroy (p->arm_proc); 312 GNUNET_OS_process_destroy (p->arm_proc);
344 p->arm_proc = NULL; 313 p->arm_proc = NULL;
@@ -347,29 +316,19 @@ stop_arm (struct PeerContext *p)
347 316
348 317
349int 318int
350main (int argc, 319main (int argc, char *argv1[])
351 char *argv1[])
352{ 320{
353 char *const argv[] = { 321 char *const argv[] = {"test-core-api", "-c", "test_core_api_data.conf", NULL};
354 "test-core-api", 322 struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END};
355 "-c",
356 "test_core_api_data.conf",
357 NULL
358 };
359 struct GNUNET_GETOPT_CommandLineOption options[] = {
360 GNUNET_GETOPT_OPTION_END
361 };
362 ok = 1; 323 ok = 1;
363 GNUNET_log_setup ("test-core-api", 324 GNUNET_log_setup ("test-core-api", "WARNING", NULL);
364 "WARNING",
365 NULL);
366 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 325 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
367 argv, 326 argv,
368 "test-core-api", 327 "test-core-api",
369 "nohelp", 328 "nohelp",
370 options, 329 options,
371 &run, 330 &run,
372 &ok); 331 &ok);
373 stop_arm (&p1); 332 stop_arm (&p1);
374 stop_arm (&p2); 333 stop_arm (&p2);
375 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); 334 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");