]> pd.if.org Git - uuid/commitdiff
Removed unused node variable.
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 30 Sep 2012 19:48:29 +0000 (19:48 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 30 Sep 2012 19:54:35 +0000 (19:54 +0000)
The node is now calculated by read_state and in the state
structure.  The node could be reset by re-initializing
the state or calling the read state function.  Given that
the mac address is just used to provide additional uniqueness
its actual value doesn't really matter, so assuming it
wasn't just a bunch of zeroes or similar, there shouldn't
be any reason to re-determine it.

Makefile
internal.c
pduuid.h
t/sha1.c
t/uuidgen.c

index 3dd183ce3c498be3683a5902e9774e37a3f3845f..ed7deb6e276d249255d98a461478e673428ab83e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,9 @@ rng.o:        rng.c
 internal.o:    internal.c
        $(CC) $(CFLAGS) -Wall -fPIC -c -o $@ $+
 
+uuidgen2:      libpduuid.a uuidgen2.o
+       $(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen2.o -lpduuid $(LDFLAGS)
+
 uuidgen:       libpduuid.a uuidgen.o
        $(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen.o -lpduuid $(LDFLAGS)
 
index 59e1bbf402d05b3416b1c1323e625f1f095b9e16..c911099ff6bee130f9daf05e7730cec1c72f060d 100644 (file)
@@ -127,11 +127,12 @@ static int release_global_lock(void *data) {
 static uint64_t current_time(void) {
        uint64_t now;
        struct timeval tv;
+       static int seq = 0;
        
        /* TODO is this BSD specific? */
        gettimeofday(&tv, 0);
 
-       now = (tv.tv_sec * 10000000ULL + tv.tv_usec * 10ULL) + GREGORIAN;
+       now = (tv.tv_sec * 10000000ULL + tv.tv_usec * 10ULL + seq++ % 10) + GREGORIAN;
        return now;
 }
 
@@ -274,11 +275,19 @@ static uint16_t random_clock_sequence(struct pd_uuid_state *s) {
 }
 
 static int read_state(struct pd_uuid_state *s) {
+       uint64_t        node;
+
        s->available = 0;
        s->node = 0LL;
        s->clock_sequence = 0;
        s->timestamp = 0LL;
 
+       node = current_node(s);
+
+       if (!s->available || s->node != node) {
+               s->clock_sequence = random_clock_sequence(s);
+       }
+
        return 0;
 }
 
@@ -297,6 +306,30 @@ static unsigned long get_bytes(void *buf, unsigned long n, void *state) {
        return i;
 }
 
+int pd_uuid_init(struct pd_uuid_state *s, int flags) {
+       if (!s) return 0;
+
+       s->get_lock = obtain_global_lock;
+       s->release_lock = release_global_lock;
+       s->lock_data = 0;
+
+       if (flags & 0x1) {
+               s->read_state = 0;
+               s->save_state = 0;
+               s->node = current_node(s);
+       } else {
+               s->read_state = read_state;
+               s->save_state = 0;
+       }
+
+       s->random_bytes = get_bytes;
+       s->rng_state = 0;
+
+       s->available = 0;
+
+       return 1;
+}
+
 int pd_uuid_init_state(struct pd_uuid_state *s) {
        if (!s) return 0;
 
@@ -318,7 +351,6 @@ int pd_uuid_init_state(struct pd_uuid_state *s) {
 int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid) {
        struct pd_uuid_state    ls;
        uint64_t        now;
-       uint64_t        node;
        int err;
 
        if (!s) {
@@ -341,13 +373,6 @@ int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid) {
        }
 
        now = current_time();
-       node = current_node(s);
-
-       if (!s->available || s->node != node) {
-               s->clock_sequence = random_clock_sequence(s);
-       }
-
-       s->node = node;
 
        if (s->available && s->timestamp > now) {
                s->clock_sequence++;
index 86c5f6d9a3159bc0befded10c7011eddeece1363..14ad6daf1dfb4d81f4e541ee51303b490ac08669 100644 (file)
--- a/pduuid.h
+++ b/pduuid.h
@@ -24,6 +24,7 @@ struct pd_uuid {
 typedef struct pd_uuid pd_uuid_t;
 
 int pd_uuid_init_state(struct pd_uuid_state *s);
+int pd_uuid_init(struct pd_uuid_state *s, int f);
 int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid);
 int pd_uuid_make_v1mc(struct pd_uuid_state *s, pd_uuid_t *uuid);
 int pd_uuid_make_v4(struct pd_uuid_state *s, pd_uuid_t *uuid);
index 4903d43a1be0aa26dd76acae189a529ce31594fa..86ba4122fbf04b776ffc159644afe07183d45f0d 100644 (file)
--- a/t/sha1.c
+++ b/t/sha1.c
@@ -18,6 +18,7 @@ static void bytestr(unsigned char *h, char *s, int len) {
        }
 }
 
+#if 0
 static int strbytes(char *s, unsigned char *d) {
         unsigned int byte;
         int i = 0;
@@ -36,6 +37,7 @@ static int strbytes(char *s, unsigned char *d) {
         }
         return i;
 }
+#endif
 
 int main(int ac, char *av[]) {
        unsigned char tmp[20];
@@ -44,7 +46,7 @@ int main(int ac, char *av[]) {
        char want[64];
        char have[64];
 
-       static const struct {
+       static struct {
                char *msg;
                int repeat;
                unsigned char hash[20];
@@ -67,7 +69,7 @@ int main(int ac, char *av[]) {
        { "0123456701234567012345670123456701234567012345670123456701234567", 10, 
        {0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC, 0xED, 0xC5, 0xEB, 0xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52},
        },
-    { NULL, { 0 } }
+    { NULL, 0, { 0 } }
   };
 
        plan(8);
index 4ab3cf4d50612a860e54cedfab1a251845727389..e17b7e927621dbf67b1ba2a9140c27e173173340 100644 (file)
@@ -63,6 +63,8 @@ int str_ok(pd_uuid_t *uuid, char *s, char *name) {
 int main(int ac, char *av[]) {
        pd_uuid_t uuid, copy;
        struct pd_uuid_state s;
+       pd_uuid_t idset[10];
+       int i;
 
        char fmt[37];
        unsigned char hash[40];
@@ -78,7 +80,7 @@ int main(int ac, char *av[]) {
        srandom(time(0));
 #endif
 
-       plan(15);
+       plan(24);
 
        pd_uuid_init_state(0);
        pd_uuid_make_v1mc(0, &uuid);
@@ -158,5 +160,14 @@ int main(int ac, char *av[]) {
        ufmt(&copy, fmt);
        diag("v1b: %s", fmt);
 
+       pd_uuid_init(&s, 0x1);
+       for (i=0;i<10;i++) {
+               pd_uuid_make_v1(&s, &idset[i]);
+       }
+       for (i=0;i<9;i++) {
+               ok(pd_uuid_cmp(&idset[i], &idset[i+1]), "id set %d != %d", i, i+1); 
+               pd_uuid_make_v1(&s, &idset[i]);
+       }
+
        return 0;
 }