Skip to content
Draft
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
2 changes: 2 additions & 0 deletions examples/network/echo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ids/
aliases.json
15 changes: 9 additions & 6 deletions examples/network/echo/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
MKID=node $(TROUPE)/rt/built/p2p/mkid.js
MKALIASES=node $(TROUPE)/rt/built/p2p/mkaliases.js
START=$(TROUPE)/bin/network.sh
MKID=node $(TROUPE)/p2p-tools/built/mkid.mjs
MKALIASES=node $(TROUPE)/p2p-tools/built/mkaliases.js
START=$(TROUPE)/network.sh

echo-server:

$(START) echo-server.trp --id=ids/echo-server.json # --debug --debugp2p

echo-client:
$(START) echo-client.trp --id=ids/echo-client.json --aliases=aliases.json --debug --debugp2p
$(START) echo-client.trp --id=ids/echo-client.json --aliases=aliases.json # --debug --debugp2p

create-network-identifiers:
mkdir -p ids
mkdir -p ids
$(MKID) --outfile=ids/echo-server.json
$(MKID) --outfile=ids/echo-client.json
$(MKALIASES) --include ids/echo-server.json --include ids/echo-client.json --outfile aliases.json

remove-network-identifiers:
rm -rf ids
rm -f aliases.json
8 changes: 5 additions & 3 deletions examples/network/echo/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Echo example

1. *First-time only* Run `make create-network-identifiers`. This command will create two network identifiers in the local subdirectory `ids/`, and an alias file with the generated identifiers.
1. *First-time only* Run `make create-network-identifiers`. This command will
create two network identifiers in the local subdirectory `ids/`, and an alias
file with the generated identifiers.

2. Run the server by running `make echo-server`
3. Open another terminal window and run the client by command `make echo-client`
2. Run the server by running `make echo-server`

3. Open another terminal window and run the client by command `make echo-client`
1 change: 0 additions & 1 deletion examples/network/echo/aliases.json

This file was deleted.

6 changes: 6 additions & 0 deletions examples/network/pingpong/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
package-lock.json

ids/
aliases.json
trustmap.json
23 changes: 15 additions & 8 deletions examples/network/pingpong/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
MKID=node $(TROUPE)/rt/built/p2p/mkid.js
MKALIASES=node $(TROUPE)/rt/built/p2p/mkaliases.js
START=$(TROUPE)/bin/network.sh
MKID=node $(TROUPE)/p2p-tools/built/mkid.mjs
MKALIASES=node $(TROUPE)/p2p-tools/built/mkaliases.js
START=$(TROUPE)/network.sh

zero.listener:
$(START) zero.trp --id=ids/pingpong-listener.json --rspawn=true --aliases=aliases.json --debug --debugp2p
listener:
$(START) zero.trp --id=ids/pingpong-listener.json --aliases=aliases.json --rspawn=true --trustmap=trustmap.json # --debug --debugp2p

pingpong.dialer:
$(START) p2ppingpong.trp --id=ids/pingpong-dialer.json --aliases=aliases.json # --debug --debugp2p
dialer:
$(START) p2ppingpong.trp --id=ids/pingpong-dialer.json --aliases=aliases.json # --debug --debugp2p

create-network-identifiers:
mkdir -p ids
mkdir -p ids
$(MKID) --outfile=ids/pingpong-listener.json
$(MKID) --outfile=ids/pingpong-dialer.json
$(MKALIASES) --include ids/pingpong-listener.json --include ids/pingpong-dialer.json --outfile aliases.json
npm install
node mktrustmap.mjs --infile aliases.json --outfile trustmap.json

remove-network-identifiers:
rm -rf ids
rm -f aliases.json
rm -f trustmap.json
11 changes: 11 additions & 0 deletions examples/network/pingpong/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ping-Pong example

1. *First-time only* Run `make create-network-identifiers`. This command will
create two network identifiers in the local subdirectory `ids/`, and an alias
file with the generated identifiers.

2. Run the Job Listener node, i.e. whereto remotely spawn a `pingpong` instance,
by running the command `make listener`.

3. Open another terminal window and run the Job Dialer, which sets up the two
instances of `pingpong`, with command `make dialer`.
1 change: 0 additions & 1 deletion examples/network/pingpong/aliases.json

This file was deleted.

19 changes: 19 additions & 0 deletions examples/network/pingpong/mktrustmap.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

import * as fs from 'node:fs';
import pkg from 'yargs';
const { argv } = pkg;

(async () => {
let trustmap = [];
const aliases_json = JSON.parse(fs.readFileSync(argv.infile, 'utf-8').toString());
for (let alias_key in aliases_json) {
trustmap.push({
level: '#TOP',
id: aliases_json[alias_key]
});
}

const outfile = argv.outfile;
fs.writeFile(outfile, JSON.stringify(trustmap), x => console.log(x));
})();
14 changes: 14 additions & 0 deletions examples/network/pingpong/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "pingpong",
"version": "1.0.0",
"description": "",
"main": "mktrustmap.mjs",
"author": "",
"license": "ISC",
"dependencies": {
"yargs": "^15.3.1"
},
"devDependencies": {
"@types/yargs": "^15.0.4"
}
}