-1

Recently I learn how to generate UUID. I find the class TimeBasedUUIDGenerator.java in elasticsearch.

I find it use mac adress to identify current machine(MacAddressProvide.java). But it XOR the mac adress with random bytes (as the code snippet below). As I know this will make the mac adress to random and increase the probability of conflict. Why we don't use mac adress directly?

public static byte[] getSecureMungedAddress() {
    byte[] address = null;
    try {
        address = getMacAddress();
    } catch (SocketException e) {
        // address will be set below
    }

    if (!isValidAddress(address)) {
        address = constructDummyMulticastAddress();
    }

    byte[] mungedBytes = new byte[6];
    SecureRandomHolder.INSTANCE.nextBytes(mungedBytes);
    for (int i = 0; i < 6; ++i) {
        mungedBytes[i] ^= address[i];
    }

    return mungedBytes;
}
bluearrow
  • 856
  • 2
  • 11
  • 26

1 Answers1

0

The code author is not sure about this either.

He said the reason may be not reveal the server's real mac address for security concern.

I think this also enable multi UUID generators deploy in the same server.

bluearrow
  • 856
  • 2
  • 11
  • 26