holepunch-hop 0.4.0 → 0.4.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holepunch-hop",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "data interface to HOP",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/bees.js CHANGED
@@ -52,6 +52,7 @@ class HyperBee extends EventEmitter {
52
52
  const discovery = this.swarm.join(this.dbPublicLibrary.discoveryKey)
53
53
  // Only display the key once the Hyperbee has been announced to the DHT
54
54
  discovery.flushed().then(() => {
55
+ console.log('public library open')
55
56
  })
56
57
 
57
58
  const core2 = this.store.get({ name: 'peerlibrary' })
package/src/index.js CHANGED
@@ -55,10 +55,10 @@ class HolepunchWorker extends EventEmitter {
55
55
 
56
56
  this.swarm.on('update', () => {
57
57
  // this.Peers.updateListen(data)
58
- console.log('update-------')
59
- console.log(this.swarm.connecting)
60
- console.log(this.swarm.connections.size)
61
- console.log(this.swarm.peers.size)
58
+ // console.log('update-------')
59
+ // console.log(this.swarm.connecting)
60
+ // console.log(this.swarm.connections.size)
61
+ // console.log(this.swarm.peers.size)
62
62
  })
63
63
 
64
64
 
@@ -284,12 +284,9 @@ class HolepunchWorker extends EventEmitter {
284
284
  }
285
285
  }
286
286
  } else if (message.action === 'retry') {
287
- console.log('retry')
288
287
  let peerDefaults = this.Peers.peerMatchTopic(message.data.key)
289
288
  this.Peers.discoveryMatch(message.data.key)
290
289
  } else if (message.action === 'peer-closed') {
291
- console.log('distroy swarm connections')
292
- console.log(message)
293
290
  this.flushConnections()
294
291
  await this.swarm.destroy()
295
292
  // this.flushConnections()
@@ -446,10 +443,6 @@ class HolepunchWorker extends EventEmitter {
446
443
  *
447
444
  */
448
445
  flushConnections = async function () {
449
- console.log('flush connections')
450
- console.log(this.swarm.connections.size)
451
- console.log(this.swarm.connecting)
452
- console.log(this.swarm.peers.size)
453
446
  await this.swarm.flush()
454
447
  await Promise.all(Array.from(this.swarm.connections).map(e => e.flush()))
455
448
  await new Promise(resolve => setImmediate(resolve))
package/src/peers.js CHANGED
@@ -230,7 +230,6 @@ class NetworkPeers extends EventEmitter {
230
230
 
231
231
  conn.on('error', data => {
232
232
  let connectLivekeys = Object.keys(this.peerConnect)
233
- // console.log(this.peerNetwork)
234
233
  for (let peer of this.peerNetwork) {
235
234
  for (let pconn of connectLivekeys) {
236
235
  if (peer.value.livePeerkey === pconn) {
@@ -257,8 +256,8 @@ class NetworkPeers extends EventEmitter {
257
256
  *
258
257
  */
259
258
  updateListen = function (data) {
260
- console.log('update listen')
261
- console.log(data)
259
+ // console.log('update listen')
260
+ // console.log(data)
262
261
  }
263
262
 
264
263
  /**
@@ -453,7 +452,12 @@ class NetworkPeers extends EventEmitter {
453
452
  originalKey = savePeer.key
454
453
  }
455
454
  }
456
- return originalKey
455
+ // check if first time peer connect
456
+ if (originalKey.length === 0) {
457
+ return currPubKey
458
+ } else {
459
+ return originalKey
460
+ }
457
461
  }
458
462
 
459
463
  /**
@@ -764,7 +768,6 @@ class NetworkPeers extends EventEmitter {
764
768
  *
765
769
  */
766
770
  topicConnect = async function (peerID, topic) {
767
- console.log('topic connect')
768
771
  // const noisePublicKey = Buffer.alloc(32).fill(topic) // A topic must be 32 bytes
769
772
  const noisePublicKey = Buffer.from(topic, 'hex') // must be 32 bytes
770
773
  if (noisePublicKey.length === 32) {
@@ -783,7 +786,6 @@ class NetworkPeers extends EventEmitter {
783
786
  *
784
787
  */
785
788
  topicListen = async function (topic, peerKey) {
786
- console.log('topic listen')
787
789
  // const noisePublicKey = Buffer.alloc(32).fill(topic) // A topic must be 32 bytes
788
790
  // let topicKeylive = noisePublicKey.toString('hex')
789
791
  const noisePublicKey = Buffer.from(topic, 'hex') // must be 32 bytes