mirror of https://github.com/waku-org/nwaku.git
feat(discv5): filter out peers without any listed capability (#2186)
This commit is contained in:
parent
b9563ae0b5
commit
200a11da09
|
@ -320,6 +320,7 @@ procSuite "Waku Discovery v5":
|
||||||
|
|
||||||
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
||||||
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
||||||
|
builder.withWakuCapabilities(Relay)
|
||||||
|
|
||||||
let recordRes = builder.build()
|
let recordRes = builder.build()
|
||||||
require recordRes.isOk()
|
require recordRes.isOk()
|
||||||
|
@ -338,6 +339,7 @@ procSuite "Waku Discovery v5":
|
||||||
|
|
||||||
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
||||||
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
||||||
|
builder.withWakuCapabilities(Relay)
|
||||||
|
|
||||||
let recordRes = builder.build()
|
let recordRes = builder.build()
|
||||||
require recordRes.isOk()
|
require recordRes.isOk()
|
||||||
|
@ -356,6 +358,7 @@ procSuite "Waku Discovery v5":
|
||||||
|
|
||||||
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
||||||
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
||||||
|
builder.withWakuCapabilities(Relay)
|
||||||
|
|
||||||
let recordRes = builder.build()
|
let recordRes = builder.build()
|
||||||
require recordRes.isOk()
|
require recordRes.isOk()
|
||||||
|
|
|
@ -52,25 +52,19 @@ type WakuDiscoveryV5* = ref object
|
||||||
|
|
||||||
proc shardingPredicate*(record: Record): Option[WakuDiscv5Predicate] =
|
proc shardingPredicate*(record: Record): Option[WakuDiscv5Predicate] =
|
||||||
## Filter peers based on relay sharding information
|
## Filter peers based on relay sharding information
|
||||||
|
let typedRecord = record.toTyped().valueOr:
|
||||||
|
debug "peer filtering failed", reason=error
|
||||||
|
return none(WakuDiscv5Predicate)
|
||||||
|
|
||||||
let typeRecordRes = record.toTyped()
|
let nodeShard = typedRecord.relaySharding().valueOr:
|
||||||
let typedRecord =
|
debug "no relay sharding information, peer filtering disabled"
|
||||||
if typeRecordRes.isErr():
|
return none(WakuDiscv5Predicate)
|
||||||
debug "peer filtering failed", reason= $typeRecordRes.error
|
|
||||||
return none(WakuDiscv5Predicate)
|
|
||||||
else: typeRecordRes.get()
|
|
||||||
|
|
||||||
let nodeShardOp = typedRecord.relaySharding()
|
|
||||||
let nodeShard =
|
|
||||||
if nodeShardOp.isNone():
|
|
||||||
debug "no relay sharding information, peer filtering disabled"
|
|
||||||
return none(WakuDiscv5Predicate)
|
|
||||||
else: nodeShardOp.get()
|
|
||||||
|
|
||||||
debug "peer filtering updated"
|
debug "peer filtering updated"
|
||||||
|
|
||||||
let predicate = proc(record: waku_enr.Record): bool =
|
let predicate = proc(record: waku_enr.Record): bool =
|
||||||
nodeShard.shardIds.anyIt(record.containsShard(nodeShard.clusterId, it))
|
record.getCapabilities().len > 0 and #RFC 31 requirement
|
||||||
|
nodeShard.shardIds.anyIt(record.containsShard(nodeShard.clusterId, it)) #RFC 64 guideline
|
||||||
|
|
||||||
return some(predicate)
|
return some(predicate)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue