aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2016-09-18 21:12:29 -0500
committerDavid Barksdale <amatus@amatus.name>2016-09-18 21:12:29 -0500
commit7330ec3826151566cfd53800db54cd851a8640a6 (patch)
tree77d214a659d745b0e6308eae9f1d0935bd9aef75
parentf61ba18c1ec18c7c309068ebed1ee3fd873dab60 (diff)
Removing inline js from transport plugin
-rw-r--r--gnunet-build/packages/gnunet/gnunet/Buildrules1
-rw-r--r--gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten.c98
-rw-r--r--gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten_int.js85
3 files changed, 98 insertions, 86 deletions
diff --git a/gnunet-build/packages/gnunet/gnunet/Buildrules b/gnunet-build/packages/gnunet/gnunet/Buildrules
index b941bc7..85ce437 100644
--- a/gnunet-build/packages/gnunet/gnunet/Buildrules
+++ b/gnunet-build/packages/gnunet/gnunet/Buildrules
@@ -215,6 +215,7 @@ pkg_compile() {
--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" \
"${S}/src/transport/.libs/gnunet-service-transport.js.mem" \
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 1d8d671..800b1d2 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
@@ -48,7 +48,6 @@
#include "gnunet_protocols.h"
#include "gnunet_transport_plugin.h"
#include "plugin_transport_http_common.h"
-#include <emscripten.h>
#define LOG(kind,...) GNUNET_log_from(kind, PLUGIN_NAME, __VA_ARGS__)
@@ -276,6 +275,7 @@ notify_session_monitor (struct HTTP_Client_Plugin *plugin,
static void
client_delete_session (struct GNUNET_ATS_Session *s)
{
+ extern void abort_xhr(double xhr);
struct HTTP_Client_Plugin *plugin = s->plugin;
if (NULL != s->timeout_task)
@@ -296,10 +296,7 @@ client_delete_session (struct GNUNET_ATS_Session *s)
GNUNET_i2s (&s->address->peer));
GNUNET_assert (plugin->cur_connections > 0);
plugin->cur_connections--;
- EM_ASM_INT({
- Module.print('Aborting xhr: ' + $0);
- xhrs[$0].abort();
- }, s->get);
+ abort_xhr(s->get);
s->get = 0;
}
GNUNET_STATISTICS_set (plugin->env->stats,
@@ -370,41 +367,15 @@ http_client_plugin_send (void *cls,
GNUNET_TRANSPORT_TransmitContinuation cont,
void *cont_cls)
{
+ extern void http_client_plugin_send_int(void *url, void *data,
+ double data_size, void *cont, void *cont_cls, void *target);
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p: Sending message with %u to peer `%s' \n",
s,
msgbuf_size, GNUNET_i2s (&s->address->peer));
-
- EM_ASM_INT({
- var url = Pointer_stringify($0);
- var data = HEAP8.subarray($1, $1 + $2);
- var data_size = $2;
- var cont = $3;
- var cont_cls = $4;
- var target = $5;
- var xhr = new XMLHttpRequest();
- xhr.open('PUT', url);
- xhr.send(data);
- xhr.onload = function(e) {
- Module.print('put onload readyState ' + xhr.readyState + ' status ' + xhr.status);
- if (cont) {
- Runtime.dynCall('viiiii', cont, [cont_cls, target, 1, data_size, data_size]);
- }
- };
- xhr.onerror = function(e) {
- Module.print('put onerror readyState ' + xhr.readyState + ' status ' + xhr.status);
- if (cont) {
- Runtime.dynCall('viiiii', cont, [cont_cls, target, -1, data_size, data_size]);
- }
- };
- },
- s->url, // $0
- msgbuf, // $1
- msgbuf_size, // $2
- cont, // $3
- cont_cls, // $4
- &s->address->peer // $5
- );
+ http_client_plugin_send_int(s->url, msgbuf, msgbuf_size, cont, cont_cls,
+ &s->address->peer);
return msgbuf_size;
}
@@ -669,59 +640,14 @@ int next_xhr = 1;
static int
client_connect_get (struct GNUNET_ATS_Session *s)
{
+ extern void client_connect_get_int(double get, void *s, void *url,
+ void *client_receive, void *session_disconnect, void *plugin);
+
/* create get connection */
s->get = next_xhr++;
s->plugin->cur_connections++;
- EM_ASM_INT({
- var s = $1;
- var url = Pointer_stringify($2);
- var client_receive = $3;
- var http_client_plugin_session_disconnect = $4;
- var plugin = $5;
- Module.print('Creating new get xhr: ' + $0);
- var xhr = new XMLHttpRequest();
- xhrs[$0] = xhr;
- xhr.responseType = 'arraybuffer';
- xhr.resend = function() {
- xhr.open('GET', url + ',1');
- xhr.send();
- };
- xhr.onreadystatechange = function() {
- Module.print('xhr' + $0 + ' readyState ' + xhr.readyState +
- ' status ' + xhr.status + ':' + xhr.statusText);
- };
- xhr.onload = function(e) {
- var response = new Uint8Array(e.target.response);
- Module.print('xhr' + $0 + ' got ' + response.length + ' bytes');
- ccallFunc(Runtime.getFuncWrapper(client_receive, 'iiiii'), 'number',
- ['array', 'number', 'number', 'number'],
- [response, response.length, 1, s]);
- xhr.resend();
- };
- xhr.onerror = function(e) {
- Module.print('xhr' + $0 + ' status:'
- + xhr.status + ':' + xhr.statusText);
- ccallFunc(Runtime.getFuncWrapper(http_client_plugin_session_disconnect, 'iii'),
- 'number',
- ['number', 'number'],
- [plugin, s]);
- };
- xhr.onabort = function() {
- Module.print('xhr' + $0 + ' aborted');
- };
- xhr.ontimeout = function() {
- Module.print('xhr' + $0 + ' timedout');
- xhr.resend();
- };
- xhr.resend();
- },
- s->get, // $0
- s, // $1
- s->url, // $2
- &client_receive, // $3
- &http_client_plugin_session_disconnect, // $4
- s->plugin // $5
- );
+ client_connect_get_int(s->get, s, s->url, &client_receive,
+ &http_client_plugin_session_disconnect, s->plugin);
return GNUNET_OK;
}
diff --git a/gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten_int.js b/gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten_int.js
new file mode 100644
index 0000000..3821a52
--- /dev/null
+++ b/gnunet-build/packages/gnunet/gnunet/files/plugin_transport_http_client_emscripten_int.js
@@ -0,0 +1,85 @@
+// plugin_transport_http_client_emscripten_int.js - js for transport plugin
+// Copyright (C) 2016 David Barksdale <amatus@amat.us>
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+mergeInto(LibraryManager.library, {
+ abort_xhr: function(xhr) {
+ Module.print('Aborting xhr: ' + xhr);
+ xhrs[xhr].abort();
+ },
+ http_client_plugin_send_int: function(url_pointer, data_pointer, data_size,
+ cont, cont_cls, target) {
+ var url = Pointer_stringify(url_pointer);
+ var data = HEAP8.subarray(data_pointer, data_pointer + data_size);
+ var xhr = new XMLHttpRequest();
+ xhr.open('PUT', url);
+ xhr.send(data);
+ xhr.onload = function(e) {
+ Module.print('put onload readyState ' + xhr.readyState + ' status ' + xhr.status);
+ if (cont) {
+ Runtime.dynCall('viiiii', cont, [cont_cls, target, 1, data_size, data_size]);
+ }
+ };
+ xhr.onerror = function(e) {
+ Module.print('put onerror readyState ' + xhr.readyState + ' status ' + xhr.status);
+ if (cont) {
+ Runtime.dynCall('viiiii', cont, [cont_cls, target, -1, data_size, data_size]);
+ }
+ };
+ },
+ client_connect_get_int: function(get, s, url_pointer, client_receive,
+ session_disconnect, plugin) {
+ var url = Pointer_stringify(url_pointer);
+ Module.print('Creating new get xhr: ' + get);
+ var xhr = new XMLHttpRequest();
+ xhrs[get] = xhr;
+ xhr.responseType = 'arraybuffer';
+ xhr.resend = function() {
+ xhr.open('GET', url + ',1');
+ xhr.send();
+ };
+ xhr.onreadystatechange = function() {
+ Module.print('xhr' + get + ' readyState ' + xhr.readyState +
+ ' status ' + xhr.status + ':' + xhr.statusText);
+ };
+ xhr.onload = function(e) {
+ var response = new Uint8Array(e.target.response);
+ Module.print('xhr' + get + ' got ' + response.length + ' bytes');
+ ccallFunc(Runtime.getFuncWrapper(client_receive, 'iiiii'), 'number',
+ ['array', 'number', 'number', 'number'],
+ [response, response.length, 1, s]);
+ xhr.resend();
+ };
+ xhr.onerror = function(e) {
+ Module.print('xhr' + get + ' status:'
+ + xhr.status + ':' + xhr.statusText);
+ ccallFunc(
+ Runtime.getFuncWrapper(session_disconnect, 'iii'),
+ 'number',
+ ['number', 'number'],
+ [plugin, s]);
+ };
+ xhr.onabort = function() {
+ Module.print('xhr' + get + ' aborted');
+ };
+ xhr.ontimeout = function() {
+ Module.print('xhr' + get + ' timedout');
+ xhr.resend();
+ };
+ xhr.resend();
+ }
+});
+
+// vim: set expandtab ts=2 sw=2: