aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c99
-rw-r--r--src/dht/gnunet-service-dht_neighbours.h6
-rw-r--r--src/include/gnunet_dht_service.h7
3 files changed, 75 insertions, 37 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index cee3e7765..4915302d4 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -645,7 +645,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
645 struct PeerInfo *ret; 645 struct PeerInfo *ret;
646 struct GNUNET_HashCode phash; 646 struct GNUNET_HashCode phash;
647 int peer_bucket; 647 int peer_bucket;
648 648
649 /* Check for connect to self message */ 649 /* Check for connect to self message */
650 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) 650 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
651 return; 651 return;
@@ -784,7 +784,7 @@ core_transmit_notify (void *cls, size_t size, void *buf)
784 struct P2PPendingMessage *pending; 784 struct P2PPendingMessage *pending;
785 size_t off; 785 size_t off;
786 size_t msize; 786 size_t msize;
787 787
788 peer->th = NULL; 788 peer->th = NULL;
789 while ((NULL != (pending = peer->head)) && 789 while ((NULL != (pending = peer->head)) &&
790 (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us)) 790 (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us))
@@ -1256,8 +1256,9 @@ get_target_peers (const struct GNUNET_HashCode *key,
1256 * @param put_path peers this request has traversed so far (if tracked) 1256 * @param put_path peers this request has traversed so far (if tracked)
1257 * @param data payload to store 1257 * @param data payload to store
1258 * @param data_size number of bytes in @a data 1258 * @param data_size number of bytes in @a data
1259 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
1259 */ 1260 */
1260void 1261int
1261GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, 1262GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1262 enum GNUNET_DHT_RouteOption options, 1263 enum GNUNET_DHT_RouteOption options,
1263 uint32_t desired_replication_level, 1264 uint32_t desired_replication_level,
@@ -1278,6 +1279,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1278 struct PeerPutMessage *ppm; 1279 struct PeerPutMessage *ppm;
1279 struct GNUNET_PeerIdentity *pp; 1280 struct GNUNET_PeerIdentity *pp;
1280 struct GNUNET_HashCode thash; 1281 struct GNUNET_HashCode thash;
1282 unsigned int skip_count;
1281 1283
1282 GNUNET_assert (NULL != bf); 1284 GNUNET_assert (NULL != bf);
1283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1295,7 +1297,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1295 "Routing PUT for %s terminates after %u hops at %s\n", 1297 "Routing PUT for %s terminates after %u hops at %s\n",
1296 GNUNET_h2s (key), (unsigned int) hop_count, 1298 GNUNET_h2s (key), (unsigned int) hop_count,
1297 GNUNET_i2s (&my_identity)); 1299 GNUNET_i2s (&my_identity));
1298 return; 1300 return GNUNET_NO;
1299 } 1301 }
1300 msize = 1302 msize =
1301 put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + 1303 put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
@@ -1309,20 +1311,24 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1309 { 1311 {
1310 GNUNET_break (0); 1312 GNUNET_break (0);
1311 GNUNET_free (targets); 1313 GNUNET_free (targets);
1312 return; 1314 return GNUNET_NO;
1313 } 1315 }
1314 GNUNET_STATISTICS_update (GDS_stats, 1316 GNUNET_STATISTICS_update (GDS_stats,
1315 gettext_noop 1317 gettext_noop
1316 ("# PUT messages queued for transmission"), 1318 ("# PUT messages queued for transmission"),
1317 target_count, GNUNET_NO); 1319 target_count, GNUNET_NO);
1320 skip_count = 0;
1318 for (i = 0; i < target_count; i++) 1321 for (i = 0; i < target_count; i++)
1319 { 1322 {
1320 target = targets[i]; 1323 target = targets[i];
1321 if (target->pending_count >= MAXIMUM_PENDING_PER_PEER) 1324 if (target->pending_count >= MAXIMUM_PENDING_PER_PEER)
1322 { 1325 {
1323 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 1326 /* skip */
1327 GNUNET_STATISTICS_update (GDS_stats,
1328 gettext_noop ("# P2P messages dropped due to full queue"),
1324 1, GNUNET_NO); 1329 1, GNUNET_NO);
1325 continue; /* skip */ 1330 skip_count++;
1331 continue;
1326 } 1332 }
1327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1328 "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key), 1334 "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key),
@@ -1360,6 +1366,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1360 process_peer_queue (target); 1366 process_peer_queue (target);
1361 } 1367 }
1362 GNUNET_free (targets); 1368 GNUNET_free (targets);
1369 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1363} 1370}
1364 1371
1365 1372
@@ -1379,8 +1386,9 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1379 * @param reply_bf bloomfilter to filter duplicates 1386 * @param reply_bf bloomfilter to filter duplicates
1380 * @param reply_bf_mutator mutator for @a reply_bf 1387 * @param reply_bf_mutator mutator for @a reply_bf
1381 * @param peer_bf filter for peers not to select (again) 1388 * @param peer_bf filter for peers not to select (again)
1389 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
1382 */ 1390 */
1383void 1391int
1384GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, 1392GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1385 enum GNUNET_DHT_RouteOption options, 1393 enum GNUNET_DHT_RouteOption options,
1386 uint32_t desired_replication_level, 1394 uint32_t desired_replication_level,
@@ -1400,6 +1408,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1400 char *xq; 1408 char *xq;
1401 size_t reply_bf_size; 1409 size_t reply_bf_size;
1402 struct GNUNET_HashCode thash; 1410 struct GNUNET_HashCode thash;
1411 unsigned int skip_count;
1403 1412
1404 GNUNET_assert (NULL != peer_bf); 1413 GNUNET_assert (NULL != peer_bf);
1405 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"), 1414 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests routed"),
@@ -1417,7 +1426,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1417 "Routing GET for %s terminates after %u hops at %s\n", 1426 "Routing GET for %s terminates after %u hops at %s\n",
1418 GNUNET_h2s (key), (unsigned int) hop_count, 1427 GNUNET_h2s (key), (unsigned int) hop_count,
1419 GNUNET_i2s (&my_identity)); 1428 GNUNET_i2s (&my_identity));
1420 return; 1429 return GNUNET_NO;
1421 } 1430 }
1422 reply_bf_size = GNUNET_CONTAINER_bloomfilter_get_size (reply_bf); 1431 reply_bf_size = GNUNET_CONTAINER_bloomfilter_get_size (reply_bf);
1423 msize = xquery_size + sizeof (struct PeerGetMessage) + reply_bf_size; 1432 msize = xquery_size + sizeof (struct PeerGetMessage) + reply_bf_size;
@@ -1425,21 +1434,25 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1425 { 1434 {
1426 GNUNET_break (0); 1435 GNUNET_break (0);
1427 GNUNET_free (targets); 1436 GNUNET_free (targets);
1428 return; 1437 return GNUNET_NO;
1429 } 1438 }
1430 GNUNET_STATISTICS_update (GDS_stats, 1439 GNUNET_STATISTICS_update (GDS_stats,
1431 gettext_noop 1440 gettext_noop
1432 ("# GET messages queued for transmission"), 1441 ("# GET messages queued for transmission"),
1433 target_count, GNUNET_NO); 1442 target_count, GNUNET_NO);
1434 /* forward request */ 1443 /* forward request */
1444 skip_count = 0;
1435 for (i = 0; i < target_count; i++) 1445 for (i = 0; i < target_count; i++)
1436 { 1446 {
1437 target = targets[i]; 1447 target = targets[i];
1438 if (target->pending_count >= MAXIMUM_PENDING_PER_PEER) 1448 if (target->pending_count >= MAXIMUM_PENDING_PER_PEER)
1439 { 1449 {
1440 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 1450 /* skip */
1451 GNUNET_STATISTICS_update (GDS_stats,
1452 gettext_noop ("# P2P messages dropped due to full queue"),
1441 1, GNUNET_NO); 1453 1, GNUNET_NO);
1442 continue; /* skip */ 1454 skip_count++;
1455 continue;
1443 } 1456 }
1444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1445 "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key), 1458 "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key),
@@ -1481,6 +1494,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1481 process_peer_queue (target); 1494 process_peer_queue (target);
1482 } 1495 }
1483 GNUNET_free (targets); 1496 GNUNET_free (targets);
1497 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1484} 1498}
1485 1499
1486 1500
@@ -1614,6 +1628,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1614 struct GNUNET_CONTAINER_BloomFilter *bf; 1628 struct GNUNET_CONTAINER_BloomFilter *bf;
1615 struct GNUNET_HashCode test_key; 1629 struct GNUNET_HashCode test_key;
1616 struct GNUNET_HashCode phash; 1630 struct GNUNET_HashCode phash;
1631 int forwarded;
1617 1632
1618 msize = ntohs (message->size); 1633 msize = ntohs (message->size);
1619 if (msize < sizeof (struct PeerPutMessage)) 1634 if (msize < sizeof (struct PeerPutMessage))
@@ -1644,7 +1659,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1644 payload_size = 1659 payload_size =
1645 msize - (sizeof (struct PeerPutMessage) + 1660 msize - (sizeof (struct PeerPutMessage) +
1646 putlen * sizeof (struct GNUNET_PeerIdentity)); 1661 putlen * sizeof (struct GNUNET_PeerIdentity));
1647 1662
1648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for `%s' from %s\n", 1663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for `%s' from %s\n",
1649 GNUNET_h2s (&put->key), GNUNET_i2s (peer)); 1664 GNUNET_h2s (&put->key), GNUNET_i2s (peer));
1650 GNUNET_CRYPTO_hash (peer, sizeof (struct GNUNET_PeerIdentity), &phash); 1665 GNUNET_CRYPTO_hash (peer, sizeof (struct GNUNET_PeerIdentity), &phash);
@@ -1738,13 +1753,16 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1738 (put->expiration_time), &put->key, putlen, pp, 1753 (put->expiration_time), &put->key, putlen, pp,
1739 ntohl (put->type), payload_size, payload); 1754 ntohl (put->type), payload_size, payload);
1740 /* route to other peers */ 1755 /* route to other peers */
1741 GDS_NEIGHBOURS_handle_put (ntohl (put->type), options, 1756 forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type), options,
1742 ntohl (put->desired_replication_level), 1757 ntohl (put->desired_replication_level),
1743 GNUNET_TIME_absolute_ntoh (put->expiration_time), 1758 GNUNET_TIME_absolute_ntoh (put->expiration_time),
1744 ntohl (put->hop_count), bf, &put->key, putlen, 1759 ntohl (put->hop_count), bf,
1745 pp, payload, payload_size); 1760 &put->key, putlen,
1761 pp, payload, payload_size);
1746 /* notify monitoring clients */ 1762 /* notify monitoring clients */
1747 GDS_CLIENTS_process_put (options, 1763 GDS_CLIENTS_process_put (options
1764 | (GNUNET_OK == forwarded)
1765 ? GNUNET_DHT_RO_LAST_HOP : 0,
1748 ntohl (put->type), 1766 ntohl (put->type),
1749 ntohl (put->hop_count), 1767 ntohl (put->hop_count),
1750 ntohl (put->desired_replication_level), 1768 ntohl (put->desired_replication_level),
@@ -1863,7 +1881,8 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1863 * #GNUNET_SYSERR to close it (signal serious error) 1881 * #GNUNET_SYSERR to close it (signal serious error)
1864 */ 1882 */
1865static int 1883static int
1866handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, 1884handle_dht_p2p_get (void *cls,
1885 const struct GNUNET_PeerIdentity *peer,
1867 const struct GNUNET_MessageHeader *message) 1886 const struct GNUNET_MessageHeader *message)
1868{ 1887{
1869 struct PeerGetMessage *get; 1888 struct PeerGetMessage *get;
@@ -1877,6 +1896,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1877 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 1896 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
1878 const char *xquery; 1897 const char *xquery;
1879 struct GNUNET_HashCode phash; 1898 struct GNUNET_HashCode phash;
1899 int forwarded;
1880 1900
1881 GNUNET_break (0 != 1901 GNUNET_break (0 !=
1882 memcmp (peer, &my_identity, 1902 memcmp (peer, &my_identity,
@@ -1906,7 +1926,9 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1906 GNUNET_STATISTICS_update (GDS_stats, 1926 GNUNET_STATISTICS_update (GDS_stats,
1907 gettext_noop ("# P2P GET bytes received"), msize, 1927 gettext_noop ("# P2P GET bytes received"), msize,
1908 GNUNET_NO); 1928 GNUNET_NO);
1909 GNUNET_CRYPTO_hash (peer, sizeof (struct GNUNET_PeerIdentity), &phash); 1929 GNUNET_CRYPTO_hash (peer,
1930 sizeof (struct GNUNET_PeerIdentity),
1931 &phash);
1910 if (GNUNET_YES == log_route_details_stderr) 1932 if (GNUNET_YES == log_route_details_stderr)
1911 { 1933 {
1912 char *tmp; 1934 char *tmp;
@@ -1918,8 +1940,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1918 ntohl(get->hop_count), 1940 ntohl(get->hop_count),
1919 GNUNET_CRYPTO_hash_matching_bits (&phash, &get->key), 1941 GNUNET_CRYPTO_hash_matching_bits (&phash, &get->key),
1920 GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, &get->key), 1942 GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, &get->key),
1921 ntohl(get->xquery_size), xquery 1943 ntohl(get->xquery_size), xquery);
1922 );
1923 GNUNET_free (tmp); 1944 GNUNET_free (tmp);
1924 } 1945 }
1925 1946
@@ -1947,8 +1968,10 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1947 /* remember request for routing replies */ 1968 /* remember request for routing replies */
1948 GDS_ROUTING_add (peer, type, options, &get->key, xquery, xquery_size, 1969 GDS_ROUTING_add (peer, type, options, &get->key, xquery, xquery_size,
1949 reply_bf, get->bf_mutator); 1970 reply_bf, get->bf_mutator);
1950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n", 1971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1951 GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity), 1972 "GET for %s at %s after %u hops\n",
1973 GNUNET_h2s (&get->key),
1974 GNUNET_i2s (&my_identity),
1952 (unsigned int) ntohl (get->hop_count)); 1975 (unsigned int) ntohl (get->hop_count));
1953 /* local lookup (this may update the reply_bf) */ 1976 /* local lookup (this may update the reply_bf) */
1954 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 1977 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
@@ -1976,19 +1999,27 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1976 1, GNUNET_NO); 1999 1, GNUNET_NO);
1977 } 2000 }
1978 2001
1979 GDS_CLIENTS_process_get (options, 2002 /* P2P forwarding */
2003 forwarded = GNUNET_NO;
2004 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
2005 forwarded = GDS_NEIGHBOURS_handle_get (type, options,
2006 ntohl (get->desired_replication_level),
2007 ntohl (get->hop_count),
2008 &get->key,
2009 xquery,
2010 xquery_size,
2011 reply_bf,
2012 get->bf_mutator, peer_bf);
2013 GDS_CLIENTS_process_get (options
2014 | (GNUNET_OK == forwarded)
2015 ? GNUNET_DHT_RO_LAST_HOP : 0,
1980 type, 2016 type,
1981 ntohl(get->hop_count), 2017 ntohl (get->hop_count),
1982 ntohl(get->desired_replication_level), 2018 ntohl (get->desired_replication_level),
1983 0, NULL, 2019 0, NULL,
1984 &get->key); 2020 &get->key);
1985 2021
1986 /* P2P forwarding */ 2022
1987 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
1988 GDS_NEIGHBOURS_handle_get (type, options,
1989 ntohl (get->desired_replication_level),
1990 ntohl (get->hop_count), &get->key, xquery,
1991 xquery_size, reply_bf, get->bf_mutator, peer_bf);
1992 /* clean up */ 2023 /* clean up */
1993 if (NULL != reply_bf) 2024 if (NULL != reply_bf)
1994 GNUNET_CONTAINER_bloomfilter_free (reply_bf); 2025 GNUNET_CONTAINER_bloomfilter_free (reply_bf);
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h
index 6eac593a0..1c0b24c1b 100644
--- a/src/dht/gnunet-service-dht_neighbours.h
+++ b/src/dht/gnunet-service-dht_neighbours.h
@@ -49,8 +49,9 @@
49 * @param put_path peers this request has traversed so far (if tracked) 49 * @param put_path peers this request has traversed so far (if tracked)
50 * @param data payload to store 50 * @param data payload to store
51 * @param data_size number of bytes in data 51 * @param data_size number of bytes in data
52 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
52 */ 53 */
53void 54int
54GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, 55GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
55 enum GNUNET_DHT_RouteOption options, 56 enum GNUNET_DHT_RouteOption options,
56 uint32_t desired_replication_level, 57 uint32_t desired_replication_level,
@@ -79,8 +80,9 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
79 * @param reply_bf bloomfilter to filter duplicates 80 * @param reply_bf bloomfilter to filter duplicates
80 * @param reply_bf_mutator mutator for @a reply_bf 81 * @param reply_bf_mutator mutator for @a reply_bf
81 * @param peer_bf filter for peers not to select (again, updated) 82 * @param peer_bf filter for peers not to select (again, updated)
83 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
82 */ 84 */
83void 85int
84GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, 86GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
85 enum GNUNET_DHT_RouteOption options, 87 enum GNUNET_DHT_RouteOption options,
86 uint32_t desired_replication_level, 88 uint32_t desired_replication_level,
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h
index 3e59f2b6d..33c6551db 100644
--- a/src/include/gnunet_dht_service.h
+++ b/src/include/gnunet_dht_service.h
@@ -95,7 +95,12 @@ enum GNUNET_DHT_RouteOption
95 /** 95 /**
96 * Possible message option for query key randomization. 96 * Possible message option for query key randomization.
97 */ 97 */
98 GNUNET_DHT_RO_BART = 8 98 GNUNET_DHT_RO_BART = 8,
99
100 /**
101 * Flag given to monitors if this was the last hop for a GET/PUT.
102 */
103 GNUNET_DHT_RO_LAST_HOP = 16
99}; 104};
100 105
101 106