mirror of https://codeberg.org/pzp/pzp-hub.git
add secret-stack, shse, ppppp-keypair
This commit is contained in:
parent
aa09550c75
commit
c5085c64cf
|
@ -1,4 +1,5 @@
|
||||||
node_modules
|
node_modules
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
yarn.lock
|
yarn.lock
|
||||||
TODO
|
TODO
|
||||||
|
keypair
|
|
@ -1,9 +1,9 @@
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
import { unified } from 'unified'
|
import { unified } from 'unified'
|
||||||
import remarkParse from 'remark-parse'
|
import remarkParse from 'remark-parse'
|
||||||
import remarkRehype from 'remark-rehype'
|
import remarkRehype from 'remark-rehype'
|
||||||
import rehypeStringify from 'rehype-stringify'
|
import rehypeStringify from 'rehype-stringify'
|
||||||
import fs from 'fs'
|
|
||||||
import path from 'path'
|
|
||||||
|
|
||||||
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
||||||
const homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md')
|
const homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md')
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { createRequire } from 'module'
|
import { createRequire } from 'node:module'
|
||||||
import path from 'path'
|
import path from 'node:path'
|
||||||
import homepageHTML from './homepage.js'
|
import homepageHTML from './homepage.js'
|
||||||
|
|
||||||
const require = createRequire(import.meta.url)
|
const require = createRequire(import.meta.url)
|
||||||
|
|
13
lib/peer.cjs
13
lib/peer.cjs
|
@ -1,11 +1,18 @@
|
||||||
const SecretStack = require('secret-stack')
|
const Keypair = require('ppppp-keypair')
|
||||||
const caps = require('ssb-caps')
|
const SSAPI = require('secret-stack/lib/api')
|
||||||
|
|
||||||
module.exports = function startPeer() {
|
module.exports = function startPeer() {
|
||||||
SecretStack({ appKey: caps.shs })
|
const keypair = Keypair.loadOrCreateSync('./keypair')
|
||||||
|
|
||||||
|
SSAPI([], {})
|
||||||
|
.use(require('secret-stack/lib/core'))
|
||||||
|
.use(require('secret-stack/lib/plugins/net'))
|
||||||
|
.use(require('secret-handshake-ext/secret-stack'))
|
||||||
.use(require('ssb-conn'))
|
.use(require('ssb-conn'))
|
||||||
.use(require('./plugin-hub.cjs'))
|
.use(require('./plugin-hub.cjs'))
|
||||||
.call(null, {
|
.call(null, {
|
||||||
|
caps: { shse: 'p2pLq5VZKvNWaaafMUEcxH9BKm2WjNBCxsc8TRQV5gS' },
|
||||||
|
keypair,
|
||||||
port: 8008,
|
port: 8008,
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
conn: {
|
conn: {
|
||||||
|
|
|
@ -19,14 +19,14 @@ module.exports = {
|
||||||
name: 'hub',
|
name: 'hub',
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
manifest: {
|
manifest: {
|
||||||
connect: 'duplex',
|
createTunnel: 'duplex',
|
||||||
ping: 'sync',
|
ping: 'sync',
|
||||||
attendants: 'source',
|
attendants: 'source',
|
||||||
createToken: 'async',
|
createToken: 'async',
|
||||||
},
|
},
|
||||||
permissions: {
|
permissions: {
|
||||||
anonymous: {
|
anonymous: {
|
||||||
allow: ['connect', 'ping', 'attendants', 'createToken'],
|
allow: ['createTunnel', 'ping', 'attendants', 'createToken'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
init(me) {
|
init(me) {
|
||||||
|
@ -82,20 +82,15 @@ module.exports = {
|
||||||
return cat([initial, notifyAttendants.listen()])
|
return cat([initial, notifyAttendants.listen()])
|
||||||
},
|
},
|
||||||
|
|
||||||
connect(opts) {
|
createTunnel(target) {
|
||||||
if (!opts) return ErrorDuplex('opts MUST be provided')
|
|
||||||
|
|
||||||
const target = opts.target
|
|
||||||
if (attendants.has(target)) {
|
if (attendants.has(target)) {
|
||||||
debug(
|
// prettier-ignore
|
||||||
'received tunnel request for target %s from %s',
|
debug('received tunnel request for target %s from %s', target, this.id)
|
||||||
target,
|
const origin = this.id
|
||||||
this.id
|
return attendants.get(target).hubClient.connect(origin, () => {})
|
||||||
)
|
|
||||||
opts.origin = this.id
|
|
||||||
return attendants.get(target).tunnel.connect(opts, () => {})
|
|
||||||
} else {
|
} else {
|
||||||
return ErrorDuplex('Could not connect to: ' + target)
|
// prettier-ignore
|
||||||
|
return ErrorDuplex(`Cannot createTunnel with ${target} who appears to be offline`)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -29,11 +29,13 @@
|
||||||
"debug": "4.3.4",
|
"debug": "4.3.4",
|
||||||
"ejs": "3.1.9",
|
"ejs": "3.1.9",
|
||||||
"fastify": "4.17.0",
|
"fastify": "4.17.0",
|
||||||
|
"ppppp-keypair": "github:staltz/ppppp-keypair",
|
||||||
"pino": "8.14.1",
|
"pino": "8.14.1",
|
||||||
"pull-cat": "1.1.11",
|
"pull-cat": "1.1.11",
|
||||||
"pull-notify": "0.1.2",
|
"pull-notify": "0.1.2",
|
||||||
"pull-stream": "3.7.0",
|
"pull-stream": "3.7.0",
|
||||||
"secret-stack": "6.4.1",
|
"secret-stack": "6.4.1",
|
||||||
|
"secret-handshake-ext": "0.0.4",
|
||||||
"ssb-caps": "1.1.0",
|
"ssb-caps": "1.1.0",
|
||||||
"ssb-conn": "6.0.4",
|
"ssb-conn": "6.0.4",
|
||||||
"unified": "10.1.2",
|
"unified": "10.1.2",
|
||||||
|
@ -44,14 +46,12 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"c8": "7",
|
"c8": "7",
|
||||||
"prettier": "^2.6.2",
|
"prettier": "^2.6.2",
|
||||||
"pretty-quick": "^3.1.3",
|
"pretty-quick": "^3.1.3"
|
||||||
"tap-arc": "^0.3.5",
|
|
||||||
"tape": "^5.6.3"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"setup": "npm install --omit=dev",
|
"setup": "npm install --omit=dev",
|
||||||
"start": "DEBUG=*,-avvio node lib/index.js",
|
"start": "DEBUG=*,-avvio node lib/index.js",
|
||||||
"test": "tape test/*.js | tap-arc --bail",
|
"test": "node --test",
|
||||||
"format-code": "prettier --write \"(lib|test)/**/*.(c)?js\"",
|
"format-code": "prettier --write \"(lib|test)/**/*.(c)?js\"",
|
||||||
"format-code-staged": "pretty-quick --staged --pattern \"(lib|test)/**/*.(c)?js\"",
|
"format-code-staged": "pretty-quick --staged --pattern \"(lib|test)/**/*.(c)?js\"",
|
||||||
"coverage": "c8 --reporter=lcov npm run test"
|
"coverage": "c8 --reporter=lcov npm run test"
|
||||||
|
|
Loading…
Reference in New Issue