-
Notifications
You must be signed in to change notification settings - Fork 54
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
test: Spammer #2821
Draft
vpavlin
wants to merge
5
commits into
rlnv2-only
Choose a base branch
from
rlnv2/spammer
base: rlnv2-only
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+163
−12
Draft
test: Spammer #2821
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab712ea
WIP: add network spammer code
vpavlin 8aa76dc
spammer is publishing messages at given rats
vpavlin 68869a9
add burst and auto-registration
vpavlin f8d09d0
nonce to reset if limit is reached
stubbsta 3a28684
use normal appendRLNProof instead of unsafe
stubbsta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
when (NimMajor, NimMinor) < (1, 4): | ||
{.push raises: [Defect].} | ||
else: | ||
{.push raises: [].} | ||
|
||
import | ||
chronos, | ||
chronicles, | ||
stew/[byteutils, results], | ||
std/times, | ||
libp2p/protocols/pubsub/gossipsub, | ||
strutils | ||
|
||
import | ||
../../waku/factory/waku, | ||
../../waku/factory/external_config, | ||
../../waku/waku_core, | ||
../../waku/waku_relay, | ||
../../waku/node/waku_node, | ||
../../waku/node/peer_manager/peer_manager, | ||
../../waku/waku_rln_relay/rln_relay, | ||
../../tests/waku_rln_relay/rln/waku_rln_relay_utils | ||
|
||
proc send( | ||
waku: Waku, contentTopic: ContentTopic | ||
): Future[Result[void, string]] {.async.} = | ||
var ephemeral = true | ||
|
||
var message = WakuMessage( | ||
payload: toBytes("Hello World!" & intToStr(int(getTime().toUnix()))), | ||
contentTopic: contentTopic, | ||
# meta: metaBytes, | ||
version: 2, | ||
timestamp: getNanosecondTime(getTime().toUnixFloat()), | ||
ephemeral: ephemeral, | ||
) | ||
|
||
let rlnRes = | ||
waku.node.wakuRlnRelay.appendRLNProof(message, float64(getTime().toUnix())) | ||
if rlnRes.isOk: | ||
let pubRes = await waku.node.publish(none(PubsubTopic), message) | ||
if pubRes.isErr(): | ||
error "failed to publish", msg = pubRes.error | ||
return err(pubRes.error) | ||
else: | ||
error "failed to append RLNProof", err = rlnRes.error | ||
return err(rlnRes.error) | ||
|
||
return ok() | ||
|
||
proc burstPublish( | ||
waku: Waku, conf: WakuNodeConf, contentTopic: ContentTopic | ||
) {.async.} = | ||
var futures: seq[Future[Result[void, string]]] | ||
var i: uint64 = 0 | ||
var start = getTime().toUnixFloat() | ||
|
||
while i < conf.rlnRelayUserMessageLimit: | ||
futures.add(send(waku, contentTopic)) | ||
inc i | ||
|
||
let results = await allFinished(futures) | ||
|
||
var current = getTime().toUnixFloat() | ||
var tillNextBurst = | ||
int(int64(conf.rlnEpochSizeSec * 1000) - int64((current - start) * 1000)) | ||
info "Published messages", | ||
sleep = tillNextBurst, msgCount = conf.rlnRelayUserMessageLimit | ||
|
||
await sleepAsync(tillNextBurst) | ||
|
||
proc iterativePublish( | ||
waku: Waku, conf: WakuNodeConf, contentTopic: ContentTopic | ||
) {.async.} = | ||
var start = getTime().toUnixFloat() | ||
|
||
(await send(waku, contentTopic)).isOkOr: | ||
error "Failed to publish", err = error | ||
|
||
#echo await (waku.node.isReady()) | ||
var current = getTime().toUnixFloat() | ||
var tillNextMsg = int(int64(conf.spammerDelay) - int64((current - start) * 1000)) | ||
info "Published message", sleep = tillNextMsg | ||
|
||
await sleepAsync(tillNextMsg) | ||
|
||
proc runSpammer*( | ||
waku: Waku, conf: WakuNodeConf, contentTopic: ContentTopic = "/spammer/0/test/plain" | ||
) {.async.} = | ||
if not conf.spammerEnable: | ||
return | ||
|
||
if not conf.rlnRelay: | ||
error "RLN not configured!" | ||
quit(QuitFailure) | ||
|
||
while true: | ||
var (inRelayPeers, outRelayPeers) = | ||
waku.node.peerManager.connectedPeers(WakuRelayCodec) | ||
|
||
var numPeers = len(inRelayPeers) + len(outRelayPeers) | ||
if numPeers > 0: | ||
break | ||
info "Waiting for peers", numPeers = numPeers | ||
await sleepAsync(1000) | ||
|
||
#var rate = int(float(1000) / float(conf.msgRate)) | ||
#var delayBetweenMsg = | ||
# float(conf.rlnEpochSizeSec * 1000) / | ||
# (float(conf.rlnRelayUserMessageLimit) * conf.msgRateMultiplier) | ||
|
||
info "Sending message with delay", delay = conf.spammerDelay | ||
|
||
while true: | ||
if conf.spammerBurst: | ||
await burstPublish(waku, conf, contentTopic) | ||
else: | ||
await iterativePublish(waku, conf, contentTopic) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
i
not needed?and here
for i in conf.rlnRelayUserMessageLimit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how Nim works:-P There is a function I could use to turn the msg limit into iterator, but I am not sure it is worth searching for it:D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah my bad. gues for i in 0..<conf.rlnRelayUserMessageLimit
no big deal tho