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

Various improvements #22

Merged
merged 4 commits into from
Dec 30, 2019
Merged

Various improvements #22

merged 4 commits into from
Dec 30, 2019

Conversation

lfos
Copy link
Contributor

@lfos lfos commented Dec 24, 2019

No description provided.

With the current subnet whitelist implementation, each lookup requires a
linear scan of the entire whitelist. If the whitelist contains millions
of entries, this can slow down connections significantly.

In other projects, CIDR lookups are often implemented using prefix
trees. This makes lookups very fast but the implementation is
significantly more complex.

An alternative, much simpler solution is to store the whitelisted
subnets in a hash set. To perform a query, one can then apply all 33
possible CIDR masks to the IP address and check whether any of the
resulting CIDR blocks exists in the hash set. With this implementation,
the time complexity of single lookups is still in O(1).

An additional speedup is achieved by maintaining a hash set of the CIDR
masks occurring in the whitelist, instead of always testing all 33
values.

Also, since a strict separation between IP address whitelists and subnet
whitelists are no longer needed, the two features are merged.
Currently, the link-connect debug information is squelched if the IP
address is whitelisted or does not have a Sender Score. Change this and
display the line for all IPv4 connections.
Replace the old formula d - (d / 100) * s by d * (100 - s) / 100 (where
d denotes the slow factor and s denotes the score).

The new formula does not only match to the expected behavior "interpret
the inverse score as a percentage and take that fraction of the slow
factor" more closely, it is also less prone to unwanted rounding
effects. For example, if the score is 100, the new formula is guaranteed
to yield a delay of 0, while the original formula might not.
@lfos
Copy link
Contributor Author

lfos commented Dec 24, 2019

These changes are based on the "constant time whitelist queries" patch which is included here for convenience. If all changes look good, it might be easier to just merge this PR and close #21.

@poolpOrg poolpOrg self-assigned this Dec 30, 2019
@poolpOrg poolpOrg merged commit 5dc15a2 into poolpOrg:master Dec 30, 2019
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.

2 participants