/** * Returns the result of {@link #bestAvailableMac()} if non-{@code null} otherwise returns a random EUI-64 MAC * address. */ public static byte[] defaultMachineId() { byte[] bestMacAddr = bestAvailableMac(); if (bestMacAddr == null) { bestMacAddr = new byte[EUI64_MAC_ADDRESS_LENGTH]; PlatformDependent.threadLocalRandom().nextBytes(bestMacAddr); logger.warn( "Failed to find a usable hardware address from the network interfaces; using random bytes: {}", formatAddress(bestMacAddr)); } return bestMacAddr; }
int res = compareAddresses(bestMacAddr, macAddr); if (res < 0) { } else if (res == 0) { res = compareAddresses(bestInetAddr, inetAddr); if (res < 0) {
/** * @return positive - current is better, 0 - cannot tell, negative - candidate is better */ private static int compareAddresses(InetAddress current, InetAddress candidate) { return scoreAddress(current) - scoreAddress(candidate); }
case 17: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI48_MAC_ADDRESS_LENGTH]; break; case 23: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI64_MAC_ADDRESS_LENGTH]; break;
private static String getUniquifierPrefix() { // To make a request ID globally unique, we will add MAC-based machine ID and a random number. // The random number tries to make this instance unique in the same machine and process. final byte[] r = new byte[6]; ThreadLocalRandom.current().nextBytes(r); final Encoder encoder = Base64.getEncoder(); return new StringBuilder().append(encoder.encodeToString(defaultMachineId())) .append(encoder.encodeToString(r)) .toString(); } }
case 17: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI48_MAC_ADDRESS_LENGTH]; break; case 23: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI64_MAC_ADDRESS_LENGTH]; break;
private static String getUniquifierPrefix() { // To make a request ID globally unique, we will add MAC-based machine ID and a random number. // The random number tries to make this instance unique in the same machine and process. final byte[] r = new byte[6]; ThreadLocalRandom.current().nextBytes(r); final Encoder encoder = Base64.getEncoder(); return new StringBuilder().append(encoder.encodeToString(defaultMachineId())) .append(encoder.encodeToString(r)) .toString(); } }
/** * Returns the result of {@link #bestAvailableMac()} if non-{@code null} otherwise returns a random EUI-64 MAC * address. */ public static byte[] defaultMachineId() { byte[] bestMacAddr = bestAvailableMac(); if (bestMacAddr == null) { bestMacAddr = new byte[EUI64_MAC_ADDRESS_LENGTH]; PlatformDependent.threadLocalRandom().nextBytes(bestMacAddr); logger.warn( "Failed to find a usable hardware address from the network interfaces; using random bytes: {}", formatAddress(bestMacAddr)); } return bestMacAddr; }
/** * @return positive - current is better, 0 - cannot tell, negative - candidate is better */ private static int compareAddresses(InetAddress current, InetAddress candidate) { return scoreAddress(current) - scoreAddress(candidate); }
case 17: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI48_MAC_ADDRESS_LENGTH]; break; case 23: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI64_MAC_ADDRESS_LENGTH]; break;
int res = compareAddresses(bestMacAddr, macAddr); if (res < 0) { } else if (res == 0) { res = compareAddresses(bestInetAddr, inetAddr); if (res < 0) {
/** * Returns the result of {@link #bestAvailableMac()} if non-{@code null} otherwise returns a random EUI-64 MAC * address. */ public static byte[] defaultMachineId() { byte[] bestMacAddr = bestAvailableMac(); if (bestMacAddr == null) { bestMacAddr = new byte[EUI64_MAC_ADDRESS_LENGTH]; PlatformDependent.threadLocalRandom().nextBytes(bestMacAddr); logger.warn( "Failed to find a usable hardware address from the network interfaces; using random bytes: {}", formatAddress(bestMacAddr)); } return bestMacAddr; }
/** * @return positive - current is better, 0 - cannot tell, negative - candidate is better */ private static int compareAddresses(InetAddress current, InetAddress candidate) { return scoreAddress(current) - scoreAddress(candidate); }
case 17: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI48_MAC_ADDRESS_LENGTH]; break; case 23: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI64_MAC_ADDRESS_LENGTH]; break;
int res = compareAddresses(bestMacAddr, macAddr); if (res < 0) { } else if (res == 0) { res = compareAddresses(bestInetAddr, inetAddr); if (res < 0) {
/** * Returns the result of {@link #bestAvailableMac()} if non-{@code null} otherwise returns a random EUI-64 MAC * address. */ public static byte[] defaultMachineId() { byte[] bestMacAddr = bestAvailableMac(); if (bestMacAddr == null) { bestMacAddr = new byte[EUI64_MAC_ADDRESS_LENGTH]; PlatformDependent.threadLocalRandom().nextBytes(bestMacAddr); logger.warn( "Failed to find a usable hardware address from the network interfaces; using random bytes: {}", formatAddress(bestMacAddr)); } return bestMacAddr; }
/** * @return positive - current is better, 0 - cannot tell, negative - candidate is better */ private static int compareAddresses(InetAddress current, InetAddress candidate) { return scoreAddress(current) - scoreAddress(candidate); }
case 17: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI48_MAC_ADDRESS_LENGTH]; break; case 23: separator = value.charAt(2); validateMacSeparator(separator); machineId = new byte[EUI64_MAC_ADDRESS_LENGTH]; break;
int res = compareAddresses(bestMacAddr, macAddr); if (res < 0) { } else if (res == 0) { res = compareAddresses(bestInetAddr, inetAddr); if (res < 0) {
/** * Returns the result of {@link #bestAvailableMac()} if non-{@code null} otherwise returns a random EUI-64 MAC * address. */ public static byte[] defaultMachineId() { byte[] bestMacAddr = bestAvailableMac(); if (bestMacAddr == null) { bestMacAddr = new byte[EUI64_MAC_ADDRESS_LENGTH]; PlatformDependent.threadLocalRandom().nextBytes(bestMacAddr); logger.warn( "Failed to find a usable hardware address from the network interfaces; using random bytes: {}", formatAddress(bestMacAddr)); } return bestMacAddr; }