aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-04-09 16:21:37 +0000
committerNathan S. Evans <evans@in.tum.de>2010-04-09 16:21:37 +0000
commite330680665c97ce4ec3e2ccca1b24981830ab5da (patch)
treecb9af78dd1ac1d4ea29e6aa3deee1d1356f315bd
parentb85f126feb0f722be9c37a5ba0fa1a053b82a704 (diff)
downloadgnunet-e330680665c97ce4ec3e2ccca1b24981830ab5da.tar.gz
gnunet-e330680665c97ce4ec3e2ccca1b24981830ab5da.zip
many changes, won't work without blacklisting and more work
-rw-r--r--src/dv/dv.h1
-rw-r--r--src/dv/dv_api.c4
-rw-r--r--src/dv/gnunet-service-dv.c627
-rw-r--r--src/dv/plugin_transport_dv.c12
-rw-r--r--src/dv/test_transport_api_dv.c252
-rw-r--r--src/dv/test_transport_api_dv_peer1.conf7
-rw-r--r--src/dv/test_transport_api_dv_peer2.conf5
-rw-r--r--src/dv/test_transport_api_dv_peer3.conf9
8 files changed, 711 insertions, 206 deletions
diff --git a/src/dv/dv.h b/src/dv/dv.h
index 38c6f2a60..b665b4d70 100644
--- a/src/dv/dv.h
+++ b/src/dv/dv.h
@@ -28,6 +28,7 @@
28 28
29#include "gnunet_common.h" 29#include "gnunet_common.h"
30 30
31#define DEBUG_DV_GOSSIP GNUNET_NO
31#define DEBUG_DV GNUNET_YES 32#define DEBUG_DV GNUNET_YES
32#define DEBUG_DV_API GNUNET_YES 33#define DEBUG_DV_API GNUNET_YES
33 34
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index 60c1ba4e4..182f9ab72 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -171,7 +171,8 @@ transmit_pending (void *cls, size_t size, void *buf)
171 size_t tsize; 171 size_t tsize;
172 172
173#if DEBUG_DV 173#if DEBUG_DV
174 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Transmit pending called with message type %d\n", ntohs(handle->current->msg->header.type)); 174 if (handle->current != NULL)
175 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Transmit pending called with message type %d\n", ntohs(handle->current->msg->header.type));
175#endif 176#endif
176 177
177 if (buf == NULL) 178 if (buf == NULL)
@@ -320,6 +321,7 @@ void handle_message_receipt (void *cls,
320 321
321#if DEBUG_DV 322#if DEBUG_DV
322 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "packed message type: %d or %d\n", ntohs(((struct GNUNET_MessageHeader *)packed_msg)->type), ((struct GNUNET_MessageHeader *)packed_msg)->type); 323 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "packed message type: %d or %d\n", ntohs(((struct GNUNET_MessageHeader *)packed_msg)->type), ((struct GNUNET_MessageHeader *)packed_msg)->type);
324 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message sender reported as %s\n", GNUNET_i2s(&received_msg->sender));
323#endif 325#endif
324 handle->receive_handler(handle->receive_cls, 326 handle->receive_handler(handle->receive_cls,
325 &received_msg->sender, 327 &received_msg->sender,
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index b5fb9ba7d..696ccc165 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -27,6 +27,15 @@
27 * @author Christian Grothoff 27 * @author Christian Grothoff
28 * @author Nathan Evans 28 * @author Nathan Evans
29 * 29 *
30 * TODO: Currently the final hop of a DV message assigns a 0 to the receiver
31 * id field. This probably can't work(!) even if we know that the peer is
32 * a direct neighbor (unless we can trust that transport will choose that
33 * address for the peer). So the DV message will likely need to have the
34 * peer identity of the recipient.
35 *
36 * Also the gossip rates need to be worked out. Probably many other things
37 * as well.
38 *
30 */ 39 */
31#include "platform.h" 40#include "platform.h"
32#include "gnunet_client_lib.h" 41#include "gnunet_client_lib.h"
@@ -134,28 +143,60 @@ static size_t default_dv_priority = 0;
134 143
135 144
136/** 145/**
137 * Pending message struct, also a test to see if these can 146 * Linked list of messages to send to clients.
138 * safely ONLY be freed by callback.
139 */ 147 */
140struct PendingMessage 148struct PendingMessage
141{ 149{
142 /** 150 /**
143 * Copy of message to be sent 151 * Pointer to next item in the list
144 */ 152 */
145 struct GNUNET_MessageHeader *msg; 153 struct PendingMessage *next;
146 154
147 /** 155 /**
148 * Size of message to be sent 156 * Pointer to previous item in the list
149 */ 157 */
150 size_t msg_size; 158 struct PendingMessage *prev;
151 159
152 /** 160 /**
153 * Transmit handle, for cancellation if necessary. 161 * Actual message to be sent; // avoid allocation
154 */ 162 */
155 struct GNUNET_CORE_TransmitHandle *transmit_handle; 163 const struct GNUNET_MessageHeader *msg; // msg = (cast) &pm[1]; // memcpy (&pm[1], data, len);
156 164
157}; 165};
158 166
167/**
168 * Transmit handle to the plugin.
169 */
170struct GNUNET_CONNECTION_TransmitHandle * plugin_transmit_handle;
171
172/**
173 * Head of DLL for client messages
174 */
175struct PendingMessage *plugin_pending_head;
176
177/**
178 * Tail of DLL for client messages
179 */
180struct PendingMessage *plugin_pending_tail;
181
182
183/**
184 * Transmit handle to core service.
185 */
186struct GNUNET_CORE_TransmitHandle * core_transmit_handle;
187
188/**
189 * Head of DLL for core messages
190 */
191struct PendingMessage *core_pending_head;
192
193/**
194 * Tail of DLL for core messages
195 */
196struct PendingMessage *core_pending_tail;
197
198
199
159 200
160/** 201/**
161 * Context created whenever a direct peer connects to us, 202 * Context created whenever a direct peer connects to us,
@@ -341,7 +382,7 @@ struct HelloContext
341 /** 382 /**
342 * Identity of distant neighbor. 383 * Identity of distant neighbor.
343 */ 384 */
344 struct GNUNET_PeerIdentity *distant_peer; 385 struct GNUNET_PeerIdentity distant_peer;
345 386
346 /** 387 /**
347 * Identity of direct neighbor, via which we send this message. 388 * Identity of direct neighbor, via which we send this message.
@@ -355,6 +396,41 @@ struct HelloContext
355 396
356}; 397};
357 398
399struct DV_SendContext
400{
401 /**
402 * The distant peer (should always match)
403 */
404 struct GNUNET_PeerIdentity *distant_peer;
405
406 /**
407 * The direct peer, we need to verify the referrer of.
408 */
409 struct GNUNET_PeerIdentity *direct_peer;
410
411 /**
412 * The message to be sent
413 */
414 struct GNUNET_MessageHeader *message;
415
416 /**
417 * The size of the message being sent, may be larger
418 * than message->header.size because it's multiple
419 * messages packed into one!
420 */
421 size_t message_size;
422
423 /**
424 * How important is this message?
425 */
426 unsigned int importance;
427
428 /**
429 * Timeout for this message
430 */
431 struct GNUNET_TIME_Relative timeout;
432};
433
358/** 434/**
359 * Global construct 435 * Global construct
360 */ 436 */
@@ -439,23 +515,42 @@ find_destination (void *cls,
439size_t transmit_to_plugin (void *cls, 515size_t transmit_to_plugin (void *cls,
440 size_t size, void *buf) 516 size_t size, void *buf)
441{ 517{
442 struct GNUNET_DV_MessageReceived *msg = cls; 518 char *cbuf = buf;
443 int msize; 519 struct PendingMessage *reply;
520 size_t off;
521 size_t msize;
444 522
445 if (buf == NULL) 523 if (buf == NULL)
446 return 0; 524 {
447 525 /* client disconnected */
448#if DEBUG_DV 526#if DEBUG_DV
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
450 "%s: Transmit to plugin sending message of type %d!\n", "dv", ntohs(msg->header.type)); 528#endif
529 return 0;
530 }
531 plugin_transmit_handle = NULL;
532 off = 0;
533 while ( (NULL != (reply = plugin_pending_head)) &&
534 (size >= off + (msize = ntohs (reply->msg->size))))
535 {
536#if DEBUG_DV
537 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s' : transmit_notify (plugin) called with size %d\n", "dv service", msize);
451#endif 538#endif
539 GNUNET_CONTAINER_DLL_remove (plugin_pending_head,
540 plugin_pending_tail,
541 reply);
542 memcpy (&cbuf[off], reply->msg, msize);
543 GNUNET_free (reply);
544 off += msize;
545 }
452 546
453 msize = ntohs(msg->header.size); 547 if (plugin_pending_head != NULL)
454 GNUNET_assert(size >= msize); 548 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
549 ntohs(plugin_pending_head->msg->size),
550 GNUNET_TIME_UNIT_FOREVER_REL,
551 &transmit_to_plugin, NULL);
455 552
456 memcpy(buf, msg, msize); 553 return off;
457 /* FIXME: this causes crash? GNUNET_free(msg);*/
458 return msize;
459} 554}
460 555
461 556
@@ -466,6 +561,7 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
466 size_t cost) 561 size_t cost)
467{ 562{
468 struct GNUNET_DV_MessageReceived *received_msg; 563 struct GNUNET_DV_MessageReceived *received_msg;
564 struct PendingMessage *pending_message;
469#if DEBUG_DV 565#if DEBUG_DV
470 struct GNUNET_MessageHeader * packed_message_header; 566 struct GNUNET_MessageHeader * packed_message_header;
471 struct GNUNET_HELLO_Message *hello_msg; 567 struct GNUNET_HELLO_Message *hello_msg;
@@ -476,6 +572,10 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
476 char *packed_msg_start; 572 char *packed_msg_start;
477 int size; 573 int size;
478 574
575#if DEBUG_DV
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_to_plugin called with peer %s as sender\n", GNUNET_i2s(distant_neighbor));
577#endif
578
479 if (memcmp(sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)) != 0) 579 if (memcmp(sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)) != 0)
480 { 580 {
481 sender_address_len = sizeof(struct GNUNET_PeerIdentity) * 2; 581 sender_address_len = sizeof(struct GNUNET_PeerIdentity) * 2;
@@ -498,7 +598,7 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
498 received_msg->distance = htonl(cost); 598 received_msg->distance = htonl(cost);
499 received_msg->msg_len = htons(message_size); 599 received_msg->msg_len = htons(message_size);
500 /* Set the sender in this message to be the original sender! */ 600 /* Set the sender in this message to be the original sender! */
501 memcpy(&received_msg->sender, &distant_neighbor, sizeof(struct GNUNET_PeerIdentity)); 601 memcpy(&received_msg->sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity));
502 /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */ 602 /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */
503 memcpy(&received_msg[1], sender_address, sender_address_len); 603 memcpy(&received_msg[1], sender_address, sender_address_len);
504 GNUNET_free(sender_address); 604 GNUNET_free(sender_address);
@@ -517,13 +617,26 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Packed HELLO message is about peer %s\n", GNUNET_i2s(&hello_identity)); 617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Packed HELLO message is about peer %s\n", GNUNET_i2s(&hello_identity));
518 } 618 }
519#endif 619#endif
620 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + size);
621 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
622 memcpy(&pending_message[1], received_msg, size);
623 GNUNET_free(received_msg);
624
625 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message);
626
520 if (client_handle != NULL) 627 if (client_handle != NULL)
521 { 628 {
522 GNUNET_SERVER_notify_transmit_ready (client_handle, 629 if (plugin_transmit_handle == NULL)
523 size, client_transmit_timeout, 630 {
524 &transmit_to_plugin, received_msg); 631 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
632 size, GNUNET_TIME_UNIT_FOREVER_REL,
633 &transmit_to_plugin, NULL);
634 }
635 else
636 {
637 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to queue message for plugin, must be one in progress already!!\n");
638 }
525 } 639 }
526
527} 640}
528 641
529 642
@@ -541,27 +654,127 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
541size_t core_transmit_notify (void *cls, 654size_t core_transmit_notify (void *cls,
542 size_t size, void *buf) 655 size_t size, void *buf)
543{ 656{
544 struct PendingMessage *pending_message = cls; 657 char *cbuf = buf;
545 size_t ssize; 658 struct PendingMessage *reply;
659 size_t off;
660 size_t msize;
546 661
547 if (buf == NULL) 662 if (buf == NULL)
548 { 663 {
549 /* FIXME: error handling: try again? free pending_message? */ 664 /* client disconnected */
665#if DEBUG_DV
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
667#endif
550 return 0; 668 return 0;
551 } 669 }
552 ssize = pending_message->msg_size; 670
553 GNUNET_assert(size >= ssize); 671 core_transmit_handle = NULL;
554 memcpy(buf, pending_message->msg, ssize); 672 off = 0;
555 GNUNET_free(pending_message->msg); 673 while ( (NULL != (reply = core_pending_head)) &&
556 GNUNET_free(pending_message); 674 (size >= off + (msize = ntohs (reply->msg->size))))
557 return ssize; 675 {
676#if DEBUG_DV
677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s' : transmit_notify (core) called with size %d\n", "dv service", msize);
678#endif
679 GNUNET_CONTAINER_DLL_remove (core_pending_head,
680 core_pending_tail,
681 reply);
682 memcpy (&cbuf[off], reply->msg, msize);
683 GNUNET_free (reply);
684 off += msize;
685 }
686 return off;
687}
688
689
690/**
691 * Send a DV data message via DV.
692 *
693 * @param sender the original sender of the message
694 * @param specific_neighbor the specific DistantNeighbor to use, complete with referrer!
695 * @param message the packed message
696 * @param importance what priority to send this message with
697 * @param timeout how long to possibly delay sending this message
698 */
699static int
700send_message_via (const struct GNUNET_PeerIdentity * sender,
701 const struct DistantNeighbor * specific_neighbor,
702 struct DV_SendContext *send_context)
703{
704 p2p_dv_MESSAGE_Data *toSend;
705 unsigned int msg_size;
706 unsigned int cost;
707 unsigned int recipient_id;
708 unsigned int sender_id;
709 struct DistantNeighbor *source;
710 struct PendingMessage *pending_message;
711#if DEBUG_DV
712 char shortname[5];
713#endif
714
715 msg_size = send_context->message_size + sizeof (p2p_dv_MESSAGE_Data);
716
717 if (specific_neighbor == NULL)
718 {
719 /* target unknown to us, drop! */
720 return GNUNET_SYSERR;
721 }
722 recipient_id = specific_neighbor->referrer_id;
723
724 source = GNUNET_CONTAINER_multihashmap_get (ctx.extended_neighbors,
725 &sender->hashPubKey);
726 if (source == NULL)
727 {
728 if (0 != (memcmp (&my_identity,
729 sender, sizeof (struct GNUNET_PeerIdentity))))
730 {
731 /* sender unknown to us, drop! */
732 return GNUNET_SYSERR;
733 }
734 sender_id = 0; /* 0 == us */
735 }
736 else
737 {
738 /* find out the number that we use when we gossip about
739 the sender */
740 sender_id = source->our_id;
741 }
742
743 cost = specific_neighbor->cost;
744 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size);
745 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
746 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg;
747 toSend->header.size = htons (msg_size);
748 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
749 toSend->sender = htonl (sender_id);
750 toSend->recipient = htonl (recipient_id);
751 memcpy (&toSend[1], send_context->message, send_context->message_size);
752
753#if DEBUG_DV
754 memcpy(&shortname, GNUNET_i2s(&specific_neighbor->identity), 4);
755 shortname[4] = '\0';
756 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send to destination `%s' via `%s' size %u\n", "DV", &shortname, GNUNET_i2s(&specific_neighbor->referrer->identity), msg_size);
757#endif
758
759 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
760 core_pending_tail,
761 core_pending_tail,
762 pending_message);
763 if (core_transmit_handle == NULL)
764 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, send_context->importance, send_context->timeout, &specific_neighbor->referrer->identity, msg_size, &core_transmit_notify, NULL);
765 else
766 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`%s': Failed to schedule pending transmission (must be one in progress!)\n", "dv service");
767
768 return (int) cost;
558} 769}
559 770
771
560/** 772/**
561 * Send a DV data message via DV. 773 * Send a DV data message via DV.
562 * 774 *
563 * @param recipient the ultimate recipient of this message 775 * @param recipient the ultimate recipient of this message
564 * @param sender the original sender of the message 776 * @param sender the original sender of the message
777 * @param specific_neighbor the specific neighbor to send this message via
565 * @param message the packed message 778 * @param message the packed message
566 * @param importance what priority to send this message with 779 * @param importance what priority to send this message with
567 * @param timeout how long to possibly delay sending this message 780 * @param timeout how long to possibly delay sending this message
@@ -569,7 +782,9 @@ size_t core_transmit_notify (void *cls,
569static int 782static int
570send_message (const struct GNUNET_PeerIdentity * recipient, 783send_message (const struct GNUNET_PeerIdentity * recipient,
571 const struct GNUNET_PeerIdentity * sender, 784 const struct GNUNET_PeerIdentity * sender,
785 const struct DistantNeighbor * specific_neighbor,
572 const struct GNUNET_MessageHeader * message, 786 const struct GNUNET_MessageHeader * message,
787 size_t message_size,
573 unsigned int importance, struct GNUNET_TIME_Relative timeout) 788 unsigned int importance, struct GNUNET_TIME_Relative timeout)
574{ 789{
575 p2p_dv_MESSAGE_Data *toSend; 790 p2p_dv_MESSAGE_Data *toSend;
@@ -581,7 +796,7 @@ send_message (const struct GNUNET_PeerIdentity * recipient,
581 struct DistantNeighbor *source; 796 struct DistantNeighbor *source;
582 struct PendingMessage *pending_message; 797 struct PendingMessage *pending_message;
583 798
584 msg_size = ntohs (message->size) + sizeof (p2p_dv_MESSAGE_Data); 799 msg_size = message_size + sizeof (p2p_dv_MESSAGE_Data);
585 800
586 target = GNUNET_CONTAINER_multihashmap_get (ctx.extended_neighbors, 801 target = GNUNET_CONTAINER_multihashmap_get (ctx.extended_neighbors,
587 &recipient->hashPubKey); 802 &recipient->hashPubKey);
@@ -612,26 +827,25 @@ send_message (const struct GNUNET_PeerIdentity * recipient,
612 } 827 }
613 828
614 cost = target->cost; 829 cost = target->cost;
615 pending_message = GNUNET_malloc(sizeof(struct PendingMessage)); 830 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size);
616 pending_message->msg = GNUNET_malloc (msg_size); 831 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
617 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg; 832 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg;
618 toSend->header.size = htons (msg_size); 833 toSend->header.size = htons (msg_size);
619 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA); 834 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
620 toSend->sender = htonl (sender_id); 835 toSend->sender = htonl (sender_id);
621 toSend->recipient = htonl (recipient_id); 836 toSend->recipient = htonl (recipient_id);
622 memcpy (&toSend[1], message, ntohs (message->size)); 837 memcpy (&toSend[1], message, message_size);
623 pending_message->msg_size = msg_size;
624 838
625 pending_message->transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, importance, timeout, &target->referrer->identity, msg_size, &core_transmit_notify, pending_message); 839 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
626 if (NULL == pending_message->transmit_handle) 840 core_pending_tail,
627 { 841 core_pending_tail,
628 GNUNET_free (pending_message->msg); 842 pending_message);
629 GNUNET_free (pending_message); 843#if DEBUG_DV
630 return GNUNET_SYSERR; 844 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));
631 } 845#endif
846 if (core_transmit_handle == NULL)
847 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, importance, timeout, &target->referrer->identity, msg_size, &core_transmit_notify, NULL);
632 848
633 /*coreAPI->ciphertext_send (&target->referrer->identity,
634 &toSend->header, importance, maxdelay);*/
635 return (int) cost; 849 return (int) cost;
636} 850}
637 851
@@ -654,13 +868,8 @@ static int handle_dv_data_message (void *cls,
654 struct GNUNET_TIME_Relative latency, 868 struct GNUNET_TIME_Relative latency,
655 uint32_t distance) 869 uint32_t distance)
656{ 870{
657#if DEBUG_DV
658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
659 "%s: Receives %s message!\n", "dv", "DV DATA");
660#endif
661
662 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message; 871 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
663 const struct GNUNET_MessageHeader *packed_message = (const struct GNUNET_MessageHeader *) &incoming[1]; 872 const struct GNUNET_MessageHeader *packed_message;
664 struct DirectNeighbor *dn; 873 struct DirectNeighbor *dn;
665 struct DistantNeighbor *pos; 874 struct DistantNeighbor *pos;
666 unsigned int sid; /* Sender id */ 875 unsigned int sid; /* Sender id */
@@ -669,12 +878,22 @@ static int handle_dv_data_message (void *cls,
669 struct GNUNET_PeerIdentity destination; 878 struct GNUNET_PeerIdentity destination;
670 struct FindDestinationContext fdc; 879 struct FindDestinationContext fdc;
671 int ret; 880 int ret;
881 size_t packed_message_size;
882 char *cbuf;
883 size_t offset;
884
885 packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data);
672 886
673 if ((ntohs (incoming->header.size) < 887#if DEBUG_DV
674 sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader)) 888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
675 || (ntohs (incoming->header.size) != 889 "%s: Receives %s message size %d, packed message size %d!\n", "dv", "DV DATA", ntohs(incoming->header.size), packed_message_size);
676 (sizeof (p2p_dv_MESSAGE_Data) + ntohs (packed_message->size)))) 890#endif
891 if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader))
677 { 892 {
893#if DEBUG_DV
894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
895 "`%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));
896#endif
678 return GNUNET_SYSERR; 897 return GNUNET_SYSERR;
679 } 898 }
680 899
@@ -682,6 +901,10 @@ static int handle_dv_data_message (void *cls,
682 &peer->hashPubKey); 901 &peer->hashPubKey);
683 if (dn == NULL) 902 if (dn == NULL)
684 { 903 {
904#if DEBUG_DV
905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
906 "%s: dn NULL!\n", "dv");
907#endif
685 return GNUNET_OK; 908 return GNUNET_OK;
686 } 909 }
687 sid = ntohl (incoming->sender); 910 sid = ntohl (incoming->sender);
@@ -690,6 +913,10 @@ static int handle_dv_data_message (void *cls,
690 pos = pos->next; 913 pos = pos->next;
691 if (pos == NULL) 914 if (pos == NULL)
692 { 915 {
916#if DEBUG_DV
917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
918 "%s: unknown sender (%d), size of extended_peers is %d!\n", "dv", ntohl(incoming->sender), GNUNET_CONTAINER_multihashmap_size (ctx.extended_neighbors));
919#endif
693 /* unknown sender */ 920 /* unknown sender */
694 return GNUNET_OK; 921 return GNUNET_OK;
695 } 922 }
@@ -699,19 +926,31 @@ static int handle_dv_data_message (void *cls,
699 { 926 {
700 /* 0 == us */ 927 /* 0 == us */
701 928
702 /* FIXME: Will we support wrapped messages being these types? Probably not, they should 929 cbuf = (char *)&incoming[1];
703 * be encrypted messages that need decrypting and junk like that. 930 offset = 0;
704 */ 931 while(offset < packed_message_size)
705 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP); 932 {
706 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA); 933 packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset];
707 if ( (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) && 934#if DEBUG_DV
708 (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) ) 935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
709 { 936 "%s: Receives %s message for me, size %d type %d!\n", "dv", "DV DATA", ntohs(packed_message->size), ntohs(packed_message->type));
710 send_to_plugin(peer, packed_message, ntohs(packed_message->size), &pos->identity, pos->cost); 937#endif
711 } 938 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP);
939 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA);
940 if ( (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
941 (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) )
942 {
943 send_to_plugin(peer, packed_message, ntohs(packed_message->size), &pos->identity, pos->cost);
944 }
945 offset += ntohs(packed_message->size);
946 }
712 947
713 return GNUNET_OK; 948 return GNUNET_OK;
714 } 949 }
950 else
951 {
952 packed_message = (struct GNUNET_MessageHeader *)&incoming[1];
953 }
715 954
716 /* FIXME: this is the *only* per-request operation we have in DV 955 /* FIXME: this is the *only* per-request operation we have in DV
717 that is O(n) in relation to the number of connected peers; a 956 that is O(n) in relation to the number of connected peers; a
@@ -721,6 +960,12 @@ static int handle_dv_data_message (void *cls,
721 fdc.dest = NULL; 960 fdc.dest = NULL;
722 GNUNET_CONTAINER_heap_iterate (ctx.neighbor_max_heap, 961 GNUNET_CONTAINER_heap_iterate (ctx.neighbor_max_heap,
723 &find_destination, &fdc); 962 &find_destination, &fdc);
963
964#if DEBUG_DV
965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
966 "%s: Receives %s message for someone else!\n", "dv", "DV DATA");
967#endif
968
724 if (fdc.dest == NULL) 969 if (fdc.dest == NULL)
725 { 970 {
726 return GNUNET_OK; 971 return GNUNET_OK;
@@ -730,6 +975,9 @@ static int handle_dv_data_message (void *cls,
730 if (0 == memcmp (&destination, peer, sizeof (struct GNUNET_PeerIdentity))) 975 if (0 == memcmp (&destination, peer, sizeof (struct GNUNET_PeerIdentity)))
731 { 976 {
732 /* FIXME: create stat: routing loop-discard! */ 977 /* FIXME: create stat: routing loop-discard! */
978#if DEBUG_DV
979 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\n\n\nLoopy loo message\n\n\n");
980#endif
733 return GNUNET_OK; 981 return GNUNET_OK;
734 } 982 }
735 983
@@ -742,7 +990,11 @@ static int handle_dv_data_message (void *cls,
742 /*ret = send_message (&destination, 990 /*ret = send_message (&destination,
743 &original_sender, 991 &original_sender,
744 packed_message, DV_PRIORITY, DV_DELAY);*/ 992 packed_message, DV_PRIORITY, DV_DELAY);*/
745 ret = send_message(&destination, &original_sender, packed_message, default_dv_priority, default_dv_delay); 993#if DEBUG_DV
994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
995 "%s: Sends message size %d on!\n", "dv", packed_message_size);
996#endif
997 ret = send_message(&destination, &original_sender, NULL, packed_message, packed_message_size, default_dv_priority, default_dv_delay);
746 998
747 if (ret != GNUNET_SYSERR) 999 if (ret != GNUNET_SYSERR)
748 return GNUNET_OK; 1000 return GNUNET_OK;
@@ -761,13 +1013,12 @@ neighbor_send_task (void *cls,
761 const struct GNUNET_SCHEDULER_TaskContext *tc) 1013 const struct GNUNET_SCHEDULER_TaskContext *tc)
762{ 1014{
763 struct NeighborSendContext *send_context = cls; 1015 struct NeighborSendContext *send_context = cls;
764#if DEBUG_DV 1016#if DEBUG_DV_GOSSIP
765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
766 "%s: Entering neighbor_send_task...\n", 1018 "%s: Entering neighbor_send_task...\n",
767 GNUNET_i2s(&my_identity)); 1019 GNUNET_i2s(&my_identity));
768 char * encPeerAbout; 1020 char * encPeerAbout;
769 char * encPeerTo; 1021 char * encPeerTo;
770 struct GNUNET_PeerIdentity about_peer_id;
771#endif 1022#endif
772 struct DistantNeighbor *about; 1023 struct DistantNeighbor *about;
773 struct DirectNeighbor *to; 1024 struct DirectNeighbor *to;
@@ -777,7 +1028,7 @@ neighbor_send_task (void *cls,
777 1028
778 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 1029 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
779 { 1030 {
780#if DEBUG_DV 1031#if DEBUG_DV_GOSSIP
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "%s: Called with reason shutdown, shutting down!\n", 1033 "%s: Called with reason shutdown, shutting down!\n",
783 GNUNET_i2s(&my_identity)); 1034 GNUNET_i2s(&my_identity));
@@ -810,7 +1061,7 @@ neighbor_send_task (void *cls,
810 &to->identity, sizeof (struct GNUNET_PeerIdentity))) && 1061 &to->identity, sizeof (struct GNUNET_PeerIdentity))) &&
811 (about->pkey != NULL)) 1062 (about->pkey != NULL))
812 { 1063 {
813#if DEBUG_DV 1064#if DEBUG_DV_GOSSIP
814 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&about->identity)); 1065 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&about->identity));
815 encPeerTo = GNUNET_strdup(GNUNET_i2s(&to->identity)); 1066 encPeerTo = GNUNET_strdup(GNUNET_i2s(&to->identity));
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -820,8 +1071,8 @@ neighbor_send_task (void *cls,
820 GNUNET_free(encPeerAbout); 1071 GNUNET_free(encPeerAbout);
821 GNUNET_free(encPeerTo); 1072 GNUNET_free(encPeerTo);
822#endif 1073#endif
823 pending_message = GNUNET_malloc(sizeof(struct PendingMessage)); 1074 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_NeighborInfo));
824 pending_message->msg = GNUNET_malloc(sizeof(p2p_dv_MESSAGE_NeighborInfo)); 1075 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
825 message = (p2p_dv_MESSAGE_NeighborInfo *)pending_message->msg; 1076 message = (p2p_dv_MESSAGE_NeighborInfo *)pending_message->msg;
826 message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo)); 1077 message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo));
827 message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP); 1078 message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP);
@@ -832,26 +1083,14 @@ neighbor_send_task (void *cls,
832 memcpy (&message->neighbor, 1083 memcpy (&message->neighbor,
833 &about->identity, sizeof (struct GNUNET_PeerIdentity)); 1084 &about->identity, sizeof (struct GNUNET_PeerIdentity));
834 1085
835#if DEBUG_DV 1086 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
836 GNUNET_CRYPTO_hash (about->pkey, 1087 core_pending_tail,
837 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1088 core_pending_tail,
838 &about_peer_id.hashPubKey); 1089 pending_message);
839 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer id from message %s\n", GNUNET_i2s(&about->identity));
840 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer id from pubkey %s\n", GNUNET_i2s(&about_peer_id));
841#endif
842 1090
843 pending_message->msg_size = sizeof(p2p_dv_MESSAGE_NeighborInfo); 1091 if (core_transmit_handle == NULL)
844 pending_message->transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, default_dv_delay, &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, pending_message); 1092 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, default_dv_delay, &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);
845 1093
846 if (NULL == pending_message->transmit_handle)
847 {
848 GNUNET_free (pending_message->msg);
849 GNUNET_free (pending_message);
850 return;
851 }
852 /*coreAPI->ciphertext_send (&to->identity, &message.header,
853 GNUNET_DV_DHT_GOSSIP_PRIORITY,
854 ctx.send_interval);*/
855 } 1094 }
856 1095
857 send_context->task = GNUNET_SCHEDULER_add_delayed(sched, send_context->timeout, &neighbor_send_task, send_context); 1096 send_context->task = GNUNET_SCHEDULER_add_delayed(sched, send_context->timeout, &neighbor_send_task, send_context);
@@ -886,6 +1125,32 @@ handle_start (void *cls,
886 1125
887 1126
888/** 1127/**
1128 * Iterate over hash map entries for a distant neighbor,
1129 * if direct neighbor matches context call send message
1130 *
1131 * @param cls closure, a DV_SendContext
1132 * @param key current key code
1133 * @param value value in the hash map
1134 * @return GNUNET_YES if we should continue to
1135 * iterate,
1136 * GNUNET_NO if not.
1137 */
1138int send_iterator (void *cls,
1139 const GNUNET_HashCode * key,
1140 void *value)
1141{
1142 struct DV_SendContext *send_context = cls;
1143 struct DistantNeighbor *distant_neighbor = value;
1144
1145 if (memcmp(distant_neighbor->referrer, send_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */
1146 {
1147 send_message_via(&my_identity, distant_neighbor, send_context);
1148 return GNUNET_NO;
1149 }
1150 return GNUNET_YES;
1151}
1152
1153/**
889 * Service server's handler for message send requests (which come 1154 * Service server's handler for message send requests (which come
890 * bubbling up to us through the DV plugin). 1155 * bubbling up to us through the DV plugin).
891 * 1156 *
@@ -900,10 +1165,14 @@ void handle_dv_send_message (void *cls,
900 struct GNUNET_DV_SendMessage *send_msg; 1165 struct GNUNET_DV_SendMessage *send_msg;
901 size_t address_len; 1166 size_t address_len;
902 size_t message_size; 1167 size_t message_size;
903#if DEBUG_DV 1168 struct GNUNET_PeerIdentity *destination;
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1169 struct GNUNET_PeerIdentity *direct;
905 "%s: Receives %s message!\n\n\n", "dv", "SEND"); 1170 struct GNUNET_MessageHeader *message_buf;
906#endif 1171 char *temp_pos;
1172 int offset;
1173 static struct GNUNET_CRYPTO_HashAsciiEncoded dest_hash;
1174 struct DV_SendContext *send_context;
1175
907 if (client_handle == NULL) 1176 if (client_handle == NULL)
908 { 1177 {
909 client_handle = client; 1178 client_handle = client;
@@ -920,28 +1189,63 @@ void handle_dv_send_message (void *cls,
920 1189
921 GNUNET_assert(ntohs(message->size) > sizeof(struct GNUNET_DV_SendMessage)); 1190 GNUNET_assert(ntohs(message->size) > sizeof(struct GNUNET_DV_SendMessage));
922 send_msg = (struct GNUNET_DV_SendMessage *)message; 1191 send_msg = (struct GNUNET_DV_SendMessage *)message;
1192
923 address_len = ntohs(send_msg->addrlen); 1193 address_len = ntohs(send_msg->addrlen);
1194 GNUNET_assert(address_len == sizeof(struct GNUNET_PeerIdentity) * 2);
924 message_size = ntohs(send_msg->msgbuf_size); 1195 message_size = ntohs(send_msg->msgbuf_size);
1196
1197#if DEBUG_DV
1198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1199 "%s: Receives %s message size %u!\n\n\n", "dv", "SEND", message_size);
1200#endif
925 GNUNET_assert(ntohs(message->size) == sizeof(struct GNUNET_DV_SendMessage) + address_len + message_size); 1201 GNUNET_assert(ntohs(message->size) == sizeof(struct GNUNET_DV_SendMessage) + address_len + message_size);
1202 destination = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
1203 direct = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
1204 message_buf = GNUNET_malloc(message_size);
1205
1206 temp_pos = (char *)&send_msg[1]; /* Set pointer to end of message */
1207 offset = 0; /* Offset starts at zero */
1208
1209 memcpy(destination, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity));
1210 offset += sizeof(struct GNUNET_PeerIdentity);
1211
1212 memcpy(direct, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity));
1213 offset += sizeof(struct GNUNET_PeerIdentity);
1214
1215
1216 memcpy(message_buf, &temp_pos[offset], message_size);
1217 if (memcmp(&send_msg->target, destination, sizeof(struct GNUNET_PeerIdentity)) != 0)
1218 {
1219 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1220 dest_hash.encoding[4] = '\0';
1221 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);
1222 }
926 1223
927#if DEBUG_DV 1224#if DEBUG_DV
928 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV SEND called with message of size %d, address size %d\n", message_size, address_len); 1225 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1226 dest_hash.encoding[4] = '\0';
1227 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV SEND called with message of size %d type %d, destination `%s' via `%s'\n", message_size, ntohs(message_buf->type), (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
929#endif 1228#endif
930/* How this was created, opposite to get data */ 1229 send_context = GNUNET_malloc(sizeof(struct DV_SendContext));
931 /* 1230
932 msg = GNUNET_malloc(sizeof(struct GNUNET_DV_SendMessage) + addrlen + msgbuf_size); 1231 send_context->importance = ntohs(send_msg->priority);
933 msg->header.size = htons(sizeof(struct GNUNET_DV_SendMessage) + addrlen + msgbuf_size); 1232 send_context->timeout = send_msg->timeout;
934 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND); 1233 send_context->direct_peer = direct;
935 memcpy(&msg->target, target, sizeof(struct GNUNET_PeerIdentity)); 1234 send_context->distant_peer = destination;
936 msg->msgbuf_size = htons(msgbuf_size); 1235 send_context->message = message_buf;
937 msg->priority = htonl(priority); 1236 send_context->message_size = message_size;
938 msg->timeout = timeout; 1237
939 msg->addrlen = htons(addrlen); 1238 /* In bizarro world GNUNET_SYSERR indicates that we succeeded */
940 memcpy(&msg[1], addr, addrlen); 1239 if (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple(ctx.extended_neighbors, &destination->hashPubKey, &send_iterator, send_context))
941 end_of_message = (char *)&msg[1]; 1240 {
942 end_of_message = &end_of_message[addrlen]; 1241 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SEND failed to send message to destination `%s' via `%s'\n", (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
943 memcpy(end_of_message, msgbuf, msgbuf_size); 1242 }
944 */ 1243
1244 GNUNET_free(message_buf);
1245 GNUNET_free(send_context);
1246 GNUNET_free(direct);
1247 GNUNET_free(destination);
1248
945 GNUNET_SERVER_receive_done(client, GNUNET_OK); 1249 GNUNET_SERVER_receive_done(client, GNUNET_OK);
946} 1250}
947 1251
@@ -967,24 +1271,9 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
967 {NULL, 0, 0} 1271 {NULL, 0, 0}
968}; 1272};
969 1273
970
971#if DEBUG_DV
972static void handle_any(void *cls,
973 struct GNUNET_SERVER_Client * client,
974 const struct GNUNET_MessageHeader * message)
975{
976 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\n\n\n\n\n\nDV service receives message of type %d, size %d\n\n\n\n\n\n", ntohs(message->type), ntohs(message->size));
977 GNUNET_SERVER_receive_done (client, GNUNET_OK);
978}
979#endif
980
981
982static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { 1274static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
983 {&handle_dv_send_message, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND, 0}, 1275 {&handle_dv_send_message, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND, 0},
984 {&handle_start, NULL, GNUNET_MESSAGE_TYPE_DV_START, 0}, 1276 {&handle_start, NULL, GNUNET_MESSAGE_TYPE_DV_START, 0},
985#if DEBUG_DV
986 {&handle_any, NULL, GNUNET_MESSAGE_TYPE_ALL, 0},
987#endif
988 {NULL, NULL, 0, 0} 1277 {NULL, NULL, 0, 0}
989}; 1278};
990 1279
@@ -999,7 +1288,13 @@ static void
999shutdown_task (void *cls, 1288shutdown_task (void *cls,
1000 const struct GNUNET_SCHEDULER_TaskContext *tc) 1289 const struct GNUNET_SCHEDULER_TaskContext *tc)
1001{ 1290{
1291#if DEBUG_DV
1292 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n");
1293#endif
1002 GNUNET_CORE_disconnect (coreAPI); 1294 GNUNET_CORE_disconnect (coreAPI);
1295#if DEBUG_DV
1296 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n");
1297#endif
1003} 1298}
1004 1299
1005/** 1300/**
@@ -1041,22 +1336,11 @@ static int add_pkey_to_extended (void *cls,
1041{ 1336{
1042 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls; 1337 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls;
1043 struct DistantNeighbor *distant_neighbor = value; 1338 struct DistantNeighbor *distant_neighbor = value;
1044#if DEBUG_DV
1045 struct GNUNET_PeerIdentity about_peer_id;
1046#endif
1047 1339
1048 if (distant_neighbor->pkey == NULL) 1340 if (distant_neighbor->pkey == NULL)
1049 { 1341 {
1050 distant_neighbor->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1342 distant_neighbor->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1051 memcpy(distant_neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1343 memcpy(distant_neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1052#if DEBUG_DV
1053 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating pkey for extended list for peer %s\n", GNUNET_i2s(&distant_neighbor->identity));
1054 GNUNET_CRYPTO_hash (distant_neighbor->pkey,
1055 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1056 &about_peer_id.hashPubKey);
1057 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer id from setup %s\n", GNUNET_i2s(&distant_neighbor->identity));
1058 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peer id from pkey %s\n", GNUNET_i2s(&about_peer_id));
1059#endif
1060 } 1344 }
1061 1345
1062 return GNUNET_YES; 1346 return GNUNET_YES;
@@ -1118,6 +1402,35 @@ distant_neighbor_free (struct DistantNeighbor *referee)
1118} 1402}
1119 1403
1120 1404
1405#if DEBUG_DV_GOSSIP
1406/**
1407 * Iterator over hash map entries.
1408 *
1409 * @param cls closure (NULL)
1410 * @param key current key code
1411 * @param value value in the hash map (DistantNeighbor)
1412 * @return GNUNET_YES if we should continue to
1413 * iterate,
1414 * GNUNET_NO if not.
1415 */
1416int print_neighbors (void *cls,
1417 const GNUNET_HashCode * key,
1418 void *value)
1419{
1420 struct DistantNeighbor *distant_neighbor = value;
1421 char my_shortname[5];
1422 char referrer_shortname[5];
1423 memcpy(&my_shortname, GNUNET_i2s(&my_identity), 4);
1424 my_shortname[4] = '\0';
1425 memcpy(&referrer_shortname, GNUNET_i2s(&distant_neighbor->referrer->identity), 4);
1426 referrer_shortname[4] = '\0';
1427
1428 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s' %s: Peer `%s', distance %d, referrer `%s'\n", &my_shortname, "DV", GNUNET_i2s(&distant_neighbor->identity), distant_neighbor->cost, &referrer_shortname);
1429 return GNUNET_YES;
1430}
1431
1432#endif
1433
1121/** 1434/**
1122 * Handles when a peer is either added due to being newly connected 1435 * Handles when a peer is either added due to being newly connected
1123 * or having been gossiped about, also called when the cost for a neighbor 1436 * or having been gossiped about, also called when the cost for a neighbor
@@ -1215,18 +1528,21 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO
1215 } 1528 }
1216 else 1529 else
1217 { 1530 {
1218#if DEBUG_DV 1531#if DEBUG_DV_GOSSIP
1219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1220 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv", GNUNET_i2s(peer), cost, referrer_peer_id); 1533 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv", GNUNET_i2s(peer), cost, referrer_peer_id);
1221#endif 1534#endif
1222 } 1535 }
1223#if DEBUG_DV 1536#if DEBUG_DV_GOSSIP
1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1225 "%s: Size of extended_neighbors is %d\n", "dv", GNUNET_CONTAINER_multihashmap_size(ctx.extended_neighbors)); 1538 "%s: Size of extended_neighbors is %d\n", "dv", GNUNET_CONTAINER_multihashmap_size(ctx.extended_neighbors));
1539 GNUNET_CONTAINER_multihashmap_iterate(ctx.extended_neighbors, &print_neighbors, NULL);
1226#endif 1540#endif
1227 GNUNET_free(neighbor_update); 1541 GNUNET_free(neighbor_update);
1228 /* Old logic to remove entry and replace, not needed now as we only want to remove when full 1542 /* Old logic to remove entry and replace, not needed now as we only want to remove when full
1229 * or when the referring peer disconnects from us. 1543 * or when the referring peer disconnects from us.
1544 *
1545 * FIXME: add new functionality, or check if it already exists (i forget)
1230 */ 1546 */
1231 /* 1547 /*
1232 GNUNET_DLL_remove (neighbor->referrer->referee_head, 1548 GNUNET_DLL_remove (neighbor->referrer->referee_head,
@@ -1264,7 +1580,7 @@ generate_hello_address (void *cls, size_t max, void *buf)
1264 addr_buffer = GNUNET_malloc(size); 1580 addr_buffer = GNUNET_malloc(size);
1265 offset = 0; 1581 offset = 0;
1266 /* Copy the distant peer identity to buffer */ 1582 /* Copy the distant peer identity to buffer */
1267 memcpy(addr_buffer, hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)); 1583 memcpy(addr_buffer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity));
1268 offset += sizeof(struct GNUNET_PeerIdentity); 1584 offset += sizeof(struct GNUNET_PeerIdentity);
1269 /* Copy the direct peer identity to buffer */ 1585 /* Copy the direct peer identity to buffer */
1270 memcpy(&addr_buffer[offset], hello_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)); 1586 memcpy(&addr_buffer[offset], hello_context->direct_peer, sizeof(struct GNUNET_PeerIdentity));
@@ -1275,6 +1591,7 @@ generate_hello_address (void *cls, size_t max, void *buf)
1275 1591
1276 hello_context->addresses_to_add--; 1592 hello_context->addresses_to_add--;
1277 1593
1594 GNUNET_free(addr_buffer);
1278 return ret; 1595 return ret;
1279} 1596}
1280 1597
@@ -1309,7 +1626,7 @@ static int handle_dv_gossip_message (void *cls,
1309 return GNUNET_SYSERR; /* invalid message */ 1626 return GNUNET_SYSERR; /* invalid message */
1310 } 1627 }
1311 1628
1312#if DEBUG_DV 1629#if DEBUG_DV_GOSSIP
1313 char * encPeerAbout; 1630 char * encPeerAbout;
1314 char * encPeerFrom; 1631 char * encPeerFrom;
1315 1632
@@ -1332,17 +1649,18 @@ static int handle_dv_gossip_message (void *cls,
1332 1649
1333 hello_context = GNUNET_malloc(sizeof(struct HelloContext)); 1650 hello_context = GNUNET_malloc(sizeof(struct HelloContext));
1334 hello_context->direct_peer = peer; 1651 hello_context->direct_peer = peer;
1335 hello_context->distant_peer = &enc_message->neighbor; 1652 memcpy(&hello_context->distant_peer, &enc_message->neighbor, sizeof(struct GNUNET_PeerIdentity));
1336 hello_context->addresses_to_add = 1; 1653 hello_context->addresses_to_add = 1;
1337 hello_msg = GNUNET_HELLO_create(&enc_message->pkey, &generate_hello_address, hello_context); 1654 hello_msg = GNUNET_HELLO_create(&enc_message->pkey, &generate_hello_address, hello_context);
1338
1339 hello_hdr = GNUNET_HELLO_get_header(hello_msg); 1655 hello_hdr = GNUNET_HELLO_get_header(hello_msg);
1340#if DEBUG_DV 1656#if DEBUG_DV_GOSSIP
1341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1342 "%s: Sending %s message to plugin, type is %d, size %d!\n", "dv", "HELLO", ntohs(hello_hdr->type), ntohs(hello_hdr->size)); 1658 "%s: Sending %s message to plugin, type is %d, size %d!\n", "dv", "HELLO", ntohs(hello_hdr->type), ntohs(hello_hdr->size));
1343#endif 1659#endif
1344 1660
1345 send_to_plugin(hello_context->direct_peer, GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg), hello_context->distant_peer, ntohl(enc_message->cost) + 1); 1661 send_to_plugin(hello_context->direct_peer, GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg), &hello_context->distant_peer, ntohl(enc_message->cost) + 1);
1662 GNUNET_free(hello_context);
1663 GNUNET_free(hello_msg);
1346 return GNUNET_OK; 1664 return GNUNET_OK;
1347} 1665}
1348 1666
@@ -1354,15 +1672,10 @@ process_peerinfo (void *cls,
1354 struct PeerIteratorContext *peerinfo_iterator = cls; 1672 struct PeerIteratorContext *peerinfo_iterator = cls;
1355 struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor; 1673 struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor;
1356 1674
1357#if DEBUG_DV
1358 struct GNUNET_PeerIdentity about_peer_id;
1359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1360 "%s: process_peerinfo called!\n", "dv");
1361#endif
1362
1363 if ((peer == NULL))/* && (neighbor->pkey == NULL))*/ 1675 if ((peer == NULL))/* && (neighbor->pkey == NULL))*/
1364 { 1676 {
1365 /* FIXME: Remove peer! */ 1677 /* FIXME: Remove peer! */
1678 GNUNET_free(peerinfo_iterator);
1366 return; 1679 return;
1367 } 1680 }
1368 1681
@@ -1371,14 +1684,6 @@ process_peerinfo (void *cls,
1371 1684
1372 if ((hello != NULL) && (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK)) 1685 if ((hello != NULL) && (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK))
1373 { 1686 {
1374#if DEBUG_DV
1375 GNUNET_CRYPTO_hash (&neighbor->pkey,
1376 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1377 &about_peer_id.hashPubKey);
1378 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(peerinfo) Peer id from setup %s\n", GNUNET_i2s(&neighbor->identity));
1379 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "(peerinfo) Peer id from hello %s\n", GNUNET_i2s(&about_peer_id));
1380#endif
1381
1382 GNUNET_CONTAINER_multihashmap_get_multiple(ctx.extended_neighbors, 1687 GNUNET_CONTAINER_multihashmap_get_multiple(ctx.extended_neighbors,
1383 &peer->hashPubKey, 1688 &peer->hashPubKey,
1384 &add_pkey_to_extended, 1689 &add_pkey_to_extended,
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index f31801813..6faeaaea2 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -254,11 +254,13 @@ dv_plugin_send (void *cls,
254 addr, 254 addr,
255 addrlen); 255 addrlen);
256 256
257 if (ret == 0) 257 if (cont != NULL)
258 cont(cont_cls, target, GNUNET_OK); 258 {
259 else 259 if (ret == 0)
260 cont(cont_cls, target, GNUNET_SYSERR); 260 cont(cont_cls, target, GNUNET_OK);
261 261 else
262 cont(cont_cls, target, GNUNET_SYSERR);
263 }
262 return ret; 264 return ret;
263} 265}
264 266
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c
index 8b4593814..bacec6f0f 100644
--- a/src/dv/test_transport_api_dv.c
+++ b/src/dv/test_transport_api_dv.c
@@ -60,6 +60,8 @@ struct PeerContext
60 struct GNUNET_CONFIGURATION_Handle *cfg; 60 struct GNUNET_CONFIGURATION_Handle *cfg;
61 struct GNUNET_TRANSPORT_Handle *th; 61 struct GNUNET_TRANSPORT_Handle *th;
62 struct GNUNET_PeerIdentity id; 62 struct GNUNET_PeerIdentity id;
63 const char *cfg_file;
64 const struct GNUNET_HELLO_Message *hello;
63#if START_ARM 65#if START_ARM
64 pid_t arm_pid; 66 pid_t arm_pid;
65#endif 67#endif
@@ -88,11 +90,12 @@ static void
88end () 90end ()
89{ 91{
90 /* do work here */ 92 /* do work here */
91 GNUNET_assert (ok == 6);
92 GNUNET_SCHEDULER_cancel (sched, die_task); 93 GNUNET_SCHEDULER_cancel (sched, die_task);
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 1!\n");
94 GNUNET_TRANSPORT_disconnect (p1.th); 95 GNUNET_TRANSPORT_disconnect (p1.th);
96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 2!\n");
95 GNUNET_TRANSPORT_disconnect (p2.th); 97 GNUNET_TRANSPORT_disconnect (p2.th);
98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 3!\n");
96 GNUNET_TRANSPORT_disconnect (p3.th); 99 GNUNET_TRANSPORT_disconnect (p3.th);
97 100
98 die_task = GNUNET_SCHEDULER_NO_TASK; 101 die_task = GNUNET_SCHEDULER_NO_TASK;
@@ -104,8 +107,13 @@ static void
104stop_arm (struct PeerContext *p) 107stop_arm (struct PeerContext *p)
105{ 108{
106#if START_ARM 109#if START_ARM
107 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) 110 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
108 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 111 "gnunet-arm",
112#if VERBOSE
113 "-L", "DEBUG",
114#endif
115 "-c", p->cfg_file, "-e", NULL);
116
109 GNUNET_OS_process_wait (p->arm_pid); 117 GNUNET_OS_process_wait (p->arm_pid);
110#endif 118#endif
111 GNUNET_CONFIGURATION_destroy (p->cfg); 119 GNUNET_CONFIGURATION_destroy (p->cfg);
@@ -113,6 +121,34 @@ stop_arm (struct PeerContext *p)
113 121
114 122
115static void 123static void
124restart_transport (struct PeerContext *p)
125{
126#if START_ARM
127 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
128 "gnunet-arm",
129#if VERBOSE
130 "-L", "DEBUG",
131#endif
132 "-c", p->cfg_file, "-k", "transport", NULL);
133
134 fprintf(stderr, "stop arm command returned %d\n", p->arm_pid);
135 GNUNET_OS_process_wait (p->arm_pid);
136#endif
137
138#if START_ARM
139 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
140 "gnunet-arm",
141#if VERBOSE
142 "-L", "DEBUG",
143#endif
144 "-c", p->cfg_file, "-i", "transport", NULL);
145
146 GNUNET_OS_process_wait (p->arm_pid);
147#endif
148}
149
150
151static void
116end_badly () 152end_badly ()
117{ 153{
118 /* do work here */ 154 /* do work here */
@@ -139,17 +175,12 @@ notify_receive (void *cls,
139 if (ntohs(message->type) != MTYPE) 175 if (ntohs(message->type) != MTYPE)
140 return; 176 return;
141 177
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p)!\n", 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p) distance %d!\n",
143 ntohs(message->type), cls); 179 ntohs(message->type), cls, distance);
144
145 GNUNET_assert (ok == 5);
146 OKPP;
147 180
148 GNUNET_assert (MTYPE == ntohs (message->type)); 181 GNUNET_assert (MTYPE == ntohs (message->type));
149 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 182 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
150 ntohs (message->size)); 183 ntohs (message->size));
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer (%p)!\n",
152 cls);
153 end (); 184 end ();
154} 185}
155 186
@@ -162,8 +193,7 @@ notify_ready (void *cls, size_t size, void *buf)
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Transmitting message to peer (%p) - %u!\n", cls, size); 194 "Transmitting message to peer (%p) - %u!\n", cls, size);
164 GNUNET_assert (size >= 256); 195 GNUNET_assert (size >= 256);
165 GNUNET_assert (ok == 4); 196
166 OKPP;
167 if (buf != NULL) 197 if (buf != NULL)
168 { 198 {
169 hdr = buf; 199 hdr = buf;
@@ -181,17 +211,36 @@ notify_connect (void *cls,
181 struct GNUNET_TIME_Relative latency, 211 struct GNUNET_TIME_Relative latency,
182 uint32_t distance) 212 uint32_t distance)
183{ 213{
214 int peer_num = 0;
215 int connect_num = 0;
216
217 if (cls == &p1)
218 peer_num = 1;
219 else if (cls == &p2)
220 peer_num = 2;
221 else if (cls == &p3)
222 peer_num = 3;
223
224 if (memcmp(peer, &p1.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
225 connect_num = 1;
226 else if (memcmp(peer, &p2.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
227 connect_num = 2;
228 else if (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
229 connect_num = 3;
230
184 if ((cls == &p1) && (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0)) 231 if ((cls == &p1) && (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0))
185 { 232 {
233
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Peer 1 notified about connection to peer 3!\n", GNUNET_i2s (peer), cls); 235 "Peer 1 notified about connection to peer 3, distance %d!\n", GNUNET_i2s (peer), cls, distance);
188 GNUNET_TRANSPORT_notify_transmit_ready (p1.th, 236
237 GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
189 &p3.id, 238 &p3.id,
190 256, 0, TIMEOUT, &notify_ready, 239 256, 0, TIMEOUT, &notify_ready,
191 &p1); 240 &p1);
192 } 241 }
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); 243 "Peer `%d' connected to peer `%d' distance %d!\n", peer_num, connect_num, distance);
195} 244}
196 245
197 246
@@ -208,21 +257,44 @@ static void
208setup_peer (struct PeerContext *p, const char *cfgname) 257setup_peer (struct PeerContext *p, const char *cfgname)
209{ 258{
210 p->cfg = GNUNET_CONFIGURATION_create (); 259 p->cfg = GNUNET_CONFIGURATION_create ();
260 p->cfg_file = strdup(cfgname);
211#if START_ARM 261#if START_ARM
212 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 262 p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
213 "gnunet-service-arm", 263 "gnunet-arm",
214#if VERBOSE_ARM 264#if VERBOSE_ARM
215 "-L", "DEBUG", 265 "-L", "DEBUG",
216#endif 266#endif
217 "-c", cfgname, NULL); 267 "-c", cfgname, "-s", NULL);
218#endif 268#endif
219 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 269 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
220 270
221 p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, 271 /*p->th = GNUNET_TRANSPORT_connect (sched, p->cfg,
222 p, 272 p,
223 &notify_receive, 273 &notify_receive,
224 &notify_connect, &notify_disconnect); 274 &notify_connect, &notify_disconnect);*/
225 GNUNET_assert (p->th != NULL); 275 /*GNUNET_assert (p->th != NULL);*/
276}
277
278
279static void
280exchange_hello_last (void *cls,
281 const struct GNUNET_MessageHeader *message)
282{
283 struct PeerContext *me = cls;
284
285 GNUNET_TRANSPORT_get_hello_cancel (p3.th, &exchange_hello_last, me);
286
287 GNUNET_assert (message != NULL);
288 GNUNET_assert (GNUNET_OK ==
289 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
290 message, &me->id));
291
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
294
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
296 "Finished exchanging HELLOs, now waiting for transmission!\n");
297
226} 298}
227 299
228 300
@@ -235,8 +307,7 @@ exchange_hello_next (void *cls,
235 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_next, me); 307 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_next, me);
236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
237 "Exchanging HELLO with peer (%p)!\n", cls); 309 "Exchanging HELLO with peer (%p)!\n", cls);
238 GNUNET_assert (ok >= 3); 310
239 OKPP;
240 GNUNET_assert (message != NULL); 311 GNUNET_assert (message != NULL);
241 GNUNET_assert (GNUNET_OK == 312 GNUNET_assert (GNUNET_OK ==
242 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 313 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
@@ -247,8 +318,8 @@ exchange_hello_next (void *cls,
247 318
248 GNUNET_TRANSPORT_offer_hello (p3.th, message); 319 GNUNET_TRANSPORT_offer_hello (p3.th, message);
249 320
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 321 GNUNET_TRANSPORT_get_hello (p3.th, &exchange_hello_last, &p3);
251 "Finished exchanging HELLOs, now waiting for transmission!\n"); 322
252 323
253} 324}
254 325
@@ -260,10 +331,16 @@ exchange_hello (void *cls,
260 struct PeerContext *me = cls; 331 struct PeerContext *me = cls;
261 332
262 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me); 333 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me);
334 p2.th = GNUNET_TRANSPORT_connect (sched, p2.cfg,
335 &p2,
336 &notify_receive,
337 &notify_connect, &notify_disconnect);
338
339 GNUNET_assert(p2.th != NULL);
340
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Exchanging HELLO with peer (%p)!\n", cls); 342 "Exchanging HELLO with peer (%p)!\n", cls);
265 GNUNET_assert (ok >= 2); 343
266 OKPP;
267 GNUNET_assert (message != NULL); 344 GNUNET_assert (message != NULL);
268 GNUNET_assert (GNUNET_OK == 345 GNUNET_assert (GNUNET_OK ==
269 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 346 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
@@ -277,6 +354,115 @@ exchange_hello (void *cls,
277} 354}
278 355
279static void 356static void
357blacklist_setup_third (void *cls,
358 const struct GNUNET_MessageHeader *message)
359{
360 struct PeerContext *me = cls;
361 char *blacklist_filename;
362 struct GNUNET_DISK_FileHandle *file;
363 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
364 char *buf;
365 size_t size;
366
367 GNUNET_TRANSPORT_get_hello_cancel (p3.th, &blacklist_setup_third, &p3);
368
369 GNUNET_assert (message != NULL);
370 GNUNET_assert (GNUNET_OK ==
371 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
372 message, &me->id));
373
374 GNUNET_asprintf(&blacklist_filename, "/tmp/test-gnunetd-transport-peer-1/blacklist");
375 if (blacklist_filename != NULL)
376 {
377 file = GNUNET_DISK_file_open(blacklist_filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE,
378 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
379 GNUNET_free(blacklist_filename);
380
381 if (file == NULL)
382 {
383 GNUNET_SCHEDULER_cancel(sched, die_task);
384 GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
385 return;
386 }
387 GNUNET_CRYPTO_hash_to_enc(&me->id.hashPubKey, &peer_enc);
388 size = GNUNET_asprintf(&buf, "%s:%s\n", "tcp", (char *)&peer_enc);
389 GNUNET_DISK_file_write(file, buf, size);
390 GNUNET_free_non_null(buf);
391 }
392
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", cls, p1.cfg_file);
395
396 restart_transport(&p1);
397
398 p1.th = GNUNET_TRANSPORT_connect (sched, p1.cfg,
399 &p1,
400 &notify_receive,
401 &notify_connect, &notify_disconnect);
402
403 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
404}
405
406static void
407blacklist_setup_first (void *cls,
408 const struct GNUNET_MessageHeader *message)
409{
410 struct PeerContext *me = cls;
411 char *blacklist_filename;
412 struct GNUNET_DISK_FileHandle *file;
413 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
414 char *buf;
415 size_t size;
416
417 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &blacklist_setup_first, me);
418 sleep(2);
419
420 GNUNET_assert (message != NULL);
421 GNUNET_assert (GNUNET_OK ==
422 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
423 message, &me->id));
424
425 GNUNET_asprintf(&blacklist_filename, "/tmp/test-gnunetd-transport-peer-3/blacklist");
426 if (blacklist_filename != NULL)
427 {
428 file = GNUNET_DISK_file_open(blacklist_filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE,
429 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
430 GNUNET_free(blacklist_filename);
431
432 if (file == NULL)
433 {
434 GNUNET_SCHEDULER_cancel(sched, die_task);
435 GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
436 return;
437 }
438 GNUNET_CRYPTO_hash_to_enc(&me->id.hashPubKey, &peer_enc);
439 size = GNUNET_asprintf(&buf, "%s:%s\n", "tcp", (char *)&peer_enc);
440 GNUNET_DISK_file_write(file, buf, size);
441 GNUNET_free_non_null(buf);
442 }
443
444 GNUNET_TRANSPORT_disconnect(p1.th);
445
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", cls, p3.cfg_file);
448 restart_transport(&p3);
449
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
451 "reconnecting to transport (%p)!\n", cls);
452 p3.th = GNUNET_TRANSPORT_connect (sched, p3.cfg,
453 &p3,
454 &notify_receive,
455 &notify_connect, &notify_disconnect);
456 if (p3.th != NULL)
457 GNUNET_TRANSPORT_get_hello (p3.th, &blacklist_setup_third, &p3);
458 else
459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
460 "reconnecting to transport (%p) failed.!\n", cls);
461 //GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
462}
463
464
465static void
280run (void *cls, 466run (void *cls,
281 struct GNUNET_SCHEDULER_Handle *s, 467 struct GNUNET_SCHEDULER_Handle *s,
282 char *const *args, 468 char *const *args,
@@ -293,11 +479,15 @@ run (void *cls,
293 setup_peer (&p2, "test_transport_api_dv_peer2.conf"); 479 setup_peer (&p2, "test_transport_api_dv_peer2.conf");
294 setup_peer (&p3, "test_transport_api_dv_peer3.conf"); 480 setup_peer (&p3, "test_transport_api_dv_peer3.conf");
295 481
482 p1.th = GNUNET_TRANSPORT_connect (sched, p1.cfg,
483 &p1,
484 &notify_receive,
485 &notify_connect, &notify_disconnect);
296 GNUNET_assert(p1.th != NULL); 486 GNUNET_assert(p1.th != NULL);
297 GNUNET_assert(p2.th != NULL); 487 /*GNUNET_assert(p2.th != NULL);
298 GNUNET_assert(p3.th != NULL); 488 GNUNET_assert(p3.th != NULL);*/
299 489
300 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 490 GNUNET_TRANSPORT_get_hello (p1.th, &blacklist_setup_first, &p1);
301} 491}
302 492
303static int 493static int
diff --git a/src/dv/test_transport_api_dv_peer1.conf b/src/dv/test_transport_api_dv_peer1.conf
index f5621f1b3..eee6af02d 100644
--- a/src/dv/test_transport_api_dv_peer1.conf
+++ b/src/dv/test_transport_api_dv_peer1.conf
@@ -59,6 +59,7 @@ CONFIG = $DEFAULTCONFIG
59HOME = $SERVICEHOME 59HOME = $SERVICEHOME
60HOSTNAME = localhost 60HOSTNAME = localhost
61PORT = 12365 61PORT = 12365
62BLACKLIST_FILE = $SERVICEHOME/blacklist
62 63
63[peerinfo] 64[peerinfo]
64TRUST = $SERVICEHOME/data/credit/ 65TRUST = $SERVICEHOME/data/credit/
@@ -97,10 +98,10 @@ DEBUG = NO
97ALLOW_SHUTDOWN = YES 98ALLOW_SHUTDOWN = YES
98ACCEPT_FROM6 = ::1; 99ACCEPT_FROM6 = ::1;
99ACCEPT_FROM = 127.0.0.1; 100ACCEPT_FROM = 127.0.0.1;
100BINARY = gnunet-service-dv 101#BINARY = gnunet-service-dv
101#BINARY = /root/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv 102BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv
102#PREFIX = xterm -T dvservice -e gdb --args 103#PREFIX = xterm -T dvservice -e gdb --args
103#PREFIX = valgrind --log-file=dv-%p --leak-check=full 104#PREFIX = valgrind --log-file=dv1-%p --leak-check=full
104CONFIG = $DEFAULTCONFIG 105CONFIG = $DEFAULTCONFIG
105HOME = $SERVICEHOME 106HOME = $SERVICEHOME
106HOSTNAME = localhost 107HOSTNAME = localhost
diff --git a/src/dv/test_transport_api_dv_peer2.conf b/src/dv/test_transport_api_dv_peer2.conf
index 194f43405..3bd14c274 100644
--- a/src/dv/test_transport_api_dv_peer2.conf
+++ b/src/dv/test_transport_api_dv_peer2.conf
@@ -71,6 +71,7 @@ HOSTNAME = localhost
71PORT = 22365 71PORT = 22365
72#PREFIX = xterm -T transport1 -e gdb --command=cmd --args 72#PREFIX = xterm -T transport1 -e gdb --command=cmd --args
73#PREFIX = valgrind --leak-check=full 73#PREFIX = valgrind --leak-check=full
74BLACKLIST_FILE = $SERVICEHOME/blacklist
74 75
75[peerinfo] 76[peerinfo]
76TRUST = $SERVICEHOME/data/credit/ 77TRUST = $SERVICEHOME/data/credit/
@@ -110,8 +111,8 @@ ALLOW_SHUTDOWN = YES
110ACCEPT_FROM6 = ::1; 111ACCEPT_FROM6 = ::1;
111ACCEPT_FROM = 127.0.0.1; 112ACCEPT_FROM = 127.0.0.1;
112BINARY = gnunet-service-dv 113BINARY = gnunet-service-dv
113#BINARY = /root/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv 114#BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv
114#PREFIX = xterm -T dvservice -e gdb --args 115#PREFIX = xterm -T dvservice2 -e gdb --args
115CONFIG = $DEFAULTCONFIG 116CONFIG = $DEFAULTCONFIG
116HOME = $SERVICEHOME 117HOME = $SERVICEHOME
117HOSTNAME = localhost 118HOSTNAME = localhost
diff --git a/src/dv/test_transport_api_dv_peer3.conf b/src/dv/test_transport_api_dv_peer3.conf
index 8ec149b26..0adf5d128 100644
--- a/src/dv/test_transport_api_dv_peer3.conf
+++ b/src/dv/test_transport_api_dv_peer3.conf
@@ -46,12 +46,12 @@ MINIMUM-FRIENDS = 0
46 46
47[transport] 47[transport]
48PLUGINS = tcp dv 48PLUGINS = tcp dv
49DEBUG = NO 49DEBUG = YES
50ALLOW_SHUTDOWN = YES 50ALLOW_SHUTDOWN = YES
51ACCEPT_FROM6 = ::1; 51ACCEPT_FROM6 = ::1;
52ACCEPT_FROM = 127.0.0.1; 52ACCEPT_FROM = 127.0.0.1;
53NEIGHBOUR_LIMIT = 50 53NEIGHBOUR_LIMIT = 50
54#BINARY = /root/documents/research/gnunet/gnunet-ng/src/transport/.libs/gnunet-service-transport 54BINARY = /root/documents/research/gnunet/gnunet-ng/src/transport/.libs/gnunet-service-transport
55BINARY = gnunet-service-transport 55BINARY = gnunet-service-transport
56CONFIG = $DEFAULTCONFIG 56CONFIG = $DEFAULTCONFIG
57HOME = $SERVICEHOME 57HOME = $SERVICEHOME
@@ -59,6 +59,7 @@ HOSTNAME = localhost
59PORT = 32365 59PORT = 32365
60#PREFIX = xterm -T transport1 -e gdb --command=cmd --args 60#PREFIX = xterm -T transport1 -e gdb --command=cmd --args
61#PREFIX = valgrind --leak-check=full 61#PREFIX = valgrind --leak-check=full
62BLACKLIST_FILE = $SERVICEHOME/blacklist
62 63
63[peerinfo] 64[peerinfo]
64TRUST = $SERVICEHOME/data/credit/ 65TRUST = $SERVICEHOME/data/credit/
@@ -105,11 +106,13 @@ HOSTNAME = localhost
105PORT = 32367 106PORT = 32367
106 107
107[dv] 108[dv]
108DEBUG = NO 109DEBUG = YES
109ALLOW_SHUTDOWN = YES 110ALLOW_SHUTDOWN = YES
110ACCEPT_FROM6 = ::1; 111ACCEPT_FROM6 = ::1;
111ACCEPT_FROM = 127.0.0.1; 112ACCEPT_FROM = 127.0.0.1;
112BINARY = gnunet-service-dv 113BINARY = gnunet-service-dv
114#BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv
115#PREFIX = xterm -T dvservice3 -e gdb --args
113CONFIG = $DEFAULTCONFIG 116CONFIG = $DEFAULTCONFIG
114HOME = $SERVICEHOME 117HOME = $SERVICEHOME
115HOSTNAME = localhost 118HOSTNAME = localhost