Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: graft/prune events and mesh peer tagging #383

Merged
merged 17 commits into from
Feb 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@
const now = Date.now()
let doPX = this.opts.doPX

graft.forEach(({ topicID }) => {
graft.forEach(async ({ topicID }) => {
maschad marked this conversation as resolved.
Show resolved Hide resolved
if (!topicID) {
return
}
Expand Down Expand Up @@ -1545,22 +1545,22 @@
peersInMesh.add(id)

this.metrics?.onAddToMesh(topicID, InclusionReason.Subscribed, 1)

if (this.opts?.taggingEnabled ?? false) {
await this.components.peerStore.merge(peerIdFromString(id), {
tags: {
[topicID]: {
value: 100 // value should be 0-100
}
}
})
}
})

if (!prune.length) {
return []
}

if (this.opts?.taggingEnabled ?? false) {
await this.components.peerStore.merge(peerIdFromString(id), {
tags: {
'gossipsub-mesh-peer': {
value: 100 // value should be 0-100
}
}
})
}

const onUnsubscribe = false
return await Promise.all(prune.map((topic) => this.makePrune(id, topic, doPX, onUnsubscribe)))
}
Expand Down Expand Up @@ -1609,14 +1609,14 @@
}
await this.pxConnect(peers)
}
}

if (this.opts?.taggingEnabled ?? false) {
await this.components.peerStore.save(peerIdFromString(id), {
tags: {
'gossipsub-mesh-peer': {}
}
})
if (this.opts?.taggingEnabled ?? false) {
await this.components.peerStore.save(peerIdFromString(id), {
tags: {
[topicID]: {}
}
})
}
}
}

Expand Down Expand Up @@ -2225,7 +2225,7 @@
if (this.opts?.taggingEnabled ?? false) {
await this.components.peerStore.merge(peerIdFromString(id), {
tags: {
'gossipsub-mesh-peer': {
[topic]: {
value: 100 // value should be 0-100
}
}
Expand All @@ -2246,7 +2246,7 @@
if (this.opts.taggingEnabled ?? false) {
await this.components.peerStore.save(peerIdFromString(id), {
tags: {
'gossipsub-mesh-peer': {}
[topic]: {}
}
})
}
Expand Down Expand Up @@ -2500,7 +2500,7 @@

try {
peerInfo = await this.components.peerStore.get(id)
} catch (err: any) {

Check warning on line 2503 in src/index.ts

View workflow job for this annotation

GitHub Actions / check

Unexpected any. Specify a different type
if (err.code !== 'ERR_NOT_FOUND') {
throw err
}
Expand Down
Loading