aboutsummaryrefslogtreecommitdiff
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
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
-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
-rw-r--r--src/hostlist/gnunet-daemon-hostlist_server.c268
-rw-r--r--src/include/gnunet_core_service.h90
-rw-r--r--src/include/gnunet_mq_lib.h288
-rw-r--r--src/nse/gnunet-service-nse.c627
-rw-r--r--src/topology/gnunet-daemon-topology.c377
-rw-r--r--src/transport/gnunet-service-tng.c3
-rw-r--r--src/transport/transport.h4
-rw-r--r--src/transport/transport_api2_core.c7
-rw-r--r--src/transport/transport_api_core.c7
-rw-r--r--src/util/mq.c277
17 files changed, 1413 insertions, 1881 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");
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c
index 529fe4e62..8764586d6 100644
--- a/src/hostlist/gnunet-daemon-hostlist_server.c
+++ b/src/hostlist/gnunet-daemon-hostlist_server.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
@@ -38,7 +38,8 @@
38 * How long until our hostlist advertisment transmission via CORE should 38 * How long until our hostlist advertisment transmission via CORE should
39 * time out? 39 * time out?
40 */ 40 */
41#define GNUNET_ADV_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 41#define GNUNET_ADV_TIMEOUT \
42 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
42 43
43 44
44/** 45/**
@@ -121,7 +122,6 @@ struct HostSet
121 * Number of bytes in @e data. 122 * Number of bytes in @e data.
122 */ 123 */
123 unsigned int size; 124 unsigned int size;
124
125}; 125};
126 126
127 127
@@ -140,15 +140,11 @@ static struct HostSet *builder;
140static void 140static void
141add_cors_headers (struct MHD_Response *response) 141add_cors_headers (struct MHD_Response *response)
142{ 142{
143 MHD_add_response_header (response, 143 MHD_add_response_header (response, "Access-Control-Allow-Origin", "*");
144 "Access-Control-Allow-Origin",
145 "*");
146 MHD_add_response_header (response, 144 MHD_add_response_header (response,
147 "Access-Control-Allow-Methods", 145 "Access-Control-Allow-Methods",
148 "GET, OPTIONS"); 146 "GET, OPTIONS");
149 MHD_add_response_header (response, 147 MHD_add_response_header (response, "Access-Control-Max-Age", "86400");
150 "Access-Control-Max-Age",
151 "86400");
152} 148}
153 149
154 150
@@ -163,18 +159,19 @@ finish_response ()
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Creating hostlist response with %u bytes\n", 160 "Creating hostlist response with %u bytes\n",
165 (unsigned int) builder->size); 161 (unsigned int) builder->size);
166 response = 162 response = MHD_create_response_from_buffer (builder->size,
167 MHD_create_response_from_buffer (builder->size, 163 builder->data,
168 builder->data, 164 MHD_RESPMEM_MUST_FREE);
169 MHD_RESPMEM_MUST_FREE);
170 add_cors_headers (response); 165 add_cors_headers (response);
171 if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) 166 if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6))
172 { 167 {
173 MHD_destroy_response (response); 168 MHD_destroy_response (response);
174 response = NULL; 169 response = NULL;
175 } 170 }
176 GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"), 171 GNUNET_STATISTICS_set (stats,
177 builder->size, GNUNET_YES); 172 gettext_noop ("bytes in hostlist"),
173 builder->size,
174 GNUNET_YES);
178 GNUNET_free (builder); 175 GNUNET_free (builder);
179 builder = NULL; 176 builder = NULL;
180} 177}
@@ -198,9 +195,10 @@ check_has_addr (void *cls,
198 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) 195 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
199 { 196 {
200 GNUNET_STATISTICS_update (stats, 197 GNUNET_STATISTICS_update (stats,
201 gettext_noop ("expired addresses encountered"), 1, 198 gettext_noop ("expired addresses encountered"),
199 1,
202 GNUNET_YES); 200 GNUNET_YES);
203 return GNUNET_YES; /* ignore this address */ 201 return GNUNET_YES; /* ignore this address */
204 } 202 }
205 *arg = GNUNET_YES; 203 *arg = GNUNET_YES;
206 return GNUNET_SYSERR; 204 return GNUNET_SYSERR;
@@ -234,7 +232,7 @@ host_processor (void *cls,
234 GNUNET_free (builder); 232 GNUNET_free (builder);
235 builder = NULL; 233 builder = NULL;
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 234 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
237 _("Error in communication with PEERINFO service: %s\n"), 235 _ ("Error in communication with PEERINFO service: %s\n"),
238 err_msg); 236 err_msg);
239 return; 237 return;
240 } 238 }
@@ -247,19 +245,17 @@ host_processor (void *cls,
247 if (NULL == hello) 245 if (NULL == hello)
248 return; 246 return;
249 has_addr = GNUNET_NO; 247 has_addr = GNUNET_NO;
250 GNUNET_HELLO_iterate_addresses (hello, 248 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_has_addr, &has_addr);
251 GNUNET_NO,
252 &check_has_addr,
253 &has_addr);
254 if (GNUNET_NO == has_addr) 249 if (GNUNET_NO == has_addr)
255 { 250 {
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
257 "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", 252 "HELLO for peer `%4s' has no address, not suitable for hostlist!\n",
258 GNUNET_i2s (peer)); 253 GNUNET_i2s (peer));
259 GNUNET_STATISTICS_update (stats, 254 GNUNET_STATISTICS_update (stats,
260 gettext_noop 255 gettext_noop (
261 ("HELLOs without addresses encountered (ignored)"), 256 "HELLOs without addresses encountered (ignored)"),
262 1, GNUNET_NO); 257 1,
258 GNUNET_NO);
263 return; 259 return;
264 } 260 }
265 old = builder->size; 261 old = builder->size;
@@ -269,26 +265,23 @@ host_processor (void *cls,
269 (unsigned int) s, 265 (unsigned int) s,
270 "HELLO", 266 "HELLO",
271 GNUNET_i2s (peer)); 267 GNUNET_i2s (peer));
272 if ( (old + s >= GNUNET_MAX_MALLOC_CHECKED) || 268 if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
273 (old + s >= MAX_BYTES_PER_HOSTLISTS) ) 269 (old + s >= MAX_BYTES_PER_HOSTLISTS))
274 { 270 {
275 /* too large, skip! */ 271 /* too large, skip! */
276 GNUNET_STATISTICS_update (stats, 272 GNUNET_STATISTICS_update (stats,
277 gettext_noop 273 gettext_noop (
278 ("bytes not included in hostlist (size limit)"), 274 "bytes not included in hostlist (size limit)"),
279 s, GNUNET_NO); 275 s,
276 GNUNET_NO);
280 return; 277 return;
281 } 278 }
282 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 279 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
283 "Adding peer `%s' to hostlist (%u bytes)\n", 280 "Adding peer `%s' to hostlist (%u bytes)\n",
284 GNUNET_i2s (peer), 281 GNUNET_i2s (peer),
285 (unsigned int) s); 282 (unsigned int) s);
286 GNUNET_array_grow (builder->data, 283 GNUNET_array_grow (builder->data, builder->size, old + s);
287 builder->size, 284 GNUNET_memcpy (&builder->data[old], hello, s);
288 old + s);
289 GNUNET_memcpy (&builder->data[old],
290 hello,
291 s);
292} 285}
293 286
294 287
@@ -308,11 +301,12 @@ accept_policy_callback (void *cls,
308{ 301{
309 if (NULL == response) 302 if (NULL == response)
310 { 303 {
311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 304 GNUNET_log (
312 "Received request for hostlist, but I am not yet ready; rejecting!\n"); 305 GNUNET_ERROR_TYPE_DEBUG,
306 "Received request for hostlist, but I am not yet ready; rejecting!\n");
313 return MHD_NO; 307 return MHD_NO;
314 } 308 }
315 return MHD_YES; /* accept all */ 309 return MHD_YES; /* accept all */
316} 310}
317 311
318 312
@@ -369,9 +363,9 @@ access_handler_callback (void *cls,
369 struct MHD_Response *options_response; 363 struct MHD_Response *options_response;
370 int rc; 364 int rc;
371 365
372 options_response = MHD_create_response_from_buffer (0, NULL, 366 options_response =
373 MHD_RESPMEM_PERSISTENT); 367 MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT);
374 add_cors_headers(options_response); 368 add_cors_headers (options_response);
375 rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response); 369 rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
376 MHD_destroy_response (options_response); 370 MHD_destroy_response (options_response);
377 return rc; 371 return rc;
@@ -379,10 +373,12 @@ access_handler_callback (void *cls,
379 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 373 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
380 { 374 {
381 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 375 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
382 _("Refusing `%s' request to hostlist server\n"), method); 376 _ ("Refusing `%s' request to hostlist server\n"),
377 method);
383 GNUNET_STATISTICS_update (stats, 378 GNUNET_STATISTICS_update (stats,
384 gettext_noop 379 gettext_noop (
385 ("hostlist requests refused (not HTTP GET)"), 1, 380 "hostlist requests refused (not HTTP GET)"),
381 1,
386 GNUNET_YES); 382 GNUNET_YES);
387 return MHD_NO; 383 return MHD_NO;
388 } 384 }
@@ -394,29 +390,35 @@ access_handler_callback (void *cls,
394 if (0 != *upload_data_size) 390 if (0 != *upload_data_size)
395 { 391 {
396 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 392 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
397 _("Refusing `%s' request with %llu bytes of upload data\n"), 393 _ ("Refusing `%s' request with %llu bytes of upload data\n"),
398 method, (unsigned long long) *upload_data_size); 394 method,
395 (unsigned long long) *upload_data_size);
399 GNUNET_STATISTICS_update (stats, 396 GNUNET_STATISTICS_update (stats,
400 gettext_noop 397 gettext_noop (
401 ("hostlist requests refused (upload data)"), 1, 398 "hostlist requests refused (upload data)"),
399 1,
402 GNUNET_YES); 400 GNUNET_YES);
403 return MHD_NO; /* do not support upload data */ 401 return MHD_NO; /* do not support upload data */
404 } 402 }
405 if (NULL == response) 403 if (NULL == response)
406 { 404 {
407 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 405 GNUNET_log (
408 _("Could not handle hostlist request since I do not have a response yet\n")); 406 GNUNET_ERROR_TYPE_WARNING,
407 _ (
408 "Could not handle hostlist request since I do not have a response yet\n"));
409 GNUNET_STATISTICS_update (stats, 409 GNUNET_STATISTICS_update (stats,
410 gettext_noop 410 gettext_noop (
411 ("hostlist requests refused (not ready)"), 1, 411 "hostlist requests refused (not ready)"),
412 1,
412 GNUNET_YES); 413 GNUNET_YES);
413 return MHD_NO; /* internal error, no response yet */ 414 return MHD_NO; /* internal error, no response yet */
414 } 415 }
415 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 416 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
416 _("Received request for our hostlist\n")); 417 _ ("Received request for our hostlist\n"));
417 GNUNET_STATISTICS_update (stats, 418 GNUNET_STATISTICS_update (stats,
418 gettext_noop ("hostlist requests processed"), 419 gettext_noop ("hostlist requests processed"),
419 1, GNUNET_YES); 420 1,
421 GNUNET_YES);
420 return MHD_queue_response (connection, MHD_HTTP_OK, response); 422 return MHD_queue_response (connection, MHD_HTTP_OK, response);
421} 423}
422 424
@@ -434,27 +436,19 @@ static void
434adv_transmit (struct GNUNET_MQ_Handle *mq) 436adv_transmit (struct GNUNET_MQ_Handle *mq)
435{ 437{
436 static uint64_t hostlist_adv_count; 438 static uint64_t hostlist_adv_count;
437 const void *extra; 439 size_t uri_size; /* Including \0 termination! */
438 uint64_t flags;
439 size_t uri_size; /* Including \0 termination! */
440 struct GNUNET_MessageHeader *header; 440 struct GNUNET_MessageHeader *header;
441 struct GNUNET_MQ_Envelope *env; 441 struct GNUNET_MQ_Envelope *env;
442 442
443 extra = GNUNET_CORE_get_mq_options (GNUNET_YES,
444 GNUNET_CORE_PRIO_BEST_EFFORT,
445 &flags);
446 uri_size = strlen (hostlist_uri) + 1; 443 uri_size = strlen (hostlist_uri) + 1;
447 env = GNUNET_MQ_msg_extra (header, 444 env = GNUNET_MQ_msg_extra (header,
448 uri_size, 445 uri_size,
449 GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); 446 GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
450 GNUNET_memcpy (&header[1], 447 GNUNET_memcpy (&header[1], hostlist_uri, uri_size);
451 hostlist_uri,
452 uri_size);
453 GNUNET_MQ_env_set_options (env, 448 GNUNET_MQ_env_set_options (env,
454 flags, 449 GNUNET_MQ_PREF_CORK_ALLOWED |
455 extra); 450 GNUNET_MQ_PREF_UNRELIABLE);
456 GNUNET_MQ_send (mq, 451 GNUNET_MQ_send (mq, env);
457 env);
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "Sent advertisement message: Copied %u bytes into buffer!\n", 453 "Sent advertisement message: Copied %u bytes into buffer!\n",
460 (unsigned int) uri_size); 454 (unsigned int) uri_size);
@@ -463,7 +457,8 @@ adv_transmit (struct GNUNET_MQ_Handle *mq)
463 " # Sent advertisement message: %llu\n", 457 " # Sent advertisement message: %llu\n",
464 (unsigned long long) hostlist_adv_count); 458 (unsigned long long) hostlist_adv_count);
465 GNUNET_STATISTICS_update (stats, 459 GNUNET_STATISTICS_update (stats,
466 gettext_noop ("# hostlist advertisements send"), 1, 460 gettext_noop ("# hostlist advertisements send"),
461 1,
467 GNUNET_NO); 462 GNUNET_NO);
468} 463}
469 464
@@ -479,7 +474,7 @@ adv_transmit (struct GNUNET_MQ_Handle *mq)
479static void * 474static void *
480connect_handler (void *cls, 475connect_handler (void *cls,
481 const struct GNUNET_PeerIdentity *peer, 476 const struct GNUNET_PeerIdentity *peer,
482 struct GNUNET_MQ_Handle *mq) 477 struct GNUNET_MQ_Handle *mq)
483{ 478{
484 size_t size; 479 size_t size;
485 480
@@ -488,8 +483,7 @@ connect_handler (void *cls,
488 if (NULL == hostlist_uri) 483 if (NULL == hostlist_uri)
489 return NULL; 484 return NULL;
490 size = strlen (hostlist_uri) + 1; 485 size = strlen (hostlist_uri) + 1;
491 if (size + sizeof (struct GNUNET_MessageHeader) >= 486 if (size + sizeof (struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE)
492 GNUNET_MAX_MESSAGE_SIZE)
493 { 487 {
494 GNUNET_break (0); 488 GNUNET_break (0);
495 return NULL; 489 return NULL;
@@ -500,10 +494,11 @@ connect_handler (void *cls,
500 GNUNET_break (0); 494 GNUNET_break (0);
501 return NULL; 495 return NULL;
502 } 496 }
503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 497 GNUNET_log (
504 "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", 498 GNUNET_ERROR_TYPE_DEBUG,
505 (unsigned int) size, 499 "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n",
506 GNUNET_i2s (peer)); 500 (unsigned int) size,
501 GNUNET_i2s (peer));
507 adv_transmit (mq); 502 adv_transmit (mq);
508 return NULL; 503 return NULL;
509} 504}
@@ -528,8 +523,8 @@ process_notify (void *cls,
528 "Peerinfo is notifying us to rebuild our hostlist\n"); 523 "Peerinfo is notifying us to rebuild our hostlist\n");
529 if (NULL != err_msg) 524 if (NULL != err_msg)
530 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 525 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
531 _("Error in communication with PEERINFO service: %s\n"), 526 _ ("Error in communication with PEERINFO service: %s\n"),
532 err_msg); 527 err_msg);
533 if (NULL != builder) 528 if (NULL != builder)
534 { 529 {
535 /* restart re-build already in progress ... */ 530 /* restart re-build already in progress ... */
@@ -547,10 +542,8 @@ process_notify (void *cls,
547 builder = GNUNET_new (struct HostSet); 542 builder = GNUNET_new (struct HostSet);
548 } 543 }
549 GNUNET_assert (NULL != peerinfo); 544 GNUNET_assert (NULL != peerinfo);
550 builder->pitr 545 builder->pitr =
551 = GNUNET_PEERINFO_iterate (peerinfo, 546 GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, &host_processor, NULL);
552 GNUNET_NO, NULL,
553 &host_processor, NULL);
554} 547}
555 548
556 549
@@ -594,7 +587,7 @@ run_daemon (void *cls)
594static struct GNUNET_SCHEDULER_Task * 587static struct GNUNET_SCHEDULER_Task *
595prepare_daemon (struct MHD_Daemon *daemon_handle) 588prepare_daemon (struct MHD_Daemon *daemon_handle)
596{ 589{
597 struct GNUNET_SCHEDULER_Task * ret; 590 struct GNUNET_SCHEDULER_Task *ret;
598 fd_set rs; 591 fd_set rs;
599 fd_set ws; 592 fd_set ws;
600 fd_set es; 593 fd_set es;
@@ -611,9 +604,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
611 wrs = GNUNET_NETWORK_fdset_create (); 604 wrs = GNUNET_NETWORK_fdset_create ();
612 wws = GNUNET_NETWORK_fdset_create (); 605 wws = GNUNET_NETWORK_fdset_create ();
613 max = -1; 606 max = -1;
614 GNUNET_assert (MHD_YES == 607 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
615 MHD_get_fdset (daemon_handle,
616 &rs, &ws, &es, &max));
617 haveto = MHD_get_timeout (daemon_handle, &timeout); 608 haveto = MHD_get_timeout (daemon_handle, &timeout);
618 if (haveto == MHD_YES) 609 if (haveto == MHD_YES)
619 tv.rel_value_us = (uint64_t) timeout * 1000LL; 610 tv.rel_value_us = (uint64_t) timeout * 1000LL;
@@ -622,8 +613,11 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
622 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); 613 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
623 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); 614 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
624 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 615 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
625 tv, wrs, wws, 616 tv,
626 &run_daemon, daemon_handle); 617 wrs,
618 wws,
619 &run_daemon,
620 daemon_handle);
627 GNUNET_NETWORK_fdset_destroy (wrs); 621 GNUNET_NETWORK_fdset_destroy (wrs);
628 GNUNET_NETWORK_fdset_destroy (wws); 622 GNUNET_NETWORK_fdset_destroy (wws);
629 return ret; 623 return ret;
@@ -676,19 +670,18 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
676 if (NULL == peerinfo) 670 if (NULL == peerinfo)
677 { 671 {
678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
679 _("Could not access PEERINFO service. Exiting.\n")); 673 _ ("Could not access PEERINFO service. Exiting.\n"));
680 return GNUNET_SYSERR; 674 return GNUNET_SYSERR;
681 } 675 }
682 if (GNUNET_OK != 676 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
683 GNUNET_CONFIGURATION_get_value_number (cfg, 677 "HOSTLIST",
684 "HOSTLIST", 678 "HTTPPORT",
685 "HTTPPORT", 679 &port))
686 &port))
687 return GNUNET_SYSERR; 680 return GNUNET_SYSERR;
688 if ((0 == port) || (port > UINT16_MAX)) 681 if ((0 == port) || (port > UINT16_MAX))
689 { 682 {
690 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 683 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
691 _("Invalid port number %llu. Exiting.\n"), 684 _ ("Invalid port number %llu. Exiting.\n"),
692 port); 685 port);
693 return GNUNET_SYSERR; 686 return GNUNET_SYSERR;
694 } 687 }
@@ -700,8 +693,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
700 &hostname)) 693 &hostname))
701 hostname = GNUNET_RESOLVER_local_fqdn_get (); 694 hostname = GNUNET_RESOLVER_local_fqdn_get ();
702 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 695 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
703 _("Hostlist service starts on %s:%llu\n"), 696 _ ("Hostlist service starts on %s:%llu\n"),
704 hostname, port); 697 hostname,
698 port);
705 if (NULL != hostname) 699 if (NULL != hostname)
706 { 700 {
707 size = strlen (hostname); 701 size = strlen (hostname);
@@ -712,10 +706,11 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
712 else 706 else
713 { 707 {
714 GNUNET_asprintf (&hostlist_uri, 708 GNUNET_asprintf (&hostlist_uri,
715 "http://%s:%u/", hostname, 709 "http://%s:%u/",
710 hostname,
716 (unsigned int) port); 711 (unsigned int) port);
717 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 712 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
718 _("Address to obtain hostlist: `%s'\n"), 713 _ ("Address to obtain hostlist: `%s'\n"),
719 hostlist_uri); 714 hostlist_uri);
720 } 715 }
721 GNUNET_free (hostname); 716 GNUNET_free (hostname);
@@ -723,29 +718,28 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
723 718
724 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4")) 719 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
725 { 720 {
726 if (GNUNET_OK != 721 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
727 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", 722 "HOSTLIST",
728 "BINDTOIP", &ipv4)) 723 "BINDTOIP",
724 &ipv4))
729 { 725 {
730 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 726 GNUNET_log (
731 _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); 727 GNUNET_ERROR_TYPE_WARNING,
728 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
732 } 729 }
733
734 } 730 }
735 else 731 else
736 ipv4 = NULL; 732 ipv4 = NULL;
737 if (GNUNET_CONFIGURATION_have_value (cfg, 733 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
738 "HOSTLIST", 734 {
739 "BINDTOIPV6")) 735 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
740 { 736 "HOSTLIST",
741 if (GNUNET_OK != 737 "BINDTOIP",
742 GNUNET_CONFIGURATION_get_value_string (cfg, 738 &ipv6))
743 "HOSTLIST", 739 {
744 "BINDTOIP", 740 GNUNET_log (
745 &ipv6)) 741 GNUNET_ERROR_TYPE_WARNING,
746 { 742 _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
747 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
748 _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
749 } 743 }
750 } 744 }
751 else 745 else
@@ -766,7 +760,8 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
766 } 760 }
767 else 761 else
768 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 762 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
769 _("`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), 763 _ (
764 "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
770 ipv4); 765 ipv4);
771 GNUNET_free (ipv4); 766 GNUNET_free (ipv4);
772 } 767 }
@@ -786,15 +781,18 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
786 } 781 }
787 else 782 else
788 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 783 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
789 _("`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), 784 _ (
785 "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
790 ipv6); 786 ipv6);
791 GNUNET_free (ipv6); 787 GNUNET_free (ipv6);
792 } 788 }
793 789
794 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG, 790 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
795 (uint16_t) port, 791 (uint16_t) port,
796 &accept_policy_callback, NULL, 792 &accept_policy_callback,
797 &access_handler_callback, NULL, 793 NULL,
794 &access_handler_callback,
795 NULL,
798 MHD_OPTION_CONNECTION_LIMIT, 796 MHD_OPTION_CONNECTION_LIMIT,
799 (unsigned int) 128, 797 (unsigned int) 128,
800 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 798 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
@@ -807,9 +805,11 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
807 sa6, 805 sa6,
808 MHD_OPTION_END); 806 MHD_OPTION_END);
809 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG, 807 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
810 (uint16_t) port, 808 (uint16_t) port,
811 &accept_policy_callback, NULL, 809 &accept_policy_callback,
812 &access_handler_callback, NULL, 810 NULL,
811 &access_handler_callback,
812 NULL,
813 MHD_OPTION_CONNECTION_LIMIT, 813 MHD_OPTION_CONNECTION_LIMIT,
814 (unsigned int) 128, 814 (unsigned int) 128,
815 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 815 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
@@ -822,11 +822,10 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
822 sa4, 822 sa4,
823 MHD_OPTION_END); 823 MHD_OPTION_END);
824 824
825 if ( (NULL == daemon_handle_v6) && 825 if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
826 (NULL == daemon_handle_v4) )
827 { 826 {
828 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 827 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
829 _("Could not start hostlist HTTP server on port %u\n"), 828 _ ("Could not start hostlist HTTP server on port %u\n"),
830 (unsigned short) port); 829 (unsigned short) port);
831 return GNUNET_SYSERR; 830 return GNUNET_SYSERR;
832 } 831 }
@@ -837,9 +836,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
837 hostlist_task_v4 = prepare_daemon (daemon_handle_v4); 836 hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
838 if (NULL != daemon_handle_v6) 837 if (NULL != daemon_handle_v6)
839 hostlist_task_v6 = prepare_daemon (daemon_handle_v6); 838 hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
840 notify = GNUNET_PEERINFO_notify (cfg, 839 notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL);
841 GNUNET_NO,
842 &process_notify, NULL);
843 return GNUNET_OK; 840 return GNUNET_OK;
844} 841}
845 842
@@ -850,8 +847,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
850void 847void
851GNUNET_HOSTLIST_server_stop () 848GNUNET_HOSTLIST_server_stop ()
852{ 849{
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
854 "Hostlist server shutdown\n");
855 if (NULL != hostlist_task_v6) 851 if (NULL != hostlist_task_v6)
856 { 852 {
857 GNUNET_SCHEDULER_cancel (hostlist_task_v6); 853 GNUNET_SCHEDULER_cancel (hostlist_task_v6);
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index f10ddee75..111eb529d 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.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
@@ -34,9 +34,8 @@
34#define GNUNET_CORE_SERVICE_H 34#define GNUNET_CORE_SERVICE_H
35 35
36#ifdef __cplusplus 36#ifdef __cplusplus
37extern "C" 37extern "C" {
38{ 38#if 0 /* keep Emacsens' auto-indent happy */
39#if 0 /* keep Emacsens' auto-indent happy */
40} 39}
41#endif 40#endif
42#endif 41#endif
@@ -49,35 +48,6 @@ extern "C"
49 */ 48 */
50#define GNUNET_CORE_VERSION 0x00000001 49#define GNUNET_CORE_VERSION 0x00000001
51 50
52/**
53 * Traffic priorities.
54 */
55enum GNUNET_CORE_Priority
56{
57
58 /**
59 * Lowest priority, i.e. background traffic (i.e. fs)
60 */
61 GNUNET_CORE_PRIO_BACKGROUND = 0,
62
63 /**
64 * Normal traffic (i.e. cadet/dv relay, DHT)
65 */
66 GNUNET_CORE_PRIO_BEST_EFFORT = 1,
67
68 /**
69 * Urgent traffic (local peer, i.e. conversation).
70 */
71 GNUNET_CORE_PRIO_URGENT = 2,
72
73 /**
74 * Highest priority, control traffic (i.e. NSE, Core/Cadet KX).
75 */
76 GNUNET_CORE_PRIO_CRITICAL_CONTROL = 3
77
78
79};
80
81 51
82/** 52/**
83 * Opaque handle to the service. 53 * Opaque handle to the service.
@@ -93,10 +63,10 @@ struct GNUNET_CORE_Handle;
93 * @return closure associated with @a peer. given to mq callbacks and 63 * @return closure associated with @a peer. given to mq callbacks and
94 * #GNUNET_CORE_DisconnectEventHandler 64 * #GNUNET_CORE_DisconnectEventHandler
95 */ 65 */
96typedef void * 66typedef void *(*GNUNET_CORE_ConnectEventHandler) (
97(*GNUNET_CORE_ConnectEventHandler) (void *cls, 67 void *cls,
98 const struct GNUNET_PeerIdentity *peer, 68 const struct GNUNET_PeerIdentity *peer,
99 struct GNUNET_MQ_Handle *mq); 69 struct GNUNET_MQ_Handle *mq);
100 70
101 71
102/** 72/**
@@ -107,10 +77,10 @@ typedef void *
107 * @param peer_cls closure associated with peer. given in 77 * @param peer_cls closure associated with peer. given in
108 * #GNUNET_CORE_ConnectEventHandler 78 * #GNUNET_CORE_ConnectEventHandler
109 */ 79 */
110typedef void 80typedef void (*GNUNET_CORE_DisconnectEventHandler) (
111(*GNUNET_CORE_DisconnectEventHandler) (void *cls, 81 void *cls,
112 const struct GNUNET_PeerIdentity *peer, 82 const struct GNUNET_PeerIdentity *peer,
113 void *peer_cls); 83 void *peer_cls);
114 84
115 85
116/** 86/**
@@ -125,9 +95,9 @@ typedef void
125 * @param cls closure 95 * @param cls closure
126 * @param my_identity ID of this peer, NULL if we failed 96 * @param my_identity ID of this peer, NULL if we failed
127 */ 97 */
128typedef void 98typedef void (*GNUNET_CORE_StartupCallback) (
129(*GNUNET_CORE_StartupCallback) (void *cls, 99 void *cls,
130 const struct GNUNET_PeerIdentity *my_identity); 100 const struct GNUNET_PeerIdentity *my_identity);
131 101
132 102
133/** 103/**
@@ -173,22 +143,6 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle);
173 143
174 144
175/** 145/**
176 * Inquire with CORE what options should be set for a message
177 * so that it is transmitted with the given @a priority and
178 * the given @a cork value.
179 *
180 * @param cork desired corking
181 * @param priority desired message priority
182 * @param[out] flags set to `flags` value for #GNUNET_MQ_set_options()
183 * @return `extra` argument to give to #GNUNET_MQ_set_options()
184 */
185const void *
186GNUNET_CORE_get_mq_options (int cork,
187 enum GNUNET_CORE_Priority priority,
188 uint64_t *flags);
189
190
191/**
192 * Obtain the message queue for a connected peer. 146 * Obtain the message queue for a connected peer.
193 * 147 *
194 * @param h the core handle 148 * @param h the core handle
@@ -197,7 +151,7 @@ GNUNET_CORE_get_mq_options (int cork,
197 */ 151 */
198struct GNUNET_MQ_Handle * 152struct GNUNET_MQ_Handle *
199GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h, 153GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h,
200 const struct GNUNET_PeerIdentity *pid); 154 const struct GNUNET_PeerIdentity *pid);
201 155
202 156
203/** 157/**
@@ -287,11 +241,11 @@ enum GNUNET_CORE_KxState
287 * @param state current key exchange state of the peer 241 * @param state current key exchange state of the peer
288 * @param timeout when does the current state expire 242 * @param timeout when does the current state expire
289 */ 243 */
290typedef void 244typedef void (*GNUNET_CORE_MonitorCallback) (
291(*GNUNET_CORE_MonitorCallback)(void *cls, 245 void *cls,
292 const struct GNUNET_PeerIdentity *pid, 246 const struct GNUNET_PeerIdentity *pid,
293 enum GNUNET_CORE_KxState state, 247 enum GNUNET_CORE_KxState state,
294 struct GNUNET_TIME_Absolute timeout); 248 struct GNUNET_TIME_Absolute timeout);
295 249
296 250
297/** 251/**
@@ -360,7 +314,7 @@ GNUNET_CORE_mq_create (struct GNUNET_CORE_Handle *h,
360 const struct GNUNET_PeerIdentity *target); 314 const struct GNUNET_PeerIdentity *target);
361 315
362 316
363#if 0 /* keep Emacsens' auto-indent happy */ 317#if 0 /* keep Emacsens' auto-indent happy */
364{ 318{
365#endif 319#endif
366#ifdef __cplusplus 320#ifdef __cplusplus
@@ -370,6 +324,6 @@ GNUNET_CORE_mq_create (struct GNUNET_CORE_Handle *h,
370/* ifndef GNUNET_CORE_SERVICE_H */ 324/* ifndef GNUNET_CORE_SERVICE_H */
371#endif 325#endif
372 326
373/** @} */ /* end of group core */ 327/** @} */ /* end of group core */
374 328
375/* end of gnunet_core_service.h */ 329/* end of gnunet_core_service.h */
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 2a459636a..498567ec2 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -49,7 +49,10 @@
49 * @param type type of the message 49 * @param type type of the message
50 * @return the MQ message 50 * @return the MQ message
51 */ 51 */
52#define GNUNET_MQ_msg_extra(mvar, esize, type) GNUNET_MQ_msg_(((struct GNUNET_MessageHeader**) &(mvar)), (esize) + sizeof *(mvar), (type)) 52#define GNUNET_MQ_msg_extra(mvar, esize, type) \
53 GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \
54 (esize) + sizeof *(mvar), \
55 (type))
53 56
54/** 57/**
55 * Allocate a GNUNET_MQ_Envelope. 58 * Allocate a GNUNET_MQ_Envelope.
@@ -61,7 +64,7 @@
61 * @param type type of the message 64 * @param type type of the message
62 * @return the allocated envelope 65 * @return the allocated envelope
63 */ 66 */
64#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type) 67#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra (mvar, 0, type)
65 68
66 69
67/** 70/**
@@ -70,7 +73,8 @@
70 * 73 *
71 * @param type type of the message 74 * @param type type of the message
72 */ 75 */
73#define GNUNET_MQ_msg_header(type) GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type) 76#define GNUNET_MQ_msg_header(type) \
77 GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type)
74 78
75 79
76/** 80/**
@@ -81,7 +85,8 @@
81 * @param esize extra space to allocate after the message header 85 * @param esize extra space to allocate after the message header
82 * @param type type of the message 86 * @param type type of the message
83 */ 87 */
84#define GNUNET_MQ_msg_header_extra(mh, esize, type) GNUNET_MQ_msg_ (&mh, (esize) + sizeof (struct GNUNET_MessageHeader), type) 88#define GNUNET_MQ_msg_header_extra(mh, esize, type) \
89 GNUNET_MQ_msg_ (&mh, (esize) + sizeof (struct GNUNET_MessageHeader), type)
85 90
86 91
87/** 92/**
@@ -94,14 +99,16 @@
94 * @param mh message to nest 99 * @param mh message to nest
95 * @return a newly allocated 'struct GNUNET_MQ_Envelope *' 100 * @return a newly allocated 'struct GNUNET_MQ_Envelope *'
96 */ 101 */
97#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \ 102#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \
98 ({struct GNUNET_MQ_Envelope *_ev;\ 103 ({ \
99 _ev = GNUNET_MQ_msg_nested_mh_((struct GNUNET_MessageHeader**) &(mvar),\ 104 struct GNUNET_MQ_Envelope *_ev; \
100 sizeof (*(mvar)),\ 105 _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \
101 (type),\ 106 sizeof (*(mvar)), \
102 (mh));\ 107 (type), \
103 (void)(mvar)->header; /* type check */\ 108 (mh)); \
104 _ev;}) 109 (void) (mvar)->header; /* type check */ \
110 _ev; \
111 })
105 112
106 113
107/** 114/**
@@ -112,7 +119,9 @@
112 * @return a 'struct GNUNET_MessageHeader *' that points at the nested message of the given message, 119 * @return a 'struct GNUNET_MessageHeader *' that points at the nested message of the given message,
113 * or NULL if the given message in @a var does not have any space after the message struct 120 * or NULL if the given message in @a var does not have any space after the message struct
114 */ 121 */
115#define GNUNET_MQ_extract_nested_mh(var) GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), sizeof (*(var))) 122#define GNUNET_MQ_extract_nested_mh(var) \
123 GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \
124 sizeof (*(var)))
116 125
117 126
118/** 127/**
@@ -213,14 +222,89 @@ enum GNUNET_MQ_Error
213 222
214 223
215/** 224/**
225 * Per envelope preferences and priorities.
226 */
227enum GNUNET_MQ_PriorityPreferences
228{
229
230 /**
231 * Lowest priority, i.e. background traffic (i.e. NSE, FS).
232 * This is the default!
233 */
234 GNUNET_MQ_PRIO_BACKGROUND = 0,
235
236 /**
237 * Best-effort traffic (i.e. CADET relay, DHT)
238 */
239 GNUNET_MQ_PRIO_BEST_EFFORT = 1,
240
241 /**
242 * Urgent traffic (local peer, i.e. Conversation).
243 */
244 GNUNET_MQ_PRIO_URGENT = 2,
245
246 /**
247 * Highest priority, control traffic (i.e. CORE/CADET KX).
248 */
249 GNUNET_MQ_PRIO_CRITICAL_CONTROL = 3,
250
251 /**
252 * Bit mask to apply to extract the priority bits.
253 */
254 GNUNET_MQ_PRIORITY_MASK = 3,
255
256 /**
257 * Flag to indicate that unreliable delivery is acceptable. This
258 * means TRANSPORT will not attempt to receive an
259 * acknowledgment. CORE will just pass this flag through. CADET
260 * will use unreliable delivery if this flag is set.
261 *
262 * Note that even without this flag, messages may be lost by
263 * TRANSPORT and CORE.
264 *
265 * Thus, how "strong" the semantics of reliable delivery are depends
266 * on the layer!
267 */
268 GNUNET_MQ_PREF_UNRELIABLE = 16,
269
270 /**
271 * Flag to indicate that low latency is important. This flag must
272 * generally not be used in combination with
273 * #GNUNET_MQ_PREF_CORKING_ALLOWED as it would be a contradiction.
274 * When this flags is set, the envelope may skip forward in the
275 * queue (depending on priority) and also TRANSPORT should attempt
276 * to pick a communicator with particularly low latency.
277 */
278 GNUNET_MQ_PREF_LOW_LATENCY = 32,
279
280 /**
281 * Flag to indicate that CORKing is acceptable. This allows the
282 * receiver to delay transmission in hope of combining this message
283 * with other messages into a larger transmission with less
284 * per-message overhead.
285 */
286 GNUNET_MQ_PREF_CORK_ALLOWED = 64,
287
288 /**
289 * Flag to indicate that high bandwidth is desired. This flag
290 * indicates that the method chosen for transmission should focus on
291 * overall goodput. It rarely makes sense to combine this flag with
292 * #GNUNET_MQ_PREF_LOW_LATENCY.
293 */
294 GNUNET_MQ_PREF_GOODPUT = 128
295
296};
297
298
299/**
216 * Called when a message has been received. 300 * Called when a message has been received.
217 * 301 *
218 * @param cls closure 302 * @param cls closure
219 * @param msg the received message 303 * @param msg the received message
220 */ 304 */
221typedef void 305typedef void (*GNUNET_MQ_MessageCallback) (
222(*GNUNET_MQ_MessageCallback) (void *cls, 306 void *cls,
223 const struct GNUNET_MessageHeader *msg); 307 const struct GNUNET_MessageHeader *msg);
224 308
225 309
226/** 310/**
@@ -231,9 +315,9 @@ typedef void
231 * @return #GNUNET_OK if the message is well-formed, 315 * @return #GNUNET_OK if the message is well-formed,
232 * #GNUNET_SYSERR if not 316 * #GNUNET_SYSERR if not
233 */ 317 */
234typedef int 318typedef int (*GNUNET_MQ_MessageValidationCallback) (
235(*GNUNET_MQ_MessageValidationCallback) (void *cls, 319 void *cls,
236 const struct GNUNET_MessageHeader *msg); 320 const struct GNUNET_MessageHeader *msg);
237 321
238 322
239/** 323/**
@@ -244,10 +328,9 @@ typedef int
244 * @param msg the message to send 328 * @param msg the message to send
245 * @param impl_state state of the implementation 329 * @param impl_state state of the implementation
246 */ 330 */
247typedef void 331typedef void (*GNUNET_MQ_SendImpl) (struct GNUNET_MQ_Handle *mq,
248(*GNUNET_MQ_SendImpl) (struct GNUNET_MQ_Handle *mq, 332 const struct GNUNET_MessageHeader *msg,
249 const struct GNUNET_MessageHeader *msg, 333 void *impl_state);
250 void *impl_state);
251 334
252 335
253/** 336/**
@@ -259,9 +342,8 @@ typedef void
259 * @param mq the message queue to destroy 342 * @param mq the message queue to destroy
260 * @param impl_state state of the implementation 343 * @param impl_state state of the implementation
261 */ 344 */
262typedef void 345typedef void (*GNUNET_MQ_DestroyImpl) (struct GNUNET_MQ_Handle *mq,
263(*GNUNET_MQ_DestroyImpl) (struct GNUNET_MQ_Handle *mq, 346 void *impl_state);
264 void *impl_state);
265 347
266 348
267/** 349/**
@@ -270,9 +352,8 @@ typedef void
270 * @param mq message queue 352 * @param mq message queue
271 * @param impl_state state specific to the implementation 353 * @param impl_state state specific to the implementation
272 */ 354 */
273typedef void 355typedef void (*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq,
274(*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq, 356 void *impl_state);
275 void *impl_state);
276 357
277 358
278/** 359/**
@@ -284,9 +365,7 @@ typedef void
284 * @param cls closure 365 * @param cls closure
285 * @param error error code 366 * @param error error code
286 */ 367 */
287typedef void 368typedef void (*GNUNET_MQ_ErrorHandler) (void *cls, enum GNUNET_MQ_Error error);
288(*GNUNET_MQ_ErrorHandler) (void *cls,
289 enum GNUNET_MQ_Error error);
290 369
291 370
292/** 371/**
@@ -411,7 +490,10 @@ struct GNUNET_MQ_MessageHandler
411/** 490/**
412 * End-marker for the handlers array 491 * End-marker for the handlers array
413 */ 492 */
414#define GNUNET_MQ_handler_end() { NULL, NULL, NULL, 0, 0 } 493#define GNUNET_MQ_handler_end() \
494 { \
495 NULL, NULL, NULL, 0, 0 \
496 }
415 497
416 498
417/** 499/**
@@ -442,12 +524,14 @@ struct GNUNET_MQ_MessageHandler
442 * @param str type of the message (a struct) 524 * @param str type of the message (a struct)
443 * @param ctx context for the callbacks 525 * @param ctx context for the callbacks
444 */ 526 */
445#define GNUNET_MQ_hd_fixed_size(name,code,str,ctx) \ 527#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \
446 ({ \ 528 ({ \
447 void (*_cb)(void *cls, const str *msg) = &handle_##name; \ 529 void (*_cb) (void *cls, const str *msg) = &handle_##name; \
448 ((struct GNUNET_MQ_MessageHandler) { \ 530 ((struct GNUNET_MQ_MessageHandler){NULL, \
449 NULL, (GNUNET_MQ_MessageCallback) _cb, \ 531 (GNUNET_MQ_MessageCallback) _cb, \
450 (ctx), (code), sizeof (str) }); \ 532 (ctx), \
533 (code), \
534 sizeof (str)}); \
451 }) 535 })
452 536
453 537
@@ -491,14 +575,16 @@ struct GNUNET_MQ_MessageHandler
491 * @param str type of the message (a struct) 575 * @param str type of the message (a struct)
492 * @param ctx context for the callbacks 576 * @param ctx context for the callbacks
493 */ 577 */
494#define GNUNET_MQ_hd_var_size(name,code,str,ctx) \ 578#define GNUNET_MQ_hd_var_size(name, code, str, ctx) \
495 __extension__ ({ \ 579 __extension__({ \
496 int (*_mv)(void *cls, const str *msg) = &check_##name; \ 580 int (*_mv) (void *cls, const str *msg) = &check_##name; \
497 void (*_cb)(void *cls, const str *msg) = &handle_##name; \ 581 void (*_cb) (void *cls, const str *msg) = &handle_##name; \
498 ((struct GNUNET_MQ_MessageHandler) \ 582 ((struct GNUNET_MQ_MessageHandler){(GNUNET_MQ_MessageValidationCallback) \
499 { (GNUNET_MQ_MessageValidationCallback) _mv, \ 583 _mv, \
500 (GNUNET_MQ_MessageCallback) _cb, \ 584 (GNUNET_MQ_MessageCallback) _cb, \
501 (ctx), (code), sizeof (str) }); \ 585 (ctx), \
586 (code), \
587 sizeof (str)}); \
502 }) 588 })
503 589
504 590
@@ -512,18 +598,17 @@ struct GNUNET_MQ_MessageHandler
512 * @param an IPC message with proper type to determine 598 * @param an IPC message with proper type to determine
513 * the size, starting with a `struct GNUNET_MessageHeader` 599 * the size, starting with a `struct GNUNET_MessageHeader`
514 */ 600 */
515#define GNUNET_MQ_check_zero_termination(m) \ 601#define GNUNET_MQ_check_zero_termination(m) \
516 { \ 602 { \
517 const char *str = (const char *) &m[1]; \ 603 const char *str = (const char *) &m[1]; \
518 const struct GNUNET_MessageHeader *hdr = \ 604 const struct GNUNET_MessageHeader *hdr = \
519 (const struct GNUNET_MessageHeader *) m; \ 605 (const struct GNUNET_MessageHeader *) m; \
520 uint16_t slen = ntohs (hdr->size) - sizeof (*m); \ 606 uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
521 if ( (0 == slen) || \ 607 if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \
522 (memchr (str, 0, slen) != &str[slen - 1]) ) \ 608 { \
523 { \ 609 GNUNET_break (0); \
524 GNUNET_break (0); \ 610 return GNUNET_NO; \
525 return GNUNET_NO; \ 611 } \
526 } \
527 } 612 }
528 613
529 614
@@ -539,19 +624,19 @@ struct GNUNET_MQ_MessageHandler
539 * @param an IPC message with proper type to determine 624 * @param an IPC message with proper type to determine
540 * the size, starting with a `struct GNUNET_MessageHeader` 625 * the size, starting with a `struct GNUNET_MessageHeader`
541 */ 626 */
542#define GNUNET_MQ_check_boxed_message(m) \ 627#define GNUNET_MQ_check_boxed_message(m) \
543 { \ 628 { \
544 const struct GNUNET_MessageHeader *inbox = \ 629 const struct GNUNET_MessageHeader *inbox = \
545 (const struct GNUNET_MessageHeader *) &m[1]; \ 630 (const struct GNUNET_MessageHeader *) &m[1]; \
546 const struct GNUNET_MessageHeader *hdr = \ 631 const struct GNUNET_MessageHeader *hdr = \
547 (const struct GNUNET_MessageHeader *) m; \ 632 (const struct GNUNET_MessageHeader *) m; \
548 uint16_t slen = ntohs (hdr->size) - sizeof (*m); \ 633 uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
549 if ( (slen < sizeof (struct GNUNET_MessageHeader))||\ 634 if ((slen < sizeof (struct GNUNET_MessageHeader)) || \
550 (slen != ntohs (inbox->size)) ) \ 635 (slen != ntohs (inbox->size))) \
551 { \ 636 { \
552 GNUNET_break (0); \ 637 GNUNET_break (0); \
553 return GNUNET_NO; \ 638 return GNUNET_NO; \
554 } \ 639 } \
555 } 640 }
556 641
557 642
@@ -645,25 +730,34 @@ GNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq);
645 * #GNUNET_MQ_set_options() for this message only. 730 * #GNUNET_MQ_set_options() for this message only.
646 * 731 *
647 * @param env message to set options for 732 * @param env message to set options for
648 * @param flags flags to use (meaning is queue-specific) 733 * @param pp priority and preferences to set for @a env
649 * @param extra additional buffer for further data (also queue-specific)
650 */ 734 */
651void 735void
652GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env, 736GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env,
653 uint64_t flags, 737 enum GNUNET_MQ_PriorityPreferences pp);
654 const void *extra);
655 738
656 739
657/** 740/**
658 * Get application-specific options for this envelope. 741 * Get performance preferences set for this envelope.
659 * 742 *
660 * @param env message to set options for 743 * @param env message to set options for
661 * @param[out] flags set to flags to use (meaning is queue-specific) 744 * @return priority and preferences to use
662 * @return extra additional buffer for further data (also queue-specific) 745 */
746enum GNUNET_MQ_PriorityPreferences
747GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env);
748
749
750/**
751 * Combine performance preferences set for different
752 * envelopes that are being combined into one larger envelope.
753 *
754 * @param p1 one set of preferences
755 * @param p2 second set of preferences
756 * @return combined priority and preferences to use
663 */ 757 */
664const void * 758enum GNUNET_MQ_PriorityPreferences
665GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env, 759GNUNET_MQ_env_combine_options (enum GNUNET_MQ_PriorityPreferences p1,
666 uint64_t *flags); 760 enum GNUNET_MQ_PriorityPreferences p2);
667 761
668 762
669/** 763/**
@@ -681,13 +775,11 @@ GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq);
681 * Set application-specific options for this queue. 775 * Set application-specific options for this queue.
682 * 776 *
683 * @param mq message queue to set options for 777 * @param mq message queue to set options for
684 * @param flags flags to use (meaning is queue-specific) 778 * @param pp priority and preferences to use by default
685 * @param extra additional buffer for further data (also queue-specific)
686 */ 779 */
687void 780void
688GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq, 781GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
689 uint64_t flags, 782 enum GNUNET_MQ_PriorityPreferences pp);
690 const void *extra);
691 783
692 784
693/** 785/**
@@ -708,8 +800,7 @@ GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq);
708 * @param ev the envelope with the message to send. 800 * @param ev the envelope with the message to send.
709 */ 801 */
710void 802void
711GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, 803GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev);
712 struct GNUNET_MQ_Envelope *ev);
713 804
714 805
715/** 806/**
@@ -742,8 +833,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev);
742 * @param assoc_data to associate 833 * @param assoc_data to associate
743 */ 834 */
744uint32_t 835uint32_t
745GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, 836GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data);
746 void *assoc_data);
747 837
748 838
749/** 839/**
@@ -754,8 +844,7 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
754 * @return the associated data 844 * @return the associated data
755 */ 845 */
756void * 846void *
757GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, 847GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id);
758 uint32_t request_id);
759 848
760 849
761/** 850/**
@@ -766,8 +855,7 @@ GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
766 * @return the associated data 855 * @return the associated data
767 */ 856 */
768void * 857void *
769GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, 858GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id);
770 uint32_t request_id);
771 859
772 860
773/** 861/**
@@ -846,8 +934,8 @@ struct GNUNET_MQ_DestroyNotificationHandle;
846 */ 934 */
847struct GNUNET_MQ_DestroyNotificationHandle * 935struct GNUNET_MQ_DestroyNotificationHandle *
848GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq, 936GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
849 GNUNET_SCHEDULER_TaskCallback cb, 937 GNUNET_SCHEDULER_TaskCallback cb,
850 void *cb_cls); 938 void *cb_cls);
851 939
852/** 940/**
853 * Cancel registration from #GNUNET_MQ_destroy_notify(). 941 * Cancel registration from #GNUNET_MQ_destroy_notify().
@@ -855,7 +943,8 @@ GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
855 * @param dnh handle for registration to cancel 943 * @param dnh handle for registration to cancel
856 */ 944 */
857void 945void
858GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh); 946GNUNET_MQ_destroy_notify_cancel (
947 struct GNUNET_MQ_DestroyNotificationHandle *dnh);
859 948
860 949
861/** 950/**
@@ -947,7 +1036,6 @@ const struct GNUNET_MessageHeader *
947GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq); 1036GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq);
948 1037
949 1038
950
951/** 1039/**
952 * Enum defining all known preference categories. 1040 * Enum defining all known preference categories.
953 */ 1041 */
@@ -977,7 +1065,7 @@ enum GNUNET_MQ_PreferenceKind
977 */ 1065 */
978 GNUNET_MQ_PREFERENCE_RELIABILITY = 3 1066 GNUNET_MQ_PREFERENCE_RELIABILITY = 3
979 1067
980 /** 1068/**
981 * Number of preference values allowed. 1069 * Number of preference values allowed.
982 */ 1070 */
983#define GNUNET_MQ_PREFERENCE_COUNT 4 1071#define GNUNET_MQ_PREFERENCE_COUNT 4
@@ -995,8 +1083,6 @@ const char *
995GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type); 1083GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type);
996 1084
997 1085
998
999
1000#endif 1086#endif
1001 1087
1002/** @} */ /* end of group mq */ 1088/** @} */ /* end of group mq */
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 5b12c4b98..09316dbcf 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.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
@@ -51,7 +51,6 @@
51#include <gcrypt.h> 51#include <gcrypt.h>
52 52
53 53
54
55/** 54/**
56 * Should messages be delayed randomly? This option should be set to 55 * Should messages be delayed randomly? This option should be set to
57 * #GNUNET_NO only for experiments, not in production. 56 * #GNUNET_NO only for experiments, not in production.
@@ -69,12 +68,15 @@
69#define HISTORY_SIZE 64 68#define HISTORY_SIZE 64
70 69
71/** 70/**
72 * Message priority to use. 71 * Message priority to use. No real rush, reliability not
72 * required. Corking OK.
73 */ 73 */
74#define NSE_PRIORITY GNUNET_CORE_PRIO_CRITICAL_CONTROL 74#define NSE_PRIORITY \
75 (GNUNET_MQ_PRIO_BACKGROUND | GNUNET_MQ_PREF_UNRELIABLE | \
76 GNUNET_MQ_PREF_CORK_ALLOWED)
75 77
76#if FREEBSD 78#if FREEBSD
77#define log2(a) (log(a)/log(2)) 79#define log2(a) (log (a) / log (2))
78#endif 80#endif
79 81
80/** 82/**
@@ -158,7 +160,6 @@ struct NSEPeerEntry
158 unsigned int last_transmitted_size; 160 unsigned int last_transmitted_size;
159 161
160#endif 162#endif
161
162}; 163};
163 164
164 165
@@ -380,13 +381,14 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
380 if (0 != estimate_count) 381 if (0 != estimate_count)
381 { 382 {
382 mean = sum / estimate_count; 383 mean = sum / estimate_count;
383 variance = (vsq - mean * sum) / (estimate_count - 1.0); // terrible for numerical stability... 384 variance = (vsq - mean * sum) /
385 (estimate_count - 1.0); // terrible for numerical stability...
384 } 386 }
385#endif 387#endif
386 if (variance >= 0) 388 if (variance >= 0)
387 std_dev = sqrt (variance); 389 std_dev = sqrt (variance);
388 else 390 else
389 std_dev = variance; /* must be infinity due to estimate_count == 0 */ 391 std_dev = variance; /* must be infinity due to estimate_count == 0 */
390 current_std_dev = std_dev; 392 current_std_dev = std_dev;
391 current_size_estimate = mean; 393 current_size_estimate = mean;
392 394
@@ -401,14 +403,12 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
401 j = 1; /* Avoid log2(0); can only happen if CORE didn't report 403 j = 1; /* Avoid log2(0); can only happen if CORE didn't report
402 connection to self yet */ 404 connection to self yet */
403 nsize = log2 (j); 405 nsize = log2 (j);
404 em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se, 406 em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se, nsize));
405 nsize));
406 em->std_deviation = GNUNET_hton_double (std_dev); 407 em->std_deviation = GNUNET_hton_double (std_dev);
407 GNUNET_STATISTICS_set (stats, 408 GNUNET_STATISTICS_set (stats,
408 "# nodes in the network (estimate)", 409 "# nodes in the network (estimate)",
409 (uint64_t) pow (2, GNUNET_MAX (se, 410 (uint64_t) pow (2, GNUNET_MAX (se, nsize)),
410 nsize)), 411 GNUNET_NO);
411 GNUNET_NO);
412 } 412 }
413} 413}
414 414
@@ -423,23 +423,19 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
423 * @param message the message received 423 * @param message the message received
424 */ 424 */
425static void 425static void
426handle_start (void *cls, 426handle_start (void *cls, const struct GNUNET_MessageHeader *message)
427 const struct GNUNET_MessageHeader *message)
428{ 427{
429 struct GNUNET_SERVICE_Client *client = cls; 428 struct GNUNET_SERVICE_Client *client = cls;
430 struct GNUNET_MQ_Handle *mq; 429 struct GNUNET_MQ_Handle *mq;
431 struct GNUNET_NSE_ClientMessage em; 430 struct GNUNET_NSE_ClientMessage em;
432 struct GNUNET_MQ_Envelope *env; 431 struct GNUNET_MQ_Envelope *env;
433 432
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
435 "Received START message from client\n");
436 mq = GNUNET_SERVICE_client_get_mq (client); 434 mq = GNUNET_SERVICE_client_get_mq (client);
437 GNUNET_notification_context_add (nc, 435 GNUNET_notification_context_add (nc, mq);
438 mq);
439 setup_estimate_message (&em); 436 setup_estimate_message (&em);
440 env = GNUNET_MQ_msg_copy (&em.header); 437 env = GNUNET_MQ_msg_copy (&em.header);
441 GNUNET_MQ_send (mq, 438 GNUNET_MQ_send (mq, env);
442 env);
443 GNUNET_SERVICE_client_continue (client); 439 GNUNET_SERVICE_client_continue (client);
444} 440}
445 441
@@ -459,8 +455,8 @@ get_matching_bits_delay (uint32_t matching_bits)
459 // x is matching_bits 455 // x is matching_bits
460 // p' is current_size_estimate 456 // p' is current_size_estimate
461 return ((double) gnunet_nse_interval.rel_value_us / (double) 2.0) - 457 return ((double) gnunet_nse_interval.rel_value_us / (double) 2.0) -
462 ((gnunet_nse_interval.rel_value_us / M_PI) * 458 ((gnunet_nse_interval.rel_value_us / M_PI) *
463 atan (matching_bits - current_size_estimate)); 459 atan (matching_bits - current_size_estimate));
464} 460}
465 461
466 462
@@ -482,10 +478,10 @@ get_delay_randomization (uint32_t matching_bits)
482 i = (uint32_t) (d / (double) (hop_count_max + 1)); 478 i = (uint32_t) (d / (double) (hop_count_max + 1));
483 ret.rel_value_us = i; 479 ret.rel_value_us = i;
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "Randomizing flood using latencies up to %s\n", 481 "Randomizing flood using latencies up to %s\n",
486 GNUNET_STRINGS_relative_time_to_string (ret, 482 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
487 GNUNET_YES)); 483 ret.rel_value_us =
488 ret.rel_value_us = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, i + 1); 484 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, i + 1);
489 return ret; 485 return ret;
490#else 486#else
491 return GNUNET_TIME_UNIT_ZERO; 487 return GNUNET_TIME_UNIT_ZERO;
@@ -501,19 +497,18 @@ get_delay_randomization (uint32_t matching_bits)
501 * @param result where to write the resulting hash 497 * @param result where to write the resulting hash
502 */ 498 */
503static void 499static void
504pow_hash (const void *buf, 500pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
505 size_t buf_len,
506 struct GNUNET_HashCode *result)
507{ 501{
508 GNUNET_break (0 == 502 GNUNET_break (
509 gcry_kdf_derive (buf, buf_len, 503 0 == gcry_kdf_derive (buf,
510 GCRY_KDF_SCRYPT, 504 buf_len,
511 1 /* subalgo */, 505 GCRY_KDF_SCRYPT,
512 "gnunet-proof-of-work", 506 1 /* subalgo */,
513 strlen ("gnunet-proof-of-work"), 507 "gnunet-proof-of-work",
514 2 /* iterations; keep cost of individual op small */, 508 strlen ("gnunet-proof-of-work"),
515 sizeof (struct GNUNET_HashCode), 509 2 /* iterations; keep cost of individual op small */,
516 result)); 510 sizeof (struct GNUNET_HashCode),
511 result));
517} 512}
518 513
519 514
@@ -534,11 +529,8 @@ get_matching_bits (struct GNUNET_TIME_Absolute timestamp,
534 GNUNET_CRYPTO_hash (&timestamp.abs_value_us, 529 GNUNET_CRYPTO_hash (&timestamp.abs_value_us,
535 sizeof (timestamp.abs_value_us), 530 sizeof (timestamp.abs_value_us),
536 &timestamp_hash); 531 &timestamp_hash);
537 GNUNET_CRYPTO_hash (id, 532 GNUNET_CRYPTO_hash (id, sizeof (struct GNUNET_PeerIdentity), &pid_hash);
538 sizeof (struct GNUNET_PeerIdentity), 533 return GNUNET_CRYPTO_hash_matching_bits (&timestamp_hash, &pid_hash);
539 &pid_hash);
540 return GNUNET_CRYPTO_hash_matching_bits (&timestamp_hash,
541 &pid_hash);
542} 534}
543 535
544 536
@@ -563,20 +555,19 @@ get_transmit_delay (int round_offset)
563 case -1: 555 case -1:
564 /* previous round is randomized between 0 and 50 ms */ 556 /* previous round is randomized between 0 and 50 ms */
565#if USE_RANDOM_DELAYS 557#if USE_RANDOM_DELAYS
566 ret.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 558 ret.rel_value_us =
567 50); 559 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50);
568#else 560#else
569 ret = GNUNET_TIME_UNIT_ZERO; 561 ret = GNUNET_TIME_UNIT_ZERO;
570#endif 562#endif
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 "Transmitting previous round behind schedule in %s\n", 564 "Transmitting previous round behind schedule in %s\n",
573 GNUNET_STRINGS_relative_time_to_string (ret, 565 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
574 GNUNET_YES));
575 return ret; 566 return ret;
576 case 0: 567 case 0:
577 /* current round is based on best-known matching_bits */ 568 /* current round is based on best-known matching_bits */
578 matching_bits = 569 matching_bits =
579 ntohl (size_estimate_messages[estimate_index].matching_bits); 570 ntohl (size_estimate_messages[estimate_index].matching_bits);
580 dist_delay = get_matching_bits_delay (matching_bits); 571 dist_delay = get_matching_bits_delay (matching_bits);
581 dist_delay += get_delay_randomization (matching_bits).rel_value_us; 572 dist_delay += get_delay_randomization (matching_bits).rel_value_us;
582 ret.rel_value_us = (uint64_t) dist_delay; 573 ret.rel_value_us = (uint64_t) dist_delay;
@@ -584,11 +575,9 @@ get_transmit_delay (int round_offset)
584 "For round %s, delay for %u matching bits is %s\n", 575 "For round %s, delay for %u matching bits is %s\n",
585 GNUNET_STRINGS_absolute_time_to_string (current_timestamp), 576 GNUNET_STRINGS_absolute_time_to_string (current_timestamp),
586 (unsigned int) matching_bits, 577 (unsigned int) matching_bits,
587 GNUNET_STRINGS_relative_time_to_string (ret, 578 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
588 GNUNET_YES));
589 /* now consider round start time and add delay to it */ 579 /* now consider round start time and add delay to it */
590 tgt = GNUNET_TIME_absolute_add (current_timestamp, 580 tgt = GNUNET_TIME_absolute_add (current_timestamp, ret);
591 ret);
592 return GNUNET_TIME_absolute_get_remaining (tgt); 581 return GNUNET_TIME_absolute_get_remaining (tgt);
593 } 582 }
594 GNUNET_break (0); 583 GNUNET_break (0);
@@ -614,10 +603,10 @@ transmit_task_cb (void *cls)
614 { 603 {
615 idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE; 604 idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE;
616 peer_entry->previous_round = GNUNET_YES; 605 peer_entry->previous_round = GNUNET_YES;
617 peer_entry->transmit_task 606 peer_entry->transmit_task =
618 = GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0), 607 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0),
619 &transmit_task_cb, 608 &transmit_task_cb,
620 peer_entry); 609 peer_entry);
621 } 610 }
622 if ((0 == ntohl (size_estimate_messages[idx].hop_count)) && 611 if ((0 == ntohl (size_estimate_messages[idx].hop_count)) &&
623 (NULL != proof_task)) 612 (NULL != proof_task))
@@ -625,7 +614,7 @@ transmit_task_cb (void *cls)
625 GNUNET_STATISTICS_update (stats, 614 GNUNET_STATISTICS_update (stats,
626 "# flood messages not generated (no proof yet)", 615 "# flood messages not generated (no proof yet)",
627 1, 616 1,
628 GNUNET_NO); 617 GNUNET_NO);
629 return; 618 return;
630 } 619 }
631 if (0 == ntohs (size_estimate_messages[idx].header.size)) 620 if (0 == ntohs (size_estimate_messages[idx].header.size))
@@ -633,31 +622,29 @@ transmit_task_cb (void *cls)
633 GNUNET_STATISTICS_update (stats, 622 GNUNET_STATISTICS_update (stats,
634 "# flood messages not generated (lack of history)", 623 "# flood messages not generated (lack of history)",
635 1, 624 1,
636 GNUNET_NO); 625 GNUNET_NO);
637 return; 626 return;
638 } 627 }
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
640 "In round %s, sending to `%s' estimate with %u bits\n", 629 "In round %s, sending to `%s' estimate with %u bits\n",
641 GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp)), 630 GNUNET_STRINGS_absolute_time_to_string (
631 GNUNET_TIME_absolute_ntoh (
632 size_estimate_messages[idx].timestamp)),
642 GNUNET_i2s (peer_entry->id), 633 GNUNET_i2s (peer_entry->id),
643 (unsigned int) ntohl (size_estimate_messages[idx].matching_bits)); 634 (unsigned int) ntohl (size_estimate_messages[idx].matching_bits));
644 if (0 == ntohl (size_estimate_messages[idx].hop_count)) 635 if (0 == ntohl (size_estimate_messages[idx].hop_count))
645 GNUNET_STATISTICS_update (stats, 636 GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO);
646 "# flood messages started",
647 1,
648 GNUNET_NO);
649 GNUNET_STATISTICS_update (stats, 637 GNUNET_STATISTICS_update (stats,
650 "# flood messages transmitted", 638 "# flood messages transmitted",
651 1, 639 1,
652 GNUNET_NO); 640 GNUNET_NO);
653#if ENABLE_NSE_HISTOGRAM 641#if ENABLE_NSE_HISTOGRAM
654 peer_entry->transmitted_messages++; 642 peer_entry->transmitted_messages++;
655 peer_entry->last_transmitted_size 643 peer_entry->last_transmitted_size =
656 = ntohl(size_estimate_messages[idx].matching_bits); 644 ntohl (size_estimate_messages[idx].matching_bits);
657#endif 645#endif
658 env = GNUNET_MQ_msg_copy (&size_estimate_messages[idx].header); 646 env = GNUNET_MQ_msg_copy (&size_estimate_messages[idx].header);
659 GNUNET_MQ_send (peer_entry->mq, 647 GNUNET_MQ_send (peer_entry->mq, env);
660 env);
661} 648}
662 649
663 650
@@ -673,9 +660,7 @@ update_network_size_estimate ()
673 struct GNUNET_NSE_ClientMessage em; 660 struct GNUNET_NSE_ClientMessage em;
674 661
675 setup_estimate_message (&em); 662 setup_estimate_message (&em);
676 GNUNET_notification_context_broadcast (nc, 663 GNUNET_notification_context_broadcast (nc, &em.header, GNUNET_YES);
677 &em.header,
678 GNUNET_YES);
679} 664}
680 665
681 666
@@ -687,36 +672,31 @@ update_network_size_estimate ()
687 * @param ts timestamp to use 672 * @param ts timestamp to use
688 */ 673 */
689static void 674static void
690setup_flood_message (unsigned int slot, 675setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
691 struct GNUNET_TIME_Absolute ts)
692{ 676{
693 struct GNUNET_NSE_FloodMessage *fm; 677 struct GNUNET_NSE_FloodMessage *fm;
694 uint32_t matching_bits; 678 uint32_t matching_bits;
695 679
696 matching_bits = get_matching_bits (ts, 680 matching_bits = get_matching_bits (ts, &my_identity);
697 &my_identity);
698 fm = &size_estimate_messages[slot]; 681 fm = &size_estimate_messages[slot];
699 fm->header.size = htons (sizeof (struct GNUNET_NSE_FloodMessage)); 682 fm->header.size = htons (sizeof (struct GNUNET_NSE_FloodMessage));
700 fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD); 683 fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD);
701 fm->hop_count = htonl (0); 684 fm->hop_count = htonl (0);
702 fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND); 685 fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND);
703 fm->purpose.size = 686 fm->purpose.size =
704 htonl (sizeof (struct GNUNET_NSE_FloodMessage) - 687 htonl (sizeof (struct GNUNET_NSE_FloodMessage) -
705 sizeof (struct GNUNET_MessageHeader) - sizeof (uint32_t) - 688 sizeof (struct GNUNET_MessageHeader) - sizeof (uint32_t) -
706 sizeof (struct GNUNET_CRYPTO_EddsaSignature)); 689 sizeof (struct GNUNET_CRYPTO_EddsaSignature));
707 fm->matching_bits = htonl (matching_bits); 690 fm->matching_bits = htonl (matching_bits);
708 fm->timestamp = GNUNET_TIME_absolute_hton (ts); 691 fm->timestamp = GNUNET_TIME_absolute_hton (ts);
709 fm->origin = my_identity; 692 fm->origin = my_identity;
710 fm->proof_of_work = my_proof; 693 fm->proof_of_work = my_proof;
711 if (nse_work_required > 0) 694 if (nse_work_required > 0)
712 GNUNET_assert (GNUNET_OK == 695 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key,
713 GNUNET_CRYPTO_eddsa_sign (my_private_key, 696 &fm->purpose,
714 &fm->purpose, 697 &fm->signature));
715 &fm->signature));
716 else 698 else
717 memset (&fm->signature, 699 memset (&fm->signature, 0, sizeof (fm->signature));
718 0,
719 sizeof (fm->signature));
720} 700}
721 701
722 702
@@ -731,8 +711,8 @@ setup_flood_message (unsigned int slot,
731 */ 711 */
732static int 712static int
733schedule_current_round (void *cls, 713schedule_current_round (void *cls,
734 const struct GNUNET_PeerIdentity * key, 714 const struct GNUNET_PeerIdentity *key,
735 void *value) 715 void *value)
736{ 716{
737 struct NSEPeerEntry *peer_entry = value; 717 struct NSEPeerEntry *peer_entry = value;
738 struct GNUNET_TIME_Relative delay; 718 struct GNUNET_TIME_Relative delay;
@@ -744,20 +724,18 @@ schedule_current_round (void *cls,
744 } 724 }
745#if ENABLE_NSE_HISTOGRAM 725#if ENABLE_NSE_HISTOGRAM
746 if (peer_entry->received_messages > 1) 726 if (peer_entry->received_messages > 1)
747 GNUNET_STATISTICS_update(stats, 727 GNUNET_STATISTICS_update (stats,
748 "# extra messages", 728 "# extra messages",
749 peer_entry->received_messages - 1, 729 peer_entry->received_messages - 1,
750 GNUNET_NO); 730 GNUNET_NO);
751 peer_entry->transmitted_messages = 0; 731 peer_entry->transmitted_messages = 0;
752 peer_entry->last_transmitted_size = 0; 732 peer_entry->last_transmitted_size = 0;
753 peer_entry->received_messages = 0; 733 peer_entry->received_messages = 0;
754#endif 734#endif
755 delay = 735 delay =
756 get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0); 736 get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0);
757 peer_entry->transmit_task = 737 peer_entry->transmit_task =
758 GNUNET_SCHEDULER_add_delayed (delay, 738 GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
759 &transmit_task_cb,
760 peer_entry);
761 return GNUNET_OK; 739 return GNUNET_OK;
762} 740}
763 741
@@ -779,9 +757,7 @@ update_flood_message (void *cls)
779 { 757 {
780 /* somehow run early, delay more */ 758 /* somehow run early, delay more */
781 flood_task = 759 flood_task =
782 GNUNET_SCHEDULER_add_delayed (offset, 760 GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL);
783 &update_flood_message,
784 NULL);
785 return; 761 return;
786 } 762 }
787 estimate_index = (estimate_index + 1) % HISTORY_SIZE; 763 estimate_index = (estimate_index + 1) % HISTORY_SIZE;
@@ -789,32 +765,27 @@ update_flood_message (void *cls)
789 estimate_count++; 765 estimate_count++;
790 current_timestamp = next_timestamp; 766 current_timestamp = next_timestamp;
791 next_timestamp = 767 next_timestamp =
792 GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval); 768 GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval);
793 if ( (current_timestamp.abs_value_us == 769 if ((current_timestamp.abs_value_us ==
794 GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) && 770 GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) &&
795 (get_matching_bits (current_timestamp, &my_identity) < 771 (get_matching_bits (current_timestamp, &my_identity) <
796 ntohl(next_message.matching_bits)) ) 772 ntohl (next_message.matching_bits)))
797 { 773 {
798 /* we received a message for this round way early, use it! */ 774 /* we received a message for this round way early, use it! */
799 size_estimate_messages[estimate_index] = next_message; 775 size_estimate_messages[estimate_index] = next_message;
800 size_estimate_messages[estimate_index].hop_count = 776 size_estimate_messages[estimate_index].hop_count =
801 htonl (1 + ntohl (next_message.hop_count)); 777 htonl (1 + ntohl (next_message.hop_count));
802 } 778 }
803 else 779 else
804 setup_flood_message (estimate_index, 780 setup_flood_message (estimate_index, current_timestamp);
805 current_timestamp); 781 next_message.matching_bits = htonl (0); /* reset for 'next' round */
806 next_message.matching_bits = htonl (0); /* reset for 'next' round */
807 hop_count_max = 0; 782 hop_count_max = 0;
808 for (i = 0; i < HISTORY_SIZE; i++) 783 for (i = 0; i < HISTORY_SIZE; i++)
809 hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), 784 hop_count_max =
810 hop_count_max); 785 GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max);
811 GNUNET_CONTAINER_multipeermap_iterate (peers, 786 GNUNET_CONTAINER_multipeermap_iterate (peers, &schedule_current_round, NULL);
812 &schedule_current_round, 787 flood_task =
813 NULL); 788 GNUNET_SCHEDULER_add_at (next_timestamp, &update_flood_message, NULL);
814 flood_task
815 = GNUNET_SCHEDULER_add_at (next_timestamp,
816 &update_flood_message,
817 NULL);
818} 789}
819 790
820 791
@@ -830,8 +801,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash)
830 unsigned int hash_count; 801 unsigned int hash_count;
831 802
832 hash_count = 0; 803 hash_count = 0;
833 while (0 == GNUNET_CRYPTO_hash_get_bit (hash, 804 while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
834 hash_count))
835 hash_count++; 805 hash_count++;
836 return hash_count; 806 return hash_count;
837} 807}
@@ -853,17 +823,13 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey,
853 sizeof (val)] GNUNET_ALIGN; 823 sizeof (val)] GNUNET_ALIGN;
854 struct GNUNET_HashCode result; 824 struct GNUNET_HashCode result;
855 825
856 GNUNET_memcpy (buf, 826 GNUNET_memcpy (buf, &val, sizeof (val));
857 &val,
858 sizeof (val));
859 GNUNET_memcpy (&buf[sizeof (val)], 827 GNUNET_memcpy (&buf[sizeof (val)],
860 pkey, 828 pkey,
861 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); 829 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
862 pow_hash (buf, 830 pow_hash (buf, sizeof (buf), &result);
863 sizeof (buf), 831 return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES
864 &result); 832 : GNUNET_NO;
865 return (count_leading_zeroes (&result) >=
866 nse_work_required) ? GNUNET_YES : GNUNET_NO;
867} 833}
868 834
869 835
@@ -876,20 +842,14 @@ write_proof ()
876 char *proof; 842 char *proof;
877 843
878 if (GNUNET_OK != 844 if (GNUNET_OK !=
879 GNUNET_CONFIGURATION_get_value_filename (cfg, 845 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof))
880 "NSE",
881 "PROOFFILE",
882 &proof))
883 return; 846 return;
884 if (sizeof (my_proof) != 847 if (sizeof (my_proof) != GNUNET_DISK_fn_write (proof,
885 GNUNET_DISK_fn_write (proof, 848 &my_proof,
886 &my_proof, 849 sizeof (my_proof),
887 sizeof (my_proof), 850 GNUNET_DISK_PERM_USER_READ |
888 GNUNET_DISK_PERM_USER_READ | 851 GNUNET_DISK_PERM_USER_WRITE))
889 GNUNET_DISK_PERM_USER_WRITE)) 852 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof);
890 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
891 "write",
892 proof);
893 GNUNET_free (proof); 853 GNUNET_free (proof);
894} 854}
895 855
@@ -910,8 +870,9 @@ find_proof (void *cls)
910 unsigned int i; 870 unsigned int i;
911 871
912 proof_task = NULL; 872 proof_task = NULL;
913 GNUNET_memcpy (&buf[sizeof (uint64_t)], &my_identity, 873 GNUNET_memcpy (&buf[sizeof (uint64_t)],
914 sizeof (struct GNUNET_PeerIdentity)); 874 &my_identity,
875 sizeof (struct GNUNET_PeerIdentity));
915 i = 0; 876 i = 0;
916 counter = my_proof; 877 counter = my_proof;
917 while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) 878 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
@@ -921,7 +882,8 @@ find_proof (void *cls)
921 if (nse_work_required <= count_leading_zeroes (&result)) 882 if (nse_work_required <= count_leading_zeroes (&result))
922 { 883 {
923 my_proof = counter; 884 my_proof = counter;
924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof of work found: %llu!\n", 885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
886 "Proof of work found: %llu!\n",
925 (unsigned long long) GNUNET_ntohll (counter)); 887 (unsigned long long) GNUNET_ntohll (counter));
926 write_proof (); 888 write_proof ();
927 setup_flood_message (estimate_index, current_timestamp); 889 setup_flood_message (estimate_index, current_timestamp);
@@ -944,9 +906,10 @@ find_proof (void *cls)
944 my_proof = counter; 906 my_proof = counter;
945 } 907 }
946 proof_task = 908 proof_task =
947 GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, 909 GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
948 GNUNET_SCHEDULER_PRIORITY_IDLE, 910 GNUNET_SCHEDULER_PRIORITY_IDLE,
949 &find_proof, NULL); 911 &find_proof,
912 NULL);
950} 913}
951 914
952 915
@@ -962,23 +925,22 @@ find_proof (void *cls)
962static int 925static int
963verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood) 926verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
964{ 927{
965 if (GNUNET_YES != 928 if (GNUNET_YES != check_proof_of_work (&incoming_flood->origin.public_key,
966 check_proof_of_work (&incoming_flood->origin.public_key, 929 incoming_flood->proof_of_work))
967 incoming_flood->proof_of_work))
968 { 930 {
969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
970 "Proof of work invalid: %llu!\n", 932 "Proof of work invalid: %llu!\n",
971 (unsigned long long) 933 (unsigned long long) GNUNET_ntohll (
972 GNUNET_ntohll (incoming_flood->proof_of_work)); 934 incoming_flood->proof_of_work));
973 GNUNET_break_op (0); 935 GNUNET_break_op (0);
974 return GNUNET_NO; 936 return GNUNET_NO;
975 } 937 }
976 if ((nse_work_required > 0) && 938 if ((nse_work_required > 0) &&
977 (GNUNET_OK != 939 (GNUNET_OK !=
978 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND, 940 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND,
979 &incoming_flood->purpose, 941 &incoming_flood->purpose,
980 &incoming_flood->signature, 942 &incoming_flood->signature,
981 &incoming_flood->origin.public_key))) 943 &incoming_flood->origin.public_key)))
982 { 944 {
983 GNUNET_break_op (0); 945 GNUNET_break_op (0);
984 return GNUNET_NO; 946 return GNUNET_NO;
@@ -998,15 +960,15 @@ verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
998 */ 960 */
999static int 961static int
1000update_flood_times (void *cls, 962update_flood_times (void *cls,
1001 const struct GNUNET_PeerIdentity *key, 963 const struct GNUNET_PeerIdentity *key,
1002 void *value) 964 void *value)
1003{ 965{
1004 struct NSEPeerEntry *exclude = cls; 966 struct NSEPeerEntry *exclude = cls;
1005 struct NSEPeerEntry *peer_entry = value; 967 struct NSEPeerEntry *peer_entry = value;
1006 struct GNUNET_TIME_Relative delay; 968 struct GNUNET_TIME_Relative delay;
1007 969
1008 if (peer_entry == exclude) 970 if (peer_entry == exclude)
1009 return GNUNET_OK; /* trigger of the update */ 971 return GNUNET_OK; /* trigger of the update */
1010 if (GNUNET_NO == peer_entry->previous_round) 972 if (GNUNET_NO == peer_entry->previous_round)
1011 { 973 {
1012 /* still stuck in previous round, no point to update, check that 974 /* still stuck in previous round, no point to update, check that
@@ -1024,8 +986,7 @@ update_flood_times (void *cls,
1024 } 986 }
1025 delay = get_transmit_delay (0); 987 delay = get_transmit_delay (0);
1026 peer_entry->transmit_task = 988 peer_entry->transmit_task =
1027 GNUNET_SCHEDULER_add_delayed (delay, 989 GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
1028 &transmit_task_cb, peer_entry);
1029 return GNUNET_OK; 990 return GNUNET_OK;
1030} 991}
1031 992
@@ -1038,7 +999,7 @@ update_flood_times (void *cls,
1038 */ 999 */
1039static void 1000static void
1040handle_p2p_estimate (void *cls, 1001handle_p2p_estimate (void *cls,
1041 const struct GNUNET_NSE_FloodMessage *incoming_flood) 1002 const struct GNUNET_NSE_FloodMessage *incoming_flood)
1042{ 1003{
1043 struct NSEPeerEntry *peer_entry = cls; 1004 struct NSEPeerEntry *peer_entry = cls;
1044 struct GNUNET_TIME_Absolute ts; 1005 struct GNUNET_TIME_Absolute ts;
@@ -1049,17 +1010,14 @@ handle_p2p_estimate (void *cls,
1049 { 1010 {
1050 uint64_t t; 1011 uint64_t t;
1051 1012
1052 t = GNUNET_TIME_absolute_get().abs_value_us; 1013 t = GNUNET_TIME_absolute_get ().abs_value_us;
1053 if (NULL != lh) 1014 if (NULL != lh)
1054 GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof (uint64_t)); 1015 GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof (uint64_t));
1055 if (NULL != histogram) 1016 if (NULL != histogram)
1056 GNUNET_BIO_write_int64 (histogram, t); 1017 GNUNET_BIO_write_int64 (histogram, t);
1057 } 1018 }
1058#endif 1019#endif
1059 GNUNET_STATISTICS_update (stats, 1020 GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO);
1060 "# flood messages received",
1061 1,
1062 GNUNET_NO);
1063 matching_bits = ntohl (incoming_flood->matching_bits); 1021 matching_bits = ntohl (incoming_flood->matching_bits);
1064#if DEBUG_NSE 1022#if DEBUG_NSE
1065 { 1023 {
@@ -1068,19 +1026,17 @@ handle_p2p_estimate (void *cls,
1068 struct GNUNET_PeerIdentity os; 1026 struct GNUNET_PeerIdentity os;
1069 1027
1070 GNUNET_snprintf (origin, 1028 GNUNET_snprintf (origin,
1071 sizeof (origin), 1029 sizeof (origin),
1072 "%s", 1030 "%s",
1073 GNUNET_i2s (&incoming_flood->origin)); 1031 GNUNET_i2s (&incoming_flood->origin));
1074 GNUNET_snprintf (pred, 1032 GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer_entry->id));
1075 sizeof (pred),
1076 "%s",
1077 GNUNET_i2s (peer_entry->id));
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 "Flood at %s from `%s' via `%s' at `%s' with bits %u\n", 1034 "Flood at %s from `%s' via `%s' at `%s' with bits %u\n",
1080 GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)), 1035 GNUNET_STRINGS_absolute_time_to_string (
1036 GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)),
1081 origin, 1037 origin,
1082 pred, 1038 pred,
1083 GNUNET_i2s (&my_identity), 1039 GNUNET_i2s (&my_identity),
1084 (unsigned int) matching_bits); 1040 (unsigned int) matching_bits);
1085 } 1041 }
1086#endif 1042#endif
@@ -1089,10 +1045,7 @@ handle_p2p_estimate (void *cls,
1089 peer_entry->received_messages++; 1045 peer_entry->received_messages++;
1090 if (peer_entry->transmitted_messages > 0 && 1046 if (peer_entry->transmitted_messages > 0 &&
1091 peer_entry->last_transmitted_size >= matching_bits) 1047 peer_entry->last_transmitted_size >= matching_bits)
1092 GNUNET_STATISTICS_update(stats, 1048 GNUNET_STATISTICS_update (stats, "# cross messages", 1, GNUNET_NO);
1093 "# cross messages",
1094 1,
1095 GNUNET_NO);
1096#endif 1049#endif
1097 1050
1098 ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); 1051 ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp);
@@ -1104,9 +1057,8 @@ handle_p2p_estimate (void *cls,
1104 else if (ts.abs_value_us == next_timestamp.abs_value_us) 1057 else if (ts.abs_value_us == next_timestamp.abs_value_us)
1105 { 1058 {
1106 if (matching_bits <= ntohl (next_message.matching_bits)) 1059 if (matching_bits <= ntohl (next_message.matching_bits))
1107 return; /* ignore, simply too early/late */ 1060 return; /* ignore, simply too early/late */
1108 if (GNUNET_YES != 1061 if (GNUNET_YES != verify_message_crypto (incoming_flood))
1109 verify_message_crypto (incoming_flood))
1110 { 1062 {
1111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1063 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1112 "Peer %s is likely ill-configured!\n", 1064 "Peer %s is likely ill-configured!\n",
@@ -1121,21 +1073,18 @@ handle_p2p_estimate (void *cls,
1121 { 1073 {
1122 GNUNET_STATISTICS_update (stats, 1074 GNUNET_STATISTICS_update (stats,
1123 "# flood messages discarded (clock skew too large)", 1075 "# flood messages discarded (clock skew too large)",
1124 1, GNUNET_NO); 1076 1,
1077 GNUNET_NO);
1125 return; 1078 return;
1126 } 1079 }
1127 if (0 == (GNUNET_memcmp (peer_entry->id, 1080 if (0 == (GNUNET_memcmp (peer_entry->id, &my_identity)))
1128 &my_identity)))
1129 { 1081 {
1130 /* send to self, update our own estimate IF this also comes from us! */ 1082 /* send to self, update our own estimate IF this also comes from us! */
1131 if (0 == 1083 if (0 == GNUNET_memcmp (&incoming_flood->origin, &my_identity))
1132 GNUNET_memcmp (&incoming_flood->origin,
1133 &my_identity))
1134 update_network_size_estimate (); 1084 update_network_size_estimate ();
1135 return; 1085 return;
1136 } 1086 }
1137 if (matching_bits == 1087 if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits))
1138 ntohl (size_estimate_messages[idx].matching_bits))
1139 { 1088 {
1140 /* Cancel transmission in the other direction, as this peer clearly has 1089 /* Cancel transmission in the other direction, as this peer clearly has
1141 up-to-date information already. Even if we didn't talk to this peer in 1090 up-to-date information already. Even if we didn't talk to this peer in
@@ -1159,26 +1108,23 @@ handle_p2p_estimate (void *cls,
1159 } 1108 }
1160 if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits)) 1109 if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits))
1161 { 1110 {
1162 if ( (idx < estimate_index) && 1111 if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES))
1163 (peer_entry->previous_round == GNUNET_YES))
1164 { 1112 {
1165 peer_entry->previous_round = GNUNET_NO; 1113 peer_entry->previous_round = GNUNET_NO;
1166 } 1114 }
1167 /* push back our result now, that peer is spreading bad information... */ 1115 /* push back our result now, that peer is spreading bad information... */
1168 if (NULL != peer_entry->transmit_task) 1116 if (NULL != peer_entry->transmit_task)
1169 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 1117 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1170 peer_entry->transmit_task 1118 peer_entry->transmit_task =
1171 = GNUNET_SCHEDULER_add_now (&transmit_task_cb, 1119 GNUNET_SCHEDULER_add_now (&transmit_task_cb, peer_entry);
1172 peer_entry);
1173 /* Not closer than our most recent message, no need to do work here */ 1120 /* Not closer than our most recent message, no need to do work here */
1174 GNUNET_STATISTICS_update (stats, 1121 GNUNET_STATISTICS_update (stats,
1175 "# flood messages ignored (had closer already)", 1122 "# flood messages ignored (had closer already)",
1176 1, 1123 1,
1177 GNUNET_NO); 1124 GNUNET_NO);
1178 return; 1125 return;
1179 } 1126 }
1180 if (GNUNET_YES != 1127 if (GNUNET_YES != verify_message_crypto (incoming_flood))
1181 verify_message_crypto (incoming_flood))
1182 { 1128 {
1183 GNUNET_break_op (0); 1129 GNUNET_break_op (0);
1184 return; 1130 return;
@@ -1200,20 +1146,20 @@ handle_p2p_estimate (void *cls,
1200 } 1146 }
1201 size_estimate_messages[idx] = *incoming_flood; 1147 size_estimate_messages[idx] = *incoming_flood;
1202 size_estimate_messages[idx].hop_count = 1148 size_estimate_messages[idx].hop_count =
1203 htonl (ntohl (incoming_flood->hop_count) + 1); 1149 htonl (ntohl (incoming_flood->hop_count) + 1);
1204 hop_count_max = 1150 hop_count_max =
1205 GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, 1151 GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max);
1206 hop_count_max);
1207 GNUNET_STATISTICS_set (stats, 1152 GNUNET_STATISTICS_set (stats,
1208 "# estimated network diameter", 1153 "# estimated network diameter",
1209 hop_count_max, GNUNET_NO); 1154 hop_count_max,
1155 GNUNET_NO);
1210 1156
1211 /* have a new, better size estimate, inform clients */ 1157 /* have a new, better size estimate, inform clients */
1212 update_network_size_estimate (); 1158 update_network_size_estimate ();
1213 1159
1214 /* flood to rest */ 1160 /* flood to rest */
1215 GNUNET_CONTAINER_multipeermap_iterate (peers, 1161 GNUNET_CONTAINER_multipeermap_iterate (peers,
1216 &update_flood_times, 1162 &update_flood_times,
1217 peer_entry); 1163 peer_entry);
1218} 1164}
1219 1165
@@ -1227,40 +1173,31 @@ handle_p2p_estimate (void *cls,
1227 */ 1173 */
1228static void * 1174static void *
1229handle_core_connect (void *cls, 1175handle_core_connect (void *cls,
1230 const struct GNUNET_PeerIdentity *peer, 1176 const struct GNUNET_PeerIdentity *peer,
1231 struct GNUNET_MQ_Handle *mq) 1177 struct GNUNET_MQ_Handle *mq)
1232{ 1178{
1233 struct NSEPeerEntry *peer_entry; 1179 struct NSEPeerEntry *peer_entry;
1234 uint64_t flags;
1235 const void *extra;
1236 1180
1237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1238 "Peer `%s' connected to us\n", 1182 "Peer `%s' connected to us\n",
1239 GNUNET_i2s (peer)); 1183 GNUNET_i2s (peer));
1240 /* set our default transmission options */ 1184 /* set our default transmission options */
1241 extra = GNUNET_CORE_get_mq_options (GNUNET_NO, 1185 GNUNET_MQ_set_options (mq, NSE_PRIORITY);
1242 NSE_PRIORITY,
1243 &flags);
1244 GNUNET_MQ_set_options (mq,
1245 flags,
1246 extra);
1247 /* create our peer entry for this peer */ 1186 /* create our peer entry for this peer */
1248 peer_entry = GNUNET_new (struct NSEPeerEntry); 1187 peer_entry = GNUNET_new (struct NSEPeerEntry);
1249 peer_entry->id = peer; 1188 peer_entry->id = peer;
1250 peer_entry->mq = mq; 1189 peer_entry->mq = mq;
1251 GNUNET_assert (GNUNET_OK == 1190 GNUNET_assert (GNUNET_OK ==
1252 GNUNET_CONTAINER_multipeermap_put (peers, 1191 GNUNET_CONTAINER_multipeermap_put (
1253 peer_entry->id, 1192 peers,
1254 peer_entry, 1193 peer_entry->id,
1255 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1194 peer_entry,
1195 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1256 peer_entry->transmit_task = 1196 peer_entry->transmit_task =
1257 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1), 1197 GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1),
1258 &transmit_task_cb, 1198 &transmit_task_cb,
1259 peer_entry); 1199 peer_entry);
1260 GNUNET_STATISTICS_update (stats, 1200 GNUNET_STATISTICS_update (stats, "# peers connected", 1, GNUNET_NO);
1261 "# peers connected",
1262 1,
1263 GNUNET_NO);
1264 return peer_entry; 1201 return peer_entry;
1265} 1202}
1266 1203
@@ -1275,28 +1212,23 @@ handle_core_connect (void *cls,
1275 */ 1212 */
1276static void 1213static void
1277handle_core_disconnect (void *cls, 1214handle_core_disconnect (void *cls,
1278 const struct GNUNET_PeerIdentity *peer, 1215 const struct GNUNET_PeerIdentity *peer,
1279 void *internal_cls) 1216 void *internal_cls)
1280{ 1217{
1281 struct NSEPeerEntry *pos = internal_cls; 1218 struct NSEPeerEntry *pos = internal_cls;
1282 1219
1283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1284 "Peer `%s' disconnected from us\n", 1221 "Peer `%s' disconnected from us\n",
1285 GNUNET_i2s (peer)); 1222 GNUNET_i2s (peer));
1286 GNUNET_assert (GNUNET_YES == 1223 GNUNET_assert (GNUNET_YES ==
1287 GNUNET_CONTAINER_multipeermap_remove (peers, 1224 GNUNET_CONTAINER_multipeermap_remove (peers, peer, pos));
1288 peer,
1289 pos));
1290 if (NULL != pos->transmit_task) 1225 if (NULL != pos->transmit_task)
1291 { 1226 {
1292 GNUNET_SCHEDULER_cancel (pos->transmit_task); 1227 GNUNET_SCHEDULER_cancel (pos->transmit_task);
1293 pos->transmit_task = NULL; 1228 pos->transmit_task = NULL;
1294 } 1229 }
1295 GNUNET_free (pos); 1230 GNUNET_free (pos);
1296 GNUNET_STATISTICS_update (stats, 1231 GNUNET_STATISTICS_update (stats, "# peers connected", -1, GNUNET_NO);
1297 "# peers connected",
1298 -1,
1299 GNUNET_NO);
1300} 1232}
1301 1233
1302 1234
@@ -1309,8 +1241,7 @@ handle_core_disconnect (void *cls,
1309 * @param size the amount of data sent (ignored) 1241 * @param size the amount of data sent (ignored)
1310 */ 1242 */
1311static void 1243static void
1312flush_comp_cb (void *cls, 1244flush_comp_cb (void *cls, size_t size)
1313 size_t size)
1314{ 1245{
1315 GNUNET_TESTBED_LOGGER_disconnect (lh); 1246 GNUNET_TESTBED_LOGGER_disconnect (lh);
1316 lh = NULL; 1247 lh = NULL;
@@ -1335,7 +1266,7 @@ shutdown_task (void *cls)
1335 { 1266 {
1336 GNUNET_SCHEDULER_cancel (proof_task); 1267 GNUNET_SCHEDULER_cancel (proof_task);
1337 proof_task = NULL; 1268 proof_task = NULL;
1338 write_proof (); /* remember progress */ 1269 write_proof (); /* remember progress */
1339 } 1270 }
1340 if (NULL != nc) 1271 if (NULL != nc)
1341 { 1272 {
@@ -1370,9 +1301,7 @@ shutdown_task (void *cls)
1370 } 1301 }
1371 if (NULL != lh) 1302 if (NULL != lh)
1372 { 1303 {
1373 GNUNET_TESTBED_LOGGER_flush (lh, 1304 GNUNET_TESTBED_LOGGER_flush (lh, &flush_comp_cb, NULL);
1374 &flush_comp_cb,
1375 NULL);
1376 } 1305 }
1377 if (NULL != histogram) 1306 if (NULL != histogram)
1378 { 1307 {
@@ -1390,48 +1319,37 @@ shutdown_task (void *cls)
1390 * @param identity the public identity of this peer 1319 * @param identity the public identity of this peer
1391 */ 1320 */
1392static void 1321static void
1393core_init (void *cls, 1322core_init (void *cls, const struct GNUNET_PeerIdentity *identity)
1394 const struct GNUNET_PeerIdentity *identity)
1395{ 1323{
1396 struct GNUNET_TIME_Absolute now; 1324 struct GNUNET_TIME_Absolute now;
1397 struct GNUNET_TIME_Absolute prev_time; 1325 struct GNUNET_TIME_Absolute prev_time;
1398 1326
1399 if (NULL == identity) 1327 if (NULL == identity)
1400 { 1328 {
1401 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n");
1402 "Connection to core FAILED!\n");
1403 GNUNET_SCHEDULER_shutdown (); 1330 GNUNET_SCHEDULER_shutdown ();
1404 return; 1331 return;
1405 } 1332 }
1406 GNUNET_assert (0 == 1333 GNUNET_assert (0 == GNUNET_memcmp (&my_identity, identity));
1407 GNUNET_memcmp (&my_identity,
1408 identity));
1409 now = GNUNET_TIME_absolute_get (); 1334 now = GNUNET_TIME_absolute_get ();
1410 current_timestamp.abs_value_us = 1335 current_timestamp.abs_value_us =
1411 (now.abs_value_us / gnunet_nse_interval.rel_value_us) * 1336 (now.abs_value_us / gnunet_nse_interval.rel_value_us) *
1412 gnunet_nse_interval.rel_value_us; 1337 gnunet_nse_interval.rel_value_us;
1413 next_timestamp = 1338 next_timestamp =
1414 GNUNET_TIME_absolute_add (current_timestamp, 1339 GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval);
1415 gnunet_nse_interval);
1416 estimate_index = HISTORY_SIZE - 1; 1340 estimate_index = HISTORY_SIZE - 1;
1417 estimate_count = 0; 1341 estimate_count = 0;
1418 if (GNUNET_YES == 1342 if (GNUNET_YES == check_proof_of_work (&my_identity.public_key, my_proof))
1419 check_proof_of_work (&my_identity.public_key,
1420 my_proof))
1421 { 1343 {
1422 int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE; 1344 int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
1423 prev_time.abs_value_us = 1345 prev_time.abs_value_us =
1424 current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us; 1346 current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us;
1425 setup_flood_message (idx, 1347 setup_flood_message (idx, prev_time);
1426 prev_time); 1348 setup_flood_message (estimate_index, current_timestamp);
1427 setup_flood_message (estimate_index,
1428 current_timestamp);
1429 estimate_count++; 1349 estimate_count++;
1430 } 1350 }
1431 flood_task 1351 flood_task =
1432 = GNUNET_SCHEDULER_add_at (next_timestamp, 1352 GNUNET_SCHEDULER_add_at (next_timestamp, &update_flood_message, NULL);
1433 &update_flood_message,
1434 NULL);
1435} 1353}
1436 1354
1437 1355
@@ -1445,14 +1363,12 @@ core_init (void *cls,
1445 * #GNUNET_SYSERR if the configuration is invalid 1363 * #GNUNET_SYSERR if the configuration is invalid
1446 */ 1364 */
1447static void 1365static void
1448status_cb (void *cls, 1366status_cb (void *cls, int status)
1449 int status)
1450{ 1367{
1451 logger_test = NULL; 1368 logger_test = NULL;
1452 if (GNUNET_YES != status) 1369 if (GNUNET_YES != status)
1453 { 1370 {
1454 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1371 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n");
1455 "Testbed logger not running\n");
1456 return; 1372 return;
1457 } 1373 }
1458 if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg))) 1374 if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg)))
@@ -1477,59 +1393,49 @@ run (void *cls,
1477 const struct GNUNET_CONFIGURATION_Handle *c, 1393 const struct GNUNET_CONFIGURATION_Handle *c,
1478 struct GNUNET_SERVICE_Handle *service) 1394 struct GNUNET_SERVICE_Handle *service)
1479{ 1395{
1480 struct GNUNET_MQ_MessageHandler core_handlers[] = { 1396 struct GNUNET_MQ_MessageHandler core_handlers[] =
1481 GNUNET_MQ_hd_fixed_size (p2p_estimate, 1397 {GNUNET_MQ_hd_fixed_size (p2p_estimate,
1482 GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, 1398 GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD,
1483 struct GNUNET_NSE_FloodMessage, 1399 struct GNUNET_NSE_FloodMessage,
1484 NULL), 1400 NULL),
1485 GNUNET_MQ_handler_end () 1401 GNUNET_MQ_handler_end ()};
1486 };
1487 char *proof; 1402 char *proof;
1488 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 1403 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
1489 1404
1490 cfg = c; 1405 cfg = c;
1491 if (GNUNET_OK != 1406 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg,
1492 GNUNET_CONFIGURATION_get_value_time (cfg, 1407 "NSE",
1493 "NSE", 1408 "INTERVAL",
1494 "INTERVAL", 1409 &gnunet_nse_interval))
1495 &gnunet_nse_interval))
1496 { 1410 {
1497 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1411 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "INTERVAL");
1498 "NSE",
1499 "INTERVAL");
1500 GNUNET_SCHEDULER_shutdown (); 1412 GNUNET_SCHEDULER_shutdown ();
1501 return; 1413 return;
1502 } 1414 }
1503 if (GNUNET_OK != 1415 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg,
1504 GNUNET_CONFIGURATION_get_value_time (cfg, 1416 "NSE",
1505 "NSE", 1417 "WORKDELAY",
1506 "WORKDELAY", 1418 &proof_find_delay))
1507 &proof_find_delay))
1508 { 1419 {
1509 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1420 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKDELAY");
1510 "NSE",
1511 "WORKDELAY");
1512 GNUNET_SCHEDULER_shutdown (); 1421 GNUNET_SCHEDULER_shutdown ();
1513 return; 1422 return;
1514 } 1423 }
1515 if (GNUNET_OK != 1424 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
1516 GNUNET_CONFIGURATION_get_value_number (cfg, 1425 "NSE",
1517 "NSE", 1426 "WORKBITS",
1518 "WORKBITS", 1427 &nse_work_required))
1519 &nse_work_required))
1520 { 1428 {
1521 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1429 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS");
1522 "NSE",
1523 "WORKBITS");
1524 GNUNET_SCHEDULER_shutdown (); 1430 GNUNET_SCHEDULER_shutdown ();
1525 return; 1431 return;
1526 } 1432 }
1527 if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) 1433 if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8)
1528 { 1434 {
1529 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 1435 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
1530 "NSE", 1436 "NSE",
1531 "WORKBITS", 1437 "WORKBITS",
1532 _("Value is too large.\n")); 1438 _ ("Value is too large.\n"));
1533 GNUNET_SCHEDULER_shutdown (); 1439 GNUNET_SCHEDULER_shutdown ();
1534 return; 1440 return;
1535 } 1441 }
@@ -1539,49 +1445,38 @@ run (void *cls,
1539 char *histogram_dir; 1445 char *histogram_dir;
1540 char *histogram_fn; 1446 char *histogram_fn;
1541 1447
1542 if (GNUNET_OK == 1448 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
1543 GNUNET_CONFIGURATION_get_value_filename (cfg, 1449 "NSE",
1544 "NSE", 1450 "HISTOGRAM_DIR",
1545 "HISTOGRAM_DIR", 1451 &histogram_dir))
1546 &histogram_dir))
1547 { 1452 {
1548 GNUNET_assert (0 < GNUNET_asprintf (&histogram_fn, 1453 GNUNET_assert (
1549 "%s/timestamps", 1454 0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir));
1550 histogram_dir));
1551 GNUNET_free (histogram_dir); 1455 GNUNET_free (histogram_dir);
1552 histogram = GNUNET_BIO_write_open (histogram_fn); 1456 histogram = GNUNET_BIO_write_open (histogram_fn);
1553 if (NULL == histogram) 1457 if (NULL == histogram)
1554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1458 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1555 "Unable to open histogram file `%s'\n", 1459 "Unable to open histogram file `%s'\n",
1556 histogram_fn); 1460 histogram_fn);
1557 GNUNET_free (histogram_fn); 1461 GNUNET_free (histogram_fn);
1558 } 1462 }
1559 logger_test = 1463 logger_test = GNUNET_CLIENT_service_test ("testbed-logger",
1560 GNUNET_CLIENT_service_test ("testbed-logger", 1464 cfg,
1561 cfg, 1465 GNUNET_TIME_UNIT_SECONDS,
1562 GNUNET_TIME_UNIT_SECONDS, 1466 &status_cb,
1563 &status_cb, 1467 NULL);
1564 NULL);
1565
1566 } 1468 }
1567#endif 1469#endif
1568 1470
1569 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1471 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1570 NULL);
1571 pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); 1472 pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
1572 GNUNET_assert (NULL != pk); 1473 GNUNET_assert (NULL != pk);
1573 my_private_key = pk; 1474 my_private_key = pk;
1574 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, 1475 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
1575 &my_identity.public_key);
1576 if (GNUNET_OK != 1476 if (GNUNET_OK !=
1577 GNUNET_CONFIGURATION_get_value_filename (cfg, 1477 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof))
1578 "NSE",
1579 "PROOFFILE",
1580 &proof))
1581 { 1478 {
1582 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1479 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE");
1583 "NSE",
1584 "PROOFFILE");
1585 GNUNET_free (my_private_key); 1480 GNUNET_free (my_private_key);
1586 my_private_key = NULL; 1481 my_private_key = NULL;
1587 GNUNET_SCHEDULER_shutdown (); 1482 GNUNET_SCHEDULER_shutdown ();
@@ -1589,33 +1484,30 @@ run (void *cls,
1589 } 1484 }
1590 if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || 1485 if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) ||
1591 (sizeof (my_proof) != 1486 (sizeof (my_proof) !=
1592 GNUNET_DISK_fn_read (proof, 1487 GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof))))
1593 &my_proof,
1594 sizeof (my_proof))))
1595 my_proof = 0; 1488 my_proof = 0;
1596 GNUNET_free (proof); 1489 GNUNET_free (proof);
1597 proof_task = 1490 proof_task =
1598 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1491 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1599 &find_proof, 1492 &find_proof,
1600 NULL); 1493 NULL);
1601 1494
1602 peers = GNUNET_CONTAINER_multipeermap_create (128, 1495 peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
1603 GNUNET_YES);
1604 nc = GNUNET_notification_context_create (1); 1496 nc = GNUNET_notification_context_create (1);
1605 /* Connect to core service and register core handlers */ 1497 /* Connect to core service and register core handlers */
1606 core_api = GNUNET_CORE_connect (cfg, /* Main configuration */ 1498 core_api =
1607 NULL, /* Closure passed to functions */ 1499 GNUNET_CORE_connect (cfg, /* Main configuration */
1608 &core_init, /* Call core_init once connected */ 1500 NULL, /* Closure passed to functions */
1609 &handle_core_connect, /* Handle connects */ 1501 &core_init, /* Call core_init once connected */
1610 &handle_core_disconnect, /* Handle disconnects */ 1502 &handle_core_connect, /* Handle connects */
1611 core_handlers); /* Register these handlers */ 1503 &handle_core_disconnect, /* Handle disconnects */
1504 core_handlers); /* Register these handlers */
1612 if (NULL == core_api) 1505 if (NULL == core_api)
1613 { 1506 {
1614 GNUNET_SCHEDULER_shutdown (); 1507 GNUNET_SCHEDULER_shutdown ();
1615 return; 1508 return;
1616 } 1509 }
1617 stats = GNUNET_STATISTICS_create ("nse", 1510 stats = GNUNET_STATISTICS_create ("nse", cfg);
1618 cfg);
1619} 1511}
1620 1512
1621 1513
@@ -1629,8 +1521,8 @@ run (void *cls,
1629 */ 1521 */
1630static void * 1522static void *
1631client_connect_cb (void *cls, 1523client_connect_cb (void *cls,
1632 struct GNUNET_SERVICE_Client *c, 1524 struct GNUNET_SERVICE_Client *c,
1633 struct GNUNET_MQ_Handle *mq) 1525 struct GNUNET_MQ_Handle *mq)
1634{ 1526{
1635 return c; 1527 return c;
1636} 1528}
@@ -1645,8 +1537,8 @@ client_connect_cb (void *cls,
1645 */ 1537 */
1646static void 1538static void
1647client_disconnect_cb (void *cls, 1539client_disconnect_cb (void *cls,
1648 struct GNUNET_SERVICE_Client *c, 1540 struct GNUNET_SERVICE_Client *c,
1649 void *internal_cls) 1541 void *internal_cls)
1650{ 1542{
1651 GNUNET_assert (c == internal_cls); 1543 GNUNET_assert (c == internal_cls);
1652} 1544}
@@ -1655,18 +1547,17 @@ client_disconnect_cb (void *cls,
1655/** 1547/**
1656 * Define "main" method using service macro. 1548 * Define "main" method using service macro.
1657 */ 1549 */
1658GNUNET_SERVICE_MAIN 1550GNUNET_SERVICE_MAIN ("nse",
1659("nse", 1551 GNUNET_SERVICE_OPTION_NONE,
1660 GNUNET_SERVICE_OPTION_NONE, 1552 &run,
1661 &run, 1553 &client_connect_cb,
1662 &client_connect_cb, 1554 &client_disconnect_cb,
1663 &client_disconnect_cb, 1555 NULL,
1664 NULL, 1556 GNUNET_MQ_hd_fixed_size (start,
1665 GNUNET_MQ_hd_fixed_size (start, 1557 GNUNET_MESSAGE_TYPE_NSE_START,
1666 GNUNET_MESSAGE_TYPE_NSE_START, 1558 struct GNUNET_MessageHeader,
1667 struct GNUNET_MessageHeader, 1559 NULL),
1668 NULL), 1560 GNUNET_MQ_handler_end ());
1669 GNUNET_MQ_handler_end ());
1670 1561
1671 1562
1672#if defined(LINUX) && defined(__GLIBC__) 1563#if defined(LINUX) && defined(__GLIBC__)
@@ -1675,8 +1566,7 @@ GNUNET_SERVICE_MAIN
1675/** 1566/**
1676 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1567 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1677 */ 1568 */
1678void __attribute__ ((constructor)) 1569void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
1679GNUNET_ARM_memory_init ()
1680{ 1570{
1681 mallopt (M_TRIM_THRESHOLD, 4 * 1024); 1571 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1682 mallopt (M_TOP_PAD, 1 * 1024); 1572 mallopt (M_TOP_PAD, 1 * 1024);
@@ -1685,5 +1575,4 @@ GNUNET_ARM_memory_init ()
1685#endif 1575#endif
1686 1576
1687 1577
1688
1689/* end of gnunet-service-nse.c */ 1578/* end of gnunet-service-nse.c */
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index e5734abb4..5a22ee0d2 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.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
@@ -51,12 +51,14 @@
51/** 51/**
52 * At what frequency do we sent HELLOs to a peer? 52 * At what frequency do we sent HELLOs to a peer?
53 */ 53 */
54#define HELLO_ADVERTISEMENT_MIN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 54#define HELLO_ADVERTISEMENT_MIN_FREQUENCY \
55 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
55 56
56/** 57/**
57 * After what time period do we expire the HELLO Bloom filter? 58 * After what time period do we expire the HELLO Bloom filter?
58 */ 59 */
59#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 60#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY \
61 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
60 62
61 63
62/** 64/**
@@ -116,7 +118,6 @@ struct Peer
116 * Is this peer listed here because it is a friend? 118 * Is this peer listed here because it is a friend?
117 */ 119 */
118 int is_friend; 120 int is_friend;
119
120}; 121};
121 122
122 123
@@ -216,15 +217,12 @@ static unsigned int friend_count;
216 * @return #GNUNET_OK if the connection is allowed 217 * @return #GNUNET_OK if the connection is allowed
217 */ 218 */
218static int 219static int
219blacklist_check (void *cls, 220blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid)
220 const struct GNUNET_PeerIdentity *pid)
221{ 221{
222 struct Peer *pos; 222 struct Peer *pos;
223 223
224 pos = GNUNET_CONTAINER_multipeermap_get (peers, 224 pos = GNUNET_CONTAINER_multipeermap_get (peers, pid);
225 pid); 225 if ((NULL != pos) && (GNUNET_YES == pos->is_friend))
226 if ( (NULL != pos) &&
227 (GNUNET_YES == pos->is_friend))
228 return GNUNET_OK; 226 return GNUNET_OK;
229 GNUNET_STATISTICS_update (stats, 227 GNUNET_STATISTICS_update (stats,
230 gettext_noop ("# peers blacklisted"), 228 gettext_noop ("# peers blacklisted"),
@@ -258,17 +256,13 @@ whitelist_peers ()
258 * @return #GNUNET_YES (always: continue to iterate) 256 * @return #GNUNET_YES (always: continue to iterate)
259 */ 257 */
260static int 258static int
261free_peer (void *cls, 259free_peer (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
262 const struct GNUNET_PeerIdentity * pid,
263 void *value)
264{ 260{
265 struct Peer *pos = value; 261 struct Peer *pos = value;
266 262
267 GNUNET_break (NULL == pos->mq); 263 GNUNET_break (NULL == pos->mq);
268 GNUNET_break (GNUNET_OK == 264 GNUNET_break (GNUNET_OK ==
269 GNUNET_CONTAINER_multipeermap_remove (peers, 265 GNUNET_CONTAINER_multipeermap_remove (peers, pid, pos));
270 pid,
271 pos));
272 if (NULL != pos->hello_delay_task) 266 if (NULL != pos->hello_delay_task)
273 { 267 {
274 GNUNET_SCHEDULER_cancel (pos->hello_delay_task); 268 GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
@@ -305,16 +299,13 @@ attempt_connect (struct Peer *pos)
305{ 299{
306 uint32_t strength; 300 uint32_t strength;
307 301
308 if (0 == 302 if (0 == GNUNET_memcmp (&my_identity, &pos->pid))
309 GNUNET_memcmp (&my_identity,
310 &pos->pid))
311 return; /* This is myself, nothing to do. */ 303 return; /* This is myself, nothing to do. */
312 if (connection_count < target_connection_count) 304 if (connection_count < target_connection_count)
313 strength = 1; 305 strength = 1;
314 else 306 else
315 strength = 0; 307 strength = 0;
316 if ( (friend_count < minimum_friend_count) || 308 if ((friend_count < minimum_friend_count) || (GNUNET_YES == friends_only))
317 (GNUNET_YES == friends_only) )
318 { 309 {
319 if (pos->is_friend) 310 if (pos->is_friend)
320 strength += 10; /* urgently needed */ 311 strength += 10; /* urgently needed */
@@ -343,9 +334,7 @@ attempt_connect (struct Peer *pos)
343 gettext_noop ("# connect requests issued to ATS"), 334 gettext_noop ("# connect requests issued to ATS"),
344 1, 335 1,
345 GNUNET_NO); 336 GNUNET_NO);
346 pos->sh = GNUNET_ATS_connectivity_suggest (ats, 337 pos->sh = GNUNET_ATS_connectivity_suggest (ats, &pos->pid, strength);
347 &pos->pid,
348 strength);
349 } 338 }
350} 339}
351 340
@@ -371,15 +360,14 @@ make_peer (const struct GNUNET_PeerIdentity *peer,
371 if (NULL != hello) 360 if (NULL != hello)
372 { 361 {
373 ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); 362 ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
374 GNUNET_memcpy (ret->hello, 363 GNUNET_memcpy (ret->hello, hello, GNUNET_HELLO_size (hello));
375 hello,
376 GNUNET_HELLO_size (hello));
377 } 364 }
378 GNUNET_break (GNUNET_OK == 365 GNUNET_break (GNUNET_OK ==
379 GNUNET_CONTAINER_multipeermap_put (peers, 366 GNUNET_CONTAINER_multipeermap_put (
380 peer, 367 peers,
381 ret, 368 peer,
382 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 369 ret,
370 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
383 return ret; 371 return ret;
384} 372}
385 373
@@ -403,12 +391,9 @@ setup_filter (struct Peer *peer)
403 * any case; hence 64, 5 as bloomfilter parameters. */ 391 * any case; hence 64, 5 as bloomfilter parameters. */
404 peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5); 392 peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
405 peer->filter_expiration = 393 peer->filter_expiration =
406 GNUNET_TIME_relative_to_absolute 394 GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
407 (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
408 /* never send a peer its own HELLO */ 395 /* never send a peer its own HELLO */
409 GNUNET_CRYPTO_hash (&peer->pid, 396 GNUNET_CRYPTO_hash (&peer->pid, sizeof (struct GNUNET_PeerIdentity), &hc);
410 sizeof (struct GNUNET_PeerIdentity),
411 &hc);
412 GNUNET_CONTAINER_bloomfilter_add (peer->filter, &hc); 397 GNUNET_CONTAINER_bloomfilter_add (peer->filter, &hc);
413} 398}
414 399
@@ -473,10 +458,9 @@ find_advertisable_hello (void *cls,
473 if (hs > fah->max_size) 458 if (hs > fah->max_size)
474 return GNUNET_YES; 459 return GNUNET_YES;
475 GNUNET_CRYPTO_hash (&fah->peer->pid, 460 GNUNET_CRYPTO_hash (&fah->peer->pid,
476 sizeof (struct GNUNET_PeerIdentity), &hc); 461 sizeof (struct GNUNET_PeerIdentity),
477 if (GNUNET_NO == 462 &hc);
478 GNUNET_CONTAINER_bloomfilter_test (pos->filter, 463 if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (pos->filter, &hc))
479 &hc))
480 fah->result = pos; 464 fah->result = pos;
481 return GNUNET_YES; 465 return GNUNET_YES;
482} 466}
@@ -505,13 +489,9 @@ schedule_next_hello (void *cls)
505 fah.result = NULL; 489 fah.result = NULL;
506 fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1; 490 fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1;
507 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; 491 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
508 GNUNET_CONTAINER_multipeermap_iterate (peers, 492 GNUNET_CONTAINER_multipeermap_iterate (peers, &find_advertisable_hello, &fah);
509 &find_advertisable_hello,
510 &fah);
511 pl->hello_delay_task = 493 pl->hello_delay_task =
512 GNUNET_SCHEDULER_add_delayed (fah.next_adv, 494 GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl);
513 &schedule_next_hello,
514 pl);
515 if (NULL == fah.result) 495 if (NULL == fah.result)
516 return; 496 return;
517 delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed); 497 delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
@@ -520,31 +500,25 @@ schedule_next_hello (void *cls)
520 500
521 want = GNUNET_HELLO_size (fah.result->hello); 501 want = GNUNET_HELLO_size (fah.result->hello);
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 "Sending HELLO with %u bytes", 503 "Sending HELLO with %u bytes",
524 (unsigned int) want); 504 (unsigned int) want);
525 env = GNUNET_MQ_msg_copy (&fah.result->hello->header); 505 env = GNUNET_MQ_msg_copy (&fah.result->hello->header);
526 GNUNET_MQ_send (pl->mq, 506 GNUNET_MQ_send (pl->mq, env);
527 env);
528 507
529 /* avoid sending this one again soon */ 508 /* avoid sending this one again soon */
530 GNUNET_CRYPTO_hash (&pl->pid, 509 GNUNET_CRYPTO_hash (&pl->pid, sizeof (struct GNUNET_PeerIdentity), &hc);
531 sizeof (struct GNUNET_PeerIdentity), 510 GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &hc);
532 &hc);
533 GNUNET_CONTAINER_bloomfilter_add (fah.result->filter,
534 &hc);
535 511
536 GNUNET_STATISTICS_update (stats, 512 GNUNET_STATISTICS_update (stats,
537 gettext_noop ("# HELLO messages gossipped"), 513 gettext_noop ("# HELLO messages gossipped"),
538 1, 514 1,
539 GNUNET_NO); 515 GNUNET_NO);
540 /* prepare to send the next one */ 516 /* prepare to send the next one */
541 pl->next_hello_allowed 517 pl->next_hello_allowed =
542 = GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY); 518 GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
543 if (NULL != pl->hello_delay_task) 519 if (NULL != pl->hello_delay_task)
544 GNUNET_SCHEDULER_cancel (pl->hello_delay_task); 520 GNUNET_SCHEDULER_cancel (pl->hello_delay_task);
545 pl->hello_delay_task 521 pl->hello_delay_task = GNUNET_SCHEDULER_add_now (&schedule_next_hello, pl);
546 = GNUNET_SCHEDULER_add_now (&schedule_next_hello,
547 pl);
548} 522}
549 523
550 524
@@ -576,7 +550,7 @@ reschedule_hellos (void *cls,
576 peer->hello_delay_task = NULL; 550 peer->hello_delay_task = NULL;
577 } 551 }
578 peer->hello_delay_task = 552 peer->hello_delay_task =
579 GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer); 553 GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer);
580 return GNUNET_YES; 554 return GNUNET_YES;
581} 555}
582 556
@@ -592,36 +566,25 @@ reschedule_hellos (void *cls,
592static void * 566static void *
593connect_notify (void *cls, 567connect_notify (void *cls,
594 const struct GNUNET_PeerIdentity *peer, 568 const struct GNUNET_PeerIdentity *peer,
595 struct GNUNET_MQ_Handle *mq) 569 struct GNUNET_MQ_Handle *mq)
596{ 570{
597 struct Peer *pos; 571 struct Peer *pos;
598 uint64_t flags;
599 const void *extra;
600 572
601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
602 "Core told us that we are connecting to `%s'\n", 574 "Core told us that we are connecting to `%s'\n",
603 GNUNET_i2s (peer)); 575 GNUNET_i2s (peer));
604 if (0 == GNUNET_memcmp (&my_identity, 576 if (0 == GNUNET_memcmp (&my_identity, peer))
605 peer))
606 return NULL; 577 return NULL;
607 extra = GNUNET_CORE_get_mq_options (GNUNET_YES, 578 GNUNET_MQ_set_options (mq, GNUNET_MQ_PRIO_BEST_EFFORT);
608 GNUNET_CORE_PRIO_BEST_EFFORT,
609 &flags);
610 GNUNET_MQ_set_options (mq,
611 flags,
612 extra);
613 connection_count++; 579 connection_count++;
614 GNUNET_STATISTICS_set (stats, 580 GNUNET_STATISTICS_set (stats,
615 gettext_noop ("# peers connected"), 581 gettext_noop ("# peers connected"),
616 connection_count, 582 connection_count,
617 GNUNET_NO); 583 GNUNET_NO);
618 pos = GNUNET_CONTAINER_multipeermap_get (peers, 584 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
619 peer);
620 if (NULL == pos) 585 if (NULL == pos)
621 { 586 {
622 pos = make_peer (peer, 587 pos = make_peer (peer, NULL, GNUNET_NO);
623 NULL,
624 GNUNET_NO);
625 } 588 }
626 else 589 else
627 { 590 {
@@ -631,17 +594,14 @@ connect_notify (void *cls,
631 if (pos->is_friend) 594 if (pos->is_friend)
632 { 595 {
633 friend_count++; 596 friend_count++;
634 if ( (friend_count == minimum_friend_count) && 597 if ((friend_count == minimum_friend_count) && (GNUNET_YES != friends_only))
635 (GNUNET_YES != friends_only) )
636 whitelist_peers (); 598 whitelist_peers ();
637 GNUNET_STATISTICS_set (stats, 599 GNUNET_STATISTICS_set (stats,
638 gettext_noop ("# friends connected"), 600 gettext_noop ("# friends connected"),
639 friend_count, 601 friend_count,
640 GNUNET_NO); 602 GNUNET_NO);
641 } 603 }
642 reschedule_hellos (NULL, 604 reschedule_hellos (NULL, peer, pos);
643 peer,
644 pos);
645 return pos; 605 return pos;
646} 606}
647 607
@@ -655,9 +615,7 @@ connect_notify (void *cls,
655 * @return #GNUNET_YES (continue to iterate) 615 * @return #GNUNET_YES (continue to iterate)
656 */ 616 */
657static int 617static int
658try_add_peers (void *cls, 618try_add_peers (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
659 const struct GNUNET_PeerIdentity *pid,
660 void *value)
661{ 619{
662 struct Peer *pos = value; 620 struct Peer *pos = value;
663 621
@@ -676,9 +634,7 @@ add_peer_task (void *cls)
676{ 634{
677 add_task = NULL; 635 add_task = NULL;
678 636
679 GNUNET_CONTAINER_multipeermap_iterate (peers, 637 GNUNET_CONTAINER_multipeermap_iterate (peers, &try_add_peers, NULL);
680 &try_add_peers,
681 NULL);
682} 638}
683 639
684 640
@@ -692,7 +648,7 @@ add_peer_task (void *cls)
692static void 648static void
693disconnect_notify (void *cls, 649disconnect_notify (void *cls,
694 const struct GNUNET_PeerIdentity *peer, 650 const struct GNUNET_PeerIdentity *peer,
695 void *internal_cls) 651 void *internal_cls)
696{ 652{
697 struct Peer *pos = internal_cls; 653 struct Peer *pos = internal_cls;
698 654
@@ -725,16 +681,12 @@ disconnect_notify (void *cls,
725 friend_count, 681 friend_count,
726 GNUNET_NO); 682 GNUNET_NO);
727 } 683 }
728 if ( ( (connection_count < target_connection_count) || 684 if (((connection_count < target_connection_count) ||
729 (friend_count < minimum_friend_count)) && 685 (friend_count < minimum_friend_count)) &&
730 (NULL == add_task) ) 686 (NULL == add_task))
731 add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, 687 add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL);
732 NULL); 688 if ((friend_count < minimum_friend_count) && (NULL == blacklist))
733 if ( (friend_count < minimum_friend_count) && 689 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
734 (NULL == blacklist))
735 blacklist = GNUNET_TRANSPORT_blacklist (cfg,
736 &blacklist_check,
737 NULL);
738} 690}
739 691
740 692
@@ -779,38 +731,32 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
779 GNUNET_break (0); 731 GNUNET_break (0);
780 return; 732 return;
781 } 733 }
782 if (0 == GNUNET_memcmp (&pid, 734 if (0 == GNUNET_memcmp (&pid, &my_identity))
783 &my_identity)) 735 return; /* that's me! */
784 return; /* that's me! */
785 have_address = GNUNET_NO; 736 have_address = GNUNET_NO;
786 GNUNET_HELLO_iterate_addresses (hello, 737 GNUNET_HELLO_iterate_addresses (hello,
787 GNUNET_NO, 738 GNUNET_NO,
788 &address_iterator, 739 &address_iterator,
789 &have_address); 740 &have_address);
790 if (GNUNET_NO == have_address) 741 if (GNUNET_NO == have_address)
791 return; /* no point in advertising this one... */ 742 return; /* no point in advertising this one... */
792 peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid); 743 peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid);
793 if (NULL == peer) 744 if (NULL == peer)
794 { 745 {
795 peer = make_peer (&pid, 746 peer = make_peer (&pid, hello, GNUNET_NO);
796 hello,
797 GNUNET_NO);
798 } 747 }
799 else if (NULL != peer->hello) 748 else if (NULL != peer->hello)
800 { 749 {
801 dt = GNUNET_HELLO_equals (peer->hello, 750 dt = GNUNET_HELLO_equals (peer->hello, hello, GNUNET_TIME_absolute_get ());
802 hello,
803 GNUNET_TIME_absolute_get ());
804 if (dt.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 751 if (dt.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
805 return; /* nothing new here */ 752 return; /* nothing new here */
806 } 753 }
807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
808 "Found HELLO from peer `%s' for advertising\n", 755 "Found HELLO from peer `%s' for advertising\n",
809 GNUNET_i2s (&pid)); 756 GNUNET_i2s (&pid));
810 if (NULL != peer->hello) 757 if (NULL != peer->hello)
811 { 758 {
812 nh = GNUNET_HELLO_merge (peer->hello, 759 nh = GNUNET_HELLO_merge (peer->hello, hello);
813 hello);
814 GNUNET_free (peer->hello); 760 GNUNET_free (peer->hello);
815 peer->hello = nh; 761 peer->hello = nh;
816 } 762 }
@@ -818,9 +764,7 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
818 { 764 {
819 size = GNUNET_HELLO_size (hello); 765 size = GNUNET_HELLO_size (hello);
820 peer->hello = GNUNET_malloc (size); 766 peer->hello = GNUNET_malloc (size);
821 GNUNET_memcpy (peer->hello, 767 GNUNET_memcpy (peer->hello, hello, size);
822 hello,
823 size);
824 } 768 }
825 if (NULL != peer->filter) 769 if (NULL != peer->filter)
826 { 770 {
@@ -830,9 +774,7 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
830 setup_filter (peer); 774 setup_filter (peer);
831 /* since we have a new HELLO to pick from, re-schedule all 775 /* since we have a new HELLO to pick from, re-schedule all
832 * HELLO requests that are not bound by the HELLO send rate! */ 776 * HELLO requests that are not bound by the HELLO send rate! */
833 GNUNET_CONTAINER_multipeermap_iterate (peers, 777 GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, peer);
834 &reschedule_hellos,
835 peer);
836} 778}
837 779
838 780
@@ -856,24 +798,20 @@ process_peer (void *cls,
856 if (NULL != err_msg) 798 if (NULL != err_msg)
857 { 799 {
858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
859 _("Error in communication with PEERINFO service: %s\n"), 801 _ ("Error in communication with PEERINFO service: %s\n"),
860 err_msg); 802 err_msg);
861 GNUNET_PEERINFO_notify_cancel (peerinfo_notify); 803 GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
862 peerinfo_notify = GNUNET_PEERINFO_notify (cfg, 804 peerinfo_notify =
863 GNUNET_NO, 805 GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
864 &process_peer,
865 NULL);
866 return; 806 return;
867 } 807 }
868 GNUNET_assert (NULL != peer); 808 GNUNET_assert (NULL != peer);
869 if (0 == GNUNET_memcmp (&my_identity, 809 if (0 == GNUNET_memcmp (&my_identity, peer))
870 peer)) 810 return; /* that's me! */
871 return; /* that's me! */
872 if (NULL == hello) 811 if (NULL == hello)
873 { 812 {
874 /* free existing HELLO, if any */ 813 /* free existing HELLO, if any */
875 pos = GNUNET_CONTAINER_multipeermap_get (peers, 814 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
876 peer);
877 if (NULL != pos) 815 if (NULL != pos)
878 { 816 {
879 GNUNET_free_non_null (pos->hello); 817 GNUNET_free_non_null (pos->hello);
@@ -883,21 +821,15 @@ process_peer (void *cls,
883 GNUNET_CONTAINER_bloomfilter_free (pos->filter); 821 GNUNET_CONTAINER_bloomfilter_free (pos->filter);
884 pos->filter = NULL; 822 pos->filter = NULL;
885 } 823 }
886 if ( (NULL == pos->mq) && 824 if ((NULL == pos->mq) && (GNUNET_NO == pos->is_friend))
887 (GNUNET_NO == pos->is_friend) ) 825 free_peer (NULL, &pos->pid, pos);
888 free_peer (NULL,
889 &pos->pid,
890 pos);
891 } 826 }
892 return; 827 return;
893 } 828 }
894 consider_for_advertising (hello); 829 consider_for_advertising (hello);
895 pos = GNUNET_CONTAINER_multipeermap_get (peers, 830 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
896 peer);
897 if (NULL == pos) 831 if (NULL == pos)
898 pos = make_peer (peer, 832 pos = make_peer (peer, hello, GNUNET_NO);
899 hello,
900 GNUNET_NO);
901 attempt_connect (pos); 833 attempt_connect (pos);
902} 834}
903 835
@@ -910,24 +842,20 @@ process_peer (void *cls,
910 * @param my_id ID of this peer, NULL if we failed 842 * @param my_id ID of this peer, NULL if we failed
911 */ 843 */
912static void 844static void
913core_init (void *cls, 845core_init (void *cls, const struct GNUNET_PeerIdentity *my_id)
914 const struct GNUNET_PeerIdentity *my_id)
915{ 846{
916 if (NULL == my_id) 847 if (NULL == my_id)
917 { 848 {
918 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 849 GNUNET_log (
919 _("Failed to connect to core service, can not manage topology!\n")); 850 GNUNET_ERROR_TYPE_ERROR,
851 _ ("Failed to connect to core service, can not manage topology!\n"));
920 GNUNET_SCHEDULER_shutdown (); 852 GNUNET_SCHEDULER_shutdown ();
921 return; 853 return;
922 } 854 }
923 my_identity = *my_id; 855 my_identity = *my_id;
924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
925 "I am peer `%s'\n", 857 peerinfo_notify =
926 GNUNET_i2s (my_id)); 858 GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
927 peerinfo_notify = GNUNET_PEERINFO_notify (cfg,
928 GNUNET_NO,
929 &process_peer,
930 NULL);
931} 859}
932 860
933 861
@@ -938,24 +866,22 @@ core_init (void *cls,
938 * @param pid identity of the friend 866 * @param pid identity of the friend
939 */ 867 */
940static void 868static void
941handle_friend (void *cls, 869handle_friend (void *cls, const struct GNUNET_PeerIdentity *pid)
942 const struct GNUNET_PeerIdentity *pid)
943{ 870{
944 unsigned int *entries_found = cls; 871 unsigned int *entries_found = cls;
945 struct Peer *fl; 872 struct Peer *fl;
946 873
947 if (0 == GNUNET_memcmp (pid, 874 if (0 == GNUNET_memcmp (pid, &my_identity))
948 &my_identity))
949 { 875 {
950 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 876 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
951 _("Found myself `%s' in friend list (useless, ignored)\n"), 877 _ ("Found myself `%s' in friend list (useless, ignored)\n"),
952 GNUNET_i2s (pid)); 878 GNUNET_i2s (pid));
953 return; 879 return;
954 } 880 }
955 (*entries_found)++; 881 (*entries_found)++;
956 fl = make_peer (pid, NULL, GNUNET_YES); 882 fl = make_peer (pid, NULL, GNUNET_YES);
957 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 883 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
958 _("Found friend `%s' in configuration\n"), 884 _ ("Found friend `%s' in configuration\n"),
959 GNUNET_i2s (&fl->pid)); 885 GNUNET_i2s (&fl->pid));
960} 886}
961 887
@@ -969,31 +895,30 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
969 unsigned int entries_found; 895 unsigned int entries_found;
970 896
971 entries_found = 0; 897 entries_found = 0;
972 if (GNUNET_OK != 898 if (GNUNET_OK != GNUNET_FRIENDS_parse (cfg, &handle_friend, &entries_found))
973 GNUNET_FRIENDS_parse (cfg,
974 &handle_friend,
975 &entries_found))
976 { 899 {
977 if ( (GNUNET_YES == friends_only) || 900 if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
978 (minimum_friend_count > 0))
979 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 901 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
980 _("Encountered errors parsing friends list!\n")); 902 _ ("Encountered errors parsing friends list!\n"));
981 } 903 }
982 GNUNET_STATISTICS_update (stats, 904 GNUNET_STATISTICS_update (stats,
983 gettext_noop ("# friends in configuration"), 905 gettext_noop ("# friends in configuration"),
984 entries_found, 906 entries_found,
985 GNUNET_NO); 907 GNUNET_NO);
986 if ( (minimum_friend_count > entries_found) && 908 if ((minimum_friend_count > entries_found) && (GNUNET_NO == friends_only))
987 (GNUNET_NO == friends_only) )
988 { 909 {
989 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 910 GNUNET_log (
990 _("Fewer friends specified than required by minimum friend count. Will only connect to friends.\n")); 911 GNUNET_ERROR_TYPE_WARNING,
912 _ (
913 "Fewer friends specified than required by minimum friend count. Will only connect to friends.\n"));
991 } 914 }
992 if ( (minimum_friend_count > target_connection_count) && 915 if ((minimum_friend_count > target_connection_count) &&
993 (GNUNET_NO == friends_only)) 916 (GNUNET_NO == friends_only))
994 { 917 {
995 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 918 GNUNET_log (
996 _("More friendly connections required than target total number of connections.\n")); 919 GNUNET_ERROR_TYPE_WARNING,
920 _ (
921 "More friendly connections required than target total number of connections.\n"));
997 } 922 }
998} 923}
999 924
@@ -1008,14 +933,11 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1008 * #GNUNET_SYSERR if @a message is invalid 933 * #GNUNET_SYSERR if @a message is invalid
1009 */ 934 */
1010static int 935static int
1011check_hello (void *cls, 936check_hello (void *cls, const struct GNUNET_HELLO_Message *message)
1012 const struct GNUNET_HELLO_Message *message)
1013{ 937{
1014 struct GNUNET_PeerIdentity pid; 938 struct GNUNET_PeerIdentity pid;
1015 939
1016 if (GNUNET_OK != 940 if (GNUNET_OK != GNUNET_HELLO_get_id (message, &pid))
1017 GNUNET_HELLO_get_id (message,
1018 &pid))
1019 { 941 {
1020 GNUNET_break_op (0); 942 GNUNET_break_op (0);
1021 return GNUNET_SYSERR; 943 return GNUNET_SYSERR;
@@ -1032,8 +954,7 @@ check_hello (void *cls,
1032 * @param message the actual HELLO message 954 * @param message the actual HELLO message
1033 */ 955 */
1034static void 956static void
1035handle_hello (void *cls, 957handle_hello (void *cls, const struct GNUNET_HELLO_Message *message)
1036 const struct GNUNET_HELLO_Message *message)
1037{ 958{
1038 const struct GNUNET_PeerIdentity *other = cls; 959 const struct GNUNET_PeerIdentity *other = cls;
1039 struct Peer *peer; 960 struct Peer *peer;
@@ -1042,34 +963,26 @@ handle_hello (void *cls,
1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1043 "Received encrypted HELLO from peer `%s'", 964 "Received encrypted HELLO from peer `%s'",
1044 GNUNET_i2s (other)); 965 GNUNET_i2s (other));
1045 GNUNET_assert (GNUNET_OK == 966 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (message, &pid));
1046 GNUNET_HELLO_get_id (message,
1047 &pid));
1048 GNUNET_STATISTICS_update (stats, 967 GNUNET_STATISTICS_update (stats,
1049 gettext_noop ("# HELLO messages received"), 968 gettext_noop ("# HELLO messages received"),
1050 1, 969 1,
1051 GNUNET_NO); 970 GNUNET_NO);
1052 peer = GNUNET_CONTAINER_multipeermap_get (peers, 971 peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid);
1053 &pid);
1054 if (NULL == peer) 972 if (NULL == peer)
1055 { 973 {
1056 if ( (GNUNET_YES == friends_only) || 974 if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count))
1057 (friend_count < minimum_friend_count) )
1058 return; 975 return;
1059 } 976 }
1060 else 977 else
1061 { 978 {
1062 if ( (GNUNET_YES != peer->is_friend) && 979 if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only))
1063 (GNUNET_YES == friends_only) )
1064 return; 980 return;
1065 if ((GNUNET_YES != peer->is_friend) && 981 if ((GNUNET_YES != peer->is_friend) &&
1066 (friend_count < minimum_friend_count)) 982 (friend_count < minimum_friend_count))
1067 return; 983 return;
1068 } 984 }
1069 (void) GNUNET_PEERINFO_add_peer (pi, 985 (void) GNUNET_PEERINFO_add_peer (pi, message, NULL, NULL);
1070 message,
1071 NULL,
1072 NULL);
1073} 986}
1074 987
1075 988
@@ -1103,9 +1016,7 @@ cleaning_task (void *cls)
1103 GNUNET_TRANSPORT_offer_hello_cancel (oh); 1016 GNUNET_TRANSPORT_offer_hello_cancel (oh);
1104 oh = NULL; 1017 oh = NULL;
1105 } 1018 }
1106 GNUNET_CONTAINER_multipeermap_iterate (peers, 1019 GNUNET_CONTAINER_multipeermap_iterate (peers, &free_peer, NULL);
1107 &free_peer,
1108 NULL);
1109 GNUNET_CONTAINER_multipeermap_destroy (peers); 1020 GNUNET_CONTAINER_multipeermap_destroy (peers);
1110 peers = NULL; 1021 peers = NULL;
1111 if (NULL != ats) 1022 if (NULL != ats)
@@ -1140,26 +1051,22 @@ run (void *cls,
1140 const char *cfgfile, 1051 const char *cfgfile,
1141 const struct GNUNET_CONFIGURATION_Handle *c) 1052 const struct GNUNET_CONFIGURATION_Handle *c)
1142{ 1053{
1143 struct GNUNET_MQ_MessageHandler handlers[] = { 1054 struct GNUNET_MQ_MessageHandler handlers[] =
1144 GNUNET_MQ_hd_var_size (hello, 1055 {GNUNET_MQ_hd_var_size (hello,
1145 GNUNET_MESSAGE_TYPE_HELLO, 1056 GNUNET_MESSAGE_TYPE_HELLO,
1146 struct GNUNET_HELLO_Message, 1057 struct GNUNET_HELLO_Message,
1147 NULL), 1058 NULL),
1148 GNUNET_MQ_handler_end () 1059 GNUNET_MQ_handler_end ()};
1149 };
1150 unsigned long long opt; 1060 unsigned long long opt;
1151 1061
1152 cfg = c; 1062 cfg = c;
1153 stats = GNUNET_STATISTICS_create ("topology", cfg); 1063 stats = GNUNET_STATISTICS_create ("topology", cfg);
1154 friends_only = 1064 friends_only =
1155 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1065 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY");
1156 "TOPOLOGY", 1066 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
1157 "FRIENDS-ONLY"); 1067 "TOPOLOGY",
1158 if (GNUNET_OK != 1068 "MINIMUM-FRIENDS",
1159 GNUNET_CONFIGURATION_get_value_number (cfg, 1069 &opt))
1160 "TOPOLOGY",
1161 "MINIMUM-FRIENDS",
1162 &opt))
1163 opt = 0; 1070 opt = 0;
1164 minimum_friend_count = (unsigned int) opt; 1071 minimum_friend_count = (unsigned int) opt;
1165 if (GNUNET_OK != 1072 if (GNUNET_OK !=
@@ -1176,25 +1083,21 @@ run (void *cls,
1176 "Topology would like %u connections with at least %u friends\n", 1083 "Topology would like %u connections with at least %u friends\n",
1177 target_connection_count, 1084 target_connection_count,
1178 minimum_friend_count); 1085 minimum_friend_count);
1179 if ( (GNUNET_YES == friends_only) || 1086 if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
1180 (minimum_friend_count > 0)) 1087 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
1181 blacklist = GNUNET_TRANSPORT_blacklist (cfg,
1182 &blacklist_check,
1183 NULL);
1184 ats = GNUNET_ATS_connectivity_init (cfg); 1088 ats = GNUNET_ATS_connectivity_init (cfg);
1185 pi = GNUNET_PEERINFO_connect (cfg); 1089 pi = GNUNET_PEERINFO_connect (cfg);
1186 handle = GNUNET_CORE_connect (cfg, 1090 handle = GNUNET_CORE_connect (cfg,
1187 NULL, 1091 NULL,
1188 &core_init, 1092 &core_init,
1189 &connect_notify, 1093 &connect_notify,
1190 &disconnect_notify, 1094 &disconnect_notify,
1191 handlers); 1095 handlers);
1192 GNUNET_SCHEDULER_add_shutdown (&cleaning_task, 1096 GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL);
1193 NULL);
1194 if (NULL == handle) 1097 if (NULL == handle)
1195 { 1098 {
1196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1099 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1197 _("Failed to connect to `%s' service.\n"), 1100 _ ("Failed to connect to `%s' service.\n"),
1198 "core"); 1101 "core");
1199 GNUNET_SCHEDULER_shutdown (); 1102 GNUNET_SCHEDULER_shutdown ();
1200 return; 1103 return;
@@ -1210,24 +1113,25 @@ run (void *cls,
1210 * @return 0 ok, 1 on error 1113 * @return 0 ok, 1 on error
1211 */ 1114 */
1212int 1115int
1213main (int argc, 1116main (int argc, char *const *argv)
1214 char *const *argv)
1215{ 1117{
1216 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1118 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1217 GNUNET_GETOPT_OPTION_END 1119 GNUNET_GETOPT_OPTION_END};
1218 };
1219 int ret; 1120 int ret;
1220 1121
1221 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 1122 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1222 return 2; 1123 return 2;
1223 1124
1224 ret = 1125 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
1225 (GNUNET_OK == 1126 argv,
1226 GNUNET_PROGRAM_run (argc, argv, 1127 "gnunet-daemon-topology",
1227 "gnunet-daemon-topology", 1128 _ ("GNUnet topology control"),
1228 _("GNUnet topology control"), 1129 options,
1229 options, &run, NULL)) ? 0 : 1; 1130 &run,
1230 GNUNET_free ((void*) argv); 1131 NULL))
1132 ? 0
1133 : 1;
1134 GNUNET_free ((void *) argv);
1231 return ret; 1135 return ret;
1232} 1136}
1233 1137
@@ -1238,8 +1142,7 @@ main (int argc,
1238/** 1142/**
1239 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1143 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1240 */ 1144 */
1241void __attribute__ ((constructor)) 1145void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
1242GNUNET_ARM_memory_init ()
1243{ 1146{
1244 mallopt (M_TRIM_THRESHOLD, 4 * 1024); 1147 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1245 mallopt (M_TOP_PAD, 1 * 1024); 1148 mallopt (M_TOP_PAD, 1 * 1024);
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 95ea102df..b217c8aa9 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -3743,10 +3743,13 @@ handle_client_send (void *cls, const struct OutboundMessage *obm)
3743 size_t payload_size; 3743 size_t payload_size;
3744 struct TransportDVBoxMessage *dvb; 3744 struct TransportDVBoxMessage *dvb;
3745 struct VirtualLink *vl; 3745 struct VirtualLink *vl;
3746 enum GNUNET_MQ_PriorityPreferences pp;
3746 3747
3747 GNUNET_assert (CT_CORE == tc->type); 3748 GNUNET_assert (CT_CORE == tc->type);
3748 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 3749 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
3749 bytes_msg = ntohs (obmm->size); 3750 bytes_msg = ntohs (obmm->size);
3751 pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority);
3752 /* FIXME: actually make use of pp */ (void) pp;
3750 vl = GNUNET_CONTAINER_multipeermap_get (links, &obm->peer); 3753 vl = GNUNET_CONTAINER_multipeermap_get (links, &obm->peer);
3751 if (NULL == vl) 3754 if (NULL == vl)
3752 { 3755 {
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 4ba628112..7fe869fa8 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -302,9 +302,9 @@ struct OutboundMessage
302 struct GNUNET_MessageHeader header; 302 struct GNUNET_MessageHeader header;
303 303
304 /** 304 /**
305 * Always zero. 305 * An `enum GNUNET_MQ_PriorityPreferences` in NBO.
306 */ 306 */
307 uint32_t reserved GNUNET_PACKED; 307 uint32_t priority GNUNET_PACKED;
308 308
309#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ 309#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \
310 defined(GNUNET_TRANSPORT_CORE_VERSION)) 310 defined(GNUNET_TRANSPORT_CORE_VERSION))
diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c
index a3c49e94f..20bbf2994 100644
--- a/src/transport/transport_api2_core.c
+++ b/src/transport/transport_api2_core.c
@@ -329,7 +329,12 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
329 n->env = 329 n->env =
330 GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); 330 GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg);
331 n->env_size = ntohs (msg->size); 331 n->env_size = ntohs (msg->size);
332 obm->reserved = htonl (0); 332 {
333 struct GNUNET_MQ_Envelope *env;
334
335 env = GNUNET_MQ_get_current_envelope (mq);
336 obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
337 }
333 obm->peer = n->id; 338 obm->peer = n->id;
334 if (0 == n->ready_window) 339 if (0 == n->ready_window)
335 { 340 {
diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c
index a163d7ccf..54dc7f4c3 100644
--- a/src/transport/transport_api_core.c
+++ b/src/transport/transport_api_core.c
@@ -418,7 +418,12 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
418 GNUNET_assert (NULL == n->env); 418 GNUNET_assert (NULL == n->env);
419 n->env = 419 n->env =
420 GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); 420 GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg);
421 obm->reserved = htonl (0); 421 {
422 struct GNUNET_MQ_Envelope *env;
423
424 env = GNUNET_MQ_get_current_envelope (mq);
425 obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
426 }
422 obm->timeout = GNUNET_TIME_relative_hton ( 427 obm->timeout = GNUNET_TIME_relative_hton (
423 GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ 428 GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */
424 obm->peer = n->id; 429 obm->peer = n->id;
diff --git a/src/util/mq.c b/src/util/mq.c
index 513c008ee..2f9e650b6 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -26,7 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28 28
29#define LOG(kind,...) GNUNET_log_from (kind, "util-mq",__VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from (kind, "util-mq", __VA_ARGS__)
30 30
31 31
32struct GNUNET_MQ_Envelope 32struct GNUNET_MQ_Envelope
@@ -70,14 +70,7 @@ struct GNUNET_MQ_Envelope
70 * #GNUNET_MQ_env_set_options(). Only valid if 70 * #GNUNET_MQ_env_set_options(). Only valid if
71 * @e have_custom_options is set. 71 * @e have_custom_options is set.
72 */ 72 */
73 uint64_t flags; 73 enum GNUNET_MQ_PriorityPreferences priority;
74
75 /**
76 * Additional options buffer set for this envelope by
77 * #GNUNET_MQ_env_set_options(). Only valid if
78 * @e have_custom_options is set.
79 */
80 const void *extra;
81 74
82 /** 75 /**
83 * Did the application call #GNUNET_MQ_env_set_options()? 76 * Did the application call #GNUNET_MQ_env_set_options()?
@@ -165,16 +158,10 @@ struct GNUNET_MQ_Handle
165 struct GNUNET_MQ_DestroyNotificationHandle *dnh_tail; 158 struct GNUNET_MQ_DestroyNotificationHandle *dnh_tail;
166 159
167 /** 160 /**
168 * Additional options buffer set for this queue by
169 * #GNUNET_MQ_set_options(). Default is 0.
170 */
171 const void *default_extra;
172
173 /**
174 * Flags that were set for this queue by 161 * Flags that were set for this queue by
175 * #GNUNET_MQ_set_options(). Default is 0. 162 * #GNUNET_MQ_set_options(). Default is 0.
176 */ 163 */
177 uint64_t default_flags; 164 enum GNUNET_MQ_PriorityPreferences priority;
178 165
179 /** 166 /**
180 * Next id that should be used for the @e assoc_map, 167 * Next id that should be used for the @e assoc_map,
@@ -217,12 +204,10 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
217{ 204{
218 int ret; 205 int ret;
219 206
220 ret = GNUNET_MQ_handle_message (mq->handlers, 207 ret = GNUNET_MQ_handle_message (mq->handlers, mh);
221 mh);
222 if (GNUNET_SYSERR == ret) 208 if (GNUNET_SYSERR == ret)
223 { 209 {
224 GNUNET_MQ_inject_error (mq, 210 GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_MALFORMED);
225 GNUNET_MQ_ERROR_MALFORMED);
226 return; 211 return;
227 } 212 }
228} 213}
@@ -251,7 +236,8 @@ GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers,
251 236
252 LOG (GNUNET_ERROR_TYPE_DEBUG, 237 LOG (GNUNET_ERROR_TYPE_DEBUG,
253 "Received message of type %u and size %u\n", 238 "Received message of type %u and size %u\n",
254 mtype, msize); 239 mtype,
240 msize);
255 241
256 if (NULL == handlers) 242 if (NULL == handlers)
257 goto done; 243 goto done;
@@ -260,41 +246,40 @@ GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers,
260 if (handler->type == mtype) 246 if (handler->type == mtype)
261 { 247 {
262 handled = GNUNET_YES; 248 handled = GNUNET_YES;
263 if ( (handler->expected_size > msize) || 249 if ((handler->expected_size > msize) ||
264 ( (handler->expected_size != msize) && 250 ((handler->expected_size != msize) && (NULL == handler->mv)))
265 (NULL == handler->mv) ) )
266 { 251 {
267 /* Too small, or not an exact size and 252 /* Too small, or not an exact size and
268 no 'mv' handler to check rest */ 253 no 'mv' handler to check rest */
269 LOG (GNUNET_ERROR_TYPE_ERROR, 254 LOG (GNUNET_ERROR_TYPE_ERROR,
270 "Received malformed message of type %u\n", 255 "Received malformed message of type %u\n",
271 (unsigned int) handler->type); 256 (unsigned int) handler->type);
272 return GNUNET_SYSERR; 257 return GNUNET_SYSERR;
273 } 258 }
274 if ( (NULL == handler->mv) || 259 if ((NULL == handler->mv) ||
275 (GNUNET_OK == 260 (GNUNET_OK == handler->mv (handler->cls, mh)))
276 handler->mv (handler->cls, mh)) )
277 { 261 {
278 /* message well-formed, pass to handler */ 262 /* message well-formed, pass to handler */
279 handler->cb (handler->cls, mh); 263 handler->cb (handler->cls, mh);
280 } 264 }
281 else 265 else
282 { 266 {
283 /* Message rejected by check routine */ 267 /* Message rejected by check routine */
284 LOG (GNUNET_ERROR_TYPE_ERROR, 268 LOG (GNUNET_ERROR_TYPE_ERROR,
285 "Received malformed message of type %u\n", 269 "Received malformed message of type %u\n",
286 (unsigned int) handler->type); 270 (unsigned int) handler->type);
287 return GNUNET_SYSERR; 271 return GNUNET_SYSERR;
288 } 272 }
289 break; 273 break;
290 } 274 }
291 } 275 }
292 done: 276done:
293 if (GNUNET_NO == handled) 277 if (GNUNET_NO == handled)
294 { 278 {
295 LOG (GNUNET_ERROR_TYPE_INFO, 279 LOG (GNUNET_ERROR_TYPE_INFO,
296 "No handler for message of type %u and size %u\n", 280 "No handler for message of type %u and size %u\n",
297 mtype, msize); 281 mtype,
282 msize);
298 return GNUNET_NO; 283 return GNUNET_NO;
299 } 284 }
300 return GNUNET_OK; 285 return GNUNET_OK;
@@ -312,8 +297,7 @@ GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers,
312 * @param error the error type 297 * @param error the error type
313 */ 298 */
314void 299void
315GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, 300GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error)
316 enum GNUNET_MQ_Error error)
317{ 301{
318 if (NULL == mq->error_handler) 302 if (NULL == mq->error_handler)
319 { 303 {
@@ -322,8 +306,7 @@ GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq,
322 (int) error); 306 (int) error);
323 return; 307 return;
324 } 308 }
325 mq->error_handler (mq->error_handler_cls, 309 mq->error_handler (mq->error_handler_cls, error);
326 error);
327} 310}
328 311
329 312
@@ -367,8 +350,7 @@ GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq)
367 * @param ev the envelope with the message to send. 350 * @param ev the envelope with the message to send.
368 */ 351 */
369void 352void
370GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, 353GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
371 struct GNUNET_MQ_Envelope *ev)
372{ 354{
373 GNUNET_assert (NULL != mq); 355 GNUNET_assert (NULL != mq);
374 GNUNET_assert (NULL == ev->parent_queue); 356 GNUNET_assert (NULL == ev->parent_queue);
@@ -378,18 +360,15 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
378 { 360 {
379 /* This would seem like a bug... */ 361 /* This would seem like a bug... */
380 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 362 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
381 "MQ with %u entries extended by message of type %u (FC broken?)\n", 363 "MQ with %u entries extended by message of type %u (FC broken?)\n",
382 (unsigned int) mq->queue_length, 364 (unsigned int) mq->queue_length,
383 (unsigned int) ntohs (ev->mh->type)); 365 (unsigned int) ntohs (ev->mh->type));
384 } 366 }
385 ev->parent_queue = mq; 367 ev->parent_queue = mq;
386 /* is the implementation busy? queue it! */ 368 /* is the implementation busy? queue it! */
387 if ( (NULL != mq->current_envelope) || 369 if ((NULL != mq->current_envelope) || (NULL != mq->send_task))
388 (NULL != mq->send_task) )
389 { 370 {
390 GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head, 371 GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head, mq->envelope_tail, ev);
391 mq->envelope_tail,
392 ev);
393 return; 372 return;
394 } 373 }
395 GNUNET_assert (NULL == mq->envelope_head); 374 GNUNET_assert (NULL == mq->envelope_head);
@@ -397,12 +376,10 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
397 376
398 LOG (GNUNET_ERROR_TYPE_DEBUG, 377 LOG (GNUNET_ERROR_TYPE_DEBUG,
399 "sending message of type %u, queue empty (MQ: %p)\n", 378 "sending message of type %u, queue empty (MQ: %p)\n",
400 ntohs(ev->mh->type), 379 ntohs (ev->mh->type),
401 mq); 380 mq);
402 381
403 mq->send_impl (mq, 382 mq->send_impl (mq, ev->mh, mq->impl_state);
404 ev->mh,
405 mq->impl_state);
406} 383}
407 384
408 385
@@ -419,9 +396,7 @@ GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq)
419 struct GNUNET_MQ_Envelope *env; 396 struct GNUNET_MQ_Envelope *env;
420 397
421 env = mq->envelope_head; 398 env = mq->envelope_head;
422 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 399 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, env);
423 mq->envelope_tail,
424 env);
425 mq->queue_length--; 400 mq->queue_length--;
426 env->parent_queue = NULL; 401 env->parent_queue = NULL;
427 return env; 402 return env;
@@ -461,16 +436,12 @@ GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq,
461 uint16_t msize; 436 uint16_t msize;
462 437
463 msize = ntohs (ev->mh->size); 438 msize = ntohs (ev->mh->size);
464 env = GNUNET_malloc (sizeof (struct GNUNET_MQ_Envelope) + 439 env = GNUNET_malloc (sizeof (struct GNUNET_MQ_Envelope) + msize);
465 msize);
466 env->mh = (struct GNUNET_MessageHeader *) &env[1]; 440 env->mh = (struct GNUNET_MessageHeader *) &env[1];
467 env->sent_cb = ev->sent_cb; 441 env->sent_cb = ev->sent_cb;
468 env->sent_cls = ev->sent_cls; 442 env->sent_cls = ev->sent_cls;
469 GNUNET_memcpy (&env[1], 443 GNUNET_memcpy (&env[1], ev->mh, msize);
470 ev->mh, 444 GNUNET_MQ_send (mq, env);
471 msize);
472 GNUNET_MQ_send (mq,
473 env);
474} 445}
475 446
476 447
@@ -493,16 +464,14 @@ impl_send_continue (void *cls)
493 return; 464 return;
494 mq->current_envelope = mq->envelope_head; 465 mq->current_envelope = mq->envelope_head;
495 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 466 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
496 mq->envelope_tail, 467 mq->envelope_tail,
497 mq->current_envelope); 468 mq->current_envelope);
498 469
499 LOG (GNUNET_ERROR_TYPE_DEBUG, 470 LOG (GNUNET_ERROR_TYPE_DEBUG,
500 "sending message of type %u from queue\n", 471 "sending message of type %u from queue\n",
501 ntohs(mq->current_envelope->mh->type)); 472 ntohs (mq->current_envelope->mh->type));
502 473
503 mq->send_impl (mq, 474 mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
504 mq->current_envelope->mh,
505 mq->impl_state);
506} 475}
507 476
508 477
@@ -526,8 +495,7 @@ GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
526 current_envelope->parent_queue = NULL; 495 current_envelope->parent_queue = NULL;
527 mq->current_envelope = NULL; 496 mq->current_envelope = NULL;
528 GNUNET_assert (NULL == mq->send_task); 497 GNUNET_assert (NULL == mq->send_task);
529 mq->send_task = GNUNET_SCHEDULER_add_now (&impl_send_continue, 498 mq->send_task = GNUNET_SCHEDULER_add_now (&impl_send_continue, mq);
530 mq);
531 if (NULL != (cb = current_envelope->sent_cb)) 499 if (NULL != (cb = current_envelope->sent_cb))
532 { 500 {
533 current_envelope->sent_cb = NULL; 501 current_envelope->sent_cb = NULL;
@@ -612,12 +580,11 @@ GNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send,
612 * @param handlers_cls new closure to use 580 * @param handlers_cls new closure to use
613 */ 581 */
614void 582void
615GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq, 583GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq, void *handlers_cls)
616 void *handlers_cls)
617{ 584{
618 if (NULL == mq->handlers) 585 if (NULL == mq->handlers)
619 return; 586 return;
620 for (unsigned int i=0;NULL != mq->handlers[i].cb; i++) 587 for (unsigned int i = 0; NULL != mq->handlers[i].cb; i++)
621 mq->handlers[i].cls = handlers_cls; 588 mq->handlers[i].cls = handlers_cls;
622} 589}
623 590
@@ -662,9 +629,7 @@ GNUNET_MQ_impl_state (struct GNUNET_MQ_Handle *mq)
662 629
663 630
664struct GNUNET_MQ_Envelope * 631struct GNUNET_MQ_Envelope *
665GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, 632GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
666 uint16_t size,
667 uint16_t type)
668{ 633{
669 struct GNUNET_MQ_Envelope *ev; 634 struct GNUNET_MQ_Envelope *ev;
670 635
@@ -692,9 +657,7 @@ GNUNET_MQ_msg_copy (const struct GNUNET_MessageHeader *hdr)
692 657
693 mqm = GNUNET_malloc (sizeof (*mqm) + size); 658 mqm = GNUNET_malloc (sizeof (*mqm) + size);
694 mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1]; 659 mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
695 GNUNET_memcpy (mqm->mh, 660 GNUNET_memcpy (mqm->mh, hdr, size);
696 hdr,
697 size);
698 return mqm; 661 return mqm;
699} 662}
700 663
@@ -728,8 +691,8 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
728 691
729 mqm = GNUNET_MQ_msg_ (mhp, size, type); 692 mqm = GNUNET_MQ_msg_ (mhp, size, type);
730 GNUNET_memcpy ((char *) mqm->mh + base_size, 693 GNUNET_memcpy ((char *) mqm->mh + base_size,
731 nested_mh, 694 nested_mh,
732 ntohs (nested_mh->size)); 695 ntohs (nested_mh->size));
733 696
734 return mqm; 697 return mqm;
735} 698}
@@ -742,8 +705,7 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
742 * @param assoc_data to associate 705 * @param assoc_data to associate
743 */ 706 */
744uint32_t 707uint32_t
745GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, 708GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data)
746 void *assoc_data)
747{ 709{
748 uint32_t id; 710 uint32_t id;
749 711
@@ -754,10 +716,11 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
754 } 716 }
755 id = mq->assoc_id++; 717 id = mq->assoc_id++;
756 GNUNET_assert (GNUNET_OK == 718 GNUNET_assert (GNUNET_OK ==
757 GNUNET_CONTAINER_multihashmap32_put (mq->assoc_map, 719 GNUNET_CONTAINER_multihashmap32_put (
758 id, 720 mq->assoc_map,
759 assoc_data, 721 id,
760 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 722 assoc_data,
723 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
761 return id; 724 return id;
762} 725}
763 726
@@ -770,13 +733,11 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
770 * @return the associated data 733 * @return the associated data
771 */ 734 */
772void * 735void *
773GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, 736GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
774 uint32_t request_id)
775{ 737{
776 if (NULL == mq->assoc_map) 738 if (NULL == mq->assoc_map)
777 return NULL; 739 return NULL;
778 return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, 740 return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
779 request_id);
780} 741}
781 742
782 743
@@ -788,17 +749,14 @@ GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
788 * @return the associated data 749 * @return the associated data
789 */ 750 */
790void * 751void *
791GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, 752GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
792 uint32_t request_id)
793{ 753{
794 void *val; 754 void *val;
795 755
796 if (NULL == mq->assoc_map) 756 if (NULL == mq->assoc_map)
797 return NULL; 757 return NULL;
798 val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, 758 val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
799 request_id); 759 GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map, request_id);
800 GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map,
801 request_id);
802 return val; 760 return val;
803} 761}
804 762
@@ -818,8 +776,7 @@ GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev,
818 void *cb_cls) 776 void *cb_cls)
819{ 777{
820 /* allow setting *OR* clearing callback */ 778 /* allow setting *OR* clearing callback */
821 GNUNET_assert ( (NULL == ev->sent_cb) || 779 GNUNET_assert ((NULL == ev->sent_cb) || (NULL == cb));
822 (NULL == cb) );
823 ev->sent_cb = cb; 780 ev->sent_cb = cb;
824 ev->sent_cls = cb_cls; 781 ev->sent_cls = cb_cls;
825} 782}
@@ -883,9 +840,7 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
883 840
884 ev = mq->envelope_head; 841 ev = mq->envelope_head;
885 ev->parent_queue = NULL; 842 ev->parent_queue = NULL;
886 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 843 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
887 mq->envelope_tail,
888 ev);
889 GNUNET_assert (0 < mq->queue_length); 844 GNUNET_assert (0 < mq->queue_length);
890 mq->queue_length--; 845 mq->queue_length--;
891 LOG (GNUNET_ERROR_TYPE_DEBUG, 846 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -974,8 +929,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
974 GNUNET_assert (GNUNET_NO == mq->in_flight); 929 GNUNET_assert (GNUNET_NO == mq->in_flight);
975 GNUNET_assert (0 < mq->queue_length); 930 GNUNET_assert (0 < mq->queue_length);
976 mq->queue_length--; 931 mq->queue_length--;
977 mq->cancel_impl (mq, 932 mq->cancel_impl (mq, mq->impl_state);
978 mq->impl_state);
979 /* continue sending the next message, if any */ 933 /* continue sending the next message, if any */
980 mq->current_envelope = mq->envelope_head; 934 mq->current_envelope = mq->envelope_head;
981 if (NULL != mq->current_envelope) 935 if (NULL != mq->current_envelope)
@@ -986,19 +940,15 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
986 940
987 LOG (GNUNET_ERROR_TYPE_DEBUG, 941 LOG (GNUNET_ERROR_TYPE_DEBUG,
988 "sending canceled message of type %u queue\n", 942 "sending canceled message of type %u queue\n",
989 ntohs(ev->mh->type)); 943 ntohs (ev->mh->type));
990 944
991 mq->send_impl (mq, 945 mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
992 mq->current_envelope->mh,
993 mq->impl_state);
994 } 946 }
995 } 947 }
996 else 948 else
997 { 949 {
998 /* simple case, message is still waiting in the queue */ 950 /* simple case, message is still waiting in the queue */
999 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 951 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
1000 mq->envelope_tail,
1001 ev);
1002 GNUNET_assert (0 < mq->queue_length); 952 GNUNET_assert (0 < mq->queue_length);
1003 mq->queue_length--; 953 mq->queue_length--;
1004 } 954 }
@@ -1044,21 +994,18 @@ GNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq)
1044 994
1045 995
1046/** 996/**
1047 * Set application-specific options for this envelope. 997 * Set application-specific preferences for this envelope.
1048 * Overrides the options set for the queue with 998 * Overrides the options set for the queue with
1049 * #GNUNET_MQ_set_options() for this message only. 999 * #GNUNET_MQ_set_options() for this message only.
1050 * 1000 *
1051 * @param env message to set options for 1001 * @param env message to set options for
1052 * @param flags flags to use (meaning is queue-specific) 1002 * @param pp priorities and preferences to apply
1053 * @param extra additional buffer for further data (also queue-specific)
1054 */ 1003 */
1055void 1004void
1056GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env, 1005GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env,
1057 uint64_t flags, 1006 enum GNUNET_MQ_PriorityPreferences pp)
1058 const void *extra)
1059{ 1007{
1060 env->flags = flags; 1008 env->priority = pp;
1061 env->extra = extra;
1062 env->have_custom_options = GNUNET_YES; 1009 env->have_custom_options = GNUNET_YES;
1063} 1010}
1064 1011
@@ -1067,44 +1014,57 @@ GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env,
1067 * Get application-specific options for this envelope. 1014 * Get application-specific options for this envelope.
1068 * 1015 *
1069 * @param env message to set options for 1016 * @param env message to set options for
1070 * @param[out] flags set to flags to use (meaning is queue-specific) 1017 * @return priorities and preferences to apply for @a env
1071 * @return extra additional buffer for further data (also queue-specific)
1072 */ 1018 */
1073const void * 1019enum GNUNET_MQ_PriorityPreferences
1074GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env, 1020GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env)
1075 uint64_t *flags)
1076{ 1021{
1077 struct GNUNET_MQ_Handle *mq = env->parent_queue; 1022 struct GNUNET_MQ_Handle *mq = env->parent_queue;
1078 1023
1079 if (GNUNET_YES == env->have_custom_options) 1024 if (GNUNET_YES == env->have_custom_options)
1080 { 1025 return env->priority;
1081 *flags = env->flags;
1082 return env->extra;
1083 }
1084 if (NULL == mq) 1026 if (NULL == mq)
1085 { 1027 return 0;
1086 *flags = 0; 1028 return mq->priority;
1087 return NULL; 1029}
1088 } 1030
1089 *flags = mq->default_flags; 1031
1090 return mq->default_extra; 1032/**
1033 * Combine performance preferences set for different
1034 * envelopes that are being combined into one larger envelope.
1035 *
1036 * @param p1 one set of preferences
1037 * @param p2 second set of preferences
1038 * @return combined priority and preferences to use
1039 */
1040enum GNUNET_MQ_PriorityPreferences
1041GNUNET_MQ_env_combine_options (enum GNUNET_MQ_PriorityPreferences p1,
1042 enum GNUNET_MQ_PriorityPreferences p2)
1043{
1044 enum GNUNET_MQ_PriorityPreferences ret;
1045
1046 ret = GNUNET_MAX (p1 & GNUNET_MQ_PRIORITY_MASK, p2 & GNUNET_MQ_PRIORITY_MASK);
1047 ret |= ((p1 & GNUNET_MQ_PREF_UNRELIABLE) & (p2 & GNUNET_MQ_PREF_UNRELIABLE));
1048 ret |=
1049 ((p1 & GNUNET_MQ_PREF_LOW_LATENCY) | (p2 & GNUNET_MQ_PREF_LOW_LATENCY));
1050 ret |=
1051 ((p1 & GNUNET_MQ_PREF_CORK_ALLOWED) & (p2 & GNUNET_MQ_PREF_CORK_ALLOWED));
1052 ret |= ((p1 & GNUNET_MQ_PREF_GOODPUT) & (p2 & GNUNET_MQ_PREF_GOODPUT));
1053 return ret;
1091} 1054}
1092 1055
1093 1056
1094/** 1057/**
1095 * Set application-specific options for this queue. 1058 * Set application-specific default options for this queue.
1096 * 1059 *
1097 * @param mq message queue to set options for 1060 * @param mq message queue to set options for
1098 * @param flags flags to use (meaning is queue-specific) 1061 * @param pp priorities and preferences to apply
1099 * @param extra additional buffer for further data (also queue-specific)
1100 */ 1062 */
1101void 1063void
1102GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq, 1064GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
1103 uint64_t flags, 1065 enum GNUNET_MQ_PriorityPreferences pp)
1104 const void *extra)
1105{ 1066{
1106 mq->default_flags = flags; 1067 mq->priority = pp;
1107 mq->default_extra = extra;
1108} 1068}
1109 1069
1110 1070
@@ -1145,8 +1105,8 @@ GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env)
1145 */ 1105 */
1146struct GNUNET_MQ_DestroyNotificationHandle * 1106struct GNUNET_MQ_DestroyNotificationHandle *
1147GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq, 1107GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
1148 GNUNET_SCHEDULER_TaskCallback cb, 1108 GNUNET_SCHEDULER_TaskCallback cb,
1149 void *cb_cls) 1109 void *cb_cls)
1150{ 1110{
1151 struct GNUNET_MQ_DestroyNotificationHandle *dnh; 1111 struct GNUNET_MQ_DestroyNotificationHandle *dnh;
1152 1112
@@ -1154,9 +1114,7 @@ GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
1154 dnh->mq = mq; 1114 dnh->mq = mq;
1155 dnh->cb = cb; 1115 dnh->cb = cb;
1156 dnh->cb_cls = cb_cls; 1116 dnh->cb_cls = cb_cls;
1157 GNUNET_CONTAINER_DLL_insert (mq->dnh_head, 1117 GNUNET_CONTAINER_DLL_insert (mq->dnh_head, mq->dnh_tail, dnh);
1158 mq->dnh_tail,
1159 dnh);
1160 return dnh; 1118 return dnh;
1161} 1119}
1162 1120
@@ -1167,13 +1125,12 @@ GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
1167 * @param dnh handle for registration to cancel 1125 * @param dnh handle for registration to cancel
1168 */ 1126 */
1169void 1127void
1170GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh) 1128GNUNET_MQ_destroy_notify_cancel (
1129 struct GNUNET_MQ_DestroyNotificationHandle *dnh)
1171{ 1130{
1172 struct GNUNET_MQ_Handle *mq = dnh->mq; 1131 struct GNUNET_MQ_Handle *mq = dnh->mq;
1173 1132
1174 GNUNET_CONTAINER_DLL_remove (mq->dnh_head, 1133 GNUNET_CONTAINER_DLL_remove (mq->dnh_head, mq->dnh_tail, dnh);
1175 mq->dnh_tail,
1176 dnh);
1177 GNUNET_free (dnh); 1134 GNUNET_free (dnh);
1178} 1135}
1179 1136
@@ -1195,9 +1152,7 @@ GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
1195 struct GNUNET_MQ_Envelope **env_tail, 1152 struct GNUNET_MQ_Envelope **env_tail,
1196 struct GNUNET_MQ_Envelope *env) 1153 struct GNUNET_MQ_Envelope *env)
1197{ 1154{
1198 GNUNET_CONTAINER_DLL_insert_tail (*env_head, 1155 GNUNET_CONTAINER_DLL_insert_tail (*env_head, *env_tail, env);
1199 *env_tail,
1200 env);
1201} 1156}
1202 1157
1203 1158
@@ -1218,9 +1173,7 @@ GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head,
1218 struct GNUNET_MQ_Envelope **env_tail, 1173 struct GNUNET_MQ_Envelope **env_tail,
1219 struct GNUNET_MQ_Envelope *env) 1174 struct GNUNET_MQ_Envelope *env)
1220{ 1175{
1221 GNUNET_CONTAINER_DLL_remove (*env_head, 1176 GNUNET_CONTAINER_DLL_remove (*env_head, *env_tail, env);
1222 *env_tail,
1223 env);
1224} 1177}
1225 1178
1226 1179
@@ -1244,8 +1197,7 @@ GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1244 return NULL; 1197 return NULL;
1245 1198
1246 count = GNUNET_MQ_count_handlers (handlers); 1199 count = GNUNET_MQ_count_handlers (handlers);
1247 copy = GNUNET_new_array (count + 1, 1200 copy = GNUNET_new_array (count + 1, struct GNUNET_MQ_MessageHandler);
1248 struct GNUNET_MQ_MessageHandler);
1249 GNUNET_memcpy (copy, 1201 GNUNET_memcpy (copy,
1250 handlers, 1202 handlers,
1251 count * sizeof (struct GNUNET_MQ_MessageHandler)); 1203 count * sizeof (struct GNUNET_MQ_MessageHandler));
@@ -1276,8 +1228,7 @@ GNUNET_MQ_copy_handlers2 (const struct GNUNET_MQ_MessageHandler *handlers,
1276 if (NULL == handlers) 1228 if (NULL == handlers)
1277 return NULL; 1229 return NULL;
1278 count = GNUNET_MQ_count_handlers (handlers); 1230 count = GNUNET_MQ_count_handlers (handlers);
1279 copy = GNUNET_new_array (count + 2, 1231 copy = GNUNET_new_array (count + 2, struct GNUNET_MQ_MessageHandler);
1280 struct GNUNET_MQ_MessageHandler);
1281 GNUNET_memcpy (copy, 1232 GNUNET_memcpy (copy,
1282 handlers, 1233 handlers,
1283 count * sizeof (struct GNUNET_MQ_MessageHandler)); 1234 count * sizeof (struct GNUNET_MQ_MessageHandler));
@@ -1304,7 +1255,8 @@ GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1304 if (NULL == handlers) 1255 if (NULL == handlers)
1305 return 0; 1256 return 0;
1306 1257
1307 for (i=0; NULL != handlers[i].cb; i++) ; 1258 for (i = 0; NULL != handlers[i].cb; i++)
1259 ;
1308 1260
1309 return i; 1261 return i;
1310} 1262}
@@ -1319,7 +1271,8 @@ GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1319const char * 1271const char *
1320GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type) 1272GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type)
1321{ 1273{
1322 switch (type) { 1274 switch (type)
1275 {
1323 case GNUNET_MQ_PREFERENCE_NONE: 1276 case GNUNET_MQ_PREFERENCE_NONE:
1324 return "NONE"; 1277 return "NONE";
1325 case GNUNET_MQ_PREFERENCE_BANDWIDTH: 1278 case GNUNET_MQ_PREFERENCE_BANDWIDTH: