-
Notifications
You must be signed in to change notification settings - Fork 1
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
Canonical form for IP addresses #18
Comments
As far as implementation for this goes. I'm thinking we have a The host address will be stored in the raw byte form, We can call this |
I thought the ip-num library we are using already have classes for this. I want to maintain a distinction between This is because downstream systems will take only strings. And we need these opaque types to classify the different strings. Any class used for advanced operations is more of a transformer to and from these different forms. |
Honestly I prefer mapping functions. Do not use classes or objects here. It will get confusing when doing serialisation or deserialisation. |
For As for the conversion methods we need ones for
|
* added conversions from V4 to V6 mapped, both Dec and hex types. * Added isX for mappedV4 dec and hex. added a helper toCanonicalIp to convert all format types to the canonical form. * Related #18 [ci skip]
I've expanded the transforms. Mostly added ipv4 -> ipv6 mapped hex and dec form, and isX checkers for the IPv6 mapped hex and dec form. I also added a function that transforms all formats to the canonical format. It's pretty simple in that it converts all the mapped forms to IPv4 dec, and all normal IPv6 and IPv4 are left unchanged I've updated the tests with the changes, adding new tests where needed, I don't know if this fully covers this issue so I haven't resolved it yet. Let me know if I'm missing anything or mis-interpreted something. @CMCDragonkai |
I'm going to merge the changes and resolve this. Anything more should be addressed in polykey with respect to the node graph. I'll make a new issue in Polykey repo for this? |
These functions may be more useful in PK than in js-quic. It all depends on integration. Which is why we must start now in order to iron out any problems. |
* added conversions from V4 to V6 mapped, both Dec and hex types. * Added isX for mappedV4 dec and hex. added a helper toCanonicalIp to convert all format types to the canonical form. * Fixes #18 [ci skip]
Specification
There are multiple ways to represent IP addresses.
IPv4
specifically has 3 ways,IPv6
mapped form::ffff:127.0.0.1
, normal form,127.0.0.1
and the hex form::ffff:7f00:1
. Theses 3 forms represent the sameIPv4
address.If we need to store this address in the database we can't use all 3 representations although they are equivalent. We need a canonical form for storing and manipulating the address.
To this end we need to create a helper class that stores the address as the canonical form, we can use the raw byte form representing an
A
address forIPv4
and anAAAA
address forIPv6
. Theses are 4 and 16 bytes respectively.From the canonical byte form we can map the address to all supported formats.
Additional context
dgram
module #1Tasks
The text was updated successfully, but these errors were encountered: