aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-11-12 13:38:39 +0000
committerChristian Grothoff <christian@grothoff.org>2012-11-12 13:38:39 +0000
commit386e076d4958b21dcc100661ec1343054904949a (patch)
treeed5c3556a7499d3ceaa023bf7c5745710eea2907
parent7c816a27d26eaa70f7596346b6d47a5bfdf9ac84 (diff)
downloadgnunet-386e076d4958b21dcc100661ec1343054904949a.tar.gz
gnunet-386e076d4958b21dcc100661ec1343054904949a.zip
-do not expire too soon
-rw-r--r--src/mesh/gnunet-service-mesh.c323
1 files changed, 165 insertions, 158 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index a3f1087f2..7d125ca4b 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -1539,138 +1539,6 @@ regex_free_result (void *cls,
1539 1539
1540 1540
1541/** 1541/**
1542 * Regex callback iterator to store own service description in the DHT.
1543 *
1544 * @param cls closure.
1545 * @param key hash for current state.
1546 * @param proof proof for current state.
1547 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
1548 * @param num_edges number of edges leaving current state.
1549 * @param edges edges leaving current state.
1550 */
1551void
1552regex_iterator (void *cls,
1553 const struct GNUNET_HashCode *key,
1554 const char *proof,
1555 int accepting,
1556 unsigned int num_edges,
1557 const struct GNUNET_REGEX_Edge *edges)
1558{
1559 struct MeshRegexBlock *block;
1560 struct MeshRegexEdge *block_edge;
1561 enum GNUNET_DHT_RouteOption opt;
1562 size_t size;
1563 size_t len;
1564 unsigned int i;
1565 unsigned int offset;
1566 char *aux;
1567
1568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1569 " regex dht put for state %s\n",
1570 GNUNET_h2s(key));
1571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1572 " proof: %s\n",
1573 proof);
1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1575 " num edges: %u\n",
1576 num_edges);
1577
1578 opt = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
1579 if (GNUNET_YES == accepting)
1580 {
1581 struct MeshRegexAccept block;
1582
1583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1584 " state %s is accepting, putting own id\n",
1585 GNUNET_h2s(key));
1586 size = sizeof (block);
1587 block.key = *key;
1588 block.id = my_full_id;
1589 (void)
1590 GNUNET_DHT_put(dht_handle, key,
1591 dht_replication_level,
1592 opt | GNUNET_DHT_RO_RECORD_ROUTE,
1593 GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT,
1594 size,
1595 (char *) &block,
1596 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1597 app_announce_time),
1598 app_announce_time,
1599 NULL, NULL);
1600 }
1601 len = strlen(proof);
1602 size = sizeof (struct MeshRegexBlock) + len;
1603 block = GNUNET_malloc (size);
1604
1605 block->key = *key;
1606 block->n_proof = htonl (len);
1607 block->n_edges = htonl (num_edges);
1608 block->accepting = htonl (accepting);
1609
1610 /* Store the proof at the end of the block. */
1611 aux = (char *) &block[1];
1612 memcpy (aux, proof, len);
1613 aux = &aux[len];
1614
1615 /* Store each edge in a variable length MeshEdge struct at the
1616 * very end of the MeshRegexBlock structure.
1617 */
1618 for (i = 0; i < num_edges; i++)
1619 {
1620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1621 " edge %s towards %s\n",
1622 edges[i].label,
1623 GNUNET_h2s(&edges[i].destination));
1624
1625 /* aux points at the end of the last block */
1626 len = strlen (edges[i].label);
1627 size += sizeof (struct MeshRegexEdge) + len;
1628 // Calculate offset FIXME is this ok? use size instead?
1629 offset = aux - (char *) block;
1630 block = GNUNET_realloc (block, size);
1631 aux = &((char *) block)[offset];
1632 block_edge = (struct MeshRegexEdge *) aux;
1633 block_edge->key = edges[i].destination;
1634 block_edge->n_token = htonl (len);
1635 aux = (char *) &block_edge[1];
1636 memcpy (aux, edges[i].label, len);
1637 aux = &aux[len];
1638 }
1639 (void)
1640 GNUNET_DHT_put(dht_handle, key,
1641 dht_replication_level,
1642 opt,
1643 GNUNET_BLOCK_TYPE_MESH_REGEX, size,
1644 (char *) block,
1645 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1646 app_announce_time),
1647 app_announce_time,
1648 NULL, NULL);
1649 GNUNET_free (block);
1650}
1651
1652
1653/**
1654 * Store the regular expression describing a local service into the DHT.
1655 *
1656 * @param regex The regular expresion.
1657 */
1658static void
1659regex_put (struct MeshRegexDescriptor *regex)
1660{
1661 if (NULL == regex->dfa)
1662 {
1663 regex->dfa = GNUNET_REGEX_construct_dfa (regex->regex,
1664 strlen (regex->regex),
1665 regex->compression);
1666 }
1667
1668 DEBUG_DHT (" regex_put (%s) start\n", regex->regex);
1669 GNUNET_REGEX_iterate_all_edges (regex->dfa, &regex_iterator, NULL);
1670 DEBUG_DHT (" regex_put (%s) end\n", regex);
1671}
1672
1673/**
1674 * Find a path to a peer that offers a regex servcie compatible 1542 * Find a path to a peer that offers a regex servcie compatible
1675 * with a given string. 1543 * with a given string.
1676 * 1544 *
@@ -1823,19 +1691,170 @@ announce_application (void *cls, const struct GNUNET_HashCode * key, void *value
1823 1691
1824 GNUNET_break (NULL != 1692 GNUNET_break (NULL !=
1825 GNUNET_DHT_put (dht_handle, key, 1693 GNUNET_DHT_put (dht_handle, key,
1826 dht_replication_level, 1694 dht_replication_level,
1827 GNUNET_DHT_RO_RECORD_ROUTE | 1695 GNUNET_DHT_RO_RECORD_ROUTE |
1828 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 1696 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1829 GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE, 1697 GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE,
1830 sizeof (block), 1698 sizeof (block),
1831 (const char *) &block, 1699 (const char *) &block,
1832 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), 1700 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: this should be an option */
1833 app_announce_time), 1701 app_announce_time, NULL, NULL));
1834 app_announce_time, NULL, NULL));
1835 return GNUNET_OK; 1702 return GNUNET_OK;
1836} 1703}
1837 1704
1838 1705
1706#if 0
1707/**
1708 * Function called when the DHT regex put is complete.
1709 *
1710 * @param the 'struct MeshClient' for which we were PUTting
1711 * @param success GNUNET_OK if the PUT was transmitted,
1712 * GNUNET_NO on timeout,
1713 * GNUNET_SYSERR on disconnect from service
1714 * after the PUT message was transmitted
1715 * (so we don't know if it was received or not)
1716 */
1717static void
1718announce_regex_done (void *cls,
1719 int success)
1720{
1721 struct MeshClient *c = cls;
1722
1723}
1724#endif
1725
1726
1727/**
1728 * Regex callback iterator to store own service description in the DHT.
1729 *
1730 * @param cls closure.
1731 * @param key hash for current state.
1732 * @param proof proof for current state.
1733 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
1734 * @param num_edges number of edges leaving current state.
1735 * @param edges edges leaving current state.
1736 */
1737static void
1738regex_iterator (void *cls,
1739 const struct GNUNET_HashCode *key,
1740 const char *proof,
1741 int accepting,
1742 unsigned int num_edges,
1743 const struct GNUNET_REGEX_Edge *edges)
1744{
1745 struct MeshRegexBlock *block;
1746 struct MeshRegexEdge *block_edge;
1747 enum GNUNET_DHT_RouteOption opt;
1748 size_t size;
1749 size_t len;
1750 unsigned int i;
1751 unsigned int offset;
1752 char *aux;
1753
1754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1755 " regex dht put for state %s\n",
1756 GNUNET_h2s(key));
1757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1758 " proof: %s\n",
1759 proof);
1760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1761 " num edges: %u\n",
1762 num_edges);
1763
1764 opt = GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
1765 if (GNUNET_YES == accepting)
1766 {
1767 struct MeshRegexAccept block;
1768
1769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1770 " state %s is accepting, putting own id\n",
1771 GNUNET_h2s(key));
1772 size = sizeof (block);
1773 block.key = *key;
1774 block.id = my_full_id;
1775 (void)
1776 GNUNET_DHT_put(dht_handle, key,
1777 dht_replication_level,
1778 opt | GNUNET_DHT_RO_RECORD_ROUTE,
1779 GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT,
1780 size,
1781 (char *) &block,
1782 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: expiration time should be option */
1783 app_announce_time,
1784 NULL, NULL);
1785 }
1786 len = strlen(proof);
1787 size = sizeof (struct MeshRegexBlock) + len;
1788 block = GNUNET_malloc (size);
1789
1790 block->key = *key;
1791 block->n_proof = htonl (len);
1792 block->n_edges = htonl (num_edges);
1793 block->accepting = htonl (accepting);
1794
1795 /* Store the proof at the end of the block. */
1796 aux = (char *) &block[1];
1797 memcpy (aux, proof, len);
1798 aux = &aux[len];
1799
1800 /* Store each edge in a variable length MeshEdge struct at the
1801 * very end of the MeshRegexBlock structure.
1802 */
1803 for (i = 0; i < num_edges; i++)
1804 {
1805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1806 " edge %s towards %s\n",
1807 edges[i].label,
1808 GNUNET_h2s(&edges[i].destination));
1809
1810 /* aux points at the end of the last block */
1811 len = strlen (edges[i].label);
1812 size += sizeof (struct MeshRegexEdge) + len;
1813 // Calculate offset FIXME is this ok? use size instead?
1814 offset = aux - (char *) block;
1815 block = GNUNET_realloc (block, size);
1816 aux = &((char *) block)[offset];
1817 block_edge = (struct MeshRegexEdge *) aux;
1818 block_edge->key = edges[i].destination;
1819 block_edge->n_token = htonl (len);
1820 aux = (char *) &block_edge[1];
1821 memcpy (aux, edges[i].label, len);
1822 aux = &aux[len];
1823 }
1824 (void)
1825 GNUNET_DHT_put(dht_handle, key,
1826 dht_replication_level,
1827 opt,
1828 GNUNET_BLOCK_TYPE_MESH_REGEX, size,
1829 (char *) block,
1830 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: this should be an option */
1831 app_announce_time,
1832 NULL, NULL);
1833 GNUNET_free (block);
1834}
1835
1836
1837/**
1838 * Store the regular expression describing a local service into the DHT.
1839 *
1840 * @param regex The regular expresion.
1841 */
1842static void
1843regex_put (struct MeshRegexDescriptor *regex)
1844{
1845 if (NULL == regex->dfa)
1846 {
1847 regex->dfa = GNUNET_REGEX_construct_dfa (regex->regex,
1848 strlen (regex->regex),
1849 regex->compression);
1850 }
1851
1852 DEBUG_DHT (" regex_put (%s) start\n", regex->regex);
1853 GNUNET_REGEX_iterate_all_edges (regex->dfa, &regex_iterator, NULL);
1854 DEBUG_DHT (" regex_put (%s) end\n", regex);
1855}
1856
1857
1839/** 1858/**
1840 * Periodically announce what applications are provided by local clients 1859 * Periodically announce what applications are provided by local clients
1841 * (by regex) 1860 * (by regex)
@@ -1851,22 +1870,14 @@ announce_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1851 1870
1852 c->regex_announce_task = GNUNET_SCHEDULER_NO_TASK; 1871 c->regex_announce_task = GNUNET_SCHEDULER_NO_TASK;
1853 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1872 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1854 {
1855 return; 1873 return;
1856 }
1857
1858 DEBUG_DHT ("Starting PUT for regex\n"); 1874 DEBUG_DHT ("Starting PUT for regex\n");
1859
1860 for (i = 0; i < c->n_regex; i++) 1875 for (i = 0; i < c->n_regex; i++)
1861 {
1862 regex_put (&c->regexes[i]); 1876 regex_put (&c->regexes[i]);
1863 }
1864 c->regex_announce_task = GNUNET_SCHEDULER_add_delayed (app_announce_time, 1877 c->regex_announce_task = GNUNET_SCHEDULER_add_delayed (app_announce_time,
1865 &announce_regex, 1878 &announce_regex,
1866 cls); 1879 cls);
1867 DEBUG_DHT ("Finished PUT for regex\n"); 1880 DEBUG_DHT ("Finished PUT for regex\n");
1868
1869 return;
1870} 1881}
1871 1882
1872 1883
@@ -1894,8 +1905,6 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1894 GNUNET_SCHEDULER_add_delayed (app_announce_time, &announce_applications, 1905 GNUNET_SCHEDULER_add_delayed (app_announce_time, &announce_applications,
1895 cls); 1906 cls);
1896 DEBUG_DHT ("Finished PUT for apps\n"); 1907 DEBUG_DHT ("Finished PUT for apps\n");
1897
1898 return;
1899} 1908}
1900 1909
1901 1910
@@ -6796,7 +6805,7 @@ static void
6796handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client, 6805handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
6797 const struct GNUNET_MessageHeader *message) 6806 const struct GNUNET_MessageHeader *message)
6798{ 6807{
6799 struct GNUNET_MESH_RegexAnnounce *msg; 6808 const struct GNUNET_MESH_RegexAnnounce *msg;
6800 struct MeshRegexDescriptor rd; 6809 struct MeshRegexDescriptor rd;
6801 struct MeshClient *c; 6810 struct MeshClient *c;
6802 char *regex; 6811 char *regex;
@@ -6813,7 +6822,7 @@ handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
6813 } 6822 }
6814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); 6823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6815 6824
6816 msg = (struct GNUNET_MESH_RegexAnnounce *) message; 6825 msg = (const struct GNUNET_MESH_RegexAnnounce *) message;
6817 len = ntohs (message->size) - sizeof(struct GNUNET_MESH_RegexAnnounce); 6826 len = ntohs (message->size) - sizeof(struct GNUNET_MESH_RegexAnnounce);
6818 regex = GNUNET_malloc (len + 1); 6827 regex = GNUNET_malloc (len + 1);
6819 memcpy (regex, &msg[1], len); 6828 memcpy (regex, &msg[1], len);
@@ -8374,8 +8383,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
8374 GNUNET_SCHEDULER_shutdown (); 8383 GNUNET_SCHEDULER_shutdown ();
8375 return; 8384 return;
8376 } 8385 }
8377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "APP_ANNOUNCE_TIME %llu ms\n", app_announce_time.rel_value); 8386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8378 8387 "APP_ANNOUNCE_TIME %llu ms\n",
8388 app_announce_time.rel_value);
8379 if (GNUNET_OK != 8389 if (GNUNET_OK !=
8380 GNUNET_CONFIGURATION_get_value_time (c, "MESH", "ID_ANNOUNCE_TIME", 8390 GNUNET_CONFIGURATION_get_value_time (c, "MESH", "ID_ANNOUNCE_TIME",
8381 &id_announce_time)) 8391 &id_announce_time))
@@ -8387,9 +8397,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
8387 GNUNET_SCHEDULER_shutdown (); 8397 GNUNET_SCHEDULER_shutdown ();
8388 return; 8398 return;
8389 } 8399 }
8390 else
8391 {
8392 }
8393 8400
8394 if (GNUNET_OK != 8401 if (GNUNET_OK !=
8395 GNUNET_CONFIGURATION_get_value_time (c, "MESH", "CONNECT_TIMEOUT", 8402 GNUNET_CONFIGURATION_get_value_time (c, "MESH", "CONNECT_TIMEOUT",