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.
internal.o: internal.c
$(CC) $(CFLAGS) -Wall -fPIC -c -o $@ $+
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)
uuidgen: libpduuid.a uuidgen.o
$(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen.o -lpduuid $(LDFLAGS)
static uint64_t current_time(void) {
uint64_t now;
struct timeval tv;
static uint64_t current_time(void) {
uint64_t now;
struct timeval tv;
/* TODO is this BSD specific? */
gettimeofday(&tv, 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;
}
static int read_state(struct pd_uuid_state *s) {
}
static int read_state(struct pd_uuid_state *s) {
s->available = 0;
s->node = 0LL;
s->clock_sequence = 0;
s->timestamp = 0LL;
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);
+ }
+
+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;
int pd_uuid_init_state(struct pd_uuid_state *s) {
if (!s) return 0;
int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid) {
struct pd_uuid_state ls;
uint64_t now;
int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid) {
struct pd_uuid_state ls;
uint64_t now;
- 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++;
if (s->available && s->timestamp > now) {
s->clock_sequence++;
typedef struct pd_uuid pd_uuid_t;
int pd_uuid_init_state(struct pd_uuid_state *s);
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);
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);
static int strbytes(char *s, unsigned char *d) {
unsigned int byte;
int i = 0;
static int strbytes(char *s, unsigned char *d) {
unsigned int byte;
int i = 0;
int main(int ac, char *av[]) {
unsigned char tmp[20];
int main(int ac, char *av[]) {
unsigned char tmp[20];
char want[64];
char have[64];
char want[64];
char have[64];
char *msg;
int repeat;
unsigned char hash[20];
char *msg;
int repeat;
unsigned char hash[20];
{ "0123456701234567012345670123456701234567012345670123456701234567", 10,
{0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC, 0xED, 0xC5, 0xEB, 0xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52},
},
{ "0123456701234567012345670123456701234567012345670123456701234567", 10,
{0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC, 0xED, 0xC5, 0xEB, 0xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52},
},
int main(int ac, char *av[]) {
pd_uuid_t uuid, copy;
struct pd_uuid_state s;
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];
char fmt[37];
unsigned char hash[40];
pd_uuid_init_state(0);
pd_uuid_make_v1mc(0, &uuid);
pd_uuid_init_state(0);
pd_uuid_make_v1mc(0, &uuid);
ufmt(©, fmt);
diag("v1b: %s", fmt);
ufmt(©, 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]);
+ }
+