holepunch-hop 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/bees.js +87 -6
- package/src/index.js +0 -15
- package/src/peers.js +20 -6
package/package.json
CHANGED
package/src/bees.js
CHANGED
|
@@ -78,6 +78,15 @@ class HyperBee extends EventEmitter {
|
|
|
78
78
|
await this.dbBentospaces.ready()
|
|
79
79
|
beePubkeys.push({store:'bentospaces', pubkey: b4a.toString(core3.key, 'hex')})
|
|
80
80
|
|
|
81
|
+
const core14 = this.store.get({ name: 'bentochat' })
|
|
82
|
+
this.dbBentochat = new Hyperbee(core14, {
|
|
83
|
+
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding
|
|
84
|
+
valueEncoding: 'json' // same options as above
|
|
85
|
+
})
|
|
86
|
+
await this.dbBentochat.ready()
|
|
87
|
+
beePubkeys.push({store:'bentochat', pubkey: b4a.toString(core3.key, 'hex')})
|
|
88
|
+
|
|
89
|
+
|
|
81
90
|
const core4 = this.store.get({ name: 'hopresults' })
|
|
82
91
|
this.dbHOPresults = new Hyperbee(core4, {
|
|
83
92
|
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding
|
|
@@ -105,6 +114,13 @@ class HyperBee extends EventEmitter {
|
|
|
105
114
|
await this.dbBentocues.ready()
|
|
106
115
|
beePubkeys.push({store:'bentocues', pubkey: b4a.toString(core7.key, 'hex')})
|
|
107
116
|
|
|
117
|
+
const core13 = this.store.get({ name: 'bentomodels' })
|
|
118
|
+
this.dbBentomodels = new Hyperbee(core13, {
|
|
119
|
+
keyEncoding: 'utf-8', // can be set to undefined (binary), utf-8, ascii or and abstract-encoding
|
|
120
|
+
valueEncoding: 'json' // same options as above
|
|
121
|
+
})
|
|
122
|
+
await this.dbBentomodels.ready()
|
|
123
|
+
beePubkeys.push({store:'bentomodels', pubkey: b4a.toString(core7.key, 'hex')})
|
|
108
124
|
|
|
109
125
|
const core8 = this.store.get({ name: 'bentodecisions' })
|
|
110
126
|
this.dbBentodecisions = new Hyperbee(core8, {
|
|
@@ -149,6 +165,23 @@ class HyperBee extends EventEmitter {
|
|
|
149
165
|
await this.dbBentomedia.ready()
|
|
150
166
|
beePubkeys.push({store:'bentomedia', pubkey: b4a.toString(core12.key, 'hex')})
|
|
151
167
|
|
|
168
|
+
// temp delete agents
|
|
169
|
+
// this.deleteBentoModel({ id: '5e6e36c953b673fe7b2dd06dd773d43feea42a0d'})
|
|
170
|
+
// this.deleteBentoModel({ id: '8439ec4e6d6b89227145da877fffb697b1209d78'})
|
|
171
|
+
// this.deleteBentoModel({ id: 'ba5b7ba40a1dc5c37722c75d29353437e94f805c'})
|
|
172
|
+
|
|
173
|
+
/*this.deleteBentospace({ cueid: '296ce0efc66045c5842707d4652186e440f2fc21'})
|
|
174
|
+
this.deleteBentospace({ cueid: '7baf3109a5b2c5b64981b494984d1bb1fe72f3ba'})
|
|
175
|
+
this.deleteBentospace({ cueid: 'a820ec16b810603b3b1c6458f33d9f36bafdc533'})
|
|
176
|
+
this.deleteBentospace({ cueid: 'b96fa316c2f7eddf9b842da8c9ac2780f36abdff'})
|
|
177
|
+
this.deleteBentospace({ cueid: 'ddd7eb037439f97ead2d1e1be880e58d329ca54b'})
|
|
178
|
+
this.deleteBentospace({ cueid: 's-296ce0efc66045c5842707d4652186e440f2fc21'})
|
|
179
|
+
this.deleteBentospace({ cueid: 's-7baf3109a5b2c5b64981b494984d1bb1fe72f3ba'})
|
|
180
|
+
this.deleteBentospace({ cueid: 's-83dc025c2298b4673f62fbc436d2c1f8dc525fe8'})
|
|
181
|
+
this.deleteBentospace({ cueid: 's-b96fa316c2f7eddf9b842da8c9ac2780f36abdff'}) */
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
152
185
|
this.emit('hbee-live')
|
|
153
186
|
// return beePubkeys
|
|
154
187
|
let startBeePubkey = {}
|
|
@@ -211,13 +244,15 @@ class HyperBee extends EventEmitter {
|
|
|
211
244
|
await this.dbHOPresults.put(refContract.hash, refContract.data)
|
|
212
245
|
}
|
|
213
246
|
|
|
247
|
+
/** CHAT */
|
|
248
|
+
|
|
214
249
|
/**
|
|
215
250
|
* save chat history
|
|
216
251
|
* @method saveBentochat
|
|
217
252
|
*
|
|
218
253
|
*/
|
|
219
254
|
saveBentochat = async function (chatHistory) {
|
|
220
|
-
await this.
|
|
255
|
+
await this.dbBentochat.put(chatHistory.chat.chatid, chatHistory)
|
|
221
256
|
let checkSave = await this.getBentochat(chatHistory.chat.chatid)
|
|
222
257
|
return checkSave
|
|
223
258
|
}
|
|
@@ -228,7 +263,7 @@ class HyperBee extends EventEmitter {
|
|
|
228
263
|
*
|
|
229
264
|
*/
|
|
230
265
|
deleteBentochat = async function (chat) {
|
|
231
|
-
await this.
|
|
266
|
+
await this.dbBentochat.del(chat.chatid)
|
|
232
267
|
let deleteInfo = {}
|
|
233
268
|
deleteInfo.chatid = chat.chatid
|
|
234
269
|
return deleteInfo
|
|
@@ -240,8 +275,7 @@ class HyperBee extends EventEmitter {
|
|
|
240
275
|
*
|
|
241
276
|
*/
|
|
242
277
|
getBentochat = async function (key) {
|
|
243
|
-
|
|
244
|
-
const nodeData = await this.dbBentospaces.get(key)
|
|
278
|
+
const nodeData = await this.dbBentochat.get(key)
|
|
245
279
|
return nodeData
|
|
246
280
|
}
|
|
247
281
|
|
|
@@ -251,7 +285,7 @@ class HyperBee extends EventEmitter {
|
|
|
251
285
|
*
|
|
252
286
|
*/
|
|
253
287
|
getBentochatHistory = async function (range) {
|
|
254
|
-
const chathistoryData = this.
|
|
288
|
+
const chathistoryData = this.dbBentochat.createReadStream() // { gt: 'a', lt: 'z' }) // anything >a and <z
|
|
255
289
|
let chatData = []
|
|
256
290
|
for await (const { key, value } of chathistoryData) {
|
|
257
291
|
chatData.push({ key, value })
|
|
@@ -259,6 +293,8 @@ class HyperBee extends EventEmitter {
|
|
|
259
293
|
return chatData
|
|
260
294
|
}
|
|
261
295
|
|
|
296
|
+
/** SPACE */
|
|
297
|
+
|
|
262
298
|
/**
|
|
263
299
|
* save space menu
|
|
264
300
|
* @method saveSpaceHistory
|
|
@@ -365,6 +401,52 @@ class HyperBee extends EventEmitter {
|
|
|
365
401
|
return deleteInfo
|
|
366
402
|
}
|
|
367
403
|
|
|
404
|
+
/** MODELS */
|
|
405
|
+
/**
|
|
406
|
+
* save model
|
|
407
|
+
* @method saveModel
|
|
408
|
+
*/
|
|
409
|
+
saveModel = async function (modelInfo) {
|
|
410
|
+
await this.dbBentomodels.put(modelInfo.id, modelInfo.data)
|
|
411
|
+
let checkSave = await this.getModel(modelInfo.id)
|
|
412
|
+
return checkSave
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* get one cue by id
|
|
417
|
+
* @method getModel
|
|
418
|
+
*
|
|
419
|
+
*/
|
|
420
|
+
getModel = async function (key) {
|
|
421
|
+
const nodeData = await this.dbBentomodels.get(key)
|
|
422
|
+
return nodeData
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* get all cuees
|
|
427
|
+
* @method getModelHistory
|
|
428
|
+
*
|
|
429
|
+
*/
|
|
430
|
+
getModelHistory = async function (key) {
|
|
431
|
+
const modelHistory = await this.dbBentomodels.createReadStream()
|
|
432
|
+
let modelData = []
|
|
433
|
+
for await (const { key, value } of modelHistory) {
|
|
434
|
+
modelData.push({ key, value })
|
|
435
|
+
}
|
|
436
|
+
return modelData
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* delete nxp ref contract from peer library
|
|
441
|
+
* @method deleteBentomodel
|
|
442
|
+
*/
|
|
443
|
+
deleteBentoModel = async function (model) {
|
|
444
|
+
const deleteStatus = await this.dbBentomodels.del(model.id)
|
|
445
|
+
let deleteInfo = {}
|
|
446
|
+
deleteInfo.id = model.id
|
|
447
|
+
return deleteInfo
|
|
448
|
+
}
|
|
449
|
+
|
|
368
450
|
/** MEDIA */
|
|
369
451
|
/**
|
|
370
452
|
* save media
|
|
@@ -422,7 +504,6 @@ class HyperBee extends EventEmitter {
|
|
|
422
504
|
savePeer = async function (peerInfo) {
|
|
423
505
|
await this.dbPeers.put(peerInfo.publickey, peerInfo)
|
|
424
506
|
let checkSave = await this.getPeer(peerInfo.publickey)
|
|
425
|
-
console.log('save peer over---------')
|
|
426
507
|
return checkSave
|
|
427
508
|
}
|
|
428
509
|
|
package/src/index.js
CHANGED
|
@@ -319,21 +319,6 @@ class HolepunchWorker extends EventEmitter {
|
|
|
319
319
|
// what type of data being shared?
|
|
320
320
|
// check for data along with new peer?
|
|
321
321
|
this.Peers.routeDataPath(data, peerDataExist)
|
|
322
|
-
/*
|
|
323
|
-
if (peerDataExist.data !== undefined) {
|
|
324
|
-
if (peerDataExist.data.type === 'private-chart') {
|
|
325
|
-
this.Peers.writeTonetworkData(data, peerDataExist.data)
|
|
326
|
-
} else if (peerDataExist.data.type === 'private-cue-space') {
|
|
327
|
-
this.Peers.writeToCueSpace(this.Peers.peerHolder[peerFirstID].publickey)
|
|
328
|
-
} else if (peerDataExist.data.type === 'public-n1-experiment') {
|
|
329
|
-
this.Peers.writeTonetworkData(data, peerDataExist.data)
|
|
330
|
-
} else if (peerDataExist.data.type === 'public-library') {
|
|
331
|
-
this.Peers.writeToPublicLibrary(data)
|
|
332
|
-
} else if (peerDataExist.data.type === 'text-message') {
|
|
333
|
-
// simpole text message
|
|
334
|
-
this.Peers.writeTonetwork(data)
|
|
335
|
-
}
|
|
336
|
-
} */
|
|
337
322
|
}
|
|
338
323
|
}
|
|
339
324
|
|
package/src/peers.js
CHANGED
|
@@ -82,8 +82,8 @@ class NetworkPeers extends EventEmitter {
|
|
|
82
82
|
for (let sPeer of this.peerNetwork) {
|
|
83
83
|
// sPeer.value.key = publicKeylive
|
|
84
84
|
if (sPeer.value.settopic === true) {
|
|
85
|
-
// client role
|
|
86
|
-
this.topicConnect(sPeer.value.topic)
|
|
85
|
+
// client role need to pass on peerUniqueID
|
|
86
|
+
this.topicConnect(sPeer.key, sPeer.value.topic)
|
|
87
87
|
} else {
|
|
88
88
|
// server role
|
|
89
89
|
this.topicListen(sPeer.value.topic, sPeer.key)
|
|
@@ -100,8 +100,6 @@ class NetworkPeers extends EventEmitter {
|
|
|
100
100
|
this.peerEstContext[pubKey] = established
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
103
|
/**
|
|
106
104
|
* connection listen
|
|
107
105
|
* @method listenNetwork
|
|
@@ -493,13 +491,29 @@ class NetworkPeers extends EventEmitter {
|
|
|
493
491
|
let discovery = this.swarm.status(noisePublicKey)
|
|
494
492
|
let discoverTopic = discovery.topic.toString('hex')
|
|
495
493
|
if (discoverTopic === topicH.topic) {
|
|
494
|
+
// do the peerid match?
|
|
496
495
|
discovery.swarm.connections.forEach((value, key) => {
|
|
497
496
|
checkDiscoveryTopic.server = value.publicKey.toString('hex')
|
|
498
497
|
checkDiscoveryTopic.client = value.remotePublicKey.toString('hex')
|
|
499
498
|
checkDiscoveryTopic.topic = discoverTopic
|
|
500
499
|
})
|
|
500
|
+
if (checkDiscoveryTopic.client === topicH.peerKey) {
|
|
501
|
+
return checkDiscoveryTopic
|
|
502
|
+
} else {
|
|
503
|
+
if (checkDiscoveryTopic.topic === topicH.topic) {
|
|
504
|
+
return checkDiscoveryTopic
|
|
505
|
+
} else {
|
|
506
|
+
checkDiscoveryTopic.topic = ''
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
} else {
|
|
510
|
+
|
|
501
511
|
}
|
|
502
512
|
}
|
|
513
|
+
} else {
|
|
514
|
+
checkDiscoveryTopic.server = ''
|
|
515
|
+
checkDiscoveryTopic.client = ''
|
|
516
|
+
checkDiscoveryTopic.topic = ''
|
|
503
517
|
}
|
|
504
518
|
return checkDiscoveryTopic
|
|
505
519
|
}
|
|
@@ -665,13 +679,13 @@ class NetworkPeers extends EventEmitter {
|
|
|
665
679
|
* @method topicConnect
|
|
666
680
|
*
|
|
667
681
|
*/
|
|
668
|
-
topicConnect = async function (topic) {
|
|
682
|
+
topicConnect = async function (peerID, topic) {
|
|
669
683
|
// const noisePublicKey = Buffer.alloc(32).fill(topic) // A topic must be 32 bytes
|
|
670
684
|
const noisePublicKey = Buffer.from(topic, 'hex') // must be 32 bytes
|
|
671
685
|
if (noisePublicKey.length === 32) {
|
|
672
686
|
let topicKeylive = noisePublicKey.toString('hex')
|
|
673
687
|
this.topicHolder[topic] = { role: 'server', livePubkey: this.swarm.keyPair.publicKey.toString('hex'), topic: topic, key: topicKeylive, timestamp: '' }
|
|
674
|
-
this.sendTopicHolder.push({ livePubkey: this.swarm.keyPair.publicKey.toString('hex'), topic: topic })
|
|
688
|
+
this.sendTopicHolder.push({ livePubkey: this.swarm.keyPair.publicKey.toString('hex'), peerKey: peerID, topic: topic })
|
|
675
689
|
const peerConnect = this.swarm.join(noisePublicKey, { server: true, client: false })
|
|
676
690
|
await peerConnect.flushed() // Waits for the topic to be fully announced on the DHT
|
|
677
691
|
}
|