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

Add missing msgId in validateReceivedMessage #215

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Changes from all commits
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
36 changes: 18 additions & 18 deletions ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,23 @@ export default class Gossipsub extends EventEmitter {
topic: rpcMsg.topic
}

// TODO: Check if message is from a blacklisted source or propagation origin
// - Reject any message from a blacklisted peer
// - Also reject any message that originated from a blacklisted peer
// - reject messages claiming to be from ourselves but not locally published

// Calculate the message id on the transformed data.
const msgIdStr = msgIdCached ?? messageIdToString(await this.msgIdFn(msg))

// Add the message to the duplicate caches
if (fastMsgIdStr) this.fastMsgIdCache?.put(fastMsgIdStr, msgIdStr)

if (this.seenCache.has(msgIdStr)) {
return { code: MessageStatus.duplicate, msgId: msgIdStr }
} else {
this.seenCache.put(msgIdStr)
}

// (Optional) Provide custom validation here with dynamic validators per topic
// NOTE: This custom topicValidator() must resolve fast (< 100ms) to allow scores
// to not penalize peers for long validation times.
Expand All @@ -987,27 +1004,10 @@ export default class Gossipsub extends EventEmitter {
}

if (acceptance !== MessageAcceptance.Accept) {
return { code: MessageStatus.invalid, reason: rejectReasonFromAcceptance(acceptance) }
return { code: MessageStatus.invalid, reason: rejectReasonFromAcceptance(acceptance), msgId: msgIdStr }
}
}

// TODO: Check if message is from a blacklisted source or propagation origin
// - Reject any message from a blacklisted peer
// - Also reject any message that originated from a blacklisted peer
// - reject messages claiming to be from ourselves but not locally published

// Calculate the message id on the transformed data.
const msgIdStr = msgIdCached ?? messageIdToString(await this.msgIdFn(msg))

// Add the message to the duplicate caches
if (fastMsgIdStr) this.fastMsgIdCache?.put(fastMsgIdStr, msgIdStr)

if (this.seenCache.has(msgIdStr)) {
return { code: MessageStatus.duplicate, msgId: msgIdStr }
} else {
this.seenCache.put(msgIdStr)
}

return { code: MessageStatus.valid, msgIdStr, msg }
}

Expand Down