Skip to content

Commit

Permalink
Remove hasGossipProtocols
Browse files Browse the repository at this point in the history
The gossip codecs are now available on `GossipSub.multicodecs`.
Hence, the check can use this field instead of a function that uses
the constants.

This enables library consumers to set their own codecs by assigning a
different value to `GossipSub.multicodecs`.
  • Loading branch information
D4nte committed Jun 23, 2022
1 parent 475c861 commit 954046f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { MessageCache } from './message-cache.js'
import { RPC } from './message/rpc.js'
import * as constants from './constants.js'
import { createGossipRpc, shuffle, hasGossipProtocol, messageIdToString } from './utils/index.js'
import { createGossipRpc, shuffle, messageIdToString } from './utils/index.js'
import {
PeerScore,
PeerScoreParams,
Expand Down Expand Up @@ -2341,7 +2341,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements Initiali
const backoff = this.backoff.get(topic)
for (const id of shuffledPeers) {
const peerStreams = this.peers.get(id)
if (peerStreams && hasGossipProtocol(peerStreams.protocol) && !peers.has(id) && !this.direct.has(id)) {
if (peerStreams && this.multicodecs.includes(peerStreams.protocol) && !peers.has(id) && !this.direct.has(id)) {
const score = getScore(id)
if ((!backoff || !backoff.has(id)) && score >= 0) candidateMeshPeers.add(id)
// instead of having to find gossip peers after heartbeat which require another loop
Expand Down
5 changes: 0 additions & 5 deletions src/utils/has-gossip-protocol.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './create-gossip-rpc.js'
export * from './shuffle.js'
export * from './has-gossip-protocol.js'
export * from './messageIdToString.js'
export { getPublishConfigFromPeerId } from './publishConfig.js'

0 comments on commit 954046f

Please sign in to comment.