holepunch-hop 0.4.5 → 0.5.0
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/.vscode/settings.json +3 -0
- package/package.json +11 -5
- package/src/adapters/timeConvertor.js +3 -0
- package/src/index.js +45 -10
- package/src/{peers.js → network/peers.js} +507 -136
- package/src/{bees.js → storage/bees.js} +142 -60
- package/src/{drive.js → storage/drive.js} +2 -3
- package/src/{fileParser.js → storage/fileParser.js} +7 -1
- package/test/datacommands/files/data/jan3-bitcoin.csv +17 -0
- package/test/datacommands/files/large-csv.test.js +7 -0
- package/test/datacommands/files/small-csv.test.js +76 -0
- package/test/datacommands/ledger/save-get-ledger.test.js +117 -0
- package/test/datacommands/results/save-get-results.test.js +122 -0
- package/test/holepunch-initiate.test.js +47 -0
- package/test/multipers/ten-peers-network.test.js +437 -0
- package/test/setup-bee-holepunch.test.js +45 -0
- package/test/setup-holepunch.test.js +14 -13
- package/test/threepers/peer3-geninvite-after.test.js +439 -0
- package/test/threepers/three-peers.test.js +159 -0
- package/test/threepers/two-then-three.test.js +434 -0
- package/test/twopeers/peerClient-Server.test.js +243 -0
- package/test/twopeers/reconnect-peers.test.js +257 -0
- package/test/twopeers/reconnect-serverthen-conerr.test.js +304 -0
- package/test/twopeers/reconnect-then-conerr.test.js +309 -0
- package/test/twopeers/two-peer-one-disconnect.test.js +162 -0
- package/test/twopeers/two-peer-server-disconnect.test.js +167 -0
- package/vitest.config.js +8 -0
- /package/src/{kbledger.js → ledger/kbledger.js} +0 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "holepunch-hop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "data interface to HOP",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "node src/index.js",
|
|
9
|
-
"test": "
|
|
9
|
+
"test": "vitest run"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"atob": "^2.1.2",
|
|
29
29
|
"axios": "^1.2.2",
|
|
30
30
|
"b4a": "^1.6.1",
|
|
31
|
+
"chrono-node": "^2.7.5",
|
|
31
32
|
"corestore": "^6.4.0",
|
|
32
33
|
"csv-parser": "^3.0.0",
|
|
33
34
|
"debounceify": "^1.0.0",
|
|
@@ -38,11 +39,16 @@
|
|
|
38
39
|
"hyperswarm": "^4.3.5",
|
|
39
40
|
"localdrive": "github:holepunchto/localdrive",
|
|
40
41
|
"luxon": "^3.4.4",
|
|
41
|
-
"chrono-node": "^2.7.5",
|
|
42
42
|
"sqlite3": "^5.1.7"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"object-hash": "^3.0.0",
|
|
46
|
+
"vitest": "^3.1.1",
|
|
47
|
+
"brittle": "^3.1.0",
|
|
48
|
+
"protocol-buffers": "^4.2.0",
|
|
49
|
+
"standard": "^17.0.0",
|
|
50
|
+
"sub-encoder": "^1.0.6",
|
|
51
|
+
"tree-to-string": "^1.1.1",
|
|
52
|
+
"ws": "^8.11.0"
|
|
47
53
|
}
|
|
48
54
|
}
|
|
@@ -25,6 +25,8 @@ class TimeConvertor extends EventEmitter {
|
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
27
|
testDataExtact = function (sampleDate) {
|
|
28
|
+
console.log('time adopter')
|
|
29
|
+
console.log(sampleDate)
|
|
28
30
|
let parseDate0 = DateTime.fromISO(sampleDate)
|
|
29
31
|
let parseDate1 = DateTime.fromHTTP(sampleDate)
|
|
30
32
|
let parseDate2 = DateTime.fromJSDate(sampleDate)
|
|
@@ -35,6 +37,7 @@ class TimeConvertor extends EventEmitter {
|
|
|
35
37
|
// .fromJSDate(sampleDate) // .fromHTTP(sampleDate) // fromFormat(sampleDate, "YYY-MM-DD ") //.fromISO(sampleDate) // or DateTime. fromFormat("23-06-2019", "dd-MM-yyyy") .(splitRow[0])// new Date(splitRow[0])
|
|
36
38
|
// console.log(parseDate) */
|
|
37
39
|
let millDate = parseDate2.toMillis()
|
|
40
|
+
console.log(millDate)
|
|
38
41
|
return millDate
|
|
39
42
|
}
|
|
40
43
|
|
package/src/index.js
CHANGED
|
@@ -16,15 +16,16 @@ import goodbye from 'graceful-goodbye'
|
|
|
16
16
|
import b4a from 'b4a'
|
|
17
17
|
|
|
18
18
|
// import { Node } from 'hyperbee/lib/messages.js'
|
|
19
|
-
import BeeWorker from './bees.js'
|
|
20
|
-
import DriveWorker from './drive.js'
|
|
21
|
-
import PeerWorker from './peers.js'
|
|
19
|
+
import BeeWorker from './storage/bees.js'
|
|
20
|
+
import DriveWorker from './storage/drive.js'
|
|
21
|
+
import PeerWorker from './network/peers.js'
|
|
22
22
|
|
|
23
23
|
class HolepunchWorker extends EventEmitter {
|
|
24
24
|
|
|
25
|
-
constructor() {
|
|
25
|
+
constructor(storeName) {
|
|
26
26
|
super()
|
|
27
27
|
this.hello = 'holepunch'
|
|
28
|
+
this.peerStore = ''
|
|
28
29
|
this.store = {}
|
|
29
30
|
this.swarm = {}
|
|
30
31
|
this.BeeData = {}
|
|
@@ -37,17 +38,31 @@ class HolepunchWorker extends EventEmitter {
|
|
|
37
38
|
this.warmPeers = [] // ikeep track of live incoming sharing
|
|
38
39
|
this.codenameUpdates = []
|
|
39
40
|
this.topicExhange = []
|
|
41
|
+
this.setStorename(storeName)
|
|
40
42
|
this.startHolepunch()
|
|
41
43
|
this.networkListeners()
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
/**
|
|
47
|
+
* set store name
|
|
48
|
+
* @method setStorename
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
setStorename = function (storeName) {
|
|
52
|
+
if (storeName === undefined || storeName?.length === 0) {
|
|
53
|
+
this.peerStore = '.hop-storage'
|
|
54
|
+
} else {
|
|
55
|
+
this.peerStore = '.' + storeName
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
44
59
|
/**
|
|
45
60
|
* setup holepunch protocol
|
|
46
61
|
* @method startHolepunch
|
|
47
62
|
*
|
|
48
63
|
*/
|
|
49
64
|
startHolepunch = async function () {
|
|
50
|
-
this.store = new Corestore(os.homedir() + '
|
|
65
|
+
this.store = new Corestore(os.homedir() + '/' + this.peerStore)
|
|
51
66
|
this.swarm = new Hyperswarm()
|
|
52
67
|
// make replication possible
|
|
53
68
|
this.swarm.on('connection', conn => this.store.replicate(conn))
|
|
@@ -58,7 +73,7 @@ class HolepunchWorker extends EventEmitter {
|
|
|
58
73
|
// console.log('update-------')
|
|
59
74
|
// console.log(this.swarm.connecting)
|
|
60
75
|
// console.log(this.swarm.connections.size)
|
|
61
|
-
//
|
|
76
|
+
//console.log(this.swarm.peers)
|
|
62
77
|
})
|
|
63
78
|
|
|
64
79
|
|
|
@@ -96,8 +111,8 @@ class HolepunchWorker extends EventEmitter {
|
|
|
96
111
|
* @method startStores
|
|
97
112
|
*
|
|
98
113
|
*/
|
|
99
|
-
startStores = function (
|
|
100
|
-
this.activateHypercores()
|
|
114
|
+
startStores = async function () {
|
|
115
|
+
await this.activateHypercores()
|
|
101
116
|
}
|
|
102
117
|
|
|
103
118
|
/**
|
|
@@ -111,7 +126,7 @@ class HolepunchWorker extends EventEmitter {
|
|
|
111
126
|
})
|
|
112
127
|
// peer connection active for first time
|
|
113
128
|
this.Peers.on('peer-connect', (data) => {
|
|
114
|
-
//this.warmPeerPrepare(data)
|
|
129
|
+
// this.warmPeerPrepare(data)
|
|
115
130
|
})
|
|
116
131
|
// share connection failed
|
|
117
132
|
this.Peers.on('peer-share-fail', (data) => {
|
|
@@ -126,6 +141,18 @@ class HolepunchWorker extends EventEmitter {
|
|
|
126
141
|
data.prime = false
|
|
127
142
|
this.emit('peer-topic-update', data)
|
|
128
143
|
})
|
|
144
|
+
// reconnect topic peer id
|
|
145
|
+
this.Peers.on('peer-reconnect-topic-id', (peerIn, data) => {
|
|
146
|
+
// update status to live
|
|
147
|
+
this.Peers.updatePeerStatus(data.topic, peerIn)
|
|
148
|
+
// match current key to peerid
|
|
149
|
+
let peerMatch = this.Peers.matchPeerTopic(data.topic)
|
|
150
|
+
let codeNameInform = {}
|
|
151
|
+
codeNameInform.type = 'peer-codename-inform'
|
|
152
|
+
codeNameInform.action = 'set'
|
|
153
|
+
codeNameInform.data = { inviteCode: '' , publickey: peerMatch.key }
|
|
154
|
+
this.emit('invite-live-peer', codeNameInform)
|
|
155
|
+
})
|
|
129
156
|
// peer reconnection topic ie. able to reconnect again
|
|
130
157
|
this.Peers.on('topic-formed-save', (data) => {
|
|
131
158
|
// put data into holder await for codename matching over
|
|
@@ -133,6 +160,8 @@ class HolepunchWorker extends EventEmitter {
|
|
|
133
160
|
})
|
|
134
161
|
// codename matching
|
|
135
162
|
this.Peers.on('peer-codename-match', (data) => {
|
|
163
|
+
// check if first time?
|
|
164
|
+
this.Peers.matchInviteFirst(data)
|
|
136
165
|
// put in holding and then complete once save first complete
|
|
137
166
|
this.codenameUpdates.push(data)
|
|
138
167
|
})
|
|
@@ -170,6 +199,7 @@ class HolepunchWorker extends EventEmitter {
|
|
|
170
199
|
if (data.roletaken === 'server') {
|
|
171
200
|
// not unique info to match on yet.
|
|
172
201
|
} else {
|
|
202
|
+
// client path --->
|
|
173
203
|
let peerRole = this.Peers.matchCodename(data.publickey)
|
|
174
204
|
if (peerRole.name.length > 0) {
|
|
175
205
|
// receiving peer
|
|
@@ -289,7 +319,12 @@ class HolepunchWorker extends EventEmitter {
|
|
|
289
319
|
}
|
|
290
320
|
} else if (message.action === 'retry') {
|
|
291
321
|
let peerDefaults = this.Peers.peerMatchTopic(message.data.key)
|
|
292
|
-
this.Peers.discoveryMatch(message.data.key)
|
|
322
|
+
// this.Peers.discoveryMatch(message.data.key)
|
|
323
|
+
if (message.data.value.settopic === true) {
|
|
324
|
+
this.Peers.topicConnect(message.data.key, message.data.value.topic)
|
|
325
|
+
} else {
|
|
326
|
+
this.Peers.topicListen(message.data.value.topic, message.data.key)
|
|
327
|
+
}
|
|
293
328
|
} else if (message.action === 'peer-closed') {
|
|
294
329
|
this.flushConnections()
|
|
295
330
|
await this.swarm.destroy()
|