diff --git a/index.js b/index.js index 0178928..42c9bd2 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ const { EventEmitter } = require('events') const DHT = require('hyperdht') const spq = require('shuffled-priority-queue') const b4a = require('b4a') -const unslab = require('unslab') const PeerInfo = require('./lib/peer-info') const RetryTimer = require('./lib/retry-timer') @@ -424,7 +423,6 @@ module.exports = class Hyperswarm extends EventEmitter { // TODO: When you rejoin, it should reannounce + bump lookup priority join (topic, opts = {}) { if (!topic) throw new Error(ERR_MISSING_TOPIC) - topic = unslab(topic) const topicString = b4a.toString(topic, 'hex') diff --git a/lib/peer-discovery.js b/lib/peer-discovery.js index aeefe6d..6971595 100644 --- a/lib/peer-discovery.js +++ b/lib/peer-discovery.js @@ -1,5 +1,6 @@ const safetyCatch = require('safety-catch') const b4a = require('b4a') +const unslab = require('unslab') const REFRESH_INTERVAL = 1000 * 60 * 10 // 10 min const RANDOM_JITTER = 1000 * 60 * 2 // 2 min @@ -8,7 +9,7 @@ const DELAY_GRACE_PERIOD = 1000 * 30 // 30s module.exports = class PeerDiscovery { constructor (swarm, topic, { wait = null, suspended = false, onpeer = noop, onerror = safetyCatch }) { this.swarm = swarm - this.topic = topic + this.topic = unslab(topic) this.isClient = false this.isServer = false this.destroyed = false diff --git a/lib/peer-info.js b/lib/peer-info.js index 6d601ee..55f8005 100644 --- a/lib/peer-info.js +++ b/lib/peer-info.js @@ -95,7 +95,10 @@ module.exports = class PeerInfo extends EventEmitter { _topic (topic) { const topicString = b4a.toString(topic, 'hex') if (this._seenTopics.has(topicString)) return + this._seenTopics.add(topicString) + + topic = unslab(topic) this.topics.push(topic) this.emit('topic', topic) }