From dc29338042877158bba42fed72b2d722c270b49d Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Sun, 4 Feb 2018 17:44:34 -0600 Subject: Update gnunet to commit 3f9b17 --- gnunet-build/packages/gnunet/gnunet/Buildrules | 6 +- .../packages/gnunet/gnunet/files/configuration.js | 12 + .../packages/gnunet/gnunet/files/datastore-pre.js | 22 +- .../gnunet/files/gnunet-git-3f9b17-all.patch | 990 +++++++++++++++++++++ .../gnunet/files/gnunet-git-a03d29-all.patch | 990 --------------------- .../packages/gnunet/gnunet/files/network.js | 21 + .../gnunet/files/plugin_datastore_emscripten.c | 165 ++-- .../files/plugin_datastore_emscripten_int.js | 322 +++---- .../gnunet/files/plugin_peerstore_emscripten.c | 8 +- .../plugin_transport_http_client_emscripten.c | 21 +- .../packages/gnunet/gnunet/files/scheduler.c | 13 + src/cljs/gnunet_web/transport.cljs | 10 +- 12 files changed, 1330 insertions(+), 1250 deletions(-) create mode 100644 gnunet-build/packages/gnunet/gnunet/files/gnunet-git-3f9b17-all.patch delete mode 100644 gnunet-build/packages/gnunet/gnunet/files/gnunet-git-a03d29-all.patch diff --git a/gnunet-build/packages/gnunet/gnunet/Buildrules b/gnunet-build/packages/gnunet/gnunet/Buildrules index 8e84763..5300307 100644 --- a/gnunet-build/packages/gnunet/gnunet/Buildrules +++ b/gnunet-build/packages/gnunet/gnunet/Buildrules @@ -1,4 +1,4 @@ -COMMIT="a03d29" +COMMIT="3f9b17" VERSION="git-${COMMIT}" RELEASE="0" DESCRIPTION="GNUnet is a framework for secure peer-to-peer networking that does not use any centralized or otherwise trusted services." @@ -288,6 +288,7 @@ pkg_compile() { "${S}/src/dht/gnunet-service-dht"*.o \ "${S}/src/ats/libgnunetats.la" \ "${S}/src/block/libgnunetblock.la" \ + "${S}/src/block/libgnunetblockgroup.la" \ "${S}/src/core/libgnunetcore.la" \ "${S}/src/datacache/libgnunetdatacache.la" \ "${S}/src/hello/libgnunethello.la" \ @@ -348,7 +349,7 @@ pkg_compile() { --use-preload-plugins \ "-I${SYSROOT}/usr/include" "-L${SYSROOT}/usr/lib" \ -o "${S}/src/cadet/gnunet-service-cadet.js" \ - "${S}/src/cadet/gnunet_service_cadet"*.o \ + "${S}/src/cadet/gnunet-service-cadet"*.o \ "${S}/src/ats/libgnunetats.la" \ "${S}/src/block/libgnunetblock.la" \ "${S}/src/core/libgnunetcore.la" \ @@ -422,6 +423,7 @@ pkg_compile() { "${S}/src/fs/gnunet-service-fs"*.o \ "${S}/src/ats/libgnunetats.la" \ "${S}/src/block/libgnunetblock.la" \ + "${S}/src/block/libgnunetblockgroup.la" \ "${S}/src/cadet/libgnunetcadet.la" \ "${S}/src/core/libgnunetcore.la" \ "${S}/src/datastore/libgnunetdatastore.la" \ diff --git a/gnunet-build/packages/gnunet/gnunet/files/configuration.js b/gnunet-build/packages/gnunet/gnunet/files/configuration.js index dcf17d7..d67d53f 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/configuration.js +++ b/gnunet-build/packages/gnunet/gnunet/files/configuration.js @@ -201,11 +201,23 @@ mergeInto(LibraryManager.library, { [iter_cls, section_name, option, value]); } }, + GNUNET_CONFIGURATION_set_value_string: function(cfg, section, option, value) { + var section_name = Pointer_stringify(section); + var option_str = Pointer_stringify(option); + var value_str = Pointer_stringify(value); + if(!(section_name in CONFIG)) { + CONFIG[section_name] = {} + } + var sec = CONFIG[section_name] + sec[option] = value + }, GNUNET_CONFIGURATION_create: function() { return 1; // opaque non-null pointer }, GNUNET_CONFIGURATION_load: function(cfg, filename) { return 1; + }, + GNUNET_CONFIGURATION_destroy: function(cfg) { } }); diff --git a/gnunet-build/packages/gnunet/gnunet/files/datastore-pre.js b/gnunet-build/packages/gnunet/gnunet/files/datastore-pre.js index d4a584b..6183bf0 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/datastore-pre.js +++ b/gnunet-build/packages/gnunet/gnunet/files/datastore-pre.js @@ -1,6 +1,6 @@ datastore_prerun = function() { addRunDependency('datastore-indexedDB'); - var request = indexedDB.open('datastore', 1); + var request = indexedDB.open('datastore', 2); request.onsuccess = function(e) { self.dsdb = e.target.result; removeRunDependency('datastore-indexedDB'); @@ -10,12 +10,20 @@ datastore_prerun = function() { }; request.onupgradeneeded = function(e) { var db = e.target.result; - var store = db.createObjectStore('datastore', {keyPath: 'uid', - autoIncrement: true}); - store.createIndex('by_key', 'key'); - store.createIndex('by_anon_type', ['anonymity', 'type']); - store.createIndex('by_replication', 'replication'); - store.createIndex('by_expiry', 'expiry'); + if (0 == e.oldVersion) { + var store = db.createObjectStore('datastore', {keyPath: 'uid', + autoIncrement: true}); + store.createIndex('by_key', ['key', 'uid']); + store.createIndex('by_anon_type', ['anonymity', 'type', 'uid']); + store.createIndex('by_replication', 'replication'); + store.createIndex('by_expiry', 'expiry'); + } else if (1 == e.oldVersion) { + var store = request.transaction.objectStore('datastore'); + store.deleteIndex('by_key'); + store.createIndex('by_key', ['key', 'uid']); + store.deleteIndex('by_anon_type'); + store.createIndex('by_anon_type', ['anonymity', 'type', 'uid']); + } }; }; Module['preInit'].push(datastore_prerun); diff --git a/gnunet-build/packages/gnunet/gnunet/files/gnunet-git-3f9b17-all.patch b/gnunet-build/packages/gnunet/gnunet/files/gnunet-git-3f9b17-all.patch new file mode 100644 index 0000000..69721e1 --- /dev/null +++ b/gnunet-build/packages/gnunet/gnunet/files/gnunet-git-3f9b17-all.patch @@ -0,0 +1,990 @@ +diff --git a/configure.ac b/configure.ac +index 145a6aaff..93b13d636 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -701,7 +701,7 @@ AC_ARG_WITH(ltdl, + AC_CHECK_HEADERS(ltdl.h, + AC_CHECK_LIB([ltdl], [lt_dlopenext], + ltdl=1))]) +-if test x$ltdl = x1 ++if true + then + AC_MSG_RESULT([libltdl found]) + else +diff --git a/src/Makefile.am b/src/Makefile.am +index 6d0284157..58a954b53 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -100,7 +100,6 @@ SUBDIRS = \ + $(ATS_TESTS) \ + nse \ + dht \ +- hostlist \ + topology \ + regex \ + dns \ +@@ -114,20 +113,8 @@ SUBDIRS = \ + consensus \ + scalarproduct \ + revocation \ +- vpn \ +- gns \ +- zonemaster \ + $(CONVERSATION_DIR) \ + fs \ +- exit \ +- pt \ +- secretsharing \ +- integration-tests \ +- multicast \ +- psycutil \ +- psycstore \ +- psyc \ +- social \ + $(AUCTION_DIR) \ + $(EXP_DIR) + +diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am +index 240abbc67..db784cc44 100644 +--- a/src/datastore/Makefile.am ++++ b/src/datastore/Makefile.am +@@ -104,7 +104,8 @@ plugin_LTLIBRARIES = \ + $(SQLITE_PLUGIN) \ + $(MYSQL_PLUGIN) \ + $(POSTGRES_PLUGIN) \ +- libgnunet_plugin_datastore_heap.la ++ libgnunet_plugin_datastore_heap.la \ ++ libgnunet_plugin_datastore_emscripten.la + + # Real plugins should of course go into + # plugin_LTLIBRARIES +@@ -131,6 +132,13 @@ libgnunet_plugin_datastore_heap_la_LIBADD = \ + libgnunet_plugin_datastore_heap_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) + ++libgnunet_plugin_datastore_emscripten_la_SOURCES = \ ++ plugin_datastore_emscripten.c ++libgnunet_plugin_datastore_emscripten_la_LIBADD = \ ++ $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ ++ $(LTLIBINTL) ++libgnunet_plugin_datastore_emscripten_la_LDFLAGS = \ ++ $(GN_PLUGIN_LDFLAGS) + + libgnunet_plugin_datastore_mysql_la_SOURCES = \ + plugin_datastore_mysql.c +diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am +index c52ac93c7..d3983ef9e 100644 +--- a/src/dht/Makefile.am ++++ b/src/dht/Makefile.am +@@ -50,15 +50,6 @@ libgnunet_plugin_block_dht_la_LDFLAGS = \ + libexec_PROGRAMS = \ + gnunet-service-dht + +-bin_PROGRAMS = \ +- gnunet-dht-monitor \ +- gnunet-dht-get \ +- gnunet-dht-put +- +-if HAVE_TESTING +-noinst_PROGRAMS = \ +- gnunet-dht-profiler +-endif + + gnunet_service_dht_SOURCES = \ + gnunet-service-dht.c gnunet-service-dht.h \ +diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am +index 5af228121..523c760a8 100644 +--- a/src/dns/Makefile.am ++++ b/src/dns/Makefile.am +@@ -18,14 +18,6 @@ plugindir = $(libdir)/gnunet + pkgcfg_DATA = \ + dns.conf + +-if LINUX +-HIJACKBIN = gnunet-helper-dns +-install-exec-hook: +- $(top_srcdir)/src/dns/install-dns-helper.sh $(DESTDIR)$(libexecdir) $(GNUNETDNS_GROUP) $(SUDO_BINARY) || true +-else +-install-exec-hook: +-endif +- + lib_LTLIBRARIES = \ + libgnunetdnsparser.la \ + libgnunetdnsstub.la \ +diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c +index a5b82ec27..5801aa87b 100644 +--- a/src/fs/fs_api.c ++++ b/src/fs/fs_api.c +@@ -456,19 +456,22 @@ struct FileInfo + * to provide less data unless there is an error; + * a value of "0" will be used at the end to allow + * the reader to clean up its internal state +- * @param buf where the reader should write the data +- * @param emsg location for the reader to store an error message +- * @return number of bytes written, usually @a max, 0 on error ++ * @param cont continuation to call with a pointer to the read bytes or an ++ * error message ++ * @param cont_cls closure to pass to the continuation ++ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise + */ +-size_t ++int + GNUNET_FS_data_reader_file_ (void *cls, + uint64_t offset, + size_t max, +- void *buf, +- char **emsg) ++ GNUNET_FS_ReaderContinuation cont, ++ void *cont_cls) + { + struct FileInfo *fi = cls; + ssize_t ret; ++ char **emsg = NULL; ++ char buf[max]; + + if (UINT64_MAX == offset) + { +@@ -477,7 +480,7 @@ GNUNET_FS_data_reader_file_ (void *cls, + GNUNET_DISK_file_close (fi->fd); + fi->fd = NULL; + } +- return 0; ++ return GNUNET_SYSERR; + } + if (0 == max) + { +@@ -485,7 +488,7 @@ GNUNET_FS_data_reader_file_ (void *cls, + GNUNET_DISK_file_close (fi->fd); + GNUNET_free (fi->filename); + GNUNET_free (fi); +- return 0; ++ return GNUNET_SYSERR; + } + if (NULL == fi->fd) + { +@@ -499,7 +502,9 @@ GNUNET_FS_data_reader_file_ (void *cls, + _("Could not open file `%s': %s"), + fi->filename, + STRERROR (errno)); +- return 0; ++ if (cont) ++ cont (cont_cls, NULL, max, *emsg); ++ return GNUNET_OK; + } + } + if ( (GNUNET_SYSERR == +@@ -510,16 +515,22 @@ GNUNET_FS_data_reader_file_ (void *cls, + _("Could not read file `%s': %s"), + fi->filename, + STRERROR (errno)); +- return 0; ++ if (cont) ++ cont (cont_cls, NULL, max, *emsg); ++ return GNUNET_OK; + } + if (ret != max) + { + GNUNET_asprintf (emsg, + _("Short read reading from file `%s'!"), + fi->filename); +- return 0; ++ if (cont) ++ cont (cont_cls, NULL, max, *emsg); ++ return GNUNET_OK; + } +- return max; ++ if (cont) ++ cont (cont_cls, buf, max, NULL); ++ return GNUNET_OK; + } + + +@@ -561,28 +572,30 @@ GNUNET_FS_make_file_reader_context_ (const char *filename) + * to provide less data unless there is an error; + * a value of "0" will be used at the end to allow + * the reader to clean up its internal state +- * @param buf where the reader should write the data +- * @param emsg location for the reader to store an error message +- * @return number of bytes written, usually @a max, 0 on error ++ * @param cont continuation to call with a pointer to the read bytes or an ++ * error message ++ * @param cont_cls closure to pass to the continuation ++ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise + */ +-size_t ++int + GNUNET_FS_data_reader_copy_ (void *cls, + uint64_t offset, + size_t max, +- void *buf, +- char **emsg) ++ GNUNET_FS_ReaderContinuation cont, ++ void *cont_cls) + { + char *data = cls; + + if (UINT64_MAX == offset) +- return 0; ++ return GNUNET_SYSERR; + if (0 == max) + { + GNUNET_free_non_null (data); +- return 0; ++ return GNUNET_SYSERR; + } +- GNUNET_memcpy (buf, &data[offset], max); +- return max; ++ if (cont) ++ cont (cont_cls, &data[offset], max, NULL); ++ return GNUNET_OK; + } + + +@@ -1250,43 +1263,6 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, + + + /** +- * Copy all of the data from the reader to the write handle. +- * +- * @param wh write handle +- * @param fi file with reader +- * @return #GNUNET_OK on success +- */ +-static int +-copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, +- struct GNUNET_FS_FileInformation *fi) +-{ +- char buf[32 * 1024]; +- uint64_t off; +- size_t ret; +- size_t left; +- char *emsg; +- +- emsg = NULL; +- off = 0; +- while (off < fi->data.file.file_size) +- { +- left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); +- ret = +- fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); +- if (0 == ret) +- { +- GNUNET_free (emsg); +- return GNUNET_SYSERR; +- } +- if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret)) +- return GNUNET_SYSERR; +- off += ret; +- } +- return GNUNET_OK; +-} +- +- +-/** + * Create a temporary file on disk to store the current + * state of @a fi in. + * +@@ -1370,7 +1346,6 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) + goto cleanup; + } + if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename)) +- if (GNUNET_OK != copy_from_reader (wh, fi)) + { + GNUNET_break (0); + goto cleanup; +diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h +index be22ea73e..2ae9f71f5 100644 +--- a/src/fs/fs_api.h ++++ b/src/fs/fs_api.h +@@ -670,16 +670,17 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe); + * to provide less data unless there is an error; + * a value of "0" will be used at the end to allow + * the reader to clean up its internal state +- * @param buf where the reader should write the data +- * @param emsg location for the reader to store an error message +- * @return number of bytes written, usually "max", 0 on error ++ * @param cont continuation to call with a pointer to the read bytes or an ++ * error message ++ * @param cont_cls closure to pass to the continuation ++ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise + */ +-size_t ++int + GNUNET_FS_data_reader_file_ (void *cls, + uint64_t offset, + size_t max, +- void *buf, +- char **emsg); ++ GNUNET_FS_ReaderContinuation cont, ++ void *cont_cls); + + + /** +@@ -705,16 +706,17 @@ GNUNET_FS_make_file_reader_context_ (const char *filename); + * to provide less data unless there is an error; + * a value of "0" will be used at the end to allow + * the reader to clean up its internal state +- * @param buf where the reader should write the data +- * @param emsg location for the reader to store an error message +- * @return number of bytes written, usually @a max, 0 on error ++ * @param cont continuation to call with a pointer to the read bytes or an ++ * error message ++ * @param cont_cls closure to pass to the continuation ++ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise + */ +-size_t ++int + GNUNET_FS_data_reader_copy_ (void *cls, + uint64_t offset, + size_t max, +- void *buf, +- char **emsg); ++ GNUNET_FS_ReaderContinuation cont, ++ void *cont_cls); + + + /** +diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c +index c2a3d4c5d..f386ce1f3 100644 +--- a/src/fs/fs_download.c ++++ b/src/fs/fs_download.c +@@ -1762,33 +1762,36 @@ reconstruct_cb (void *cls, + * @param offset identifies which block to get + * @param max (maximum) number of bytes to get; returning + * fewer will also cause errors +- * @param buf where to copy the plaintext buffer +- * @param emsg location to store an error message (on error) +- * @return number of bytes copied to buf, 0 on error ++ * @param cont continuation to call with a pointer to the read bytes or an ++ * error message ++ * @param cont_cls closure to pass to the continuation ++ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise + */ +-static size_t +-fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) ++static int ++fh_reader (void *cls, uint64_t offset, size_t max, ++ GNUNET_FS_ReaderContinuation cont, void *cont_cls) + { + struct GNUNET_FS_DownloadContext *dc = cls; + struct GNUNET_DISK_FileHandle *fh = dc->rfh; + ssize_t ret; ++ char buf[max]; + +- if (NULL != emsg) +- *emsg = NULL; + if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET)) + { +- if (NULL != emsg) +- *emsg = GNUNET_strdup (strerror (errno)); +- return 0; ++ if (cont) ++ cont (cont_cls, NULL, max, GNUNET_strdup (strerror (errno))); ++ return GNUNET_OK; + } + ret = GNUNET_DISK_file_read (fh, buf, max); + if (ret < 0) + { +- if (NULL != emsg) +- *emsg = GNUNET_strdup (strerror (errno)); +- return 0; ++ if (cont) ++ cont (cont_cls, NULL, max, GNUNET_strdup (strerror (errno))); ++ return GNUNET_OK; + } +- return ret; ++ if (cont) ++ cont (cont_cls, buf, max, NULL); ++ return GNUNET_OK; + } + + +diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c +index 759467ba4..bd7bc606e 100644 +--- a/src/fs/fs_publish.c ++++ b/src/fs/fs_publish.c +@@ -363,24 +363,24 @@ publish_kblocks_cont (void *cls, + * @param emsg location to store an error message (on error) + * @return number of bytes copied to buf, 0 on error + */ +-static size_t ++static int + block_reader (void *cls, + uint64_t offset, + size_t max, +- void *buf, +- char **emsg) ++ GNUNET_FS_ReaderContinuation cont, ++ void *cont_cls) + { + struct GNUNET_FS_PublishContext *pc = cls; + struct GNUNET_FS_FileInformation *p; + const char *dd; +- size_t pt_size; + + p = pc->fi_pos; + if (GNUNET_YES == p->is_directory) + { +- pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset); + dd = p->data.dir.dir_data; +- GNUNET_memcpy (buf, &dd[offset], pt_size); ++ if (cont) ++ cont (cont_cls, &dd[offset], max, NULL); ++ return GNUNET_OK; + } + else + { +@@ -391,18 +391,11 @@ block_reader (void *cls, + /* force closing the file to avoid keeping too many files open */ + p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL); + } +- return 0; ++ return GNUNET_SYSERR; /* return value ignored in this case */ + } +- pt_size = GNUNET_MIN (max, p->data.file.file_size - offset); +- if (0 == pt_size) +- return 0; /* calling reader with pt_size==0 +- * might free buf, so don't! */ +- if (pt_size != +- p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf, +- emsg)) +- return 0; +- } +- return pt_size; ++ return p->data.file.reader (p->data.file.reader_cls, offset, max, ++ cont, cont_cls); ++ } + } + + +@@ -610,7 +603,6 @@ static void + publish_content (struct GNUNET_FS_PublishContext *pc) + { + struct GNUNET_FS_FileInformation *p; +- char *emsg; + struct GNUNET_FS_DirectoryBuilder *db; + struct GNUNET_FS_FileInformation *dirpos; + void *raw_data; +@@ -635,22 +627,6 @@ publish_content (struct GNUNET_FS_PublishContext *pc) + else + { + raw_data = NULL; +- if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) && +- (dirpos->data.file.file_size > 0)) +- { +- raw_data = GNUNET_malloc (dirpos->data.file.file_size); +- emsg = NULL; +- if (dirpos->data.file.file_size != +- dirpos->data.file.reader (dirpos->data.file.reader_cls, 0, +- dirpos->data.file.file_size, raw_data, +- &emsg)) +- { +- GNUNET_free_non_null (emsg); +- GNUNET_free (raw_data); +- raw_data = NULL; +- } +- dirpos->data.file.reader (dirpos->data.file.reader_cls, UINT64_MAX, 0, 0, NULL); +- } + } + GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta, + raw_data); +diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c +index d03888021..7c05639ac 100644 +--- a/src/fs/fs_test_lib.c ++++ b/src/fs/fs_test_lib.c +@@ -273,26 +273,23 @@ publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) + * @param cls pointer to uint32_t with publishing seed + * @param offset offset to generate data for + * @param max maximum number of bytes to generate +- * @param buf where to write generated data +- * @param emsg where to store error message (unused) +- * @return number of bytes written to buf ++ * @param cont continuation to call with a pointer to the read bytes or an ++ * error message ++ * @param cont_cls closure to pass to the continuation ++ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise + */ +-static size_t ++static int + file_generator (void *cls, + uint64_t offset, + size_t max, +- void *buf, +- char **emsg) ++ GNUNET_FS_ReaderContinuation cont, ++ void *cont_cls) + { + uint32_t *publish_seed = cls; + uint64_t pos; +- uint8_t *cbuf = buf; ++ uint8_t cbuf[max]; + int mod; + +- if (emsg != NULL) +- *emsg = NULL; +- if (buf == NULL) +- return 0; + for (pos = 0; pos < 8; pos++) + cbuf[pos] = (uint8_t) (offset >> pos * 8); + for (pos = 8; pos < max; pos++) +@@ -302,7 +299,9 @@ file_generator (void *cls, + mod = 1; + cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod); + } +- return max; ++ if (cont) ++ cont (cont_cls, cbuf, max, NULL); ++ return GNUNET_OK; + } + + +@@ -346,6 +345,24 @@ fs_disconnect_adapter (void *cls, + + + /** ++ * Continuation for GNUNET_FS_DataReader ++ */ ++static void ++disk_write_cont (void *cls, ++ const void *pt_block, ++ uint16_t pt_size, ++ char *emsg) ++{ ++ struct GNUNET_DISK_FileHandle *fh = cls; ++ ++ GNUNET_assert (NULL != fh); ++ GNUNET_assert (NULL != pt_block); ++ GNUNET_assert (NULL == emsg); ++ GNUNET_assert (pt_size == GNUNET_DISK_file_write (fh, pt_block, pt_size)); ++} ++ ++ ++/** + * Callback to be called when testbed has connected to the fs service + * + * @param cls the 'struct TestPublishOperation' +@@ -363,9 +380,7 @@ publish_fs_connect_complete_cb (void *cls, + struct TestPublishOperation *po = cls; + struct GNUNET_FS_FileInformation *fi; + struct GNUNET_DISK_FileHandle *fh; +- char *em; + uint64_t off; +- char buf[DBLOCK_SIZE]; + size_t bsize; + struct GNUNET_FS_BlockOptions bo; + +@@ -397,11 +412,8 @@ publish_fs_connect_complete_cb (void *cls, + off = 0; + while (off < po->size) + { +- bsize = GNUNET_MIN (sizeof (buf), po->size - off); +- emsg = NULL; +- GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize, buf, &em)); +- GNUNET_assert (em == NULL); +- GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize)); ++ bsize = GNUNET_MIN (DBLOCK_SIZE, po->size - off); ++ GNUNET_assert (GNUNET_OK == file_generator (&po->publish_seed, off, bsize, disk_write_cont, fh)); + off += bsize; + } + GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); +diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c +index e57e4e494..c5b7dbdd2 100644 +--- a/src/fs/fs_tree.c ++++ b/src/fs/fs_tree.c +@@ -322,59 +322,27 @@ compute_chk_offset (unsigned int depth, uint64_t end_offset) + + + /** +- * Encrypt the next block of the file (and call proc and progress +- * accordingly; or of course "cont" if we have already completed +- * encoding of the entire file). +- * +- * @param te tree encoder to use ++ * Continuation for te->reader + */ +-void +-GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) ++static void ++encrypt_block(void *cls, ++ const void *pt_block, ++ uint16_t pt_size, ++ char *emsg) + { ++ struct GNUNET_FS_TreeEncoder *te = cls; + struct ContentHashKey *mychk; +- const void *pt_block; +- uint16_t pt_size; +- char iob[DBLOCK_SIZE]; + char enc[DBLOCK_SIZE]; + struct GNUNET_CRYPTO_SymmetricSessionKey sk; + struct GNUNET_CRYPTO_SymmetricInitializationVector iv; + unsigned int off; + +- GNUNET_assert (GNUNET_NO == te->in_next); +- te->in_next = GNUNET_YES; +- if (te->chk_tree_depth == te->current_depth) +- { +- off = CHK_PER_INODE * (te->chk_tree_depth - 1); +- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", +- GNUNET_h2s (&te->chk_tree[off].query), off); +- te->uri = GNUNET_new (struct GNUNET_FS_Uri); +- te->uri->type = GNUNET_FS_URI_CHK; +- te->uri->data.chk.chk = te->chk_tree[off]; +- te->uri->data.chk.file_length = GNUNET_htonll (te->size); ++ if (NULL != emsg || NULL == pt_block) { ++ te->emsg = emsg; + te->in_next = GNUNET_NO; + te->cont (te->cls); + return; + } +- if (0 == te->current_depth) +- { +- /* read DBLOCK */ +- pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset); +- if (pt_size != +- te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg)) +- { +- te->in_next = GNUNET_NO; +- te->cont (te->cls); +- return; +- } +- pt_block = iob; +- } +- else +- { +- pt_size = +- GNUNET_FS_tree_compute_iblock_size (te->current_depth, +- te->publish_offset); +- pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; +- } + off = compute_chk_offset (te->current_depth, te->publish_offset); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", +@@ -416,6 +384,58 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) + + + /** ++ * Encrypt the next block of the file (and call proc and progress ++ * accordingly; or of course "cont" if we have already completed ++ * encoding of the entire file). ++ * ++ * @param te tree encoder to use ++ */ ++void ++GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) ++{ ++ const void *pt_block; ++ uint16_t pt_size; ++ unsigned int off; ++ ++ GNUNET_assert (GNUNET_NO == te->in_next); ++ te->in_next = GNUNET_YES; ++ if (te->chk_tree_depth == te->current_depth) ++ { ++ off = CHK_PER_INODE * (te->chk_tree_depth - 1); ++ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", ++ GNUNET_h2s (&te->chk_tree[off].query), off); ++ te->uri = GNUNET_new (struct GNUNET_FS_Uri); ++ te->uri->type = GNUNET_FS_URI_CHK; ++ te->uri->data.chk.chk = te->chk_tree[off]; ++ te->uri->data.chk.file_length = GNUNET_htonll (te->size); ++ te->in_next = GNUNET_NO; ++ te->cont (te->cls); ++ return; ++ } ++ if (0 == te->current_depth) ++ { ++ /* read DBLOCK */ ++ pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset); ++ if (GNUNET_OK != ++ te->reader (te->cls, te->publish_offset, pt_size, &encrypt_block, te)) ++ { ++ te->in_next = GNUNET_NO; ++ te->cont (te->cls); ++ return; ++ } ++ } ++ else ++ { ++ pt_size = ++ GNUNET_FS_tree_compute_iblock_size (te->current_depth, ++ te->publish_offset); ++ pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; ++ encrypt_block(te, pt_block, pt_size, NULL); ++ } ++} ++ ++ ++/** + * Get the resulting URI from the encoding. + * + * @param te the tree encoder to clean up +@@ -446,7 +466,7 @@ GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, + { + if (NULL != te->reader) + { +- (void) te->reader (te->cls, UINT64_MAX, 0, 0, NULL); ++ (void) te->reader (te->cls, UINT64_MAX, 0, NULL, NULL); + te->reader = NULL; + } + GNUNET_assert (GNUNET_NO == te->in_next); +diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c +index 95a48f8cc..7e55936cf 100644 +--- a/src/fs/fs_unindex.c ++++ b/src/fs/fs_unindex.c +@@ -43,32 +43,37 @@ + * @param offset identifies which block to get + * @param max (maximum) number of bytes to get; returning + * fewer will also cause errors +- * @param buf where to copy the plaintext buffer +- * @param emsg location to store an error message (on error) +- * @return number of bytes copied to buf, 0 on error ++ * @param cont continuation to call with a pointer to the read bytes or an ++ * error message ++ * @param cont_cls closure to pass to the continuation ++ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise + */ +-static size_t ++static int + unindex_reader (void *cls, + uint64_t offset, + size_t max, +- void *buf, +- char **emsg) ++ GNUNET_FS_ReaderContinuation cont, ++ void *cont_cls) + { + struct GNUNET_FS_UnindexContext *uc = cls; +- size_t pt_size; ++ char buf[max]; + +- pt_size = GNUNET_MIN (max, uc->file_size - offset); + if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET)) + { +- *emsg = GNUNET_strdup (_("Failed to find given position in file")); +- return 0; ++ if (cont) ++ cont (cont_cls, NULL, max, ++ GNUNET_strdup (_("Failed to find given position in file"))); ++ return GNUNET_OK; + } +- if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size)) ++ if (max != GNUNET_DISK_file_read (uc->fh, buf, max)) + { +- *emsg = GNUNET_strdup (_("Failed to read file")); +- return 0; ++ if (cont) ++ cont (cont_cls, NULL, max, GNUNET_strdup (_("Failed to read file"))); ++ return GNUNET_OK; + } +- return pt_size; ++ if (cont) ++ cont (cont_cls, buf, max, NULL); ++ return GNUNET_OK; + } + + +diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h +index cbad374b5..9cbc66c2e 100644 +--- a/src/include/gnunet_fs_service.h ++++ b/src/include/gnunet_fs_service.h +@@ -1860,6 +1860,20 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, + + + /** ++ * Continuation for GNUNET_FS_DataReader ++ * ++ * @param cls closure ++ * @param pt_block pointer to bytes read by the reader ++ * @param pt_size the number of bytes read, must be equal to max ++ * @param emsg error message, NULL is there is no error ++ */ ++typedef void (*GNUNET_FS_ReaderContinuation) (void *cls, ++ const void *pt_block, ++ uint16_t pt_size, ++ char *emsg); ++ ++ ++/** + * Function that provides data. + * + * @param cls closure +@@ -1871,20 +1885,21 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, + * clean up the reader's state); in this case, + * a value of '0' for max should be ignored + * @param max maximum number of bytes that should be +- * copied to buf; readers are not allowed ++ * passed to cont; readers are not allowed + * to provide less data unless there is an error; + * a value of "0" will be used at the end to allow + * the reader to clean up its internal state +- * @param buf where the reader should write the data +- * @param emsg location for the reader to store an error message +- * @return number of bytes written, usually @a max, 0 on error ++ * @param cont continuation to call with a pointer to the read bytes or an ++ * error message ++ * @param cont_cls closure to pass to the continuation ++ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise + */ + typedef size_t + (*GNUNET_FS_DataReader) (void *cls, + uint64_t offset, + size_t max, +- void *buf, +- char **emsg); ++ GNUNET_FS_ReaderContinuation cont, ++ void *cont_cls); + + + /** +diff --git a/src/nat/Makefile.am b/src/nat/Makefile.am +index f0d5639a1..f1fbd0ef2 100644 +--- a/src/nat/Makefile.am ++++ b/src/nat/Makefile.am +@@ -15,24 +15,6 @@ pkgcfgdir= $(pkgdatadir)/config.d/ + pkgcfg_DATA = \ + nat.conf + +-if LINUX +- NATBIN = gnunet-helper-nat-server gnunet-helper-nat-client +- NATSERVER = gnunet-helper-nat-server.c +- NATCLIENT = gnunet-helper-nat-client.c +-install-exec-hook: +- $(top_srcdir)/src/nat/install-nat-helper.sh $(DESTDIR)$(libexecdir) $(SUDO_BINARY) || true +-else +-if XFREEBSD +- NATBIN = gnunet-helper-nat-server gnunet-helper-nat-client +- NATSERVER = gnunet-helper-nat-server.c +- NATCLIENT = gnunet-helper-nat-client.c +-install-exec-hook: +- $(top_srcdir)/src/nat/install-nat-helper.sh $(DESTDIR)$(libexecdir) $(SUDO_BINARY) || true +-endif +-else +-install-exec-hook: +-endif +- + bin_PROGRAMS = \ + gnunet-nat + +diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am +index 3aef05769..beaf6a204 100644 +--- a/src/peerstore/Makefile.am ++++ b/src/peerstore/Makefile.am +@@ -81,7 +81,20 @@ libgnunet_plugin_peerstore_sqlite_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) + endif + ++libgnunet_plugin_peerstore_emscripten_la_SOURCES = \ ++ plugin_peerstore_emscripten.c ++libgnunet_plugin_peerstore_emscripten_la_LIBADD = \ ++ $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ ++ $(top_builddir)/src/util/libgnunetutil.la \ ++ $(LTLIBINTL) ++libgnunet_plugin_peerstore_emscripten_la_LDFLAGS = \ ++ $(GN_PLUGIN_LDFLAGS) ++libgnunet_plugin_peerstore_emscripten_la_DEPENDENCIES = \ ++ $(top_builddir)/src/util/libgnunetutil.la \ ++ libgnunetpeerstore.la ++ + plugin_LTLIBRARIES = \ ++ libgnunet_plugin_peerstore_emscripten.la \ + $(SQLITE_PLUGIN) \ + $(FLAT_PLUGIN) + +diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am +index e8c1f5d4a..0863ed399 100644 +--- a/src/transport/Makefile.am ++++ b/src/transport/Makefile.am +@@ -80,20 +80,6 @@ endif + + if HAVE_EXPERIMENTAL + if LINUX +- WLAN_BIN = gnunet-helper-transport-wlan +- WLAN_BIN_DUMMY = gnunet-helper-transport-wlan-dummy +- WLAN_BIN_SENDER = gnunet-transport-wlan-sender +- WLAN_BIN_RECEIVER = gnunet-transport-wlan-receiver +- WLAN_PLUGIN_LA = libgnunet_plugin_transport_wlan.la +- WLAN_PLUGIN_TEST = test_plugin_wlan +- WLAN_API_TEST = test_transport_api_wlan +- WLAN_TIMEOUT_TEST = test_transport_api_timeout_wlan +- WLAN_REL_TEST = test_transport_api_reliability_wlan +- WLAN_QUOTA_TEST = test_quota_compliance_wlan \ +- test_quota_compliance_wlan_asymmetric +-endif +- +-if LINUX + install-exec-hook: + $(top_srcdir)/src/transport/install-wlan-helper.sh $(DESTDIR)$(libexecdir) $(SUDO_BINARY) || true + if HAVE_LIBBLUETOOTH +@@ -278,21 +264,7 @@ gnunet_service_transport_CFLAGS = \ + $(CFLAGS) + # -DANALYZE + +-plugin_LTLIBRARIES = \ +- libgnunet_plugin_transport_tcp.la \ +- libgnunet_plugin_transport_udp.la \ +- $(UNIX_PLUGIN_LA) \ +- $(HTTP_CLIENT_PLUGIN_LA) \ +- $(HTTPS_CLIENT_PLUGIN_LA) \ +- $(HTTP_SERVER_PLUGIN_LA) \ +- $(HTTPS_SERVER_PLUGIN_LA) \ +- $(WLAN_PLUGIN_LA) \ +- $(BT_PLUGIN_LA) +- +-# Note: real plugins of course need to be added +-# to the plugin_LTLIBRARIES above +-noinst_LTLIBRARIES = \ +- libgnunet_plugin_transport_template.la ++plugin_LTLIBRARIES = libgnunet_plugin_transport_http_client.la + + libgnunet_plugin_transport_tcp_la_SOURCES = \ + plugin_transport_tcp.c +@@ -367,7 +339,7 @@ libgnunet_plugin_transport_unix_la_LDFLAGS = \ + + + libgnunet_plugin_transport_http_client_la_SOURCES = \ +- plugin_transport_http_client.c plugin_transport_http_common.c plugin_transport_http_common.h ++ plugin_transport_http_client_emscripten.c plugin_transport_http_common.c plugin_transport_http_common.h + libgnunet_plugin_transport_http_client_la_LIBADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ +diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c +index 17157436d..a6e9f0f17 100644 +--- a/src/transport/tcp_connection_legacy.c ++++ b/src/transport/tcp_connection_legacy.c +@@ -408,7 +408,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, + &gc.gid)) + gcp = &gc; + #else +-#ifdef SO_PEERCRED ++#if 0 + /* largely traditional GNU/Linux */ + olen = sizeof (uc); + if ( (0 == +diff --git a/src/util/Makefile.am b/src/util/Makefile.am +index eb655157d..fdaca5721 100644 +--- a/src/util/Makefile.am ++++ b/src/util/Makefile.am +@@ -65,8 +65,6 @@ libgnunetutil_la_SOURCES = \ + common_allocation.c \ + common_endian.c \ + common_logging.c \ +- configuration.c \ +- configuration_loader.c \ + container_bloomfilter.c \ + container_heap.c \ + container_meta_data.c \ +@@ -96,13 +94,11 @@ libgnunetutil_la_SOURCES = \ + mst.c \ + mq.c \ + nc.c \ +- network.c \ + op.c \ + os_installation.c \ + os_network.c \ + os_priority.c \ + peer.c \ +- plugin.c \ + program.c \ + resolver_api.c resolver.h \ + scheduler.c \ diff --git a/gnunet-build/packages/gnunet/gnunet/files/gnunet-git-a03d29-all.patch b/gnunet-build/packages/gnunet/gnunet/files/gnunet-git-a03d29-all.patch deleted file mode 100644 index b1e8b3b..0000000 --- a/gnunet-build/packages/gnunet/gnunet/files/gnunet-git-a03d29-all.patch +++ /dev/null @@ -1,990 +0,0 @@ -diff --git a/configure.ac b/configure.ac -index 7c10d07..a3c121f 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -655,7 +655,7 @@ AC_ARG_WITH(ltdl, - AC_CHECK_HEADERS(ltdl.h, - AC_CHECK_LIB([ltdl], [lt_dlopenext], - ltdl=1))]) --if test x$ltdl = x1 -+if true - then - AC_MSG_RESULT([libltdl found]) - else -diff --git a/src/Makefile.am b/src/Makefile.am -index 56f301a..0fcefed 100644 ---- a/src/Makefile.am -+++ b/src/Makefile.am -@@ -100,7 +100,6 @@ SUBDIRS = \ - $(ATS_TESTS) \ - nse \ - dht \ -- hostlist \ - topology \ - regex \ - dns \ -@@ -113,19 +112,8 @@ SUBDIRS = \ - set \ - scalarproduct \ - revocation \ -- vpn \ -- gns \ -- zonemaster \ - $(CONVERSATION_DIR) \ - fs \ -- exit \ -- pt \ -- integration-tests \ -- multicast \ -- psycutil \ -- psycstore \ -- psyc \ -- social \ - $(AUCTION_DIR) \ - $(EXP_DIR) \ - $(PROVIDER_DIR) -diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am -index 1285020..e3203cc 100644 ---- a/src/datastore/Makefile.am -+++ b/src/datastore/Makefile.am -@@ -104,7 +104,8 @@ plugin_LTLIBRARIES = \ - $(SQLITE_PLUGIN) \ - $(MYSQL_PLUGIN) \ - $(POSTGRES_PLUGIN) \ -- libgnunet_plugin_datastore_heap.la -+ libgnunet_plugin_datastore_heap.la \ -+ libgnunet_plugin_datastore_emscripten.la - - # Real plugins should of course go into - # plugin_LTLIBRARIES -@@ -130,6 +131,13 @@ libgnunet_plugin_datastore_heap_la_LIBADD = \ - libgnunet_plugin_datastore_heap_la_LDFLAGS = \ - $(GN_PLUGIN_LDFLAGS) - -+libgnunet_plugin_datastore_emscripten_la_SOURCES = \ -+ plugin_datastore_emscripten.c -+libgnunet_plugin_datastore_emscripten_la_LIBADD = \ -+ $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ -+ $(LTLIBINTL) -+libgnunet_plugin_datastore_emscripten_la_LDFLAGS = \ -+ $(GN_PLUGIN_LDFLAGS) - - libgnunet_plugin_datastore_mysql_la_SOURCES = \ - plugin_datastore_mysql.c -diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am -index 26beb30..1cb6c03 100644 ---- a/src/dht/Makefile.am -+++ b/src/dht/Makefile.am -@@ -55,16 +55,6 @@ libexec_PROGRAMS += \ - gnunet-service-dht-whanau - endif - --noinst_PROGRAMS = \ -- gnunet-dht-monitor \ -- gnunet-dht-get \ -- gnunet-dht-put -- --if HAVE_TESTING --noinst_PROGRAMS += \ -- gnunet-dht-profiler --endif -- - gnunet_service_dht_SOURCES = \ - gnunet-service-dht.c gnunet-service-dht.h \ - gnunet-service-dht_datacache.c gnunet-service-dht_datacache.h \ -diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am -index f74c41f..f7c7ce1 100644 ---- a/src/dns/Makefile.am -+++ b/src/dns/Makefile.am -@@ -18,14 +18,6 @@ plugindir = $(libdir)/gnunet - pkgcfg_DATA = \ - dns.conf - --if LINUX --HIJACKBIN = gnunet-helper-dns --install-exec-hook: -- $(top_srcdir)/src/dns/install-dns-helper.sh $(DESTDIR)$(libexecdir) $(GNUNETDNS_GROUP) $(SUDO_BINARY) || true --else --install-exec-hook: --endif -- - lib_LTLIBRARIES = \ - libgnunetdnsparser.la \ - libgnunetdnsstub.la \ -diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c -index a5b82ec..5801aa8 100644 ---- a/src/fs/fs_api.c -+++ b/src/fs/fs_api.c -@@ -456,19 +456,22 @@ struct FileInfo - * to provide less data unless there is an error; - * a value of "0" will be used at the end to allow - * the reader to clean up its internal state -- * @param buf where the reader should write the data -- * @param emsg location for the reader to store an error message -- * @return number of bytes written, usually @a max, 0 on error -+ * @param cont continuation to call with a pointer to the read bytes or an -+ * error message -+ * @param cont_cls closure to pass to the continuation -+ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise - */ --size_t -+int - GNUNET_FS_data_reader_file_ (void *cls, - uint64_t offset, - size_t max, -- void *buf, -- char **emsg) -+ GNUNET_FS_ReaderContinuation cont, -+ void *cont_cls) - { - struct FileInfo *fi = cls; - ssize_t ret; -+ char **emsg = NULL; -+ char buf[max]; - - if (UINT64_MAX == offset) - { -@@ -477,7 +480,7 @@ GNUNET_FS_data_reader_file_ (void *cls, - GNUNET_DISK_file_close (fi->fd); - fi->fd = NULL; - } -- return 0; -+ return GNUNET_SYSERR; - } - if (0 == max) - { -@@ -485,7 +488,7 @@ GNUNET_FS_data_reader_file_ (void *cls, - GNUNET_DISK_file_close (fi->fd); - GNUNET_free (fi->filename); - GNUNET_free (fi); -- return 0; -+ return GNUNET_SYSERR; - } - if (NULL == fi->fd) - { -@@ -499,7 +502,9 @@ GNUNET_FS_data_reader_file_ (void *cls, - _("Could not open file `%s': %s"), - fi->filename, - STRERROR (errno)); -- return 0; -+ if (cont) -+ cont (cont_cls, NULL, max, *emsg); -+ return GNUNET_OK; - } - } - if ( (GNUNET_SYSERR == -@@ -510,16 +515,22 @@ GNUNET_FS_data_reader_file_ (void *cls, - _("Could not read file `%s': %s"), - fi->filename, - STRERROR (errno)); -- return 0; -+ if (cont) -+ cont (cont_cls, NULL, max, *emsg); -+ return GNUNET_OK; - } - if (ret != max) - { - GNUNET_asprintf (emsg, - _("Short read reading from file `%s'!"), - fi->filename); -- return 0; -+ if (cont) -+ cont (cont_cls, NULL, max, *emsg); -+ return GNUNET_OK; - } -- return max; -+ if (cont) -+ cont (cont_cls, buf, max, NULL); -+ return GNUNET_OK; - } - - -@@ -561,28 +572,30 @@ GNUNET_FS_make_file_reader_context_ (const char *filename) - * to provide less data unless there is an error; - * a value of "0" will be used at the end to allow - * the reader to clean up its internal state -- * @param buf where the reader should write the data -- * @param emsg location for the reader to store an error message -- * @return number of bytes written, usually @a max, 0 on error -+ * @param cont continuation to call with a pointer to the read bytes or an -+ * error message -+ * @param cont_cls closure to pass to the continuation -+ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise - */ --size_t -+int - GNUNET_FS_data_reader_copy_ (void *cls, - uint64_t offset, - size_t max, -- void *buf, -- char **emsg) -+ GNUNET_FS_ReaderContinuation cont, -+ void *cont_cls) - { - char *data = cls; - - if (UINT64_MAX == offset) -- return 0; -+ return GNUNET_SYSERR; - if (0 == max) - { - GNUNET_free_non_null (data); -- return 0; -+ return GNUNET_SYSERR; - } -- GNUNET_memcpy (buf, &data[offset], max); -- return max; -+ if (cont) -+ cont (cont_cls, &data[offset], max, NULL); -+ return GNUNET_OK; - } - - -@@ -1250,43 +1263,6 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, - - - /** -- * Copy all of the data from the reader to the write handle. -- * -- * @param wh write handle -- * @param fi file with reader -- * @return #GNUNET_OK on success -- */ --static int --copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, -- struct GNUNET_FS_FileInformation *fi) --{ -- char buf[32 * 1024]; -- uint64_t off; -- size_t ret; -- size_t left; -- char *emsg; -- -- emsg = NULL; -- off = 0; -- while (off < fi->data.file.file_size) -- { -- left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); -- ret = -- fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); -- if (0 == ret) -- { -- GNUNET_free (emsg); -- return GNUNET_SYSERR; -- } -- if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret)) -- return GNUNET_SYSERR; -- off += ret; -- } -- return GNUNET_OK; --} -- -- --/** - * Create a temporary file on disk to store the current - * state of @a fi in. - * -@@ -1370,7 +1346,6 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) - goto cleanup; - } - if ((GNUNET_NO == fi->is_published) && (NULL == fi->filename)) -- if (GNUNET_OK != copy_from_reader (wh, fi)) - { - GNUNET_break (0); - goto cleanup; -diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h -index e85de94..20a13fe 100644 ---- a/src/fs/fs_api.h -+++ b/src/fs/fs_api.h -@@ -670,16 +670,17 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe); - * to provide less data unless there is an error; - * a value of "0" will be used at the end to allow - * the reader to clean up its internal state -- * @param buf where the reader should write the data -- * @param emsg location for the reader to store an error message -- * @return number of bytes written, usually "max", 0 on error -+ * @param cont continuation to call with a pointer to the read bytes or an -+ * error message -+ * @param cont_cls closure to pass to the continuation -+ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise - */ --size_t -+int - GNUNET_FS_data_reader_file_ (void *cls, - uint64_t offset, - size_t max, -- void *buf, -- char **emsg); -+ GNUNET_FS_ReaderContinuation cont, -+ void *cont_cls); - - - /** -@@ -705,16 +706,17 @@ GNUNET_FS_make_file_reader_context_ (const char *filename); - * to provide less data unless there is an error; - * a value of "0" will be used at the end to allow - * the reader to clean up its internal state -- * @param buf where the reader should write the data -- * @param emsg location for the reader to store an error message -- * @return number of bytes written, usually @a max, 0 on error -+ * @param cont continuation to call with a pointer to the read bytes or an -+ * error message -+ * @param cont_cls closure to pass to the continuation -+ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise - */ --size_t -+int - GNUNET_FS_data_reader_copy_ (void *cls, - uint64_t offset, - size_t max, -- void *buf, -- char **emsg); -+ GNUNET_FS_ReaderContinuation cont, -+ void *cont_cls); - - - /** -diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c -index a89a959..a11515a 100644 ---- a/src/fs/fs_download.c -+++ b/src/fs/fs_download.c -@@ -1723,33 +1723,36 @@ reconstruct_cb (void *cls, - * @param offset identifies which block to get - * @param max (maximum) number of bytes to get; returning - * fewer will also cause errors -- * @param buf where to copy the plaintext buffer -- * @param emsg location to store an error message (on error) -- * @return number of bytes copied to buf, 0 on error -+ * @param cont continuation to call with a pointer to the read bytes or an -+ * error message -+ * @param cont_cls closure to pass to the continuation -+ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise - */ --static size_t --fh_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) -+static int -+fh_reader (void *cls, uint64_t offset, size_t max, -+ GNUNET_FS_ReaderContinuation cont, void *cont_cls) - { - struct GNUNET_FS_DownloadContext *dc = cls; - struct GNUNET_DISK_FileHandle *fh = dc->rfh; - ssize_t ret; -+ char buf[max]; - -- if (NULL != emsg) -- *emsg = NULL; - if (offset != GNUNET_DISK_file_seek (fh, offset, GNUNET_DISK_SEEK_SET)) - { -- if (NULL != emsg) -- *emsg = GNUNET_strdup (strerror (errno)); -- return 0; -+ if (cont) -+ cont (cont_cls, NULL, max, GNUNET_strdup (strerror (errno))); -+ return GNUNET_OK; - } - ret = GNUNET_DISK_file_read (fh, buf, max); - if (ret < 0) - { -- if (NULL != emsg) -- *emsg = GNUNET_strdup (strerror (errno)); -- return 0; -+ if (cont) -+ cont (cont_cls, NULL, max, GNUNET_strdup (strerror (errno))); -+ return GNUNET_OK; - } -- return ret; -+ if (cont) -+ cont (cont_cls, buf, max, NULL); -+ return GNUNET_OK; - } - - -diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c -index 86a58a5..2c616fc 100644 ---- a/src/fs/fs_publish.c -+++ b/src/fs/fs_publish.c -@@ -363,24 +363,24 @@ publish_kblocks_cont (void *cls, - * @param emsg location to store an error message (on error) - * @return number of bytes copied to buf, 0 on error - */ --static size_t -+static int - block_reader (void *cls, - uint64_t offset, - size_t max, -- void *buf, -- char **emsg) -+ GNUNET_FS_ReaderContinuation cont, -+ void *cont_cls) - { - struct GNUNET_FS_PublishContext *pc = cls; - struct GNUNET_FS_FileInformation *p; - const char *dd; -- size_t pt_size; - - p = pc->fi_pos; - if (GNUNET_YES == p->is_directory) - { -- pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset); - dd = p->data.dir.dir_data; -- GNUNET_memcpy (buf, &dd[offset], pt_size); -+ if (cont) -+ cont (cont_cls, &dd[offset], max, NULL); -+ return GNUNET_OK; - } - else - { -@@ -391,18 +391,11 @@ block_reader (void *cls, - /* force closing the file to avoid keeping too many files open */ - p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL); - } -- return 0; -+ return GNUNET_SYSERR; /* return value ignored in this case */ - } -- pt_size = GNUNET_MIN (max, p->data.file.file_size - offset); -- if (0 == pt_size) -- return 0; /* calling reader with pt_size==0 -- * might free buf, so don't! */ -- if (pt_size != -- p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf, -- emsg)) -- return 0; -- } -- return pt_size; -+ return p->data.file.reader (p->data.file.reader_cls, offset, max, -+ cont, cont_cls); -+ } - } - - -@@ -610,7 +603,6 @@ static void - publish_content (struct GNUNET_FS_PublishContext *pc) - { - struct GNUNET_FS_FileInformation *p; -- char *emsg; - struct GNUNET_FS_DirectoryBuilder *db; - struct GNUNET_FS_FileInformation *dirpos; - void *raw_data; -@@ -635,22 +627,6 @@ publish_content (struct GNUNET_FS_PublishContext *pc) - else - { - raw_data = NULL; -- if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) && -- (dirpos->data.file.file_size > 0)) -- { -- raw_data = GNUNET_malloc (dirpos->data.file.file_size); -- emsg = NULL; -- if (dirpos->data.file.file_size != -- dirpos->data.file.reader (dirpos->data.file.reader_cls, 0, -- dirpos->data.file.file_size, raw_data, -- &emsg)) -- { -- GNUNET_free_non_null (emsg); -- GNUNET_free (raw_data); -- raw_data = NULL; -- } -- dirpos->data.file.reader (dirpos->data.file.reader_cls, UINT64_MAX, 0, 0, NULL); -- } - } - GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta, - raw_data); -diff --git a/src/fs/fs_test_lib.c b/src/fs/fs_test_lib.c -index d038880..7c05639 100644 ---- a/src/fs/fs_test_lib.c -+++ b/src/fs/fs_test_lib.c -@@ -273,26 +273,23 @@ publish_progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) - * @param cls pointer to uint32_t with publishing seed - * @param offset offset to generate data for - * @param max maximum number of bytes to generate -- * @param buf where to write generated data -- * @param emsg where to store error message (unused) -- * @return number of bytes written to buf -+ * @param cont continuation to call with a pointer to the read bytes or an -+ * error message -+ * @param cont_cls closure to pass to the continuation -+ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise - */ --static size_t -+static int - file_generator (void *cls, - uint64_t offset, - size_t max, -- void *buf, -- char **emsg) -+ GNUNET_FS_ReaderContinuation cont, -+ void *cont_cls) - { - uint32_t *publish_seed = cls; - uint64_t pos; -- uint8_t *cbuf = buf; -+ uint8_t cbuf[max]; - int mod; - -- if (emsg != NULL) -- *emsg = NULL; -- if (buf == NULL) -- return 0; - for (pos = 0; pos < 8; pos++) - cbuf[pos] = (uint8_t) (offset >> pos * 8); - for (pos = 8; pos < max; pos++) -@@ -302,7 +299,9 @@ file_generator (void *cls, - mod = 1; - cbuf[pos] = (uint8_t) ((offset * (*publish_seed)) % mod); - } -- return max; -+ if (cont) -+ cont (cont_cls, cbuf, max, NULL); -+ return GNUNET_OK; - } - - -@@ -346,6 +345,24 @@ fs_disconnect_adapter (void *cls, - - - /** -+ * Continuation for GNUNET_FS_DataReader -+ */ -+static void -+disk_write_cont (void *cls, -+ const void *pt_block, -+ uint16_t pt_size, -+ char *emsg) -+{ -+ struct GNUNET_DISK_FileHandle *fh = cls; -+ -+ GNUNET_assert (NULL != fh); -+ GNUNET_assert (NULL != pt_block); -+ GNUNET_assert (NULL == emsg); -+ GNUNET_assert (pt_size == GNUNET_DISK_file_write (fh, pt_block, pt_size)); -+} -+ -+ -+/** - * Callback to be called when testbed has connected to the fs service - * - * @param cls the 'struct TestPublishOperation' -@@ -363,9 +380,7 @@ publish_fs_connect_complete_cb (void *cls, - struct TestPublishOperation *po = cls; - struct GNUNET_FS_FileInformation *fi; - struct GNUNET_DISK_FileHandle *fh; -- char *em; - uint64_t off; -- char buf[DBLOCK_SIZE]; - size_t bsize; - struct GNUNET_FS_BlockOptions bo; - -@@ -397,11 +412,8 @@ publish_fs_connect_complete_cb (void *cls, - off = 0; - while (off < po->size) - { -- bsize = GNUNET_MIN (sizeof (buf), po->size - off); -- emsg = NULL; -- GNUNET_assert (bsize == file_generator (&po->publish_seed, off, bsize, buf, &em)); -- GNUNET_assert (em == NULL); -- GNUNET_assert (bsize == GNUNET_DISK_file_write (fh, buf, bsize)); -+ bsize = GNUNET_MIN (DBLOCK_SIZE, po->size - off); -+ GNUNET_assert (GNUNET_OK == file_generator (&po->publish_seed, off, bsize, disk_write_cont, fh)); - off += bsize; - } - GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); -diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c -index b3c6322..1771f07 100644 ---- a/src/fs/fs_tree.c -+++ b/src/fs/fs_tree.c -@@ -322,59 +322,27 @@ compute_chk_offset (unsigned int depth, uint64_t end_offset) - - - /** -- * Encrypt the next block of the file (and call proc and progress -- * accordingly; or of course "cont" if we have already completed -- * encoding of the entire file). -- * -- * @param te tree encoder to use -+ * Continuation for te->reader - */ --void --GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) -+static void -+encrypt_block(void *cls, -+ const void *pt_block, -+ uint16_t pt_size, -+ char *emsg) - { -+ struct GNUNET_FS_TreeEncoder *te = cls; - struct ContentHashKey *mychk; -- const void *pt_block; -- uint16_t pt_size; -- char iob[DBLOCK_SIZE]; - char enc[DBLOCK_SIZE]; - struct GNUNET_CRYPTO_SymmetricSessionKey sk; - struct GNUNET_CRYPTO_SymmetricInitializationVector iv; - unsigned int off; - -- GNUNET_assert (GNUNET_NO == te->in_next); -- te->in_next = GNUNET_YES; -- if (te->chk_tree_depth == te->current_depth) -- { -- off = CHK_PER_INODE * (te->chk_tree_depth - 1); -- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", -- GNUNET_h2s (&te->chk_tree[off].query), off); -- te->uri = GNUNET_new (struct GNUNET_FS_Uri); -- te->uri->type = GNUNET_FS_URI_CHK; -- te->uri->data.chk.chk = te->chk_tree[off]; -- te->uri->data.chk.file_length = GNUNET_htonll (te->size); -+ if (NULL != emsg || NULL == pt_block) { -+ te->emsg = emsg; - te->in_next = GNUNET_NO; - te->cont (te->cls); - return; - } -- if (0 == te->current_depth) -- { -- /* read DBLOCK */ -- pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset); -- if (pt_size != -- te->reader (te->cls, te->publish_offset, pt_size, iob, &te->emsg)) -- { -- te->in_next = GNUNET_NO; -- te->cont (te->cls); -- return; -- } -- pt_block = iob; -- } -- else -- { -- pt_size = -- GNUNET_FS_tree_compute_iblock_size (te->current_depth, -- te->publish_offset); -- pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; -- } - off = compute_chk_offset (te->current_depth, te->publish_offset); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "TE is at offset %llu and depth %u with block size %u and target-CHK-offset %u\n", -@@ -416,6 +384,58 @@ GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) - - - /** -+ * Encrypt the next block of the file (and call proc and progress -+ * accordingly; or of course "cont" if we have already completed -+ * encoding of the entire file). -+ * -+ * @param te tree encoder to use -+ */ -+void -+GNUNET_FS_tree_encoder_next (struct GNUNET_FS_TreeEncoder *te) -+{ -+ const void *pt_block; -+ uint16_t pt_size; -+ unsigned int off; -+ -+ GNUNET_assert (GNUNET_NO == te->in_next); -+ te->in_next = GNUNET_YES; -+ if (te->chk_tree_depth == te->current_depth) -+ { -+ off = CHK_PER_INODE * (te->chk_tree_depth - 1); -+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TE done, reading CHK `%s' from %u\n", -+ GNUNET_h2s (&te->chk_tree[off].query), off); -+ te->uri = GNUNET_new (struct GNUNET_FS_Uri); -+ te->uri->type = GNUNET_FS_URI_CHK; -+ te->uri->data.chk.chk = te->chk_tree[off]; -+ te->uri->data.chk.file_length = GNUNET_htonll (te->size); -+ te->in_next = GNUNET_NO; -+ te->cont (te->cls); -+ return; -+ } -+ if (0 == te->current_depth) -+ { -+ /* read DBLOCK */ -+ pt_size = GNUNET_MIN (DBLOCK_SIZE, te->size - te->publish_offset); -+ if (GNUNET_OK != -+ te->reader (te->cls, te->publish_offset, pt_size, &encrypt_block, te)) -+ { -+ te->in_next = GNUNET_NO; -+ te->cont (te->cls); -+ return; -+ } -+ } -+ else -+ { -+ pt_size = -+ GNUNET_FS_tree_compute_iblock_size (te->current_depth, -+ te->publish_offset); -+ pt_block = &te->chk_tree[(te->current_depth - 1) * CHK_PER_INODE]; -+ encrypt_block(te, pt_block, pt_size, NULL); -+ } -+} -+ -+ -+/** - * Get the resulting URI from the encoding. - * - * @param te the tree encoder to clean up -@@ -446,7 +466,7 @@ GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder *te, - { - if (NULL != te->reader) - { -- (void) te->reader (te->cls, UINT64_MAX, 0, 0, NULL); -+ (void) te->reader (te->cls, UINT64_MAX, 0, NULL, NULL); - te->reader = NULL; - } - GNUNET_assert (GNUNET_NO == te->in_next); -diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c -index a672b84..c2713c0 100644 ---- a/src/fs/fs_unindex.c -+++ b/src/fs/fs_unindex.c -@@ -43,32 +43,37 @@ - * @param offset identifies which block to get - * @param max (maximum) number of bytes to get; returning - * fewer will also cause errors -- * @param buf where to copy the plaintext buffer -- * @param emsg location to store an error message (on error) -- * @return number of bytes copied to buf, 0 on error -+ * @param cont continuation to call with a pointer to the read bytes or an -+ * error message -+ * @param cont_cls closure to pass to the continuation -+ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise - */ --static size_t -+static int - unindex_reader (void *cls, - uint64_t offset, - size_t max, -- void *buf, -- char **emsg) -+ GNUNET_FS_ReaderContinuation cont, -+ void *cont_cls) - { - struct GNUNET_FS_UnindexContext *uc = cls; -- size_t pt_size; -+ char buf[max]; - -- pt_size = GNUNET_MIN (max, uc->file_size - offset); - if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET)) - { -- *emsg = GNUNET_strdup (_("Failed to find given position in file")); -- return 0; -+ if (cont) -+ cont (cont_cls, NULL, max, -+ GNUNET_strdup (_("Failed to find given position in file"))); -+ return GNUNET_OK; - } -- if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size)) -+ if (max != GNUNET_DISK_file_read (uc->fh, buf, max)) - { -- *emsg = GNUNET_strdup (_("Failed to read file")); -- return 0; -+ if (cont) -+ cont (cont_cls, NULL, max, GNUNET_strdup (_("Failed to read file"))); -+ return GNUNET_OK; - } -- return pt_size; -+ if (cont) -+ cont (cont_cls, buf, max, NULL); -+ return GNUNET_OK; - } - - -diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h -index a9c7e89..29c3072 100644 ---- a/src/include/gnunet_fs_service.h -+++ b/src/include/gnunet_fs_service.h -@@ -1846,6 +1846,20 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, - - - /** -+ * Continuation for GNUNET_FS_DataReader -+ * -+ * @param cls closure -+ * @param pt_block pointer to bytes read by the reader -+ * @param pt_size the number of bytes read, must be equal to max -+ * @param emsg error message, NULL is there is no error -+ */ -+typedef void (*GNUNET_FS_ReaderContinuation) (void *cls, -+ const void *pt_block, -+ uint16_t pt_size, -+ char *emsg); -+ -+ -+/** - * Function that provides data. - * - * @param cls closure -@@ -1857,20 +1871,21 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, - * clean up the reader's state); in this case, - * a value of '0' for max should be ignored - * @param max maximum number of bytes that should be -- * copied to buf; readers are not allowed -+ * passed to cont; readers are not allowed - * to provide less data unless there is an error; - * a value of "0" will be used at the end to allow - * the reader to clean up its internal state -- * @param buf where the reader should write the data -- * @param emsg location for the reader to store an error message -- * @return number of bytes written, usually @a max, 0 on error -+ * @param cont continuation to call with a pointer to the read bytes or an -+ * error message -+ * @param cont_cls closure to pass to the continuation -+ * @return GNUNET_SYSERR if cont will not be called, GNUNET_OK otherwise - */ - typedef size_t - (*GNUNET_FS_DataReader) (void *cls, - uint64_t offset, - size_t max, -- void *buf, -- char **emsg); -+ GNUNET_FS_ReaderContinuation cont, -+ void *cont_cls); - - - /** -diff --git a/src/nat/Makefile.am b/src/nat/Makefile.am -index f0d5639..f1fbd0e 100644 ---- a/src/nat/Makefile.am -+++ b/src/nat/Makefile.am -@@ -15,24 +15,6 @@ pkgcfgdir= $(pkgdatadir)/config.d/ - pkgcfg_DATA = \ - nat.conf - --if LINUX -- NATBIN = gnunet-helper-nat-server gnunet-helper-nat-client -- NATSERVER = gnunet-helper-nat-server.c -- NATCLIENT = gnunet-helper-nat-client.c --install-exec-hook: -- $(top_srcdir)/src/nat/install-nat-helper.sh $(DESTDIR)$(libexecdir) $(SUDO_BINARY) || true --else --if XFREEBSD -- NATBIN = gnunet-helper-nat-server gnunet-helper-nat-client -- NATSERVER = gnunet-helper-nat-server.c -- NATCLIENT = gnunet-helper-nat-client.c --install-exec-hook: -- $(top_srcdir)/src/nat/install-nat-helper.sh $(DESTDIR)$(libexecdir) $(SUDO_BINARY) || true --endif --else --install-exec-hook: --endif -- - bin_PROGRAMS = \ - gnunet-nat - -diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am -index 21db6ad..5b3612a 100644 ---- a/src/peerstore/Makefile.am -+++ b/src/peerstore/Makefile.am -@@ -79,7 +79,20 @@ libgnunet_plugin_peerstore_sqlite_la_LDFLAGS = \ - $(GN_PLUGIN_LDFLAGS) - endif - -+libgnunet_plugin_peerstore_emscripten_la_SOURCES = \ -+ plugin_peerstore_emscripten.c -+libgnunet_plugin_peerstore_emscripten_la_LIBADD = \ -+ $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ -+ $(top_builddir)/src/util/libgnunetutil.la \ -+ $(LTLIBINTL) -+libgnunet_plugin_peerstore_emscripten_la_LDFLAGS = \ -+ $(GN_PLUGIN_LDFLAGS) -+libgnunet_plugin_peerstore_emscripten_la_DEPENDENCIES = \ -+ $(top_builddir)/src/util/libgnunetutil.la \ -+ libgnunetpeerstore.la -+ - plugin_LTLIBRARIES = \ -+ libgnunet_plugin_peerstore_emscripten.la \ - $(SQLITE_PLUGIN) \ - $(FLAT_PLUGIN) - -diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am -index acc2557..dc3aaba 100644 ---- a/src/transport/Makefile.am -+++ b/src/transport/Makefile.am -@@ -80,20 +80,6 @@ if USE_COVERAGE - endif - - if LINUX -- WLAN_BIN = gnunet-helper-transport-wlan -- WLAN_BIN_DUMMY = gnunet-helper-transport-wlan-dummy -- WLAN_BIN_SENDER = gnunet-transport-wlan-sender -- WLAN_BIN_RECEIVER = gnunet-transport-wlan-receiver -- WLAN_PLUGIN_LA = libgnunet_plugin_transport_wlan.la -- WLAN_PLUGIN_TEST = test_plugin_wlan -- WLAN_API_TEST = test_transport_api_wlan -- WLAN_TIMEOUT_TEST = test_transport_api_timeout_wlan -- WLAN_REL_TEST = test_transport_api_reliability_wlan -- WLAN_QUOTA_TEST = test_quota_compliance_wlan \ -- test_quota_compliance_wlan_asymmetric --endif -- --if LINUX - install-exec-hook: - $(top_srcdir)/src/transport/install-wlan-helper.sh $(DESTDIR)$(libexecdir) $(SUDO_BINARY) || true - if HAVE_LIBBLUETOOTH -@@ -274,21 +260,7 @@ gnunet_service_transport_CFLAGS = \ - $(CFLAGS) - # -DANALYZE - --plugin_LTLIBRARIES = \ -- libgnunet_plugin_transport_tcp.la \ -- libgnunet_plugin_transport_udp.la \ -- $(UNIX_PLUGIN_LA) \ -- $(HTTP_CLIENT_PLUGIN_LA) \ -- $(HTTPS_CLIENT_PLUGIN_LA) \ -- $(HTTP_SERVER_PLUGIN_LA) \ -- $(HTTPS_SERVER_PLUGIN_LA) \ -- $(WLAN_PLUGIN_LA) \ -- $(BT_PLUGIN_LA) -- --# Note: real plugins of course need to be added --# to the plugin_LTLIBRARIES above --noinst_LTLIBRARIES = \ -- libgnunet_plugin_transport_template.la -+plugin_LTLIBRARIES = libgnunet_plugin_transport_http_client.la - - libgnunet_plugin_transport_tcp_la_SOURCES = \ - plugin_transport_tcp.c -@@ -363,7 +335,7 @@ libgnunet_plugin_transport_unix_la_LDFLAGS = \ - - - libgnunet_plugin_transport_http_client_la_SOURCES = \ -- plugin_transport_http_client.c plugin_transport_http_common.c plugin_transport_http_common.h -+ plugin_transport_http_client_emscripten.c plugin_transport_http_common.c plugin_transport_http_common.h - libgnunet_plugin_transport_http_client_la_LIBADD = \ - $(top_builddir)/src/hello/libgnunethello.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ -diff --git a/src/util/Makefile.am b/src/util/Makefile.am -index 931dd95..52c1c29 100644 ---- a/src/util/Makefile.am -+++ b/src/util/Makefile.am -@@ -63,8 +63,6 @@ libgnunetutil_la_SOURCES = \ - common_allocation.c \ - common_endian.c \ - common_logging.c \ -- configuration.c \ -- configuration_loader.c \ - connection.c \ - container_bloomfilter.c \ - container_heap.c \ -@@ -95,13 +93,11 @@ libgnunetutil_la_SOURCES = \ - mst.c \ - mq.c \ - nc.c \ -- network.c \ - op.c \ - os_installation.c \ - os_network.c \ - os_priority.c \ - peer.c \ -- plugin.c \ - program.c \ - resolver_api.c resolver.h \ - scheduler.c \ -diff --git a/src/util/connection.c b/src/util/connection.c -index 6d30704..a8b8633 100644 ---- a/src/util/connection.c -+++ b/src/util/connection.c -@@ -397,7 +397,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, - &gc.gid)) - gcp = &gc; - #else --#ifdef SO_PEERCRED -+#if 0 - /* largely traditional GNU/Linux */ - olen = sizeof (uc); - if ( (0 == diff --git a/gnunet-build/packages/gnunet/gnunet/files/network.js b/gnunet-build/packages/gnunet/gnunet/files/network.js index ef7c1bf..aff706a 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/network.js +++ b/gnunet-build/packages/gnunet/gnunet/files/network.js @@ -225,6 +225,27 @@ mergeInto(LibraryManager.library, { } return 0; }, + GNUNET_NETWORK_shorten_unixpath: function(unixpath) { + console.error("GNUNET_NETWORK_shorten_unixpath should not be called"); + return unixpath; + }, + GNUNET_NETWORK_socket_box_native: function(fd) { + console.error("GNUNET_NETWORK_socket_box_native should not be called"); + return 0; + }, + GNUNET_NETWORK_socket_free_memory_only_: function(desc) { + console.error("GNUNET_NETWORK_socket_free_memory_only_ should not be called"); + delete SOCKETS[desc]; + }, + GNUNET_NETWORK_socket_getsockopt: function(desc, level, optname, optval, + optlen) { + console.error("GNUNET_NETWORK_socket_getsockopt should not be called"); + return -1; + }, + GNUNET_NETWORK_socket_select: function(rfds, wfds, efds, timeout) { + console.error("GNUNET_NETWORK_socket_select should not be called"); + return -1; + } }); // vim: set expandtab ts=2 sw=2: diff --git a/gnunet-build/packages/gnunet/gnunet/files/plugin_datastore_emscripten.c b/gnunet-build/packages/gnunet/gnunet/files/plugin_datastore_emscripten.c index 3dcac82..697254d 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/plugin_datastore_emscripten.c +++ b/gnunet-build/packages/gnunet/gnunet/files/plugin_datastore_emscripten.c @@ -51,6 +51,7 @@ emscripten_plugin_estimate_size (void *cls, unsigned long long *estimate) * * @param cls closure * @param key key for the item + * @param absent true if the key was not found in the bloom filter * @param size number of bytes in data * @param data content stored * @param type type of the content @@ -62,37 +63,55 @@ emscripten_plugin_estimate_size (void *cls, unsigned long long *estimate) * @param cont_cls continuation closure */ static void -emscripten_plugin_put (void *cls, const struct GNUNET_HashCode *key, - uint32_t size, const void *data, - enum GNUNET_BLOCK_Type type, uint32_t priority, - uint32_t anonymity, uint32_t replication, +emscripten_plugin_put (void *cls, + const struct GNUNET_HashCode *key, + bool absent, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, struct GNUNET_TIME_Absolute expiration, - PluginPutCont cont, void *cont_cls) + PluginPutCont cont, + void *cont_cls) { - extern void emscripten_plugin_put_int(const void *key, const void *data, - double size, double type, double priority, double anonymity, - double replication, double expiration, void *vhash, void *cont, - void *cons_cls); - struct GNUNET_HashCode vhash; - - GNUNET_CRYPTO_hash (data, size, &vhash); - emscripten_plugin_put_int(key, data, size, type, priority, anonymity, - replication, expiration.abs_value_us, &vhash, cont, cont_cls); + extern void + emscripten_plugin_put_int(const void *key, + double absent, + const void *data, + double size, + double type, + double priority, + double anonymity, + double replication, + double expiration, + void *cont, + void *cons_cls); + + emscripten_plugin_put_int(key, absent, data, size, type, priority, anonymity, + replication, expiration.abs_value_us, cont, cont_cls); } static int -datum_processor_wrapper(PluginDatumProcessor proc, void *proc_cls, - const struct GNUNET_HashCode *key, uint32_t size, - const void *data, enum GNUNET_BLOCK_Type type, - uint32_t priority, uint32_t anonymity, - double *expiration, uint32_t uid) +datum_processor_wrapper(PluginDatumProcessor proc, + void *proc_cls, + const struct GNUNET_HashCode *key, + uint32_t size, + const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + uint32_t replication, + double *expiration, + uint32_t uid) { struct GNUNET_TIME_Absolute expiry; expiry.abs_value_us = *expiration; - return proc(proc_cls, key, size, data, type, priority, anonymity, expiry, - uid); + return proc(proc_cls, key, size, data, type, priority, anonymity, replication, + expiry, uid); } @@ -100,14 +119,9 @@ datum_processor_wrapper(PluginDatumProcessor proc, void *proc_cls, * Get one of the results for a particular key in the datastore. * * @param cls closure - * @param offset offset of the result (modulo num-results); - * specific ordering does not matter for the offset + * @param next_uid return the result with lowest uid >= next_uid + * @param random if true, return a random result instead of using next_uid * @param key maybe NULL (to match all entries) - * @param vhash hash of the value, maybe NULL (to - * match all values that have the right key). - * Note that for DBlocks there is no difference - * betwen key and vhash, but for other blocks - * there may be! * @param type entries of which type are relevant? * Use 0 for any type. * @param proc function to call on each matching value; @@ -115,17 +129,18 @@ datum_processor_wrapper(PluginDatumProcessor proc, void *proc_cls, * @param proc_cls closure for proc */ static void -emscripten_plugin_get_key (void *cls, uint64_t offset, +emscripten_plugin_get_key (void *cls, + uint64_t next_uid, + bool random, const struct GNUNET_HashCode *key, - const struct GNUNET_HashCode *vhash, enum GNUNET_BLOCK_Type type, - PluginDatumProcessor proc, void *proc_cls) + PluginDatumProcessor proc, + void *proc_cls) { - extern void emscripten_plugin_get_key_int(double offset, const void *key, - const void *vhash, double type, void *proc, void *proc_cls, - void *wrapper); + extern void emscripten_plugin_get_key_int(double next_uid, double random, + const void *key, double type, void *proc, void *proc_cls, void *wrapper); - emscripten_plugin_get_key_int(offset, key, vhash, type, proc, proc_cls, + emscripten_plugin_get_key_int(next_uid, random, key, type, proc, proc_cls, &datum_processor_wrapper); } @@ -174,46 +189,11 @@ emscripten_plugin_get_expiration (void *cls, PluginDatumProcessor proc, } -/** - * Update the priority for a particular key in the datastore. If - * the expiration time in value is different than the time found in - * the datastore, the higher value should be kept. The specified - * priority should be added to the existing priority, ignoring the - * priority in value. - * - * Note that it is possible for multiple values to match this put. - * In that case, all of the respective values are updated. - * - * @param cls our "struct Plugin*" - * @param uid unique identifier of the datum - * @param delta by how much should the priority - * change? If priority + delta < 0 the - * priority should be set to 0 (never go - * negative). - * @param expire new expiration time should be the - * MAX of any existing expiration time and - * this value - * @param cont continuation called with success or failure status - * @param cons_cls continuation closure - */ -static void -emscripten_plugin_update (void *cls, uint64_t uid, int delta, - struct GNUNET_TIME_Absolute expire, - PluginUpdateCont cont, void *cont_cls) -{ - extern void emscripten_plugin_update_int(double uid, double delta, - double expriy, void *cont, void *cont_cls); - - emscripten_plugin_update_int(uid, delta, expire.abs_value_us, cont, cont_cls); -} - - /** * Call the given processor on an item with zero anonymity. * * @param cls our "struct Plugin*" - * @param offset offset of the result (modulo num-results); - * specific ordering does not matter for the offset + * @param next_uid return the result with lowest uid >= next_uid * @param type entries of which type should be considered? * Use 0 for any type. * @param proc function to call on each matching value; @@ -221,14 +201,16 @@ emscripten_plugin_update (void *cls, uint64_t uid, int delta, * @param proc_cls closure for proc */ static void -emscripten_plugin_get_zero_anonymity (void *cls, uint64_t offset, - enum GNUNET_BLOCK_Type type, - PluginDatumProcessor proc, void *proc_cls) +emscripten_plugin_get_zero_anonymity (void *cls, + uint64_t next_uid, + enum GNUNET_BLOCK_Type type, + PluginDatumProcessor proc, + void *proc_cls) { - extern void emscripten_plugin_get_zero_anonymity_int(double offset, + extern void emscripten_plugin_get_zero_anonymity_int(double next_uid, double type, void *proc, void *proc_cls, void *wrapper); - emscripten_plugin_get_zero_anonymity_int(offset, type, proc, proc_cls, + emscripten_plugin_get_zero_anonymity_int(next_uid, type, proc, proc_cls, &datum_processor_wrapper); } @@ -261,6 +243,35 @@ emscripten_plugin_get_keys (void *cls, } +/** + * Remove a particular key in the datastore. + * + * @param cls closure + * @param key key for the content + * @param size number of bytes in data + * @param data content stored + * @param cont continuation called with success or failure status + * @param cont_cls continuation closure for @a cont + */ +static void +emscripten_plugin_remove_key (void *cls, + const struct GNUNET_HashCode *key, + uint32_t size, + const void *data, + PluginRemoveCont cont, + void *cont_cls) +{ + extern void + emscripten_plugin_remove_key_int(void *key, + double size, + void *data, + void *cont, + void *cont_cls); + + emscripten_plugin_remove_key_int(key, size, data, cont, cont_cls); +} + + /** * Entry point for the plugin. * @@ -276,13 +287,13 @@ libgnunet_plugin_datastore_emscripten_init (void *cls) api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions); api->estimate_size = &emscripten_plugin_estimate_size; api->put = &emscripten_plugin_put; - api->update = &emscripten_plugin_update; api->get_key = &emscripten_plugin_get_key; api->get_replication = &emscripten_plugin_get_replication; api->get_expiration = &emscripten_plugin_get_expiration; api->get_zero_anonymity = &emscripten_plugin_get_zero_anonymity; api->drop = &emscripten_plugin_drop; api->get_keys = &emscripten_plugin_get_keys; + api->remove_key = &emscripten_plugin_remove_key; GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "emscripten", _("Emscripten database running\n")); return api; diff --git a/gnunet-build/packages/gnunet/gnunet/files/plugin_datastore_emscripten_int.js b/gnunet-build/packages/gnunet/gnunet/files/plugin_datastore_emscripten_int.js index 47c3a8f..582cc68 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/plugin_datastore_emscripten_int.js +++ b/gnunet-build/packages/gnunet/gnunet/files/plugin_datastore_emscripten_int.js @@ -15,105 +15,125 @@ // along with this program. If not, see . mergeInto(LibraryManager.library, { - emscripten_plugin_put_int: function(key_pointer, data_pointer, size, type, - priority, anonymity, replication, expiry, - vhash_pointer, cont, cont_cls) { + emscripten_plugin_put_int: function(key_pointer, absent, data_pointer, size, + type, priority, anonymity, replication, + expiry, cont, cont_cls) { var key = Array.prototype.slice.call(HEAP8.subarray(key_pointer, key_pointer + 64)); var data = Array.prototype.slice.call(HEAP8.subarray(data_pointer, data_pointer + size)); - var vhash = Array.prototype.slice.call(HEAP8.subarray(vhash_pointer, - vhash_pointer + 64)); - var request = self.dsdb.transaction(['datastore'], 'readwrite') - .objectStore('datastore') - .put({key: key, - data: data, - type: type, - priority: priority, - anonymity: anonymity, - replication: replication, - expiry: expiry, - vhash: vhash}); - request.onerror = function(e) { - console.error('put request failed'); - dynCall('viiiii', cont, [cont_cls, key_pointer, size, -1, 0]); - }; - request.onsuccess = function(e) { - dynCall('viiiii', cont, [cont_cls, key_pointer, size, 1, 0]); + var transaction = self.dsdb.transaction(['datastore'], 'readwrite'); + var do_put = function() { + var request = transaction.objectStore('datastore') + .put({key: key, + data: data, + type: type, + priority: priority, + anonymity: anonymity, + replication: replication, + expiry: expiry}); + request.onerror = function(e) { + console.error('put request failed'); + dynCall('viiiii', cont, [cont_cls, key_pointer, size, -1, 0]); + }; + request.onsuccess = function(e) { + dynCall('viiiii', cont, [cont_cls, key_pointer, size, 1, 0]); + }; }; - }, - emscripten_plugin_get_key_int: function(offset, key_pointer, vhash_pointer, - type, proc, proc_cls, - datum_processor_wrapper) { + if (absent) { + do_put(); + } else { + var request = transaction.objectStore('datastore').index('by_key') + .openCursor(IDBKeyRange.bound( + [key], [key, Number.MAX_VALUE])); + request.onsuccess = function(e) { + var cursor = e.target.result; + if (cursor) { + var value = cursor.value; + // filter by data + if (size != value.data.length + || !data.every(function(x, i) { + return x == value.data[i] + })) { + cursor.continue(); + return; + } + value.priority += priority; + value.replication += replication; + if (value.expiry < expiry) { + value.expiry = expiry; + } + var request = transaction.objectStore('datastore').put(value); + request.onerror = function(e) { + console.error('put request failed'); + dynCall('viiiii', cont, + [cont_cls, key_pointer, size, -1, 0]); + }; + request.onsuccess = function(e) { + dynCall('viiiii', cont, + [cont_cls, key_pointer, size, 0, 0]); + }; + } else { + do_put(); + } + }; + } + }, emscripten_plugin_get_key_int: function(next_uid, random, key_pointer, + type, proc, proc_cls, + datum_processor_wrapper) { var key = key_pointer ? Array.prototype.slice.call(HEAP8.subarray( key_pointer, key_pointer + 64)) : null; - var vhash = vhash_pointer ? Array.prototype.slice.call(HEAP8.subarray( - vhash_pointer, vhash_pointer + 64)) : null; - var count = 0; - var request = self.dsdb.transaction(['datastore'], 'readwrite') - .objectStore('datastore').index('by_key') - .openCursor(key); + var range = null; + var transaction = self.dsdb.transaction(['datastore'], 'readonly'); + // TODO: random + var request; + if (key_pointer) { + request = transaction.objectStore('datastore').index('by_key') + .openCursor(IDBKeyRange.bound( + [key, next_uid], + [key, Number.MAX_VALUE])); + } else { + request = transaction.objectStore('datastore').openCursor(); + } request.onerror = function(e) { console.error('cursor request failed'); - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); }; request.onsuccess = function(e) { var cursor = e.target.result; if (cursor) { + var value = cursor.value; // optional filter by type - if (type && type != cursor.value.type) { - cursor.continue(); - return; - } - // optional filter by vhash - if (vhash != null) { - if (vhash.length != cursor.value.vhash.length - || !vhash.every(function(x, i) { - return x == cursor.value.vhash[i] - })) { - cursor.continue(); - return; - } - } - // filter by offset - if (offset != 0) { - --offset; - ++count; + if (type && type != value.type) { cursor.continue(); return; } // got a result var stack = stackSave(); var expiry = stackAlloc(getNativeTypeSize('double')); - setValue(expiry, cursor.value.expiry, 'double'); + setValue(expiry, value.expiry, 'double'); var ret = ccallFunc( getFuncWrapper(datum_processor_wrapper, - 'iiiiiiiiiii'), + 'iiiiiiiiiiii'), 'number', ['number', 'number', 'array', 'number', 'array', 'number', 'number', - 'number', 'number', 'number'], - [proc, proc_cls, cursor.value.key, cursor.value.data.length, - cursor.value.data, cursor.value.type, cursor.value.priority, - cursor.value.anonymity, expiry, cursor.value.uid]); + 'number', 'number', 'number', 'number'], + [proc, proc_cls, value.key, value.data.length, value.data, + value.type, value.priority, value.anonymity, value.replication, + expiry, value.uid]); stackRestore(stack); - if (!ret) { - cursor.delete().onerror = function(e) { - console.error('delete request failed'); - } - } } else { - // did offset wrap around? - if (count != 0) { - offset = offset % count; + // do we need to wrap around? + if (next_uid != 0) { // recurse - _emscripten_plugin_get_key_int(offset, key_pointer, vhash_pointer, - type, proc, proc_cls, datum_processor_wrapper); + _emscripten_plugin_get_key_int(0, false, key_pointer, type, proc, + proc_cls, datum_processor_wrapper); return; } // not found - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); } }; }, emscripten_plugin_get_replication_int: function(proc, proc_cls, @@ -123,44 +143,39 @@ mergeInto(LibraryManager.library, { .openCursor(null, 'prev'); request.onerror = function(e) { console.error('cursor request failed'); - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); }; request.onsuccess = function(e) { var cursor = e.target.result; if (cursor) { - // got a result - if (cursor.value.replication > 0) { - --cursor.value.replication; + var value = cursor.value + if (value.replication > 0) { + --value.replication; } - var request = transaction.objectStore('datastore').put(value); + var request = cursor.update(value); request.onerror = function(e) { - console.error('put request failed'); - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + console.error('replication update request failed'); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); }; request.onsuccess = function(e) { var stack = stackSave(); var expiry = stackAlloc(getNativeTypeSize('double')); setValue(expiry, cursor.value.expiry, 'double'); var ret = ccallFunc( - getFuncWrapper(datum_processor_wrapper, 'iiiiiiiiiii'), + getFuncWrapper(datum_processor_wrapper, 'iiiiiiiiiiii'), 'number', ['number', 'number', 'array', 'number', 'array', 'number', - 'number', 'number', 'number', 'number'], - [proc, proc_cls, cursor.value.key, cursor.value.data.length, - cursor.value.data, cursor.value.type, cursor.value.priority, - cursor.value.anonymity, expiry, cursor.value.uid]); + 'number', 'number', 'number', 'number', 'number'], + [proc, proc_cls, value.key, value.data.length, value.data, + value.type, value.priority, value.anonymity, value.replication, + expiry, value.uid]); stackRestore(stack); - if (!ret) { - cursor.delete().onerror = function(e) { - console.error('delete request failed'); - } - } }; } else { - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); } }; }, emscripten_plugin_get_expiration_int: function(proc, proc_cls, now, @@ -170,8 +185,8 @@ mergeInto(LibraryManager.library, { .openCursor(IDBKeyRange.upperBound(now, true)); request.onerror = function(e) { console.error('cursor request failed'); - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); }; request.onsuccess = function(e) { var cursor = e.target.result; @@ -182,13 +197,14 @@ mergeInto(LibraryManager.library, { setValue(expiry, cursor.value.expiry, 'double'); var ret = ccallFunc( getFuncWrapper(datum_processor_wrapper, - 'iiiiiiiiiii'), + 'iiiiiiiiiiii'), 'number', ['number', 'number', 'array', 'number', 'array', 'number', 'number', - 'number', 'number', 'number'], + 'number', 'number', 'number', 'number'], [proc, proc_cls, cursor.value.key, cursor.value.data.length, cursor.value.data, cursor.value.type, cursor.value.priority, - cursor.value.anonymity, expiry, cursor.value.uid]); + cursor.value.anonymity, cursor.value.replication, expiry, + cursor.value.uid]); stackRestore(stack); if (!ret) { cursor.delete().onerror = function(e) { @@ -196,88 +212,49 @@ mergeInto(LibraryManager.library, { } } } else { - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); } }; - }, emscripten_plugin_update_int: function(uid, delta, expiry, cont, - cont_cls) { - var transaction = self.dsdb.transaction(['datastore'], 'readwrite'); - var request = transaction.objectStore('datastore').get(uid); - request.onerror = function(e) { - console.warning('get request failed'); - dynCall('viii', cont, [cont_cls, -1, 0]); - }; - request.onsuccess = function(e) { - var value = e.target.result; - value.priority += delta; - if (value.priority < 0) { - value.priority = 0; - } - if (value.expiry < expiry) { - value.expiry = expiry; - } - var request = transaction.objectStore('datastore').put(value); - request.onerror = function(e) { - console.error('put request failed'); - dynCall('viii', cont, [cont_cls, -1, 0]); - }; - request.onsuccess = function(e) { - dynCall('viii', cont, [cont_cls, 1, 0]); - }; - }; - }, emscripten_plugin_get_zero_anonymity_int: function(offset, type, proc, + }, emscripten_plugin_get_zero_anonymity_int: function(next_uid, type, proc, proc_cls, datum_processor_wrapper) { - var count = 0; - var request = self.dsdb.transaction(['datastore'], 'readwrite') + var request = self.dsdb.transaction(['datastore'], 'readonly') .objectStore('datastore').index('by_anon_type') - .openCursor([0, type]); + .openCursor(IDBKeyRange.bound( + [0, type, next_uid], [0, type, Number.MAX_VALUE])); request.onerror = function(e) { console.error('cursor request failed'); - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); }; request.onsuccess = function(e) { var cursor = e.target.result; if (cursor) { - // filter by offset - if (offset != 0) { - --offset; - ++count; - cursor.continue(); - return; - } - // got a result var stack = stackSave(); var expiry = stackAlloc(getNativeTypeSize('double')); setValue(expiry, cursor.value.expiry, 'double'); var ret = ccallFunc( getFuncWrapper(datum_processor_wrapper, - 'iiiiiiiiiii'), + 'iiiiiiiiiiii'), 'number', ['number', 'number', 'array', 'number', 'array', 'number', 'number', - 'number', 'number', 'number'], + 'number', 'number', 'number', 'number'], [proc, proc_cls, cursor.value.key, cursor.value.data.length, cursor.value.data, cursor.value.type, cursor.value.priority, - cursor.value.anonymity, expiry, cursor.value.uid]); + cursor.value.anonymity, cursor.value.replication, expiry, + cursor.value.uid]); stackRestore(stack); - if (!ret) { - cursor.delete().onerror = function(e) { - console.error('delete request failed'); - } - } } else { - // did offset wrap around? - if (count != 0) { - offset = offset % count; + // do we need to wrap around? + if (next_uid != 0) { // recurse - _emscripten_plugin_get_zero_anonymity_int(offset, type, proc, - proc_cls, datum_processor_wrapper); + _emscripten_plugin_get_zero_anonymity_int(0, type, proc, proc_cls, + datum_processor_wrapper); return; } // not found - dynCall('iiiiiiiiiii', proc, - [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + dynCall('iiiiiiiiiiii', proc, + [proc_cls, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); } }; }, emscripten_plugin_get_keys_int: function(proc, proc_cls) { @@ -306,6 +283,47 @@ mergeInto(LibraryManager.library, { dynCall('viii', proc, [proc_cls, 0, 0]); } }; + }, emscripten_plugin_remove_key_int: function(key_pointer, size, data_pointer, + cont, cont_cls) { + var key = Array.prototype.slice.call(HEAP8.subarray(key_pointer, + key_pointer + 64)); + var data = Array.prototype.slice.call(HEAP8.subarray(data_pointer, + data_pointer + size)); + var transaction = self.dsdb.transaction(['datastore'], 'readwrite'); + var request = transaction.objectStore('datastore').index('by_key') + .openCursor(IDBKeyRange.bound( + [key], [key, Number.MAX_VALUE])); + request.onerror = function(e) { + console.error('cursor request failed'); + dynCall('viiiii', cont, [cont_cls, key_pointer, size, -1, 0]); + } + request.onsuccess = function(e) { + var cursor = e.target.result; + if (cursor) { + var value = cursor.value; + // filter by data + if (size != value.data.length + || !data.every(function(x, i) { + return x == value.data[i] + })) { + cursor.continue(); + return; + } + // found + request = cursor.delete(); + request.onerror = function(e) { + console.error('delete request failed'); + dynCall('viiiii', cont, [cont_cls, key_pointer, size, -1, 0]); + } + request.onsuccess = function(e) { + // removed + dynCall('viiiii', cont, [cont_cls, key_pointer, size, 1, 0]); + } + } else { + // not found + dynCall('viiiii', cont, [cont_cls, key_pointer, size, 0, 0]); + } + } } }); diff --git a/gnunet-build/packages/gnunet/gnunet/files/plugin_peerstore_emscripten.c b/gnunet-build/packages/gnunet/gnunet/files/plugin_peerstore_emscripten.c index 5fde4d3..2f9a0c3 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/plugin_peerstore_emscripten.c +++ b/gnunet-build/packages/gnunet/gnunet/files/plugin_peerstore_emscripten.c @@ -84,18 +84,16 @@ peerstore_emscripten_iter_wrapper ( char *key, void *value, size_t value_size, - double *expiry_dbl) + double *expiry) { - struct GNUNET_TIME_Absolute expiry; struct GNUNET_PEERSTORE_Record ret; - expiry.abs_value_us = *expiry_dbl; ret.sub_system = sub_system; - ret.peer = peer; + ret.peer = *peer; ret.key = key; ret.value = value; ret.value_size = value_size; - ret.expiry = &expiry; + ret.expiry.abs_value_us = expiry; iter (iter_cls, &ret, NULL); } diff --git a/gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten.c b/gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten.c index f0c05d6..ac4779f 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten.c +++ b/gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten.c @@ -130,7 +130,7 @@ struct GNUNET_ATS_Session /** * Message stream tokenizer for incoming data */ - struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk; + struct GNUNET_MessageStreamTokenizer *msg_tk; /** * Session timeout task @@ -309,7 +309,7 @@ client_delete_session (struct GNUNET_ATS_Session *s) GNUNET_TRANSPORT_SS_DONE); if (NULL != s->msg_tk) { - GNUNET_SERVER_mst_destroy (s->msg_tk); + GNUNET_MST_destroy (s->msg_tk); s->msg_tk = NULL; } GNUNET_HELLO_address_free (s->address); @@ -533,13 +533,11 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin, * Callback for message stream tokenizer * * @param cls the session - * @param client not used * @param message the message received * @return always #GNUNET_OK */ static int client_receive_mst_cb (void *cls, - void *client, const struct GNUNET_MessageHeader *message) { struct GNUNET_ATS_Session *s = cls; @@ -618,14 +616,13 @@ client_receive (void *stream, return 0; } if (NULL == s->msg_tk) - s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, - s); - GNUNET_SERVER_mst_receive (s->msg_tk, - s, - stream, - len, - GNUNET_NO, - GNUNET_NO); + s->msg_tk = GNUNET_MST_create (&client_receive_mst_cb, + s); + GNUNET_MST_from_buffer (s->msg_tk, + stream, + len, + GNUNET_NO, + GNUNET_NO); return len; } diff --git a/gnunet-build/packages/gnunet/gnunet/files/scheduler.c b/gnunet-build/packages/gnunet/gnunet/files/scheduler.c index 6874326..ba3c5aa 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/scheduler.c +++ b/gnunet-build/packages/gnunet/gnunet/files/scheduler.c @@ -62,6 +62,13 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, void *task_cls) return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, task, task_cls); } +struct GNUNET_SCHEDULER_Task * +GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, + GNUNET_SCHEDULER_TaskCallback task, void *task_cls) +{ + return GNUNET_SCHEDULER_add_now (task, task_cls); +} + struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at, enum GNUNET_SCHEDULER_Priority priority, @@ -108,4 +115,10 @@ GNUNET_SCHEDULER_get_task_context () return &tc; } +void +GNUNET_SCHEDULER_shutdown (void) +{ + // TODO: do we even need this? +} + /* vim: set expandtab ts=2 sw=2: */ diff --git a/src/cljs/gnunet_web/transport.cljs b/src/cljs/gnunet_web/transport.cljs index a93ec41..59332d8 100644 --- a/src/cljs/gnunet_web/transport.cljs +++ b/src/cljs/gnunet_web/transport.cljs @@ -89,11 +89,11 @@ {:state state :peer peer :address (when-not (zero? transport-pointer) - (let [transport (js/Pointer_stringify transport-pointer) - address (read-memory address-pointer address-length)] - (when (= "http_client" transport) - (gcrypt/utf8ByteArrayToString - (to-array (drop 8 address))))))}))) + (let [transport (js/Pointer_stringify transport-pointer)] + (when (and (= "http_client" transport) + (<= 9 address-length)) + (js/Pointer_stringify (+ 8 address-pointer) + (- address-length 9)))))}))) (def monitor-callback-pointer (+++ (js/addFunction monitor-callback))) -- cgit v1.2.3-18-g5258