aboutsummaryrefslogtreecommitdiff
path: root/src/dv
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/dv
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/dv')
-rw-r--r--src/dv/dv.h15
-rw-r--r--src/dv/dv_api.c347
-rw-r--r--src/dv/gnunet-service-dv.c2271
-rw-r--r--src/dv/plugin_transport_dv.c157
-rw-r--r--src/dv/test_transport_api_dv.c1154
5 files changed, 2149 insertions, 1795 deletions
diff --git a/src/dv/dv.h b/src/dv/dv.h
index 10b531ced..3c62a22bc 100644
--- a/src/dv/dv.h
+++ b/src/dv/dv.h
@@ -37,8 +37,8 @@
37#define DEBUG_MESSAGE_DROP GNUNET_NO 37#define DEBUG_MESSAGE_DROP GNUNET_NO
38 38
39typedef void (*GNUNET_DV_MessageReceivedHandler) (void *cls, 39typedef void (*GNUNET_DV_MessageReceivedHandler) (void *cls,
40 struct GNUNET_PeerIdentity *sender, 40 struct GNUNET_PeerIdentity *
41 char *msg, 41 sender, char *msg,
42 size_t msg_len, 42 size_t msg_len,
43 uint32_t distance, 43 uint32_t distance,
44 char *sender_address, 44 char *sender_address,
@@ -257,16 +257,17 @@ typedef struct
257} p2p_dv_MESSAGE_Disconnect; 257} p2p_dv_MESSAGE_Disconnect;
258 258
259 259
260struct GNUNET_DV_Handle * 260struct GNUNET_DV_Handle *GNUNET_DV_connect (const struct
261GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 261 GNUNET_CONFIGURATION_Handle *cfg,
262 GNUNET_DV_MessageReceivedHandler receive_handler, 262 GNUNET_DV_MessageReceivedHandler
263 void *receive_handler_cls); 263 receive_handler,
264 void *receive_handler_cls);
264 265
265/** 266/**
266 * Disconnect from the DV service 267 * Disconnect from the DV service
267 * 268 *
268 * @param handle the current handle to the service to disconnect 269 * @param handle the current handle to the service to disconnect
269 */ 270 */
270void GNUNET_DV_disconnect(struct GNUNET_DV_Handle *handle); 271void GNUNET_DV_disconnect (struct GNUNET_DV_Handle *handle);
271 272
272#endif 273#endif
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index d954d718b..7a250b5a6 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -152,11 +152,10 @@ struct SendCallbackContext
152 * @param hash set to uid (extended with zeros) 152 * @param hash set to uid (extended with zeros)
153 */ 153 */
154static void 154static void
155hash_from_uid (uint32_t uid, 155hash_from_uid (uint32_t uid, GNUNET_HashCode * hash)
156 GNUNET_HashCode *hash)
157{ 156{
158 memset (hash, 0, sizeof(GNUNET_HashCode)); 157 memset (hash, 0, sizeof (GNUNET_HashCode));
159 *((uint32_t*)hash) = uid; 158 *((uint32_t *) hash) = uid;
160} 159}
161 160
162/** 161/**
@@ -181,7 +180,7 @@ try_connect (struct GNUNET_DV_Handle *ret)
181 return GNUNET_NO; 180 return GNUNET_NO;
182} 181}
183 182
184static void process_pending_message(struct GNUNET_DV_Handle *handle); 183static void process_pending_message (struct GNUNET_DV_Handle *handle);
185 184
186/** 185/**
187 * Send complete, schedule next 186 * Send complete, schedule next
@@ -193,10 +192,11 @@ static void
193finish (struct GNUNET_DV_Handle *handle, int code) 192finish (struct GNUNET_DV_Handle *handle, int code)
194{ 193{
195 struct PendingMessages *pos = handle->current; 194 struct PendingMessages *pos = handle->current;
195
196 handle->current = NULL; 196 handle->current = NULL;
197 process_pending_message (handle); 197 process_pending_message (handle);
198 198
199 GNUNET_free(pos->msg); 199 GNUNET_free (pos->msg);
200 GNUNET_free (pos); 200 GNUNET_free (pos);
201} 201}
202 202
@@ -218,31 +218,35 @@ transmit_pending (void *cls, size_t size, void *buf)
218 218
219#if DEBUG_DV 219#if DEBUG_DV
220 if (handle->current != NULL) 220 if (handle->current != NULL)
221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Transmit pending called with message type %d\n", ntohs(handle->current->msg->header.type)); 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "DV API: Transmit pending called with message type %d\n",
223 ntohs (handle->current->msg->header.type));
222#endif 224#endif
223 225
224 if (buf == NULL) 226 if (buf == NULL)
225 { 227 {
226#if DEBUG_DV 228#if DEBUG_DV
227 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Transmit pending FAILED!\n\n\n"); 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "DV API: Transmit pending FAILED!\n\n\n");
228#endif 231#endif
229 finish(handle, GNUNET_SYSERR); 232 finish (handle, GNUNET_SYSERR);
230 return 0; 233 return 0;
231 } 234 }
232 handle->th = NULL; 235 handle->th = NULL;
233 236
234 ret = 0; 237 ret = 0;
235 238
236 if (handle->current != NULL) 239 if (handle->current != NULL)
237 { 240 {
238 tsize = ntohs(handle->current->msg->header.size); 241 tsize = ntohs (handle->current->msg->header.size);
239 if (size >= tsize) 242 if (size >= tsize)
240 { 243 {
241 memcpy(buf, handle->current->msg, tsize); 244 memcpy (buf, handle->current->msg, tsize);
242#if DEBUG_DV 245#if DEBUG_DV
243 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Copied %d bytes into buffer!\n\n\n", tsize); 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "DV API: Copied %d bytes into buffer!\n\n\n", tsize);
244#endif 248#endif
245 finish(handle, GNUNET_OK); 249 finish (handle, GNUNET_OK);
246 return tsize; 250 return tsize;
247 } 251 }
248 252
@@ -256,39 +260,44 @@ transmit_pending (void *cls, size_t size, void *buf)
256 * 260 *
257 * @param handle handle to the distance vector service 261 * @param handle handle to the distance vector service
258 */ 262 */
259static void process_pending_message(struct GNUNET_DV_Handle *handle) 263static void
264process_pending_message (struct GNUNET_DV_Handle *handle)
260{ 265{
261 266
262 if (handle->current != NULL) 267 if (handle->current != NULL)
263 return; /* action already pending */ 268 return; /* action already pending */
264 if (GNUNET_YES != try_connect (handle)) 269 if (GNUNET_YES != try_connect (handle))
265 { 270 {
266 finish (handle, GNUNET_SYSERR); 271 finish (handle, GNUNET_SYSERR);
267 return; 272 return;
268 } 273 }
269 274
270 /* schedule next action */ 275 /* schedule next action */
271 handle->current = handle->pending_list; 276 handle->current = handle->pending_list;
272 if (NULL == handle->current) 277 if (NULL == handle->current)
273 { 278 {
274 return; 279 return;
275 } 280 }
276 handle->pending_list = handle->pending_list->next; 281 handle->pending_list = handle->pending_list->next;
277 handle->current->next = NULL; 282 handle->current->next = NULL;
278 283
279 if (NULL == 284 if (NULL ==
280 (handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client, 285 (handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client,
281 ntohs(handle->current->msg->header.size), 286 ntohs
282 handle->current->msg->timeout, 287 (handle->current->
288 msg->header.size),
289 handle->current->
290 msg->timeout,
283 GNUNET_YES, 291 GNUNET_YES,
284 &transmit_pending, handle))) 292 &transmit_pending,
285 { 293 handle)))
294 {
286#if DEBUG_DV 295#if DEBUG_DV
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "Failed to transmit request to dv service.\n"); 297 "Failed to transmit request to dv service.\n");
289#endif 298#endif
290 finish (handle, GNUNET_SYSERR); 299 finish (handle, GNUNET_SYSERR);
291 } 300 }
292} 301}
293 302
294/** 303/**
@@ -297,31 +306,32 @@ static void process_pending_message(struct GNUNET_DV_Handle *handle)
297 * @param handle handle to the specified DV api 306 * @param handle handle to the specified DV api
298 * @param msg the message to add to the list 307 * @param msg the message to add to the list
299 */ 308 */
300static void add_pending(struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMessage *msg) 309static void
310add_pending (struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMessage *msg)
301{ 311{
302 struct PendingMessages *new_message; 312 struct PendingMessages *new_message;
303 struct PendingMessages *pos; 313 struct PendingMessages *pos;
304 struct PendingMessages *last; 314 struct PendingMessages *last;
305 315
306 new_message = GNUNET_malloc(sizeof(struct PendingMessages)); 316 new_message = GNUNET_malloc (sizeof (struct PendingMessages));
307 new_message->msg = msg; 317 new_message->msg = msg;
308 318
309 if (handle->pending_list != NULL) 319 if (handle->pending_list != NULL)
320 {
321 pos = handle->pending_list;
322 while (pos != NULL)
310 { 323 {
311 pos = handle->pending_list; 324 last = pos;
312 while(pos != NULL) 325 pos = pos->next;
313 {
314 last = pos;
315 pos = pos->next;
316 }
317 last->next = new_message;
318 } 326 }
327 last->next = new_message;
328 }
319 else 329 else
320 { 330 {
321 handle->pending_list = new_message; 331 handle->pending_list = new_message;
322 } 332 }
323 333
324 process_pending_message(handle); 334 process_pending_message (handle);
325} 335}
326 336
327/** 337/**
@@ -331,8 +341,8 @@ static void add_pending(struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMe
331 * @param cls the handle to the DV API 341 * @param cls the handle to the DV API
332 * @param msg the message that was received 342 * @param msg the message that was received
333 */ 343 */
334void handle_message_receipt (void *cls, 344void
335 const struct GNUNET_MessageHeader * msg) 345handle_message_receipt (void *cls, const struct GNUNET_MessageHeader *msg)
336{ 346{
337 struct GNUNET_DV_Handle *handle = cls; 347 struct GNUNET_DV_Handle *handle = cls;
338 struct GNUNET_DV_MessageReceived *received_msg; 348 struct GNUNET_DV_MessageReceived *received_msg;
@@ -348,65 +358,75 @@ void handle_message_receipt (void *cls,
348 if (msg == NULL) 358 if (msg == NULL)
349 { 359 {
350#if DEBUG_DV_MESSAGES 360#if DEBUG_DV_MESSAGES
351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: connection closed\n"); 361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: connection closed\n");
352#endif 362#endif
353 return; /* Connection closed? */ 363 return; /* Connection closed? */
354 } 364 }
355 365
356 GNUNET_assert((ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE) || (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT)); 366 GNUNET_assert ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE)
367 || (ntohs (msg->type) ==
368 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT));
357 369
358 switch (ntohs(msg->type)) 370 switch (ntohs (msg->type))
359 { 371 {
360 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE: 372 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE:
361 if (ntohs(msg->size) < sizeof(struct GNUNET_DV_MessageReceived)) 373 if (ntohs (msg->size) < sizeof (struct GNUNET_DV_MessageReceived))
362 return; 374 return;
363 375
364 received_msg = (struct GNUNET_DV_MessageReceived *)msg; 376 received_msg = (struct GNUNET_DV_MessageReceived *) msg;
365 packed_msg_len = ntohl(received_msg->msg_len); 377 packed_msg_len = ntohl (received_msg->msg_len);
366 sender_address_len = ntohs(msg->size) - packed_msg_len - sizeof(struct GNUNET_DV_MessageReceived); 378 sender_address_len =
367 GNUNET_assert(sender_address_len > 0); 379 ntohs (msg->size) - packed_msg_len -
368 sender_address = GNUNET_malloc(sender_address_len); 380 sizeof (struct GNUNET_DV_MessageReceived);
369 memcpy(sender_address, &received_msg[1], sender_address_len); 381 GNUNET_assert (sender_address_len > 0);
370 packed_msg_start = (char *)&received_msg[1]; 382 sender_address = GNUNET_malloc (sender_address_len);
371 packed_msg = GNUNET_malloc(packed_msg_len); 383 memcpy (sender_address, &received_msg[1], sender_address_len);
372 memcpy(packed_msg, &packed_msg_start[sender_address_len], packed_msg_len); 384 packed_msg_start = (char *) &received_msg[1];
385 packed_msg = GNUNET_malloc (packed_msg_len);
386 memcpy (packed_msg, &packed_msg_start[sender_address_len], packed_msg_len);
373 387
374#if DEBUG_DV_MESSAGES 388#if DEBUG_DV_MESSAGES
375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: packed message type: %d or %d\n", ntohs(((struct GNUNET_MessageHeader *)packed_msg)->type), ((struct GNUNET_MessageHeader *)packed_msg)->type); 389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: message sender reported as %s\n", GNUNET_i2s(&received_msg->sender)); 390 "DV_API receive: packed message type: %d or %d\n",
377 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: distance is %u\n", ntohl(received_msg->distance)); 391 ntohs (((struct GNUNET_MessageHeader *) packed_msg)->type),
392 ((struct GNUNET_MessageHeader *) packed_msg)->type);
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "DV_API receive: message sender reported as %s\n",
395 GNUNET_i2s (&received_msg->sender));
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: distance is %u\n",
397 ntohl (received_msg->distance));
378#endif 398#endif
379 399
380 handle->receive_handler(handle->receive_cls, 400 handle->receive_handler (handle->receive_cls,
381 &received_msg->sender, 401 &received_msg->sender,
382 packed_msg, 402 packed_msg,
383 packed_msg_len, 403 packed_msg_len,
384 ntohl(received_msg->distance), 404 ntohl (received_msg->distance),
385 sender_address, 405 sender_address, sender_address_len);
386 sender_address_len);
387 406
388 GNUNET_free(sender_address); 407 GNUNET_free (sender_address);
389 break; 408 break;
390 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT: 409 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT:
391 if (ntohs(msg->size) < sizeof(struct GNUNET_DV_SendResultMessage)) 410 if (ntohs (msg->size) < sizeof (struct GNUNET_DV_SendResultMessage))
392 return; 411 return;
393 412
394 send_result_msg = (struct GNUNET_DV_SendResultMessage *)msg; 413 send_result_msg = (struct GNUNET_DV_SendResultMessage *) msg;
395 hash_from_uid(ntohl(send_result_msg->uid), &uidhash); 414 hash_from_uid (ntohl (send_result_msg->uid), &uidhash);
396 send_ctx = GNUNET_CONTAINER_multihashmap_get(handle->send_callbacks, &uidhash); 415 send_ctx =
416 GNUNET_CONTAINER_multihashmap_get (handle->send_callbacks, &uidhash);
397 417
398 if ((send_ctx != NULL) && (send_ctx->cont != NULL)) 418 if ((send_ctx != NULL) && (send_ctx->cont != NULL))
419 {
420 if (ntohl (send_result_msg->result) == 0)
421 {
422 send_ctx->cont (send_ctx->cont_cls, &send_ctx->target, GNUNET_OK);
423 }
424 else
399 { 425 {
400 if (ntohl(send_result_msg->result) == 0) 426 send_ctx->cont (send_ctx->cont_cls, &send_ctx->target, GNUNET_SYSERR);
401 {
402 send_ctx->cont(send_ctx->cont_cls, &send_ctx->target, GNUNET_OK);
403 }
404 else
405 {
406 send_ctx->cont(send_ctx->cont_cls, &send_ctx->target, GNUNET_SYSERR);
407 }
408 } 427 }
409 GNUNET_free_non_null(send_ctx); 428 }
429 GNUNET_free_non_null (send_ctx);
410 break; 430 break;
411 default: 431 default:
412 break; 432 break;
@@ -432,48 +452,52 @@ void handle_message_receipt (void *cls,
432 * @param cont_cls closure for continuation 452 * @param cont_cls closure for continuation
433 * 453 *
434 */ 454 */
435int GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle, 455int
436 const struct GNUNET_PeerIdentity *target, 456GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
437 const char *msgbuf, 457 const struct GNUNET_PeerIdentity *target,
438 size_t msgbuf_size, 458 const char *msgbuf,
439 unsigned int priority, 459 size_t msgbuf_size,
440 struct GNUNET_TIME_Relative timeout, 460 unsigned int priority,
441 const void *addr, 461 struct GNUNET_TIME_Relative timeout,
442 size_t addrlen, 462 const void *addr,
443 GNUNET_TRANSPORT_TransmitContinuation 463 size_t addrlen,
444 cont, void *cont_cls) 464 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
445{ 465{
446 struct GNUNET_DV_SendMessage *msg; 466 struct GNUNET_DV_SendMessage *msg;
447 struct SendCallbackContext *send_ctx; 467 struct SendCallbackContext *send_ctx;
448 char *end_of_message; 468 char *end_of_message;
449 GNUNET_HashCode uidhash; 469 GNUNET_HashCode uidhash;
450 int msize; 470 int msize;
471
451#if DEBUG_DV_MESSAGES 472#if DEBUG_DV_MESSAGES
452 dv_handle->uid_gen = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX); 473 dv_handle->uid_gen =
474 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX);
453#else 475#else
454 dv_handle->uid_gen++; 476 dv_handle->uid_gen++;
455#endif 477#endif
456 478
457 msize = sizeof(struct GNUNET_DV_SendMessage) + addrlen + msgbuf_size; 479 msize = sizeof (struct GNUNET_DV_SendMessage) + addrlen + msgbuf_size;
458 msg = GNUNET_malloc(msize); 480 msg = GNUNET_malloc (msize);
459 msg->header.size = htons(msize); 481 msg->header.size = htons (msize);
460 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND); 482 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND);
461 memcpy(&msg->target, target, sizeof(struct GNUNET_PeerIdentity)); 483 memcpy (&msg->target, target, sizeof (struct GNUNET_PeerIdentity));
462 msg->priority = htonl(priority); 484 msg->priority = htonl (priority);
463 msg->timeout = timeout; 485 msg->timeout = timeout;
464 msg->addrlen = htonl(addrlen); 486 msg->addrlen = htonl (addrlen);
465 msg->uid = htonl(dv_handle->uid_gen); 487 msg->uid = htonl (dv_handle->uid_gen);
466 memcpy(&msg[1], addr, addrlen); 488 memcpy (&msg[1], addr, addrlen);
467 end_of_message = (char *)&msg[1]; 489 end_of_message = (char *) &msg[1];
468 end_of_message = &end_of_message[addrlen]; 490 end_of_message = &end_of_message[addrlen];
469 memcpy(end_of_message, msgbuf, msgbuf_size); 491 memcpy (end_of_message, msgbuf, msgbuf_size);
470 add_pending(dv_handle, msg); 492 add_pending (dv_handle, msg);
471 send_ctx = GNUNET_malloc(sizeof(struct SendCallbackContext)); 493 send_ctx = GNUNET_malloc (sizeof (struct SendCallbackContext));
472 send_ctx->cont = cont; 494 send_ctx->cont = cont;
473 send_ctx->cont_cls = cont_cls; 495 send_ctx->cont_cls = cont_cls;
474 memcpy(&send_ctx->target, target, sizeof(struct GNUNET_PeerIdentity)); 496 memcpy (&send_ctx->target, target, sizeof (struct GNUNET_PeerIdentity));
475 hash_from_uid(dv_handle->uid_gen, &uidhash); 497 hash_from_uid (dv_handle->uid_gen, &uidhash);
476 GNUNET_CONTAINER_multihashmap_put(dv_handle->send_callbacks, &uidhash, send_ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 498 GNUNET_CONTAINER_multihashmap_put (dv_handle->send_callbacks, &uidhash,
499 send_ctx,
500 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
477 501
478 return GNUNET_OK; 502 return GNUNET_OK;
479} 503}
@@ -494,23 +518,25 @@ transmit_start (void *cls, size_t size, void *buf)
494 struct StartContext *start_context = cls; 518 struct StartContext *start_context = cls;
495 struct GNUNET_DV_Handle *handle = start_context->handle; 519 struct GNUNET_DV_Handle *handle = start_context->handle;
496 size_t tsize; 520 size_t tsize;
521
497#if DEBUG_DV 522#if DEBUG_DV
498 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: sending start request to service\n"); 523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
524 "DV API: sending start request to service\n");
499#endif 525#endif
500 if (buf == NULL) 526 if (buf == NULL)
501 { 527 {
502 GNUNET_free(start_context->message); 528 GNUNET_free (start_context->message);
503 GNUNET_free(start_context); 529 GNUNET_free (start_context);
504 GNUNET_DV_disconnect(handle); 530 GNUNET_DV_disconnect (handle);
505 return 0; 531 return 0;
506 } 532 }
507 533
508 tsize = ntohs(start_context->message->size); 534 tsize = ntohs (start_context->message->size);
509 if (size >= tsize) 535 if (size >= tsize)
510 { 536 {
511 memcpy(buf, start_context->message, tsize); 537 memcpy (buf, start_context->message, tsize);
512 GNUNET_free(start_context->message); 538 GNUNET_free (start_context->message);
513 GNUNET_free(start_context); 539 GNUNET_free (start_context);
514 GNUNET_CLIENT_receive (handle->client, 540 GNUNET_CLIENT_receive (handle->client,
515 &handle_message_receipt, 541 &handle_message_receipt,
516 handle, GNUNET_TIME_UNIT_FOREVER_REL); 542 handle, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -533,42 +559,44 @@ transmit_start (void *cls, size_t size, void *buf)
533 */ 559 */
534struct GNUNET_DV_Handle * 560struct GNUNET_DV_Handle *
535GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 561GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
536 GNUNET_DV_MessageReceivedHandler receive_handler, 562 GNUNET_DV_MessageReceivedHandler receive_handler,
537 void *receive_handler_cls) 563 void *receive_handler_cls)
538{ 564{
539 struct GNUNET_DV_Handle *handle; 565 struct GNUNET_DV_Handle *handle;
540 struct GNUNET_MessageHeader *start_message; 566 struct GNUNET_MessageHeader *start_message;
541 struct StartContext *start_context; 567 struct StartContext *start_context;
542 handle = GNUNET_malloc(sizeof(struct GNUNET_DV_Handle)); 568
569 handle = GNUNET_malloc (sizeof (struct GNUNET_DV_Handle));
543 570
544 handle->cfg = cfg; 571 handle->cfg = cfg;
545 handle->pending_list = NULL; 572 handle->pending_list = NULL;
546 handle->current = NULL; 573 handle->current = NULL;
547 handle->th = NULL; 574 handle->th = NULL;
548 handle->client = GNUNET_CLIENT_connect("dv", cfg); 575 handle->client = GNUNET_CLIENT_connect ("dv", cfg);
549 handle->receive_handler = receive_handler; 576 handle->receive_handler = receive_handler;
550 handle->receive_cls = receive_handler_cls; 577 handle->receive_cls = receive_handler_cls;
551 578
552 if (handle->client == NULL) 579 if (handle->client == NULL)
553 { 580 {
554 GNUNET_free(handle); 581 GNUNET_free (handle);
555 return NULL; 582 return NULL;
556 } 583 }
557 584
558 start_message = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)); 585 start_message = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
559 start_message->size = htons(sizeof(struct GNUNET_MessageHeader)); 586 start_message->size = htons (sizeof (struct GNUNET_MessageHeader));
560 start_message->type = htons(GNUNET_MESSAGE_TYPE_DV_START); 587 start_message->type = htons (GNUNET_MESSAGE_TYPE_DV_START);
561 588
562 start_context = GNUNET_malloc(sizeof(struct StartContext)); 589 start_context = GNUNET_malloc (sizeof (struct StartContext));
563 start_context->handle = handle; 590 start_context->handle = handle;
564 start_context->message = start_message; 591 start_context->message = start_message;
565 GNUNET_CLIENT_notify_transmit_ready (handle->client, 592 GNUNET_CLIENT_notify_transmit_ready (handle->client,
566 sizeof(struct GNUNET_MessageHeader), 593 sizeof (struct GNUNET_MessageHeader),
567 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), 594 GNUNET_TIME_relative_multiply
568 GNUNET_YES, 595 (GNUNET_TIME_UNIT_SECONDS, 60),
569 &transmit_start, start_context); 596 GNUNET_YES, &transmit_start,
597 start_context);
570 598
571 handle->send_callbacks = GNUNET_CONTAINER_multihashmap_create(100); 599 handle->send_callbacks = GNUNET_CONTAINER_multihashmap_create (100);
572 600
573 return handle; 601 return handle;
574} 602}
@@ -578,29 +606,30 @@ GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
578 * 606 *
579 * @param handle the current handle to the service to disconnect 607 * @param handle the current handle to the service to disconnect
580 */ 608 */
581void GNUNET_DV_disconnect(struct GNUNET_DV_Handle *handle) 609void
610GNUNET_DV_disconnect (struct GNUNET_DV_Handle *handle)
582{ 611{
583 struct PendingMessages *pos; 612 struct PendingMessages *pos;
584 613
585 GNUNET_assert(handle != NULL); 614 GNUNET_assert (handle != NULL);
586 615
587 if (handle->th != NULL) /* We have a live transmit request in the Aether */ 616 if (handle->th != NULL) /* We have a live transmit request in the Aether */
588 { 617 {
589 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 618 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
590 handle->th = NULL; 619 handle->th = NULL;
591 } 620 }
592 if (handle->current != NULL) /* We are trying to send something now, clean it up */ 621 if (handle->current != NULL) /* We are trying to send something now, clean it up */
593 GNUNET_free(handle->current); 622 GNUNET_free (handle->current);
594 while (NULL != (pos = handle->pending_list)) /* Remove all pending sends from the list */ 623 while (NULL != (pos = handle->pending_list)) /* Remove all pending sends from the list */
595 { 624 {
596 handle->pending_list = pos->next; 625 handle->pending_list = pos->next;
597 GNUNET_free(pos); 626 GNUNET_free (pos);
598 } 627 }
599 if (handle->client != NULL) /* Finally, disconnect from the service */ 628 if (handle->client != NULL) /* Finally, disconnect from the service */
600 { 629 {
601 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); 630 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
602 handle->client = NULL; 631 handle->client = NULL;
603 } 632 }
604 633
605 GNUNET_free (handle); 634 GNUNET_free (handle);
606} 635}
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 3f52ddf2c..4b68f69b1 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -158,7 +158,7 @@ struct PendingMessage
158 /** 158 /**
159 * Actual message to be sent; // avoid allocation 159 * Actual message to be sent; // avoid allocation
160 */ 160 */
161 const struct GNUNET_MessageHeader *msg; // msg = (cast) &pm[1]; // memcpy (&pm[1], data, len); 161 const struct GNUNET_MessageHeader *msg; // msg = (cast) &pm[1]; // memcpy (&pm[1], data, len);
162 162
163}; 163};
164 164
@@ -568,7 +568,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
568 * this client will never change, although if the plugin dies 568 * this client will never change, although if the plugin dies
569 * and returns for some reason it may happen. 569 * and returns for some reason it may happen.
570 */ 570 */
571static struct GNUNET_SERVER_Client * client_handle; 571static struct GNUNET_SERVER_Client *client_handle;
572 572
573/** 573/**
574 * Task to run when we shut down, cleaning up all our trash 574 * Task to run when we shut down, cleaning up all our trash
@@ -582,7 +582,7 @@ static char *my_short_id;
582/** 582/**
583 * Transmit handle to the plugin. 583 * Transmit handle to the plugin.
584 */ 584 */
585static struct GNUNET_CONNECTION_TransmitHandle * plugin_transmit_handle; 585static struct GNUNET_CONNECTION_TransmitHandle *plugin_transmit_handle;
586 586
587/** 587/**
588 * Head of DLL for client messages 588 * Head of DLL for client messages
@@ -602,7 +602,7 @@ static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
602/** 602/**
603 * Transmit handle to core service. 603 * Transmit handle to core service.
604 */ 604 */
605static struct GNUNET_CORE_TransmitHandle * core_transmit_handle; 605static struct GNUNET_CORE_TransmitHandle *core_transmit_handle;
606 606
607/** 607/**
608 * Head of DLL for core messages 608 * Head of DLL for core messages
@@ -682,18 +682,18 @@ find_destination (void *cls,
682 * respective neighbor. 682 * respective neighbor.
683 */ 683 */
684static int 684static int
685find_specific_id (void *cls, 685find_specific_id (void *cls, const GNUNET_HashCode * key, void *value)
686 const GNUNET_HashCode *key,
687 void *value)
688{ 686{
689 struct FindIDContext *fdc = cls; 687 struct FindIDContext *fdc = cls;
690 struct DistantNeighbor *dn = value; 688 struct DistantNeighbor *dn = value;
691 689
692 if (memcmp(&dn->referrer->identity, fdc->via, sizeof(struct GNUNET_PeerIdentity)) == 0) 690 if (memcmp
693 { 691 (&dn->referrer->identity, fdc->via,
694 fdc->tid = dn->referrer_id; 692 sizeof (struct GNUNET_PeerIdentity)) == 0)
695 return GNUNET_NO; 693 {
696 } 694 fdc->tid = dn->referrer_id;
695 return GNUNET_NO;
696 }
697 return GNUNET_YES; 697 return GNUNET_YES;
698} 698}
699 699
@@ -704,18 +704,17 @@ find_specific_id (void *cls,
704 * want to remove those that may be accessible via a different 704 * want to remove those that may be accessible via a different
705 * route. 705 * route.
706 */ 706 */
707static int find_distant_peer (void *cls, 707static int
708 const GNUNET_HashCode * key, 708find_distant_peer (void *cls, const GNUNET_HashCode * key, void *value)
709 void *value)
710{ 709{
711 struct FindDestinationContext *fdc = cls; 710 struct FindDestinationContext *fdc = cls;
712 struct DistantNeighbor *distant = value; 711 struct DistantNeighbor *distant = value;
713 712
714 if (fdc->tid == distant->referrer_id) 713 if (fdc->tid == distant->referrer_id)
715 { 714 {
716 fdc->dest = distant; 715 fdc->dest = distant;
717 return GNUNET_NO; 716 return GNUNET_NO;
718 } 717 }
719 return GNUNET_YES; 718 return GNUNET_YES;
720} 719}
721 720
@@ -730,8 +729,8 @@ static int find_distant_peer (void *cls,
730 * @param buf where the callee should write the message 729 * @param buf where the callee should write the message
731 * @return number of bytes written to buf 730 * @return number of bytes written to buf
732 */ 731 */
733size_t transmit_to_plugin (void *cls, 732size_t
734 size_t size, void *buf) 733transmit_to_plugin (void *cls, size_t size, void *buf)
735{ 734{
736 char *cbuf = buf; 735 char *cbuf = buf;
737 struct PendingMessage *reply; 736 struct PendingMessage *reply;
@@ -739,31 +738,35 @@ size_t transmit_to_plugin (void *cls,
739 size_t msize; 738 size_t msize;
740 739
741 if (buf == NULL) 740 if (buf == NULL)
742 { 741 {
743 /* client disconnected */ 742 /* client disconnected */
744#if DEBUG_DV_MESSAGES 743#if DEBUG_DV_MESSAGES
745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s: %s buffer was NULL (client disconnect?)\n", my_short_id, "transmit_to_plugin"); 744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "%s: %s buffer was NULL (client disconnect?)\n", my_short_id,
746 "transmit_to_plugin");
746#endif 747#endif
747 return 0; 748 return 0;
748 } 749 }
749 plugin_transmit_handle = NULL; 750 plugin_transmit_handle = NULL;
750 off = 0; 751 off = 0;
751 while ( (NULL != (reply = plugin_pending_head)) && 752 while ((NULL != (reply = plugin_pending_head)) &&
752 (size >= off + (msize = ntohs (reply->msg->size)))) 753 (size >= off + (msize = ntohs (reply->msg->size))))
753 { 754 {
754 GNUNET_CONTAINER_DLL_remove (plugin_pending_head, 755 GNUNET_CONTAINER_DLL_remove (plugin_pending_head,
755 plugin_pending_tail, 756 plugin_pending_tail, reply);
756 reply); 757 memcpy (&cbuf[off], reply->msg, msize);
757 memcpy (&cbuf[off], reply->msg, msize); 758 GNUNET_free (reply);
758 GNUNET_free (reply); 759 off += msize;
759 off += msize; 760 }
760 }
761 761
762 if (plugin_pending_head != NULL) 762 if (plugin_pending_head != NULL)
763 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 763 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
764 ntohs(plugin_pending_head->msg->size), 764 ntohs
765 (plugin_pending_head->msg->
766 size),
765 GNUNET_TIME_UNIT_FOREVER_REL, 767 GNUNET_TIME_UNIT_FOREVER_REL,
766 &transmit_to_plugin, NULL); 768 &transmit_to_plugin,
769 NULL);
767 770
768 return off; 771 return off;
769} 772}
@@ -778,11 +781,11 @@ size_t transmit_to_plugin (void *cls,
778 * @param distant_neighbor the original sender of the message 781 * @param distant_neighbor the original sender of the message
779 * @param cost the cost to the original sender of the message 782 * @param cost the cost to the original sender of the message
780 */ 783 */
781void send_to_plugin(const struct GNUNET_PeerIdentity * sender, 784void
782 const struct GNUNET_MessageHeader *message, 785send_to_plugin (const struct GNUNET_PeerIdentity *sender,
783 size_t message_size, 786 const struct GNUNET_MessageHeader *message,
784 struct GNUNET_PeerIdentity *distant_neighbor, 787 size_t message_size,
785 size_t cost) 788 struct GNUNET_PeerIdentity *distant_neighbor, size_t cost)
786{ 789{
787 struct GNUNET_DV_MessageReceived *received_msg; 790 struct GNUNET_DV_MessageReceived *received_msg;
788 struct PendingMessage *pending_message; 791 struct PendingMessage *pending_message;
@@ -792,85 +795,96 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
792 int size; 795 int size;
793 796
794#if DEBUG_DV 797#if DEBUG_DV
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_to_plugin called with peer %s as sender\n", GNUNET_i2s(distant_neighbor)); 798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "send_to_plugin called with peer %s as sender\n",
800 GNUNET_i2s (distant_neighbor));
796#endif 801#endif
797 802
798 if (memcmp(sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)) != 0) 803 if (memcmp (sender, distant_neighbor, sizeof (struct GNUNET_PeerIdentity)) !=
804 0)
799 { 805 {
800 sender_address_len = sizeof(struct GNUNET_PeerIdentity) * 2; 806 sender_address_len = sizeof (struct GNUNET_PeerIdentity) * 2;
801 sender_address = GNUNET_malloc(sender_address_len); 807 sender_address = GNUNET_malloc (sender_address_len);
802 memcpy(sender_address, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)); 808 memcpy (sender_address, distant_neighbor,
803 memcpy(&sender_address[sizeof(struct GNUNET_PeerIdentity)], sender, sizeof(struct GNUNET_PeerIdentity)); 809 sizeof (struct GNUNET_PeerIdentity));
810 memcpy (&sender_address[sizeof (struct GNUNET_PeerIdentity)], sender,
811 sizeof (struct GNUNET_PeerIdentity));
804 } 812 }
805 else 813 else
806 { 814 {
807 sender_address_len = sizeof(struct GNUNET_PeerIdentity); 815 sender_address_len = sizeof (struct GNUNET_PeerIdentity);
808 sender_address = GNUNET_malloc(sender_address_len); 816 sender_address = GNUNET_malloc (sender_address_len);
809 memcpy(sender_address, sender, sizeof(struct GNUNET_PeerIdentity)); 817 memcpy (sender_address, sender, sizeof (struct GNUNET_PeerIdentity));
810 } 818 }
811 819
812 size = sizeof(struct GNUNET_DV_MessageReceived) + sender_address_len + message_size; 820 size =
813 received_msg = GNUNET_malloc(size); 821 sizeof (struct GNUNET_DV_MessageReceived) + sender_address_len +
814 received_msg->header.size = htons(size); 822 message_size;
815 received_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE); 823 received_msg = GNUNET_malloc (size);
816 received_msg->distance = htonl(cost); 824 received_msg->header.size = htons (size);
817 received_msg->msg_len = htonl(message_size); 825 received_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE);
826 received_msg->distance = htonl (cost);
827 received_msg->msg_len = htonl (message_size);
818 /* Set the sender in this message to be the original sender! */ 828 /* Set the sender in this message to be the original sender! */
819 memcpy(&received_msg->sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)); 829 memcpy (&received_msg->sender, distant_neighbor,
830 sizeof (struct GNUNET_PeerIdentity));
820 /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */ 831 /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */
821 memcpy(&received_msg[1], sender_address, sender_address_len); 832 memcpy (&received_msg[1], sender_address, sender_address_len);
822 GNUNET_free(sender_address); 833 GNUNET_free (sender_address);
823 /* Copy the actual message after the sender */ 834 /* Copy the actual message after the sender */
824 packed_msg_start = (char *)&received_msg[1]; 835 packed_msg_start = (char *) &received_msg[1];
825 packed_msg_start = &packed_msg_start[sender_address_len]; 836 packed_msg_start = &packed_msg_start[sender_address_len];
826 memcpy(packed_msg_start, message, message_size); 837 memcpy (packed_msg_start, message, message_size);
827 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + size); 838 pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + size);
828 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 839 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
829 memcpy(&pending_message[1], received_msg, size); 840 memcpy (&pending_message[1], received_msg, size);
830 GNUNET_free(received_msg); 841 GNUNET_free (received_msg);
831 842
832 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message); 843 GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head, plugin_pending_tail,
844 plugin_pending_tail, pending_message);
833 845
834 if (client_handle != NULL) 846 if (client_handle != NULL)
847 {
848 if (plugin_transmit_handle == NULL)
835 { 849 {
836 if (plugin_transmit_handle == NULL) 850 plugin_transmit_handle =
837 { 851 GNUNET_SERVER_notify_transmit_ready (client_handle, size,
838 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 852 GNUNET_TIME_UNIT_FOREVER_REL,
839 size, GNUNET_TIME_UNIT_FOREVER_REL, 853 &transmit_to_plugin, NULL);
840 &transmit_to_plugin, NULL);
841 }
842 } 854 }
855 }
843 else 856 else
844 { 857 {
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, client_handle not yet set (how?)!\n"); 858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
846 } 859 "Failed to queue message for plugin, client_handle not yet set (how?)!\n");
860 }
847} 861}
848 862
849/* Declare here so retry_core_send is aware of it */ 863/* Declare here so retry_core_send is aware of it */
850size_t core_transmit_notify (void *cls, 864size_t core_transmit_notify (void *cls, size_t size, void *buf);
851 size_t size, void *buf);
852 865
853/** 866/**
854 * Try to send another message from our core sending list 867 * Try to send another message from our core sending list
855 */ 868 */
856static void 869static void
857try_core_send (void *cls, 870try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
858 const struct GNUNET_SCHEDULER_TaskContext *tc)
859{ 871{
860 struct PendingMessage *pending; 872 struct PendingMessage *pending;
873
861 pending = core_pending_head; 874 pending = core_pending_head;
862 875
863 if (core_transmit_handle != NULL) 876 if (core_transmit_handle != NULL)
864 return; /* Message send already in progress */ 877 return; /* Message send already in progress */
865 878
866 if ((pending != NULL) && (coreAPI != NULL)) 879 if ((pending != NULL) && (coreAPI != NULL))
867 core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI, 880 core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI,
868 GNUNET_YES, 881 GNUNET_YES,
869 pending->importance, 882 pending->importance,
870 pending->timeout, 883 pending->timeout,
871 &pending->recipient, 884 &pending->recipient,
872 pending->msg_size, 885 pending->msg_size,
873 &core_transmit_notify, NULL); 886 &core_transmit_notify,
887 NULL);
874} 888}
875 889
876 890
@@ -885,8 +899,8 @@ try_core_send (void *cls,
885 * @param buf where the callee should write the message 899 * @param buf where the callee should write the message
886 * @return number of bytes written to buf 900 * @return number of bytes written to buf
887 */ 901 */
888size_t core_transmit_notify (void *cls, 902size_t
889 size_t size, void *buf) 903core_transmit_notify (void *cls, size_t size, void *buf)
890{ 904{
891 char *cbuf = buf; 905 char *cbuf = buf;
892 struct PendingMessage *pending; 906 struct PendingMessage *pending;
@@ -895,58 +909,65 @@ size_t core_transmit_notify (void *cls,
895 size_t msize; 909 size_t msize;
896 910
897 if (buf == NULL) 911 if (buf == NULL)
898 { 912 {
899 /* client disconnected */ 913 /* client disconnected */
900#if DEBUG_DV 914#if DEBUG_DV
901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT"); 915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
902#endif 916#endif
903 return 0; 917 return 0;
904 } 918 }
905 919
906 core_transmit_handle = NULL; 920 core_transmit_handle = NULL;
907 off = 0; 921 off = 0;
908 pending = core_pending_head; 922 pending = core_pending_head;
909 if ( (pending != NULL) && 923 if ((pending != NULL) && (size >= (msize = ntohs (pending->msg->size))))
910 (size >= (msize = ntohs (pending->msg->size)))) 924 {
911 {
912#if DEBUG_DV 925#if DEBUG_DV
913 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s' : transmit_notify (core) called with size %d\n", "dv service", msize); 926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
927 "`%s' : transmit_notify (core) called with size %d\n",
928 "dv service", msize);
914#endif 929#endif
915 GNUNET_CONTAINER_DLL_remove (core_pending_head, 930 GNUNET_CONTAINER_DLL_remove (core_pending_head, core_pending_tail, pending);
916 core_pending_tail, 931 if (pending->send_result != NULL) /* Will only be non-null if a real client asked for this send */
917 pending); 932 {
918 if (pending->send_result != NULL) /* Will only be non-null if a real client asked for this send */ 933 client_reply =
934 GNUNET_malloc (sizeof (struct PendingMessage) +
935 sizeof (struct GNUNET_DV_SendResultMessage));
936 client_reply->msg = (struct GNUNET_MessageHeader *) &client_reply[1];
937 memcpy (&client_reply[1], pending->send_result,
938 sizeof (struct GNUNET_DV_SendResultMessage));
939 GNUNET_free (pending->send_result);
940
941 GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head,
942 plugin_pending_tail,
943 plugin_pending_tail, client_reply);
944 if (client_handle != NULL)
945 {
946 if (plugin_transmit_handle == NULL)
947 {
948 plugin_transmit_handle =
949 GNUNET_SERVER_notify_transmit_ready (client_handle,
950 sizeof (struct
951 GNUNET_DV_SendResultMessage),
952 GNUNET_TIME_UNIT_FOREVER_REL,
953 &transmit_to_plugin, NULL);
954 }
955 else
919 { 956 {
920 client_reply = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage)); 957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
921 client_reply->msg = (struct GNUNET_MessageHeader *)&client_reply[1]; 958 "Failed to queue message for plugin, must be one in progress already!!\n");
922 memcpy(&client_reply[1], pending->send_result, sizeof(struct GNUNET_DV_SendResultMessage));
923 GNUNET_free(pending->send_result);
924
925 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, client_reply);
926 if (client_handle != NULL)
927 {
928 if (plugin_transmit_handle == NULL)
929 {
930 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
931 sizeof(struct GNUNET_DV_SendResultMessage),
932 GNUNET_TIME_UNIT_FOREVER_REL,
933 &transmit_to_plugin, NULL);
934 }
935 else
936 {
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
938 }
939 }
940 } 959 }
941 memcpy (&cbuf[off], pending->msg, msize); 960 }
942 GNUNET_free (pending);
943 off += msize;
944 } 961 }
945 /*reply = core_pending_head;*/ 962 memcpy (&cbuf[off], pending->msg, msize);
963 GNUNET_free (pending);
964 off += msize;
965 }
966 /*reply = core_pending_head; */
946 967
947 GNUNET_SCHEDULER_add_now(&try_core_send, NULL); 968 GNUNET_SCHEDULER_add_now (&try_core_send, NULL);
948 /*if (reply != NULL) 969 /*if (reply != NULL)
949 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL);*/ 970 * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL); */
950 971
951 return off; 972 return off;
952} 973}
@@ -971,6 +992,7 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
971 struct DistantNeighbor *source; 992 struct DistantNeighbor *source;
972 struct PendingMessage *pending_message; 993 struct PendingMessage *pending_message;
973 struct FindIDContext find_context; 994 struct FindIDContext find_context;
995
974#if DEBUG_DV 996#if DEBUG_DV
975 char shortname[5]; 997 char shortname[5];
976#endif 998#endif
@@ -980,70 +1002,76 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
980 find_context.dest = send_context->distant_peer; 1002 find_context.dest = send_context->distant_peer;
981 find_context.via = recipient; 1003 find_context.via = recipient;
982 find_context.tid = 0; 1004 find_context.tid = 0;
983 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, &send_context->distant_peer->hashPubKey, 1005 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
1006 &send_context->
1007 distant_peer->hashPubKey,
984 &find_specific_id, &find_context); 1008 &find_specific_id, &find_context);
985 1009
986 if (find_context.tid == 0) 1010 if (find_context.tid == 0)
987 { 1011 {
988 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: find_specific_id failed to find peer!\n", my_short_id); 1012 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
989 /* target unknown to us, drop! */ 1013 "%s: find_specific_id failed to find peer!\n", my_short_id);
990 return GNUNET_SYSERR; 1014 /* target unknown to us, drop! */
991 } 1015 return GNUNET_SYSERR;
1016 }
992 recipient_id = find_context.tid; 1017 recipient_id = find_context.tid;
993 1018
994 if (0 == (memcmp (&my_identity, 1019 if (0 == (memcmp (&my_identity, sender, sizeof (struct GNUNET_PeerIdentity))))
995 sender, sizeof (struct GNUNET_PeerIdentity))))
996 { 1020 {
997 sender_id = 0; 1021 sender_id = 0;
998 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1022 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
999 &sender->hashPubKey); 1023 &sender->hashPubKey);
1000 if (source != NULL) 1024 if (source != NULL)
1001 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: send_message_via found %s, myself in extended peer list???\n", my_short_id, GNUNET_i2s(&source->identity)); 1025 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1026 "%s: send_message_via found %s, myself in extended peer list???\n",
1027 my_short_id, GNUNET_i2s (&source->identity));
1002 } 1028 }
1003 else 1029 else
1004 { 1030 {
1005 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1031 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1006 &sender->hashPubKey); 1032 &sender->hashPubKey);
1007 if (source == NULL) 1033 if (source == NULL)
1008 { 1034 {
1009 /* sender unknown to us, drop! */ 1035 /* sender unknown to us, drop! */
1010 return GNUNET_SYSERR; 1036 return GNUNET_SYSERR;
1011 } 1037 }
1012 sender_id = source->our_id; 1038 sender_id = source->our_id;
1013 } 1039 }
1014 1040
1015 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size); 1041 pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
1016 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 1042 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
1017 pending_message->send_result = send_context->send_result; 1043 pending_message->send_result = send_context->send_result;
1018 memcpy(&pending_message->recipient, recipient, sizeof(struct GNUNET_PeerIdentity)); 1044 memcpy (&pending_message->recipient, recipient,
1045 sizeof (struct GNUNET_PeerIdentity));
1019 pending_message->msg_size = msg_size; 1046 pending_message->msg_size = msg_size;
1020 pending_message->importance = send_context->importance; 1047 pending_message->importance = send_context->importance;
1021 pending_message->timeout = send_context->timeout; 1048 pending_message->timeout = send_context->timeout;
1022 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg; 1049 toSend = (p2p_dv_MESSAGE_Data *) pending_message->msg;
1023 toSend->header.size = htons (msg_size); 1050 toSend->header.size = htons (msg_size);
1024 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA); 1051 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
1025 toSend->sender = htonl (sender_id); 1052 toSend->sender = htonl (sender_id);
1026 toSend->recipient = htonl (recipient_id); 1053 toSend->recipient = htonl (recipient_id);
1027#if DEBUG_DV_MESSAGES 1054#if DEBUG_DV_MESSAGES
1028 toSend->uid = send_context->uid; /* Still sent around in network byte order */ 1055 toSend->uid = send_context->uid; /* Still sent around in network byte order */
1029#else 1056#else
1030 toSend->uid = htonl(0); 1057 toSend->uid = htonl (0);
1031#endif 1058#endif
1032 1059
1033 memcpy (&toSend[1], send_context->message, send_context->message_size); 1060 memcpy (&toSend[1], send_context->message, send_context->message_size);
1034 1061
1035#if DEBUG_DV 1062#if DEBUG_DV
1036 memcpy(&shortname, GNUNET_i2s(send_context->distant_peer), 4); 1063 memcpy (&shortname, GNUNET_i2s (send_context->distant_peer), 4);
1037 shortname[4] = '\0'; 1064 shortname[4] = '\0';
1038 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send to destination `%s' via `%s' size %u\n", "DV", &shortname, GNUNET_i2s(recipient), msg_size); 1065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1066 "%s: Notifying core of send to destination `%s' via `%s' size %u\n",
1067 "DV", &shortname, GNUNET_i2s (recipient), msg_size);
1039#endif 1068#endif
1040 1069
1041 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1070 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1042 core_pending_tail, 1071 core_pending_tail,
1043 core_pending_tail, 1072 core_pending_tail, pending_message);
1044 pending_message);
1045 1073
1046 GNUNET_SCHEDULER_add_now(try_core_send, NULL); 1074 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
1047 1075
1048 return GNUNET_YES; 1076 return GNUNET_YES;
1049} 1077}
@@ -1059,17 +1087,15 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
1059 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 1087 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
1060 */ 1088 */
1061static int 1089static int
1062find_least_cost_peer (void *cls, 1090find_least_cost_peer (void *cls, const GNUNET_HashCode * key, void *value)
1063 const GNUNET_HashCode *key,
1064 void *value)
1065{ 1091{
1066 struct FindLeastCostContext *find_context = cls; 1092 struct FindLeastCostContext *find_context = cls;
1067 struct DistantNeighbor *dn = value; 1093 struct DistantNeighbor *dn = value;
1068 1094
1069 if (dn->cost < find_context->least_cost) 1095 if (dn->cost < find_context->least_cost)
1070 { 1096 {
1071 find_context->target = dn; 1097 find_context->target = dn;
1072 } 1098 }
1073 if (dn->cost == DIRECT_NEIGHBOR_COST) 1099 if (dn->cost == DIRECT_NEIGHBOR_COST)
1074 return GNUNET_NO; 1100 return GNUNET_NO;
1075 return GNUNET_YES; 1101 return GNUNET_YES;
@@ -1088,14 +1114,13 @@ find_least_cost_peer (void *cls,
1088 * @param timeout how long to possibly delay sending this message 1114 * @param timeout how long to possibly delay sending this message
1089 */ 1115 */
1090static int 1116static int
1091send_message (const struct GNUNET_PeerIdentity * recipient, 1117send_message (const struct GNUNET_PeerIdentity *recipient,
1092 const struct GNUNET_PeerIdentity * sender, 1118 const struct GNUNET_PeerIdentity *sender,
1093 const struct DistantNeighbor * specific_neighbor, 1119 const struct DistantNeighbor *specific_neighbor,
1094 const struct GNUNET_MessageHeader * message, 1120 const struct GNUNET_MessageHeader *message,
1095 size_t message_size, 1121 size_t message_size,
1096 unsigned int importance, 1122 unsigned int importance,
1097 unsigned int uid, 1123 unsigned int uid, struct GNUNET_TIME_Relative timeout)
1098 struct GNUNET_TIME_Relative timeout)
1099{ 1124{
1100 p2p_dv_MESSAGE_Data *toSend; 1125 p2p_dv_MESSAGE_Data *toSend;
1101 unsigned int msg_size; 1126 unsigned int msg_size;
@@ -1106,6 +1131,7 @@ send_message (const struct GNUNET_PeerIdentity * recipient,
1106 struct DistantNeighbor *source; 1131 struct DistantNeighbor *source;
1107 struct PendingMessage *pending_message; 1132 struct PendingMessage *pending_message;
1108 struct FindLeastCostContext find_least_ctx; 1133 struct FindLeastCostContext find_least_ctx;
1134
1109#if DEBUG_DV_PEER_NUMBERS 1135#if DEBUG_DV_PEER_NUMBERS
1110 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerFrom; 1136 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerFrom;
1111 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerTo; 1137 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerTo;
@@ -1122,84 +1148,97 @@ send_message (const struct GNUNET_PeerIdentity * recipient,
1122 * over all known peers, just those that apply. 1148 * over all known peers, just those that apply.
1123 */ 1149 */
1124 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, 1150 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
1125 &recipient->hashPubKey, &find_least_cost_peer, &find_least_ctx); 1151 &recipient->hashPubKey,
1152 &find_least_cost_peer,
1153 &find_least_ctx);
1126 target = find_least_ctx.target; 1154 target = find_least_ctx.target;
1127 1155
1128 if (target == NULL) 1156 if (target == NULL)
1129 { 1157 {
1130 /* target unknown to us, drop! */ 1158 /* target unknown to us, drop! */
1131 return GNUNET_SYSERR; 1159 return GNUNET_SYSERR;
1132 } 1160 }
1133 recipient_id = target->referrer_id; 1161 recipient_id = target->referrer_id;
1134 1162
1135 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1163 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1136 &sender->hashPubKey); 1164 &sender->hashPubKey);
1137 if (source == NULL) 1165 if (source == NULL)
1166 {
1167 if (0 != (memcmp (&my_identity,
1168 sender, sizeof (struct GNUNET_PeerIdentity))))
1138 { 1169 {
1139 if (0 != (memcmp (&my_identity, 1170 /* sender unknown to us, drop! */
1140 sender, sizeof (struct GNUNET_PeerIdentity)))) 1171 return GNUNET_SYSERR;
1141 {
1142 /* sender unknown to us, drop! */
1143 return GNUNET_SYSERR;
1144 }
1145 sender_id = 0; /* 0 == us */
1146 } 1172 }
1173 sender_id = 0; /* 0 == us */
1174 }
1147 else 1175 else
1148 { 1176 {
1149 /* find out the number that we use when we gossip about 1177 /* find out the number that we use when we gossip about
1150 the sender */ 1178 * the sender */
1151 sender_id = source->our_id; 1179 sender_id = source->our_id;
1152 } 1180 }
1153 1181
1154#if DEBUG_DV_PEER_NUMBERS 1182#if DEBUG_DV_PEER_NUMBERS
1155 GNUNET_CRYPTO_hash_to_enc (&source->identity.hashPubKey, &encPeerFrom); 1183 GNUNET_CRYPTO_hash_to_enc (&source->identity.hashPubKey, &encPeerFrom);
1156 GNUNET_CRYPTO_hash_to_enc (&target->referrer->identity.hashPubKey, &encPeerVia); 1184 GNUNET_CRYPTO_hash_to_enc (&target->referrer->identity.hashPubKey,
1185 &encPeerVia);
1157 encPeerFrom.encoding[4] = '\0'; 1186 encPeerFrom.encoding[4] = '\0';
1158 encPeerVia.encoding[4] = '\0'; 1187 encPeerVia.encoding[4] = '\0';
1159#endif 1188#endif
1160 if ((sender_id != 0) && (0 == memcmp(&source->identity, &target->referrer->identity, sizeof(struct GNUNET_PeerIdentity)))) 1189 if ((sender_id != 0) &&
1161 { 1190 (0 ==
1162 return 0; 1191 memcmp (&source->identity, &target->referrer->identity,
1163 } 1192 sizeof (struct GNUNET_PeerIdentity))))
1193 {
1194 return 0;
1195 }
1164 1196
1165 cost = target->cost; 1197 cost = target->cost;
1166 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size); 1198 pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
1167 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 1199 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
1168 pending_message->send_result = NULL; 1200 pending_message->send_result = NULL;
1169 pending_message->importance = importance; 1201 pending_message->importance = importance;
1170 pending_message->timeout = timeout; 1202 pending_message->timeout = timeout;
1171 memcpy(&pending_message->recipient, &target->referrer->identity, sizeof(struct GNUNET_PeerIdentity)); 1203 memcpy (&pending_message->recipient, &target->referrer->identity,
1204 sizeof (struct GNUNET_PeerIdentity));
1172 pending_message->msg_size = msg_size; 1205 pending_message->msg_size = msg_size;
1173 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg; 1206 toSend = (p2p_dv_MESSAGE_Data *) pending_message->msg;
1174 toSend->header.size = htons (msg_size); 1207 toSend->header.size = htons (msg_size);
1175 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA); 1208 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
1176 toSend->sender = htonl (sender_id); 1209 toSend->sender = htonl (sender_id);
1177 toSend->recipient = htonl (recipient_id); 1210 toSend->recipient = htonl (recipient_id);
1178#if DEBUG_DV_MESSAGES 1211#if DEBUG_DV_MESSAGES
1179 toSend->uid = htonl(uid); 1212 toSend->uid = htonl (uid);
1180#else 1213#else
1181 toSend->uid = htonl(0); 1214 toSend->uid = htonl (0);
1182#endif 1215#endif
1183 1216
1184#if DEBUG_DV_PEER_NUMBERS 1217#if DEBUG_DV_PEER_NUMBERS
1185 GNUNET_CRYPTO_hash_to_enc (&target->identity.hashPubKey, &encPeerTo); 1218 GNUNET_CRYPTO_hash_to_enc (&target->identity.hashPubKey, &encPeerTo);
1186 encPeerTo.encoding[4] = '\0'; 1219 encPeerTo.encoding[4] = '\0';
1187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Sending DATA message. Sender id %u, source %s, destination %s, via %s\n", GNUNET_i2s(&my_identity), sender_id, &encPeerFrom, &encPeerTo, &encPeerVia); 1220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1221 "%s: Sending DATA message. Sender id %u, source %s, destination %s, via %s\n",
1222 GNUNET_i2s (&my_identity), sender_id, &encPeerFrom, &encPeerTo,
1223 &encPeerVia);
1188#endif 1224#endif
1189 memcpy (&toSend[1], message, message_size); 1225 memcpy (&toSend[1], message, message_size);
1190 if ((source != NULL) && (source->pkey == NULL)) /* Test our hypothesis about message failures! */ 1226 if ((source != NULL) && (source->pkey == NULL)) /* Test our hypothesis about message failures! */
1191 { 1227 {
1192 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n", my_short_id); 1228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1193 } 1229 "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n",
1230 my_short_id);
1231 }
1194 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1232 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1195 core_pending_tail, 1233 core_pending_tail,
1196 core_pending_tail, 1234 core_pending_tail, pending_message);
1197 pending_message);
1198#if DEBUG_DV 1235#if DEBUG_DV
1199 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send size %d to destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient)); 1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1237 "%s: Notifying core of send size %d to destination `%s'\n",
1238 "DV SEND MESSAGE", msg_size, GNUNET_i2s (recipient));
1200#endif 1239#endif
1201 1240
1202 GNUNET_SCHEDULER_add_now(try_core_send, NULL); 1241 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
1203 return (int) cost; 1242 return (int) cost;
1204} 1243}
1205 1244
@@ -1227,14 +1266,13 @@ struct CheckPeerContext
1227 * iterate, 1266 * iterate,
1228 * GNUNET_NO if not. 1267 * GNUNET_NO if not.
1229 */ 1268 */
1230int checkPeerID (void *cls, 1269int
1231 const GNUNET_HashCode * key, 1270checkPeerID (void *cls, const GNUNET_HashCode * key, void *value)
1232 void *value)
1233{ 1271{
1234 struct CheckPeerContext *ctx = cls; 1272 struct CheckPeerContext *ctx = cls;
1235 struct DistantNeighbor *distant = value; 1273 struct DistantNeighbor *distant = value;
1236 1274
1237 if (memcmp(key, &ctx->sender_id, sizeof(unsigned int)) == 0) 1275 if (memcmp (key, &ctx->sender_id, sizeof (unsigned int)) == 0)
1238 { 1276 {
1239 ctx->peer = distant; 1277 ctx->peer = distant;
1240 return GNUNET_NO; 1278 return GNUNET_NO;
@@ -1253,22 +1291,30 @@ int checkPeerID (void *cls,
1253 * @param client the TokenizedMessageContext which contains message information 1291 * @param client the TokenizedMessageContext which contains message information
1254 * @param message the actual message 1292 * @param message the actual message
1255 */ 1293 */
1256void tokenized_message_handler (void *cls, 1294void
1257 void *client, 1295tokenized_message_handler (void *cls,
1258 const struct GNUNET_MessageHeader *message) 1296 void *client,
1297 const struct GNUNET_MessageHeader *message)
1259{ 1298{
1260 struct TokenizedMessageContext *ctx = client; 1299 struct TokenizedMessageContext *ctx = client;
1300
1261 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP); 1301 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1262 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA); 1302 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA);
1263 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) && 1303 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
1264 (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) ) 1304 (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA))
1265 { 1305 {
1266#if DEBUG_DV_MESSAGES 1306#if DEBUG_DV_MESSAGES
1267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1268 "%s: Receives %s message for me, uid %u, size %d, type %d cost %u from %s!\n", my_short_id, "DV DATA", ctx->uid, ntohs(message->size), ntohs(message->type), ctx->distant->cost, GNUNET_i2s(&ctx->distant->identity)); 1308 "%s: Receives %s message for me, uid %u, size %d, type %d cost %u from %s!\n",
1269#endif 1309 my_short_id, "DV DATA", ctx->uid, ntohs (message->size),
1270 GNUNET_assert(memcmp(ctx->peer, &ctx->distant->identity, sizeof(struct GNUNET_PeerIdentity)) != 0); 1310 ntohs (message->type), ctx->distant->cost,
1271 send_to_plugin(ctx->peer, message, ntohs(message->size), &ctx->distant->identity, ctx->distant->cost); 1311 GNUNET_i2s (&ctx->distant->identity));
1312#endif
1313 GNUNET_assert (memcmp
1314 (ctx->peer, &ctx->distant->identity,
1315 sizeof (struct GNUNET_PeerIdentity)) != 0);
1316 send_to_plugin (ctx->peer, message, ntohs (message->size),
1317 &ctx->distant->identity, ctx->distant->cost);
1272 } 1318 }
1273} 1319}
1274 1320
@@ -1282,23 +1328,23 @@ struct DelayedMessageContext
1282 uint32_t uid; 1328 uint32_t uid;
1283}; 1329};
1284 1330
1285void send_message_delayed (void *cls, 1331void
1286 const struct GNUNET_SCHEDULER_TaskContext *tc) 1332send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1287{ 1333{
1288 struct DelayedMessageContext *msg_ctx = cls; 1334 struct DelayedMessageContext *msg_ctx = cls;
1335
1289 if (msg_ctx != NULL) 1336 if (msg_ctx != NULL)
1290 { 1337 {
1291 send_message(&msg_ctx->dest, 1338 send_message (&msg_ctx->dest,
1292 &msg_ctx->sender, 1339 &msg_ctx->sender,
1293 NULL, 1340 NULL,
1294 msg_ctx->message, 1341 msg_ctx->message,
1295 msg_ctx->message_size, 1342 msg_ctx->message_size,
1296 default_dv_priority, 1343 default_dv_priority,
1297 msg_ctx->uid, 1344 msg_ctx->uid, GNUNET_TIME_relative_get_forever ());
1298 GNUNET_TIME_relative_get_forever()); 1345 GNUNET_free (msg_ctx->message);
1299 GNUNET_free(msg_ctx->message); 1346 GNUNET_free (msg_ctx);
1300 GNUNET_free(msg_ctx); 1347 }
1301 }
1302} 1348}
1303#endif 1349#endif
1304 1350
@@ -1311,15 +1357,15 @@ void send_message_delayed (void *cls,
1311static uint32_t 1357static uint32_t
1312get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1358get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1313{ 1359{
1314 while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && 1360 while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
1315 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) ) 1361 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE))
1316 atsi++; 1362 atsi++;
1317 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) 1363 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
1318 { 1364 {
1319 GNUNET_break (0); 1365 GNUNET_break (0);
1320 /* FIXME: we do not have distance data? Assume direct neighbor. */ 1366 /* FIXME: we do not have distance data? Assume direct neighbor. */
1321 return DIRECT_NEIGHBOR_COST; 1367 return DIRECT_NEIGHBOR_COST;
1322 } 1368 }
1323 return ntohl (atsi->value); 1369 return ntohl (atsi->value);
1324} 1370}
1325 1371
@@ -1332,17 +1378,18 @@ get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1332static struct GNUNET_TIME_Relative 1378static struct GNUNET_TIME_Relative
1333get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1379get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1334{ 1380{
1335 while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && 1381 while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
1336 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) ) 1382 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY))
1337 atsi++; 1383 atsi++;
1338 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) 1384 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
1339 { 1385 {
1340 GNUNET_break (0); 1386 GNUNET_break (0);
1341 /* how can we not have latency data? */ 1387 /* how can we not have latency data? */
1342 return GNUNET_TIME_UNIT_SECONDS; 1388 return GNUNET_TIME_UNIT_SECONDS;
1343 } 1389 }
1344 /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */ 1390 /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */
1345 return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, ntohl (atsi->value)); 1391 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1392 ntohl (atsi->value));
1346} 1393}
1347 1394
1348/** 1395/**
@@ -1356,11 +1403,11 @@ get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1356 * @param message the message 1403 * @param message the message
1357 * @param atsi transport ATS information (latency, distance, etc.) 1404 * @param atsi transport ATS information (latency, distance, etc.)
1358 */ 1405 */
1359static int 1406static int
1360handle_dv_data_message (void *cls, 1407handle_dv_data_message (void *cls,
1361 const struct GNUNET_PeerIdentity * peer, 1408 const struct GNUNET_PeerIdentity *peer,
1362 const struct GNUNET_MessageHeader * message, 1409 const struct GNUNET_MessageHeader *message,
1363 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1410 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1364{ 1411{
1365 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message; 1412 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
1366 const struct GNUNET_MessageHeader *packed_message; 1413 const struct GNUNET_MessageHeader *packed_message;
@@ -1374,6 +1421,7 @@ handle_dv_data_message (void *cls,
1374 struct TokenizedMessageContext tkm_ctx; 1421 struct TokenizedMessageContext tkm_ctx;
1375 int i; 1422 int i;
1376 int found_pos; 1423 int found_pos;
1424
1377#if DELAY_FORWARDS 1425#if DELAY_FORWARDS
1378 struct DelayedMessageContext *delayed_context; 1426 struct DelayedMessageContext *delayed_context;
1379#endif 1427#endif
@@ -1386,29 +1434,35 @@ handle_dv_data_message (void *cls,
1386 int ret; 1434 int ret;
1387 size_t packed_message_size; 1435 size_t packed_message_size;
1388 char *cbuf; 1436 char *cbuf;
1389 uint32_t distance; /* Distance information */ 1437 uint32_t distance; /* Distance information */
1390 struct GNUNET_TIME_Relative latency; /* Latency information */ 1438 struct GNUNET_TIME_Relative latency; /* Latency information */
1391 1439
1392 packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data); 1440 packed_message_size =
1441 ntohs (incoming->header.size) - sizeof (p2p_dv_MESSAGE_Data);
1393#if DEBUG_DV 1442#if DEBUG_DV
1394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1395 "%s: Receives DATA message from %s size %d, packed size %d!\n", my_short_id, GNUNET_i2s(peer) , ntohs(incoming->header.size), packed_message_size); 1444 "%s: Receives DATA message from %s size %d, packed size %d!\n",
1445 my_short_id, GNUNET_i2s (peer), ntohs (incoming->header.size),
1446 packed_message_size);
1396#endif 1447#endif
1397 1448
1398 if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader)) 1449 if (ntohs (incoming->header.size) <
1399 { 1450 sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader))
1451 {
1400#if DEBUG_DV 1452#if DEBUG_DV
1401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1402 "`%s': Message sizes don't add up, total size %u, expected at least %u!\n", "dv service", ntohs(incoming->header.size), sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader)); 1454 "`%s': Message sizes don't add up, total size %u, expected at least %u!\n",
1455 "dv service", ntohs (incoming->header.size),
1456 sizeof (p2p_dv_MESSAGE_Data) +
1457 sizeof (struct GNUNET_MessageHeader));
1403#endif 1458#endif
1404 return GNUNET_SYSERR; 1459 return GNUNET_SYSERR;
1405 } 1460 }
1406 1461
1407 /* Iterate over ATS_Information to get distance and latency */ 1462 /* Iterate over ATS_Information to get distance and latency */
1408 latency = get_atsi_latency(atsi); 1463 latency = get_atsi_latency (atsi);
1409 distance = get_atsi_distance(atsi); 1464 distance = get_atsi_distance (atsi);
1410 dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, 1465 dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
1411 &peer->hashPubKey);
1412 if (dn == NULL) 1466 if (dn == NULL)
1413 return GNUNET_OK; 1467 return GNUNET_OK;
1414 1468
@@ -1418,7 +1472,8 @@ handle_dv_data_message (void *cls,
1418 { 1472 {
1419 checkPeerCtx.sender_id = sid; 1473 checkPeerCtx.sender_id = sid;
1420 checkPeerCtx.peer = NULL; 1474 checkPeerCtx.peer = NULL;
1421 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &checkPeerID, &checkPeerCtx); 1475 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &checkPeerID,
1476 &checkPeerCtx);
1422 pos = checkPeerCtx.peer; 1477 pos = checkPeerCtx.peer;
1423 } 1478 }
1424 else 1479 else
@@ -1433,154 +1488,177 @@ handle_dv_data_message (void *cls,
1433#endif 1488#endif
1434 1489
1435 if (pos == NULL) 1490 if (pos == NULL)
1436 { 1491 {
1437#if DEBUG_DV_MESSAGES 1492#if DEBUG_DV_MESSAGES
1438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1439 "%s: unknown sender (%u), Message uid %u from %s!\n", my_short_id, ntohl(incoming->sender), ntohl(incoming->uid), GNUNET_i2s(&dn->identity)); 1494 "%s: unknown sender (%u), Message uid %u from %s!\n",
1440 pos = dn->referee_head; 1495 my_short_id, ntohl (incoming->sender), ntohl (incoming->uid),
1441 while ((NULL != pos) && (pos->referrer_id != sid)) 1496 GNUNET_i2s (&dn->identity));
1442 { 1497 pos = dn->referee_head;
1443 sender_id = strdup(GNUNET_i2s(&pos->identity)); 1498 while ((NULL != pos) && (pos->referrer_id != sid))
1444 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I know sender %u %s\n", pos->referrer_id, sender_id); 1499 {
1445 GNUNET_free(sender_id); 1500 sender_id = strdup (GNUNET_i2s (&pos->identity));
1446 pos = pos->next; 1501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I know sender %u %s\n",
1447 } 1502 pos->referrer_id, sender_id);
1503 GNUNET_free (sender_id);
1504 pos = pos->next;
1505 }
1448#endif 1506#endif
1449 1507
1450 found_pos = -1; 1508 found_pos = -1;
1451 for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++) 1509 for (i = 0; i < MAX_OUTSTANDING_MESSAGES; i++)
1452 { 1510 {
1453 if (dn->pending_messages[i].sender_id == 0) 1511 if (dn->pending_messages[i].sender_id == 0)
1454 { 1512 {
1455 found_pos = i; 1513 found_pos = i;
1456 break; 1514 break;
1457 } 1515 }
1458 } 1516 }
1459 1517
1460 if (found_pos == -1) 1518 if (found_pos == -1)
1461 { 1519 {
1462 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1520 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1463 "%s: Too many unknown senders (%u), ignoring message! Message uid %llu from %s!\n", my_short_id, ntohl(incoming->sender), ntohl(incoming->uid), GNUNET_i2s(&dn->identity)); 1521 "%s: Too many unknown senders (%u), ignoring message! Message uid %llu from %s!\n",
1464 } 1522 my_short_id, ntohl (incoming->sender), ntohl (incoming->uid),
1465 else 1523 GNUNET_i2s (&dn->identity));
1466 {
1467 dn->pending_messages[found_pos].message = GNUNET_malloc(ntohs (message->size));
1468 memcpy(dn->pending_messages[found_pos].message, message, ntohs(message->size));
1469 dn->pending_messages[found_pos].distance = distance;
1470 dn->pending_messages[found_pos].latency = latency;
1471 memcpy(&dn->pending_messages[found_pos].sender, peer, sizeof(struct GNUNET_PeerIdentity));
1472 dn->pending_messages[found_pos].sender_id = sid;
1473 }
1474 /* unknown sender */
1475 return GNUNET_OK;
1476 } 1524 }
1525 else
1526 {
1527 dn->pending_messages[found_pos].message =
1528 GNUNET_malloc (ntohs (message->size));
1529 memcpy (dn->pending_messages[found_pos].message, message,
1530 ntohs (message->size));
1531 dn->pending_messages[found_pos].distance = distance;
1532 dn->pending_messages[found_pos].latency = latency;
1533 memcpy (&dn->pending_messages[found_pos].sender, peer,
1534 sizeof (struct GNUNET_PeerIdentity));
1535 dn->pending_messages[found_pos].sender_id = sid;
1536 }
1537 /* unknown sender */
1538 return GNUNET_OK;
1539 }
1477 original_sender = &pos->identity; 1540 original_sender = &pos->identity;
1478 tid = ntohl (incoming->recipient); 1541 tid = ntohl (incoming->recipient);
1479 if (tid == 0) 1542 if (tid == 0)
1543 {
1544 /* 0 == us */
1545 cbuf = (char *) &incoming[1];
1546
1547 tkm_ctx.peer = peer;
1548 tkm_ctx.distant = pos;
1549 tkm_ctx.uid = ntohl (incoming->uid);
1550 if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST,
1551 &tkm_ctx,
1552 cbuf,
1553 packed_message_size,
1554 GNUNET_NO, GNUNET_NO))
1480 { 1555 {
1481 /* 0 == us */ 1556 GNUNET_break_op (0);
1482 cbuf = (char *)&incoming[1]; 1557 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1483 1558 "%s: %s Received corrupt data, discarding!", my_short_id,
1484 tkm_ctx.peer = peer; 1559 "DV SERVICE");
1485 tkm_ctx.distant = pos;
1486 tkm_ctx.uid = ntohl(incoming->uid);
1487 if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST,
1488 &tkm_ctx,
1489 cbuf,
1490 packed_message_size,
1491 GNUNET_NO,
1492 GNUNET_NO))
1493 {
1494 GNUNET_break_op(0);
1495 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: %s Received corrupt data, discarding!", my_short_id, "DV SERVICE");
1496 }
1497 return GNUNET_OK;
1498 } 1560 }
1561 return GNUNET_OK;
1562 }
1499 else 1563 else
1500 { 1564 {
1501 packed_message = (struct GNUNET_MessageHeader *)&incoming[1]; 1565 packed_message = (struct GNUNET_MessageHeader *) &incoming[1];
1502 } 1566 }
1503 1567
1504 /* FIXME: this is the *only* per-request operation we have in DV 1568 /* FIXME: this is the *only* per-request operation we have in DV
1505 that is O(n) in relation to the number of connected peers; a 1569 * that is O(n) in relation to the number of connected peers; a
1506 hash-table lookup could easily solve this (minor performance 1570 * hash-table lookup could easily solve this (minor performance
1507 issue) */ 1571 * issue) */
1508 fdc.tid = tid; 1572 fdc.tid = tid;
1509 fdc.dest = NULL; 1573 fdc.dest = NULL;
1510 GNUNET_CONTAINER_heap_iterate (neighbor_max_heap, 1574 GNUNET_CONTAINER_heap_iterate (neighbor_max_heap, &find_destination, &fdc);
1511 &find_destination, &fdc);
1512 1575
1513#if DEBUG_DV 1576#if DEBUG_DV
1514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1515 "%s: Receives %s message for someone else!\n", "dv", "DV DATA"); 1578 "%s: Receives %s message for someone else!\n", "dv", "DV DATA");
1516#endif 1579#endif
1517 1580
1518 if (fdc.dest == NULL) 1581 if (fdc.dest == NULL)
1519 { 1582 {
1520#if DEBUG_DV_MESSAGES 1583#if DEBUG_DV_MESSAGES
1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1522 "%s: Receives %s message uid %u for someone we don't know (id %u)!\n", my_short_id, "DV DATA", ntohl(incoming->uid), tid); 1585 "%s: Receives %s message uid %u for someone we don't know (id %u)!\n",
1586 my_short_id, "DV DATA", ntohl (incoming->uid), tid);
1523#endif 1587#endif
1524 return GNUNET_OK; 1588 return GNUNET_OK;
1525 } 1589 }
1526 destination = &fdc.dest->identity; 1590 destination = &fdc.dest->identity;
1527 1591
1528 if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity))) 1592 if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity)))
1529 { 1593 {
1530 /* FIXME: create stat: routing loop-discard! */ 1594 /* FIXME: create stat: routing loop-discard! */
1531 1595
1532#if DEBUG_DV_MESSAGES 1596#if DEBUG_DV_MESSAGES
1533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1534 "%s: DROPPING MESSAGE uid %u type %d, routing loop! Message immediately from %s!\n", my_short_id, ntohl(incoming->uid), ntohs(packed_message->type), GNUNET_i2s(&dn->identity)); 1598 "%s: DROPPING MESSAGE uid %u type %d, routing loop! Message immediately from %s!\n",
1599 my_short_id, ntohl (incoming->uid),
1600 ntohs (packed_message->type), GNUNET_i2s (&dn->identity));
1535#endif 1601#endif
1536 return GNUNET_OK; 1602 return GNUNET_OK;
1537 } 1603 }
1538 1604
1539 /* At this point we have a message, and we need to forward it on to the 1605 /* At this point we have a message, and we need to forward it on to the
1540 * next DV hop. 1606 * next DV hop.
1541 */ 1607 */
1542#if DEBUG_DV_MESSAGES 1608#if DEBUG_DV_MESSAGES
1543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1544 "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost %u!\n", my_short_id, "DV DATA", GNUNET_i2s(destination), ntohl(incoming->uid), ntohs(packed_message->size), ntohs(packed_message->type), pos->cost); 1610 "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost %u!\n",
1611 my_short_id, "DV DATA", GNUNET_i2s (destination),
1612 ntohl (incoming->uid), ntohs (packed_message->size),
1613 ntohs (packed_message->type), pos->cost);
1545#endif 1614#endif
1546 1615
1547#if DELAY_FORWARDS 1616#if DELAY_FORWARDS
1548 if (GNUNET_TIME_absolute_get_duration(pos->last_gossip).abs_value < GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2).abs_value) 1617 if (GNUNET_TIME_absolute_get_duration (pos->last_gossip).abs_value <
1549 { 1618 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2).abs_value)
1550 delayed_context = GNUNET_malloc(sizeof(struct DelayedMessageContext)); 1619 {
1551 memcpy(&delayed_context->dest, destination, sizeof(struct GNUNET_PeerIdentity)); 1620 delayed_context = GNUNET_malloc (sizeof (struct DelayedMessageContext));
1552 memcpy(&delayed_context->sender, original_sender, sizeof(struct GNUNET_PeerIdentity)); 1621 memcpy (&delayed_context->dest, destination,
1553 delayed_context->message = GNUNET_malloc(packed_message_size); 1622 sizeof (struct GNUNET_PeerIdentity));
1554 memcpy(delayed_context->message, packed_message, packed_message_size); 1623 memcpy (&delayed_context->sender, original_sender,
1555 delayed_context->message_size = packed_message_size; 1624 sizeof (struct GNUNET_PeerIdentity));
1556 delayed_context->uid = ntohl(incoming->uid); 1625 delayed_context->message = GNUNET_malloc (packed_message_size);
1557 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 2500), &send_message_delayed, delayed_context); 1626 memcpy (delayed_context->message, packed_message, packed_message_size);
1558 return GNUNET_OK; 1627 delayed_context->message_size = packed_message_size;
1559 } 1628 delayed_context->uid = ntohl (incoming->uid);
1629 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1630 (GNUNET_TIME_UNIT_MILLISECONDS, 2500),
1631 &send_message_delayed, delayed_context);
1632 return GNUNET_OK;
1633 }
1560 else 1634 else
1561#endif 1635#endif
1562 { 1636 {
1563 ret = send_message(destination, 1637 ret = send_message (destination,
1564 original_sender, 1638 original_sender,
1565 NULL, 1639 NULL,
1566 packed_message, 1640 packed_message,
1567 packed_message_size, 1641 packed_message_size,
1568 default_dv_priority, 1642 default_dv_priority,
1569 ntohl(incoming->uid), 1643 ntohl (incoming->uid),
1570 GNUNET_TIME_relative_get_forever()); 1644 GNUNET_TIME_relative_get_forever ());
1571 } 1645 }
1572 if (ret != GNUNET_SYSERR) 1646 if (ret != GNUNET_SYSERR)
1573 return GNUNET_OK; 1647 return GNUNET_OK;
1574 else 1648 else
1575 { 1649 {
1576#if DEBUG_MESSAGE_DROP 1650#if DEBUG_MESSAGE_DROP
1577 char *direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity)); 1651 char *direct_id = GNUNET_strdup (GNUNET_i2s (&dn->identity));
1578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1652
1579 "%s: DROPPING MESSAGE type %d, forwarding failed! Message immediately from %s!\n", GNUNET_i2s(&my_identity), ntohs(((struct GNUNET_MessageHeader *)&incoming[1])->type), direct_id); 1653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1580 GNUNET_free (direct_id); 1654 "%s: DROPPING MESSAGE type %d, forwarding failed! Message immediately from %s!\n",
1655 GNUNET_i2s (&my_identity),
1656 ntohs (((struct GNUNET_MessageHeader *) &incoming[1])->type),
1657 direct_id);
1658 GNUNET_free (direct_id);
1581#endif 1659#endif
1582 return GNUNET_SYSERR; 1660 return GNUNET_SYSERR;
1583 } 1661 }
1584} 1662}
1585 1663
1586#if DEBUG_DV 1664#if DEBUG_DV
@@ -1594,19 +1672,24 @@ handle_dv_data_message (void *cls,
1594 * iterate, 1672 * iterate,
1595 * GNUNET_NO if not. 1673 * GNUNET_NO if not.
1596 */ 1674 */
1597int print_neighbors (void *cls, 1675int
1598 const GNUNET_HashCode * key, 1676print_neighbors (void *cls, const GNUNET_HashCode * key, void *abs_value)
1599 void *abs_value)
1600{ 1677{
1601 struct DistantNeighbor *distant_neighbor = abs_value; 1678 struct DistantNeighbor *distant_neighbor = abs_value;
1602 char my_shortname[5]; 1679 char my_shortname[5];
1603 char referrer_shortname[5]; 1680 char referrer_shortname[5];
1604 memcpy(&my_shortname, GNUNET_i2s(&my_identity), 4); 1681
1682 memcpy (&my_shortname, GNUNET_i2s (&my_identity), 4);
1605 my_shortname[4] = '\0'; 1683 my_shortname[4] = '\0';
1606 memcpy(&referrer_shortname, GNUNET_i2s(&distant_neighbor->referrer->identity), 4); 1684 memcpy (&referrer_shortname,
1685 GNUNET_i2s (&distant_neighbor->referrer->identity), 4);
1607 referrer_shortname[4] = '\0'; 1686 referrer_shortname[4] = '\0';
1608 1687
1609 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`%s' %s: Peer `%s', distance %d, referrer `%s' pkey: %s\n", &my_shortname, "DV", GNUNET_i2s(&distant_neighbor->identity), distant_neighbor->cost, &referrer_shortname, distant_neighbor->pkey == NULL ? "no" : "yes"); 1688 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1689 "`%s' %s: Peer `%s', distance %d, referrer `%s' pkey: %s\n",
1690 &my_shortname, "DV", GNUNET_i2s (&distant_neighbor->identity),
1691 distant_neighbor->cost, &referrer_shortname,
1692 distant_neighbor->pkey == NULL ? "no" : "yes");
1610 return GNUNET_YES; 1693 return GNUNET_YES;
1611} 1694}
1612#endif 1695#endif
@@ -1616,13 +1699,13 @@ int print_neighbors (void *cls,
1616 * peers. Will run until called with reason shutdown. 1699 * peers. Will run until called with reason shutdown.
1617 */ 1700 */
1618static void 1701static void
1619neighbor_send_task (void *cls, 1702neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1620 const struct GNUNET_SCHEDULER_TaskContext *tc)
1621{ 1703{
1622 struct NeighborSendContext *send_context = cls; 1704 struct NeighborSendContext *send_context = cls;
1705
1623#if DEBUG_DV_GOSSIP_SEND 1706#if DEBUG_DV_GOSSIP_SEND
1624 char * encPeerAbout; 1707 char *encPeerAbout;
1625 char * encPeerTo; 1708 char *encPeerTo;
1626#endif 1709#endif
1627 struct DistantNeighbor *about; 1710 struct DistantNeighbor *about;
1628 struct DirectNeighbor *to; 1711 struct DirectNeighbor *to;
@@ -1631,41 +1714,41 @@ neighbor_send_task (void *cls,
1631 p2p_dv_MESSAGE_NeighborInfo *message; 1714 p2p_dv_MESSAGE_NeighborInfo *message;
1632 struct PendingMessage *pending_message; 1715 struct PendingMessage *pending_message;
1633 1716
1634 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 1717 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1635 { 1718 {
1636#if DEBUG_DV_GOSSIP 1719#if DEBUG_DV_GOSSIP
1637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1638 "%s: Called with reason shutdown, shutting down!\n", 1721 "%s: Called with reason shutdown, shutting down!\n",
1639 GNUNET_i2s(&my_identity)); 1722 GNUNET_i2s (&my_identity));
1640#endif 1723#endif
1641 return; 1724 return;
1642 } 1725 }
1643 1726
1644 if (send_context->fast_gossip_list_head != NULL) 1727 if (send_context->fast_gossip_list_head != NULL)
1645 { 1728 {
1646 about_list = send_context->fast_gossip_list_head; 1729 about_list = send_context->fast_gossip_list_head;
1647 about = about_list->about; 1730 about = about_list->about;
1648 GNUNET_CONTAINER_DLL_remove(send_context->fast_gossip_list_head, 1731 GNUNET_CONTAINER_DLL_remove (send_context->fast_gossip_list_head,
1649 send_context->fast_gossip_list_tail, 1732 send_context->fast_gossip_list_tail,
1650 about_list); 1733 about_list);
1651 GNUNET_free(about_list); 1734 GNUNET_free (about_list);
1652 } 1735 }
1653 else 1736 else
1654 { 1737 {
1655 /* FIXME: this may become a problem, because the heap walk has only one internal "walker". This means 1738 /* FIXME: this may become a problem, because the heap walk has only one internal "walker". This means
1656 * that if two neighbor_send_tasks are operating in lockstep (which is quite possible, given default 1739 * that if two neighbor_send_tasks are operating in lockstep (which is quite possible, given default
1657 * values for all connected peers) there may be a serious bias as to which peers get gossiped about! 1740 * values for all connected peers) there may be a serious bias as to which peers get gossiped about!
1658 * Probably the *best* way to fix would be to have an opaque pointer to the walk position passed as 1741 * Probably the *best* way to fix would be to have an opaque pointer to the walk position passed as
1659 * part of the walk_get_next call. Then the heap would have to keep a list of walks, or reset the walk 1742 * part of the walk_get_next call. Then the heap would have to keep a list of walks, or reset the walk
1660 * whenever a modification has been detected. Yuck either way. Perhaps we could iterate over the heap 1743 * whenever a modification has been detected. Yuck either way. Perhaps we could iterate over the heap
1661 * once to get a list of peers to gossip about and gossip them over time... But then if one goes away 1744 * once to get a list of peers to gossip about and gossip them over time... But then if one goes away
1662 * in the mean time that becomes nasty. For now we'll just assume that the walking is done 1745 * in the mean time that becomes nasty. For now we'll just assume that the walking is done
1663 * asynchronously enough to avoid major problems (-; 1746 * asynchronously enough to avoid major problems (-;
1664 * 1747 *
1665 * NOTE: probably fixed once we decided send rate based on allowed bandwidth. 1748 * NOTE: probably fixed once we decided send rate based on allowed bandwidth.
1666 */ 1749 */
1667 about = GNUNET_CONTAINER_heap_walk_get_next (neighbor_min_heap); 1750 about = GNUNET_CONTAINER_heap_walk_get_next (neighbor_min_heap);
1668 } 1751 }
1669 to = send_context->toNeighbor; 1752 to = send_context->toNeighbor;
1670 1753
1671 if ((about != NULL) && (to != about->referrer /* split horizon */ ) && 1754 if ((about != NULL) && (to != about->referrer /* split horizon */ ) &&
@@ -1674,61 +1757,69 @@ neighbor_send_task (void *cls,
1674#endif 1757#endif
1675 (to != NULL) && 1758 (to != NULL) &&
1676 (0 != memcmp (&about->identity, 1759 (0 != memcmp (&about->identity,
1677 &to->identity, sizeof (struct GNUNET_PeerIdentity))) && 1760 &to->identity, sizeof (struct GNUNET_PeerIdentity))) &&
1678 (about->pkey != NULL)) 1761 (about->pkey != NULL))
1679 { 1762 {
1680#if DEBUG_DV_GOSSIP_SEND 1763#if DEBUG_DV_GOSSIP_SEND
1681 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&about->identity)); 1764 encPeerAbout = GNUNET_strdup (GNUNET_i2s (&about->identity));
1682 encPeerTo = GNUNET_strdup(GNUNET_i2s(&to->identity)); 1765 encPeerTo = GNUNET_strdup (GNUNET_i2s (&to->identity));
1683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1684 "%s: Sending info about peer %s id %u to directly connected peer %s\n", 1767 "%s: Sending info about peer %s id %u to directly connected peer %s\n",
1685 GNUNET_i2s(&my_identity), 1768 GNUNET_i2s (&my_identity),
1686 encPeerAbout, about->our_id, encPeerTo); 1769 encPeerAbout, about->our_id, encPeerTo);
1687 GNUNET_free(encPeerAbout); 1770 GNUNET_free (encPeerAbout);
1688 GNUNET_free(encPeerTo); 1771 GNUNET_free (encPeerTo);
1689#endif 1772#endif
1690 about->last_gossip = GNUNET_TIME_absolute_get(); 1773 about->last_gossip = GNUNET_TIME_absolute_get ();
1691 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_NeighborInfo)); 1774 pending_message =
1692 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 1775 GNUNET_malloc (sizeof (struct PendingMessage) +
1693 pending_message->importance = default_dv_priority; 1776 sizeof (p2p_dv_MESSAGE_NeighborInfo));
1694 pending_message->timeout = GNUNET_TIME_relative_get_forever(); 1777 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
1695 memcpy(&pending_message->recipient, &to->identity, sizeof(struct GNUNET_PeerIdentity)); 1778 pending_message->importance = default_dv_priority;
1696 pending_message->msg_size = sizeof(p2p_dv_MESSAGE_NeighborInfo); 1779 pending_message->timeout = GNUNET_TIME_relative_get_forever ();
1697 message = (p2p_dv_MESSAGE_NeighborInfo *)pending_message->msg; 1780 memcpy (&pending_message->recipient, &to->identity,
1698 message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo)); 1781 sizeof (struct GNUNET_PeerIdentity));
1699 message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP); 1782 pending_message->msg_size = sizeof (p2p_dv_MESSAGE_NeighborInfo);
1700 message->cost = htonl (about->cost); 1783 message = (p2p_dv_MESSAGE_NeighborInfo *) pending_message->msg;
1701 message->neighbor_id = htonl (about->our_id); 1784 message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo));
1702 1785 message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1703 memcpy (&message->pkey, about->pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1786 message->cost = htonl (about->cost);
1704 memcpy (&message->neighbor, 1787 message->neighbor_id = htonl (about->our_id);
1705 &about->identity, sizeof (struct GNUNET_PeerIdentity)); 1788
1706 1789 memcpy (&message->pkey, about->pkey,
1707 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1790 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1708 core_pending_tail, 1791 memcpy (&message->neighbor, &about->identity,
1709 core_pending_tail, 1792 sizeof (struct GNUNET_PeerIdentity));
1710 pending_message); 1793
1711 1794 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1712 GNUNET_SCHEDULER_add_now(try_core_send, NULL); 1795 core_pending_tail,
1713 /*if (core_transmit_handle == NULL) 1796 core_pending_tail, pending_message);
1714 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);*/ 1797
1798 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
1799 /*if (core_transmit_handle == NULL)
1800 * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL); */
1715 1801
1716 } 1802 }
1717 1803
1718 if (send_context->fast_gossip_list_head != NULL) /* If there are other peers in the fast list, schedule right away */ 1804 if (send_context->fast_gossip_list_head != NULL) /* If there are other peers in the fast list, schedule right away */
1719 { 1805 {
1720#if DEBUG_DV_PEER_NUMBERS 1806#if DEBUG_DV_PEER_NUMBERS
1721 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: still in fast send mode\n"); 1807 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1808 "DV SERVICE: still in fast send mode\n");
1722#endif 1809#endif
1723 send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context); 1810 send_context->task =
1724 } 1811 GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
1812 }
1725 else 1813 else
1726 { 1814 {
1727#if DEBUG_DV_PEER_NUMBERS 1815#if DEBUG_DV_PEER_NUMBERS
1728 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: entering slow send mode\n"); 1816 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1817 "DV SERVICE: entering slow send mode\n");
1729#endif 1818#endif
1730 send_context->task = GNUNET_SCHEDULER_add_delayed(GNUNET_DV_DEFAULT_SEND_INTERVAL, &neighbor_send_task, send_context); 1819 send_context->task =
1731 } 1820 GNUNET_SCHEDULER_add_delayed (GNUNET_DV_DEFAULT_SEND_INTERVAL,
1821 &neighbor_send_task, send_context);
1822 }
1732 1823
1733 return; 1824 return;
1734} 1825}
@@ -1755,7 +1846,7 @@ handle_start (void *cls,
1755 1846
1756 client_handle = client; 1847 client_handle = client;
1757 1848
1758 GNUNET_SERVER_client_keep(client_handle); 1849 GNUNET_SERVER_client_keep (client_handle);
1759 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1850 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1760} 1851}
1761 1852
@@ -1771,18 +1862,17 @@ handle_start (void *cls,
1771 * iterate, 1862 * iterate,
1772 * GNUNET_NO if not. 1863 * GNUNET_NO if not.
1773 */ 1864 */
1774int send_iterator (void *cls, 1865int
1775 const GNUNET_HashCode * key, 1866send_iterator (void *cls, const GNUNET_HashCode * key, void *abs_value)
1776 void *abs_value)
1777{ 1867{
1778 struct DV_SendContext *send_context = cls; 1868 struct DV_SendContext *send_context = cls;
1779 struct DistantNeighbor *distant_neighbor = abs_value; 1869 struct DistantNeighbor *distant_neighbor = abs_value;
1780 1870
1781 if (memcmp(distant_neighbor->referrer, send_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */ 1871 if (memcmp (distant_neighbor->referrer, send_context->direct_peer, sizeof (struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */
1782 { 1872 {
1783 send_message_via(&my_identity, distant_neighbor, send_context); 1873 send_message_via (&my_identity, distant_neighbor, send_context);
1784 return GNUNET_NO; 1874 return GNUNET_NO;
1785 } 1875 }
1786 return GNUNET_YES; 1876 return GNUNET_YES;
1787} 1877}
1788#endif 1878#endif
@@ -1795,9 +1885,10 @@ int send_iterator (void *cls,
1795 * @param client identification of the client 1885 * @param client identification of the client
1796 * @param message the actual message 1886 * @param message the actual message
1797 */ 1887 */
1798void handle_dv_send_message (void *cls, 1888void
1799 struct GNUNET_SERVER_Client * client, 1889handle_dv_send_message (void *cls,
1800 const struct GNUNET_MessageHeader * message) 1890 struct GNUNET_SERVER_Client *client,
1891 const struct GNUNET_MessageHeader *message)
1801{ 1892{
1802 struct GNUNET_DV_SendMessage *send_msg; 1893 struct GNUNET_DV_SendMessage *send_msg;
1803 struct GNUNET_DV_SendResultMessage *send_result_msg; 1894 struct GNUNET_DV_SendResultMessage *send_result_msg;
@@ -1811,6 +1902,7 @@ void handle_dv_send_message (void *cls,
1811 int offset; 1902 int offset;
1812 static struct GNUNET_CRYPTO_HashAsciiEncoded dest_hash; 1903 static struct GNUNET_CRYPTO_HashAsciiEncoded dest_hash;
1813 struct DV_SendContext *send_context; 1904 struct DV_SendContext *send_context;
1905
1814#if DEBUG_DV_MESSAGES 1906#if DEBUG_DV_MESSAGES
1815 char *cbuf; 1907 char *cbuf;
1816 struct GNUNET_MessageHeader *packed_message; 1908 struct GNUNET_MessageHeader *packed_message;
@@ -1820,7 +1912,8 @@ void handle_dv_send_message (void *cls,
1820 { 1912 {
1821 client_handle = client; 1913 client_handle = client;
1822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1823 "%s: Setting initial client handle, never received `%s' message?\n", "dv", "START"); 1915 "%s: Setting initial client handle, never received `%s' message?\n",
1916 "dv", "START");
1824 } 1917 }
1825 else if (client_handle != client) 1918 else if (client_handle != client)
1826 { 1919 {
@@ -1832,55 +1925,67 @@ void handle_dv_send_message (void *cls,
1832#endif 1925#endif
1833 } 1926 }
1834 1927
1835 GNUNET_assert(ntohs(message->size) > sizeof(struct GNUNET_DV_SendMessage)); 1928 GNUNET_assert (ntohs (message->size) > sizeof (struct GNUNET_DV_SendMessage));
1836 send_msg = (struct GNUNET_DV_SendMessage *)message; 1929 send_msg = (struct GNUNET_DV_SendMessage *) message;
1837 1930
1838 address_len = ntohl(send_msg->addrlen); 1931 address_len = ntohl (send_msg->addrlen);
1839 GNUNET_assert(address_len == sizeof(struct GNUNET_PeerIdentity) * 2); 1932 GNUNET_assert (address_len == sizeof (struct GNUNET_PeerIdentity) * 2);
1840 message_size = ntohs(message->size) - sizeof(struct GNUNET_DV_SendMessage) - address_len; 1933 message_size =
1841 destination = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 1934 ntohs (message->size) - sizeof (struct GNUNET_DV_SendMessage) -
1842 direct = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 1935 address_len;
1843 message_buf = GNUNET_malloc(message_size); 1936 destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1937 direct = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1938 message_buf = GNUNET_malloc (message_size);
1844 1939
1845 temp_pos = (char *)&send_msg[1]; /* Set pointer to end of message */ 1940 temp_pos = (char *) &send_msg[1]; /* Set pointer to end of message */
1846 offset = 0; /* Offset starts at zero */ 1941 offset = 0; /* Offset starts at zero */
1847 1942
1848 memcpy(destination, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity)); 1943 memcpy (destination, &temp_pos[offset], sizeof (struct GNUNET_PeerIdentity));
1849 offset += sizeof(struct GNUNET_PeerIdentity); 1944 offset += sizeof (struct GNUNET_PeerIdentity);
1850 1945
1851 memcpy(direct, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity)); 1946 memcpy (direct, &temp_pos[offset], sizeof (struct GNUNET_PeerIdentity));
1852 offset += sizeof(struct GNUNET_PeerIdentity); 1947 offset += sizeof (struct GNUNET_PeerIdentity);
1853 1948
1854 1949
1855 memcpy(message_buf, &temp_pos[offset], message_size); 1950 memcpy (message_buf, &temp_pos[offset], message_size);
1856 if (memcmp(&send_msg->target, destination, sizeof(struct GNUNET_PeerIdentity)) != 0) 1951 if (memcmp
1857 { 1952 (&send_msg->target, destination,
1858 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */ 1953 sizeof (struct GNUNET_PeerIdentity)) != 0)
1859 dest_hash.encoding[4] = '\0'; 1954 {
1860 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: asked to send message to `%s', but address is for `%s'!", "DV SERVICE", GNUNET_i2s(&send_msg->target), (const char *)&dest_hash.encoding); 1955 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1861 } 1956 dest_hash.encoding[4] = '\0';
1957 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1958 "%s: asked to send message to `%s', but address is for `%s'!",
1959 "DV SERVICE", GNUNET_i2s (&send_msg->target),
1960 (const char *) &dest_hash.encoding);
1961 }
1862 1962
1863#if DEBUG_DV_MESSAGES 1963#if DEBUG_DV_MESSAGES
1864 cbuf = (char *)message_buf; 1964 cbuf = (char *) message_buf;
1865 offset = 0; 1965 offset = 0;
1866 while(offset < message_size) 1966 while (offset < message_size)
1867 { 1967 {
1868 packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset]; 1968 packed_message = (struct GNUNET_MessageHeader *) &cbuf[offset];
1869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(packed_message->type), GNUNET_i2s(destination)); 1969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1870 offset += ntohs(packed_message->size); 1970 "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id,
1871 } 1971 ntohl (send_msg->uid), ntohs (packed_message->type),
1872 /*GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(message_buf->type), GNUNET_i2s(destination));*/ 1972 GNUNET_i2s (destination));
1973 offset += ntohs (packed_message->size);
1974 }
1975 /*GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(message_buf->type), GNUNET_i2s(destination)); */
1873#endif 1976#endif
1874 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */ 1977 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1875 dest_hash.encoding[4] = '\0'; 1978 dest_hash.encoding[4] = '\0';
1876 send_context = GNUNET_malloc(sizeof(struct DV_SendContext)); 1979 send_context = GNUNET_malloc (sizeof (struct DV_SendContext));
1877 1980
1878 send_result_msg = GNUNET_malloc(sizeof(struct GNUNET_DV_SendResultMessage)); 1981 send_result_msg = GNUNET_malloc (sizeof (struct GNUNET_DV_SendResultMessage));
1879 send_result_msg->header.size = htons(sizeof(struct GNUNET_DV_SendResultMessage)); 1982 send_result_msg->header.size =
1880 send_result_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT); 1983 htons (sizeof (struct GNUNET_DV_SendResultMessage));
1984 send_result_msg->header.type =
1985 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT);
1881 send_result_msg->uid = send_msg->uid; /* No need to ntohl->htonl this */ 1986 send_result_msg->uid = send_msg->uid; /* No need to ntohl->htonl this */
1882 1987
1883 send_context->importance = ntohl(send_msg->priority); 1988 send_context->importance = ntohl (send_msg->priority);
1884 send_context->timeout = send_msg->timeout; 1989 send_context->timeout = send_msg->timeout;
1885 send_context->direct_peer = direct; 1990 send_context->direct_peer = direct;
1886 send_context->distant_peer = destination; 1991 send_context->distant_peer = destination;
@@ -1891,84 +1996,111 @@ void handle_dv_send_message (void *cls,
1891 send_context->uid = send_msg->uid; 1996 send_context->uid = send_msg->uid;
1892#endif 1997#endif
1893 1998
1894 if (send_message_via(&my_identity, direct, send_context) != GNUNET_YES) 1999 if (send_message_via (&my_identity, direct, send_context) != GNUNET_YES)
2000 {
2001 send_result_msg->result = htons (1);
2002 pending_message =
2003 GNUNET_malloc (sizeof (struct PendingMessage) +
2004 sizeof (struct GNUNET_DV_SendResultMessage));
2005 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
2006 memcpy (&pending_message[1], send_result_msg,
2007 sizeof (struct GNUNET_DV_SendResultMessage));
2008 GNUNET_free (send_result_msg);
2009
2010 GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head, plugin_pending_tail,
2011 plugin_pending_tail, pending_message);
2012
2013 if (client_handle != NULL)
1895 { 2014 {
1896 send_result_msg->result = htons(1); 2015 if (plugin_transmit_handle == NULL)
1897 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage)); 2016 {
1898 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 2017 plugin_transmit_handle =
1899 memcpy(&pending_message[1], send_result_msg, sizeof(struct GNUNET_DV_SendResultMessage)); 2018 GNUNET_SERVER_notify_transmit_ready (client_handle,
1900 GNUNET_free(send_result_msg); 2019 sizeof (struct
1901 2020 GNUNET_DV_SendResultMessage),
1902 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message); 2021 GNUNET_TIME_UNIT_FOREVER_REL,
1903 2022 &transmit_to_plugin, NULL);
1904 if (client_handle != NULL) 2023 }
1905 { 2024 else
1906 if (plugin_transmit_handle == NULL) 2025 {
1907 { 2026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1908 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 2027 "Failed to queue message for plugin, must be one in progress already!!\n");
1909 sizeof(struct GNUNET_DV_SendResultMessage), 2028 }
1910 GNUNET_TIME_UNIT_FOREVER_REL,
1911 &transmit_to_plugin, NULL);
1912 }
1913 else
1914 {
1915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
1916 }
1917 }
1918 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1919 dest_hash.encoding[4] = '\0';
1920 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s DV SEND failed to send message to destination `%s' via `%s'\n", my_short_id, (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
1921 } 2029 }
2030 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
2031 dest_hash.encoding[4] = '\0';
2032 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2033 "%s DV SEND failed to send message to destination `%s' via `%s'\n",
2034 my_short_id, (const char *) &dest_hash.encoding,
2035 GNUNET_i2s (direct));
2036 }
1922 2037
1923 /* In bizarro world GNUNET_SYSERR indicates that we succeeded */ 2038 /* In bizarro world GNUNET_SYSERR indicates that we succeeded */
1924#if UNSIMPLER 2039#if UNSIMPLER
1925 if (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple(extended_neighbors, &destination->hashPubKey, &send_iterator, send_context)) 2040 if (GNUNET_SYSERR !=
2041 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
2042 &destination->hashPubKey,
2043 &send_iterator, send_context))
2044 {
2045 send_result_msg->result = htons (1);
2046 pending_message =
2047 GNUNET_malloc (sizeof (struct PendingMessage) +
2048 sizeof (struct GNUNET_DV_SendResultMessage));
2049 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
2050 memcpy (&pending_message[1], send_result_msg,
2051 sizeof (struct GNUNET_DV_SendResultMessage));
2052 GNUNET_free (send_result_msg);
2053
2054 GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head, plugin_pending_tail,
2055 plugin_pending_tail, pending_message);
2056
2057 if (client_handle != NULL)
1926 { 2058 {
1927 send_result_msg->result = htons(1); 2059 if (plugin_transmit_handle == NULL)
1928 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage)); 2060 {
1929 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 2061 plugin_transmit_handle =
1930 memcpy(&pending_message[1], send_result_msg, sizeof(struct GNUNET_DV_SendResultMessage)); 2062 GNUNET_SERVER_notify_transmit_ready (client_handle,
1931 GNUNET_free(send_result_msg); 2063 sizeof (struct
1932 2064 GNUNET_DV_SendResultMessage),
1933 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message); 2065 GNUNET_TIME_UNIT_FOREVER_REL,
1934 2066 &transmit_to_plugin, NULL);
1935 if (client_handle != NULL) 2067 }
1936 { 2068 else
1937 if (plugin_transmit_handle == NULL) 2069 {
1938 { 2070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1939 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 2071 "Failed to queue message for plugin, must be one in progress already!!\n");
1940 sizeof(struct GNUNET_DV_SendResultMessage), 2072 }
1941 GNUNET_TIME_UNIT_FOREVER_REL,
1942 &transmit_to_plugin, NULL);
1943 }
1944 else
1945 {
1946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
1947 }
1948 }
1949 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1950 dest_hash.encoding[4] = '\0';
1951 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s DV SEND failed to send message to destination `%s' via `%s'\n", my_short_id, (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
1952 } 2073 }
2074 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
2075 dest_hash.encoding[4] = '\0';
2076 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2077 "%s DV SEND failed to send message to destination `%s' via `%s'\n",
2078 my_short_id, (const char *) &dest_hash.encoding,
2079 GNUNET_i2s (direct));
2080 }
1953#endif 2081#endif
1954 GNUNET_free(message_buf); 2082 GNUNET_free (message_buf);
1955 GNUNET_free(send_context); 2083 GNUNET_free (send_context);
1956 GNUNET_free(direct); 2084 GNUNET_free (direct);
1957 GNUNET_free(destination); 2085 GNUNET_free (destination);
1958 2086
1959 GNUNET_SERVER_receive_done(client, GNUNET_OK); 2087 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1960} 2088}
1961 2089
1962/** Forward declarations **/ 2090/** Forward declarations **/
1963static int handle_dv_gossip_message (void *cls, 2091static int handle_dv_gossip_message (void *cls,
1964 const struct GNUNET_PeerIdentity *peer, 2092 const struct GNUNET_PeerIdentity *peer,
1965 const struct GNUNET_MessageHeader *message, 2093 const struct GNUNET_MessageHeader *message,
1966 const struct GNUNET_TRANSPORT_ATS_Information *atsi); 2094 const struct
2095 GNUNET_TRANSPORT_ATS_Information *atsi);
1967 2096
1968static int handle_dv_disconnect_message (void *cls, 2097static int handle_dv_disconnect_message (void *cls,
1969 const struct GNUNET_PeerIdentity *peer, 2098 const struct GNUNET_PeerIdentity *peer,
1970 const struct GNUNET_MessageHeader *message, 2099 const struct GNUNET_MessageHeader
1971 const struct GNUNET_TRANSPORT_ATS_Information *atsi); 2100 *message,
2101 const struct
2102 GNUNET_TRANSPORT_ATS_Information
2103 *atsi);
1972/** End forward declarations **/ 2104/** End forward declarations **/
1973 2105
1974 2106
@@ -2006,14 +2138,14 @@ distant_neighbor_free (struct DistantNeighbor *referee)
2006 2138
2007 referrer = referee->referrer; 2139 referrer = referee->referrer;
2008 if (referrer != NULL) 2140 if (referrer != NULL)
2009 { 2141 {
2010 GNUNET_CONTAINER_DLL_remove (referrer->referee_head, 2142 GNUNET_CONTAINER_DLL_remove (referrer->referee_head,
2011 referrer->referee_tail, referee); 2143 referrer->referee_tail, referee);
2012 } 2144 }
2013 GNUNET_CONTAINER_heap_remove_node (referee->max_loc); 2145 GNUNET_CONTAINER_heap_remove_node (referee->max_loc);
2014 GNUNET_CONTAINER_heap_remove_node (referee->min_loc); 2146 GNUNET_CONTAINER_heap_remove_node (referee->min_loc);
2015 GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors, 2147 GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors,
2016 &referee->identity.hashPubKey); 2148 &referee->identity.hashPubKey);
2017 GNUNET_free_non_null (referee->pkey); 2149 GNUNET_free_non_null (referee->pkey);
2018 GNUNET_free (referee); 2150 GNUNET_free (referee);
2019} 2151}
@@ -2032,18 +2164,20 @@ direct_neighbor_free (struct DirectNeighbor *direct)
2032 send_context = direct->send_context; 2164 send_context = direct->send_context;
2033 2165
2034 if (send_context->task != GNUNET_SCHEDULER_NO_TASK) 2166 if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2035 GNUNET_SCHEDULER_cancel(send_context->task); 2167 GNUNET_SCHEDULER_cancel (send_context->task);
2036 2168
2037 about_list = send_context->fast_gossip_list_head; 2169 about_list = send_context->fast_gossip_list_head;
2038 while (about_list != NULL) 2170 while (about_list != NULL)
2039 { 2171 {
2040 GNUNET_CONTAINER_DLL_remove(send_context->fast_gossip_list_head, send_context->fast_gossip_list_tail, about_list); 2172 GNUNET_CONTAINER_DLL_remove (send_context->fast_gossip_list_head,
2041 prev_about = about_list; 2173 send_context->fast_gossip_list_tail,
2042 about_list = about_list->next; 2174 about_list);
2043 GNUNET_free(prev_about); 2175 prev_about = about_list;
2044 } 2176 about_list = about_list->next;
2045 GNUNET_free(send_context); 2177 GNUNET_free (prev_about);
2046 GNUNET_free(direct); 2178 }
2179 GNUNET_free (send_context);
2180 GNUNET_free (direct);
2047} 2181}
2048 2182
2049/** 2183/**
@@ -2056,9 +2190,9 @@ direct_neighbor_free (struct DirectNeighbor *direct)
2056 * 2190 *
2057 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 2191 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
2058 */ 2192 */
2059static int schedule_disconnect_messages (void *cls, 2193static int
2060 const GNUNET_HashCode * key, 2194schedule_disconnect_messages (void *cls,
2061 void *value) 2195 const GNUNET_HashCode * key, void *value)
2062{ 2196{
2063 struct DisconnectContext *disconnect_context = cls; 2197 struct DisconnectContext *disconnect_context = cls;
2064 struct DirectNeighbor *disconnected = disconnect_context->direct; 2198 struct DirectNeighbor *disconnected = disconnect_context->direct;
@@ -2066,28 +2200,32 @@ static int schedule_disconnect_messages (void *cls,
2066 struct PendingMessage *pending_message; 2200 struct PendingMessage *pending_message;
2067 p2p_dv_MESSAGE_Disconnect *disconnect_message; 2201 p2p_dv_MESSAGE_Disconnect *disconnect_message;
2068 2202
2069 if (memcmp(&notify->identity, &disconnected->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2203 if (memcmp
2070 return GNUNET_YES; /* Don't send disconnect message to peer that disconnected! */ 2204 (&notify->identity, &disconnected->identity,
2205 sizeof (struct GNUNET_PeerIdentity)) == 0)
2206 return GNUNET_YES; /* Don't send disconnect message to peer that disconnected! */
2071 2207
2072 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_Disconnect)); 2208 pending_message =
2073 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 2209 GNUNET_malloc (sizeof (struct PendingMessage) +
2210 sizeof (p2p_dv_MESSAGE_Disconnect));
2211 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
2074 pending_message->importance = default_dv_priority; 2212 pending_message->importance = default_dv_priority;
2075 pending_message->timeout = GNUNET_TIME_relative_get_forever(); 2213 pending_message->timeout = GNUNET_TIME_relative_get_forever ();
2076 memcpy(&pending_message->recipient, &notify->identity, sizeof(struct GNUNET_PeerIdentity)); 2214 memcpy (&pending_message->recipient, &notify->identity,
2077 pending_message->msg_size = sizeof(p2p_dv_MESSAGE_Disconnect); 2215 sizeof (struct GNUNET_PeerIdentity));
2078 disconnect_message = (p2p_dv_MESSAGE_Disconnect *)pending_message->msg; 2216 pending_message->msg_size = sizeof (p2p_dv_MESSAGE_Disconnect);
2217 disconnect_message = (p2p_dv_MESSAGE_Disconnect *) pending_message->msg;
2079 disconnect_message->header.size = htons (sizeof (p2p_dv_MESSAGE_Disconnect)); 2218 disconnect_message->header.size = htons (sizeof (p2p_dv_MESSAGE_Disconnect));
2080 disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT); 2219 disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT);
2081 disconnect_message->peer_id = htonl(disconnect_context->distant->our_id); 2220 disconnect_message->peer_id = htonl (disconnect_context->distant->our_id);
2082 2221
2083 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 2222 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
2084 core_pending_tail, 2223 core_pending_tail,
2085 core_pending_tail, 2224 core_pending_tail, pending_message);
2086 pending_message);
2087 2225
2088 GNUNET_SCHEDULER_add_now(try_core_send, NULL); 2226 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
2089 /*if (core_transmit_handle == NULL) 2227 /*if (core_transmit_handle == NULL)
2090 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL);*/ 2228 * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL); */
2091 2229
2092 return GNUNET_YES; 2230 return GNUNET_YES;
2093} 2231}
@@ -2101,12 +2239,12 @@ static int schedule_disconnect_messages (void *cls,
2101 * 2239 *
2102 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 2240 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
2103 */ 2241 */
2104static int free_extended_neighbors (void *cls, 2242static int
2105 const GNUNET_HashCode * key, 2243free_extended_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2106 void *value)
2107{ 2244{
2108 struct DistantNeighbor *distant = value; 2245 struct DistantNeighbor *distant = value;
2109 distant_neighbor_free(distant); 2246
2247 distant_neighbor_free (distant);
2110 return GNUNET_YES; 2248 return GNUNET_YES;
2111} 2249}
2112 2250
@@ -2119,12 +2257,12 @@ static int free_extended_neighbors (void *cls,
2119 * 2257 *
2120 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 2258 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
2121 */ 2259 */
2122static int free_direct_neighbors (void *cls, 2260static int
2123 const GNUNET_HashCode * key, 2261free_direct_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2124 void *value)
2125{ 2262{
2126 struct DirectNeighbor *direct = value; 2263 struct DirectNeighbor *direct = value;
2127 direct_neighbor_free(direct); 2264
2265 direct_neighbor_free (direct);
2128 return GNUNET_YES; 2266 return GNUNET_YES;
2129} 2267}
2130 2268
@@ -2136,52 +2274,56 @@ static int free_direct_neighbors (void *cls,
2136 * @param tc unused 2274 * @param tc unused
2137 */ 2275 */
2138static void 2276static void
2139shutdown_task (void *cls, 2277shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2140 const struct GNUNET_SCHEDULER_TaskContext *tc)
2141{ 2278{
2142#if DEBUG_DV 2279#if DEBUG_DV
2143 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n"); 2280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n");
2144 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &print_neighbors, NULL); 2281 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &print_neighbors,
2282 NULL);
2145#endif 2283#endif
2146 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &free_extended_neighbors, NULL); 2284 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
2147 GNUNET_CONTAINER_multihashmap_destroy(extended_neighbors); 2285 &free_extended_neighbors, NULL);
2148 GNUNET_CONTAINER_multihashmap_iterate(direct_neighbors, &free_direct_neighbors, NULL); 2286 GNUNET_CONTAINER_multihashmap_destroy (extended_neighbors);
2149 GNUNET_CONTAINER_multihashmap_destroy(direct_neighbors); 2287 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
2288 &free_direct_neighbors, NULL);
2289 GNUNET_CONTAINER_multihashmap_destroy (direct_neighbors);
2150 2290
2151 GNUNET_CONTAINER_heap_destroy(neighbor_max_heap); 2291 GNUNET_CONTAINER_heap_destroy (neighbor_max_heap);
2152 GNUNET_CONTAINER_heap_destroy(neighbor_min_heap); 2292 GNUNET_CONTAINER_heap_destroy (neighbor_min_heap);
2153 2293
2154 GNUNET_CORE_disconnect (coreAPI); 2294 GNUNET_CORE_disconnect (coreAPI);
2155 coreAPI = NULL; 2295 coreAPI = NULL;
2156 GNUNET_PEERINFO_disconnect(peerinfo_handle); 2296 GNUNET_PEERINFO_disconnect (peerinfo_handle);
2157 GNUNET_SERVER_mst_destroy(coreMST); 2297 GNUNET_SERVER_mst_destroy (coreMST);
2158 GNUNET_free_non_null(my_short_id); 2298 GNUNET_free_non_null (my_short_id);
2159#if DEBUG_DV 2299#if DEBUG_DV
2160 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n"); 2300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n");
2161#endif 2301#endif
2162} 2302}
2163 2303
2164/** 2304/**
2165 * To be called on core init/fail. 2305 * To be called on core init/fail.
2166 */ 2306 */
2167void core_init (void *cls, 2307void
2168 struct GNUNET_CORE_Handle * server, 2308core_init (void *cls,
2169 const struct GNUNET_PeerIdentity *identity, 2309 struct GNUNET_CORE_Handle *server,
2170 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * publicKey) 2310 const struct GNUNET_PeerIdentity *identity,
2311 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
2171{ 2312{
2172 2313
2173 if (server == NULL) 2314 if (server == NULL)
2174 { 2315 {
2175 GNUNET_SCHEDULER_cancel(cleanup_task); 2316 GNUNET_SCHEDULER_cancel (cleanup_task);
2176 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 2317 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
2177 return; 2318 return;
2178 } 2319 }
2179#if DEBUG_DV 2320#if DEBUG_DV
2180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2181 "%s: Core connection initialized, I am peer: %s\n", "dv", GNUNET_i2s(identity)); 2322 "%s: Core connection initialized, I am peer: %s\n", "dv",
2323 GNUNET_i2s (identity));
2182#endif 2324#endif
2183 memcpy(&my_identity, identity, sizeof(struct GNUNET_PeerIdentity)); 2325 memcpy (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity));
2184 my_short_id = GNUNET_strdup(GNUNET_i2s(&my_identity)); 2326 my_short_id = GNUNET_strdup (GNUNET_i2s (&my_identity));
2185 coreAPI = server; 2327 coreAPI = server;
2186} 2328}
2187 2329
@@ -2197,17 +2339,18 @@ void core_init (void *cls,
2197 * iterate, 2339 * iterate,
2198 * GNUNET_NO if not. 2340 * GNUNET_NO if not.
2199 */ 2341 */
2200static int add_pkey_to_extended (void *cls, 2342static int
2201 const GNUNET_HashCode * key, 2343add_pkey_to_extended (void *cls, const GNUNET_HashCode * key, void *abs_value)
2202 void *abs_value)
2203{ 2344{
2204 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls; 2345 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls;
2205 struct DistantNeighbor *distant_neighbor = abs_value; 2346 struct DistantNeighbor *distant_neighbor = abs_value;
2206 2347
2207 if (distant_neighbor->pkey == NULL) 2348 if (distant_neighbor->pkey == NULL)
2208 { 2349 {
2209 distant_neighbor->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 2350 distant_neighbor->pkey =
2210 memcpy(distant_neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 2351 GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2352 memcpy (distant_neighbor->pkey, pkey,
2353 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2211 } 2354 }
2212 2355
2213 return GNUNET_YES; 2356 return GNUNET_YES;
@@ -2224,20 +2367,21 @@ static int add_pkey_to_extended (void *cls,
2224 * iterate, 2367 * iterate,
2225 * GNUNET_NO if not. 2368 * GNUNET_NO if not.
2226 */ 2369 */
2227static int update_matching_neighbors (void *cls, 2370static int
2228 const GNUNET_HashCode * key, 2371update_matching_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2229 void *value)
2230{ 2372{
2231 struct NeighborUpdateInfo * update_info = cls; 2373 struct NeighborUpdateInfo *update_info = cls;
2232 struct DistantNeighbor *distant_neighbor = value; 2374 struct DistantNeighbor *distant_neighbor = value;
2233 2375
2234 if (update_info->referrer == distant_neighbor->referrer) /* Direct neighbor matches, update it's info and return GNUNET_NO */ 2376 if (update_info->referrer == distant_neighbor->referrer) /* Direct neighbor matches, update it's info and return GNUNET_NO */
2235 { 2377 {
2236 /* same referrer, cost change! */ 2378 /* same referrer, cost change! */
2237 GNUNET_CONTAINER_heap_update_cost (neighbor_max_heap, 2379 GNUNET_CONTAINER_heap_update_cost (neighbor_max_heap,
2238 update_info->neighbor->max_loc, update_info->cost); 2380 update_info->neighbor->max_loc,
2381 update_info->cost);
2239 GNUNET_CONTAINER_heap_update_cost (neighbor_min_heap, 2382 GNUNET_CONTAINER_heap_update_cost (neighbor_min_heap,
2240 update_info->neighbor->min_loc, update_info->cost); 2383 update_info->neighbor->min_loc,
2384 update_info->cost);
2241 update_info->neighbor->last_activity = update_info->now; 2385 update_info->neighbor->last_activity = update_info->now;
2242 update_info->neighbor->cost = update_info->cost; 2386 update_info->neighbor->cost = update_info->cost;
2243 update_info->neighbor->referrer_id = update_info->referrer_peer_id; 2387 update_info->neighbor->referrer_id = update_info->referrer_peer_id;
@@ -2259,54 +2403,59 @@ static int update_matching_neighbors (void *cls,
2259 * 2403 *
2260 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise 2404 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2261 */ 2405 */
2262static int add_distant_all_direct_neighbors (void *cls, 2406static int
2263 const GNUNET_HashCode * key, 2407add_distant_all_direct_neighbors (void *cls,
2264 void *value) 2408 const GNUNET_HashCode * key, void *value)
2265{ 2409{
2266 struct DirectNeighbor *direct = (struct DirectNeighbor *)value; 2410 struct DirectNeighbor *direct = (struct DirectNeighbor *) value;
2267 struct DistantNeighbor *distant = (struct DistantNeighbor *)cls; 2411 struct DistantNeighbor *distant = (struct DistantNeighbor *) cls;
2268 struct NeighborSendContext *send_context = direct->send_context; 2412 struct NeighborSendContext *send_context = direct->send_context;
2269 struct FastGossipNeighborList *gossip_entry; 2413 struct FastGossipNeighborList *gossip_entry;
2414
2270#if DEBUG_DV 2415#if DEBUG_DV
2271 char *encPeerAbout; 2416 char *encPeerAbout;
2272 char *encPeerTo; 2417 char *encPeerTo;
2273#endif 2418#endif
2274 2419
2275 if (distant == NULL) 2420 if (distant == NULL)
2276 { 2421 {
2277 return GNUNET_YES; 2422 return GNUNET_YES;
2278 } 2423 }
2279 2424
2280 if (memcmp(&direct->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2425 if (memcmp
2281 { 2426 (&direct->identity, &distant->identity,
2282 return GNUNET_YES; /* Don't gossip to a peer about itself! */ 2427 sizeof (struct GNUNET_PeerIdentity)) == 0)
2283 } 2428 {
2429 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2430 }
2284 2431
2285#if SUPPORT_HIDING 2432#if SUPPORT_HIDING
2286 if (distant->hidden == GNUNET_YES) 2433 if (distant->hidden == GNUNET_YES)
2287 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */ 2434 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2288#endif 2435#endif
2289 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList)); 2436 gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
2290 gossip_entry->about = distant; 2437 gossip_entry->about = distant;
2291 2438
2292 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head, 2439 GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
2293 send_context->fast_gossip_list_tail, 2440 send_context->fast_gossip_list_tail,
2294 send_context->fast_gossip_list_tail, 2441 send_context->fast_gossip_list_tail,
2295 gossip_entry); 2442 gossip_entry);
2296#if DEBUG_DV 2443#if DEBUG_DV
2297 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&distant->identity)); 2444 encPeerAbout = GNUNET_strdup (GNUNET_i2s (&distant->identity));
2298 encPeerTo = GNUNET_strdup(GNUNET_i2s(&direct->identity)); 2445 encPeerTo = GNUNET_strdup (GNUNET_i2s (&direct->identity));
2299 2446
2300 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Fast send info about peer %s id %u for directly connected peer %s\n", 2447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2301 GNUNET_i2s(&my_identity), 2448 "%s: Fast send info about peer %s id %u for directly connected peer %s\n",
2302 encPeerAbout, distant->our_id, encPeerTo); 2449 GNUNET_i2s (&my_identity), encPeerAbout, distant->our_id,
2303 GNUNET_free(encPeerAbout); 2450 encPeerTo);
2304 GNUNET_free(encPeerTo); 2451 GNUNET_free (encPeerAbout);
2452 GNUNET_free (encPeerTo);
2305#endif 2453#endif
2306 /*if (send_context->task != GNUNET_SCHEDULER_NO_TASK) 2454 /*if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2307 GNUNET_SCHEDULER_cancel(send_context->task);*/ 2455 * GNUNET_SCHEDULER_cancel(send_context->task); */
2308 2456
2309 send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context); 2457 send_context->task =
2458 GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
2310 return GNUNET_YES; 2459 return GNUNET_YES;
2311} 2460}
2312 2461
@@ -2333,24 +2482,27 @@ generate_hello_address (void *cls, size_t max, void *buf)
2333 return 0; 2482 return 0;
2334 2483
2335 /* Hello "address" will be concatenation of distant peer and direct peer identities */ 2484 /* Hello "address" will be concatenation of distant peer and direct peer identities */
2336 size = 2 * sizeof(struct GNUNET_PeerIdentity); 2485 size = 2 * sizeof (struct GNUNET_PeerIdentity);
2337 GNUNET_assert(max >= size); 2486 GNUNET_assert (max >= size);
2338 2487
2339 addr_buffer = GNUNET_malloc(size); 2488 addr_buffer = GNUNET_malloc (size);
2340 offset = 0; 2489 offset = 0;
2341 /* Copy the distant peer identity to buffer */ 2490 /* Copy the distant peer identity to buffer */
2342 memcpy(addr_buffer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)); 2491 memcpy (addr_buffer, &hello_context->distant_peer,
2343 offset += sizeof(struct GNUNET_PeerIdentity); 2492 sizeof (struct GNUNET_PeerIdentity));
2493 offset += sizeof (struct GNUNET_PeerIdentity);
2344 /* Copy the direct peer identity to buffer */ 2494 /* Copy the direct peer identity to buffer */
2345 memcpy(&addr_buffer[offset], hello_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)); 2495 memcpy (&addr_buffer[offset], hello_context->direct_peer,
2346 ret = GNUNET_HELLO_add_address ("dv", 2496 sizeof (struct GNUNET_PeerIdentity));
2347 GNUNET_TIME_relative_to_absolute 2497 ret =
2348 (GNUNET_TIME_UNIT_HOURS), addr_buffer, size, 2498 GNUNET_HELLO_add_address ("dv",
2349 buf, max); 2499 GNUNET_TIME_relative_to_absolute
2500 (GNUNET_TIME_UNIT_HOURS), addr_buffer, size,
2501 buf, max);
2350 2502
2351 hello_context->addresses_to_add--; 2503 hello_context->addresses_to_add--;
2352 2504
2353 GNUNET_free(addr_buffer); 2505 GNUNET_free (addr_buffer);
2354 return ret; 2506 return ret;
2355} 2507}
2356 2508
@@ -2370,8 +2522,8 @@ generate_hello_address (void *cls, size_t max, void *buf)
2370 * not added) 2522 * not added)
2371 */ 2523 */
2372static struct DistantNeighbor * 2524static struct DistantNeighbor *
2373addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, 2525addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2374 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey, 2526 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
2375 unsigned int referrer_peer_id, 2527 unsigned int referrer_peer_id,
2376 struct DirectNeighbor *referrer, unsigned int cost) 2528 struct DirectNeighbor *referrer, unsigned int cost)
2377{ 2529{
@@ -2388,6 +2540,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
2388 2540
2389#if DEBUG_DV_PEER_NUMBERS 2541#if DEBUG_DV_PEER_NUMBERS
2390 char *encAbout; 2542 char *encAbout;
2543
2391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2392 "%s Received sender id (%u)!\n", "DV SERVICE", referrer_peer_id); 2545 "%s Received sender id (%u)!\n", "DV SERVICE", referrer_peer_id);
2393#endif 2546#endif
@@ -2395,7 +2548,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
2395 now = GNUNET_TIME_absolute_get (); 2548 now = GNUNET_TIME_absolute_get ();
2396 neighbor = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 2549 neighbor = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
2397 &peer->hashPubKey); 2550 &peer->hashPubKey);
2398 neighbor_update = GNUNET_malloc(sizeof(struct NeighborUpdateInfo)); 2551 neighbor_update = GNUNET_malloc (sizeof (struct NeighborUpdateInfo));
2399 neighbor_update->neighbor = neighbor; 2552 neighbor_update->neighbor = neighbor;
2400 neighbor_update->cost = cost; 2553 neighbor_update->cost = cost;
2401 neighbor_update->now = now; 2554 neighbor_update->now = now;
@@ -2403,163 +2556,189 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
2403 neighbor_update->referrer_peer_id = referrer_peer_id; 2556 neighbor_update->referrer_peer_id = referrer_peer_id;
2404 2557
2405 if (neighbor != NULL) 2558 if (neighbor != NULL)
2406 { 2559 {
2407#if USE_PEER_ID 2560#if USE_PEER_ID
2408 memcpy(&our_id, &neighbor->identity, sizeof(unsigned int)); 2561 memcpy (&our_id, &neighbor->identity, sizeof (unsigned int));
2409#else 2562#else
2410 our_id = neighbor->our_id; 2563 our_id = neighbor->our_id;
2411#endif 2564#endif
2412 } 2565 }
2413 else 2566 else
2414 { 2567 {
2415#if USE_PEER_ID 2568#if USE_PEER_ID
2416 memcpy(&our_id, peer, sizeof(unsigned int)); 2569 memcpy (&our_id, peer, sizeof (unsigned int));
2417#else 2570#else
2418 our_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, RAND_MAX - 1) + 1; 2571 our_id =
2572 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
2573 RAND_MAX - 1) + 1;
2419#endif 2574#endif
2420 } 2575 }
2421 2576
2422 /* Either we do not know this peer, or we already do but via a different immediate peer */ 2577 /* Either we do not know this peer, or we already do but via a different immediate peer */
2423 if ((neighbor == NULL) || 2578 if ((neighbor == NULL) ||
2424 (GNUNET_CONTAINER_multihashmap_get_multiple(extended_neighbors, 2579 (GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
2425 &peer->hashPubKey, 2580 &peer->hashPubKey,
2426 &update_matching_neighbors, 2581 &update_matching_neighbors,
2427 neighbor_update) != GNUNET_SYSERR)) 2582 neighbor_update) !=
2428 { 2583 GNUNET_SYSERR))
2584 {
2429#if AT_MOST_ONE 2585#if AT_MOST_ONE
2430 if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */ 2586 if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */
2431 { 2587 {
2432 distant_neighbor_free(neighbor); 2588 distant_neighbor_free (neighbor);
2433 } 2589 }
2434 else if (neighbor != NULL) /* Only allow one DV connection to each peer */ 2590 else if (neighbor != NULL) /* Only allow one DV connection to each peer */
2435 { 2591 {
2436 return NULL; 2592 return NULL;
2437 } 2593 }
2438#endif 2594#endif
2439 /* new neighbor! */ 2595 /* new neighbor! */
2440 if (cost > fisheye_depth) 2596 if (cost > fisheye_depth)
2441 { 2597 {
2442 /* too costly */ 2598 /* too costly */
2443 GNUNET_free(neighbor_update); 2599 GNUNET_free (neighbor_update);
2444 return NULL; 2600 return NULL;
2445 } 2601 }
2446 2602
2447#if DEBUG_DV_PEER_NUMBERS 2603#if DEBUG_DV_PEER_NUMBERS
2448 encAbout = GNUNET_strdup(GNUNET_i2s(peer)); 2604 encAbout = GNUNET_strdup (GNUNET_i2s (peer));
2449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2450 "%s: %s Chose NEW id (%u) for peer %s!\n", GNUNET_i2s(&my_identity), "DV SERVICE", our_id, encAbout); 2606 "%s: %s Chose NEW id (%u) for peer %s!\n",
2451 GNUNET_free(encAbout); 2607 GNUNET_i2s (&my_identity), "DV SERVICE", our_id, encAbout);
2608 GNUNET_free (encAbout);
2452#endif 2609#endif
2453 2610
2454 if (max_table_size <= 2611 if (max_table_size <=
2455 GNUNET_CONTAINER_multihashmap_size (extended_neighbors)) 2612 GNUNET_CONTAINER_multihashmap_size (extended_neighbors))
2456 { 2613 {
2457 /* remove most expensive entry */ 2614 /* remove most expensive entry */
2458 max = GNUNET_CONTAINER_heap_peek (neighbor_max_heap); 2615 max = GNUNET_CONTAINER_heap_peek (neighbor_max_heap);
2459 GNUNET_assert(max != NULL); 2616 GNUNET_assert (max != NULL);
2460 if (cost > max->cost) 2617 if (cost > max->cost)
2461 {
2462 /* new entry most expensive, don't create */
2463 GNUNET_free(neighbor_update);
2464 return NULL;
2465 }
2466 if (max->cost > 1)
2467 {
2468 /* only free if this is not a direct connection;
2469 we could theoretically have more direct
2470 connections than DV entries allowed total! */
2471 distant_neighbor_free (max);
2472 }
2473 }
2474
2475 neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor));
2476 GNUNET_CONTAINER_DLL_insert (referrer->referee_head,
2477 referrer->referee_tail, neighbor);
2478 neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap,
2479 neighbor, cost);
2480 neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap,
2481 neighbor, cost);
2482 neighbor->referrer = referrer;
2483 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2484 if (pkey != NULL) /* pkey will be null on direct neighbor addition */
2485 { 2618 {
2486 neighbor->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 2619 /* new entry most expensive, don't create */
2487 memcpy (neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 2620 GNUNET_free (neighbor_update);
2621 return NULL;
2488 } 2622 }
2489 else 2623 if (max->cost > 1)
2490 neighbor->pkey = pkey; 2624 {
2491 2625 /* only free if this is not a direct connection;
2492 neighbor->last_activity = now; 2626 * we could theoretically have more direct
2493 neighbor->cost = cost; 2627 * connections than DV entries allowed total! */
2494 neighbor->referrer_id = referrer_peer_id; 2628 distant_neighbor_free (max);
2495 neighbor->our_id = our_id; 2629 }
2496 neighbor->hidden = 2630 }
2497 (cost == DIRECT_NEIGHBOR_COST) ? (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4) == 2631
2498 0) : GNUNET_NO; 2632 neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor));
2499 2633 GNUNET_CONTAINER_DLL_insert (referrer->referee_head,
2500 GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey, 2634 referrer->referee_tail, neighbor);
2501 neighbor, 2635 neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap,
2502 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2636 neighbor, cost);
2503 if (referrer_peer_id != 0) 2637 neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap,
2638 neighbor, cost);
2639 neighbor->referrer = referrer;
2640 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2641 if (pkey != NULL) /* pkey will be null on direct neighbor addition */
2642 {
2643 neighbor->pkey =
2644 GNUNET_malloc (sizeof
2645 (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2646 memcpy (neighbor->pkey, pkey,
2647 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2648 }
2649 else
2650 neighbor->pkey = pkey;
2651
2652 neighbor->last_activity = now;
2653 neighbor->cost = cost;
2654 neighbor->referrer_id = referrer_peer_id;
2655 neighbor->our_id = our_id;
2656 neighbor->hidden =
2657 (cost ==
2658 DIRECT_NEIGHBOR_COST)
2659 ? (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4) ==
2660 0) : GNUNET_NO;
2661
2662 GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey,
2663 neighbor,
2664 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2665 if (referrer_peer_id != 0)
2666 {
2667 for (i = 0; i < MAX_OUTSTANDING_MESSAGES; i++)
2668 {
2669 if (referrer->pending_messages[i].sender_id == referrer_peer_id) /* We have a queued message from just learned about peer! */
2504 { 2670 {
2505 for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++)
2506 {
2507 if (referrer->pending_messages[i].sender_id == referrer_peer_id) /* We have a queued message from just learned about peer! */
2508 {
2509#if DEBUG_DV_MESSAGES 2671#if DEBUG_DV_MESSAGES
2510 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", my_short_id, referrer_peer_id); 2672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2511#endif 2673 "%s: learned about peer %llu from which we have a previous unknown message, processing!\n",
2512 struct GNUNET_TRANSPORT_ATS_Information atsi[3]; 2674 my_short_id, referrer_peer_id);
2513 atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 2675#endif
2514 atsi[0].value = htonl (referrer->pending_messages[i].distance); 2676 struct GNUNET_TRANSPORT_ATS_Information atsi[3];
2515 atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY); 2677
2516 atsi[1].value = htonl ((uint32_t)referrer->pending_messages[i].latency.rel_value); 2678 atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
2517 atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 2679 atsi[0].value = htonl (referrer->pending_messages[i].distance);
2518 atsi[2].value = htonl (0); 2680 atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
2519 handle_dv_data_message(NULL, 2681 atsi[1].value =
2520 &referrer->pending_messages[i].sender, 2682 htonl ((uint32_t) referrer->pending_messages[i].
2521 referrer->pending_messages[i].message, 2683 latency.rel_value);
2522 (const struct GNUNET_TRANSPORT_ATS_Information *)&atsi); 2684 atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
2523 GNUNET_free(referrer->pending_messages[i].message); 2685 atsi[2].value = htonl (0);
2524 referrer->pending_messages[i].sender_id = 0; 2686 handle_dv_data_message (NULL,
2525 } 2687 &referrer->pending_messages[i].sender,
2526 } 2688 referrer->pending_messages[i].message,
2689 (const struct GNUNET_TRANSPORT_ATS_Information
2690 *) &atsi);
2691 GNUNET_free (referrer->pending_messages[i].message);
2692 referrer->pending_messages[i].sender_id = 0;
2527 } 2693 }
2528 if ((cost != DIRECT_NEIGHBOR_COST) && (neighbor->pkey != NULL)) 2694 }
2529 { 2695 }
2530 /* Added neighbor, now send HELLO to transport */ 2696 if ((cost != DIRECT_NEIGHBOR_COST) && (neighbor->pkey != NULL))
2531 hello_context = GNUNET_malloc(sizeof(struct HelloContext)); 2697 {
2532 hello_context->direct_peer = &referrer->identity; 2698 /* Added neighbor, now send HELLO to transport */
2533 memcpy(&hello_context->distant_peer, peer, sizeof(struct GNUNET_PeerIdentity)); 2699 hello_context = GNUNET_malloc (sizeof (struct HelloContext));
2534 hello_context->addresses_to_add = 1; 2700 hello_context->direct_peer = &referrer->identity;
2535 hello_msg = GNUNET_HELLO_create(pkey, &generate_hello_address, hello_context); 2701 memcpy (&hello_context->distant_peer, peer,
2536 GNUNET_assert(memcmp(hello_context->direct_peer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)) != 0); 2702 sizeof (struct GNUNET_PeerIdentity));
2537 addr1 = GNUNET_strdup(GNUNET_i2s(hello_context->direct_peer)); 2703 hello_context->addresses_to_add = 1;
2538 addr2 = GNUNET_strdup(GNUNET_i2s(&hello_context->distant_peer)); 2704 hello_msg =
2705 GNUNET_HELLO_create (pkey, &generate_hello_address, hello_context);
2706 GNUNET_assert (memcmp
2707 (hello_context->direct_peer, &hello_context->distant_peer,
2708 sizeof (struct GNUNET_PeerIdentity)) != 0);
2709 addr1 = GNUNET_strdup (GNUNET_i2s (hello_context->direct_peer));
2710 addr2 = GNUNET_strdup (GNUNET_i2s (&hello_context->distant_peer));
2539#if DEBUG_DV 2711#if DEBUG_DV
2540 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: GIVING HELLO size %d for %s via %s to TRANSPORT\n", my_short_id, GNUNET_HELLO_size(hello_msg), addr2, addr1); 2712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2541#endif 2713 "%s: GIVING HELLO size %d for %s via %s to TRANSPORT\n",
2542 GNUNET_free(addr1); 2714 my_short_id, GNUNET_HELLO_size (hello_msg), addr2, addr1);
2543 GNUNET_free(addr2); 2715#endif
2544 send_to_plugin(hello_context->direct_peer, GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg), &hello_context->distant_peer, cost); 2716 GNUNET_free (addr1);
2545 GNUNET_free(hello_context); 2717 GNUNET_free (addr2);
2546 GNUNET_free(hello_msg); 2718 send_to_plugin (hello_context->direct_peer,
2547 } 2719 GNUNET_HELLO_get_header (hello_msg),
2548 2720 GNUNET_HELLO_size (hello_msg),
2721 &hello_context->distant_peer, cost);
2722 GNUNET_free (hello_context);
2723 GNUNET_free (hello_msg);
2549 } 2724 }
2725
2726 }
2550 else 2727 else
2551 { 2728 {
2552#if DEBUG_DV_GOSSIP 2729#if DEBUG_DV_GOSSIP
2553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2554 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv", GNUNET_i2s(peer), cost, referrer_peer_id); 2731 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv",
2732 GNUNET_i2s (peer), cost, referrer_peer_id);
2555#endif 2733#endif
2556 } 2734 }
2557#if DEBUG_DV 2735#if DEBUG_DV
2558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2559 "%s: Size of extended_neighbors is %d\n", "dv", GNUNET_CONTAINER_multihashmap_size(extended_neighbors)); 2737 "%s: Size of extended_neighbors is %d\n", "dv",
2738 GNUNET_CONTAINER_multihashmap_size (extended_neighbors));
2560#endif 2739#endif
2561 2740
2562 GNUNET_free(neighbor_update); 2741 GNUNET_free (neighbor_update);
2563 return neighbor; 2742 return neighbor;
2564} 2743}
2565 2744
@@ -2576,19 +2755,22 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
2576 * @param message the message 2755 * @param message the message
2577 * @param atsi performance data 2756 * @param atsi performance data
2578 */ 2757 */
2579static int handle_dv_disconnect_message (void *cls, 2758static int
2580 const struct GNUNET_PeerIdentity *peer, 2759handle_dv_disconnect_message (void *cls,
2581 const struct GNUNET_MessageHeader *message, 2760 const struct GNUNET_PeerIdentity *peer,
2582 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2761 const struct GNUNET_MessageHeader *message,
2762 const struct GNUNET_TRANSPORT_ATS_Information
2763 *atsi)
2583{ 2764{
2584 struct DirectNeighbor *referrer; 2765 struct DirectNeighbor *referrer;
2585 struct DistantNeighbor *distant; 2766 struct DistantNeighbor *distant;
2586 p2p_dv_MESSAGE_Disconnect *enc_message = (p2p_dv_MESSAGE_Disconnect *)message; 2767 p2p_dv_MESSAGE_Disconnect *enc_message =
2768 (p2p_dv_MESSAGE_Disconnect *) message;
2587 2769
2588 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_Disconnect)) 2770 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_Disconnect))
2589 { 2771 {
2590 return GNUNET_SYSERR; /* invalid message */ 2772 return GNUNET_SYSERR; /* invalid message */
2591 } 2773 }
2592 2774
2593 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, 2775 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
2594 &peer->hashPubKey); 2776 &peer->hashPubKey);
@@ -2597,15 +2779,15 @@ static int handle_dv_disconnect_message (void *cls,
2597 2779
2598 distant = referrer->referee_head; 2780 distant = referrer->referee_head;
2599 while (distant != NULL) 2781 while (distant != NULL)
2782 {
2783 if (distant->referrer_id == ntohl (enc_message->peer_id))
2600 { 2784 {
2601 if (distant->referrer_id == ntohl(enc_message->peer_id)) 2785 distant_neighbor_free (distant);
2602 { 2786 distant = referrer->referee_head;
2603 distant_neighbor_free(distant);
2604 distant = referrer->referee_head;
2605 }
2606 else
2607 distant = distant->next;
2608 } 2787 }
2788 else
2789 distant = distant->next;
2790 }
2609 2791
2610 return GNUNET_OK; 2792 return GNUNET_OK;
2611} 2793}
@@ -2623,30 +2805,33 @@ static int handle_dv_disconnect_message (void *cls,
2623 * @param message the message 2805 * @param message the message
2624 * @param atsi performance data 2806 * @param atsi performance data
2625 */ 2807 */
2626static int 2808static int
2627handle_dv_gossip_message (void *cls, 2809handle_dv_gossip_message (void *cls,
2628 const struct GNUNET_PeerIdentity *peer, 2810 const struct GNUNET_PeerIdentity *peer,
2629 const struct GNUNET_MessageHeader *message, 2811 const struct GNUNET_MessageHeader *message,
2630 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2812 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2631{ 2813{
2632 struct DirectNeighbor *referrer; 2814 struct DirectNeighbor *referrer;
2633 p2p_dv_MESSAGE_NeighborInfo *enc_message = (p2p_dv_MESSAGE_NeighborInfo *)message; 2815 p2p_dv_MESSAGE_NeighborInfo *enc_message =
2816 (p2p_dv_MESSAGE_NeighborInfo *) message;
2634 2817
2635 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo)) 2818 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo))
2636 { 2819 {
2637 return GNUNET_SYSERR; /* invalid message */ 2820 return GNUNET_SYSERR; /* invalid message */
2638 } 2821 }
2639 2822
2640#if DEBUG_DV_GOSSIP_RECEIPT 2823#if DEBUG_DV_GOSSIP_RECEIPT
2641 char * encPeerAbout; 2824 char *encPeerAbout;
2642 char * encPeerFrom; 2825 char *encPeerFrom;
2643 2826
2644 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&enc_message->neighbor)); 2827 encPeerAbout = GNUNET_strdup (GNUNET_i2s (&enc_message->neighbor));
2645 encPeerFrom = GNUNET_strdup(GNUNET_i2s(peer)); 2828 encPeerFrom = GNUNET_strdup (GNUNET_i2s (peer));
2646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2647 "%s: Received %s message from peer %s about peer %s id %u distance %d!\n", GNUNET_i2s(&my_identity), "DV GOSSIP", encPeerFrom, encPeerAbout, ntohl(enc_message->neighbor_id), ntohl (enc_message->cost) + 1); 2830 "%s: Received %s message from peer %s about peer %s id %u distance %d!\n",
2648 GNUNET_free(encPeerAbout); 2831 GNUNET_i2s (&my_identity), "DV GOSSIP", encPeerFrom, encPeerAbout,
2649 GNUNET_free(encPeerFrom); 2832 ntohl (enc_message->neighbor_id), ntohl (enc_message->cost) + 1);
2833 GNUNET_free (encPeerAbout);
2834 GNUNET_free (encPeerFrom);
2650#endif 2835#endif
2651 2836
2652 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, 2837 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
@@ -2673,29 +2858,29 @@ handle_dv_gossip_message (void *cls,
2673 * 2858 *
2674 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise 2859 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2675 */ 2860 */
2676static int 2861static int
2677add_all_extended_peers (void *cls, 2862add_all_extended_peers (void *cls, const GNUNET_HashCode * key, void *value)
2678 const GNUNET_HashCode * key,
2679 void *value)
2680{ 2863{
2681 struct NeighborSendContext *send_context = (struct NeighborSendContext *)cls; 2864 struct NeighborSendContext *send_context = (struct NeighborSendContext *) cls;
2682 struct DistantNeighbor *distant = (struct DistantNeighbor *)value; 2865 struct DistantNeighbor *distant = (struct DistantNeighbor *) value;
2683 struct FastGossipNeighborList *gossip_entry; 2866 struct FastGossipNeighborList *gossip_entry;
2684 2867
2685 if (memcmp(&send_context->toNeighbor->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2868 if (memcmp
2686 return GNUNET_YES; /* Don't gossip to a peer about itself! */ 2869 (&send_context->toNeighbor->identity, &distant->identity,
2870 sizeof (struct GNUNET_PeerIdentity)) == 0)
2871 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2687 2872
2688#if SUPPORT_HIDING 2873#if SUPPORT_HIDING
2689 if (distant->hidden == GNUNET_YES) 2874 if (distant->hidden == GNUNET_YES)
2690 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */ 2875 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2691#endif 2876#endif
2692 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList)); 2877 gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
2693 gossip_entry->about = distant; 2878 gossip_entry->about = distant;
2694 2879
2695 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head, 2880 GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
2696 send_context->fast_gossip_list_tail, 2881 send_context->fast_gossip_list_tail,
2697 send_context->fast_gossip_list_tail, 2882 send_context->fast_gossip_list_tail,
2698 gossip_entry); 2883 gossip_entry);
2699 2884
2700 return GNUNET_YES; 2885 return GNUNET_YES;
2701} 2886}
@@ -2711,19 +2896,21 @@ add_all_extended_peers (void *cls,
2711 * iterate, 2896 * iterate,
2712 * GNUNET_NO if not. 2897 * GNUNET_NO if not.
2713 */ 2898 */
2714static int 2899static int
2715gossip_all_to_all_iterator (void *cls, 2900gossip_all_to_all_iterator (void *cls,
2716 const GNUNET_HashCode * key, 2901 const GNUNET_HashCode * key, void *abs_value)
2717 void *abs_value)
2718{ 2902{
2719 struct DirectNeighbor *direct = abs_value; 2903 struct DirectNeighbor *direct = abs_value;
2720 2904
2721 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &add_all_extended_peers, direct->send_context); 2905 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
2906 &add_all_extended_peers,
2907 direct->send_context);
2722 2908
2723 if (direct->send_context->task != GNUNET_SCHEDULER_NO_TASK) 2909 if (direct->send_context->task != GNUNET_SCHEDULER_NO_TASK)
2724 GNUNET_SCHEDULER_cancel(direct->send_context->task); 2910 GNUNET_SCHEDULER_cancel (direct->send_context->task);
2725 2911
2726 direct->send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, direct->send_context); 2912 direct->send_context->task =
2913 GNUNET_SCHEDULER_add_now (&neighbor_send_task, direct->send_context);
2727 return GNUNET_YES; 2914 return GNUNET_YES;
2728} 2915}
2729 2916
@@ -2734,14 +2921,14 @@ gossip_all_to_all_iterator (void *cls,
2734 * @param tc unused 2921 * @param tc unused
2735 */ 2922 */
2736static void 2923static void
2737gossip_all_to_all (void *cls, 2924gossip_all_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2738 const struct GNUNET_SCHEDULER_TaskContext *tc)
2739{ 2925{
2740 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &gossip_all_to_all_iterator, NULL); 2926 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
2927 &gossip_all_to_all_iterator, NULL);
2741 2928
2742 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 2929 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2743 &gossip_all_to_all, 2930 (GNUNET_TIME_UNIT_SECONDS, 5),
2744 NULL); 2931 &gossip_all_to_all, NULL);
2745 2932
2746} 2933}
2747#endif 2934#endif
@@ -2756,50 +2943,55 @@ gossip_all_to_all (void *cls,
2756 * 2943 *
2757 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise 2944 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2758 */ 2945 */
2759static int 2946static int
2760add_all_direct_neighbors (void *cls, 2947add_all_direct_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2761 const GNUNET_HashCode * key,
2762 void *value)
2763{ 2948{
2764 struct DirectNeighbor *direct = (struct DirectNeighbor *)value; 2949 struct DirectNeighbor *direct = (struct DirectNeighbor *) value;
2765 struct DirectNeighbor *to = (struct DirectNeighbor *)cls; 2950 struct DirectNeighbor *to = (struct DirectNeighbor *) cls;
2766 struct DistantNeighbor *distant; 2951 struct DistantNeighbor *distant;
2767 struct NeighborSendContext *send_context = direct->send_context; 2952 struct NeighborSendContext *send_context = direct->send_context;
2768 struct FastGossipNeighborList *gossip_entry; 2953 struct FastGossipNeighborList *gossip_entry;
2769 char *direct_id; 2954 char *direct_id;
2770 2955
2771 2956
2772 distant = GNUNET_CONTAINER_multihashmap_get(extended_neighbors, &to->identity.hashPubKey); 2957 distant =
2958 GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
2959 &to->identity.hashPubKey);
2773 if (distant == NULL) 2960 if (distant == NULL)
2774 { 2961 {
2775 return GNUNET_YES; 2962 return GNUNET_YES;
2776 } 2963 }
2777 2964
2778 if (memcmp(&direct->identity, &to->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2965 if (memcmp
2779 { 2966 (&direct->identity, &to->identity,
2780 return GNUNET_YES; /* Don't gossip to a peer about itself! */ 2967 sizeof (struct GNUNET_PeerIdentity)) == 0)
2781 } 2968 {
2969 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2970 }
2782 2971
2783#if SUPPORT_HIDING 2972#if SUPPORT_HIDING
2784 if (distant->hidden == GNUNET_YES) 2973 if (distant->hidden == GNUNET_YES)
2785 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */ 2974 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2786#endif 2975#endif
2787 direct_id = GNUNET_strdup(GNUNET_i2s(&direct->identity)); 2976 direct_id = GNUNET_strdup (GNUNET_i2s (&direct->identity));
2788#if DEBUG_DV_GOSSIP 2977#if DEBUG_DV_GOSSIP
2789 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: adding peer %s to fast send list for %s\n", my_short_id, GNUNET_i2s(&distant->identity), direct_id); 2978 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2979 "%s: adding peer %s to fast send list for %s\n", my_short_id,
2980 GNUNET_i2s (&distant->identity), direct_id);
2790#endif 2981#endif
2791 GNUNET_free(direct_id); 2982 GNUNET_free (direct_id);
2792 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList)); 2983 gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
2793 gossip_entry->about = distant; 2984 gossip_entry->about = distant;
2794 2985
2795 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head, 2986 GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
2796 send_context->fast_gossip_list_tail, 2987 send_context->fast_gossip_list_tail,
2797 send_context->fast_gossip_list_tail, 2988 send_context->fast_gossip_list_tail,
2798 gossip_entry); 2989 gossip_entry);
2799 if (send_context->task != GNUNET_SCHEDULER_NO_TASK) 2990 if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2800 GNUNET_SCHEDULER_cancel(send_context->task); 2991 GNUNET_SCHEDULER_cancel (send_context->task);
2801 2992
2802 send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context); 2993 send_context->task =
2994 GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
2803 //tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT; 2995 //tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT;
2804 //neighbor_send_task(send_context, &tc); 2996 //neighbor_send_task(send_context, &tc);
2805 return GNUNET_YES; 2997 return GNUNET_YES;
@@ -2817,73 +3009,97 @@ add_all_direct_neighbors (void *cls,
2817static void 3009static void
2818process_peerinfo (void *cls, 3010process_peerinfo (void *cls,
2819 const struct GNUNET_PeerIdentity *peer, 3011 const struct GNUNET_PeerIdentity *peer,
2820 const struct GNUNET_HELLO_Message *hello, 3012 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
2821 const char *err_msg)
2822{ 3013{
2823 struct PeerIteratorContext *peerinfo_iterator = cls; 3014 struct PeerIteratorContext *peerinfo_iterator = cls;
2824 struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor; 3015 struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor;
2825 struct DistantNeighbor *distant = peerinfo_iterator->distant; 3016 struct DistantNeighbor *distant = peerinfo_iterator->distant;
3017
2826#if DEBUG_DV_PEER_NUMBERS 3018#if DEBUG_DV_PEER_NUMBERS
2827 char *neighbor_pid; 3019 char *neighbor_pid;
2828#endif 3020#endif
2829 int sent; 3021 int sent;
3022
2830 if (err_msg != NULL) 3023 if (err_msg != NULL)
2831 { 3024 {
2832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2833 _("Error in communication with PEERINFO service\n")); 3026 _("Error in communication with PEERINFO service\n"));
2834 /* return; */ 3027 /* return; */
2835 } 3028 }
2836 if (peer == NULL) 3029 if (peer == NULL)
3030 {
3031 if (distant->pkey == NULL)
2837 { 3032 {
2838 if (distant->pkey == NULL)
2839 {
2840#if DEBUG_DV 3033#if DEBUG_DV
2841 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to get peerinfo information for this peer, retrying!\n"); 3034 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2842#endif 3035 "Failed to get peerinfo information for this peer, retrying!\n");
2843 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate(peerinfo_handle, 3036#endif
2844 &peerinfo_iterator->neighbor->identity, 3037 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle,
2845 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3), 3038 &peerinfo_iterator->neighbor->
2846 &process_peerinfo, 3039 identity,
2847 peerinfo_iterator); 3040 GNUNET_TIME_relative_multiply
2848 } 3041 (GNUNET_TIME_UNIT_SECONDS,
2849 else 3042 3), &process_peerinfo,
2850 { 3043 peerinfo_iterator);
2851 GNUNET_free(peerinfo_iterator);
2852 }
2853 return;
2854 } 3044 }
3045 else
3046 {
3047 GNUNET_free (peerinfo_iterator);
3048 }
3049 return;
3050 }
2855 3051
2856 if (memcmp(&neighbor->identity, peer, sizeof(struct GNUNET_PeerIdentity) != 0)) 3052 if (memcmp
3053 (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity) != 0))
2857 return; 3054 return;
2858 3055
2859 if ((hello != NULL) && (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK)) 3056 if ((hello != NULL) &&
3057 (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK))
3058 {
3059 if (distant->pkey == NULL)
2860 { 3060 {
2861 if (distant->pkey == NULL) 3061 distant->pkey =
2862 { 3062 GNUNET_malloc (sizeof
2863 distant->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 3063 (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2864 memcpy(distant->pkey, &neighbor->pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 3064 memcpy (distant->pkey, &neighbor->pkey,
2865 } 3065 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
3066 }
2866 3067
2867 sent = GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &add_all_extended_peers, neighbor->send_context); 3068 sent =
2868 if (stats != NULL) 3069 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
2869 { 3070 &add_all_extended_peers,
2870 GNUNET_STATISTICS_update (stats, "# distant peers gossiped to direct neighbors", sent, GNUNET_NO); 3071 neighbor->send_context);
2871 } 3072 if (stats != NULL)
3073 {
3074 GNUNET_STATISTICS_update (stats,
3075 "# distant peers gossiped to direct neighbors",
3076 sent, GNUNET_NO);
3077 }
2872#if DEBUG_DV_PEER_NUMBERS 3078#if DEBUG_DV_PEER_NUMBERS
2873 neighbor_pid = GNUNET_strdup(GNUNET_i2s(&neighbor->identity)); 3079 neighbor_pid = GNUNET_strdup (GNUNET_i2s (&neighbor->identity));
2874 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped %d extended peers to %s\n", GNUNET_i2s(&my_identity), sent, neighbor_pid); 3080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2875#endif 3081 "%s: Gossipped %d extended peers to %s\n",
2876 sent = GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &add_all_direct_neighbors, neighbor); 3082 GNUNET_i2s (&my_identity), sent, neighbor_pid);
2877 if (stats != NULL) 3083#endif
2878 { 3084 sent =
2879 GNUNET_STATISTICS_update (stats, "# direct peers gossiped to direct neighbors", sent, GNUNET_NO); 3085 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
2880 } 3086 &add_all_direct_neighbors,
3087 neighbor);
3088 if (stats != NULL)
3089 {
3090 GNUNET_STATISTICS_update (stats,
3091 "# direct peers gossiped to direct neighbors",
3092 sent, GNUNET_NO);
3093 }
2881#if DEBUG_DV_PEER_NUMBERS 3094#if DEBUG_DV_PEER_NUMBERS
2882 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped about %s to %d direct peers\n", GNUNET_i2s(&my_identity), neighbor_pid, sent); 3095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2883 GNUNET_free(neighbor_pid); 3096 "%s: Gossipped about %s to %d direct peers\n",
3097 GNUNET_i2s (&my_identity), neighbor_pid, sent);
3098 GNUNET_free (neighbor_pid);
2884#endif 3099#endif
2885 neighbor->send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, neighbor->send_context); 3100 neighbor->send_context->task =
2886 } 3101 GNUNET_SCHEDULER_add_now (&neighbor_send_task, neighbor->send_context);
3102 }
2887} 3103}
2888 3104
2889 3105
@@ -2894,10 +3110,10 @@ process_peerinfo (void *cls,
2894 * @param peer peer identity this notification is about 3110 * @param peer peer identity this notification is about
2895 * @param atsi performance data 3111 * @param atsi performance data
2896 */ 3112 */
2897static void 3113static void
2898handle_core_connect (void *cls, 3114handle_core_connect (void *cls,
2899 const struct GNUNET_PeerIdentity * peer, 3115 const struct GNUNET_PeerIdentity *peer,
2900 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 3116 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2901{ 3117{
2902 struct DirectNeighbor *neighbor; 3118 struct DirectNeighbor *neighbor;
2903 struct DistantNeighbor *about; 3119 struct DistantNeighbor *about;
@@ -2907,54 +3123,69 @@ handle_core_connect (void *cls,
2907 uint32_t distance; 3123 uint32_t distance;
2908 3124
2909 /* Check for connect to self message */ 3125 /* Check for connect to self message */
2910 if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) 3126 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
2911 return; 3127 return;
2912 3128
2913 distance = get_atsi_distance (atsi); 3129 distance = get_atsi_distance (atsi);
2914 if ((distance == DIRECT_NEIGHBOR_COST) && 3130 if ((distance == DIRECT_NEIGHBOR_COST) &&
2915 (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL)) 3131 (GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey)
3132 == NULL))
2916 { 3133 {
2917 peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext)); 3134 peerinfo_iterator = GNUNET_malloc (sizeof (struct PeerIteratorContext));
2918 neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor)); 3135 neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor));
2919 neighbor->send_context = GNUNET_malloc(sizeof(struct NeighborSendContext)); 3136 neighbor->send_context =
3137 GNUNET_malloc (sizeof (struct NeighborSendContext));
2920 neighbor->send_context->toNeighbor = neighbor; 3138 neighbor->send_context->toNeighbor = neighbor;
2921 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); 3139 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2922 3140
2923 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put (direct_neighbors, 3141 GNUNET_assert (GNUNET_SYSERR !=
2924 &peer->hashPubKey, 3142 GNUNET_CONTAINER_multihashmap_put (direct_neighbors,
2925 neighbor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 3143 &peer->hashPubKey,
3144 neighbor,
3145 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2926 about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST); 3146 about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST);
2927 peerinfo_iterator->distant = about; 3147 peerinfo_iterator->distant = about;
2928 peerinfo_iterator->neighbor = neighbor; 3148 peerinfo_iterator->neighbor = neighbor;
2929 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle, 3149 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle,
2930 peer, 3150 peer,
2931 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3), 3151 GNUNET_TIME_relative_multiply
2932 &process_peerinfo, 3152 (GNUNET_TIME_UNIT_SECONDS,
3153 3), &process_peerinfo,
2933 peerinfo_iterator); 3154 peerinfo_iterator);
2934 3155
2935 if ((about != NULL) && (about->pkey == NULL)) 3156 if ((about != NULL) && (about->pkey == NULL))
2936 { 3157 {
2937#if DEBUG_DV 3158#if DEBUG_DV
2938 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Newly added peer %s has NULL pkey!\n", GNUNET_i2s(peer)); 3159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3160 "Newly added peer %s has NULL pkey!\n", GNUNET_i2s (peer));
2939#endif 3161#endif
2940 } 3162 }
2941 else if (about != NULL) 3163 else if (about != NULL)
2942 { 3164 {
2943 GNUNET_free(peerinfo_iterator); 3165 GNUNET_free (peerinfo_iterator);
2944 } 3166 }
2945 } 3167 }
2946 else 3168 else
2947 { 3169 {
2948 about = GNUNET_CONTAINER_multihashmap_get(extended_neighbors, &peer->hashPubKey); 3170 about =
2949 if ((GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL) && (about != NULL)) 3171 GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
2950 { 3172 &peer->hashPubKey);
2951 sent = GNUNET_CONTAINER_multihashmap_iterate(direct_neighbors, &add_distant_all_direct_neighbors, about); 3173 if ((GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey)
2952 if (stats != NULL) 3174 == NULL) && (about != NULL))
2953 GNUNET_STATISTICS_update (stats, "# direct peers gossiped to new direct neighbors", sent, GNUNET_NO); 3175 {
2954 } 3176 sent =
3177 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
3178 &add_distant_all_direct_neighbors,
3179 about);
3180 if (stats != NULL)
3181 GNUNET_STATISTICS_update (stats,
3182 "# direct peers gossiped to new direct neighbors",
3183 sent, GNUNET_NO);
3184 }
2955#if DEBUG_DV 3185#if DEBUG_DV
2956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2957 "%s: Distance (%d) greater than %d or already know about peer (%s), not re-adding!\n", "dv", distance, DIRECT_NEIGHBOR_COST, GNUNET_i2s(peer)); 3187 "%s: Distance (%d) greater than %d or already know about peer (%s), not re-adding!\n",
3188 "dv", distance, DIRECT_NEIGHBOR_COST, GNUNET_i2s (peer));
2958#endif 3189#endif
2959 return; 3190 return;
2960 } 3191 }
@@ -2966,8 +3197,8 @@ handle_core_connect (void *cls,
2966 * @param cls closure 3197 * @param cls closure
2967 * @param peer peer identity this notification is about 3198 * @param peer peer identity this notification is about
2968 */ 3199 */
2969void handle_core_disconnect (void *cls, 3200void
2970 const struct GNUNET_PeerIdentity * peer) 3201handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
2971{ 3202{
2972 struct DirectNeighbor *neighbor; 3203 struct DirectNeighbor *neighbor;
2973 struct DistantNeighbor *referee; 3204 struct DistantNeighbor *referee;
@@ -2981,28 +3212,31 @@ void handle_core_disconnect (void *cls,
2981#endif 3212#endif
2982 3213
2983 /* Check for disconnect from self message */ 3214 /* Check for disconnect from self message */
2984 if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) 3215 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
2985 return; 3216 return;
2986 3217
2987 neighbor = 3218 neighbor =
2988 GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey); 3219 GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
2989 3220
2990 if (neighbor == NULL) 3221 if (neighbor == NULL)
2991 { 3222 {
2992 return; 3223 return;
2993 } 3224 }
2994 3225
2995 pending_pos = core_pending_head; 3226 pending_pos = core_pending_head;
2996 while (NULL != pending_pos) 3227 while (NULL != pending_pos)
3228 {
3229 if (0 ==
3230 memcmp (&pending_pos->recipient, &neighbor->identity,
3231 sizeof (struct GNUNET_PeerIdentity)))
2997 { 3232 {
2998 if (0 == memcmp(&pending_pos->recipient, &neighbor->identity, sizeof(struct GNUNET_PeerIdentity))) 3233 GNUNET_CONTAINER_DLL_remove (core_pending_head, core_pending_tail,
2999 { 3234 pending_pos);
3000 GNUNET_CONTAINER_DLL_remove(core_pending_head, core_pending_tail, pending_pos); 3235 pending_pos = core_pending_head;
3001 pending_pos = core_pending_head;
3002 }
3003 else
3004 pending_pos = pending_pos->next;
3005 } 3236 }
3237 else
3238 pending_pos = pending_pos->next;
3239 }
3006 3240
3007 while (NULL != (referee = neighbor->referee_head)) 3241 while (NULL != (referee = neighbor->referee_head))
3008 distant_neighbor_free (referee); 3242 distant_neighbor_free (referee);
@@ -3010,24 +3244,28 @@ void handle_core_disconnect (void *cls,
3010 fdc.dest = NULL; 3244 fdc.dest = NULL;
3011 fdc.tid = 0; 3245 fdc.tid = 0;
3012 3246
3013 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &find_distant_peer, &fdc); 3247 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &find_distant_peer,
3248 &fdc);
3014 3249
3015 if (fdc.dest != NULL) 3250 if (fdc.dest != NULL)
3016 { 3251 {
3017 disconnect_context.direct = neighbor; 3252 disconnect_context.direct = neighbor;
3018 disconnect_context.distant = fdc.dest; 3253 disconnect_context.distant = fdc.dest;
3019 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &schedule_disconnect_messages, &disconnect_context); 3254 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
3020 } 3255 &schedule_disconnect_messages,
3256 &disconnect_context);
3257 }
3021 3258
3022 GNUNET_assert (neighbor->referee_tail == NULL); 3259 GNUNET_assert (neighbor->referee_tail == NULL);
3023 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors, 3260 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors,
3024 &peer->hashPubKey, neighbor)) 3261 &peer->hashPubKey,
3025 { 3262 neighbor))
3026 GNUNET_break(0); 3263 {
3027 } 3264 GNUNET_break (0);
3265 }
3028 if ((neighbor->send_context != NULL) && 3266 if ((neighbor->send_context != NULL) &&
3029 (neighbor->send_context->task != GNUNET_SCHEDULER_NO_TASK)) 3267 (neighbor->send_context->task != GNUNET_SCHEDULER_NO_TASK))
3030 GNUNET_SCHEDULER_cancel(neighbor->send_context->task); 3268 GNUNET_SCHEDULER_cancel (neighbor->send_context->task);
3031 GNUNET_free (neighbor); 3269 GNUNET_free (neighbor);
3032} 3270}
3033 3271
@@ -3045,6 +3283,7 @@ run (void *cls,
3045 const struct GNUNET_CONFIGURATION_Handle *c) 3283 const struct GNUNET_CONFIGURATION_Handle *c)
3046{ 3284{
3047 unsigned long long max_hosts; 3285 unsigned long long max_hosts;
3286
3048 cfg = c; 3287 cfg = c;
3049 3288
3050 /* FIXME: Read from config, or calculate, or something other than this! */ 3289 /* FIXME: Read from config, or calculate, or something other than this! */
@@ -3052,58 +3291,59 @@ run (void *cls,
3052 max_table_size = DEFAULT_DV_SIZE; 3291 max_table_size = DEFAULT_DV_SIZE;
3053 fisheye_depth = DEFAULT_FISHEYE_DEPTH; 3292 fisheye_depth = DEFAULT_FISHEYE_DEPTH;
3054 3293
3055 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "max_direct_connections")) 3294 if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "max_direct_connections"))
3056 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "max_direct_connections", &max_hosts)); 3295 GNUNET_assert (GNUNET_OK ==
3296 GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
3297 "max_direct_connections",
3298 &max_hosts));
3057 3299
3058 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "max_total_connections")) 3300 if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "max_total_connections"))
3059 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "max_total_connections", &max_table_size)); 3301 GNUNET_assert (GNUNET_OK ==
3302 GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
3303 "max_total_connections",
3304 &max_table_size));
3060 3305
3061 3306
3062 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "fisheye_depth")) 3307 if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "fisheye_depth"))
3063 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "fisheye_depth", &fisheye_depth)); 3308 GNUNET_assert (GNUNET_OK ==
3309 GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
3310 "fisheye_depth",
3311 &fisheye_depth));
3064 3312
3065 neighbor_min_heap = 3313 neighbor_min_heap =
3066 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 3314 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
3067 neighbor_max_heap = 3315 neighbor_max_heap =
3068 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); 3316 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
3069 3317
3070 direct_neighbors = GNUNET_CONTAINER_multihashmap_create (max_hosts); 3318 direct_neighbors = GNUNET_CONTAINER_multihashmap_create (max_hosts);
3071 extended_neighbors = 3319 extended_neighbors =
3072 GNUNET_CONTAINER_multihashmap_create (max_table_size * 3); 3320 GNUNET_CONTAINER_multihashmap_create (max_table_size * 3);
3073 3321
3074 GNUNET_SERVER_add_handlers (server, plugin_handlers); 3322 GNUNET_SERVER_add_handlers (server, plugin_handlers);
3075 coreAPI = 3323 coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to pass around? */
3076 GNUNET_CORE_connect (cfg, 3324 &core_init,
3077 1, 3325 &handle_core_connect,
3078 NULL, /* FIXME: anything we want to pass around? */ 3326 &handle_core_disconnect,
3079 &core_init, 3327 NULL,
3080 &handle_core_connect, 3328 NULL,
3081 &handle_core_disconnect, 3329 GNUNET_NO, NULL, GNUNET_NO, core_handlers);
3082 NULL,
3083 NULL,
3084 GNUNET_NO,
3085 NULL,
3086 GNUNET_NO,
3087 core_handlers);
3088 3330
3089 if (coreAPI == NULL) 3331 if (coreAPI == NULL)
3090 return; 3332 return;
3091 3333
3092 coreMST = GNUNET_SERVER_mst_create (&tokenized_message_handler, 3334 coreMST = GNUNET_SERVER_mst_create (&tokenized_message_handler, NULL);
3093 NULL);
3094 3335
3095 peerinfo_handle = GNUNET_PEERINFO_connect(cfg); 3336 peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
3096 3337
3097 if (peerinfo_handle == NULL) 3338 if (peerinfo_handle == NULL)
3098 { 3339 {
3099 GNUNET_CORE_disconnect(coreAPI); 3340 GNUNET_CORE_disconnect (coreAPI);
3100 return; 3341 return;
3101 } 3342 }
3102 3343
3103 /* Scheduled the task to clean up when shutdown is called */ 3344 /* Scheduled the task to clean up when shutdown is called */
3104 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 3345 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
3105 &shutdown_task, 3346 &shutdown_task, NULL);
3106 NULL);
3107} 3347}
3108 3348
3109 3349
@@ -3121,6 +3361,5 @@ main (int argc, char *const *argv)
3121 GNUNET_SERVICE_run (argc, 3361 GNUNET_SERVICE_run (argc,
3122 argv, 3362 argv,
3123 "dv", 3363 "dv",
3124 GNUNET_SERVICE_OPTION_NONE, 3364 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
3125 &run, NULL)) ? 0 : 1;
3126} 3365}
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index 697ca0c4c..2803e347e 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -144,38 +144,40 @@ struct Plugin
144/** 144/**
145 * Handler for messages received from the DV service. 145 * Handler for messages received from the DV service.
146 */ 146 */
147void handle_dv_message_received (void *cls, 147void
148 struct GNUNET_PeerIdentity *sender, 148handle_dv_message_received (void *cls,
149 char *msg, 149 struct GNUNET_PeerIdentity *sender,
150 size_t msg_len, 150 char *msg,
151 uint32_t distance, 151 size_t msg_len,
152 char *sender_address, 152 uint32_t distance,
153 size_t sender_address_len) 153 char *sender_address, size_t sender_address_len)
154{ 154{
155 struct Plugin *plugin = cls; 155 struct Plugin *plugin = cls;
156
156#if DEBUG_DV_MESSAGES 157#if DEBUG_DV_MESSAGES
157 char *my_id; 158 char *my_id;
158 my_id = GNUNET_strdup(GNUNET_i2s(plugin->env->my_identity)); 159
160 my_id = GNUNET_strdup (GNUNET_i2s (plugin->env->my_identity));
159 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
160 "plugin_transport_dv", 162 "plugin_transport_dv",
161 _("%s Received message from %s of type %d, distance %u!\n"), 163 _("%s Received message from %s of type %d, distance %u!\n"),
162 my_id, GNUNET_i2s(sender), ntohs(((struct GNUNET_MessageHeader *)msg)->type), distance); 164 my_id, GNUNET_i2s (sender),
163 GNUNET_free_non_null(my_id); 165 ntohs (((struct GNUNET_MessageHeader *) msg)->type),
166 distance);
167 GNUNET_free_non_null (my_id);
164#endif 168#endif
165 struct GNUNET_TRANSPORT_ATS_Information ats[2]; 169 struct GNUNET_TRANSPORT_ATS_Information ats[2];
170
166 ats[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 171 ats[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
167 ats[0].value = htonl (distance); 172 ats[0].value = htonl (distance);
168 ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 173 ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
169 ats[1].value = htonl (0); 174 ats[1].value = htonl (0);
170 175
171 plugin->env->receive(plugin->env->cls, 176 plugin->env->receive (plugin->env->cls,
172 sender, 177 sender,
173 (struct GNUNET_MessageHeader *)msg, 178 (struct GNUNET_MessageHeader *) msg,
174 (const struct GNUNET_TRANSPORT_ATS_Information *) &ats, 179 (const struct GNUNET_TRANSPORT_ATS_Information *) &ats,
175 2, 180 2, NULL, sender_address, sender_address_len);
176 NULL,
177 sender_address,
178 sender_address_len);
179 181
180} 182}
181 183
@@ -218,26 +220,20 @@ dv_plugin_send (void *cls,
218 size_t msgbuf_size, 220 size_t msgbuf_size,
219 unsigned int priority, 221 unsigned int priority,
220 struct GNUNET_TIME_Relative timeout, 222 struct GNUNET_TIME_Relative timeout,
221 struct Session *session, 223 struct Session *session,
222 const void *addr, 224 const void *addr,
223 size_t addrlen, 225 size_t addrlen,
224 int force_address, 226 int force_address,
225 GNUNET_TRANSPORT_TransmitContinuation 227 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
226 cont, void *cont_cls)
227{ 228{
228 int ret = 0; 229 int ret = 0;
229 struct Plugin *plugin = cls; 230 struct Plugin *plugin = cls;
230 231
231 ret = GNUNET_DV_send(plugin->dv_handle, 232 ret = GNUNET_DV_send (plugin->dv_handle,
232 target, 233 target,
233 msgbuf, 234 msgbuf,
234 msgbuf_size, 235 msgbuf_size,
235 priority, 236 priority, timeout, addr, addrlen, cont, cont_cls);
236 timeout,
237 addr,
238 addrlen,
239 cont,
240 cont_cls);
241 return ret; 237 return ret;
242} 238}
243 239
@@ -252,8 +248,7 @@ dv_plugin_send (void *cls,
252 * @param target peer from which to disconnect 248 * @param target peer from which to disconnect
253 */ 249 */
254static void 250static void
255dv_plugin_disconnect (void *cls, 251dv_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
256 const struct GNUNET_PeerIdentity *target)
257{ 252{
258 // struct Plugin *plugin = cls; 253 // struct Plugin *plugin = cls;
259 // TODO: Add message type to send to dv service to "disconnect" a peer 254 // TODO: Add message type to send to dv service to "disconnect" a peer
@@ -287,23 +282,28 @@ dv_plugin_address_pretty_printer (void *cls,
287 char *dest_peer; 282 char *dest_peer;
288 char *via_peer; 283 char *via_peer;
289 char *print_string; 284 char *print_string;
290 char *addr_buf = (char *)addr; 285 char *addr_buf = (char *) addr;
291 286
292 if (addrlen != sizeof(struct GNUNET_PeerIdentity) * 2) 287 if (addrlen != sizeof (struct GNUNET_PeerIdentity) * 2)
293 { 288 {
294 asc (asc_cls, NULL); 289 asc (asc_cls, NULL);
295 } 290 }
296 else 291 else
297 { 292 {
298 dest_peer = GNUNET_strdup(GNUNET_i2s((struct GNUNET_PeerIdentity *)addr)); 293 dest_peer =
299 via_peer = GNUNET_strdup(GNUNET_i2s((struct GNUNET_PeerIdentity *)&addr_buf[sizeof(struct GNUNET_PeerIdentity)])); 294 GNUNET_strdup (GNUNET_i2s ((struct GNUNET_PeerIdentity *) addr));
300 GNUNET_asprintf(&print_string, "DV Peer `%s' via peer`%s'", dest_peer, via_peer); 295 via_peer =
301 asc (asc_cls, print_string); 296 GNUNET_strdup (GNUNET_i2s
302 asc (asc_cls, NULL); 297 ((struct GNUNET_PeerIdentity *)
303 GNUNET_free(via_peer); 298 &addr_buf[sizeof (struct GNUNET_PeerIdentity)]));
304 GNUNET_free(dest_peer); 299 GNUNET_asprintf (&print_string, "DV Peer `%s' via peer`%s'", dest_peer,
305 GNUNET_free(print_string); 300 via_peer);
306 } 301 asc (asc_cls, print_string);
302 asc (asc_cls, NULL);
303 GNUNET_free (via_peer);
304 GNUNET_free (dest_peer);
305 GNUNET_free (print_string);
306 }
307} 307}
308 308
309/** 309/**
@@ -315,9 +315,8 @@ dv_plugin_address_pretty_printer (void *cls,
315 * 315 *
316 * @return string representing the DV address 316 * @return string representing the DV address
317 */ 317 */
318static const char *address_to_string (void *cls, 318static const char *
319 const void *addr, 319address_to_string (void *cls, const void *addr, size_t addrlen)
320 size_t addrlen)
321{ 320{
322 static char return_buffer[2 * 4 + 2]; // Two four character peer identity prefixes a ':' and '\0' 321 static char return_buffer[2 * 4 + 2]; // Two four character peer identity prefixes a ':' and '\0'
323 322
@@ -325,23 +324,22 @@ static const char *address_to_string (void *cls,
325 struct GNUNET_CRYPTO_HashAsciiEncoded via_hash; 324 struct GNUNET_CRYPTO_HashAsciiEncoded via_hash;
326 struct GNUNET_PeerIdentity *peer; 325 struct GNUNET_PeerIdentity *peer;
327 struct GNUNET_PeerIdentity *via; 326 struct GNUNET_PeerIdentity *via;
328 char *addr_buf = (char *)addr; 327 char *addr_buf = (char *) addr;
329 328
330 if (addrlen == (2 * sizeof(struct GNUNET_PeerIdentity))) 329 if (addrlen == (2 * sizeof (struct GNUNET_PeerIdentity)))
331 { 330 {
332 peer = (struct GNUNET_PeerIdentity *)addr_buf; 331 peer = (struct GNUNET_PeerIdentity *) addr_buf;
333 via = (struct GNUNET_PeerIdentity *)&addr_buf[sizeof(struct GNUNET_PeerIdentity)]; 332 via =
334 333 (struct GNUNET_PeerIdentity *)
335 GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &peer_hash); 334 &addr_buf[sizeof (struct GNUNET_PeerIdentity)];
336 peer_hash.encoding[4] = '\0'; 335
337 GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash); 336 GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &peer_hash);
338 via_hash.encoding[4] = '\0'; 337 peer_hash.encoding[4] = '\0';
339 GNUNET_snprintf (return_buffer, 338 GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash);
340 sizeof (return_buffer), 339 via_hash.encoding[4] = '\0';
341 "%s:%s", 340 GNUNET_snprintf (return_buffer,
342 &peer_hash, 341 sizeof (return_buffer), "%s:%s", &peer_hash, &via_hash);
343 &via_hash); 342 }
344 }
345 else 343 else
346 return NULL; 344 return NULL;
347 345
@@ -365,17 +363,23 @@ static const char *address_to_string (void *cls,
365 * 363 *
366 */ 364 */
367static int 365static int
368dv_plugin_check_address (void *cls, 366dv_plugin_check_address (void *cls, const void *addr, size_t addrlen)
369 const void *addr, size_t addrlen)
370{ 367{
371 struct Plugin *plugin = cls; 368 struct Plugin *plugin = cls;
369
372 /* Verify that the first peer of this address matches our peer id! */ 370 /* Verify that the first peer of this address matches our peer id! */
373 if ((addrlen != (2 * sizeof(struct GNUNET_PeerIdentity))) || (0 != memcmp(addr, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)))) 371 if ((addrlen != (2 * sizeof (struct GNUNET_PeerIdentity))) ||
372 (0 !=
373 memcmp (addr, plugin->env->my_identity,
374 sizeof (struct GNUNET_PeerIdentity))))
374 { 375 {
375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Address not correct size or identity doesn't match ours!\n", GNUNET_i2s(plugin->env->my_identity)); 376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 if (addrlen == (2 * sizeof(struct GNUNET_PeerIdentity))) 377 "%s: Address not correct size or identity doesn't match ours!\n",
378 GNUNET_i2s (plugin->env->my_identity));
379 if (addrlen == (2 * sizeof (struct GNUNET_PeerIdentity)))
377 { 380 {
378 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer in address is %s\n", GNUNET_i2s(addr)); 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer in address is %s\n",
382 GNUNET_i2s (addr));
379 } 383 }
380 return GNUNET_SYSERR; 384 return GNUNET_SYSERR;
381 } 385 }
@@ -396,11 +400,12 @@ libgnunet_plugin_transport_dv_init (void *cls)
396 plugin = GNUNET_malloc (sizeof (struct Plugin)); 400 plugin = GNUNET_malloc (sizeof (struct Plugin));
397 plugin->env = env; 401 plugin->env = env;
398 402
399 plugin->dv_handle = GNUNET_DV_connect(env->cfg, &handle_dv_message_received, plugin); 403 plugin->dv_handle =
404 GNUNET_DV_connect (env->cfg, &handle_dv_message_received, plugin);
400 405
401 if (plugin->dv_handle == NULL) 406 if (plugin->dv_handle == NULL)
402 { 407 {
403 GNUNET_free(plugin); 408 GNUNET_free (plugin);
404 return NULL; 409 return NULL;
405 } 410 }
406 411
@@ -425,7 +430,7 @@ libgnunet_plugin_transport_dv_done (void *cls)
425 struct Plugin *plugin = api->cls; 430 struct Plugin *plugin = api->cls;
426 431
427 if (plugin->dv_handle != NULL) 432 if (plugin->dv_handle != NULL)
428 GNUNET_DV_disconnect(plugin->dv_handle); 433 GNUNET_DV_disconnect (plugin->dv_handle);
429 434
430 GNUNET_free (plugin); 435 GNUNET_free (plugin);
431 GNUNET_free (api); 436 GNUNET_free (api);
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c
index 8b42c4311..5d9d367e1 100644
--- a/src/dv/test_transport_api_dv.c
+++ b/src/dv/test_transport_api_dv.c
@@ -93,11 +93,12 @@ static int transmit_ready_called;
93 93
94static enum GNUNET_TESTING_Topology topology; 94static enum GNUNET_TESTING_Topology topology;
95 95
96static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */ 96static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
97 97
98static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */ 98static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
99 99
100static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; 100static enum GNUNET_TESTING_TopologyOption connect_topology_option =
101 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
101 102
102static double connect_topology_option_modifier = 0.0; 103static double connect_topology_option_modifier = 0.0;
103 104
@@ -167,25 +168,23 @@ static struct TestMessageContext *other_test_messages;
167/** 168/**
168 * Check whether peers successfully shut down. 169 * Check whether peers successfully shut down.
169 */ 170 */
170void shutdown_callback (void *cls, 171void
171 const char *emsg) 172shutdown_callback (void *cls, const char *emsg)
172{ 173{
173 if (emsg != NULL) 174 if (emsg != NULL)
174 { 175 {
175#if VERBOSE 176#if VERBOSE
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
177 "Shutdown of peers failed!\n");
178#endif 178#endif
179 if (ok == 0) 179 if (ok == 0)
180 ok = 666; 180 ok = 666;
181 } 181 }
182 else 182 else
183 { 183 {
184#if VERBOSE 184#if VERBOSE
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
186 "All peers successfully shut down!\n");
187#endif 186#endif
188 } 187 }
189} 188}
190 189
191static void 190static void
@@ -203,100 +202,102 @@ finish_testing ()
203#endif 202#endif
204 peer_pos = all_peers; 203 peer_pos = all_peers;
205 while (peer_pos != NULL) 204 while (peer_pos != NULL)
206 { 205 {
207 if (peer_pos->peer_handle != NULL) 206 if (peer_pos->peer_handle != NULL)
208 GNUNET_CORE_disconnect(peer_pos->peer_handle); 207 GNUNET_CORE_disconnect (peer_pos->peer_handle);
209 free_peer_pos = peer_pos; 208 free_peer_pos = peer_pos;
210 peer_pos = peer_pos->next; 209 peer_pos = peer_pos->next;
211 GNUNET_free(free_peer_pos); 210 GNUNET_free (free_peer_pos);
212 } 211 }
213 all_peers = NULL; 212 all_peers = NULL;
214 213
215 pos = test_messages; 214 pos = test_messages;
216 while (pos != NULL) 215 while (pos != NULL)
216 {
217 if (pos->peer1handle != NULL)
217 { 218 {
218 if (pos->peer1handle != NULL) 219 GNUNET_CORE_disconnect (pos->peer1handle);
219 { 220 pos->peer1handle = NULL;
220 GNUNET_CORE_disconnect(pos->peer1handle);
221 pos->peer1handle = NULL;
222 }
223 if (pos->peer2handle != NULL)
224 {
225 GNUNET_CORE_disconnect(pos->peer2handle);
226 pos->peer2handle = NULL;
227 }
228 free_pos = pos;
229 pos = pos->next;
230 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
231 {
232 GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
233 }
234 GNUNET_free(free_pos);
235 } 221 }
222 if (pos->peer2handle != NULL)
223 {
224 GNUNET_CORE_disconnect (pos->peer2handle);
225 pos->peer2handle = NULL;
226 }
227 free_pos = pos;
228 pos = pos->next;
229 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
230 {
231 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
232 }
233 GNUNET_free (free_pos);
234 }
236 235
237 pos = other_test_messages; 236 pos = other_test_messages;
238 while (pos != NULL) 237 while (pos != NULL)
238 {
239 if (pos->peer1handle != NULL)
240 {
241 GNUNET_CORE_disconnect (pos->peer1handle);
242 pos->peer1handle = NULL;
243 }
244 if (pos->peer2handle != NULL)
245 {
246 GNUNET_CORE_disconnect (pos->peer2handle);
247 pos->peer2handle = NULL;
248 }
249 free_pos = pos;
250 pos = pos->next;
251 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
239 { 252 {
240 if (pos->peer1handle != NULL) 253 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
241 {
242 GNUNET_CORE_disconnect(pos->peer1handle);
243 pos->peer1handle = NULL;
244 }
245 if (pos->peer2handle != NULL)
246 {
247 GNUNET_CORE_disconnect(pos->peer2handle);
248 pos->peer2handle = NULL;
249 }
250 free_pos = pos;
251 pos = pos->next;
252 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
253 {
254 GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
255 }
256 GNUNET_free(free_pos);
257 } 254 }
255 GNUNET_free (free_pos);
256 }
258#if VERBOSE 257#if VERBOSE
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called); 259 "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
260 transmit_ready_scheduled, transmit_ready_failed,
261 transmit_ready_called);
261#endif 262#endif
262 263
263#if VERBOSE 264#if VERBOSE
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
265 "Calling daemons_stop\n");
266#endif 266#endif
267 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 267 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
268#if VERBOSE 268#if VERBOSE
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n");
270 "daemons_stop finished\n");
271#endif 270#endif
272 if (dotOutFile != NULL) 271 if (dotOutFile != NULL)
273 { 272 {
274 fprintf(dotOutFile, "}"); 273 fprintf (dotOutFile, "}");
275 fclose(dotOutFile); 274 fclose (dotOutFile);
276 } 275 }
277 276
278 ok = 0; 277 ok = 0;
279} 278}
280 279
281 280
282static void 281static void
283disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 282disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
284{ 283{
285 struct TestMessageContext *pos = cls; 284 struct TestMessageContext *pos = cls;
286 285
287 /* Disconnect from the respective cores */ 286 /* Disconnect from the respective cores */
288#if VERBOSE 287#if VERBOSE
289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
290 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id)); 289 "Disconnecting from peer 1 `%4s'\n",
290 GNUNET_i2s (&pos->peer1->id));
291#endif 291#endif
292 if (pos->peer1handle != NULL) 292 if (pos->peer1handle != NULL)
293 GNUNET_CORE_disconnect(pos->peer1handle); 293 GNUNET_CORE_disconnect (pos->peer1handle);
294#if VERBOSE 294#if VERBOSE
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
296 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id)); 296 "Disconnecting from peer 2 `%4s'\n",
297 GNUNET_i2s (&pos->peer2->id));
297#endif 298#endif
298 if (pos->peer2handle != NULL) 299 if (pos->peer2handle != NULL)
299 GNUNET_CORE_disconnect(pos->peer2handle); 300 GNUNET_CORE_disconnect (pos->peer2handle);
300 /* Set handles to NULL so test case can be ended properly */ 301 /* Set handles to NULL so test case can be ended properly */
301 pos->peer1handle = NULL; 302 pos->peer1handle = NULL;
302 pos->peer2handle = NULL; 303 pos->peer2handle = NULL;
@@ -306,84 +307,85 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
306} 307}
307 308
308static void 309static void
309end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 310end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
310{ 311{
311 char *msg = cls; 312 char *msg = cls;
313
312 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 314 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
313 "End badly was called (%s)... stopping daemons.\n", msg); 315 "End badly was called (%s)... stopping daemons.\n", msg);
314 struct TestMessageContext *pos; 316 struct TestMessageContext *pos;
315 struct TestMessageContext *free_pos; 317 struct TestMessageContext *free_pos;
316 struct PeerContext * peer_pos; 318 struct PeerContext *peer_pos;
317 struct PeerContext * free_peer_pos; 319 struct PeerContext *free_peer_pos;
318 320
319 peer_pos = all_peers; 321 peer_pos = all_peers;
320 while (peer_pos != NULL) 322 while (peer_pos != NULL)
321 { 323 {
322 if (peer_pos->peer_handle != NULL) 324 if (peer_pos->peer_handle != NULL)
323 GNUNET_CORE_disconnect(peer_pos->peer_handle); 325 GNUNET_CORE_disconnect (peer_pos->peer_handle);
324 free_peer_pos = peer_pos; 326 free_peer_pos = peer_pos;
325 peer_pos = peer_pos->next; 327 peer_pos = peer_pos->next;
326 GNUNET_free(free_peer_pos); 328 GNUNET_free (free_peer_pos);
327 } 329 }
328 all_peers = NULL; 330 all_peers = NULL;
329 331
330 pos = test_messages; 332 pos = test_messages;
331 while (pos != NULL) 333 while (pos != NULL)
334 {
335 if (pos->peer1handle != NULL)
332 { 336 {
333 if (pos->peer1handle != NULL) 337 GNUNET_CORE_disconnect (pos->peer1handle);
334 { 338 pos->peer1handle = NULL;
335 GNUNET_CORE_disconnect(pos->peer1handle);
336 pos->peer1handle = NULL;
337 }
338 if (pos->peer2handle != NULL)
339 {
340 GNUNET_CORE_disconnect(pos->peer2handle);
341 pos->peer2handle = NULL;
342 }
343 free_pos = pos;
344 pos = pos->next;
345 GNUNET_free(free_pos);
346 } 339 }
340 if (pos->peer2handle != NULL)
341 {
342 GNUNET_CORE_disconnect (pos->peer2handle);
343 pos->peer2handle = NULL;
344 }
345 free_pos = pos;
346 pos = pos->next;
347 GNUNET_free (free_pos);
348 }
347 349
348 pos = other_test_messages; 350 pos = other_test_messages;
349 while (pos != NULL) 351 while (pos != NULL)
352 {
353 if (pos->peer1handle != NULL)
350 { 354 {
351 if (pos->peer1handle != NULL) 355 GNUNET_CORE_disconnect (pos->peer1handle);
352 { 356 pos->peer1handle = NULL;
353 GNUNET_CORE_disconnect(pos->peer1handle);
354 pos->peer1handle = NULL;
355 }
356 if (pos->peer2handle != NULL)
357 {
358 GNUNET_CORE_disconnect(pos->peer2handle);
359 pos->peer2handle = NULL;
360 }
361 free_pos = pos;
362 pos = pos->next;
363 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
364 {
365 GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
366 }
367 GNUNET_free(free_pos);
368 } 357 }
369 358 if (pos->peer2handle != NULL)
370 if (pg != NULL) 359 {
360 GNUNET_CORE_disconnect (pos->peer2handle);
361 pos->peer2handle = NULL;
362 }
363 free_pos = pos;
364 pos = pos->next;
365 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
371 { 366 {
372 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 367 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
373 ok = 7331; /* Opposite of leet */
374 } 368 }
369 GNUNET_free (free_pos);
370 }
371
372 if (pg != NULL)
373 {
374 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
375 ok = 7331; /* Opposite of leet */
376 }
375 else 377 else
376 ok = 401; /* Never got peers started */ 378 ok = 401; /* Never got peers started */
377 379
378 if (dotOutFile != NULL) 380 if (dotOutFile != NULL)
379 { 381 {
380 fprintf(dotOutFile, "}"); 382 fprintf (dotOutFile, "}");
381 fclose(dotOutFile); 383 fclose (dotOutFile);
382 } 384 }
383} 385}
384 386
385static void 387static void
386send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); 388send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
387 389
388/** 390/**
389 * Get distance information from 'atsi'. 391 * Get distance information from 'atsi'.
@@ -394,15 +396,15 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
394static uint32_t 396static uint32_t
395get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi) 397get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
396{ 398{
397 while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && 399 while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
398 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) ) 400 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE))
399 atsi++; 401 atsi++;
400 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) 402 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
401 { 403 {
402 GNUNET_break (0); 404 GNUNET_break (0);
403 /* FIXME: we do not have distance data? Assume direct neighbor. */ 405 /* FIXME: we do not have distance data? Assume direct neighbor. */
404 return 1; 406 return 1;
405 } 407 }
406 return ntohl (atsi->value); 408 return ntohl (atsi->value);
407} 409}
408 410
@@ -413,62 +415,74 @@ process_mtype (void *cls,
413 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 415 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
414{ 416{
415 struct TestMessageContext *pos = cls; 417 struct TestMessageContext *pos = cls;
416 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message; 418 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
419
417#if VERBOSE 420#if VERBOSE
418 uint32_t distance; 421 uint32_t distance;
419#endif 422#endif
420 if (pos->uid != ntohl(msg->uid)) 423 if (pos->uid != ntohl (msg->uid))
421 return GNUNET_OK; 424 return GNUNET_OK;
422 425
423#if VERBOSE 426#if VERBOSE
424 distance = get_atsi_distance(atsi); 427 distance = get_atsi_distance (atsi);
425#endif 428#endif
426 GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity))); 429 GNUNET_assert (0 ==
430 memcmp (peer, &pos->peer1->id,
431 sizeof (struct GNUNET_PeerIdentity)));
427 if (total_other_expected_messages == 0) 432 if (total_other_expected_messages == 0)
428 { 433 {
429 total_messages_received++; 434 total_messages_received++;
430#if VERBOSE 435#if VERBOSE
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
432 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); 437 "Received message from `%4s', type %d, uid %u, distance %u.\n",
433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 438 GNUNET_i2s (peer), ntohs (message->type), ntohl (msg->uid),
434 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); 439 distance);
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "Total messages received %d, expected %d.\n",
442 total_messages_received, expected_messages);
435#endif 443#endif
436 } 444 }
437 else 445 else
438 { 446 {
439 total_other_messages++; 447 total_other_messages++;
440#if VERBOSE 448#if VERBOSE
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); 450 "Received message from `%4s', type %d, uid %u, distance %u.\n",
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 451 GNUNET_i2s (peer), ntohs (message->type), ntohl (msg->uid),
444 "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages); 452 distance);
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
454 "Total messages received %d, expected %d.\n",
455 total_other_messages, total_other_expected_messages);
445#endif 456#endif
446 } 457 }
447 458
448 if ((total_messages_received == expected_messages) && (total_other_messages == 0)) 459 if ((total_messages_received == expected_messages) &&
449 { 460 (total_other_messages == 0))
450 GNUNET_SCHEDULER_cancel (die_task); 461 {
451 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 462 GNUNET_SCHEDULER_cancel (die_task);
452 &end_badly, "waiting for DV peers to connect!"); 463 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
453 /* 464 &end_badly,
454 if ((num_peers == 3) && (total_other_expected_messages == 2)) 465 "waiting for DV peers to connect!");
455 { 466 /*
456 GNUNET_SCHEDULER_add_now (&send_other_messages, NULL); 467 * if ((num_peers == 3) && (total_other_expected_messages == 2))
457 } 468 * {
458 else 469 * GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
459 { 470 * }
460 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL); 471 * else
461 }*/ 472 * {
462 } 473 * GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
463 else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages)) 474 * } */
464 { 475 }
465 GNUNET_SCHEDULER_cancel (die_task); 476 else if ((total_other_expected_messages > 0) &&
466 GNUNET_SCHEDULER_add_now (&finish_testing, NULL); 477 (total_other_messages == total_other_expected_messages))
467 } 478 {
479 GNUNET_SCHEDULER_cancel (die_task);
480 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
481 }
468 else 482 else
469 { 483 {
470 pos->disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cores, pos); 484 pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
471 } 485 }
472 486
473 return GNUNET_OK; 487 return GNUNET_OK;
474} 488}
@@ -483,11 +497,13 @@ transmit_ready (void *cls, size_t size, void *buf)
483 m = (struct GNUNET_TestMessage *) buf; 497 m = (struct GNUNET_TestMessage *) buf;
484 m->header.type = htons (MTYPE); 498 m->header.type = htons (MTYPE);
485 m->header.size = htons (sizeof (struct GNUNET_TestMessage)); 499 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
486 m->uid = htonl(pos->uid); 500 m->uid = htonl (pos->uid);
487 transmit_ready_called++; 501 transmit_ready_called++;
488#if VERBOSE 502#if VERBOSE
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id), transmit_ready_scheduled, transmit_ready_called); 504 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
505 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
506 transmit_ready_called);
491#endif 507#endif
492 return sizeof (struct GNUNET_TestMessage); 508 return sizeof (struct GNUNET_TestMessage);
493} 509}
@@ -510,47 +526,50 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
510 * @param peer peer identity this notification is about 526 * @param peer peer identity this notification is about
511 * @param atsi performance data for the connection 527 * @param atsi performance data for the connection
512 */ 528 */
513static void connect_notify_peer2 (void *cls, 529static void
514 const struct 530connect_notify_peer2 (void *cls,
515 GNUNET_PeerIdentity *peer, 531 const struct
516 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 532 GNUNET_PeerIdentity *peer,
533 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
517{ 534{
518 struct TestMessageContext *pos = cls; 535 struct TestMessageContext *pos = cls;
519 536
520 if (0 == memcmp(&pos->peer1->id, peer, sizeof(struct GNUNET_PeerIdentity))) 537 if (0 == memcmp (&pos->peer1->id, peer, sizeof (struct GNUNET_PeerIdentity)))
521 { 538 {
522#if VERBOSE 539#if VERBOSE
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
524 "Core connection from `%s' to `%4s' verfied, sending message!\n", 541 "Core connection from `%s' to `%4s' verfied, sending message!\n",
525 GNUNET_i2s(&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey)); 542 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey));
526#endif 543#endif
527 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 544 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
528 GNUNET_YES, 545 GNUNET_YES,
529 0, 546 0,
530 TIMEOUT, 547 TIMEOUT,
531 &pos->peer2->id, 548 &pos->peer2->id,
532 sizeof (struct GNUNET_TestMessage), 549 sizeof (struct
533 &transmit_ready, pos)) 550 GNUNET_TestMessage),
534 { 551 &transmit_ready, pos))
535 /* This probably shouldn't happen, but it does (timing issue?) */ 552 {
536 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 553 /* This probably shouldn't happen, but it does (timing issue?) */
537 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", 554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
538 GNUNET_i2s (&pos->peer2->id)); 555 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
539 transmit_ready_failed++; 556 GNUNET_i2s (&pos->peer2->id));
540 total_other_expected_messages--; 557 transmit_ready_failed++;
541 } 558 total_other_expected_messages--;
542 else
543 {
544 transmit_ready_scheduled++;
545 }
546 } 559 }
560 else
561 {
562 transmit_ready_scheduled++;
563 }
564 }
547} 565}
548 566
549static void 567static void
550init_notify_peer2 (void *cls, 568init_notify_peer2 (void *cls,
551 struct GNUNET_CORE_Handle *server, 569 struct GNUNET_CORE_Handle *server,
552 const struct GNUNET_PeerIdentity *my_identity, 570 const struct GNUNET_PeerIdentity *my_identity,
553 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 571 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
572 *publicKey)
554{ 573{
555#if VERBOSE 574#if VERBOSE
556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -568,39 +587,42 @@ init_notify_peer2 (void *cls,
568 * @param peer peer identity this notification is about 587 * @param peer peer identity this notification is about
569 * @param atsi performance data for the connection 588 * @param atsi performance data for the connection
570 */ 589 */
571static void connect_notify_peer1 (void *cls, 590static void
572 const struct 591connect_notify_peer1 (void *cls,
573 GNUNET_PeerIdentity *peer, 592 const struct
574 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 593 GNUNET_PeerIdentity *peer,
594 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
575{ 595{
576 struct TestMessageContext *pos = cls; 596 struct TestMessageContext *pos = cls;
577 597
578 if (0 == memcmp(&pos->peer2->id, peer, sizeof(struct GNUNET_PeerIdentity))) 598 if (0 == memcmp (&pos->peer2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
579 { 599 {
580#if VERBOSE 600#if VERBOSE
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
582 "Core connection from `%s' to `%4s' verified.\n", 602 "Core connection from `%s' to `%4s' verified.\n",
583 GNUNET_i2s(&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey)); 603 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
584#endif 604#endif
585 /* 605 /*
586 * Connect to the receiving peer 606 * Connect to the receiving peer
587 */ 607 */
588 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, 608 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
589 1, 609 1,
590 pos, 610 pos,
591 &init_notify_peer2, 611 &init_notify_peer2,
592 &connect_notify_peer2, 612 &connect_notify_peer2,
593 NULL, 613 NULL,
594 NULL, NULL, 614 NULL, NULL,
595 GNUNET_YES, NULL, GNUNET_YES, handlers); 615 GNUNET_YES, NULL, GNUNET_YES,
596 } 616 handlers);
617 }
597} 618}
598 619
599static void 620static void
600init_notify_peer1 (void *cls, 621init_notify_peer1 (void *cls,
601 struct GNUNET_CORE_Handle *server, 622 struct GNUNET_CORE_Handle *server,
602 const struct GNUNET_PeerIdentity *my_identity, 623 const struct GNUNET_PeerIdentity *my_identity,
603 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 624 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
625 *publicKey)
604{ 626{
605 total_server_connections++; 627 total_server_connections++;
606#if VERBOSE 628#if VERBOSE
@@ -612,129 +634,142 @@ init_notify_peer1 (void *cls,
612 634
613 635
614static void 636static void
615send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 637send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
616{ 638{
617 struct TestMessageContext *pos = cls; 639 struct TestMessageContext *pos = cls;
618 640
619 if (( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL)) 641 if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
620 return; 642 return;
621 643
622 if (die_task == GNUNET_SCHEDULER_NO_TASK) 644 if (die_task == GNUNET_SCHEDULER_NO_TASK)
623 { 645 {
624 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 646 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
625 &end_badly, "from create topology (timeout)"); 647 &end_badly,
626 } 648 "from create topology (timeout)");
649 }
627 650
628 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) 651 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
629 { 652 {
630 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), 653 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
631 &send_test_messages, pos); 654 (GNUNET_TIME_UNIT_SECONDS, 1),
632 return; /* Otherwise we'll double schedule messages here! */ 655 &send_test_messages, pos);
633 } 656 return; /* Otherwise we'll double schedule messages here! */
657 }
634#if VERBOSE 658#if VERBOSE
635 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname); 659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
660 "Attempting to send test message from %s to %s\n",
661 pos->peer1->shortname, pos->peer2->shortname);
636#endif 662#endif
637 /* 663 /*
638 * Connect to the sending peer 664 * Connect to the sending peer
639 */ 665 */
640 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, 666 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
641 1, 667 1,
642 pos, 668 pos,
643 &init_notify_peer1, 669 &init_notify_peer1,
644 &connect_notify_peer1, 670 &connect_notify_peer1,
645 NULL, 671 NULL,
646 NULL, 672 NULL,
647 NULL, 673 NULL,
648 GNUNET_NO, NULL, GNUNET_NO, no_handlers); 674 GNUNET_NO, NULL, GNUNET_NO,
675 no_handlers);
649 676
650 GNUNET_assert(pos->peer1handle != NULL); 677 GNUNET_assert (pos->peer1handle != NULL);
651 678
652 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) 679 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
653 { 680 {
654 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); 681 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
655 } 682 }
656 else 683 else
657 { 684 {
658 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), 685 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
659 &send_test_messages, pos->next); 686 (GNUNET_TIME_UNIT_SECONDS, 1),
660 } 687 &send_test_messages, pos->next);
688 }
661} 689}
662 690
663static void 691static void
664send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 692send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
665{ 693{
666 struct TestMessageContext *pos; 694 struct TestMessageContext *pos;
667 struct TestMessageContext *free_pos; 695 struct TestMessageContext *free_pos;
668 struct PeerContext *peer_pos; 696 struct PeerContext *peer_pos;
697
669#if TEST_ALL 698#if TEST_ALL
670 struct PeerContext *inner_peer_pos; 699 struct PeerContext *inner_peer_pos;
671 struct TestMessageContext *temp_context; 700 struct TestMessageContext *temp_context;
672#endif 701#endif
673 peer_pos = all_peers; 702 peer_pos = all_peers;
674 while (peer_pos != NULL) 703 while (peer_pos != NULL)
704 {
705 if (peer_pos->peer_handle != NULL)
675 { 706 {
676 if (peer_pos->peer_handle != NULL) 707 GNUNET_CORE_disconnect (peer_pos->peer_handle);
677 { 708 peer_pos->peer_handle = NULL;
678 GNUNET_CORE_disconnect(peer_pos->peer_handle); 709 }
679 peer_pos->peer_handle = NULL;
680 }
681#if TEST_ALL 710#if TEST_ALL
682 inner_peer_pos = all_peers; 711 inner_peer_pos = all_peers;
683 while (inner_peer_pos != NULL) 712 while (inner_peer_pos != NULL)
684 { 713 {
685 if (inner_peer_pos != peer_pos) 714 if (inner_peer_pos != peer_pos)
686 { 715 {
687 temp_total_other_messages++; 716 temp_total_other_messages++;
688 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext)); 717 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
689 temp_context->peer1 = peer_pos->daemon; 718 temp_context->peer1 = peer_pos->daemon;
690 temp_context->peer2 = inner_peer_pos->daemon; 719 temp_context->peer2 = inner_peer_pos->daemon;
691 temp_context->next = other_test_messages; 720 temp_context->next = other_test_messages;
692 temp_context->uid = total_connections + temp_total_other_messages; 721 temp_context->uid = total_connections + temp_total_other_messages;
693 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 722 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
694 other_test_messages = temp_context; 723 other_test_messages = temp_context;
695 } 724 }
696 inner_peer_pos = inner_peer_pos->next; 725 inner_peer_pos = inner_peer_pos->next;
697 }
698#endif
699 peer_pos = peer_pos->next;
700 } 726 }
727#endif
728 peer_pos = peer_pos->next;
729 }
701 all_peers = NULL; 730 all_peers = NULL;
702 731
703 pos = test_messages; 732 pos = test_messages;
704 while (pos != NULL) 733 while (pos != NULL)
734 {
735 if (pos->peer1handle != NULL)
736 {
737 GNUNET_CORE_disconnect (pos->peer1handle);
738 pos->peer1handle = NULL;
739 }
740 if (pos->peer2handle != NULL)
705 { 741 {
706 if (pos->peer1handle != NULL) 742 GNUNET_CORE_disconnect (pos->peer2handle);
707 { 743 pos->peer2handle = NULL;
708 GNUNET_CORE_disconnect(pos->peer1handle);
709 pos->peer1handle = NULL;
710 }
711 if (pos->peer2handle != NULL)
712 {
713 GNUNET_CORE_disconnect(pos->peer2handle);
714 pos->peer2handle = NULL;
715 }
716 free_pos = pos;
717 pos = pos->next;
718 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
719 {
720 GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
721 }
722 GNUNET_free(free_pos);
723 } 744 }
745 free_pos = pos;
746 pos = pos->next;
747 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
748 {
749 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
750 }
751 GNUNET_free (free_pos);
752 }
724 test_messages = NULL; 753 test_messages = NULL;
725 754
726 total_other_expected_messages = temp_total_other_messages; 755 total_other_expected_messages = temp_total_other_messages;
727 if (total_other_expected_messages == 0) 756 if (total_other_expected_messages == 0)
728 { 757 {
729 GNUNET_SCHEDULER_add_now (&end_badly, "send_other_messages had 0 messages to send, no DV connections made!"); 758 GNUNET_SCHEDULER_add_now (&end_badly,
730 } 759 "send_other_messages had 0 messages to send, no DV connections made!");
760 }
731#if VERBOSE 761#if VERBOSE
732 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test messages\n", total_other_expected_messages); 762 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
763 "Preparing to send %d other test messages\n",
764 total_other_expected_messages);
733#endif 765#endif
734 766
735 GNUNET_SCHEDULER_add_now (&send_test_messages, other_test_messages); 767 GNUNET_SCHEDULER_add_now (&send_test_messages, other_test_messages);
736 GNUNET_SCHEDULER_cancel(die_task); 768 GNUNET_SCHEDULER_cancel (die_task);
737 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages"); 769 die_task =
770 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
771 (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly,
772 "from send_other_messages");
738} 773}
739 774
740static void 775static void
@@ -749,68 +784,73 @@ topology_callback (void *cls,
749 const char *emsg) 784 const char *emsg)
750{ 785{
751 struct TestMessageContext *temp_context; 786 struct TestMessageContext *temp_context;
787
752 if (emsg == NULL) 788 if (emsg == NULL)
753 { 789 {
754 total_connections++; 790 total_connections++;
755#if VERBOSE 791#if VERBOSE
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", 792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
757 first_daemon->shortname, 793 "connected peer %s to peer %s, distance %u\n",
758 second_daemon->shortname, 794 first_daemon->shortname, second_daemon->shortname, distance);
759 distance);
760#endif 795#endif
761 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext)); 796 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
762 temp_context->peer1 = first_daemon; 797 temp_context->peer1 = first_daemon;
763 temp_context->peer2 = second_daemon; 798 temp_context->peer2 = second_daemon;
764 temp_context->next = test_messages; 799 temp_context->next = test_messages;
765 temp_context->uid = total_connections; 800 temp_context->uid = total_connections;
766 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 801 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
767 test_messages = temp_context; 802 test_messages = temp_context;
768 expected_messages++; 803 expected_messages++;
769 } 804 }
770#if VERBOSE 805#if VERBOSE
771 else 806 else
772 { 807 {
773 failed_connections++; 808 failed_connections++;
774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", 809 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
775 first_daemon->shortname, 810 "Failed to connect peer %s to peer %s with error :\n%s\n",
776 second_daemon->shortname, emsg); 811 first_daemon->shortname, second_daemon->shortname, emsg);
777 } 812 }
778#endif 813#endif
779 814
780 if (total_connections == expected_connections) 815 if (total_connections == expected_connections)
781 { 816 {
782#if VERBOSE 817#if VERBOSE
783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
784 "Created %u total connections, which is our target number! Calling send messages.\n", 819 "Created %u total connections, which is our target number! Calling send messages.\n",
785 total_connections); 820 total_connections);
786#endif 821#endif
787 822
823 GNUNET_SCHEDULER_cancel (die_task);
824 die_task = GNUNET_SCHEDULER_NO_TASK;
825 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
826 }
827 else if (total_connections + failed_connections == expected_connections)
828 {
829 if (failed_connections <
830 (unsigned int) (fail_percentage * total_connections))
831 {
788 GNUNET_SCHEDULER_cancel (die_task); 832 GNUNET_SCHEDULER_cancel (die_task);
789 die_task = GNUNET_SCHEDULER_NO_TASK; 833 die_task = GNUNET_SCHEDULER_NO_TASK;
790 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages); 834 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
791 } 835 }
792 else if (total_connections + failed_connections == expected_connections) 836 else
793 { 837 {
794 if (failed_connections < (unsigned int)(fail_percentage * total_connections)) 838 GNUNET_SCHEDULER_cancel (die_task);
795 { 839 die_task =
796 GNUNET_SCHEDULER_cancel (die_task); 840 GNUNET_SCHEDULER_add_now (&end_badly,
797 die_task = GNUNET_SCHEDULER_NO_TASK; 841 "from topology_callback (too many failed connections)");
798 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
799 }
800 else
801 {
802 GNUNET_SCHEDULER_cancel (die_task);
803 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)");
804 }
805 } 842 }
843 }
806 else 844 else
807 { 845 {
808#if VERBOSE 846#if VERBOSE
809 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
810 "Have %d total connections, %d failed connections, Want %d (at least %d)\n", 848 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
811 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections)); 849 total_connections, failed_connections, expected_connections,
850 expected_connections -
851 (unsigned int) (fail_percentage * expected_connections));
812#endif 852#endif
813 } 853 }
814} 854}
815 855
816static void 856static void
@@ -818,50 +858,56 @@ connect_topology ()
818{ 858{
819 expected_connections = -1; 859 expected_connections = -1;
820 if ((pg != NULL) && (peers_left == 0)) 860 if ((pg != NULL) && (peers_left == 0))
821 { 861 {
822 expected_connections = GNUNET_TESTING_connect_topology (pg, 862 expected_connections = GNUNET_TESTING_connect_topology (pg,
823 connection_topology, 863 connection_topology,
824 connect_topology_option, 864 connect_topology_option,
825 connect_topology_option_modifier, 865 connect_topology_option_modifier,
826 TIMEOUT, 866 TIMEOUT,
827 12, 867 12, NULL, NULL);
828 NULL, NULL);
829#if VERBOSE 868#if VERBOSE
830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
831 "Have %d expected connections\n", expected_connections); 870 "Have %d expected connections\n", expected_connections);
832#endif 871#endif
833 } 872 }
834 873
835 GNUNET_SCHEDULER_cancel (die_task); 874 GNUNET_SCHEDULER_cancel (die_task);
836 if (expected_connections == GNUNET_SYSERR) 875 if (expected_connections == GNUNET_SYSERR)
837 { 876 {
838 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); 877 die_task =
839 } 878 GNUNET_SCHEDULER_add_now (&end_badly,
879 "from connect topology (bad return)");
880 }
840 881
841 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 882 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
842 &end_badly, "from connect topology (timeout)"); 883 &end_badly,
884 "from connect topology (timeout)");
843} 885}
844 886
845static void 887static void
846create_topology () 888create_topology ()
847{ 889{
848 peers_left = num_peers; /* Reset counter */ 890 peers_left = num_peers; /* Reset counter */
849 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR) 891 if (GNUNET_TESTING_create_topology
850 { 892 (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
893 {
851#if VERBOSE 894#if VERBOSE
852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Topology set up, now starting peers!\n"); 896 "Topology set up, now starting peers!\n");
854#endif 897#endif
855 GNUNET_TESTING_daemons_continue_startup(pg); 898 GNUNET_TESTING_daemons_continue_startup (pg);
856 } 899 }
857 else 900 else
858 { 901 {
859 GNUNET_SCHEDULER_cancel (die_task); 902 GNUNET_SCHEDULER_cancel (die_task);
860 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)"); 903 die_task =
861 } 904 GNUNET_SCHEDULER_add_now (&end_badly,
905 "from create topology (bad return)");
906 }
862 GNUNET_SCHEDULER_cancel (die_task); 907 GNUNET_SCHEDULER_cancel (die_task);
863 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 908 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
864 &end_badly, "from continue startup (timeout)"); 909 &end_badly,
910 "from continue startup (timeout)");
865} 911}
866 912
867/** 913/**
@@ -872,126 +918,134 @@ create_topology ()
872 * @param latency reported latency of the connection with 'other' 918 * @param latency reported latency of the connection with 'other'
873 * @param distance reported distance (DV) to 'other' 919 * @param distance reported distance (DV) to 'other'
874 */ 920 */
875static void all_connect_handler (void *cls, 921static void
876 const struct 922all_connect_handler (void *cls,
877 GNUNET_PeerIdentity * peer, 923 const struct
878 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 924 GNUNET_PeerIdentity *peer,
925 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
879{ 926{
880 struct GNUNET_TESTING_Daemon *d = cls; 927 struct GNUNET_TESTING_Daemon *d = cls;
881 struct GNUNET_TESTING_Daemon *second_daemon; 928 struct GNUNET_TESTING_Daemon *second_daemon;
882 char *second_shortname; 929 char *second_shortname;
930
883#if !TEST_ALL 931#if !TEST_ALL
884 struct TestMessageContext *temp_context; 932 struct TestMessageContext *temp_context;
885#endif 933#endif
886 uint32_t distance; 934 uint32_t distance;
887 935
888 if (0 == memcmp(&d->id, peer, sizeof(struct GNUNET_PeerIdentity))) 936 if (0 == memcmp (&d->id, peer, sizeof (struct GNUNET_PeerIdentity)))
889 return; 937 return;
890 second_shortname = GNUNET_strdup (GNUNET_i2s(peer)); 938 second_shortname = GNUNET_strdup (GNUNET_i2s (peer));
891 distance = get_atsi_distance(atsi); 939 distance = get_atsi_distance (atsi);
892 940
893#if VERBOSE 941#if VERBOSE
894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
895 "connected peer %s to peer %s, distance %u\n", 943 "connected peer %s to peer %s, distance %u\n",
896 d->shortname, 944 d->shortname, second_shortname, distance);
897 second_shortname,
898 distance);
899#endif 945#endif
900 946
901 second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey); 947 second_daemon =
948 GNUNET_CONTAINER_multihashmap_get (peer_daemon_hash, &peer->hashPubKey);
902 949
903 if (second_daemon == NULL) 950 if (second_daemon == NULL)
904 { 951 {
905 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 952 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
906 "Couldn't find second peer!\n"); 953 GNUNET_free (second_shortname);
907 GNUNET_free(second_shortname); 954 return;
908 return; 955 }
909 }
910#if !TEST_ALL 956#if !TEST_ALL
911 if (distance > 1) 957 if (distance > 1)
912 { 958 {
913 temp_total_other_messages++; 959 temp_total_other_messages++;
914 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext)); 960 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
915 temp_context->peer1 = d; 961 temp_context->peer1 = d;
916 temp_context->peer2 = second_daemon; 962 temp_context->peer2 = second_daemon;
917 temp_context->next = other_test_messages; 963 temp_context->next = other_test_messages;
918 temp_context->uid = total_connections + temp_total_other_messages; 964 temp_context->uid = total_connections + temp_total_other_messages;
919 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 965 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
920 other_test_messages = temp_context; 966 other_test_messages = temp_context;
921 } 967 }
922#endif 968#endif
923 969
924 if (dotOutFile != NULL) 970 if (dotOutFile != NULL)
925 { 971 {
926 if (distance == 1) 972 if (distance == 1)
927 fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname); 973 fprintf (dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
928 else if (distance == 2) 974 else if (distance == 2)
929 fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname); 975 fprintf (dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname,
930 else if (distance == 3) 976 second_shortname);
931 fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname); 977 else if (distance == 3)
932 else if (distance == 4) 978 fprintf (dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname,
933 fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname); 979 second_shortname);
934 else 980 else if (distance == 4)
935 fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, second_shortname); 981 fprintf (dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname,
936 } 982 second_shortname);
937 GNUNET_free(second_shortname); 983 else
984 fprintf (dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname,
985 second_shortname);
986 }
987 GNUNET_free (second_shortname);
938 988
939 if (temp_total_other_messages == num_additional_messages) 989 if (temp_total_other_messages == num_additional_messages)
940 { 990 {
941 GNUNET_SCHEDULER_add_now (&send_other_messages, NULL); 991 GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
942 } 992 }
943} 993}
944 994
945static void 995static void
946peers_started_callback (void *cls, 996peers_started_callback (void *cls,
947 const struct GNUNET_PeerIdentity *id, 997 const struct GNUNET_PeerIdentity *id,
948 const struct GNUNET_CONFIGURATION_Handle *cfg, 998 const struct GNUNET_CONFIGURATION_Handle *cfg,
949 struct GNUNET_TESTING_Daemon *d, const char *emsg) 999 struct GNUNET_TESTING_Daemon *d, const char *emsg)
950{ 1000{
951 struct PeerContext *new_peer; 1001 struct PeerContext *new_peer;
1002
952 if (emsg != NULL) 1003 if (emsg != NULL)
953 { 1004 {
954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", 1005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
955 emsg); 1006 "Failed to start daemon with error: `%s'\n", emsg);
956 return; 1007 return;
957 } 1008 }
958 GNUNET_assert (id != NULL); 1009 GNUNET_assert (id != NULL);
959#if VERBOSE 1010#if VERBOSE
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", 1011 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
961 (num_peers - peers_left) + 1, num_peers); 1012 (num_peers - peers_left) + 1, num_peers);
962#endif 1013#endif
963 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1014 GNUNET_assert (GNUNET_SYSERR !=
964 1015 GNUNET_CONTAINER_multihashmap_put (peer_daemon_hash,
965 new_peer = GNUNET_malloc(sizeof(struct PeerContext)); 1016 &id->hashPubKey, d,
966 new_peer->peer_handle = GNUNET_CORE_connect(cfg, 1017 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
967 1, 1018
968 d, NULL, 1019 new_peer = GNUNET_malloc (sizeof (struct PeerContext));
969 &all_connect_handler, 1020 new_peer->peer_handle = GNUNET_CORE_connect (cfg,
970 NULL, NULL, NULL, 1021 1,
971 GNUNET_NO, NULL, GNUNET_NO, 1022 d, NULL,
972 no_handlers); 1023 &all_connect_handler,
1024 NULL, NULL, NULL,
1025 GNUNET_NO, NULL, GNUNET_NO,
1026 no_handlers);
973 new_peer->daemon = d; 1027 new_peer->daemon = d;
974 new_peer->next = all_peers; 1028 new_peer->next = all_peers;
975 all_peers = new_peer; 1029 all_peers = new_peer;
976 peers_left--; 1030 peers_left--;
977 1031
978 if (peers_left == 0) 1032 if (peers_left == 0)
979 { 1033 {
980#if VERBOSE 1034#if VERBOSE
981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
982 "All %d daemons started, now creating topology!\n", 1036 "All %d daemons started, now creating topology!\n", num_peers);
983 num_peers);
984#endif 1037#endif
985 GNUNET_SCHEDULER_cancel (die_task); 1038 GNUNET_SCHEDULER_cancel (die_task);
986 /* Set up task in case topology creation doesn't finish 1039 /* Set up task in case topology creation doesn't finish
987 * within a reasonable amount of time */ 1040 * within a reasonable amount of time */
988 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1041 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
989 (GNUNET_TIME_UNIT_MINUTES, 5), 1042 (GNUNET_TIME_UNIT_MINUTES, 5),
990 &end_badly, "from peers_started_callback"); 1043 &end_badly,
991 1044 "from peers_started_callback");
992 connect_topology (); 1045
993 ok = 0; 1046 connect_topology ();
994 } 1047 ok = 0;
1048 }
995} 1049}
996 1050
997/** 1051/**
@@ -1004,37 +1058,36 @@ peers_started_callback (void *cls,
1004 */ 1058 */
1005static void 1059static void
1006hostkey_callback (void *cls, 1060hostkey_callback (void *cls,
1007 const struct GNUNET_PeerIdentity *id, 1061 const struct GNUNET_PeerIdentity *id,
1008 struct GNUNET_TESTING_Daemon *d, 1062 struct GNUNET_TESTING_Daemon *d, const char *emsg)
1009 const char *emsg)
1010{ 1063{
1011 if (emsg != NULL) 1064 if (emsg != NULL)
1012 { 1065 {
1013 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg); 1066 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1014 } 1067 "Hostkey callback received error: %s\n", emsg);
1068 }
1015 1069
1016#if VERBOSE 1070#if VERBOSE
1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1018 "Hostkey created for peer `%s'\n", 1072 "Hostkey created for peer `%s'\n", GNUNET_i2s (id));
1019 GNUNET_i2s(id));
1020#endif 1073#endif
1021 peers_left--; 1074 peers_left--;
1022 if (peers_left == 0) 1075 if (peers_left == 0)
1023 { 1076 {
1024#if VERBOSE 1077#if VERBOSE
1025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1026 "All %d hostkeys created, now creating topology!\n", 1079 "All %d hostkeys created, now creating topology!\n", num_peers);
1027 num_peers);
1028#endif 1080#endif
1029 GNUNET_SCHEDULER_cancel (die_task); 1081 GNUNET_SCHEDULER_cancel (die_task);
1030 /* Set up task in case topology creation doesn't finish 1082 /* Set up task in case topology creation doesn't finish
1031 * within a reasonable amount of time */ 1083 * within a reasonable amount of time */
1032 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1084 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1033 (GNUNET_TIME_UNIT_MINUTES, 5), 1085 (GNUNET_TIME_UNIT_MINUTES, 5),
1034 &end_badly, "from hostkey_callback"); 1086 &end_badly,
1035 GNUNET_SCHEDULER_add_now(&create_topology, NULL); 1087 "from hostkey_callback");
1036 ok = 0; 1088 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
1037 } 1089 ok = 0;
1090 }
1038} 1091}
1039 1092
1040static void 1093static void
@@ -1042,117 +1095,141 @@ run (void *cls,
1042 char *const *args, 1095 char *const *args,
1043 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 1096 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1044{ 1097{
1045 char * topology_str; 1098 char *topology_str;
1046 char * connect_topology_str; 1099 char *connect_topology_str;
1047 char * blacklist_topology_str; 1100 char *blacklist_topology_str;
1048 char * connect_topology_option_str; 1101 char *connect_topology_option_str;
1049 char * connect_topology_option_modifier_string; 1102 char *connect_topology_option_modifier_string;
1103
1050 ok = 1; 1104 ok = 1;
1051 1105
1052 dotOutFile = fopen (dotOutFileName, "w"); 1106 dotOutFile = fopen (dotOutFileName, "w");
1053 if (dotOutFile != NULL) 1107 if (dotOutFile != NULL)
1054 { 1108 {
1055 fprintf (dotOutFile, "strict graph G {\n"); 1109 fprintf (dotOutFile, "strict graph G {\n");
1056 } 1110 }
1057 1111
1058#if VERBOSE 1112#if VERBOSE
1059 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1060 "Starting daemons based on config file %s\n", cfgfile); 1114 "Starting daemons based on config file %s\n", cfgfile);
1061#endif 1115#endif
1062 1116
1063 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 1117 if (GNUNET_YES !=
1064 { 1118 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1065 ok = 404; 1119 &test_directory))
1066 return; 1120 {
1067 } 1121 ok = 404;
1122 return;
1123 }
1068 1124
1069 if ((GNUNET_YES == 1125 if ((GNUNET_YES ==
1070 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology", 1126 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1071 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str))) 1127 &topology_str)) &&
1072 { 1128 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1073 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1129 {
1074 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY"); 1130 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1075 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */ 1131 "Invalid topology `%s' given for section %s option %s\n",
1076 } 1132 topology_str, "TESTING", "TOPOLOGY");
1133 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1134 }
1077 1135
1078 if ((GNUNET_YES == 1136 if ((GNUNET_YES ==
1079 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology", 1137 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1080 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str))) 1138 "connect_topology",
1081 { 1139 &connect_topology_str)) &&
1082 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1140 (GNUNET_NO ==
1083 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY"); 1141 GNUNET_TESTING_topology_get (&connection_topology,
1084 } 1142 connect_topology_str)))
1085 GNUNET_free_non_null(connect_topology_str); 1143 {
1144 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1145 "Invalid connect topology `%s' given for section %s option %s\n",
1146 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1147 }
1148 GNUNET_free_non_null (connect_topology_str);
1086 if ((GNUNET_YES == 1149 if ((GNUNET_YES ==
1087 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option", 1150 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1088 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str))) 1151 "connect_topology_option",
1089 { 1152 &connect_topology_option_str)) &&
1090 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1153 (GNUNET_NO ==
1091 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION"); 1154 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1092 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */ 1155 connect_topology_option_str)))
1093 } 1156 {
1094 GNUNET_free_non_null(connect_topology_option_str); 1157 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1158 "Invalid connect topology option `%s' given for section %s option %s\n",
1159 connect_topology_option_str, "TESTING",
1160 "CONNECT_TOPOLOGY_OPTION");
1161 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1162 }
1163 GNUNET_free_non_null (connect_topology_option_str);
1095 if (GNUNET_YES == 1164 if (GNUNET_YES ==
1096 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier", 1165 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1097 &connect_topology_option_modifier_string)) 1166 "connect_topology_option_modifier",
1167 &connect_topology_option_modifier_string))
1168 {
1169 if (sscanf
1170 (connect_topology_option_modifier_string, "%lf",
1171 &connect_topology_option_modifier) != 1)
1098 { 1172 {
1099 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1) 1173 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1100 { 1174 _
1101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1175 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1102 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"), 1176 connect_topology_option_modifier_string,
1103 connect_topology_option_modifier_string, 1177 "connect_topology_option_modifier", "TESTING");
1104 "connect_topology_option_modifier",
1105 "TESTING");
1106 }
1107 GNUNET_free (connect_topology_option_modifier_string);
1108 } 1178 }
1179 GNUNET_free (connect_topology_option_modifier_string);
1180 }
1109 1181
1110 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports", 1182 if (GNUNET_YES !=
1111 &blacklist_transports)) 1183 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1184 "blacklist_transports",
1185 &blacklist_transports))
1112 blacklist_transports = NULL; 1186 blacklist_transports = NULL;
1113 1187
1114 if ((GNUNET_YES == 1188 if ((GNUNET_YES ==
1115 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology", 1189 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1116 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str))) 1190 "blacklist_topology",
1117 { 1191 &blacklist_topology_str)) &&
1118 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1192 (GNUNET_NO ==
1119 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY"); 1193 GNUNET_TESTING_topology_get (&blacklist_topology,
1120 } 1194 blacklist_topology_str)))
1121 GNUNET_free_non_null(topology_str); 1195 {
1122 GNUNET_free_non_null(blacklist_topology_str); 1196 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1197 "Invalid topology `%s' given for section %s option %s\n",
1198 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1199 }
1200 GNUNET_free_non_null (topology_str);
1201 GNUNET_free_non_null (blacklist_topology_str);
1123 if (GNUNET_SYSERR == 1202 if (GNUNET_SYSERR ==
1124 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", 1203 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1125 &num_peers)) 1204 &num_peers))
1126 num_peers = DEFAULT_NUM_PEERS; 1205 num_peers = DEFAULT_NUM_PEERS;
1127 1206
1128 if (GNUNET_SYSERR == 1207 if (GNUNET_SYSERR ==
1129 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "additional_messages", 1208 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
1209 "additional_messages",
1130 &num_additional_messages)) 1210 &num_additional_messages))
1131 num_additional_messages = DEFAULT_ADDITIONAL_MESSAGES; 1211 num_additional_messages = DEFAULT_ADDITIONAL_MESSAGES;
1132 1212
1133 main_cfg = cfg; 1213 main_cfg = cfg;
1134 1214
1135 GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1); 1215 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1136 peers_left = num_peers; 1216 peers_left = num_peers;
1137 1217
1138 /* Set up a task to end testing if peer start fails */ 1218 /* Set up a task to end testing if peer start fails */
1139 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1219 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1140 (GNUNET_TIME_UNIT_MINUTES, 5), 1220 (GNUNET_TIME_UNIT_MINUTES, 5),
1141 &end_badly, "didn't start all daemons in reasonable amount of time!!!"); 1221 &end_badly,
1222 "didn't start all daemons in reasonable amount of time!!!");
1142 1223
1143 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left); 1224 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create (peers_left);
1144 pg = GNUNET_TESTING_daemons_start (cfg, 1225 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
1145 peers_left, /* Total number of peers */ 1226 peers_left, /* Number of outstanding connections */
1146 peers_left, /* Number of outstanding connections */ 1227 peers_left, /* Number of parallel ssh connections, or peers being started at once */
1147 peers_left, /* Number of parallel ssh connections, or peers being started at once */
1148 TIMEOUT, 1228 TIMEOUT,
1149 &hostkey_callback, 1229 &hostkey_callback,
1150 NULL, 1230 NULL,
1151 &peers_started_callback, 1231 &peers_started_callback,
1152 NULL, 1232 NULL, &topology_callback, NULL, NULL);
1153 &topology_callback,
1154 NULL,
1155 NULL);
1156 1233
1157} 1234}
1158 1235
@@ -1160,7 +1237,8 @@ static int
1160check () 1237check ()
1161{ 1238{
1162 int ret; 1239 int ret;
1163 char *const argv[] = {"test-transport-dv", 1240
1241 char *const argv[] = { "test-transport-dv",
1164 "-c", 1242 "-c",
1165 "test_transport_dv_data.conf", 1243 "test_transport_dv_data.conf",
1166#if VERBOSE 1244#if VERBOSE
@@ -1172,12 +1250,13 @@ check ()
1172 GNUNET_GETOPT_OPTION_END 1250 GNUNET_GETOPT_OPTION_END
1173 }; 1251 };
1174 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 1252 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1175 argv, "test-transport-dv", "nohelp", 1253 argv, "test-transport-dv", "nohelp",
1176 options, &run, &ok); 1254 options, &run, &ok);
1177 if (ret != GNUNET_OK) 1255 if (ret != GNUNET_OK)
1178 { 1256 {
1179 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-transport-dv': Failed with error code %d\n", ret); 1257 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1180 } 1258 "`test-transport-dv': Failed with error code %d\n", ret);
1259 }
1181 return ok; 1260 return ok;
1182} 1261}
1183 1262
@@ -1199,9 +1278,10 @@ main (int argc, char *argv[])
1199 * of by the testing framework. 1278 * of by the testing framework.
1200 */ 1279 */
1201 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) 1280 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1202 { 1281 {
1203 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); 1282 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1204 } 1283 "Failed to remove testing directory %s\n", test_directory);
1284 }
1205 return ret; 1285 return ret;
1206} 1286}
1207 1287