Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Add safeguard for handling rpcs. Reset TimeCache on unsubscribe. Give…
Browse files Browse the repository at this point in the history
… some time to peers to connect.
  • Loading branch information
haadcode committed Mar 20, 2017
1 parent 203257c commit 8d2ee5b
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/index.js
Expand Up @@ -93,7 +93,7 @@ class FloodSub extends EventEmitter {
peer.attachConnection(conn)

// Immediately send my own subscriptions to the newly established conn
peer.sendSubscriptions(this.subscriptions)
setImmediate(() => peer.sendSubscriptions(this.subscriptions))
setImmediate(() => callback())
}

Expand Down Expand Up @@ -137,21 +137,24 @@ class FloodSub extends EventEmitter {

if (subs && subs.length) {
const peer = this.peers.get(idB58Str)
peer.updateSubscriptions(subs)

subs.forEach((sub) => {
if (!sub.subscribe) {
return
}
const topic = sub.topicCID

const msg = this._lvc.get(topic)
if (msg) {
this.peers.forEach((peer) => {
this._sendSafeMessages(peer, [topic], [msg])
})
}
})

if (peer) {
peer.updateSubscriptions(subs)

subs.forEach((sub) => {
if (!sub.subscribe) {
return
}
const topic = sub.topicCID

const msg = this._lvc.get(topic)
if (msg) {
this.peers.forEach((peer) => {
this._sendSafeMessages(peer, [topic], [msg])
})
}
})
}
}

if (msgs && msgs.length) {
Expand Down Expand Up @@ -362,6 +365,8 @@ class FloodSub extends EventEmitter {
this.peers.forEach((peer) => {
peer.sendUnsubscriptions(topics)
})

this.cache = new TimeCache()
}
}

Expand Down

0 comments on commit 8d2ee5b

Please sign in to comment.