diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2022-01-03 15:35:49 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2022-01-03 15:35:49 +0100 |
commit | 44efce8316b644f15b5e87852f5b7df7d58cfa97 (patch) | |
tree | 8c65a552e11b56ab86748eafdac4a87958cf5d1e /src/dht | |
parent | f72a57c08e2f3d4c55fd0a700b48138fdfe8df5d (diff) | |
download | gnunet-44efce8316b644f15b5e87852f5b7df7d58cfa97.tar.gz gnunet-44efce8316b644f15b5e87852f5b7df7d58cfa97.zip |
-more DHT code cleanup (no substantial changes)
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-dht_clients.c | 4 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.c | 2 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 306 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.h | 16 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_routing.c | 29 |
5 files changed, 188 insertions, 169 deletions
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 28be0e9be..245130dbc 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -837,8 +837,8 @@ handle_dht_local_get_stop ( | |||
837 | struct RemoveByUniqueIdContext ctx; | 837 | struct RemoveByUniqueIdContext ctx; |
838 | 838 | ||
839 | GNUNET_STATISTICS_update (GDS_stats, | 839 | GNUNET_STATISTICS_update (GDS_stats, |
840 | gettext_noop | 840 | "# GET STOP requests received from clients", |
841 | ("# GET STOP requests received from clients"), 1, | 841 | 1, |
842 | GNUNET_NO); | 842 | GNUNET_NO); |
843 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 843 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
844 | "Received GET STOP request for %s from local client %p\n", | 844 | "Received GET STOP request for %s from local client %p\n", |
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index 131cad8aa..214c4a3f4 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c | |||
@@ -237,7 +237,7 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, | |||
237 | if (NULL == datacache) | 237 | if (NULL == datacache) |
238 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 238 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
239 | GNUNET_STATISTICS_update (GDS_stats, | 239 | GNUNET_STATISTICS_update (GDS_stats, |
240 | gettext_noop ("# GET requests given to datacache"), | 240 | "# GET requests given to datacache", |
241 | 1, | 241 | 1, |
242 | GNUNET_NO); | 242 | GNUNET_NO); |
243 | ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 243 | ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 01a68b0b7..35502e0f5 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -1253,8 +1253,6 @@ get_target_peers (const struct GNUNET_HashCode *key, | |||
1253 | } | 1253 | } |
1254 | 1254 | ||
1255 | 1255 | ||
1256 | // FIXME-CG: REVIEW from here... | ||
1257 | |||
1258 | enum GNUNET_GenericReturnValue | 1256 | enum GNUNET_GenericReturnValue |
1259 | GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | 1257 | GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, |
1260 | enum GNUNET_DHT_RouteOption options, | 1258 | enum GNUNET_DHT_RouteOption options, |
@@ -1263,13 +1261,8 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1263 | struct GNUNET_CONTAINER_BloomFilter *bf) | 1261 | struct GNUNET_CONTAINER_BloomFilter *bf) |
1264 | { | 1262 | { |
1265 | unsigned int target_count; | 1263 | unsigned int target_count; |
1266 | unsigned int i; | ||
1267 | struct PeerInfo **targets; | 1264 | struct PeerInfo **targets; |
1268 | struct PeerInfo *target; | ||
1269 | size_t msize; | 1265 | size_t msize; |
1270 | struct GNUNET_MQ_Envelope *env; | ||
1271 | struct PeerPutMessage *ppm; | ||
1272 | struct GNUNET_PeerIdentity *pp; | ||
1273 | unsigned int skip_count; | 1266 | unsigned int skip_count; |
1274 | unsigned int put_path_length = bd->put_path_length; | 1267 | unsigned int put_path_length = bd->put_path_length; |
1275 | 1268 | ||
@@ -1314,14 +1307,14 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1314 | GNUNET_free (targets); | 1307 | GNUNET_free (targets); |
1315 | return GNUNET_NO; | 1308 | return GNUNET_NO; |
1316 | } | 1309 | } |
1317 | GNUNET_STATISTICS_update (GDS_stats, | ||
1318 | "# PUT messages queued for transmission", | ||
1319 | target_count, | ||
1320 | GNUNET_NO); | ||
1321 | skip_count = 0; | 1310 | skip_count = 0; |
1322 | for (i = 0; i < target_count; i++) | 1311 | for (unsigned int i = 0; i < target_count; i++) |
1323 | { | 1312 | { |
1324 | target = targets[i]; | 1313 | struct PeerInfo *target = targets[i]; |
1314 | struct GNUNET_MQ_Envelope *env; | ||
1315 | struct PeerPutMessage *ppm; | ||
1316 | struct GNUNET_PeerIdentity *pp; | ||
1317 | |||
1325 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) | 1318 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) |
1326 | { | 1319 | { |
1327 | /* skip */ | 1320 | /* skip */ |
@@ -1365,6 +1358,10 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1365 | env); | 1358 | env); |
1366 | } | 1359 | } |
1367 | GNUNET_free (targets); | 1360 | GNUNET_free (targets); |
1361 | GNUNET_STATISTICS_update (GDS_stats, | ||
1362 | "# PUT messages queued for transmission", | ||
1363 | target_count - skip_count, | ||
1364 | GNUNET_NO); | ||
1368 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; | 1365 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; |
1369 | } | 1366 | } |
1370 | 1367 | ||
@@ -1382,11 +1379,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1382 | { | 1379 | { |
1383 | unsigned int target_count; | 1380 | unsigned int target_count; |
1384 | struct PeerInfo **targets; | 1381 | struct PeerInfo **targets; |
1385 | struct PeerInfo *target; | ||
1386 | struct GNUNET_MQ_Envelope *env; | ||
1387 | size_t msize; | 1382 | size_t msize; |
1388 | struct PeerGetMessage *pgm; | ||
1389 | char *xq; | ||
1390 | size_t reply_bf_size; | 1383 | size_t reply_bf_size; |
1391 | void *reply_bf; | 1384 | void *reply_bf; |
1392 | unsigned int skip_count; | 1385 | unsigned int skip_count; |
@@ -1436,21 +1429,22 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1436 | GNUNET_free (targets); | 1429 | GNUNET_free (targets); |
1437 | return GNUNET_NO; | 1430 | return GNUNET_NO; |
1438 | } | 1431 | } |
1439 | GNUNET_STATISTICS_update (GDS_stats, | ||
1440 | "# GET messages queued for transmission", | ||
1441 | target_count, | ||
1442 | GNUNET_NO); | ||
1443 | /* forward request */ | 1432 | /* forward request */ |
1444 | skip_count = 0; | 1433 | skip_count = 0; |
1445 | for (unsigned int i = 0; i < target_count; i++) | 1434 | for (unsigned int i = 0; i < target_count; i++) |
1446 | { | 1435 | { |
1447 | target = targets[i]; | 1436 | struct PeerInfo *target = targets[i]; |
1437 | struct GNUNET_MQ_Envelope *env; | ||
1438 | struct PeerGetMessage *pgm; | ||
1439 | char *xq; | ||
1440 | |||
1448 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) | 1441 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) |
1449 | { | 1442 | { |
1450 | /* skip */ | 1443 | /* skip */ |
1451 | GNUNET_STATISTICS_update (GDS_stats, | 1444 | GNUNET_STATISTICS_update (GDS_stats, |
1452 | "# P2P messages dropped due to full queue", | 1445 | "# P2P messages dropped due to full queue", |
1453 | 1, GNUNET_NO); | 1446 | 1, |
1447 | GNUNET_NO); | ||
1454 | skip_count++; | 1448 | skip_count++; |
1455 | continue; | 1449 | continue; |
1456 | } | 1450 | } |
@@ -1486,20 +1480,31 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1486 | GNUNET_MQ_send (target->mq, | 1480 | GNUNET_MQ_send (target->mq, |
1487 | env); | 1481 | env); |
1488 | } | 1482 | } |
1483 | GNUNET_STATISTICS_update (GDS_stats, | ||
1484 | "# GET messages queued for transmission", | ||
1485 | target_count - skip_count, | ||
1486 | GNUNET_NO); | ||
1489 | GNUNET_free (targets); | 1487 | GNUNET_free (targets); |
1490 | GNUNET_free (reply_bf); | 1488 | GNUNET_free (reply_bf); |
1491 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; | 1489 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; |
1492 | } | 1490 | } |
1493 | 1491 | ||
1494 | 1492 | ||
1493 | struct PeerInfo * | ||
1494 | GDS_NEIGHBOURS_lookup_peer (const struct GNUNET_PeerIdentity *target) | ||
1495 | { | ||
1496 | return GNUNET_CONTAINER_multipeermap_get (all_connected_peers, | ||
1497 | target); | ||
1498 | } | ||
1499 | |||
1500 | |||
1495 | void | 1501 | void |
1496 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | 1502 | GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, |
1497 | const struct GDS_DATACACHE_BlockData *bd, | 1503 | const struct GDS_DATACACHE_BlockData *bd, |
1498 | const struct GNUNET_HashCode *query_hash, | 1504 | const struct GNUNET_HashCode *query_hash, |
1499 | unsigned int get_path_length, | 1505 | unsigned int get_path_length, |
1500 | const struct GNUNET_PeerIdentity *get_path) | 1506 | const struct GNUNET_PeerIdentity *get_path) |
1501 | { | 1507 | { |
1502 | struct PeerInfo *pi; | ||
1503 | struct GNUNET_MQ_Envelope *env; | 1508 | struct GNUNET_MQ_Envelope *env; |
1504 | struct PeerResultMessage *prm; | 1509 | struct PeerResultMessage *prm; |
1505 | struct GNUNET_PeerIdentity *paths; | 1510 | struct GNUNET_PeerIdentity *paths; |
@@ -1517,16 +1522,6 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | |||
1517 | GNUNET_break (0); | 1522 | GNUNET_break (0); |
1518 | return; | 1523 | return; |
1519 | } | 1524 | } |
1520 | pi = GNUNET_CONTAINER_multipeermap_get (all_connected_peers, | ||
1521 | target); | ||
1522 | if (NULL == pi) | ||
1523 | { | ||
1524 | /* peer disconnected in the meantime, drop reply */ | ||
1525 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1526 | "No matching peer for reply for key %s\n", | ||
1527 | GNUNET_h2s (query_hash)); | ||
1528 | return; | ||
1529 | } | ||
1530 | if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER) | 1525 | if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER) |
1531 | { | 1526 | { |
1532 | /* skip */ | 1527 | /* skip */ |
@@ -1543,7 +1538,7 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | |||
1543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1544 | "Forwarding reply for key %s to peer %s\n", | 1539 | "Forwarding reply for key %s to peer %s\n", |
1545 | GNUNET_h2s (query_hash), | 1540 | GNUNET_h2s (query_hash), |
1546 | GNUNET_i2s (target)); | 1541 | GNUNET_i2s (pi->id)); |
1547 | GNUNET_STATISTICS_update (GDS_stats, | 1542 | GNUNET_STATISTICS_update (GDS_stats, |
1548 | "# RESULT messages queued for transmission", | 1543 | "# RESULT messages queued for transmission", |
1549 | 1, | 1544 | 1, |
@@ -1572,7 +1567,7 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | |||
1572 | 1567 | ||
1573 | 1568 | ||
1574 | /** | 1569 | /** |
1575 | * To be called on core init/fail. | 1570 | * To be called on core init. |
1576 | * | 1571 | * |
1577 | * @param cls service closure | 1572 | * @param cls service closure |
1578 | * @param identity the public identity of this peer | 1573 | * @param identity the public identity of this peer |
@@ -1587,7 +1582,7 @@ core_init (void *cls, | |||
1587 | GNUNET_i2s (identity)); | 1582 | GNUNET_i2s (identity)); |
1588 | my_identity = *identity; | 1583 | my_identity = *identity; |
1589 | GNUNET_CRYPTO_hash (identity, | 1584 | GNUNET_CRYPTO_hash (identity, |
1590 | sizeof(struct GNUNET_PeerIdentity), | 1585 | sizeof(struct GNUNET_PeerIdentity), |
1591 | &my_identity_hash); | 1586 | &my_identity_hash); |
1592 | GNUNET_SERVICE_resume (GDS_service); | 1587 | GNUNET_SERVICE_resume (GDS_service); |
1593 | } | 1588 | } |
@@ -1604,17 +1599,15 @@ static enum GNUNET_GenericReturnValue | |||
1604 | check_dht_p2p_put (void *cls, | 1599 | check_dht_p2p_put (void *cls, |
1605 | const struct PeerPutMessage *put) | 1600 | const struct PeerPutMessage *put) |
1606 | { | 1601 | { |
1607 | uint32_t putlen; | 1602 | uint16_t msize = ntohs (put->header.size); |
1608 | uint16_t msize; | 1603 | uint32_t putlen = ntohl (put->put_path_length); |
1609 | 1604 | ||
1610 | (void) cls; | 1605 | (void) cls; |
1611 | msize = ntohs (put->header.size); | 1606 | if ( (msize < |
1612 | putlen = ntohl (put->put_path_length); | 1607 | sizeof(struct PeerPutMessage) |
1613 | if ((msize < | 1608 | + putlen * sizeof(struct GNUNET_PeerIdentity)) || |
1614 | sizeof(struct PeerPutMessage) | 1609 | (putlen > |
1615 | + putlen * sizeof(struct GNUNET_PeerIdentity)) || | 1610 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ) |
1616 | (putlen > | ||
1617 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) | ||
1618 | { | 1611 | { |
1619 | GNUNET_break_op (0); | 1612 | GNUNET_break_op (0); |
1620 | return GNUNET_SYSERR; | 1613 | return GNUNET_SYSERR; |
@@ -1784,9 +1777,9 @@ handle_dht_p2p_put (void *cls, | |||
1784 | 0, NULL /* get path */); | 1777 | 0, NULL /* get path */); |
1785 | 1778 | ||
1786 | /* store locally */ | 1779 | /* store locally */ |
1787 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 1780 | if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
1788 | (GDS_am_closest_peer (&put->key, | 1781 | (GDS_am_closest_peer (&put->key, |
1789 | bf))) | 1782 | bf)) ) |
1790 | GDS_DATACACHE_handle_put (&bd); | 1783 | GDS_DATACACHE_handle_put (&bd); |
1791 | { | 1784 | { |
1792 | enum GNUNET_GenericReturnValue forwarded; | 1785 | enum GNUNET_GenericReturnValue forwarded; |
@@ -1816,12 +1809,12 @@ handle_dht_p2p_put (void *cls, | |||
1816 | * We have received a FIND PEER request. Send matching | 1809 | * We have received a FIND PEER request. Send matching |
1817 | * HELLOs back. | 1810 | * HELLOs back. |
1818 | * | 1811 | * |
1819 | * @param sender sender of the FIND PEER request | 1812 | * @param pi sender of the FIND PEER request |
1820 | * @param key peers close to this key are desired | 1813 | * @param key peers close to this key are desired |
1821 | * @param bg group for filtering peers | 1814 | * @param bg group for filtering peers |
1822 | */ | 1815 | */ |
1823 | static void | 1816 | static void |
1824 | handle_find_peer (const struct GNUNET_PeerIdentity *sender, | 1817 | handle_find_peer (struct PeerInfo *pi, |
1825 | const struct GNUNET_HashCode *query_hash, | 1818 | const struct GNUNET_HashCode *query_hash, |
1826 | struct GNUNET_BLOCK_Group *bg) | 1819 | struct GNUNET_BLOCK_Group *bg) |
1827 | { | 1820 | { |
@@ -1852,7 +1845,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1852 | bd.data, | 1845 | bd.data, |
1853 | bd.data_size)) | 1846 | bd.data_size)) |
1854 | { | 1847 | { |
1855 | GDS_NEIGHBOURS_handle_reply (sender, | 1848 | GDS_NEIGHBOURS_handle_reply (pi, |
1856 | &bd, | 1849 | &bd, |
1857 | query_hash, | 1850 | query_hash, |
1858 | 0, NULL /* get path */); | 1851 | 0, NULL /* get path */); |
@@ -1925,7 +1918,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1925 | bd.key = peer->phash; | 1918 | bd.key = peer->phash; |
1926 | bd.data = hello; | 1919 | bd.data = hello; |
1927 | bd.data_size = hello_size; | 1920 | bd.data_size = hello_size; |
1928 | GDS_NEIGHBOURS_handle_reply (sender, | 1921 | GDS_NEIGHBOURS_handle_reply (pi, |
1929 | &bd, | 1922 | &bd, |
1930 | query_hash, | 1923 | query_hash, |
1931 | 0, NULL /* get path */); | 1924 | 0, NULL /* get path */); |
@@ -1956,7 +1949,7 @@ handle_local_result (void *cls, | |||
1956 | pp); | 1949 | pp); |
1957 | GNUNET_free (pp); | 1950 | GNUNET_free (pp); |
1958 | } | 1951 | } |
1959 | GDS_NEIGHBOURS_handle_reply (peer->id, | 1952 | GDS_NEIGHBOURS_handle_reply (peer, |
1960 | bd, | 1953 | bd, |
1961 | &bd->key, | 1954 | &bd->key, |
1962 | 0, NULL /* get path */); | 1955 | 0, NULL /* get path */); |
@@ -1974,13 +1967,11 @@ static enum GNUNET_GenericReturnValue | |||
1974 | check_dht_p2p_get (void *cls, | 1967 | check_dht_p2p_get (void *cls, |
1975 | const struct PeerGetMessage *get) | 1968 | const struct PeerGetMessage *get) |
1976 | { | 1969 | { |
1977 | uint32_t xquery_size; | 1970 | uint16_t msize = ntohs (get->header.size); |
1978 | uint16_t msize; | 1971 | uint32_t xquery_size = ntohl (get->xquery_size); |
1979 | 1972 | ||
1980 | (void) cls; | 1973 | (void) cls; |
1981 | msize = ntohs (get->header.size); | 1974 | if (msize < sizeof(*get) + xquery_size) |
1982 | xquery_size = ntohl (get->xquery_size); | ||
1983 | if (msize < sizeof(struct PeerGetMessage) + xquery_size) | ||
1984 | { | 1975 | { |
1985 | GNUNET_break_op (0); | 1976 | GNUNET_break_op (0); |
1986 | return GNUNET_SYSERR; | 1977 | return GNUNET_SYSERR; |
@@ -2000,24 +1991,16 @@ handle_dht_p2p_get (void *cls, | |||
2000 | const struct PeerGetMessage *get) | 1991 | const struct PeerGetMessage *get) |
2001 | { | 1992 | { |
2002 | struct PeerInfo *peer = cls; | 1993 | struct PeerInfo *peer = cls; |
2003 | uint32_t xquery_size; | 1994 | uint16_t msize = ntohs (get->header.size); |
2004 | size_t reply_bf_size; | 1995 | uint32_t xquery_size = ntohl (get->xquery_size); |
2005 | uint16_t msize; | 1996 | uint32_t hop_count = ntohl (get->hop_count); |
2006 | enum GNUNET_BLOCK_Type type; | 1997 | size_t reply_bf_size = msize - (sizeof(*get) + xquery_size); |
2007 | enum GNUNET_DHT_RouteOption options; | 1998 | enum GNUNET_BLOCK_Type type = (enum GNUNET_BLOCK_Type) ntohl (get->type); |
1999 | enum GNUNET_DHT_RouteOption options = (enum GNUNET_DHT_RouteOption) ntohl (get->options); | ||
2008 | enum GNUNET_BLOCK_ReplyEvaluationResult eval = GNUNET_BLOCK_REPLY_OK_MORE; | 2000 | enum GNUNET_BLOCK_ReplyEvaluationResult eval = GNUNET_BLOCK_REPLY_OK_MORE; |
2009 | struct GNUNET_BLOCK_Group *bg; | 2001 | const void *xquery = (const void *) &get[1]; |
2010 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | ||
2011 | const void *xquery; | ||
2012 | enum GNUNET_GenericReturnValue forwarded; | ||
2013 | 2002 | ||
2014 | /* parse and validate message */ | 2003 | /* parse and validate message */ |
2015 | msize = ntohs (get->header.size); | ||
2016 | xquery_size = ntohl (get->xquery_size); | ||
2017 | reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size); | ||
2018 | type = ntohl (get->type); | ||
2019 | options = ntohl (get->options); | ||
2020 | xquery = (const void *) &get[1]; | ||
2021 | GNUNET_STATISTICS_update (GDS_stats, | 2004 | GNUNET_STATISTICS_update (GDS_stats, |
2022 | "# P2P GET requests received", | 2005 | "# P2P GET requests received", |
2023 | 1, | 2006 | 1, |
@@ -2044,7 +2027,7 @@ handle_dht_p2p_get (void *cls, | |||
2044 | GNUNET_h2s (&get->key), | 2027 | GNUNET_h2s (&get->key), |
2045 | GNUNET_i2s (peer->id), | 2028 | GNUNET_i2s (peer->id), |
2046 | tmp, | 2029 | tmp, |
2047 | ntohl (get->hop_count), | 2030 | hop_count, |
2048 | GNUNET_CRYPTO_hash_count_leading_zeros (&pxor), | 2031 | GNUNET_CRYPTO_hash_count_leading_zeros (&pxor), |
2049 | GNUNET_CRYPTO_hash_count_leading_zeros (&mxor), | 2032 | GNUNET_CRYPTO_hash_count_leading_zeros (&mxor), |
2050 | ntohl (get->xquery_size), | 2033 | ntohl (get->xquery_size), |
@@ -2062,93 +2045,104 @@ handle_dht_p2p_get (void *cls, | |||
2062 | GNUNET_break_op (0); | 2045 | GNUNET_break_op (0); |
2063 | return; | 2046 | return; |
2064 | } | 2047 | } |
2065 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, | 2048 | |
2066 | DHT_BLOOM_SIZE, | ||
2067 | GNUNET_CONSTANTS_BLOOMFILTER_K); | ||
2068 | GNUNET_break_op (GNUNET_YES == | ||
2069 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, | ||
2070 | &peer->phash)); | ||
2071 | bg = GNUNET_BLOCK_group_create (GDS_block_context, | ||
2072 | type, | ||
2073 | get->bf_mutator, | ||
2074 | xquery + xquery_size, | ||
2075 | reply_bf_size, | ||
2076 | "filter-size", | ||
2077 | reply_bf_size, | ||
2078 | NULL); | ||
2079 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2080 | "GET for %s at %s after %u hops\n", | ||
2081 | GNUNET_h2s (&get->key), | ||
2082 | GNUNET_i2s (&my_identity), | ||
2083 | (unsigned int) ntohl (get->hop_count)); | ||
2084 | /* local lookup (this may update the reply_bf) */ | ||
2085 | if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | ||
2086 | (GDS_am_closest_peer (&get->key, | ||
2087 | peer_bf)) ) | ||
2088 | { | 2049 | { |
2089 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) | 2050 | struct GNUNET_BLOCK_Group *bg; |
2051 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | ||
2052 | |||
2053 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, | ||
2054 | DHT_BLOOM_SIZE, | ||
2055 | GNUNET_CONSTANTS_BLOOMFILTER_K); | ||
2056 | GNUNET_break_op (GNUNET_YES == | ||
2057 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, | ||
2058 | &peer->phash)); | ||
2059 | bg = GNUNET_BLOCK_group_create (GDS_block_context, | ||
2060 | type, | ||
2061 | get->bf_mutator, | ||
2062 | xquery + xquery_size, | ||
2063 | reply_bf_size, | ||
2064 | "filter-size", | ||
2065 | reply_bf_size, | ||
2066 | NULL); | ||
2067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2068 | "GET for %s at %s after %u hops\n", | ||
2069 | GNUNET_h2s (&get->key), | ||
2070 | GNUNET_i2s (&my_identity), | ||
2071 | (unsigned int) hop_count); | ||
2072 | /* local lookup (this may update the reply_bf) */ | ||
2073 | if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | ||
2074 | (GDS_am_closest_peer (&get->key, | ||
2075 | peer_bf)) ) | ||
2090 | { | 2076 | { |
2091 | GNUNET_STATISTICS_update (GDS_stats, | 2077 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) |
2092 | "# P2P FIND PEER requests processed", | 2078 | { |
2093 | 1, | 2079 | GNUNET_STATISTICS_update (GDS_stats, |
2094 | GNUNET_NO); | 2080 | "# P2P FIND PEER requests processed", |
2095 | handle_find_peer (peer->id, | 2081 | 1, |
2096 | &get->key, | 2082 | GNUNET_NO); |
2097 | bg); | 2083 | handle_find_peer (peer, |
2084 | &get->key, | ||
2085 | bg); | ||
2086 | } | ||
2087 | else | ||
2088 | { | ||
2089 | eval = GDS_DATACACHE_handle_get (&get->key, | ||
2090 | type, | ||
2091 | xquery, | ||
2092 | xquery_size, | ||
2093 | bg, | ||
2094 | &handle_local_result, | ||
2095 | peer); | ||
2096 | } | ||
2098 | } | 2097 | } |
2099 | else | 2098 | else |
2099 | { | ||
2100 | GNUNET_STATISTICS_update (GDS_stats, | ||
2101 | "# P2P GET requests ONLY routed", | ||
2102 | 1, | ||
2103 | GNUNET_NO); | ||
2104 | } | ||
2105 | |||
2106 | /* remember request for routing replies */ | ||
2107 | GDS_ROUTING_add (peer->id, | ||
2108 | type, | ||
2109 | bg, /* bg now owned by routing, but valid at least until end of this function! */ | ||
2110 | options, | ||
2111 | &get->key, | ||
2112 | xquery, | ||
2113 | xquery_size); | ||
2114 | |||
2115 | /* P2P forwarding */ | ||
2100 | { | 2116 | { |
2101 | eval = GDS_DATACACHE_handle_get (&get->key, | 2117 | bool forwarded = false; |
2102 | type, | 2118 | uint32_t desired_replication_level = ntohl (get->desired_replication_level); |
2103 | xquery, | 2119 | |
2104 | xquery_size, | 2120 | if (eval != GNUNET_BLOCK_REPLY_OK_LAST) |
2105 | bg, | 2121 | forwarded = (GNUNET_OK == |
2106 | &handle_local_result, | 2122 | GDS_NEIGHBOURS_handle_get (type, |
2107 | peer); | 2123 | options, |
2124 | desired_replication_level, | ||
2125 | hop_count, | ||
2126 | &get->key, | ||
2127 | xquery, | ||
2128 | xquery_size, | ||
2129 | bg, | ||
2130 | peer_bf)); | ||
2131 | GDS_CLIENTS_process_get ( | ||
2132 | options | | ||
2133 | (forwarded | ||
2134 | ? 0 | ||
2135 | : GNUNET_DHT_RO_LAST_HOP), | ||
2136 | type, | ||
2137 | hop_count, | ||
2138 | desired_replication_level, | ||
2139 | 0, | ||
2140 | NULL, | ||
2141 | &get->key); | ||
2108 | } | 2142 | } |
2143 | /* clean up; note that 'bg' is owned by routing now! */ | ||
2144 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); | ||
2109 | } | 2145 | } |
2110 | else | ||
2111 | { | ||
2112 | GNUNET_STATISTICS_update (GDS_stats, | ||
2113 | "# P2P GET requests ONLY routed", | ||
2114 | 1, | ||
2115 | GNUNET_NO); | ||
2116 | } | ||
2117 | |||
2118 | /* remember request for routing replies */ | ||
2119 | GDS_ROUTING_add (peer->id, | ||
2120 | type, | ||
2121 | bg, /* bg now owned by routing, but valid at least until end of this function! */ | ||
2122 | options, | ||
2123 | &get->key, | ||
2124 | xquery, | ||
2125 | xquery_size); | ||
2126 | |||
2127 | /* P2P forwarding */ | ||
2128 | forwarded = GNUNET_NO; | ||
2129 | if (eval != GNUNET_BLOCK_REPLY_OK_LAST) | ||
2130 | forwarded = GDS_NEIGHBOURS_handle_get (type, | ||
2131 | options, | ||
2132 | ntohl ( | ||
2133 | get->desired_replication_level), | ||
2134 | ntohl (get->hop_count), | ||
2135 | &get->key, | ||
2136 | xquery, | ||
2137 | xquery_size, | ||
2138 | bg, | ||
2139 | peer_bf); | ||
2140 | GDS_CLIENTS_process_get (options | ||
2141 | | ((GNUNET_OK == forwarded) | ||
2142 | ? GNUNET_DHT_RO_LAST_HOP : 0), | ||
2143 | type, | ||
2144 | ntohl (get->hop_count), | ||
2145 | ntohl (get->desired_replication_level), | ||
2146 | 0, | ||
2147 | NULL, | ||
2148 | &get->key); | ||
2149 | |||
2150 | /* clean up; note that 'bg' is owned by routing now! */ | ||
2151 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); | ||
2152 | } | 2146 | } |
2153 | 2147 | ||
2154 | 2148 | ||
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h index ba7cc6055..28468c740 100644 --- a/src/dht/gnunet-service-dht_neighbours.h +++ b/src/dht/gnunet-service-dht_neighbours.h | |||
@@ -38,6 +38,18 @@ | |||
38 | extern struct GNUNET_HashCode my_identity_hash; | 38 | extern struct GNUNET_HashCode my_identity_hash; |
39 | 39 | ||
40 | 40 | ||
41 | struct PeerInfo; | ||
42 | |||
43 | /** | ||
44 | * Lookup peer by peer's identity. | ||
45 | * | ||
46 | * @param target peer to look up | ||
47 | * @return NULL if we are not connected to @a target | ||
48 | */ | ||
49 | struct PeerInfo * | ||
50 | GDS_NEIGHBOURS_lookup_peer (const struct GNUNET_PeerIdentity *target); | ||
51 | |||
52 | |||
41 | /** | 53 | /** |
42 | * Perform a PUT operation. Forwards the given request to other | 54 | * Perform a PUT operation. Forwards the given request to other |
43 | * peers. Does not store the data locally. Does not give the | 55 | * peers. Does not store the data locally. Does not give the |
@@ -94,7 +106,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
94 | * other peers waiting for it. Does not do local caching or | 106 | * other peers waiting for it. Does not do local caching or |
95 | * forwarding to local clients. | 107 | * forwarding to local clients. |
96 | * | 108 | * |
97 | * @param target neighbour that should receive the block (if still connected) | 109 | * @param pi neighbour that should receive the block |
98 | * @param type type of the block | 110 | * @param type type of the block |
99 | * @param bd details about the reply | 111 | * @param bd details about the reply |
100 | * @param query_hash query that was used for the request | 112 | * @param query_hash query that was used for the request |
@@ -102,7 +114,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
102 | * @param get_path peers this reply has traversed so far (if tracked) | 114 | * @param get_path peers this reply has traversed so far (if tracked) |
103 | */ | 115 | */ |
104 | void | 116 | void |
105 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | 117 | GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, |
106 | const struct GDS_DATACACHE_BlockData *bd, | 118 | const struct GDS_DATACACHE_BlockData *bd, |
107 | const struct GNUNET_HashCode *query_hash, | 119 | const struct GNUNET_HashCode *query_hash, |
108 | unsigned int get_path_length, | 120 | unsigned int get_path_length, |
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c index 8ba0c70ad..ec36eae75 100644 --- a/src/dht/gnunet-service-dht_routing.c +++ b/src/dht/gnunet-service-dht_routing.c | |||
@@ -179,14 +179,27 @@ process (void *cls, | |||
179 | case GNUNET_BLOCK_REPLY_OK_MORE: | 179 | case GNUNET_BLOCK_REPLY_OK_MORE: |
180 | case GNUNET_BLOCK_REPLY_OK_LAST: | 180 | case GNUNET_BLOCK_REPLY_OK_LAST: |
181 | case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED: | 181 | case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED: |
182 | GNUNET_STATISTICS_update (GDS_stats, | 182 | { |
183 | "# Good REPLIES matched against routing table", | 183 | struct PeerInfo *pi; |
184 | 1, | 184 | |
185 | GNUNET_NO); | 185 | GNUNET_STATISTICS_update (GDS_stats, |
186 | GDS_NEIGHBOURS_handle_reply (&rr->peer, | 186 | "# Good REPLIES matched against routing table", |
187 | &bdx, | 187 | 1, |
188 | query_hash, | 188 | GNUNET_NO); |
189 | get_path_length, pc->get_path); | 189 | pi = GDS_NEIGHBOURS_lookup_peer (&rr->peer); |
190 | if (NULL == pi) | ||
191 | { | ||
192 | /* peer disconnected in the meantime, drop reply */ | ||
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
194 | "No matching peer for reply for key %s\n", | ||
195 | GNUNET_h2s (query_hash)); | ||
196 | return GNUNET_OK; | ||
197 | } | ||
198 | GDS_NEIGHBOURS_handle_reply (pi, | ||
199 | &bdx, | ||
200 | query_hash, | ||
201 | get_path_length, pc->get_path); | ||
202 | } | ||
190 | break; | 203 | break; |
191 | case GNUNET_BLOCK_REPLY_OK_DUPLICATE: | 204 | case GNUNET_BLOCK_REPLY_OK_DUPLICATE: |
192 | GNUNET_STATISTICS_update (GDS_stats, | 205 | GNUNET_STATISTICS_update (GDS_stats, |