aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-01-15 20:13:59 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-19 12:41:01 +0100
commita98b548418bd0dcb8882ef913bcc2fbb516e0f2c (patch)
treecc01a85acc08d4e01cd6c26e07ec9cd12fb36c94 /src/dht/gnunet-service-dht_neighbours.c
parent4c3b6b2197ba4fb8d9d696c2a8ca9a170ad12529 (diff)
downloadgnunet-a98b548418bd0dcb8882ef913bcc2fbb516e0f2c.tar.gz
gnunet-a98b548418bd0dcb8882ef913bcc2fbb516e0f2c.zip
-add hold/drop logic
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c61
1 files changed, 55 insertions, 6 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index b7b5e8097..213308ca6 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -281,7 +281,7 @@ struct Target
281 /** 281 /**
282 * Underlay providing this target. 282 * Underlay providing this target.
283 */ 283 */
284 struct Underlay *u; 284 struct GDS_Underlay *u;
285 285
286 /** 286 /**
287 * Peer this is a target for. 287 * Peer this is a target for.
@@ -289,6 +289,11 @@ struct Target
289 struct PeerInfo *pi; 289 struct PeerInfo *pi;
290 290
291 /** 291 /**
292 * Handle used to 'hold' the connection to this peer.
293 */
294 struct GNUNET_DHTU_PreferenceHandle *ph;
295
296 /**
292 * Set to number of messages are waiting for the transmission to finish. 297 * Set to number of messages are waiting for the transmission to finish.
293 */ 298 */
294 unsigned int load; 299 unsigned int load;
@@ -686,15 +691,48 @@ send_find_peer_message (void *cls)
686} 691}
687 692
688 693
694/**
695 * The list of the first #bucket_size peers of @a bucket
696 * changed. We should thus make sure we have called 'hold'
697 * all of the first bucket_size peers!
698 *
699 * @param[in,out] bucket the bucket where the peer set changed
700 */
701static void
702update_hold (struct PeerBucket *bucket)
703{
704 unsigned int off = 0;
705
706 /* find the peer -- we just go over all of them, should
707 be hardly any more expensive than just finding the 'right'
708 one. */
709 for (struct PeerInfo *pos = bucket->head;
710 NULL != pos;
711 pos = pos->next)
712 {
713 if (off > bucket_size)
714 break; /* We only hold up to #bucket_size peers per bucket */
715 bucket_size++;
716 for (struct Target *tp = pos->t_head;
717 NULL != tp;
718 tp = tp->next)
719 if (NULL == tp->ph)
720 tp->ph = GDS_u_hold (tp->u,
721 tp->utarget);
722 }
723}
724
725
689void 726void
690GDS_u_connect (void *cls, 727GDS_u_connect (void *cls,
691 struct GNUNET_DHTU_Target *target, 728 struct GNUNET_DHTU_Target *target,
692 const struct GNUNET_PeerIdentity *pid, 729 const struct GNUNET_PeerIdentity *pid,
693 void **ctx) 730 void **ctx)
694{ 731{
695 struct Underlay *u = cls; 732 struct GDS_Underlay *u = cls;
696 struct PeerInfo *pi; 733 struct PeerInfo *pi;
697 struct PeerBucket *bucket; 734 struct PeerBucket *bucket;
735 bool do_hold = false;
698 736
699 /* Check for connect to self message */ 737 /* Check for connect to self message */
700 if (0 == GNUNET_memcmp (&GDS_my_identity, 738 if (0 == GNUNET_memcmp (&GDS_my_identity,
@@ -734,7 +772,7 @@ GDS_u_connect (void *cls,
734 if (bucket->peers_size <= bucket_size) 772 if (bucket->peers_size <= bucket_size)
735 { 773 {
736 newly_found_peers++; 774 newly_found_peers++;
737 // FIXME: call 'hold'! 775 do_hold = true;
738 } 776 }
739 if ( (1 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && 777 if ( (1 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) &&
740 (GNUNET_YES != disable_try_connect) ) 778 (GNUNET_YES != disable_try_connect) )
@@ -758,6 +796,8 @@ GDS_u_connect (void *cls,
758 *ctx = t; 796 *ctx = t;
759 797
760 } 798 }
799 if (do_hold)
800 update_hold (bucket);
761} 801}
762 802
763 803
@@ -767,6 +807,7 @@ GDS_u_disconnect (void *ctx)
767 struct Target *t = ctx; 807 struct Target *t = ctx;
768 struct PeerInfo *pi; 808 struct PeerInfo *pi;
769 struct PeerBucket *bucket; 809 struct PeerBucket *bucket;
810 bool was_held = false;
770 811
771 /* Check for disconnect from self message (on shutdown) */ 812 /* Check for disconnect from self message (on shutdown) */
772 if (NULL == t) 813 if (NULL == t)
@@ -775,6 +816,13 @@ GDS_u_disconnect (void *ctx)
775 GNUNET_CONTAINER_DLL_remove (pi->t_head, 816 GNUNET_CONTAINER_DLL_remove (pi->t_head,
776 pi->t_tail, 817 pi->t_tail,
777 t); 818 t);
819 if (NULL != t->ph)
820 {
821 GDS_u_drop (t->u,
822 t->ph);
823 t->ph = NULL;
824 was_held = true;
825 }
778 if (t->load > 0) 826 if (t->load > 0)
779 { 827 {
780 t->dropped = true; 828 t->dropped = true;
@@ -810,8 +858,9 @@ GDS_u_disconnect (void *ctx)
810 pi); 858 pi);
811 GNUNET_assert (bucket->peers_size > 0); 859 GNUNET_assert (bucket->peers_size > 0);
812 bucket->peers_size--; 860 bucket->peers_size--;
813 // FIXME: check if this peer was in one of the first 'bucket_size' 861 if ( (was_held) &&
814 // peers, and call 'hold' on the next peer if there is any! 862 (bucket->peers_size >= bucket_size - 1) )
863 update_hold (bucket);
815 while ( (closest_bucket > 0) && 864 while ( (closest_bucket > 0) &&
816 (0 == k_buckets[closest_bucket - 1].peers_size)) 865 (0 == k_buckets[closest_bucket - 1].peers_size))
817 closest_bucket--; 866 closest_bucket--;
@@ -2426,7 +2475,7 @@ GDS_u_receive (void *cls,
2426 }; 2475 };
2427 const struct GNUNET_MessageHeader *mh = message; 2476 const struct GNUNET_MessageHeader *mh = message;
2428 2477
2429 (void) cls; /* the 'struct Underlay' */ 2478 (void) cls; /* the 'struct GDS_Underlay' */
2430 (void) sctx; /* our receiver address */ 2479 (void) sctx; /* our receiver address */
2431 if (message_size < sizeof (*mh)) 2480 if (message_size < sizeof (*mh))
2432 { 2481 {