Skip to content

Commit ae00c47

Browse files
authored
Merge pull request #70 from datapartyjs/i2p-example
i2p example, secure config examle tweak, downgrade ncc
2 parents df56b72 + dc6d44e commit ae00c47

9 files changed

Lines changed: 309 additions & 48 deletions

File tree

examples/i2p-host.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const Path = require('path')
2+
const debug = require('debug')('example.i2p')
3+
const Dataparty = require('../src')
4+
const dataparty_crypto = require('@dataparty/crypto')
5+
6+
class ExampleService extends Dataparty.IService {
7+
constructor(opts){
8+
super(opts)
9+
10+
this.addMiddleware(Dataparty.middleware_paths.pre.decrypt)
11+
this.addMiddleware(Dataparty.middleware_paths.pre.validate)
12+
13+
this.addMiddleware(Dataparty.middleware_paths.post.validate)
14+
this.addMiddleware(Dataparty.middleware_paths.post.encrypt)
15+
16+
this.addEndpoint(Dataparty.endpoint_paths.echo)
17+
this.addEndpoint(Dataparty.endpoint_paths.secureecho)
18+
this.addEndpoint(Dataparty.endpoint_paths.identity)
19+
this.addEndpoint(Dataparty.endpoint_paths.version)
20+
21+
this.addSchema(Path.join(__dirname, './party/schema/basic_types.js'))
22+
}
23+
24+
}
25+
26+
async function main(){
27+
28+
29+
//const uri = 'mongodb://localhost:27017/server-party-test'
30+
//debug('db location', uri)
31+
32+
33+
const service = new ExampleService({ name: '@dataparty/example', version: '0.0.1' })
34+
const build = await service.compile(Path.join(__dirname,'/dataparty'), true)
35+
36+
const serviceName = build.package.name
37+
const basePath = '/data/dataparty/'
38+
const servicePath = Path.join(basePath, serviceName.replace('/','-'))
39+
40+
let config = new Dataparty.Config.JsonFileConfig({ basePath: servicePath })
41+
config.touchDir('/tingo')
42+
43+
const dbPath = Path.join(servicePath, '/tingo')
44+
45+
let party = new Dataparty.TingoParty({
46+
config,
47+
path: dbPath,
48+
model: build
49+
})
50+
51+
party.topics = new Dataparty.LocalTopicHost()
52+
53+
const live = new Dataparty.IService(build.package, build)
54+
55+
56+
const runner = new Dataparty.ServiceRunnerNode({
57+
party,
58+
service: live,
59+
sendFullErrors: false,
60+
useNative: false
61+
})
62+
63+
64+
65+
66+
const runnerRouter = new Dataparty.RunnerRouter(runner)
67+
68+
69+
const host = new Dataparty.ServiceHost({
70+
runner: runnerRouter,
71+
trust_proxy: true,
72+
wsEnabled: true,
73+
i2pEnabled: true,
74+
i2pSamHost: 'localhost',
75+
i2pSamPort: 7656
76+
})
77+
78+
debug(runner.party.identity)
79+
await party.start()
80+
await runnerRouter.start()
81+
await host.start()
82+
83+
console.log('started')
84+
}
85+
86+
87+
88+
main().catch(err=>{
89+
console.error(err)
90+
})

examples/secure-config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ async function main(){
1515

1616

1717
secureConfig = new Dataparty.Config.SecureConfig({
18-
config: jsonConfig
18+
config: jsonConfig,
19+
timeoutMs: 15*1000
1920
})
2021

2122

@@ -121,10 +122,9 @@ async function main(){
121122

122123
let timer = setTimeout(async ()=>{
123124

124-
125125
console.log('timer config', await secureConfig.readAll())
126126

127-
}, 30000)
127+
}, 1000*30)
128128

129129
}
130130

examples/test-service-node-host.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function main(){
3434
const build = await service.compile(Path.join(__dirname,'/dataparty'), true)
3535

3636
const serviceName = build.package.name
37-
const basePath = '/data/datparty/'
37+
const basePath = '/data/dataparty/'
3838
const servicePath = Path.join(basePath, serviceName.replace('/','-'))
3939

4040
let config = new Dataparty.Config.JsonFileConfig({ basePath: servicePath })
@@ -80,7 +80,7 @@ async function main(){
8080

8181
console.log('started')
8282

83-
process.exit()
83+
//process.exit()
8484
}
8585

8686

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@diva.exchange/i2p-sam": "^4.1.8",
6565
"@markwylde/liferaft": "^1.3.4",
6666
"@vercel/ncc": "^0.36.1",
67+
"@zeit/ncc": "^0.22.3",
6768
"ajv": "6.9.1",
6869
"axios": "^0.27.2",
6970
"bleno": "npm:@abandonware/bleno@^0.5.1-4",

src/config/json-file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class JsonFileConfig extends IConfig {
6868

6969
async write(key, value){
7070

71+
logger('writing path:', key)
7172
deepSet(this.content, key, value)
7273
await this.save()
7374
}

0 commit comments

Comments
 (0)