From 9f20815138f1971ede2a5515f9c5cb913dd6e2ca Mon Sep 17 00:00:00 2001 From: Kuntal Sampat Date: Mon, 20 Mar 2023 22:43:46 -0700 Subject: [PATCH 1/2] Added a new example that seamlessly works across 2 different machines. --- README.md | 4 ++++ test/listen.js | 38 ++++++++++++++++++++++++++++++++++++++ test/talk.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 test/listen.js create mode 100644 test/talk.js diff --git a/README.md b/README.md index 7c1ec3b..89e2065 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ var App = SecretStack({ appKey: '1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=' } var app = App(config) ``` +Added talk.js and listen.js that can run on 2 different machines. +Usage: node listen.js +Then copy the key it prints and the host IP on which you ran listen.js and put it in talk.js +Usage: node talk.js For documentation on plugins, see [PLUGINS.md](./PLUGINS.md). diff --git a/test/listen.js b/test/listen.js new file mode 100644 index 0000000..6630a57 --- /dev/null +++ b/test/listen.js @@ -0,0 +1,38 @@ +// On one server use: node listen.js +// On another server use: node talk.js +var crypto = require('crypto') +var SecretStack = require('../lib') +var seeds = require('./seeds') + +// deterministic keys make testing easy. +function hash (s) { + return crypto.createHash('sha256').update(s).digest() +} + +var appkey = hash('test_key') + +var create = SecretStack({ + appKey: appkey +}).use({ + manifest: { + hello: 'sync' + }, + permissions: { + anonymous: { allow: ['hello'], deny: null } + }, + init: function (api) { + return { + hello: function (name) { + return 'Hello, ' + name + '.' + } + } + } +}) + +var bob = create({ seed: seeds.bob }) + bob.on('rpc:connect', function (rpc, isClient) { + console.log(rpc.stream.address.substr(0, 4)) + console.log(rpc.stream.address.length) + }) + +console.log(bob.address()) diff --git a/test/talk.js b/test/talk.js new file mode 100644 index 0000000..7f0be07 --- /dev/null +++ b/test/talk.js @@ -0,0 +1,34 @@ +// First start the server usign node talk.js +// Note the computer's IP address and port and change the alice.connect +// comman accordingly +var Illuminati = require('../') +var crypto = require('crypto') +var seeds = require('./seeds') + +//deterministic keys make testing easy. +function hash (s) { + return crypto.createHash('sha256').update(s).digest() +} + +var appkey = hash('test_key') + +var create = Illuminati({ + appKey: appkey, +}).use({ + manifest: { + hello: 'sync' + }, + permissions: { + anonymous: { allow: ['hello'], deny: null } + }, + init: function (api) { + return { + hello: function (name) { + return 'Hello, ' + name + '.' + } + } + } +}) + +var alice = create({ seed: seeds.alice }) +alice.connect("net:10.0.1.52:57691~shs:bob3PzV+FJy8Xs6TtRBbWPhnOi53Brp7A+AG66XsJCY=", function (){}) From 26160e7c6ef9d61a95a4d5912b5e5189824db3f1 Mon Sep 17 00:00:00 2001 From: nuttwork <65258999+nuttwork@users.noreply.github.com> Date: Tue, 18 Apr 2023 22:26:22 -0700 Subject: [PATCH 2/2] Update README.md Changed markdown per suggestion from ahdinosaur. --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 89e2065..7559aa3 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,7 @@ var App = SecretStack({ appKey: '1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=' } var app = App(config) ``` -Added talk.js and listen.js that can run on 2 different machines. -Usage: node listen.js -Then copy the key it prints and the host IP on which you ran listen.js and put it in talk.js -Usage: node talk.js +See also: [`talk.js`](./examples/talk.js) and [`listen.js`](./examples/listen.js) For documentation on plugins, see [PLUGINS.md](./PLUGINS.md).