Skip to content

Commit

Permalink
Postpone unslab(topic) to when it's stored
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote committed Jul 30, 2024
1 parent f6b22a0 commit 502d8bf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')

Expand Down
3 changes: 2 additions & 1 deletion lib/peer-discovery.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/peer-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 502d8bf

Please sign in to comment.