diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-01-10 21:51:53 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-19 12:39:55 +0100 |
commit | ba9296269617c157baffb59a6240c87ae5935e95 (patch) | |
tree | 7f82470cce894be0b3441f8150baea36d7138834 /src/dht/gnunet-service-dht_neighbours.c | |
parent | 25ef40ef768743a10b7b29881c267e0fdc9fc677 (diff) | |
download | gnunet-ba9296269617c157baffb59a6240c87ae5935e95.tar.gz gnunet-ba9296269617c157baffb59a6240c87ae5935e95.zip |
first steps towards usable dhtu
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 235 |
1 files changed, 114 insertions, 121 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index cf150ea0c..bc473df69 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -28,13 +28,10 @@ | |||
28 | #include "gnunet_constants.h" | 28 | #include "gnunet_constants.h" |
29 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
30 | #include "gnunet_signatures.h" | 30 | #include "gnunet_signatures.h" |
31 | #include "gnunet_ats_service.h" | ||
32 | #include "gnunet_core_service.h" | ||
33 | #include "gnunet_hello_lib.h" | 31 | #include "gnunet_hello_lib.h" |
34 | #include "gnunet-service-dht.h" | 32 | #include "gnunet-service-dht.h" |
35 | #include "gnunet-service-dht_hello.h" | 33 | #include "gnunet-service-dht_hello.h" |
36 | #include "gnunet-service-dht_neighbours.h" | 34 | #include "gnunet-service-dht_neighbours.h" |
37 | #include "gnunet-service-dht_nse.h" | ||
38 | #include "gnunet-service-dht_routing.h" | 35 | #include "gnunet-service-dht_routing.h" |
39 | #include "dht.h" | 36 | #include "dht.h" |
40 | 37 | ||
@@ -278,12 +275,12 @@ struct PeerInfo | |||
278 | /** | 275 | /** |
279 | * Handle for sending messages to this peer. | 276 | * Handle for sending messages to this peer. |
280 | */ | 277 | */ |
281 | struct GNUNET_MQ_Handle *mq; | 278 | struct GNUNET_DHTU_Target *target; |
282 | 279 | ||
283 | /** | 280 | /** |
284 | * What is the identity of the peer? | 281 | * What is the identity of the peer? |
285 | */ | 282 | */ |
286 | const struct GNUNET_PeerIdentity *id; | 283 | struct GNUNET_PeerIdentity id; |
287 | 284 | ||
288 | /** | 285 | /** |
289 | * Hash of @e id. | 286 | * Hash of @e id. |
@@ -332,7 +329,7 @@ struct ConnectInfo | |||
332 | /** | 329 | /** |
333 | * Handle to active connectivity suggestion operation, or NULL. | 330 | * Handle to active connectivity suggestion operation, or NULL. |
334 | */ | 331 | */ |
335 | struct GNUNET_ATS_ConnectivitySuggestHandle *sh; | 332 | struct GNUNET_DHTU_PreferenceHandle *ph; |
336 | 333 | ||
337 | /** | 334 | /** |
338 | * How much would we like to connect to this peer? | 335 | * How much would we like to connect to this peer? |
@@ -400,16 +397,6 @@ static struct GNUNET_PeerIdentity my_identity; | |||
400 | struct GNUNET_HashCode my_identity_hash; | 397 | struct GNUNET_HashCode my_identity_hash; |
401 | 398 | ||
402 | /** | 399 | /** |
403 | * Handle to CORE. | ||
404 | */ | ||
405 | static struct GNUNET_CORE_Handle *core_api; | ||
406 | |||
407 | /** | ||
408 | * Handle to ATS connectivity. | ||
409 | */ | ||
410 | static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | ||
411 | |||
412 | /** | ||
413 | * Our private key. | 400 | * Our private key. |
414 | */ | 401 | */ |
415 | static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key; | 402 | static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key; |
@@ -517,10 +504,10 @@ free_connect_info (void *cls, | |||
517 | GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, | 504 | GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, |
518 | peer, | 505 | peer, |
519 | ci)); | 506 | ci)); |
520 | if (NULL != ci->sh) | 507 | if (NULL != ci->ph) |
521 | { | 508 | { |
522 | GNUNET_ATS_connectivity_suggest_cancel (ci->sh); | 509 | // ci->u->drop (ci->ph); // FIXME! |
523 | ci->sh = NULL; | 510 | ci->ph = NULL; |
524 | } | 511 | } |
525 | if (NULL != ci->oh) | 512 | if (NULL != ci->oh) |
526 | { | 513 | { |
@@ -597,14 +584,18 @@ try_connect (const struct GNUNET_PeerIdentity *pid, | |||
597 | h, | 584 | h, |
598 | &offer_hello_done, | 585 | &offer_hello_done, |
599 | ci); | 586 | ci); |
600 | if ( (NULL != ci->sh) && | 587 | if ( (NULL != ci->ph) && |
601 | (ci->strength != strength) ) | 588 | (ci->strength != strength) ) |
602 | GNUNET_ATS_connectivity_suggest_cancel (ci->sh); | 589 | { |
590 | // ci->u_api->drop (ci->ph); | ||
591 | ci->ph = NULL; | ||
592 | } | ||
603 | if (ci->strength != strength) | 593 | if (ci->strength != strength) |
604 | { | 594 | { |
605 | ci->sh = GNUNET_ATS_connectivity_suggest (ats_ch, | 595 | #if FIXME |
606 | pid, | 596 | ci->ph = ci->u_api->hold (ci->u_api->cls, |
607 | strength); | 597 | TARGET); |
598 | #endif | ||
608 | ci->strength = strength; | 599 | ci->strength = strength; |
609 | } | 600 | } |
610 | } | 601 | } |
@@ -719,7 +710,7 @@ send_find_peer_message (void *cls) | |||
719 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 710 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
720 | 711 | ||
721 | bg = GNUNET_BLOCK_group_create (GDS_block_context, | 712 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
722 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 713 | GNUNET_BLOCK_TYPE_DHT_URL_HELLO, |
723 | GNUNET_CRYPTO_random_u32 ( | 714 | GNUNET_CRYPTO_random_u32 ( |
724 | GNUNET_CRYPTO_QUALITY_WEAK, | 715 | GNUNET_CRYPTO_QUALITY_WEAK, |
725 | UINT32_MAX), | 716 | UINT32_MAX), |
@@ -736,7 +727,7 @@ send_find_peer_message (void *cls) | |||
736 | DHT_BLOOM_SIZE, | 727 | DHT_BLOOM_SIZE, |
737 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 728 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
738 | if (GNUNET_OK != | 729 | if (GNUNET_OK != |
739 | GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, | 730 | GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_URL_HELLO, |
740 | GNUNET_DHT_RO_FIND_PEER | 731 | GNUNET_DHT_RO_FIND_PEER |
741 | | GNUNET_DHT_RO_RECORD_ROUTE, | 732 | | GNUNET_DHT_RO_RECORD_ROUTE, |
742 | FIND_PEER_REPLICATION_LEVEL, | 733 | FIND_PEER_REPLICATION_LEVEL, |
@@ -764,18 +755,11 @@ send_find_peer_message (void *cls) | |||
764 | } | 755 | } |
765 | 756 | ||
766 | 757 | ||
767 | /** | 758 | void |
768 | * Method called whenever a peer connects. | 759 | GDS_u_connect (void *cls, |
769 | * | 760 | struct GNUNET_DHTU_Target *target, |
770 | * @param cls closure | 761 | const struct GNUNET_PeerIdentity *pid, |
771 | * @param peer peer identity this notification is about | 762 | void **ctx) |
772 | * @param mq message queue for sending messages to @a peer | ||
773 | * @return our `struct PeerInfo` for @a peer | ||
774 | */ | ||
775 | static void * | ||
776 | handle_core_connect (void *cls, | ||
777 | const struct GNUNET_PeerIdentity *peer, | ||
778 | struct GNUNET_MQ_Handle *mq) | ||
779 | { | 763 | { |
780 | struct PeerInfo *pi; | 764 | struct PeerInfo *pi; |
781 | struct PeerBucket *bucket; | 765 | struct PeerBucket *bucket; |
@@ -783,23 +767,23 @@ handle_core_connect (void *cls, | |||
783 | (void) cls; | 767 | (void) cls; |
784 | /* Check for connect to self message */ | 768 | /* Check for connect to self message */ |
785 | if (0 == GNUNET_memcmp (&my_identity, | 769 | if (0 == GNUNET_memcmp (&my_identity, |
786 | peer)) | 770 | pid)) |
787 | return NULL; | 771 | return; |
788 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 772 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
789 | "Connected to peer %s\n", | 773 | "Connected to peer %s\n", |
790 | GNUNET_i2s (peer)); | 774 | GNUNET_i2s (pid)); |
791 | GNUNET_assert (NULL == | 775 | GNUNET_assert (NULL == |
792 | GNUNET_CONTAINER_multipeermap_get (all_connected_peers, | 776 | GNUNET_CONTAINER_multipeermap_get (all_connected_peers, |
793 | peer)); | 777 | pid)); |
794 | GNUNET_STATISTICS_update (GDS_stats, | 778 | GNUNET_STATISTICS_update (GDS_stats, |
795 | "# peers connected", | 779 | "# peers connected", |
796 | 1, | 780 | 1, |
797 | GNUNET_NO); | 781 | GNUNET_NO); |
798 | pi = GNUNET_new (struct PeerInfo); | 782 | pi = GNUNET_new (struct PeerInfo); |
799 | pi->id = peer; | 783 | pi->id = *pid; |
800 | pi->mq = mq; | 784 | pi->target = target; |
801 | GNUNET_CRYPTO_hash (peer, | 785 | GNUNET_CRYPTO_hash (pid, |
802 | sizeof(struct GNUNET_PeerIdentity), | 786 | sizeof(*pid), |
803 | &pi->phash); | 787 | &pi->phash); |
804 | pi->peer_bucket = find_bucket (&pi->phash); | 788 | pi->peer_bucket = find_bucket (&pi->phash); |
805 | GNUNET_assert ( (pi->peer_bucket >= 0) && | 789 | GNUNET_assert ( (pi->peer_bucket >= 0) && |
@@ -813,7 +797,7 @@ handle_core_connect (void *cls, | |||
813 | (unsigned int) pi->peer_bucket + 1); | 797 | (unsigned int) pi->peer_bucket + 1); |
814 | GNUNET_assert (GNUNET_OK == | 798 | GNUNET_assert (GNUNET_OK == |
815 | GNUNET_CONTAINER_multipeermap_put (all_connected_peers, | 799 | GNUNET_CONTAINER_multipeermap_put (all_connected_peers, |
816 | pi->id, | 800 | &pi->id, |
817 | pi, | 801 | pi, |
818 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 802 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
819 | if (bucket->peers_size <= bucket_size) | 803 | if (bucket->peers_size <= bucket_size) |
@@ -829,39 +813,34 @@ handle_core_connect (void *cls, | |||
829 | find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, | 813 | find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, |
830 | NULL); | 814 | NULL); |
831 | } | 815 | } |
832 | return pi; | 816 | *ctx = pi; |
833 | } | 817 | } |
834 | 818 | ||
835 | 819 | ||
836 | /** | 820 | /** |
837 | * Method called whenever a peer disconnects. | 821 | * Method called whenever a peer disconnects. |
838 | * | 822 | * |
839 | * @param cls closure | 823 | * @param ctx context |
840 | * @param peer peer identity this notification is about | ||
841 | * @param internal_cls our `struct PeerInfo` for @a peer | ||
842 | */ | 824 | */ |
843 | static void | 825 | void |
844 | handle_core_disconnect (void *cls, | 826 | GDS_u_disconnect (void *ctx) |
845 | const struct GNUNET_PeerIdentity *peer, | ||
846 | void *internal_cls) | ||
847 | { | 827 | { |
848 | struct PeerInfo *to_remove = internal_cls; | 828 | struct PeerInfo *to_remove = ctx; |
849 | struct PeerBucket *bucket; | 829 | struct PeerBucket *bucket; |
850 | 830 | ||
851 | (void) cls; | ||
852 | /* Check for disconnect from self message (on shutdown) */ | 831 | /* Check for disconnect from self message (on shutdown) */ |
853 | if (NULL == to_remove) | 832 | if (NULL == to_remove) |
854 | return; | 833 | return; |
855 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
856 | "Disconnected from peer %s\n", | 835 | "Disconnected from peer %s\n", |
857 | GNUNET_i2s (peer)); | 836 | GNUNET_i2s (&to_remove->id)); |
858 | GNUNET_STATISTICS_update (GDS_stats, | 837 | GNUNET_STATISTICS_update (GDS_stats, |
859 | "# peers connected", | 838 | "# peers connected", |
860 | -1, | 839 | -1, |
861 | GNUNET_NO); | 840 | GNUNET_NO); |
862 | GNUNET_assert (GNUNET_YES == | 841 | GNUNET_assert (GNUNET_YES == |
863 | GNUNET_CONTAINER_multipeermap_remove (all_connected_peers, | 842 | GNUNET_CONTAINER_multipeermap_remove (all_connected_peers, |
864 | peer, | 843 | &to_remove->id, |
865 | to_remove)); | 844 | to_remove)); |
866 | if ( (0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && | 845 | if ( (0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && |
867 | (GNUNET_YES != disable_try_connect)) | 846 | (GNUNET_YES != disable_try_connect)) |
@@ -1073,7 +1052,7 @@ select_peer (const struct GNUNET_HashCode *key, | |||
1073 | { | 1052 | { |
1074 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1053 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1075 | "Excluded peer `%s' due to BF match in greedy routing for %s\n", | 1054 | "Excluded peer `%s' due to BF match in greedy routing for %s\n", |
1076 | GNUNET_i2s (pos->id), | 1055 | GNUNET_i2s (&pos->id), |
1077 | GNUNET_h2s (key)); | 1056 | GNUNET_h2s (key)); |
1078 | continue; | 1057 | continue; |
1079 | } | 1058 | } |
@@ -1140,7 +1119,7 @@ select_peer (const struct GNUNET_HashCode *key, | |||
1140 | } | 1119 | } |
1141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1142 | "Selected peer `%s' in greedy routing for %s\n", | 1121 | "Selected peer `%s' in greedy routing for %s\n", |
1143 | GNUNET_i2s (chosen->id), | 1122 | GNUNET_i2s (&chosen->id), |
1144 | GNUNET_h2s (key)); | 1123 | GNUNET_h2s (key)); |
1145 | return chosen; | 1124 | return chosen; |
1146 | } /* end of 'greedy' peer selection */ | 1125 | } /* end of 'greedy' peer selection */ |
@@ -1170,7 +1149,7 @@ select_peer (const struct GNUNET_HashCode *key, | |||
1170 | { | 1149 | { |
1171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1172 | "Excluded peer `%s' due to BF match in random routing for %s\n", | 1151 | "Excluded peer `%s' due to BF match in random routing for %s\n", |
1173 | GNUNET_i2s (pos->id), | 1152 | GNUNET_i2s (&pos->id), |
1174 | GNUNET_h2s (key)); | 1153 | GNUNET_h2s (key)); |
1175 | continue; /* Ignore filtered peers */ | 1154 | continue; /* Ignore filtered peers */ |
1176 | } | 1155 | } |
@@ -1209,7 +1188,7 @@ select_peer (const struct GNUNET_HashCode *key, | |||
1209 | { | 1188 | { |
1210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1211 | "Selected peer `%s' in random routing for %s\n", | 1190 | "Selected peer `%s' in random routing for %s\n", |
1212 | GNUNET_i2s (pos->id), | 1191 | GNUNET_i2s (&pos->id), |
1213 | GNUNET_h2s (key)); | 1192 | GNUNET_h2s (key)); |
1214 | return pos; | 1193 | return pos; |
1215 | } | 1194 | } |
@@ -1371,6 +1350,7 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1371 | struct PeerPutMessage *ppm; | 1350 | struct PeerPutMessage *ppm; |
1372 | struct GNUNET_DHT_PathElement *pp; | 1351 | struct GNUNET_DHT_PathElement *pp; |
1373 | 1352 | ||
1353 | #if FIXME_LEGACY | ||
1374 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) | 1354 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) |
1375 | { | 1355 | { |
1376 | /* skip */ | 1356 | /* skip */ |
@@ -1381,11 +1361,12 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1381 | skip_count++; | 1361 | skip_count++; |
1382 | continue; | 1362 | continue; |
1383 | } | 1363 | } |
1364 | #endif | ||
1384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1385 | "Routing PUT for %s after %u hops to %s\n", | 1366 | "Routing PUT for %s after %u hops to %s\n", |
1386 | GNUNET_h2s (&bd->key), | 1367 | GNUNET_h2s (&bd->key), |
1387 | (unsigned int) hop_count, | 1368 | (unsigned int) hop_count, |
1388 | GNUNET_i2s (target->id)); | 1369 | GNUNET_i2s (&target->id)); |
1389 | env = GNUNET_MQ_msg_extra (ppm, | 1370 | env = GNUNET_MQ_msg_extra (ppm, |
1390 | msize, | 1371 | msize, |
1391 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); | 1372 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); |
@@ -1417,15 +1398,17 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1417 | bd->data_size, | 1398 | bd->data_size, |
1418 | bd->expiration_time, | 1399 | bd->expiration_time, |
1419 | &pp[put_path_length - 1].pred, | 1400 | &pp[put_path_length - 1].pred, |
1420 | target->id, | 1401 | &target->id, |
1421 | &pp[put_path_length - 1].sig); | 1402 | &pp[put_path_length - 1].sig); |
1422 | } | 1403 | } |
1423 | 1404 | ||
1424 | GNUNET_memcpy (&pp[put_path_length], | 1405 | GNUNET_memcpy (&pp[put_path_length], |
1425 | bd->data, | 1406 | bd->data, |
1426 | bd->data_size); | 1407 | bd->data_size); |
1408 | #if FIXME | ||
1427 | GNUNET_MQ_send (target->mq, | 1409 | GNUNET_MQ_send (target->mq, |
1428 | env); | 1410 | env); |
1411 | #endif | ||
1429 | } | 1412 | } |
1430 | GNUNET_free (targets); | 1413 | GNUNET_free (targets); |
1431 | GNUNET_STATISTICS_update (GDS_stats, | 1414 | GNUNET_STATISTICS_update (GDS_stats, |
@@ -1508,6 +1491,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1508 | struct PeerGetMessage *pgm; | 1491 | struct PeerGetMessage *pgm; |
1509 | char *xq; | 1492 | char *xq; |
1510 | 1493 | ||
1494 | #if FIXME | ||
1511 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) | 1495 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) |
1512 | { | 1496 | { |
1513 | /* skip */ | 1497 | /* skip */ |
@@ -1518,11 +1502,12 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1518 | skip_count++; | 1502 | skip_count++; |
1519 | continue; | 1503 | continue; |
1520 | } | 1504 | } |
1505 | #endif | ||
1521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1522 | "Routing GET for %s after %u hops to %s\n", | 1507 | "Routing GET for %s after %u hops to %s\n", |
1523 | GNUNET_h2s (key), | 1508 | GNUNET_h2s (key), |
1524 | (unsigned int) hop_count, | 1509 | (unsigned int) hop_count, |
1525 | GNUNET_i2s (target->id)); | 1510 | GNUNET_i2s (&target->id)); |
1526 | env = GNUNET_MQ_msg_extra (pgm, | 1511 | env = GNUNET_MQ_msg_extra (pgm, |
1527 | msize, | 1512 | msize, |
1528 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET); | 1513 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET); |
@@ -1547,8 +1532,10 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1547 | GNUNET_memcpy (&xq[xquery_size], | 1532 | GNUNET_memcpy (&xq[xquery_size], |
1548 | reply_bf, | 1533 | reply_bf, |
1549 | reply_bf_size); | 1534 | reply_bf_size); |
1535 | #if FIXME | ||
1550 | GNUNET_MQ_send (target->mq, | 1536 | GNUNET_MQ_send (target->mq, |
1551 | env); | 1537 | env); |
1538 | #endif | ||
1552 | } | 1539 | } |
1553 | GNUNET_STATISTICS_update (GDS_stats, | 1540 | GNUNET_STATISTICS_update (GDS_stats, |
1554 | "# GET messages queued for transmission", | 1541 | "# GET messages queued for transmission", |
@@ -1622,6 +1609,7 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, | |||
1622 | GNUNET_break (0); | 1609 | GNUNET_break (0); |
1623 | return; | 1610 | return; |
1624 | } | 1611 | } |
1612 | #if FIXME | ||
1625 | if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER) | 1613 | if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER) |
1626 | { | 1614 | { |
1627 | /* skip */ | 1615 | /* skip */ |
@@ -1634,11 +1622,11 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, | |||
1634 | GNUNET_h2s (&bd->key)); | 1622 | GNUNET_h2s (&bd->key)); |
1635 | return; | 1623 | return; |
1636 | } | 1624 | } |
1637 | 1625 | #endif | |
1638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1639 | "Forwarding reply for key %s to peer %s\n", | 1627 | "Forwarding reply for key %s to peer %s\n", |
1640 | GNUNET_h2s (query_hash), | 1628 | GNUNET_h2s (query_hash), |
1641 | GNUNET_i2s (pi->id)); | 1629 | GNUNET_i2s (&pi->id)); |
1642 | GNUNET_STATISTICS_update (GDS_stats, | 1630 | GNUNET_STATISTICS_update (GDS_stats, |
1643 | "# RESULT messages queued for transmission", | 1631 | "# RESULT messages queued for transmission", |
1644 | 1, | 1632 | 1, |
@@ -1668,36 +1656,16 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, | |||
1668 | bd->data_size, | 1656 | bd->data_size, |
1669 | bd->expiration_time, | 1657 | bd->expiration_time, |
1670 | &paths[ppl + get_path_length - 1].pred, | 1658 | &paths[ppl + get_path_length - 1].pred, |
1671 | pi->id, | 1659 | &pi->id, |
1672 | &paths[ppl + get_path_length - 1].sig); | 1660 | &paths[ppl + get_path_length - 1].sig); |
1673 | } | 1661 | } |
1674 | GNUNET_memcpy (&paths[ppl + get_path_length], | 1662 | GNUNET_memcpy (&paths[ppl + get_path_length], |
1675 | bd->data, | 1663 | bd->data, |
1676 | bd->data_size); | 1664 | bd->data_size); |
1665 | #if FIXME | ||
1677 | GNUNET_MQ_send (pi->mq, | 1666 | GNUNET_MQ_send (pi->mq, |
1678 | env); | 1667 | env); |
1679 | } | 1668 | #endif |
1680 | |||
1681 | |||
1682 | /** | ||
1683 | * To be called on core init. | ||
1684 | * | ||
1685 | * @param cls service closure | ||
1686 | * @param identity the public identity of this peer | ||
1687 | */ | ||
1688 | static void | ||
1689 | core_init (void *cls, | ||
1690 | const struct GNUNET_PeerIdentity *identity) | ||
1691 | { | ||
1692 | (void) cls; | ||
1693 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1694 | "CORE called, I am %s\n", | ||
1695 | GNUNET_i2s (identity)); | ||
1696 | my_identity = *identity; | ||
1697 | GNUNET_CRYPTO_hash (identity, | ||
1698 | sizeof(struct GNUNET_PeerIdentity), | ||
1699 | &my_identity_hash); | ||
1700 | GNUNET_SERVICE_resume (GDS_service); | ||
1701 | } | 1669 | } |
1702 | 1670 | ||
1703 | 1671 | ||
@@ -1759,7 +1727,7 @@ handle_dht_p2p_put (void *cls, | |||
1759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1760 | "PUT for `%s' from %s\n", | 1728 | "PUT for `%s' from %s\n", |
1761 | GNUNET_h2s (&put->key), | 1729 | GNUNET_h2s (&put->key), |
1762 | GNUNET_i2s (peer->id)); | 1730 | GNUNET_i2s (&peer->id)); |
1763 | if (GNUNET_TIME_absolute_is_past (bd.expiration_time)) | 1731 | if (GNUNET_TIME_absolute_is_past (bd.expiration_time)) |
1764 | { | 1732 | { |
1765 | GNUNET_STATISTICS_update (GDS_stats, | 1733 | GNUNET_STATISTICS_update (GDS_stats, |
@@ -1841,7 +1809,7 @@ handle_dht_p2p_put (void *cls, | |||
1841 | } | 1809 | } |
1842 | GNUNET_break (0 != | 1810 | GNUNET_break (0 != |
1843 | GNUNET_memcmp (&pp[i].pred, | 1811 | GNUNET_memcmp (&pp[i].pred, |
1844 | peer->id)); | 1812 | &peer->id)); |
1845 | } | 1813 | } |
1846 | if (0 != | 1814 | if (0 != |
1847 | GNUNET_DHT_verify_path (&bd.key, | 1815 | GNUNET_DHT_verify_path (&bd.key, |
@@ -1860,7 +1828,7 @@ handle_dht_p2p_put (void *cls, | |||
1860 | GNUNET_memcpy (pp, | 1828 | GNUNET_memcpy (pp, |
1861 | put_path, | 1829 | put_path, |
1862 | putlen * sizeof(struct GNUNET_DHT_PathElement)); | 1830 | putlen * sizeof(struct GNUNET_DHT_PathElement)); |
1863 | pp[putlen].pred = *peer->id; | 1831 | pp[putlen].pred = peer->id; |
1864 | /* zero-out signature, not valid until we actually do forward! */ | 1832 | /* zero-out signature, not valid until we actually do forward! */ |
1865 | memset (&pp[putlen].sig, | 1833 | memset (&pp[putlen].sig, |
1866 | 0, | 1834 | 0, |
@@ -1924,7 +1892,7 @@ handle_find_peer (struct PeerInfo *pi, | |||
1924 | struct PeerInfo *peer; | 1892 | struct PeerInfo *peer; |
1925 | unsigned int choice; | 1893 | unsigned int choice; |
1926 | struct GDS_DATACACHE_BlockData bd = { | 1894 | struct GDS_DATACACHE_BlockData bd = { |
1927 | .type = GNUNET_BLOCK_TYPE_DHT_HELLO | 1895 | .type = GNUNET_BLOCK_TYPE_DHT_URL_HELLO |
1928 | }; | 1896 | }; |
1929 | 1897 | ||
1930 | /* first, check about our own HELLO */ | 1898 | /* first, check about our own HELLO */ |
@@ -1939,7 +1907,7 @@ handle_find_peer (struct PeerInfo *pi, | |||
1939 | GNUNET_break (bd.data_size >= sizeof(struct GNUNET_MessageHeader)); | 1907 | GNUNET_break (bd.data_size >= sizeof(struct GNUNET_MessageHeader)); |
1940 | if (GNUNET_BLOCK_REPLY_OK_MORE == | 1908 | if (GNUNET_BLOCK_REPLY_OK_MORE == |
1941 | GNUNET_BLOCK_check_reply (GDS_block_context, | 1909 | GNUNET_BLOCK_check_reply (GDS_block_context, |
1942 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1910 | GNUNET_BLOCK_TYPE_DHT_URL_HELLO, |
1943 | bg, | 1911 | bg, |
1944 | &my_identity_hash, | 1912 | &my_identity_hash, |
1945 | NULL, 0, | 1913 | NULL, 0, |
@@ -2003,12 +1971,12 @@ handle_find_peer (struct PeerInfo *pi, | |||
2003 | return; /* no non-masked peer available */ | 1971 | return; /* no non-masked peer available */ |
2004 | if (NULL == peer) | 1972 | if (NULL == peer) |
2005 | peer = bucket->head; | 1973 | peer = bucket->head; |
2006 | hello = GDS_HELLO_get (peer->id); | 1974 | hello = GDS_HELLO_get (&peer->id); |
2007 | } while ( (NULL == hello) || | 1975 | } while ( (NULL == hello) || |
2008 | (GNUNET_BLOCK_REPLY_OK_MORE != | 1976 | (GNUNET_BLOCK_REPLY_OK_MORE != |
2009 | GNUNET_BLOCK_check_reply ( | 1977 | GNUNET_BLOCK_check_reply ( |
2010 | GDS_block_context, | 1978 | GDS_block_context, |
2011 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1979 | GNUNET_BLOCK_TYPE_DHT_URL_HELLO, |
2012 | bg, | 1980 | bg, |
2013 | &peer->phash, | 1981 | &peer->phash, |
2014 | NULL, 0, /* xquery */ | 1982 | NULL, 0, /* xquery */ |
@@ -2170,7 +2138,7 @@ handle_dht_p2p_get (void *cls, | |||
2170 | } | 2138 | } |
2171 | 2139 | ||
2172 | /* remember request for routing replies */ | 2140 | /* remember request for routing replies */ |
2173 | GDS_ROUTING_add (peer->id, | 2141 | GDS_ROUTING_add (&peer->id, |
2174 | type, | 2142 | type, |
2175 | bg, /* bg now owned by routing, but valid at least until end of this function! */ | 2143 | bg, /* bg now owned by routing, but valid at least until end of this function! */ |
2176 | options, | 2144 | options, |
@@ -2363,7 +2331,7 @@ handle_dht_p2p_result (void *cls, | |||
2363 | } | 2331 | } |
2364 | 2332 | ||
2365 | /* if we got a HELLO, consider it for our own routing table */ | 2333 | /* if we got a HELLO, consider it for our own routing table */ |
2366 | if (GNUNET_BLOCK_TYPE_DHT_HELLO == bd.type) | 2334 | if (GNUNET_BLOCK_TYPE_DHT_URL_HELLO == bd.type) |
2367 | { | 2335 | { |
2368 | const struct GNUNET_MessageHeader *h = bd.data; | 2336 | const struct GNUNET_MessageHeader *h = bd.data; |
2369 | struct GNUNET_PeerIdentity pid; | 2337 | struct GNUNET_PeerIdentity pid; |
@@ -2397,7 +2365,7 @@ handle_dht_p2p_result (void *cls, | |||
2397 | so, truncate it instead of expanding. */ | 2365 | so, truncate it instead of expanding. */ |
2398 | for (unsigned int i = 0; i <= get_path_length; i++) | 2366 | for (unsigned int i = 0; i <= get_path_length; i++) |
2399 | if (0 == GNUNET_memcmp (&get_path[i].pred, | 2367 | if (0 == GNUNET_memcmp (&get_path[i].pred, |
2400 | peer->id)) | 2368 | &peer->id)) |
2401 | { | 2369 | { |
2402 | process_reply_with_path (&bd, | 2370 | process_reply_with_path (&bd, |
2403 | &prm->key, | 2371 | &prm->key, |
@@ -2412,7 +2380,7 @@ handle_dht_p2p_result (void *cls, | |||
2412 | GNUNET_memcpy (xget_path, | 2380 | GNUNET_memcpy (xget_path, |
2413 | get_path, | 2381 | get_path, |
2414 | get_path_length * sizeof(struct GNUNET_DHT_PathElement)); | 2382 | get_path_length * sizeof(struct GNUNET_DHT_PathElement)); |
2415 | xget_path[get_path_length].pred = *peer->id; | 2383 | xget_path[get_path_length].pred = peer->id; |
2416 | memset (&xget_path[get_path_length].sig, | 2384 | memset (&xget_path[get_path_length].sig, |
2417 | 0, | 2385 | 0, |
2418 | sizeof (xget_path[get_path_length].sig)); | 2386 | sizeof (xget_path[get_path_length].sig)); |
@@ -2423,24 +2391,57 @@ handle_dht_p2p_result (void *cls, | |||
2423 | } | 2391 | } |
2424 | 2392 | ||
2425 | 2393 | ||
2426 | enum GNUNET_GenericReturnValue | 2394 | void |
2427 | GDS_NEIGHBOURS_init () | 2395 | GDS_u_receive (void *cls, |
2396 | void **tctx, | ||
2397 | void **sctx, | ||
2398 | const void *message, | ||
2399 | size_t message_size) | ||
2428 | { | 2400 | { |
2401 | struct PeerInfo *pi = *tctx; | ||
2429 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | 2402 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
2430 | GNUNET_MQ_hd_var_size (dht_p2p_get, | 2403 | GNUNET_MQ_hd_var_size (dht_p2p_get, |
2431 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET, | 2404 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET, |
2432 | struct PeerGetMessage, | 2405 | struct PeerGetMessage, |
2433 | NULL), | 2406 | pi), |
2434 | GNUNET_MQ_hd_var_size (dht_p2p_put, | 2407 | GNUNET_MQ_hd_var_size (dht_p2p_put, |
2435 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, | 2408 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, |
2436 | struct PeerPutMessage, | 2409 | struct PeerPutMessage, |
2437 | NULL), | 2410 | pi), |
2438 | GNUNET_MQ_hd_var_size (dht_p2p_result, | 2411 | GNUNET_MQ_hd_var_size (dht_p2p_result, |
2439 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, | 2412 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, |
2440 | struct PeerResultMessage, | 2413 | struct PeerResultMessage, |
2441 | NULL), | 2414 | pi), |
2442 | GNUNET_MQ_handler_end () | 2415 | GNUNET_MQ_handler_end () |
2443 | }; | 2416 | }; |
2417 | const struct GNUNET_MessageHeader *mh = message; | ||
2418 | |||
2419 | (void) cls; /* the 'struct Underlay' */ | ||
2420 | (void) sctx; /* our receiver address */ | ||
2421 | if (message_size < sizeof (*mh)) | ||
2422 | { | ||
2423 | GNUNET_break_op (0); | ||
2424 | return; | ||
2425 | } | ||
2426 | if (message_size != ntohs (mh->size)) | ||
2427 | { | ||
2428 | GNUNET_break_op (0); | ||
2429 | return; | ||
2430 | } | ||
2431 | if (GNUNET_OK != | ||
2432 | GNUNET_MQ_handle_message (core_handlers, | ||
2433 | mh)) | ||
2434 | { | ||
2435 | GNUNET_break_op (0); | ||
2436 | return; | ||
2437 | } | ||
2438 | } | ||
2439 | |||
2440 | |||
2441 | enum GNUNET_GenericReturnValue | ||
2442 | GDS_NEIGHBOURS_init () | ||
2443 | { | ||
2444 | |||
2444 | unsigned long long temp_config_num; | 2445 | unsigned long long temp_config_num; |
2445 | 2446 | ||
2446 | disable_try_connect | 2447 | disable_try_connect |
@@ -2482,16 +2483,12 @@ GDS_NEIGHBOURS_init () | |||
2482 | } | 2483 | } |
2483 | GNUNET_free (keyfile); | 2484 | GNUNET_free (keyfile); |
2484 | } | 2485 | } |
2486 | GNUNET_CRYPTO_eddsa_key_get_public (&my_private_key, | ||
2487 | &my_identity.public_key); | ||
2488 | GNUNET_CRYPTO_hash (&my_identity, | ||
2489 | sizeof(struct GNUNET_PeerIdentity), | ||
2490 | &my_identity_hash); | ||
2485 | 2491 | ||
2486 | ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg); | ||
2487 | core_api = GNUNET_CORE_connect (GDS_cfg, | ||
2488 | NULL, | ||
2489 | &core_init, | ||
2490 | &handle_core_connect, | ||
2491 | &handle_core_disconnect, | ||
2492 | core_handlers); | ||
2493 | if (NULL == core_api) | ||
2494 | return GNUNET_SYSERR; | ||
2495 | all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256, | 2492 | all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256, |
2496 | GNUNET_YES); | 2493 | GNUNET_YES); |
2497 | all_desired_peers = GNUNET_CONTAINER_multipeermap_create (256, | 2494 | all_desired_peers = GNUNET_CONTAINER_multipeermap_create (256, |
@@ -2503,10 +2500,8 @@ GDS_NEIGHBOURS_init () | |||
2503 | void | 2500 | void |
2504 | GDS_NEIGHBOURS_done () | 2501 | GDS_NEIGHBOURS_done () |
2505 | { | 2502 | { |
2506 | if (NULL == core_api) | 2503 | if (NULL == all_connected_peers) |
2507 | return; | 2504 | return; |
2508 | GNUNET_CORE_disconnect (core_api); | ||
2509 | core_api = NULL; | ||
2510 | GNUNET_assert (0 == | 2505 | GNUNET_assert (0 == |
2511 | GNUNET_CONTAINER_multipeermap_size (all_connected_peers)); | 2506 | GNUNET_CONTAINER_multipeermap_size (all_connected_peers)); |
2512 | GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers); | 2507 | GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers); |
@@ -2516,8 +2511,6 @@ GDS_NEIGHBOURS_done () | |||
2516 | NULL); | 2511 | NULL); |
2517 | GNUNET_CONTAINER_multipeermap_destroy (all_desired_peers); | 2512 | GNUNET_CONTAINER_multipeermap_destroy (all_desired_peers); |
2518 | all_desired_peers = NULL; | 2513 | all_desired_peers = NULL; |
2519 | GNUNET_ATS_connectivity_done (ats_ch); | ||
2520 | ats_ch = NULL; | ||
2521 | GNUNET_assert (NULL == find_peer_task); | 2514 | GNUNET_assert (NULL == find_peer_task); |
2522 | } | 2515 | } |
2523 | 2516 | ||