aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c114
1 files changed, 57 insertions, 57 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 6d4534f8a..94513983e 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -2343,63 +2343,6 @@ check_dht_p2p_result (void *cls,
2343 2343
2344 2344
2345/** 2345/**
2346 * Callback function used to extract URIs from a builder.
2347 * Called when we should consider connecting to a peer.
2348 *
2349 * @param cls closure pointing to a `struct GNUNET_PeerIdentity *`
2350 * @param uri one of the URIs
2351 */
2352void
2353GDS_try_connect (void *cls,
2354 const char *uri)
2355{
2356 const struct GNUNET_PeerIdentity *pid = cls;
2357 struct GNUNET_HashCode phash;
2358 int peer_bucket;
2359 struct PeerBucket *bucket;
2360
2361 if (0 == GNUNET_memcmp (&GDS_my_identity,
2362 pid))
2363 {
2364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2365 "Got a HELLO for my own PID, ignoring it\n");
2366 return; /* that's us! */
2367 }
2368 GNUNET_CRYPTO_hash (pid,
2369 sizeof(*pid),
2370 &phash);
2371 peer_bucket = find_bucket (&phash);
2372 GNUNET_assert ( (peer_bucket >= 0) &&
2373 ((unsigned int) peer_bucket < MAX_BUCKETS));
2374 bucket = &k_buckets[peer_bucket];
2375 if (bucket->peers_size >= bucket_size)
2376 return; /* do not care */
2377 for (struct PeerInfo *pi = bucket->head;
2378 NULL != pi;
2379 pi = pi->next)
2380 if (0 ==
2381 GNUNET_memcmp (&pi->id,
2382 pid))
2383 {
2384 /* already connected */
2385 /* TODO: maybe consider 'uri' anyway as an additional
2386 alternative address??? */
2387 return;
2388 }
2389 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2390 "Discovered peer %s at %s suitable for bucket %d (%u/%u), trying to connect\n",
2391 GNUNET_i2s (pid),
2392 uri,
2393 peer_bucket,
2394 bucket->peers_size,
2395 bucket_size);
2396 /* new peer that we like! */
2397 GDS_u_try_connect (pid,
2398 uri);
2399}
2400
2401
2402/**
2403 * Core handler for p2p result messages. 2346 * Core handler for p2p result messages.
2404 * 2347 *
2405 * @param cls closure 2348 * @param cls closure
@@ -2655,6 +2598,63 @@ GDS_u_receive (void *cls,
2655 2598
2656 2599
2657/** 2600/**
2601 * Callback function used to extract URIs from a builder.
2602 * Called when we should consider connecting to a peer.
2603 *
2604 * @param cls closure pointing to a `struct GNUNET_PeerIdentity *`
2605 * @param uri one of the URIs
2606 */
2607void
2608GDS_try_connect (void *cls,
2609 const char *uri)
2610{
2611 const struct GNUNET_PeerIdentity *pid = cls;
2612 struct GNUNET_HashCode phash;
2613 int peer_bucket;
2614 struct PeerBucket *bucket;
2615
2616 if (0 == GNUNET_memcmp (&GDS_my_identity,
2617 pid))
2618 {
2619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2620 "Got a HELLO for my own PID, ignoring it\n");
2621 return; /* that's us! */
2622 }
2623 GNUNET_CRYPTO_hash (pid,
2624 sizeof(*pid),
2625 &phash);
2626 peer_bucket = find_bucket (&phash);
2627 GNUNET_assert ( (peer_bucket >= 0) &&
2628 ((unsigned int) peer_bucket < MAX_BUCKETS));
2629 bucket = &k_buckets[peer_bucket];
2630 if (bucket->peers_size >= bucket_size)
2631 return; /* do not care */
2632 for (struct PeerInfo *pi = bucket->head;
2633 NULL != pi;
2634 pi = pi->next)
2635 if (0 ==
2636 GNUNET_memcmp (&pi->id,
2637 pid))
2638 {
2639 /* already connected */
2640 /* TODO: maybe consider 'uri' anyway as an additional
2641 alternative address??? */
2642 return;
2643 }
2644 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2645 "Discovered peer %s at %s suitable for bucket %d (%u/%u), trying to connect\n",
2646 GNUNET_i2s (pid),
2647 uri,
2648 peer_bucket,
2649 bucket->peers_size,
2650 bucket_size);
2651 /* new peer that we like! */
2652 GDS_u_try_connect (pid,
2653 uri);
2654}
2655
2656
2657/**
2658 * Send @a msg to all peers in our buckets. 2658 * Send @a msg to all peers in our buckets.
2659 * 2659 *
2660 * @param msg message to broadcast 2660 * @param msg message to broadcast