holepunch-hop 0.3.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holepunch-hop",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "data interface to HOP",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/bees.js CHANGED
@@ -504,7 +504,6 @@ class HyperBee extends EventEmitter {
504
504
  savePeer = async function (peerInfo) {
505
505
  await this.dbPeers.put(peerInfo.publickey, peerInfo)
506
506
  let checkSave = await this.getPeer(peerInfo.publickey)
507
- console.log('save peer over---------')
508
507
  return checkSave
509
508
  }
510
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
  }