Hard Light Productions Forums
Off-Topic Discussion => General Discussion => Topic started by: aldo_14 on December 31, 2004, 05:10:30 am
-
I'm kind of stumpted at this, but I know there should be a way....... I want to automatically generate a GUID for nodes based upon either/or/and their ip address, port and the system time created (in ms).
The only problem is that the existing code I'm working with makes quite heavy use of arrays for bootstrapping said nodes, which means I need to get a reliably unique int id (which means I can't directly map the ip details to a long or string without breaking array referencing and also a bunch of the message formatting & routing code). The actual 32-bit int range isn't a problem in itself, getting a unique value is.
I've been considering using the UID class in java.rmi (or rather, the hashCode generated) for this, but i'm not sure on how to guarentee / test the uniqueness of this method. And I'm struggling to find too much clear information on the 'net, so I'm asking here.
Any suggestions would be muchly appreciated. (well, duh. Why else would I ask?)
(This is being written in java, obviously - but all I really need is pseudo/code for a non-library dependent solution if someone, for example, knows a good algorith for this in C or c++, etc).
Oh, and part of it was written by other people; my jobs to extend it and help commericialize it. Hence I'm having to fix these stupid little things whilst I'm at it.
-
If you're going to use UUIDs there're 2^64 possiblilities and so it'll be virtually impossible to get a non-unique UUID.
These links might help:
http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt (has sample code) http://www.opengroup.org/onlinepubs/9629399/apdxa.htm
http://en.wikipedia.org/wiki/UUID
-
The issue isn't generating a UUID per se - it's getting a 32 bit one that I can store in an int field. I don't mean UUID as in the standardized meaning (which is unique only be probability anyway, IIRC), i mean as in the generic meaning of a unique identifier set across different locations... I can't assign these via some central assignment object, because it's a deliberately distributed system that is specifically trying to avoid central points of bottleneck (including the management system I have to integrate with it....pain in the arse, may I add)
I can't use a >32 bit Id because of the code structure, though; at least, not without a massive refactoring and a lot of type changes. I'm trying to get a Id which is guarenteed to be "reasonably" unique... there are certain code limitations which can be used to restrict the Id values (for example, each port can only be bound to by one machine, so I can base it on ip:port).
I guess the key thing I'm looking for is to generate a unique int value from an ip+port value..... I'm sure there must be some existing algorithm to do this. At the moment I'm simply using user-specified ids or the results java.rmi.UUID.hashCode(), but neither is guarentted unique.
-
You should be able to do that with the JavaRMI API, probably using hashtables as you mentioned (I did something like this for my last coursework, sadly I can't remember it now!). You know the drill by now, go fumble with the API docs on the sun website till you find the solution ;)
-
The java code for objects doesn't guarantee a distinct hashcode for distinct objects, natch... I don't know what the (um) collision rate for hashodes for uuids, etc, is.