Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the changes with the interfacing with Jay #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

VALID_TOOLCHAINS := pnacl newlib glibc clang-newlib mac

NACL_SDK_ROOT ?= $(abspath $(CURDIR))
NACL_SDK_ROOT ?= /home/alex/Downloads/nacl_sdk/pepper_44

TARGET = SuperNET_API

Expand All @@ -22,6 +22,8 @@ CHROME_ARGS += --allow-nacl-socket-api=localhost
DEPS = nacl_io
LIBS = jl777 pangea nanomsg crypto777 ccoin curl ssl crypto z pthread ppapi nacl_io
PLIBS = nanoagent curl pthread ppapi nacl_io
PNACL_LDFLAGS := -L./lib/pnacl/Release


CFLAGS = -Wall -D__PNACL -fno-strict-aliasing -Ipicocoin/include

Expand Down
12 changes: 0 additions & 12 deletions Release/SuperNET_API.nmf

This file was deleted.

2 changes: 1 addition & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function createWindow(url) {
chrome.app.window.create(url, {
width: 1024,
height: 800,
frame: 'none'
frame: 'window'
});
}

Expand Down
30 changes: 20 additions & 10 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,51 +328,59 @@ var common = (function() {
return true;
}

function retmsg(msg)
function retmsg(msg, cb)
{
common.naclModule.postMessage(msg);
console.log("sent: "+msg);
console.log(cb);
postCall("js", msg, cb, function() {
// nothing
});
console.log("sent: "+msg+" "+cb);
}

function handleMessage(message_event)
{
if(isJson(message_event.data))
{
console.log("AAAA");
var request = JSON.parse(message_event.data);
var cb = request.pointer;
console.log(request);
if(request.method == "NxtAPI")
{
console.log(request.requestType);
if(request.params == undefined) request.params = "{}";
Jay.request(request.requestType, JSON.parse(request.params), function(ans) {
retmsg(ans);
retmsg(ans, cb);
})
}
else if(request.method == "status")
{
retmsg("{'status':'doing alright'}");
retmsg("{'status':'doing alright'}", cb);
}
else if(request.method == "signBytes")
{
var out = converters.byteArrayToHexString(signBytes(converters.hexStringToByteArray(request.bytes), request.secretPhrase));
var ret = {};
ret.signature = out;
retmsg(JSON.stringify(ret));
retmsg(JSON.stringify(ret), cb);
}
else if(request.method == "createToken")
{
var out = createToken(request.data, request.secretPhrase);
var ret = {};
ret.token = out;
retmsg(JSON.stringify(ret));
retmsg(JSON.stringify(ret), cb);
}
else if(request.method == "parseToken")
{
var out = parseToken(request.token, request.data);
retmsg(JSON.stringify(out));
retmsg(JSON.stringify(out), cb);
}
console.log(request);
else
{
retmsg('{"error":"method not found"}', cb);
}
}


if (typeof message_event.data === 'string') {
for (var type in defaultMessageTypes) {
Expand Down Expand Up @@ -464,6 +472,8 @@ var common = (function() {
hideModule: hideModule,
removeModule: removeModule,
logMessage: logMessage,
postMessage: postMessage,
handleMessage: handleMessage,
updateStatus: updateStatus
};

Expand Down
1 change: 1 addition & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ function close(e) {
var funcToCallback = {};

function postCall(func) {

var callback = arguments[arguments.length - 1];
funcToCallback[func] = callback;

Expand Down
17 changes: 17 additions & 0 deletions handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,20 @@ int HandleSuperNET(struct PP_Var params,struct PP_Var *output,const char **out_e
RESPONSE_STRING(retstr);
return 0;
}

int HandleJS(struct PP_Var params, struct PP_Var* output, const char** out_error) {
PostMessage("JS?");
CHECK_PARAM_COUNT(js, 2);
PARAM_STRING(0, jsonstr);
PARAM_STRING(1, ptr);

int64_t nptr = strtoll(ptr, NULL, 10);

char * addr = (char *)nptr;

strcpy(addr, jsonstr);

CREATE_RESPONSE(js);
RESPONSE_STRING(ptr);
return 0;
}
1 change: 1 addition & 0 deletions handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ int HandleConnect(struct PP_Var params, struct PP_Var* out, const char** error);
int HandleSend(struct PP_Var params, struct PP_Var* out, const char** error);
int HandleRecv(struct PP_Var params, struct PP_Var* out, const char** error);
int HandleClose(struct PP_Var params, struct PP_Var* out, const char** error);
int HandleJS(struct PP_Var params, struct PP_Var* out, const char** error);

#endif /* HANDLERS_H_ */
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ <h5 style="margin-top:0px;">
<div id="listener"></div>
</div>
</div>

<script src="js/jay.min.js"></script>
<script src="js/jay.ext.js"></script>

<script type="text/javascript" src="js/util.js"></script>

Expand All @@ -705,8 +706,7 @@ <h5 style="margin-top:0px;">
<script src="js/methods.js" type="text/javascript" charset="utf-8"></script>
<script src="js/sites.js" type="text/javascript" charset="utf-8"></script>
<script src="js/settings.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jay.min.js"></script>
<script src="js/jay.ext.js"></script>


</body>
</html>
6 changes: 0 additions & 6 deletions js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
else SPNAPI.submitRequest();
});

$(".submit_api_request").on("click", function () {

SPNAPI.submitRequest();

});

$(".clear-response").on("click", function () {

$(".hljs").html("JSON response");
Expand Down
49 changes: 49 additions & 0 deletions js/jay.min.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,3 @@ var SPNAPI = (function(SPNAPI, $, undefined) {

return SPNAPI;
}(SPNAPI || {}, jQuery));


1 change: 1 addition & 0 deletions js/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
$(".json_submit_url").html("");
$(".api_formfill").html("");
$(".api-panel-title").html("Panel Title");
SPNAPI.page = page;

$('.navigation[data-page=' + page + ']').addClass('active');

Expand Down
Binary file added libjl777.a
Binary file not shown.
2 changes: 0 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"scripts": ["background.js"]
}
},
{
"name": "My Sockets app",
"sockets": {
"tcp": { "connect": "" },
"tcpServer": { "listen": ":*" }
Expand Down
13 changes: 13 additions & 0 deletions nacl_io_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static FuncNameMapping g_function_map[] = {
{"send", HandleSend},
{"recv", HandleRecv},
{"close", HandleClose},
{"js", HandleJS},
{NULL, NULL},
};

Expand Down Expand Up @@ -683,6 +684,18 @@ void msleep(uint32_t milliseconds);
void *SuperNET(void *threads)
{
static const char *argv[2] = { "127.0.0.1" }; // int32_t sock2;


// the code to reqeust from js...
/*char * dest=malloc(100);
strcpy(dest, "\0");
PostMessage("{\"pointer\":\"%u\",\"method\":\"NxtAPI\",\"requestType\":\"getTime\",\"param\":\"{}\"}",dest);
while(dest[0] == '\0')
{
msleep(100);
}
PostMessage("Response: %s", dest);*/

SuperNET_init(1,argv);
while ( 1 )
{
Expand Down
1 change: 1 addition & 0 deletions newlib/Debug/dir.stamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Directory Stamp
36 changes: 36 additions & 0 deletions newlib/Debug/handlers_x86_32.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Updated by fix_deps.py
newlib/Debug/handlers_x86_32.o: handlers.c handlers.h \
include/ppapi/c/pp_var.h include/ppapi/c/pp_bool.h \
include/ppapi/c/pp_macros.h include/ppapi/c/pp_stdint.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/arpa/inet.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/netdb.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/netinet/in.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/netinet6/in6.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/sys/socket.h \
include/nacl_io/osdirent.h include/nacl_io/osinttypes.h nacl_io_demo.h \
include/ppapi/c/pp_instance.h include/ppapi/c/ppb_var.h \
include/ppapi/c/pp_module.h include/ppapi/c/pp_resource.h \
include/ppapi/c/pp_var.h include/ppapi/c/ppb_var_array.h \
include/ppapi/c/ppb_var_dictionary.h include/sdk_util/macros.h
handlers.c:
handlers.h:
include/ppapi/c/pp_var.h:
include/ppapi/c/pp_bool.h:
include/ppapi/c/pp_macros.h:
include/ppapi/c/pp_stdint.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/arpa/inet.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/netdb.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/netinet/in.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/netinet6/in6.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/newlib/sys/socket.h:
include/nacl_io/osdirent.h:
include/nacl_io/osinttypes.h:
nacl_io_demo.h:
include/ppapi/c/pp_instance.h:
include/ppapi/c/ppb_var.h:
include/ppapi/c/pp_module.h:
include/ppapi/c/pp_resource.h:
include/ppapi/c/pp_var.h:
include/ppapi/c/ppb_var_array.h:
include/ppapi/c/ppb_var_dictionary.h:
include/sdk_util/macros.h:
Binary file added newlib/Debug/handlers_x86_32.o
Binary file not shown.
1 change: 1 addition & 0 deletions newlib/Debug/nacl_io.stamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TOUCHED /home/alex/Downloads/nacl_sdk/pepper_44/examples/demo/nacl_io_demo/newlib/Debug/nacl_io.stamp
1 change: 1 addition & 0 deletions newlib/Debug/nanosrc/core/dir.stamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Directory Stamp
Empty file.
87 changes: 87 additions & 0 deletions pnacl/Debug/SuperNET.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Updated by fix_deps.py
pnacl/Debug/SuperNET.o: SuperNET.c plugins/includes/portable777.h \
plugins/includes/../../nanosrc/utils/mutex.h \
plugins/includes/../../nanosrc/nn.h \
plugins/includes/../../nanosrc/nn_config.h \
plugins/includes/../../nanosrc/pubsub.h \
plugins/includes/../../nanosrc/pipeline.h \
plugins/includes/../../nanosrc/survey.h \
plugins/includes/../../nanosrc/reqrep.h \
plugins/includes/../../nanosrc/bus.h \
plugins/includes/../../nanosrc/pair.h plugins/includes/sha256.h \
plugins/includes/cJSON.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/pnacl/memory.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/pnacl/sys/time.h \
plugins/includes/uthash.h plugins/includes/curve25519.h \
plugins/includes/InstantDEX_quote.h plugins/utils/utils777.c \
plugins/utils/bits777.c plugins/utils/../common/system777.c \
plugins/utils/../common/../utils/utils777.c \
plugins/utils/../common/../utils/inet.c \
plugins/utils/../includes/nonportable.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/pnacl/sys/select.h \
/home/alex/Downloads/nacl_sdk/pepper_44/include/pnacl/arpa/inet.h \
plugins/utils/../common/../includes/utlist.h plugins/utils/files777.c \
plugins/KV/kv777.c plugins/KV/../utils/NXT777.c \
plugins/utils/../utils/bits777.c plugins/utils/../utils/utils777.c \
plugins/utils/../coins/coins777.c \
plugins/utils/../coins/../utils/huffstream.c \
plugins/utils/../coins/../common/system777.c \
plugins/utils/../coins/../KV/kv777.c \
plugins/utils/../coins/../utils/files777.c \
plugins/utils/../coins/../utils/utils777.c \
plugins/utils/../coins/../utils/bits777.c \
plugins/utils/../coins/gen1.c plugins/utils/../coins/cointx.c \
plugins/utils/../includes/tweetnacl.h plugins/KV/../utils/files777.c \
plugins/KV/../common/system777.c plugins/common/system777.c \
plugins/agents/plugins.h \
plugins/agents/../nonportable/Linux/nonportable.h \
plugins/agents/transport.h plugins/agents/../common/system777.c
SuperNET.c:
plugins/includes/portable777.h:
plugins/includes/../../nanosrc/utils/mutex.h:
plugins/includes/../../nanosrc/nn.h:
plugins/includes/../../nanosrc/nn_config.h:
plugins/includes/../../nanosrc/pubsub.h:
plugins/includes/../../nanosrc/pipeline.h:
plugins/includes/../../nanosrc/survey.h:
plugins/includes/../../nanosrc/reqrep.h:
plugins/includes/../../nanosrc/bus.h:
plugins/includes/../../nanosrc/pair.h:
plugins/includes/sha256.h:
plugins/includes/cJSON.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/pnacl/memory.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/pnacl/sys/time.h:
plugins/includes/uthash.h:
plugins/includes/curve25519.h:
plugins/includes/InstantDEX_quote.h:
plugins/utils/utils777.c:
plugins/utils/bits777.c:
plugins/utils/../common/system777.c:
plugins/utils/../common/../utils/utils777.c:
plugins/utils/../common/../utils/inet.c:
plugins/utils/../includes/nonportable.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/pnacl/sys/select.h:
/home/alex/Downloads/nacl_sdk/pepper_44/include/pnacl/arpa/inet.h:
plugins/utils/../common/../includes/utlist.h:
plugins/utils/files777.c:
plugins/KV/kv777.c:
plugins/KV/../utils/NXT777.c:
plugins/utils/../utils/bits777.c:
plugins/utils/../utils/utils777.c:
plugins/utils/../coins/coins777.c:
plugins/utils/../coins/../utils/huffstream.c:
plugins/utils/../coins/../common/system777.c:
plugins/utils/../coins/../KV/kv777.c:
plugins/utils/../coins/../utils/files777.c:
plugins/utils/../coins/../utils/utils777.c:
plugins/utils/../coins/../utils/bits777.c:
plugins/utils/../coins/gen1.c:
plugins/utils/../coins/cointx.c:
plugins/utils/../includes/tweetnacl.h:
plugins/KV/../utils/files777.c:
plugins/KV/../common/system777.c:
plugins/common/system777.c:
plugins/agents/plugins.h:
plugins/agents/../nonportable/Linux/nonportable.h:
plugins/agents/transport.h:
plugins/agents/../common/system777.c:
Binary file added pnacl/Debug/SuperNET.o
Binary file not shown.
1 change: 1 addition & 0 deletions pnacl/Debug/dir.stamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Directory Stamp
Loading