holepunch-hop 0.4.5 → 0.4.8

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "vitest.disableWorkspaceWarning": true
3
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "holepunch-hop",
3
- "version": "0.4.5",
3
+ "version": "0.4.8",
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": "mocha 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
- "assert": "^2.0.0",
46
- "mocha": "^10.0.0"
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
  }
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() + '/.hop-storage')
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
- // console.log(this.swarm.peers.size)
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 (ws) {
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()