starrs icon indicating copy to clipboard operation
starrs copied to clipboard

Better free-address finder

Open clockfort opened this issue 12 years ago • 10 comments

Ranges would be 1000x easier to expand / shrink halfway through the year when one of them fills, etc, if when someone registers a machine and impulse assigns them an IP from the requested range that it gave people IP addresses from the middle first and expanded outwards in both directions from the middle for assigning new addresses.

clockfort avatar Jul 25 '12 18:07 clockfort

api.get_address_from_range() grabs the lowest non-assigned address from the given range. So if {1, 2, 3, 4, 5, 6} are assigned, the function would return 7 (assuming the range is from say {1..10}). If 3 is deleted, the function would return 3.

cohoe avatar Jul 25 '12 18:07 cohoe

pseudocode: (you have no idea how hard it is for me to not make this functional :-P )

firstHalf, secondHalf = split(range, range/2)
firstHalf = reverse firstHalf
for( i=0; i < max(firstHalf, secondHalf); ++i){
    try{
    if( free( firstHalf[i] ) ){
        return firstHalf[i]
    else if ( free( secondHalf[i] ) ){
         return secondHalf[i]
    }
    } catch IndexOutOfBounds{ }
}
throw OutOfAddressesError;

clockfort avatar Jul 25 '12 19:07 clockfort

That seems way more complicated than it needs to be. Splitting into two halves won't solve the "All addresses are in use!" problem. Pseudocode:

select first available address from all_addresses between first_ip and last_ip where address is not in system_addresses
if no address then error "All addresses in range are in use!"

cohoe avatar Jul 25 '12 20:07 cohoe

The point is just to allocate addresses starting from the middle, rather than just doing "first-free".

The half-split partial reverse simultaneous walk is just an easy way to "expand from the middle".

shrug You don't have to implement it, lol

The way it "solves" the "everything is in use" problem is that other address ranges next to it will have free space you can then manually re-allocate into that address range, since they are middle-populated as well.

clockfort avatar Jul 25 '12 22:07 clockfort

All it's saying is if you have:

ranges: [1, 2, 3, 4, 5, 6, 7, 8] and [9, 10, 11, 12, 13, 14, 15]

and you fill up [1-8], you can just edit it to be [1-10] since you only have filled 11,12, 13 in the next range over.

(As opposed to current method, where you've filled [1-8] and allocated 9, 10 and 11 so you're all like "fuckkkkk why didn't I think ahead" and have to go through a lot of trouble to move people around to expand the range.)

clockfort avatar Jul 25 '12 22:07 clockfort

OK, I see what you mean. Unfortunately without blowing away everyones registrations again (which I am not opposed to) There is no good way to implement it for CSH. Though it could be included in the codebase for other installations...

cohoe avatar Jul 25 '12 23:07 cohoe

If you include it now eventually CSH IP entropy will hit a steady state where it will help :-P

I'm playing the long game.

clockfort avatar Jul 26 '12 06:07 clockfort

Moving to Long-Term (probably next summer haha). I'm done writing new functionality for this one. Feel free to code it up and do a pull request.

cohoe avatar Jul 26 '12 18:07 cohoe

Okay. If I learn PGScript I'll rewrite all the things :-)

clockfort avatar Jul 26 '12 19:07 clockfort

The file you want is at API/IP/api_ip_get.sql

cohoe avatar Jul 27 '12 13:07 cohoe