Fix typo + break outer loop

This commit is contained in:
alrevuelta 2023-09-01 12:10:07 +02:00
parent 40648c106f
commit 5782cf5901
No known key found for this signature in database
GPG Key ID: F345C9F3CCDB886E
2 changed files with 20 additions and 22 deletions

View File

@ -86,7 +86,7 @@ type
data: seq[byte]): Future[void] {.gcsafe, raises: [].}
ValidationStrategy* {.pure, public.} = enum
Paralel, Sequential
Parallel, Sequential
ValidatorHandler* {.public.} = proc(topic: string,
message: Message): Future[ValidationResult] {.gcsafe, raises: [].}
@ -520,26 +520,24 @@ method validate*(p: PubSub, message: Message): Future[ValidationResult] {.async,
result = ValidationResult.Accept
trace "about to validate message"
for topic in message.topicIds:
trace "looking for validators on topic", topicId = topic,
registered = toSeq(p.validators.keys)
if topic in p.validators:
trace "running validators for topic", topicId = topic
for validator in p.validators[topic]:
case p.validationStrategy
of ValidationStrategy.Paralel:
pending.add(validator(topic, message))
of ValidationStrategy.Sequential:
let validatorRes = await validator(topic, message)
# early break on first Reject/Ignore
if validatorRes != ValidationResult.Accept:
result = validatorRes
# TODO: Wrong, actually need to break two loops
# but don't get why message.topicIds is a seq. This
# will just work with message.topicIds.len = 1
break
block outer:
for topic in message.topicIds:
trace "looking for validators on topic", topicId = topic,
registered = toSeq(p.validators.keys)
if topic in p.validators:
trace "running validators for topic", topicId = topic
for validator in p.validators[topic]:
case p.validationStrategy
of ValidationStrategy.Parallel:
pending.add(validator(topic, message))
of ValidationStrategy.Sequential:
let validatorRes = await validator(topic, message)
# early break on first Reject/Ignore
if validatorRes != ValidationResult.Accept:
result = validatorRes
break outer
if p.validationStrategy == ValidationStrategy.Paralel:
if p.validationStrategy == ValidationStrategy.Parallel:
let futs = await allFinished(pending)
for fut in futs:
if fut.failed:
@ -566,7 +564,7 @@ proc init*[PubParams: object | bool](
anonymize: bool = false,
verifySignature: bool = true,
sign: bool = true,
validationStrategy: ValidationStrategy = ValidationStrategy.Paralel,
validationStrategy: ValidationStrategy = ValidationStrategy.Parallel,
msgIdProvider: MsgIdProvider = defaultMsgIdProvider,
subscriptionValidator: SubscriptionValidator = nil,
maxMessageSize: int = 1024 * 1024,

View File

@ -41,7 +41,7 @@ proc generateNodes*(
verifySignature: bool = libp2p_pubsub_verify,
anonymize: bool = libp2p_pubsub_anonymize,
sign: bool = libp2p_pubsub_sign,
validationStrategy: ValidationStrategy = ValidationStrategy.Paralel,
validationStrategy: ValidationStrategy = ValidationStrategy.Parallel,
sendSignedPeerRecord = false,
unsubscribeBackoff = 1.seconds,
maxMessageSize: int = 1024 * 1024,