mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00

* API revision * update * make status a bitmap * update api * tests working * new task log APIs * update APIs * write binary structures to redis * update tests * fix clang-format * Fix formatting.
36 lines
884 B
C
36 lines
884 B
C
#include "common.h"
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
|
|
const unique_id NIL_ID = {{255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255}};
|
|
|
|
unique_id globally_unique_id(void) {
|
|
/* Use /dev/urandom for "real" randomness. */
|
|
int fd;
|
|
if ((fd = open("/dev/urandom", O_RDONLY)) == -1) {
|
|
LOG_ERR("Could not generate random number");
|
|
}
|
|
unique_id result;
|
|
read(fd, &result.id[0], UNIQUE_ID_SIZE);
|
|
close(fd);
|
|
return result;
|
|
}
|
|
|
|
char *sha1_to_hex(const unsigned char *sha1, char *buffer) {
|
|
static const char hex[] = "0123456789abcdef";
|
|
char *buf = buffer;
|
|
|
|
for (int i = 0; i < UNIQUE_ID_SIZE; i++) {
|
|
unsigned int val = *sha1++;
|
|
*buf++ = hex[val >> 4];
|
|
*buf++ = hex[val & 0xf];
|
|
}
|
|
*buf = '\0';
|
|
|
|
return buffer;
|
|
}
|