-
Notifications
You must be signed in to change notification settings - Fork 47
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
Check for bogon IPs without API call & give more info #34
Conversation
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.
Great start. Some feedback that may require quite a few changes:
- We don't need
bogonType
, it's not even in our API actually and usually not valuable information. - Doing that means you don't need to be parsing with
gson
as you added - you can simply return aboolean
from someisBogon
helper, and iftrue
, just create a blankIPResponse
with onlyip
andbogon
set, and everything else shall default to empty strings or similar. - The list of strings containing bogon ranges - can we make that not within the function itself? Likely the JVM will optimize this away but we can help it a bit by making it always available globally as a static variable (or however it's done in Java).
- If bogon type doesn't matter, just create a single "bogon" string list, with comments in the code to separate them out. See for example our CLI that does a similar thing - https://github.com/ipinfo/cli/blob/master/lib/bogon.go
- As a further optimization, you should probably not even make it a 'string list', but rather a 'IpAddressMatcher list', because then you don't have to re-initialize a separate 'IpAddressMatcher' for every single item in the list each time you run the bogon check function, that's lots of extra computations for no reason.
- Just to confirm,
matches
just checks to see if the input IP address is 'within' the CIDR right? Likecidr_start <= ip <= cidr_end
is its effective operation, correct? I'm a bit confused when skimming its logic because usually to check this, in the CLI I simply converted those 3 variables in the equation into numbers (64-bit for IPv4, 128-bit for IPv6 using a home-grown 128-bit library in https://github.com/ipinfo/cli/blob/master/lib/u128.go), and the comparison is then purely numerical. But this is doing something else, or is it? - It works fine with IPv6 bogons correct?
Yes, essentially it is checking if the IP is within the CIDR. It does so by seeing if the network bits of the bogon range and the corresponding bits of the IP Address match exactly. Works fine for IPv6: IPResponse response = ipInfo.lookupIP("2001:0:c000:200::0:255:1");
System.out.println(response); // IPResponse{ip='2001:0:c000:200::0:255:1', bogon='true'} |
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.
Looks good but can we just write a test case or two? If all works let's merge.
…add new tests for bogon
F y'all . Real cute I give y'all that.. but not as cute was y'all think..
…On Tue, Oct 11, 2022, 9:34 PM Uman Shahzad ***@***.***> wrote:
Merged #34 <#34> into master.
—
Reply to this email directly, view it on GitHub
<#34 (comment)>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZWQCMIAXQLZHOD52P4TH7DWCYISPANCNFSM6AAAAAAQ3KUKEE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Resolves #27