Skip to content

Commit e4f023e

Browse files
authored
Merge pull request #51 from datapartyjs/topic-host
local topic host
2 parents a091a6e + 04d5796 commit e4f023e

42 files changed

Lines changed: 861 additions & 138 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/test-peer-party.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ async function main(){
4242
await peer1.loadIdentity()
4343
await peer2.loadIdentity()
4444

45+
console.log('peer identity', peer1.identity)
46+
4547
//peer1.comms.remoteIdentity = peer2.identity
4648
peer2.comms.remoteIdentity = peer1.identity
4749

examples/test-service-node-host.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const Path = require('path')
22
const debug = require('debug')('test.server-db')
33
const Dataparty = require('../src')
4-
5-
const BouncerServerModels = require('@dataparty/bouncer-model')
6-
const BouncerClientModels = require('@dataparty/bouncer-model/dist/bouncer-model.json')
4+
const dataparty_crypto = require('@dataparty/crypto')
75

86
class ExampleService extends Dataparty.IService {
97
constructor(opts){
@@ -19,6 +17,8 @@ class ExampleService extends Dataparty.IService {
1917
this.addEndpoint(Dataparty.endpoint_paths.secureecho)
2018
this.addEndpoint(Dataparty.endpoint_paths.identity)
2119
this.addEndpoint(Dataparty.endpoint_paths.version)
20+
21+
this.addSchema(Path.join(__dirname, './party/schema/basic_types.js'))
2222
}
2323

2424
}
@@ -29,34 +29,53 @@ async function main(){
2929
//const uri = 'mongodb://localhost:27017/server-party-test'
3030
//debug('db location', uri)
3131

32-
const path = '/data/datparty/srv-party'
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/datparty/'
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')
3344

3445
let party = new Dataparty.TingoParty({
35-
path,
36-
model: BouncerClientModels,
37-
serverModels: BouncerServerModels,
38-
config: new Dataparty.Config.JsonFileConfig({basePath: '/data/datparty/'})
46+
config,
47+
path: dbPath,
48+
model: build
3949
})
4050

41-
const service = new ExampleService({ name: '@dataparty/example', version: '0.0.1' })
51+
party.topics = new Dataparty.LocalTopicHost()
4252

43-
const build = await service.compile(Path.join(__dirname,'/dataparty'), true)
44-
45-
debug('built', Object.keys(build))
53+
const live = new Dataparty.IService(build.package, build)
4654

55+
4756
const runner = new Dataparty.ServiceRunnerNode({
48-
party, service,
49-
sendFullErrors: false
57+
party,
58+
//prefix: 'foo',
59+
service: live,
60+
sendFullErrors: false,
61+
useNative: false
5062
})
63+
64+
65+
66+
67+
const runnerRouter = new Dataparty.RunnerRouter(runner)
68+
5169

5270
const host = new Dataparty.ServiceHost({
53-
runner,
71+
runner: runnerRouter,
5472
trust_proxy: true,
55-
wsEnabled: true
73+
wsEnabled: true,
5674
})
57-
75+
76+
debug(runner.party.identity)
5877
await party.start()
59-
await runner.start()
78+
await runnerRouter.start()
6079
await host.start()
6180

6281
console.log('started')

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"alias": {
1010
"events": "eventemitter3",
1111
"process": "process/browser.js",
12+
"path": "path-browserify",
1213
"assert": "assert",
1314
"crypto": "crypto-browserify"
1415
},
@@ -123,7 +124,9 @@
123124
"minami": "^1.2.3",
124125
"mongodb-client-encryption": "^2.2.1",
125126
"parcel": "^2.3.1",
127+
"path-browserify": "^1.0.1",
126128
"process": "^0.11.10",
129+
"punycode": "2.3.0",
127130
"querystring-es3": "^0.2.1",
128131
"stream-browserify": "^3.0.0",
129132
"stream-http": "^3.2.0",

public/example.html

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,106 @@
55
</script>
66
</head>
77

8+
<body>
9+
10+
11+
<script>
12+
13+
function makeid(length) {
14+
let result = '';
15+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
16+
const charactersLength = characters.length;
17+
let counter = 0;
18+
while (counter < length) {
19+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
20+
counter += 1;
21+
}
22+
return result;
23+
}
24+
25+
26+
async function init(){
27+
28+
config = new Dataparty.Config.MemoryConfig({
29+
basePath:'demo',
30+
cloud: {
31+
uri: 'http://172.16.3.1:4001'
32+
}
33+
})
34+
35+
/*config = new Dataparty.Config.LocalStorageConfig({
36+
basePath:'demo',
37+
cloud: {
38+
uri: 'http://172.16.3.1:4001'
39+
}
40+
})*/
41+
42+
43+
const remoteIdentity = await Dataparty.Comms.RestComms.HttpGet( config.read('cloud.uri') + '/identity')
44+
45+
console.log('cloud.uri -',config.read('cloud.uri'))
46+
console.log('\tremoteIdentity', remoteIdentity)
47+
48+
let party = new Dataparty.PeerParty({
49+
comms: new Dataparty.Comms.WebsocketComms({
50+
uri:'ws://172.16.3.1:4001/ws',
51+
discoverRemoteIdentity: false,
52+
remoteIdentity: remoteIdentity,
53+
session: Math.random().toString(36).slice(2)
54+
}),
55+
config: config
56+
})
57+
58+
window.party = party
59+
await party.start()
60+
61+
await party.comms.authorized()
62+
63+
64+
timeTopic = new party.ROSLIB.Topic({
65+
ros : party.comms.ros,
66+
name : '/time',
67+
messageType: 'number'
68+
})
69+
70+
timeTopic.subscribe((msg)=>{
71+
console.log(name, msg)
72+
})
73+
74+
75+
let text = makeid(500*1024)
76+
77+
let first = true
78+
79+
async function onTimeout(){
80+
81+
let num = first ? 2:1
82+
83+
first = false
84+
85+
let statusId = 'publish:'+timeTopic.name+':'+ (party.comms.ros.idCounter+num)
86+
87+
88+
party.comms.once(statusId,(status)=>{
89+
90+
setTimeout(onTimeout, 0)
91+
})
92+
93+
await timeTopic.publish({number: Date.now(), text:text})
94+
95+
96+
}
97+
98+
window.onTimeout = onTimeout
99+
100+
//onTimeout()
101+
}
102+
103+
init()
104+
105+
106+
</script>
107+
108+
</body>
109+
8110
</html>

src/bouncer/idb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = class IDb extends EventEmitter {
2424
for(const collectionName of this.factory.getValidators()){
2525
debug('creating collection', collectionName)
2626

27-
const indexSettings = reach(this.factory, 'model.IndexSettings.'+collectionName)
27+
const indexSettings = reach(this.factory, 'model.schemas.IndexSettings.'+collectionName)
2828
await this.createCollection(collectionName, indexSettings)
2929
}
3030
}

src/comms/host/host-protocol-scheme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const UNADVERTISE_OP = Joi.object().keys({
4949
const SUBSCRIBE_OP = Joi.object().keys({
5050
id: ID_SCHEME.required(),
5151
op: Joi.string().valid('subscribe').required(),
52-
type: Joi.string().required(),
52+
type: Joi.string(),//.required(),
5353
topic: Joi.string().required(),
5454
compression: Joi.string(),
5555
queue_length: Joi.number(),

0 commit comments

Comments
 (0)