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

Implement Jitter #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Implement Jitter #81

wants to merge 2 commits into from

Conversation

Thomas131
Copy link

fixes #71

In a simple test everything seemed to work well.

Documentation needs to be done, but I can't really get along with the manpage-Syntax.

@Thomas131 Thomas131 force-pushed the master branch 2 times, most recently from 3e77675 to 0c0aa04 Compare March 10, 2022 14:43
endlessh.c Outdated
@@ -105,6 +106,12 @@ logsyslog(enum loglevel level, const char *format, ...)
}
}

static long long random_delay(int delay, float jitter) {
long long tmp = delay*jitter;
tmp = delay+(rand()%(2*tmp))-tmp; //insecure rand() was used on purpose to avoid potential performance bottleneck
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on undefined behavior if jitter is 0.
Maybe add something like

if (jitter <= 0)
    return delay;

endlessh.c Outdated
{
errno = 0;
char *end;
float tmp = strtof(s, &end);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why parse as float? Are per mille values useful?

endlessh.c Outdated
errno = 0;
char *end;
float tmp = strtof(s, &end);
if (errno || *end) { //TODO: additional checks?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check for negative or too big (>100?) values?

@Thomas131
Copy link
Author

Thanks for this awesome code-review @skeeto . This issues are fixed and I have also documented the feature in the Manpage.

@Thomas131 Thomas131 changed the title Implement Jitter [WIP: Documentation missing] Implement Jitter Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Random message delay?
2 participants