-
Notifications
You must be signed in to change notification settings - Fork 283
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
base: master
Are you sure you want to change the base?
Implement Jitter #81
Conversation
3e77675
to
0c0aa04
Compare
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 |
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 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); |
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.
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? |
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 check for negative or too big (>100?) values?
Thanks for this awesome code-review @skeeto . This issues are fixed and I have also documented the feature in the Manpage. |
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.