holepunch-hop 0.4.1 → 0.4.3
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 +86 -28
- package/src/drive.js +3 -8
- package/src/index.js +17 -5
- package/src/peers.js +3 -1
package/package.json
CHANGED
package/src/bees.js
CHANGED
|
@@ -21,6 +21,7 @@ class HyperBee extends EventEmitter {
|
|
|
21
21
|
this.swarm = swarm
|
|
22
22
|
this.liveBees = {}
|
|
23
23
|
this.confirmPubLibList = {}
|
|
24
|
+
this.repPublicHolder = {}
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -46,7 +47,7 @@ class HyperBee extends EventEmitter {
|
|
|
46
47
|
valueEncoding: 'json' // same options as above
|
|
47
48
|
})
|
|
48
49
|
await this.dbPublicLibrary.ready()
|
|
49
|
-
beePubkeys.push({ store: 'publiclibrary', pubkey: b4a.toString(this.dbPublicLibrary.key, 'hex')})
|
|
50
|
+
beePubkeys.push({ store: 'publiclibrary', privacy: 'public', pubkey: b4a.toString(this.dbPublicLibrary.key, 'hex')})
|
|
50
51
|
// allow other peer access to public library (need to check for DDOS ie over asked)
|
|
51
52
|
// join a topic for network
|
|
52
53
|
const discovery = this.swarm.join(this.dbPublicLibrary.discoveryKey)
|
|
@@ -61,7 +62,7 @@ class HyperBee extends EventEmitter {
|
|
|
61
62
|
valueEncoding: 'json' // same options as above
|
|
62
63
|
})
|
|
63
64
|
await this.dbPeerLibrary.ready()
|
|
64
|
-
beePubkeys.push({store:'peerlibrary', pubkey: b4a.toString(core2.key, 'hex')})
|
|
65
|
+
beePubkeys.push({store:'peerlibrary', privacy: 'private', pubkey: b4a.toString(core2.key, 'hex')})
|
|
65
66
|
|
|
66
67
|
const core6 = this.store.get({ name: 'peers' })
|
|
67
68
|
this.dbPeers = new Hyperbee(core6, {
|
|
@@ -69,7 +70,7 @@ class HyperBee extends EventEmitter {
|
|
|
69
70
|
valueEncoding: 'json' // same options as above
|
|
70
71
|
})
|
|
71
72
|
await this.dbPeers.ready()
|
|
72
|
-
beePubkeys.push({store:'peers', pubkey: b4a.toString(core6.key, 'hex')})
|
|
73
|
+
beePubkeys.push({store:'peers', privacy: 'private', pubkey: b4a.toString(core6.key, 'hex')})
|
|
73
74
|
|
|
74
75
|
const core3 = this.store.get({ name: 'bentospaces' })
|
|
75
76
|
this.dbBentospaces = new Hyperbee(core3, {
|
|
@@ -85,7 +86,7 @@ class HyperBee extends EventEmitter {
|
|
|
85
86
|
valueEncoding: 'json' // same options as above
|
|
86
87
|
})
|
|
87
88
|
await this.dbBentochat.ready()
|
|
88
|
-
beePubkeys.push({store:'bentochat', pubkey: b4a.toString(core3.key, 'hex')})
|
|
89
|
+
beePubkeys.push({store:'bentochat', privacy: 'private', pubkey: b4a.toString(core3.key, 'hex')})
|
|
89
90
|
|
|
90
91
|
|
|
91
92
|
const core4 = this.store.get({ name: 'hopresults' })
|
|
@@ -95,7 +96,7 @@ class HyperBee extends EventEmitter {
|
|
|
95
96
|
})
|
|
96
97
|
await this.dbHOPresults.ready()
|
|
97
98
|
// this.client.replicate(this.dbHOPresults.feed)
|
|
98
|
-
beePubkeys.push({store:'hopresults', pubkey: b4a.toString(core4.key, 'hex')})
|
|
99
|
+
beePubkeys.push({store:'hopresults', privacy: 'private', pubkey: b4a.toString(core4.key, 'hex')})
|
|
99
100
|
|
|
100
101
|
const core5 = this.store.get({ name: 'kbledger' })
|
|
101
102
|
this.dbKBledger = new Hyperbee(core5, {
|
|
@@ -113,7 +114,7 @@ class HyperBee extends EventEmitter {
|
|
|
113
114
|
valueEncoding: 'json' // same options as above
|
|
114
115
|
})
|
|
115
116
|
await this.dbBentocues.ready()
|
|
116
|
-
beePubkeys.push({store:'bentocues', pubkey: b4a.toString(core7.key, 'hex')})
|
|
117
|
+
beePubkeys.push({store:'bentocues', privacy: 'public', pubkey: b4a.toString(core7.key, 'hex')})
|
|
117
118
|
|
|
118
119
|
const core13 = this.store.get({ name: 'bentomodels' })
|
|
119
120
|
this.dbBentomodels = new Hyperbee(core13, {
|
|
@@ -121,7 +122,7 @@ class HyperBee extends EventEmitter {
|
|
|
121
122
|
valueEncoding: 'json' // same options as above
|
|
122
123
|
})
|
|
123
124
|
await this.dbBentomodels.ready()
|
|
124
|
-
beePubkeys.push({store:'bentomodels', pubkey: b4a.toString(core7.key, 'hex')})
|
|
125
|
+
beePubkeys.push({store:'bentomodels', privacy: 'public', pubkey: b4a.toString(core7.key, 'hex')})
|
|
125
126
|
|
|
126
127
|
const core8 = this.store.get({ name: 'bentodecisions' })
|
|
127
128
|
this.dbBentodecisions = new Hyperbee(core8, {
|
|
@@ -138,7 +139,7 @@ class HyperBee extends EventEmitter {
|
|
|
138
139
|
valueEncoding: 'json' // same options as above
|
|
139
140
|
})
|
|
140
141
|
await this.dbBentomarkers.ready()
|
|
141
|
-
beePubkeys.push({store:'bentomarkers', pubkey: b4a.toString(core9.key, 'hex')})
|
|
142
|
+
beePubkeys.push({store:'bentomarkers', privacy: 'private', pubkey: b4a.toString(core9.key, 'hex')})
|
|
142
143
|
|
|
143
144
|
|
|
144
145
|
const core10 = this.store.get({ name: 'research' })
|
|
@@ -147,7 +148,7 @@ class HyperBee extends EventEmitter {
|
|
|
147
148
|
valueEncoding: 'json' // same options as above
|
|
148
149
|
})
|
|
149
150
|
await this.dbBentoresearch.ready()
|
|
150
|
-
beePubkeys.push({store:'research', pubkey: b4a.toString(core10.key, 'hex')})
|
|
151
|
+
beePubkeys.push({store:'research', privacy: 'public', pubkey: b4a.toString(core10.key, 'hex')})
|
|
151
152
|
|
|
152
153
|
|
|
153
154
|
const core11 = this.store.get({ name: 'bentoproducts' })
|
|
@@ -156,7 +157,7 @@ class HyperBee extends EventEmitter {
|
|
|
156
157
|
valueEncoding: 'json' // same options as above
|
|
157
158
|
})
|
|
158
159
|
await this.dbBentoproducts.ready()
|
|
159
|
-
beePubkeys.push({store:'bentoproducts', pubkey: b4a.toString(core11.key, 'hex')})
|
|
160
|
+
beePubkeys.push({store:'bentoproducts', privacy: 'private', pubkey: b4a.toString(core11.key, 'hex')})
|
|
160
161
|
|
|
161
162
|
const core12 = this.store.get({ name: 'bentomedia' })
|
|
162
163
|
this.dbBentomedia = new Hyperbee(core12, {
|
|
@@ -164,25 +165,8 @@ class HyperBee extends EventEmitter {
|
|
|
164
165
|
valueEncoding: 'json' // same options as above
|
|
165
166
|
})
|
|
166
167
|
await this.dbBentomedia.ready()
|
|
167
|
-
beePubkeys.push({store:'bentomedia', pubkey: b4a.toString(core12.key, 'hex')})
|
|
168
|
+
beePubkeys.push({store:'bentomedia', privacy: 'private', pubkey: b4a.toString(core12.key, 'hex')})
|
|
168
169
|
|
|
169
|
-
// temp delete agents
|
|
170
|
-
// this.deleteBentoModel({ id: '5e6e36c953b673fe7b2dd06dd773d43feea42a0d'})
|
|
171
|
-
// this.deleteBentoModel({ id: '8439ec4e6d6b89227145da877fffb697b1209d78'})
|
|
172
|
-
// this.deleteBentoModel({ id: 'ba5b7ba40a1dc5c37722c75d29353437e94f805c'})
|
|
173
|
-
|
|
174
|
-
/*this.deleteBentospace({ cueid: '296ce0efc66045c5842707d4652186e440f2fc21'})
|
|
175
|
-
this.deleteBentospace({ cueid: '7baf3109a5b2c5b64981b494984d1bb1fe72f3ba'})
|
|
176
|
-
this.deleteBentospace({ cueid: 'a820ec16b810603b3b1c6458f33d9f36bafdc533'})
|
|
177
|
-
this.deleteBentospace({ cueid: 'b96fa316c2f7eddf9b842da8c9ac2780f36abdff'})
|
|
178
|
-
this.deleteBentospace({ cueid: 'ddd7eb037439f97ead2d1e1be880e58d329ca54b'})
|
|
179
|
-
this.deleteBentospace({ cueid: 's-296ce0efc66045c5842707d4652186e440f2fc21'})
|
|
180
|
-
this.deleteBentospace({ cueid: 's-7baf3109a5b2c5b64981b494984d1bb1fe72f3ba'})
|
|
181
|
-
this.deleteBentospace({ cueid: 's-83dc025c2298b4673f62fbc436d2c1f8dc525fe8'})
|
|
182
|
-
this.deleteBentospace({ cueid: 's-b96fa316c2f7eddf9b842da8c9ac2780f36abdff'}) */
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
170
|
this.emit('hbee-live')
|
|
187
171
|
// return beePubkeys
|
|
188
172
|
let startBeePubkey = {}
|
|
@@ -875,6 +859,42 @@ class HyperBee extends EventEmitter {
|
|
|
875
859
|
*
|
|
876
860
|
*/
|
|
877
861
|
replicatePubliclibrary = async function (dataIn) {
|
|
862
|
+
// create or get the hypercore using the public key supplied as command-line argument
|
|
863
|
+
const coreRep = this.store.get({ key: b4a.from(dataIn.discoverykey, 'hex') })
|
|
864
|
+
|
|
865
|
+
// create a hyperbee instance using the hypercore instance
|
|
866
|
+
const beePlib = new Hyperbee(coreRep, {
|
|
867
|
+
keyEncoding: 'utf-8',
|
|
868
|
+
valueEncoding: 'utf-8'
|
|
869
|
+
})
|
|
870
|
+
|
|
871
|
+
// wait till the hypercore properties to be intialized
|
|
872
|
+
await coreRep.ready()
|
|
873
|
+
|
|
874
|
+
// logging the public key of the hypercore instance
|
|
875
|
+
// console.log('core key here is:', coreRep.key.toString('hex'))
|
|
876
|
+
|
|
877
|
+
// Attempt to connect to peers
|
|
878
|
+
this.swarm.join(coreRep.discoveryKey, { server: false, client: true })
|
|
879
|
+
|
|
880
|
+
await coreRep.update()
|
|
881
|
+
|
|
882
|
+
const nodeData = beePlib.createReadStream()
|
|
883
|
+
let resData = []
|
|
884
|
+
for await (const { key, value } of nodeData) {
|
|
885
|
+
resData.push({ key, value })
|
|
886
|
+
}
|
|
887
|
+
this.repPublicHolder[dataIn.discoverykey] = resData
|
|
888
|
+
// notify peer repliate complete, ask if want save
|
|
889
|
+
this.emit('publib-replicate-notification', { data: { text: 'public library replication complete', publib: dataIn.discoverykey }})
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* repicate the publiclibrary peer to peer
|
|
894
|
+
* @method replicateQueryPubliclibrary
|
|
895
|
+
*
|
|
896
|
+
*/
|
|
897
|
+
replicateQueryPubliclibrary = async function (dataIn) {
|
|
878
898
|
// create or get the hypercore using the public key supplied as command-line argument
|
|
879
899
|
const coreRep = this.store.get({ key: b4a.from(dataIn.data.data.datastores, 'hex') })
|
|
880
900
|
|
|
@@ -959,6 +979,22 @@ class HyperBee extends EventEmitter {
|
|
|
959
979
|
return repMessage */
|
|
960
980
|
}
|
|
961
981
|
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* look up holder and save data to public library datastore
|
|
985
|
+
* @method saveRepliatePubLibary
|
|
986
|
+
*
|
|
987
|
+
*/
|
|
988
|
+
saveRepliatePubLibary = async function (data) {
|
|
989
|
+
// add board nxp
|
|
990
|
+
let updatePubLib = this.repPublicHolder[data.discoverykey]
|
|
991
|
+
if (data.library === 'publiclibrary') {
|
|
992
|
+
await this.updatePublicLibrary(updatePubLib)
|
|
993
|
+
} else if (data.library === 'cues') {
|
|
994
|
+
await this.updateCuesLibrary(updatePubLib)
|
|
995
|
+
}
|
|
996
|
+
this.repPublicHolder[data.discoverykey] = []
|
|
997
|
+
}
|
|
962
998
|
|
|
963
999
|
/**
|
|
964
1000
|
* peer confirmed add to public library
|
|
@@ -996,6 +1032,28 @@ class HyperBee extends EventEmitter {
|
|
|
996
1032
|
return true
|
|
997
1033
|
}
|
|
998
1034
|
|
|
1035
|
+
/**
|
|
1036
|
+
* update cues library from replication
|
|
1037
|
+
* @method updateCuesLibrary
|
|
1038
|
+
*
|
|
1039
|
+
*/
|
|
1040
|
+
updateCuesLibrary = async function (libContracts) {
|
|
1041
|
+
// save entries required
|
|
1042
|
+
const batch = this.dbPublicLibrary.batch()
|
|
1043
|
+
for (const { key, value } of libContracts) {
|
|
1044
|
+
await batch.put(key, JSON.parse(value))
|
|
1045
|
+
}
|
|
1046
|
+
await batch.flush()
|
|
1047
|
+
|
|
1048
|
+
// check
|
|
1049
|
+
const libUpdatecheck = this.dbBentocues.createReadStream()
|
|
1050
|
+
let libConracts = []
|
|
1051
|
+
for await (const { key, value } of libUpdatecheck) {
|
|
1052
|
+
libConracts.push({ key, value })
|
|
1053
|
+
}
|
|
1054
|
+
return true
|
|
1055
|
+
}
|
|
1056
|
+
|
|
999
1057
|
/**
|
|
1000
1058
|
* repicate the publiclibrary peer to peer
|
|
1001
1059
|
* @method ryOLD
|
package/src/drive.js
CHANGED
|
@@ -56,9 +56,10 @@ class HypDrive extends EventEmitter {
|
|
|
56
56
|
await this.drive.ready()
|
|
57
57
|
|
|
58
58
|
let startDrivePubkey = {}
|
|
59
|
-
startDrivePubkey.type = '
|
|
59
|
+
startDrivePubkey.type = 'account'
|
|
60
|
+
startDrivePubkey.action = 'drive-pubkey'
|
|
60
61
|
startDrivePubkey.data = b4a.toString(this.drive.key, 'hex')
|
|
61
|
-
|
|
62
|
+
this.wsocket.send(JSON.stringify(startDrivePubkey))
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
|
|
@@ -102,7 +103,6 @@ class HypDrive extends EventEmitter {
|
|
|
102
103
|
// file input management
|
|
103
104
|
// protocol to save original file
|
|
104
105
|
let newPathFile = await this.hyperdriveFilesave(fileData.data[0].type, fileData.data[0].name, fileData.data[0].content)
|
|
105
|
-
|
|
106
106
|
// extract out the headers name for columns
|
|
107
107
|
let headerSet = this.fileUtility.extractCSVHeaderInfo(fileData)
|
|
108
108
|
// csv to JSON convertion HOP protocol standard
|
|
@@ -164,7 +164,6 @@ class HypDrive extends EventEmitter {
|
|
|
164
164
|
return fileResponse
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
168
167
|
/**
|
|
169
168
|
* blind sqlite lookup of data (maybe restricture no. of rows of data iniitally)
|
|
170
169
|
* @method blindDataSqlite
|
|
@@ -175,7 +174,6 @@ class HypDrive extends EventEmitter {
|
|
|
175
174
|
return parseData
|
|
176
175
|
}
|
|
177
176
|
|
|
178
|
-
|
|
179
177
|
/**
|
|
180
178
|
* save to hyperdrive file
|
|
181
179
|
* @method hyperdriveFilesave
|
|
@@ -213,7 +211,6 @@ class HypDrive extends EventEmitter {
|
|
|
213
211
|
return hyperdrivePath
|
|
214
212
|
}
|
|
215
213
|
|
|
216
|
-
|
|
217
214
|
/**
|
|
218
215
|
* save a stream of file ie. large file
|
|
219
216
|
* @method hyperdriveStreamSave
|
|
@@ -370,7 +367,6 @@ class HypDrive extends EventEmitter {
|
|
|
370
367
|
return summarySQLinfo
|
|
371
368
|
}
|
|
372
369
|
|
|
373
|
-
|
|
374
370
|
/**
|
|
375
371
|
* ask for device tables and info.
|
|
376
372
|
* @method SQLiteDeviceSetup
|
|
@@ -425,7 +421,6 @@ class HypDrive extends EventEmitter {
|
|
|
425
421
|
|
|
426
422
|
}
|
|
427
423
|
|
|
428
|
-
|
|
429
424
|
/**
|
|
430
425
|
* try to match to known time formats
|
|
431
426
|
* @method testDataExtact
|
package/src/index.js
CHANGED
|
@@ -146,22 +146,26 @@ class HolepunchWorker extends EventEmitter {
|
|
|
146
146
|
// check if bentoboxN1 included?
|
|
147
147
|
if (data.data.data.content.bbn1.publicN1contracts.length > 0) {
|
|
148
148
|
for (let n1Cont of data.data.data.content.bbn1.publicN1contracts) {
|
|
149
|
-
this.BeeData.
|
|
149
|
+
this.BeeData.replicateQueryPubliclibrary({ data: n1Cont })
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
})
|
|
153
153
|
// public library notification
|
|
154
154
|
this.Peers.on('publiclibrarynotification', (data) => {
|
|
155
|
-
this.BeeData.
|
|
155
|
+
this.BeeData.replicateQueryPubliclibrary(data)
|
|
156
156
|
})
|
|
157
157
|
// beebee notifications public
|
|
158
158
|
this.BeeData.on('publibbeebee-notification', (data) => {
|
|
159
159
|
this.emit('beebee-publib-notification', data)
|
|
160
160
|
})
|
|
161
|
+
// public library replicate
|
|
162
|
+
this.BeeData.on('publib-replicate-notification', (data) => {
|
|
163
|
+
this.emit('replicate-publib-notification', data)
|
|
164
|
+
})
|
|
161
165
|
// new warm incoming peer
|
|
162
166
|
this.Peers.on('connect-warm-first', (data) => {
|
|
163
167
|
// check re establishing peer to peer of first time connection?
|
|
164
|
-
let peerInfoName = 'not-matched' //
|
|
168
|
+
let peerInfoName = 'not-matched' // could be mis match or blind/ cold peer accessing public library
|
|
165
169
|
// check role and match codename
|
|
166
170
|
if (data.roletaken === 'server') {
|
|
167
171
|
// not unique info to match on yet.
|
|
@@ -282,14 +286,22 @@ class HolepunchWorker extends EventEmitter {
|
|
|
282
286
|
let peerActionData = this.Peers.peerHolder[message.data.publickey]
|
|
283
287
|
this.Peers.routeDataPath(reEstablishShort.peer.value.livePeerkey, peerActionData.data)
|
|
284
288
|
}
|
|
285
|
-
}
|
|
289
|
+
}
|
|
286
290
|
} else if (message.action === 'retry') {
|
|
287
291
|
let peerDefaults = this.Peers.peerMatchTopic(message.data.key)
|
|
288
292
|
this.Peers.discoveryMatch(message.data.key)
|
|
289
293
|
} else if (message.action === 'peer-closed') {
|
|
290
294
|
this.flushConnections()
|
|
291
295
|
await this.swarm.destroy()
|
|
292
|
-
|
|
296
|
+
} else if (message.action === 'replicate-library') {
|
|
297
|
+
// let reEstablishShort = this.Peers.checkConnectivityStatus(message, this.warmPeers, 'invite-replicate')
|
|
298
|
+
if (message.task === 'public-library-replicate') {
|
|
299
|
+
// write message to peer with open public library
|
|
300
|
+
this.BeeData.replicatePubliclibrary(message.data)
|
|
301
|
+
}
|
|
302
|
+
} else if (message.action === 'save-replicate-library') {
|
|
303
|
+
// look up holder and save to public library please
|
|
304
|
+
this.BeeData.saveRepliatePubLibary(message.data)
|
|
293
305
|
}
|
|
294
306
|
}
|
|
295
307
|
|
package/src/peers.js
CHANGED
|
@@ -281,6 +281,8 @@ class NetworkPeers extends EventEmitter {
|
|
|
281
281
|
} else if (dataShareIn.type === 'private-cue-space') {
|
|
282
282
|
this.emit('cuespace-notification', { publickey: peerMatch, data: dataShareIn })
|
|
283
283
|
} else if (dataShareIn.type === 'public-library') {
|
|
284
|
+
console.log('public rep reque arrivee')
|
|
285
|
+
console.log(dataShareIn)
|
|
284
286
|
this.emit('publiclibrarynotification', { publickey: peerMatch, data: dataShareIn })
|
|
285
287
|
} else if (dataShareIn.type === 'peer') {
|
|
286
288
|
} else if (dataShareIn.type === 'peer-codename-inform') {
|
|
@@ -626,7 +628,7 @@ class NetworkPeers extends EventEmitter {
|
|
|
626
628
|
} else if (peerTopeerState.type === 'peer-write') {
|
|
627
629
|
this.Peers.writeTonetwork(peerTopeerState)
|
|
628
630
|
} else if (peerTopeerState.type === 'public-library') {
|
|
629
|
-
this.Peers.writeToPublicLibrary(
|
|
631
|
+
this.Peers.writeToPublicLibrary(livePubkey, peerTopeerState)
|
|
630
632
|
}
|
|
631
633
|
}
|
|
632
634
|
}
|