diff options
Diffstat (limited to 'src/fs/fs_publish.c')
-rw-r--r-- | src/fs/fs_publish.c | 219 |
1 files changed, 0 insertions, 219 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 73fc710e1..2c9d41b05 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -1709,223 +1709,4 @@ GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, | |||
1709 | } | 1709 | } |
1710 | 1710 | ||
1711 | 1711 | ||
1712 | /** | ||
1713 | * Context for the SKS publication. | ||
1714 | */ | ||
1715 | struct PublishSksContext | ||
1716 | { | ||
1717 | |||
1718 | /** | ||
1719 | * Global FS context. | ||
1720 | */ | ||
1721 | struct GNUNET_FS_Uri *uri; | ||
1722 | |||
1723 | /** | ||
1724 | * Handle to the datastore. | ||
1725 | */ | ||
1726 | struct GNUNET_DATASTORE_Handle *dsh; | ||
1727 | |||
1728 | /** | ||
1729 | * Function to call once we're done. | ||
1730 | */ | ||
1731 | GNUNET_FS_PublishContinuation cont; | ||
1732 | |||
1733 | /** | ||
1734 | * Closure for cont. | ||
1735 | */ | ||
1736 | void *cont_cls; | ||
1737 | |||
1738 | }; | ||
1739 | |||
1740 | |||
1741 | /** | ||
1742 | * Function called by the datastore API with | ||
1743 | * the result from the PUT (SBlock) request. | ||
1744 | * | ||
1745 | * @param cls closure of type "struct PublishSksContext*" | ||
1746 | * @param success GNUNET_OK on success | ||
1747 | * @param msg error message (or NULL) | ||
1748 | */ | ||
1749 | static void | ||
1750 | sb_put_cont (void *cls, | ||
1751 | int success, | ||
1752 | const char *msg) | ||
1753 | { | ||
1754 | struct PublishSksContext *psc = cls; | ||
1755 | |||
1756 | if (NULL != psc->dsh) | ||
1757 | { | ||
1758 | GNUNET_DATASTORE_disconnect (psc->dsh, GNUNET_NO); | ||
1759 | psc->dsh = NULL; | ||
1760 | } | ||
1761 | if (GNUNET_OK != success) | ||
1762 | psc->cont (psc->cont_cls, | ||
1763 | NULL, | ||
1764 | msg); | ||
1765 | else | ||
1766 | psc->cont (psc->cont_cls, | ||
1767 | psc->uri, | ||
1768 | NULL); | ||
1769 | GNUNET_FS_uri_destroy (psc->uri); | ||
1770 | GNUNET_free (psc); | ||
1771 | } | ||
1772 | |||
1773 | |||
1774 | /** | ||
1775 | * Publish an SBlock on GNUnet. | ||
1776 | * | ||
1777 | * @param h handle to the file sharing subsystem | ||
1778 | * @param namespace namespace to publish in | ||
1779 | * @param identifier identifier to use | ||
1780 | * @param update update identifier to use | ||
1781 | * @param meta metadata to use | ||
1782 | * @param uri URI to refer to in the SBlock | ||
1783 | * @param expirationTime when the SBlock expires | ||
1784 | * @param anonymity anonymity level for the SBlock | ||
1785 | * @param priority priority for the SBlock | ||
1786 | * @param options publication options | ||
1787 | * @param cont continuation | ||
1788 | * @param cont_cls closure for cont | ||
1789 | */ | ||
1790 | void | ||
1791 | GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | ||
1792 | struct GNUNET_FS_Namespace *namespace, | ||
1793 | const char *identifier, | ||
1794 | const char *update, | ||
1795 | const struct GNUNET_CONTAINER_MetaData *meta, | ||
1796 | const struct GNUNET_FS_Uri *uri, | ||
1797 | struct GNUNET_TIME_Absolute expirationTime, | ||
1798 | uint32_t anonymity, | ||
1799 | uint32_t priority, | ||
1800 | enum GNUNET_FS_PublishOptions options, | ||
1801 | GNUNET_FS_PublishContinuation cont, | ||
1802 | void *cont_cls) | ||
1803 | { | ||
1804 | struct PublishSksContext *psc; | ||
1805 | struct GNUNET_CRYPTO_AesSessionKey sk; | ||
1806 | struct GNUNET_CRYPTO_AesInitializationVector iv; | ||
1807 | struct GNUNET_FS_Uri *sks_uri; | ||
1808 | char *uris; | ||
1809 | size_t size; | ||
1810 | size_t slen; | ||
1811 | size_t nidlen; | ||
1812 | size_t idlen; | ||
1813 | ssize_t mdsize; | ||
1814 | struct SBlock *sb; | ||
1815 | struct SBlock *sb_enc; | ||
1816 | char *dest; | ||
1817 | struct GNUNET_CONTAINER_MetaData *mmeta; | ||
1818 | GNUNET_HashCode key; /* hash of thisId = key */ | ||
1819 | GNUNET_HashCode id; /* hash of hc = identifier */ | ||
1820 | GNUNET_HashCode query; /* id ^ nsid = DB query */ | ||
1821 | |||
1822 | if (NULL == meta) | ||
1823 | mmeta = GNUNET_CONTAINER_meta_data_create (); | ||
1824 | else | ||
1825 | mmeta = GNUNET_CONTAINER_meta_data_duplicate (meta); | ||
1826 | uris = GNUNET_FS_uri_to_string (uri); | ||
1827 | slen = strlen (uris) + 1; | ||
1828 | idlen = strlen (identifier); | ||
1829 | if (update == NULL) | ||
1830 | update = ""; | ||
1831 | nidlen = strlen (update) + 1; | ||
1832 | mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (mmeta); | ||
1833 | size = sizeof (struct SBlock) + slen + nidlen + mdsize; | ||
1834 | if (size > MAX_SBLOCK_SIZE) | ||
1835 | { | ||
1836 | size = MAX_SBLOCK_SIZE; | ||
1837 | mdsize = size - (sizeof (struct SBlock) + slen + nidlen); | ||
1838 | } | ||
1839 | sb = GNUNET_malloc (sizeof (struct SBlock) + size); | ||
1840 | dest = (char *) &sb[1]; | ||
1841 | memcpy (dest, update, nidlen); | ||
1842 | dest += nidlen; | ||
1843 | memcpy (dest, uris, slen); | ||
1844 | GNUNET_free (uris); | ||
1845 | dest += slen; | ||
1846 | mdsize = GNUNET_CONTAINER_meta_data_serialize (mmeta, | ||
1847 | &dest, | ||
1848 | mdsize, | ||
1849 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | ||
1850 | GNUNET_CONTAINER_meta_data_destroy (mmeta); | ||
1851 | if (mdsize == -1) | ||
1852 | { | ||
1853 | GNUNET_break (0); | ||
1854 | GNUNET_free (sb); | ||
1855 | cont (cont_cls, | ||
1856 | NULL, | ||
1857 | _("Internal error.")); | ||
1858 | return; | ||
1859 | } | ||
1860 | size = sizeof (struct SBlock) + mdsize + slen + nidlen; | ||
1861 | sb_enc = GNUNET_malloc (size); | ||
1862 | GNUNET_CRYPTO_hash (identifier, idlen, &key); | ||
1863 | GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &id); | ||
1864 | sks_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | ||
1865 | sks_uri->type = sks; | ||
1866 | GNUNET_CRYPTO_rsa_key_get_public (namespace->key, &sb_enc->subspace); | ||
1867 | GNUNET_CRYPTO_hash (&sb_enc->subspace, | ||
1868 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
1869 | &sks_uri->data.sks.namespace); | ||
1870 | sks_uri->data.sks.identifier = GNUNET_strdup (identifier); | ||
1871 | GNUNET_CRYPTO_hash_xor (&id, | ||
1872 | &sks_uri->data.sks.namespace, | ||
1873 | &sb_enc->identifier); | ||
1874 | GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv); | ||
1875 | GNUNET_CRYPTO_aes_encrypt (&sb[1], | ||
1876 | size - sizeof (struct SBlock), | ||
1877 | &sk, | ||
1878 | &iv, | ||
1879 | &sb_enc[1]); | ||
1880 | sb_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK); | ||
1881 | sb_enc->purpose.size = htonl(slen + mdsize + nidlen | ||
1882 | + sizeof(struct SBlock) | ||
1883 | - sizeof(struct GNUNET_CRYPTO_RsaSignature)); | ||
1884 | GNUNET_assert (GNUNET_OK == | ||
1885 | GNUNET_CRYPTO_rsa_sign (namespace->key, | ||
1886 | &sb_enc->purpose, | ||
1887 | &sb_enc->signature)); | ||
1888 | psc = GNUNET_malloc (sizeof(struct PublishSksContext)); | ||
1889 | psc->uri = sks_uri; | ||
1890 | psc->cont = cont; | ||
1891 | psc->cont_cls = cont_cls; | ||
1892 | if (0 != (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | ||
1893 | { | ||
1894 | GNUNET_free (sb_enc); | ||
1895 | GNUNET_free (sb); | ||
1896 | sb_put_cont (psc, | ||
1897 | GNUNET_OK, | ||
1898 | NULL); | ||
1899 | return; | ||
1900 | } | ||
1901 | psc->dsh = GNUNET_DATASTORE_connect (h->cfg, h->sched); | ||
1902 | if (NULL == psc->dsh) | ||
1903 | { | ||
1904 | GNUNET_free (sb_enc); | ||
1905 | GNUNET_free (sb); | ||
1906 | sb_put_cont (psc, | ||
1907 | GNUNET_NO, | ||
1908 | _("Failed to connect to datastore.")); | ||
1909 | return; | ||
1910 | } | ||
1911 | GNUNET_CRYPTO_hash_xor (&sks_uri->data.sks.namespace, | ||
1912 | &id, | ||
1913 | &query); | ||
1914 | GNUNET_DATASTORE_put (psc->dsh, | ||
1915 | 0, | ||
1916 | &sb_enc->identifier, | ||
1917 | size, | ||
1918 | sb_enc, | ||
1919 | GNUNET_BLOCK_TYPE_SBLOCK, | ||
1920 | priority, | ||
1921 | anonymity, | ||
1922 | expirationTime, | ||
1923 | -2, 1, | ||
1924 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | ||
1925 | &sb_put_cont, | ||
1926 | psc); | ||
1927 | GNUNET_free (sb); | ||
1928 | GNUNET_free (sb_enc); | ||
1929 | } | ||
1930 | |||
1931 | /* end of fs_publish.c */ | 1712 | /* end of fs_publish.c */ |