]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.api.uuid/src/org/argeo/api/uuid/NodeIdSupplier.java
Remove dependencies to System.getLogger, for Android compatibility.
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / NodeIdSupplier.java
index ae9686c7042781348643295ef29f58a302b510b6..81d368d2c8c651c37ea9ab48f7f048db98351f16 100644 (file)
@@ -1,15 +1,13 @@
 package org.argeo.api.uuid;
 
+import java.security.SecureRandom;
 import java.util.function.Supplier;
 
 /** A factory for node id base */
 public interface NodeIdSupplier extends Supplier<Long> {
-       long LEAST_SIG_RFC4122_VARIANT = (1l << 63);
-
        static long toNodeIdBase(byte[] node) {
                assert node.length == 6;
-               return LEAST_SIG_RFC4122_VARIANT // base for Leach–Salz UUID
-                               | (node[0] & 0xFFL) //
+               return UuidFactory.LEAST_SIG_RFC4122_VARIANT | (node[0] & 0xFFL) //
                                | ((node[1] & 0xFFL) << 8) //
                                | ((node[2] & 0xFFL) << 16) //
                                | ((node[3] & 0xFFL) << 24) //
@@ -17,4 +15,14 @@ public interface NodeIdSupplier extends Supplier<Long> {
                                | ((node[5] & 0xFFL) << 40); //
        }
 
+       static boolean isNoMacAddressNodeId(byte[] nodeId) {
+               return (nodeId[0] & 1) != 0;
+       }
+
+       static byte[] randomNodeId() {
+               SecureRandom random = new SecureRandom();
+               byte[] nodeId = new byte[6];
+               random.nextBytes(nodeId);
+               return nodeId;
+       }
 }