aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-07 08:59:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-07 08:59:35 +0000
commit41782f780885e665071a8cf0d4d3e89a4509e398 (patch)
treea5df28d7e5d1738453990395fc1047ed2440c398 /src/transport/gnunet-service-transport_neighbours.c
parent4a7ea21113603575b97c37eea5c4ee93d1c376bc (diff)
downloadgnunet-41782f780885e665071a8cf0d4d3e89a4509e398.tar.gz
gnunet-41782f780885e665071a8cf0d4d3e89a4509e398.zip
implementing some neighbours fun
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c129
1 files changed, 117 insertions, 12 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index a3fdab9b7..d915261ec 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-transport_neighbours.h" 27#include "gnunet-service-transport_neighbours.h"
28#include "gnunet-service-transport.h" 28#include "gnunet-service-transport.h"
29#include "gnunet_peerinfo_service.h"
29#include "gnunet_constants.h" 30#include "gnunet_constants.h"
30 31
31 32
@@ -102,7 +103,6 @@ struct MessageQueue
102}; 103};
103 104
104 105
105
106/** 106/**
107 * Entry in neighbours. 107 * Entry in neighbours.
108 */ 108 */
@@ -191,6 +191,11 @@ struct NeighbourMapEntry
191 * DV distance to this peer (1 if no DV is used). 191 * DV distance to this peer (1 if no DV is used).
192 */ 192 */
193 uint32_t distance; 193 uint32_t distance;
194
195 /**
196 * Number of values in 'ats' array.
197 */
198 unsigned int ats_count;
194 199
195 /** 200 /**
196 * Have we seen an PONG from this neighbour in the past (and 201 * Have we seen an PONG from this neighbour in the past (and
@@ -232,6 +237,20 @@ static GNUNET_TRANSPORT_NotifyConnect connect_notify_cb;
232static GNUNET_TRANSPORT_NotifyDisconnect disconnect_notify_cb; 237static GNUNET_TRANSPORT_NotifyDisconnect disconnect_notify_cb;
233 238
234 239
240/**
241 * Lookup a neighbour entry in the neighbours hash map.
242 *
243 * @param pid identity of the peer to look up
244 * @return the entry, NULL if there is no existing record
245 */
246static struct NeighbourMapEntry *
247lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
248{
249 return GNUNET_CONTAINER_multihashmap_get (neighbours,
250 &pid->hashPubKey);
251}
252
253
235#if 0 254#if 0
236/** 255/**
237 * Check the ready list for the given neighbour and if a plugin is 256 * Check the ready list for the given neighbour and if a plugin is
@@ -555,6 +574,41 @@ GST_neighbours_start (void *cls,
555 574
556 575
557/** 576/**
577 * Disconnect from the given neighbour, clean up the record.
578 *
579 * @param n neighbour to disconnect from
580 */
581static void
582disconnect_neighbour (struct NeighbourMapEntry *n)
583{
584 struct MessageQueue *mq;
585
586 disconnect_notify_cb (callback_cls,
587 &n->id);
588 GNUNET_assert (GNUNET_YES ==
589 GNUNET_CONTAINER_multihashmap_remove (neighbours,
590 &n->id.hashPubKey,
591 n));
592 while (NULL != (mq = n->messages_head))
593 {
594 GNUNET_CONTAINER_DLL_remove (n->messages_head,
595 n->messages_tail,
596 mq);
597 GNUNET_free (mq);
598 }
599 if (NULL != n->piter)
600 {
601 GNUNET_PEERINFO_iterate_cancel (n->piter);
602 n->piter = NULL;
603 }
604 GNUNET_array_grow (n->ats,
605 n->ats_count,
606 0);
607 GNUNET_free (n);
608}
609
610
611/**
558 * Disconnect from the given neighbour. 612 * Disconnect from the given neighbour.
559 * 613 *
560 * @param cls unused 614 * @param cls unused
@@ -574,9 +628,7 @@ disconnect_all_neighbours (void *cls,
574 GNUNET_i2s(&n->id), 628 GNUNET_i2s(&n->id),
575 "SHUTDOWN_TASK"); 629 "SHUTDOWN_TASK");
576#endif 630#endif
577 // FIXME: 631 disconnect_neighbour (n);
578 // disconnect_neighbour (n);
579 n++;
580 return GNUNET_OK; 632 return GNUNET_OK;
581} 633}
582 634
@@ -649,12 +701,12 @@ void
649GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour, 701GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
650 struct GNUNET_BANDWIDTH_Value32NBO quota) 702 struct GNUNET_BANDWIDTH_Value32NBO quota)
651{ 703{
652#if 0 704 struct NeighbourMapEntry *n;
653 705
654 n = find_neighbour (neighbour); 706 n = lookup_neighbour (neighbour);
655 if (n == NULL) 707 if (n == NULL)
656 { 708 {
657 GNUNET_STATISTICS_update (stats, 709 GNUNET_STATISTICS_update (GST_stats,
658 gettext_noop ("# SET QUOTA messages ignored (no such peer)"), 710 gettext_noop ("# SET QUOTA messages ignored (no such peer)"),
659 1, 711 1,
660 GNUNET_NO); 712 GNUNET_NO);
@@ -662,7 +714,7 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
662 } 714 }
663 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, 715 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
664 quota); 716 quota);
665 if (0 != ntohl (qsm->quota.value__)) 717 if (0 != ntohl (quota.value__))
666 return; 718 return;
667#if DEBUG_TRANSPORT 719#if DEBUG_TRANSPORT
668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -670,13 +722,11 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
670 GNUNET_i2s(&n->id), 722 GNUNET_i2s(&n->id),
671 "SET_QUOTA"); 723 "SET_QUOTA");
672#endif 724#endif
673 GNUNET_STATISTICS_update (stats, 725 GNUNET_STATISTICS_update (GST_stats,
674 gettext_noop ("# disconnects due to quota of 0"), 726 gettext_noop ("# disconnects due to quota of 0"),
675 1, 727 1,
676 GNUNET_NO); 728 GNUNET_NO);
677 GST_neighbours_force_disconnect (neighbour); 729 disconnect_neighbour (n);
678
679#endif
680} 730}
681 731
682 732
@@ -688,6 +738,54 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
688void 738void
689GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) 739GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
690{ 740{
741 struct NeighbourMapEntry *n;
742
743 n = lookup_neighbour (target);
744 disconnect_neighbour (n);
745}
746
747
748/**
749 * Closure for the neighbours_iterate function.
750 */
751struct IteratorContext
752{
753 /**
754 * Function to call on each connected neighbour.
755 */
756 GST_NeighbourIterator cb;
757
758 /**
759 * Closure for 'cb'.
760 */
761 void *cb_cls;
762};
763
764
765/**
766 * Call the callback from the closure for each connected neighbour.
767 *
768 * @param cls the 'struct IteratorContext'
769 * @param key the hash of the public key of the neighbour
770 * @param value the 'struct NeighbourMapEntry'
771 * @return GNUNET_OK (continue to iterate)
772 */
773static int
774neighbours_iterate (void *cls,
775 const GNUNET_HashCode *key,
776 void *value)
777{
778 struct IteratorContext *ic = cls;
779 struct NeighbourMapEntry *n = value;
780
781 if (GNUNET_TIME_absolute_get_remaining (n->peer_timeout).rel_value == 0)
782 return GNUNET_OK; /* not connected */
783 GNUNET_assert (n->ats_count > 0);
784 ic->cb (ic->cb_cls,
785 &n->id,
786 n->ats,
787 n->ats_count - 1);
788 return GNUNET_OK;
691} 789}
692 790
693 791
@@ -701,6 +799,13 @@ void
701GST_neighbours_iterate (GST_NeighbourIterator cb, 799GST_neighbours_iterate (GST_NeighbourIterator cb,
702 void *cb_cls) 800 void *cb_cls)
703{ 801{
802 struct IteratorContext ic;
803
804 ic.cb = cb;
805 ic.cb_cls = cb_cls;
806 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
807 &neighbours_iterate,
808 &ic);
704} 809}
705 810
706 811