From b92b03c0cdf46f97381834837427903f3219c4f5 Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Sun, 30 Oct 2016 22:25:19 -0500 Subject: Moving glue to network.js for {client,service}_new --- gnunet-build/packages/gnunet/gnunet/Buildrules | 43 ++--- .../packages/gnunet/gnunet/files/client.js | 144 -------------- .../packages/gnunet/gnunet/files/configuration.js | 30 ++- .../gnunet/gnunet/files/gnunet-svn-38181-all.patch | 41 ++-- .../packages/gnunet/gnunet/files/network.js | 199 +++++++++++++++++++ .../files/plugin_peerstore_emscripten_int.js | 6 +- gnunet-build/packages/gnunet/gnunet/files/pre.js | 17 +- .../packages/gnunet/gnunet/files/scheduler.c | 6 +- .../packages/gnunet/gnunet/files/scheduler.js | 75 +++++++- .../packages/gnunet/gnunet/files/server.js | 212 --------------------- .../packages/gnunet/gnunet/files/service.js | 31 --- 11 files changed, 346 insertions(+), 458 deletions(-) delete mode 100644 gnunet-build/packages/gnunet/gnunet/files/client.js create mode 100644 gnunet-build/packages/gnunet/gnunet/files/network.js delete mode 100644 gnunet-build/packages/gnunet/gnunet/files/server.js delete mode 100644 gnunet-build/packages/gnunet/gnunet/files/service.js diff --git a/gnunet-build/packages/gnunet/gnunet/Buildrules b/gnunet-build/packages/gnunet/gnunet/Buildrules index 53976c8..897a293 100644 --- a/gnunet-build/packages/gnunet/gnunet/Buildrules +++ b/gnunet-build/packages/gnunet/gnunet/Buildrules @@ -79,9 +79,8 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgpg-error.la" \ -lz \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --pre-js "${F}/pre.js" cp "${S}/src/peerinfo/.libs/gnunet-service-peerinfo.js" \ "${S}/src/peerinfo/.libs/gnunet-service-peerinfo.js.mem" \ @@ -129,10 +128,9 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/plugin.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --js-library "${F}/plugin_datastore_emscripten_int.js" \ --pre-js "${F}/pre.js" \ --pre-js "${F}/datastore-pre.js" @@ -168,12 +166,10 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ "${SYSROOT}/usr/lib/libunistring.la" \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/plugin.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --pre-js "${F}/pre.js" cp "${S}/src/ats/.libs/gnunet-service-ats.js" \ "${S}/src/ats/.libs/gnunet-service-ats.js.mem" \ @@ -210,12 +206,10 @@ pkg_compile() { "${S}/src/util/libgnunetutil.la" \ "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/plugin.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --js-library "${F}/plugin_transport_http_client_emscripten_int.js" \ --pre-js "${F}/pre.js" cp "${S}/src/transport/.libs/gnunet-service-transport.js" \ @@ -240,11 +234,9 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ -lz \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --pre-js "${F}/pre.js" cp "${S}/src/core/.libs/gnunet-service-core.js" \ "${S}/src/core/.libs/gnunet-service-core.js.mem" \ @@ -267,11 +259,9 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ -lz \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --pre-js "${F}/pre.js" cp "${S}/src/nse/.libs/gnunet-service-nse.js" \ "${S}/src/nse/.libs/gnunet-service-nse.js.mem" \ @@ -302,12 +292,10 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ -lz \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/plugin.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --pre-js "${F}/pre.js" cp "${S}/src/dht/.libs/gnunet-service-dht.js" \ "${S}/src/dht/.libs/gnunet-service-dht.js.mem" \ @@ -333,11 +321,9 @@ pkg_compile() { "${S}/src/util/libgnunetutil.la" \ "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ - --js-library "${F}/program.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ --pre-js "${F}/pre.js" cp "${S}/src/topology/.libs/gnunet-daemon-topology.js" \ "${S}/src/topology/.libs/gnunet-daemon-topology.js.mem" \ @@ -366,12 +352,10 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ -lz \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/plugin.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --pre-js "${F}/pre.js" cp "${S}/src/cadet/.libs/gnunet-service-cadet.js" \ "${S}/src/cadet/.libs/gnunet-service-cadet.js.mem" \ @@ -402,10 +386,9 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/plugin.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --js-library "${F}/plugin_peerstore_emscripten_int.js" \ --pre-js "${F}/pre.js" \ --pre-js "${F}/peerstore-pre.js" @@ -439,12 +422,10 @@ pkg_compile() { "${SYSROOT}/usr/lib/libgcrypt.la" \ "${SYSROOT}/usr/lib/libgpg-error.la" \ -lz \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/plugin.js" \ --js-library "${F}/scheduler.js" \ - --js-library "${F}/server.js" \ - --js-library "${F}/service.js" \ --pre-js "${F}/pre.js" cp "${S}/src/fs/.libs/gnunet-service-fs.js" \ "${S}/src/fs/.libs/gnunet-service-fs.js.mem" \ @@ -476,8 +457,8 @@ pkg_compile() { "${SYSROOT}/usr/lib/libunistring.la" \ "${SYSROOT}/usr/lib/libextractor.so" \ -lz \ - --js-library "${F}/client.js" \ --js-library "${F}/configuration.js" \ + --js-library "${F}/network.js" \ --js-library "${F}/scheduler.js" \ --pre-js "${F}/client-pre.js" cp "${S}/src/.libs/client-lib.js" \ diff --git a/gnunet-build/packages/gnunet/gnunet/files/client.js b/gnunet-build/packages/gnunet/gnunet/files/client.js deleted file mode 100644 index b61767b..0000000 --- a/gnunet-build/packages/gnunet/gnunet/files/client.js +++ /dev/null @@ -1,144 +0,0 @@ -// client.js - client routines for gnunet-web services -// Copyright (C) 2013,2014 David Barksdale -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -mergeInto(LibraryManager.library, { - $CLIENT_PORTS: {}, - $NEXT_PORT: 1, - GNUNET_CLIENT_connect__deps: ['$CLIENT_PORTS', '$NEXT_PORT'], - GNUNET_CLIENT_connect: function(service_name, cfg) { - var service_name = Pointer_stringify(service_name); - var channel; - try { - channel = new MessageChannel(); - } catch (e) { - console.error("No MessageChannel in this browser", e); - return 0; - } - var port = NEXT_PORT; - NEXT_PORT = port + 1; - var client = { - port: channel.port1, - name: service_name, - queue: [], - handler: null, - th: null}; - client.port.onmessage = function(ev) { - try { - if (client.handler) { - var handler = client.handler; - client.handler = null; - handler(ev); - } else - client.queue.push(ev); - } catch (e) { - console.error("Rekt'd", e); - } - }; - CLIENT_PORTS[port] = client; - console.debug('connecting to service', service_name); - if (typeof client_connect == 'function') { - client_connect(service_name, channel.port2); - } else { - try { - gnunet_web.service.client_connect(service_name, 'client.js', - channel.port2); - } catch(e) { - console.error('Failed to connect to', service_name, e); - return 0; - } - } - return port; - }, - GNUNET_CLIENT_connecT__deps: ['GNUNET_CLIENT_connect'], - GNUNET_CLIENT_connecT: function(cfg, service_name, handlers, error_handler, - error_handler_cls) { - c = _GNUNET_CLIENT_connect(service_name, cfg); - if (0 == c) - return 0; - return _GNUNET_MQ_queue_for_connection_client(c, handlers, error_handler, - error_handler_cls); - }, - GNUNET_CLIENT_disconnect__deps: ['$CLIENT_PORTS'], - GNUNET_CLIENT_disconnect: function(port) { - var client = CLIENT_PORTS[port]; - console.debug('Closing client port to service', client.name); - clearTimeout(client.th); - client.th = null; - client.port.close(); - delete CLIENT_PORTS[port]; - }, - GNUNET_CLIENT_receive__deps: ['$CLIENT_PORTS'], - GNUNET_CLIENT_receive: function(port, handler, handler_cls, timeout) { - var client = CLIENT_PORTS[port]; - var fn = function(ev) { - console.debug('Received ' + ev.data.length + ' bytes from service ' - + client.name); - ccallFunc(Runtime.getFuncWrapper(handler, 'vii'), 'void', - ['number', 'array'], - [handler_cls, ev.data]); - }; - if (client.queue.length) { - var ev = client.queue[0]; - setTimeout(function() { fn(ev); }, 0); - client.queue = client.queue.slice(1); - } else { - client.handler = fn; - var delay = getValue(timeout, 'i64'); - if (-1 != delay) { - setTimeout(function() { - client.handler = null; - Runtime.dynCall('vii', handler, [handler_cls, 0]); - }, delay / 1000); - } - } - }, - GNUNET_CLIENT_notify_transmit_ready__deps: ['$CLIENT_PORTS'], - GNUNET_CLIENT_notify_transmit_ready: function(port, size, timeout, - auto_retry, notify, notify_cls) { - var client = CLIENT_PORTS[port]; - // Supposedly we can call notify right now, but the current code never - // does so let's emulate that. - client.th = setTimeout(function() { - client.th = null; - console.debug('I want to send ' + size + ' bytes to service ' - + client.name); - var stack = Runtime.stackSave(); - var buffer = Runtime.stackAlloc(size); - var ret = Runtime.dynCall('iiii', notify, [notify_cls, size, buffer]); - console.debug('I\'m sending ' + ret + ' bytes to service ' - + client.name); - var view = {{{ makeHEAPView('U8', 'buffer', 'buffer+ret') }}}; - // See http://code.google.com/p/chromium/issues/detail?id=169705 - if (ret > 0) { - try { - client.port.postMessage(new Uint8Array(view)); - } catch (e) { - console.error('Failed to send'); - } - } - Runtime.stackRestore(stack); - }, 0); - return port; - }, - GNUNET_CLIENT_notify_transmit_ready_cancel_deps: ['$CLIENT_PORTS'], - GNUNET_CLIENT_notify_transmit_ready_cancel: function(port) { - var client = CLIENT_PORTS[port]; - clearTimeout(client.th); - client.th = null; - }, -}); - -// vim: set expandtab ts=2 sw=2: diff --git a/gnunet-build/packages/gnunet/gnunet/files/configuration.js b/gnunet-build/packages/gnunet/gnunet/files/configuration.js index 0570464..0d736ac 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/configuration.js +++ b/gnunet-build/packages/gnunet/gnunet/files/configuration.js @@ -1,10 +1,10 @@ // configuration.js - config data handler for gnunet-web services -// Copyright (C) 2013,2014 David Barksdale +// Copyright (C) 2013-2016 David Barksdale // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,10 +23,12 @@ mergeInto(LibraryManager.library, { DISABLE: true, }, transport: { + UNIXPATH: 'transport', NEIGHBOUR_LIMIT: 50, PLUGINS: 'http_client', }, ats: { + UNIXPATH: 'ats', UNSPECIFIED_QUOTA_OUT: '65536', UNSPECIFIED_QUOTA_IN: '65536', LOOPBACK_QUOTA_OUT: '65536', @@ -41,9 +43,11 @@ mergeInto(LibraryManager.library, { BLUETOOTH_QUOTA_IN: '65536', }, core: { + UNIXPATH: 'core', USE_EPHEMERAL_KEYS: true, }, dht: { + UNIXPATH: 'dht', CACHE_RESULTS: true, DISABLE_TRY_CONNECT: false, }, @@ -53,23 +57,27 @@ mergeInto(LibraryManager.library, { DISABLE_BF: true, }, nse: { + UNIXPATH: 'nse', PROOFFILE: '/nse/proof.dat', WORKDELAY: '5 ms', INTERVAL: '1 h', WORKBITS: 22, }, cadet: { + UNIXPATH: 'cadet', MAX_MSGS_QUEUE: 10000, MAX_CONNECTIONS: 1000, REFRESH_CONNECTION_TIME: '5 min', ID_ANNOUNCE_TIME: '1 h', }, datastore: { + UNIXPATH: 'datastore', DATABASE: 'emscripten', QUOTA: '1 GB', BLOOMFILTER: '/datastore/bloomfilter', }, fs: { + UNIXPATH: 'fs', DELAY: true, CONTENT_CACHING: true, CONTENT_PUSHING: true, @@ -77,11 +85,16 @@ mergeInto(LibraryManager.library, { RESPECT: '/fs/credit', }, peerinfo: { + UNIXPATH: 'peerinfo', HOSTS: '/peerinfo/hosts', }, peerstore: { + UNIXPATH: 'peerstore', DATABASE: 'emscripten', }, + arm: { + CONFIG: '', + }, }, GNUNET_CONFIGURATION_get_value__deps: ['$CONFIG'], GNUNET_CONFIGURATION_get_value: function(section, option) { @@ -93,18 +106,18 @@ mergeInto(LibraryManager.library, { console.debug(section + ' not in CONFIG'); return undefined; } - section = CONFIG[section] - if (!(option in section)) { + var sec = CONFIG[section] + if (!(option in sec)) { console.debug(option + ' not in ' + section); return undefined; } - console.debug('found:', section[option]); - return section[option]; + console.debug('found:', sec[option]); + return sec[option]; }, GNUNET_CONFIGURATION_have_value__deps: ['GNUNET_CONFIGURATION_get_value'], GNUNET_CONFIGURATION_have_value: function(cfg, section, option) { - return undefined === _GNUNET_CONFIGURATION_get_value(cfg, section, option); + return undefined !== _GNUNET_CONFIGURATION_get_value(section, option); }, GNUNET_CONFIGURATION_get_value_string__deps: ['GNUNET_CONFIGURATION_get_value', 'GNUNET_xstrdup_'], @@ -191,6 +204,9 @@ mergeInto(LibraryManager.library, { GNUNET_CONFIGURATION_create: function() { return 1; // opaque non-null pointer }, + GNUNET_CONFIGURATION_load: function(cfg, filename) { + return 1; + } }); // vim: set expandtab ts=2 sw=2: diff --git a/gnunet-build/packages/gnunet/gnunet/files/gnunet-svn-38181-all.patch b/gnunet-build/packages/gnunet/gnunet/files/gnunet-svn-38181-all.patch index 9039d4f..5fd6014 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/gnunet-svn-38181-all.patch +++ b/gnunet-build/packages/gnunet/gnunet/files/gnunet-svn-38181-all.patch @@ -968,34 +968,39 @@ Index: gnunet-svn-38181/src/util/Makefile.am =================================================================== --- gnunet-svn-38181/src/util/Makefile.am (revision 38181) +++ gnunet-svn-38181/src/util/Makefile.am (working copy) -@@ -59,14 +59,10 @@ - libgnunetutil_la_SOURCES = \ - bandwidth.c \ - bio.c \ -- client.c \ - client_new.c \ +@@ -64,8 +64,6 @@ common_allocation.c \ common_endian.c \ common_logging.c \ - configuration.c \ - configuration_loader.c \ -- connection.c \ + connection.c \ container_bloomfilter.c \ container_heap.c \ - container_meta_data.c \ -@@ -101,15 +97,11 @@ +@@ -95,13 +93,11 @@ + 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 \ + program.c \ resolver_api.c resolver.h \ scheduler.c \ -- server.c \ - server_mst.c \ - server_nc.c \ - server_tc.c \ -- service.c \ - service_new.c \ - signal.c \ - strings.c \ +Index: gnunet-svn-38181/src/util/connection.c +=================================================================== +--- gnunet-svn-38181/src/util/connection.c (revision 38181) ++++ gnunet-svn-38181/src/util/connection.c (working copy) +@@ -397,7 +397,7 @@ + &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 new file mode 100644 index 0000000..80ad2e5 --- /dev/null +++ b/gnunet-build/packages/gnunet/gnunet/files/network.js @@ -0,0 +1,199 @@ +// network.js - network routines for gnunet-web services +// Copyright (C) 2016 David Barksdale +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +mergeInto(LibraryManager.library, { + $SOCKETS: {incoming: []}, + $NEXT_SOCKET: 1, + GNUNET_NETWORK_socket_create__deps: ['$SOCKETS', '$NEXT_SOCKET'], + GNUNET_NETWORK_socket_create: function(domain, type, protocol) { + console.debug("socket_create(", domain, type, protocol, ")"); + if (domain != 1 || type != 1 || protocol != 0) { + return 0; + } + return NEXT_SOCKET++; + }, + GNUNET_NETWORK_socket_connect__deps: ['$SOCKETS'], + GNUNET_NETWORK_socket_connect: function(desc, address, address_len) { + console.debug("socket_connect(", desc, address, address_len, ")"); + if (desc in SOCKETS) { + console.error("socket already connected?"); + return -1; + } + if (110 != address_len) { + return -1; + } + var path = Pointer_stringify(address + 2); + console.debug("connecting to", path); + var channel; + try { + channel = new MessageChannel(); + } catch (e) { + console.error("No MessageChannel in this browser", e); + return -1; + } + var socket = SOCKETS[desc] = { + port: channel.port1, + name: path, + queue: [], + }; + channel.port1.onmessage = function(ev) { + console.debug("got message on socket", desc, ev); + socket.queue.push(ev.data); + if ("task" in socket) { + console.debug("calling read handler"); + delete SCHEDULER_TASKS[socket.task]; + delete socket["task"]; + Runtime.dynCall('vi', socket.handler, [socket.cls]); + } + }; + if (typeof client_connect == 'function') { + client_connect(path, channel.port2); + } else { + try { + gnunet_web.service.client_connect(path, 'client.js', channel.port2); + } catch(e) { + console.error('Failed to connect to', path, e); + return -1; + } + } + return 1; + }, + GNUNET_NETWORK_socket_send__deps: ['$SOCKETS'], + GNUNET_NETWORK_socket_send: function(desc, buffer, length) { + console.debug("socket_send(", desc, buffer, length, ")"); + if (!(desc in SOCKETS)) { + console.error("socket not connected?"); + return -1; + } + var view = {{{ makeHEAPView('U8', 'buffer', 'buffer+length') }}}; + try { + SOCKETS[desc].port.postMessage(new Uint8Array(view)); + } catch (e) { + console.error("Failed to send"); + return -1; + } + return length; + }, + GNUNET_NETWORK_socket_close__deps: ['$SOCKETS'], + GNUNET_NETWORK_socket_close: function(desc) { + console.debug("socket_close(", desc, ")"); + if (!(desc in SOCKETS)) { + return 1; + } + var socket = SOCKETS[desc]; + delete SOCKETS[desc]; + if ("port" in socket) { + socket.port.close(); + } + return 1; + }, + GNUNET_NETWORK_socket_bind__deps: ['$SOCKETS'], + GNUNET_NETWORK_socket_bind: function(desc, address, address_len) { + console.debug("socket_bind(", desc, address, address_len, ")"); + if (desc in SOCKETS) { + console.error("socket already bound?"); + return -1; + } + if (110 != address_len) { + return -1; + } + var path = Pointer_stringify(address + 2); + console.debug("binding to", path); + SOCKETS[desc] = {}; + return 1; + }, + GNUNET_NETWORK_socket_listen__deps: ['$SOCKETS'], + GNUNET_NETWORK_socket_listen: function(desc, backlog) { + console.debug("socket_listen(", desc, backlog, ")"); + if ("listening" in SOCKETS) { + console.error("only one listening socket is supported"); + return -1; + } + SOCKETS.listening = desc; + return 1; + }, + GNUNET_NETWORK_socket_accept__deps: ['$SOCKETS', '$NEXT_SOCKET'], + GNUNET_NETWORK_socket_accept: function(desc, address, address_len) { + console.debug("socket_accept(", desc, address, address_len, ")"); + if (desc != SOCKETS.listening) { + console.error("socket is not listening"); + return 0; + } + if (0 == SOCKETS.incoming.length) { + console.debug("no incoming connections"); + return 0; + } + var data = SOCKETS.incoming.shift(); + var sd = NEXT_SOCKET++; + var socket = SOCKETS[sd] = { + port: data.port, + name: data['client-name'], + queue: [], + }; + data.port.onmessage = function(ev) { + console.debug("got message on socket", sd, ev); + socket.queue.push(ev.data); + if ("task" in socket) { + console.debug("calling read handler"); + delete SCHEDULER_TASKS[socket.task]; + delete socket["task"]; + Runtime.dynCall('vi', socket.handler, [socket.cls]); + } + }; + {{{ makeSetValue('address', '0', '1', 'i16') }}}; + {{{ makeSetValue('address_len', '0', '110', 'i32') }}}; + return sd; + }, + GNUNET_NETWORK_socket_recv__deps: ['$SOCKETS'], + GNUNET_NETWORK_socket_recv: function(desc, buffer, length) { + console.debug("socket_recv(", desc, buffer, length, ")"); + if (!(desc in SOCKETS)) { + console.error("socket not connected?"); + return -1; + } + var socket = SOCKETS[desc]; + if (0 == socket.queue.length) { + console.debug("nothing to read"); + return 0; + } + var data = socket.queue[0]; + var sub = data.subarray(0, length); + HEAP8.set(sub, buffer); + if (sub.length == data.length) { + socket.queue.shift(); + } else { + socket.queue[0] = data.subarray(sub.length); + } + console.debug("read", sub.length, "bytes"); + return sub.length; + }, + GNUNET_NETWORK_fdset_isset__deps: ['$SOCKETS'], + GNUNET_NETWORK_fdset_isset: function(fds, desc) { + if (fds == 2) { + // always ready to write + return 1; + } + if (desc == SOCKETS.listening) { + return SOCKETS.incoming.length; + } + if (desc in SOCKETS) { + return SOCKETS[desc].queue.length; + } + return 0; + }, +}); + +// vim: set expandtab ts=2 sw=2: diff --git a/gnunet-build/packages/gnunet/gnunet/files/plugin_peerstore_emscripten_int.js b/gnunet-build/packages/gnunet/gnunet/files/plugin_peerstore_emscripten_int.js index 4056cac..1a309b5 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/plugin_peerstore_emscripten_int.js +++ b/gnunet-build/packages/gnunet/gnunet/files/plugin_peerstore_emscripten_int.js @@ -4,7 +4,7 @@ // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -85,12 +85,12 @@ mergeInto(LibraryManager.library, { Runtime.stackRestore(stack); cursor.continue(); } else { - Runtime.dynCall('iiii', iter, [iter_cls, 0, 0]); + Runtime.dynCall('viii', iter, [iter_cls, 0, 0]); } }; request.onerror = function(e) { Module.print('cursor request failed'); - Runtime.dynCall('iiii', iter, [iter_cls, 0, -1]); + Runtime.dynCall('viii', iter, [iter_cls, 0, -1]); }; }, peerstore_emscripten_store_record_int: function(sub_system_pointer, diff --git a/gnunet-build/packages/gnunet/gnunet/files/pre.js b/gnunet-build/packages/gnunet/gnunet/files/pre.js index b10d085..e95fb23 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/pre.js +++ b/gnunet-build/packages/gnunet/gnunet/files/pre.js @@ -1,10 +1,10 @@ // pre.js - linked into each gnunet-web service -// Copyright (C) 2013-2015 David Barksdale +// Copyright (C) 2013-2016 David Barksdale // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -77,6 +77,7 @@ gnunet_prerun = function() { } if (typeof(Module) === "undefined") Module = { 'preInit': [] }; Module['preInit'].push(gnunet_prerun); +Module['arguments'] = ["-L", "DEBUG"]; // a map of window index to port var windows = {}; @@ -105,7 +106,17 @@ function get_message(ev) { random_offset = 0; removeRunDependency('window-init'); } else if ('connect' == ev.data.type) { - SERVER.connect(ev.data.port, ev.data['client-name']); + console.debug("got connect: ", ev.data); + SOCKETS.incoming.push(ev.data); + if ("listening" in SOCKETS) { + var socket = SOCKETS[SOCKETS.listening]; + if ("task" in socket) { + delete SCHEDULER_TASKS[socket.task]; + delete socket["task"]; + console.debug("calling handler for listening socket"); + Runtime.dynCall('vi', socket["handler"], [socket["cls"]]); + } + } } } catch (e) { console.error('Rekt', e); diff --git a/gnunet-build/packages/gnunet/gnunet/files/scheduler.c b/gnunet-build/packages/gnunet/gnunet/files/scheduler.c index 595c69d..158bcf6 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/scheduler.c +++ b/gnunet-build/packages/gnunet/gnunet/files/scheduler.c @@ -78,9 +78,9 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_TaskCallback task, } const struct GNUNET_SCHEDULER_TaskContext tc = { - .reason = GNUNET_SCHEDULER_REASON_TIMEOUT, - .read_ready = NULL, - .write_ready = NULL, + .reason = GNUNET_SCHEDULER_REASON_WRITE_READY, + .read_ready = (void *)(intptr_t)1, + .write_ready = (void *)(intptr_t)2, }; const struct GNUNET_SCHEDULER_TaskContext * diff --git a/gnunet-build/packages/gnunet/gnunet/files/scheduler.js b/gnunet-build/packages/gnunet/gnunet/files/scheduler.js index 77da2db..5f07bbb 100644 --- a/gnunet-build/packages/gnunet/gnunet/files/scheduler.js +++ b/gnunet-build/packages/gnunet/gnunet/files/scheduler.js @@ -1,10 +1,10 @@ // scheduler.js - scheduler routines for gnunet-web services -// Copyright (C) 2013-2015 David Barksdale +// Copyright (C) 2013-2016 David Barksdale // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -25,7 +25,7 @@ mergeInto(LibraryManager.library, { delete SCHEDULER_TASKS[id]; Runtime.dynCall('vi', task, [task_cls]); }, delay); - SCHEDULER_TASKS[id] = task_cls; + SCHEDULER_TASKS[id] = {cls: task_cls}; return id; }, GNUNET_SCHEDULER_add_read_file: function(delay, rfd, task, task_cls) { @@ -33,14 +33,77 @@ mergeInto(LibraryManager.library, { }, GNUNET_SCHEDULER_cancel__deps: ['$SCHEDULER_TASKS'], GNUNET_SCHEDULER_cancel: function(task) { + console.debug("cancelling task", task); clearTimeout(task); if (task in SCHEDULER_TASKS) { - var cls = SCHEDULER_TASKS[task]; + var t = SCHEDULER_TASKS[task]; delete SCHEDULER_TASKS[task]; - return cls; + if ("socket" in t) { + delete SOCKETS[t.socket]["task"]; + } + return t.cls; } return 0; - } + }, + GNUNET_SCHEDULER_add_read_net__deps: ['$SOCKETS'], + GNUNET_SCHEDULER_add_read_net: function(delay, rfd, task, task_cls) { + console.debug("add_read_net(", delay, rfd, task, task_cls, ")"); + if (!(rfd in SOCKETS)) { + console.error("socket is not connected?"); + return 0; + } + var socket = SOCKETS[rfd]; + if ("task" in socket) { + console.error("socket already has a read handler"); + } + var id = setTimeout(function() { + if (SOCKETS.listening == rfd) { + if (0 == SOCKETS.incoming.length) { + return; + } + } else if (0 == socket.queue.length) { + return; + } + delete SCHEDULER_TASKS[id]; + delete socket["task"]; + Runtime.dynCall('vi', task, [task_cls]); + }, 0); + SCHEDULER_TASKS[id] = { + cls: task_cls, + socket: rfd, + }; + socket["handler"] = task; + socket["cls"] = task_cls; + socket["task"] = id; + console.debug("read task is", id); + return id; + }, + GNUNET_SCHEDULER_add_read_net_with_priority__deps: [ + 'GNUNET_SCHEDULER_add_read_net' + ], + GNUNET_SCHEDULER_add_read_net_with_priority: function(delay, priroity, rfd, + task, task_cls) { + return _GNUNET_SCHEDULER_add_read_net(delay, rfd, task, task_cls); + }, + GNUNET_SCHEDULER_add_write_net__deps: ['$SOCKETS'], + GNUNET_SCHEDULER_add_write_net: function(delay, wfd, task, task_cls) { + console.debug("add_write_net(", delay, wfd, task, task_cls, ")"); + if (!(wfd in SOCKETS)) { + console.error("socket is not connected?"); + return 0; + } + // always writable + var id = setTimeout(function() { + delete SCHEDULER_TASKS[id]; + Runtime.dynCall('vi', task, [task_cls]); + }, 0); + SCHEDULER_TASKS[id] = {cls: task_cls}; + return id; + }, + GNUNET_SCHEDULER_run: function(task, task_cls) { + Runtime.dynCall('vi', task, [task_cls]); + throw 'SimulateInfiniteLoop'; + }, }); // vim: set expandtab ts=2 sw=2: diff --git a/gnunet-build/packages/gnunet/gnunet/files/server.js b/gnunet-build/packages/gnunet/gnunet/files/server.js deleted file mode 100644 index d8beef3..0000000 --- a/gnunet-build/packages/gnunet/gnunet/files/server.js +++ /dev/null @@ -1,212 +0,0 @@ -// server.js - server routines for gnunet-web services -// Copyright (C) 2013,2014 David Barksdale -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -mergeInto(LibraryManager.library, { - $SERVER: { - handlers: {}, - handlers_initialized: false, - connect_notify_list: [], - disconnect_notify_list: [], - connect_notify_queue: [], - clients: {}, - next_client: 1, - connect: function(port, client_name) { - console.debug('Got a connection from ' + client_name); - port.onmessage = SERVER.client_get_message; - port._name = SERVER.next_client++; - SERVER.clients[port._name] = { - port: port, - name: client_name, - ref_count: 0, - shtudown_now: false, - user_context: 0, - user_context_size: 0, - }; - if (!SERVER.handlers_initialized) { - console.debug('And I\'m queueing it for later'); - SERVER.connect_notify_queue.push(port._name); - return; - } - SERVER.connect_notify_list.map(function(notify) { - ccallFunc(Runtime.getFuncWrapper(notify.callback, 'vii'), 'void', - ['number', 'number'], - [notify.callback_cls, port._name]); - }); - }, - message_queue: [], - client_get_message: function(ev) { - try { - var size = ev.data[0] << 8 | ev.data[1]; - var type = ev.data[2] << 8 | ev.data[3]; - console.debug('Got message of type ' + type + ' size ' + size + ' from ' - + SERVER.clients[ev.target._name].name); - if (!SERVER.handlers_initialized) { - console.debug('And I\'m queueing it for later'); - SERVER.message_queue.push(ev); - return; - } - var handler = SERVER.handlers[type]; - if (typeof handler === 'undefined') { - console.debug("But I don't know what to do with it"); - } else { - if (handler.expected_size == 0 || handler.expected_size == size) { - ccallFunc(Runtime.getFuncWrapper(handler.callback, 'viii'), 'void', - ['number', 'number', 'array'], - [handler.callback_cls, ev.target._name, ev.data]); - } else { - console.debug("But I was expecting size " + handler.expected_size); - } - } - } catch (e) { - console.error("ReKt", e); - } - } - }, - GNUNET_SERVER_add_handlers__deps: ['$SERVER'], - GNUNET_SERVER_add_handlers: function(server, handlers) { - for (var i = 0; ; i += 12 /* sizeof GNUNET_SERVER_MessageHandler */) { - var callback = getValue(handlers + i, 'i32'); - var callback_cls = getValue(handlers + i + 4, 'i32'); - var type = getValue(handlers + i + 8, 'i16'); - var expected_size = getValue(handlers + i + 10, 'i16'); - if (callback === 0) - break; - //Module.print('Adding handler for message type: ' + type); - SERVER.handlers[type] = { - 'callback': callback, - 'callback_cls': callback_cls, - 'expected_size': expected_size - }; - } - setTimeout(function() { - SERVER.handlers_initialized = true; - var queue = SERVER.connect_notify_queue; - SERVER.connect_notify_queue = []; - console.debug('Processing ' + queue.length + ' queued connections'); - queue.forEach(function(client) { - SERVER.connect_notify_list.map(function(notify) { - ccallFunc(Runtime.getFuncWrapper(notify.callback, 'vii'), 'void', - ['number', 'number'], - [notify.callback_cls, client]); - }); - }); - queue = SERVER.message_queue; - SERVER.message_queue = []; - console.debug('Processing ' + queue.length + ' queued messages'); - queue.forEach(SERVER.client_get_message); - }, 0); - }, - GNUNET_SERVER_receive_done__deps: [ - '$SERVER', - 'GNUNET_SERVER_client_disconnect', - ], - GNUNET_SERVER_receive_done: function(client, success) { - var c = SERVER.clients[client]; - if (!success) { - if (c.ref_count > 0) - c.shutdown_now = true; - else - _GNUNET_SERVER_client_disconnect(client); - return; - } - if (c.shutdown_now) - _GNUNET_SERVER_client_disconnect(client); - }, - GNUNET_SERVER_client_keep__deps: ['$SERVER'], - GNUNET_SERVER_client_keep: function(client) { - SERVER.clients[client].ref_count++; - }, - GNUNET_SERVER_client_drop__deps: [ - '$SERVER', - 'GNUNET_SERVER_client_disconnect', - ], - GNUNET_SERVER_client_drop: function(client) { - var c = SERVER.clients[client]; - c.ref_count--; - if (c.ref_count == 0 && c.shutdown_now) - _GNUNET_SERVER_client_disconnect(client); - }, - GNUNET_SERVER_client_disconnect: function(client) { - console.error('GNUNET_SERVER_client_disconnect not implemented'); - }, - GNUNET_SERVER_notify_transmit_ready: function(client, size, timeout, callback, - callback_cls) { - setTimeout(function() { - console.debug('I want to send ' + size + ' bytes to client ' - + SERVER.clients[client].name); - var stack = Runtime.stackSave(); - var buffer = Runtime.stackAlloc(size); - var ret = Runtime.dynCall('iiii', callback, [callback_cls, size, buffer]); - var view = {{{ makeHEAPView('U8', 'buffer', 'buffer+ret') }}}; - console.debug('I\'m sending ' + size + ' bytes to client ' - + SERVER.clients[client].name); - // See http://code.google.com/p/chromium/issues/detail?id=169705 - if (ret > 0) - SERVER.clients[client].port.postMessage(new Uint8Array(view)); - Runtime.stackRestore(stack); - }, 0); - return 1; // opaque GNUNET_SERVER_TransmitHandle* - }, - GNUNET_SERVER_connect_notify__deps: ['$SERVER'], - GNUNET_SERVER_connect_notify: function(server, callback, callback_cls) { - SERVER.connect_notify_list.push({ - callback: callback, - callback_cls: callback_cls - }); - }, - GNUNET_SERVER_disconnect_notify__deps: ['$SERVER'], - GNUNET_SERVER_disconnect_notify: function(server, callback, callback_cls) { - SERVER.disconnect_notify_list.push({ - callback: callback, - callback_cls: callback_cls - }); - }, - GNUNET_SERVER_suspend: function(server) { - // TODO: We either need to fail client connections when the server is - // suspended or we could allow connections but queue messages and - // connection notifications for delivery when the server is resumed. - console.debug("SERVER_suspend called"); - }, - GNUNET_SERVER_resume: function(server) { - // TODO: see GNUNET_SERVER_suspend - console.debug("SERVER_resume called"); - }, - GNUNET_SERVER_client_mark_monitor: function(client) { - // Mark the client as a 'monitor' so we don't wait for it to disconnect - // when we are shutting down. - // Since we don't handle shutdown this is a noop for now. - }, - GNUNET_SERVER_client_get_user_context___deps: ['$SERVER'], - GNUNET_SERVER_client_get_user_context_: function(client, size) { - if (0 == SERVER.clients[client].user_context && - 0 == SERVER.clients[client].user_context_size) - return 0; - assert(size == SERVER.clients[client].user_context_size); - return SERVER.clients[client].user_context; - }, - GNUNET_SERVER_client_set_user_context___deps: ['$SERVER'], - GNUNET_SERVER_client_set_user_context_: function(client, ptr, size) { - if (0 == ptr) - size = 0; - SERVER.clients[client].user_context = ptr; - SERVER.clients[client].user_context_size = size; - }, - GNUNET_SERVER_disable_receive_done_warning: function(client) { - // We don't currently have a receive done warning - }, -}); - -// vim: set expandtab ts=2 sw=2: diff --git a/gnunet-build/packages/gnunet/gnunet/files/service.js b/gnunet-build/packages/gnunet/gnunet/files/service.js deleted file mode 100644 index b1a92bf..0000000 --- a/gnunet-build/packages/gnunet/gnunet/files/service.js +++ /dev/null @@ -1,31 +0,0 @@ -// service.js - service routines for gnunet-web services -// Copyright (C) 2013,2014 David Barksdale -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -mergeInto(LibraryManager.library, { - GNUNET_SERVICE_run__deps: ['GNUNET_log_setup'], - GNUNET_SERVICE_run: function(argc, argv, service_name, options, task, - task_cls) { - ccall('GNUNET_log_setup', 'void', - ['number', 'string', 'number'], - [service_name, 'DEBUG', 0]); - var server = 1; // opaque non-null pointer - var cfg = 2; // same - Runtime.dynCall('viii', task, [task_cls, server, cfg]); - throw 'SimulateInfiniteLoop'; - } -}); - -// vim: set expandtab ts=2 sw=2: -- cgit v1.2.3-18-g5258