Skip to content

Commit

Permalink
Merge pull request #67 from Kos-M/master
Browse files Browse the repository at this point in the history
catch lib crash when call rpc without args closes #63
  • Loading branch information
chr15m committed Jan 26, 2023
2 parents 00b0c2d + 73c41d7 commit 62ddbc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function onMessage(bugout, identifier, wire, message) {
} else if (packet.y == "r") { // rpc call
debug("rpc", identifier, packet);
var call = packet.c.toString();
var argsstring = packet.a.toString();
var argsstring = packet["a"] ? packet.a.toString() : "null";
try {
var args = JSON.parse(argsstring);
} catch(e) {
Expand Down
25 changes: 25 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ test("RPC and message passing", function(t) {
});
});

test("RPC Call without passing any message/data", function(t) {
t.plan(5);

const bs = new Bugout({dht: false, tracker: false});
const bc = new Bugout(bs.address(), {dht: false, tracker: false});

bs.register("call_without_args", function(pk,args){
t.assert(args === null, 'args should be null, when called without args from another peer')
});
bs.register("call_with_args", function(pk,args){
t.assert(typeof args === 'object' , 'type of args should be an object')
t.assert( args.hasOwnProperty('hello'), 'args has correct message data props')
t.assert( args.hello === 'world', 'args has correct message data')
});
bc.on("server", function(address) {
t.equal(address,bs.address(), "server check client was rpc sender");
bc.rpc(bs.address(), 'call_without_args')
bc.rpc(bs.address(), 'call_with_args', { hello: 'world'})
});
// connect the two clients together
bs.torrent.on("infoHash", function() {
bs.torrent.addPeer("127.0.0.1:" + bc.wt.address().port);
});
});

test("3 party incomplete graph gossip test", function(t) {
t.plan(10);

Expand Down

0 comments on commit 62ddbc8

Please sign in to comment.