2014-02-26 00:18:07 +04:00
|
|
|
/* v/sist.c
|
|
|
|
**
|
|
|
|
*/
|
2014-04-10 15:24:19 +04:00
|
|
|
#include <errno.h>
|
2014-03-08 06:56:15 +04:00
|
|
|
#include <fcntl.h>
|
2014-02-26 00:18:07 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2018-09-07 04:35:17 +03:00
|
|
|
#include <curl/curl.h>
|
2014-02-26 00:18:07 +04:00
|
|
|
#include <uv.h>
|
|
|
|
|
|
|
|
#include "all.h"
|
2015-06-24 04:28:38 +03:00
|
|
|
#include "vere/vere.h"
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-11-05 03:29:08 +03:00
|
|
|
#if defined(U3_OS_linux)
|
2014-02-26 00:18:07 +04:00
|
|
|
#include <stdio_ext.h>
|
|
|
|
#define fpurge(fd) __fpurge(fd)
|
|
|
|
#define DEVRANDOM "/dev/urandom"
|
|
|
|
#else
|
|
|
|
#define DEVRANDOM "/dev/random"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
/* u3_sist_pack(): write a blob to disk, transferring.
|
2014-02-26 00:18:07 +04:00
|
|
|
*/
|
2014-04-08 20:25:49 +04:00
|
|
|
c3_d
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_ulog* lug_u = &u3Z->lug_u;
|
2014-02-26 00:18:07 +04:00
|
|
|
c3_d tar_d;
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_ular lar_u;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
tar_d = lug_u->len_d + len_w;
|
|
|
|
|
2014-03-11 03:13:19 +04:00
|
|
|
lar_u.tem_w = tem_w;
|
|
|
|
lar_u.typ_w = typ_w;
|
2015-11-07 01:08:58 +03:00
|
|
|
lar_u.syn_w = u3r_mug_d(tar_d);
|
2014-11-06 03:20:01 +03:00
|
|
|
lar_u.mug_w = u3r_mug_both(u3r_mug_words(bob_w, len_w),
|
|
|
|
u3r_mug_both(u3r_mug(lar_u.tem_w),
|
|
|
|
u3r_mug(lar_u.typ_w)));
|
2014-09-11 04:01:32 +04:00
|
|
|
lar_u.ent_d = u3A->ent_d;
|
|
|
|
u3A->ent_d++;
|
2014-02-26 00:18:07 +04:00
|
|
|
lar_u.len_w = len_w;
|
|
|
|
|
|
|
|
if ( -1 == lseek64(lug_u->fid_i, 4ULL * tar_d, SEEK_SET) ) {
|
|
|
|
perror("lseek");
|
|
|
|
uL(fprintf(uH, "sist_pack: seek failed\n"));
|
|
|
|
c3_assert(0);
|
|
|
|
}
|
|
|
|
if ( sizeof(lar_u) != write(lug_u->fid_i, &lar_u, sizeof(lar_u)) ) {
|
|
|
|
perror("write");
|
|
|
|
uL(fprintf(uH, "sist_pack: write failed\n"));
|
|
|
|
c3_assert(0);
|
|
|
|
}
|
|
|
|
if ( -1 == lseek64(lug_u->fid_i, 4ULL * lug_u->len_d, SEEK_SET) ) {
|
|
|
|
perror("lseek");
|
|
|
|
uL(fprintf(uH, "sist_pack: seek failed\n"));
|
|
|
|
c3_assert(0);
|
|
|
|
}
|
|
|
|
#if 0
|
2014-11-29 23:36:33 +03:00
|
|
|
uL(fprintf(uH, "sist_pack: write %" PRIu64 ", %" PRIu64 ": lar ent %" PRIu64 ", len %d, mug %x\n",
|
2014-02-26 00:18:07 +04:00
|
|
|
lug_u->len_d,
|
|
|
|
tar_d,
|
2014-04-08 20:25:49 +04:00
|
|
|
lar_u.ent_d,
|
2014-02-26 00:18:07 +04:00
|
|
|
lar_u.len_w,
|
|
|
|
lar_u.mug_w));
|
|
|
|
#endif
|
|
|
|
if ( (4 * len_w) != write(lug_u->fid_i, bob_w, (4 * len_w)) ) {
|
|
|
|
perror("write");
|
|
|
|
uL(fprintf(uH, "sist_pack: write failed\n"));
|
|
|
|
c3_assert(0);
|
|
|
|
}
|
|
|
|
lug_u->len_d += (c3_d)(lar_u.len_w + c3_wiseof(lar_u));
|
2014-03-13 22:26:27 +04:00
|
|
|
free(bob_w);
|
|
|
|
|
2014-04-22 05:59:09 +04:00
|
|
|
// Sync. Or, what goes by sync.
|
|
|
|
{
|
|
|
|
fsync(lug_u->fid_i); // fsync is almost useless, F_FULLFSYNC too slow
|
2014-11-05 03:29:08 +03:00
|
|
|
#if defined(U3_OS_linux)
|
2014-11-04 01:12:54 +03:00
|
|
|
fdatasync(lug_u->fid_i);
|
2014-11-05 03:29:08 +03:00
|
|
|
#elif defined(U3_OS_osx)
|
2014-10-31 00:40:05 +03:00
|
|
|
fcntl(lug_u->fid_i, F_FULLFSYNC);
|
2014-11-05 03:29:08 +03:00
|
|
|
#elif defined(U3_OS_bsd)
|
2014-11-04 01:12:54 +03:00
|
|
|
fsync(lug_u->fid_i);
|
|
|
|
#else
|
|
|
|
# error "port: datasync"
|
|
|
|
#endif
|
2014-04-22 05:59:09 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
return u3A->ent_d;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
/* u3_sist_put(): moronic key-value store put.
|
2014-03-08 06:56:15 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_sist_put(const c3_c* key_c, const c3_y* val_y, size_t siz_i)
|
2014-03-08 06:56:15 +04:00
|
|
|
{
|
|
|
|
c3_c ful_c[2048];
|
|
|
|
c3_i ret_i;
|
|
|
|
c3_i fid_i;
|
|
|
|
|
2014-11-16 04:10:15 +03:00
|
|
|
ret_i = snprintf(ful_c, 2048, "%s/.urb/sis/_%s", u3_Host.dir_c, key_c);
|
2014-03-08 06:56:15 +04:00
|
|
|
c3_assert(ret_i < 2048);
|
|
|
|
|
|
|
|
if ( (fid_i = open(ful_c, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0 ) {
|
|
|
|
uL(fprintf(uH, "sist: could not put %s\n", key_c));
|
|
|
|
perror("open");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-08 06:56:15 +04:00
|
|
|
}
|
|
|
|
if ( (ret_i = write(fid_i, val_y, siz_i)) != siz_i ) {
|
|
|
|
uL(fprintf(uH, "sist: could not write %s\n", key_c));
|
|
|
|
if ( ret_i < 0 ) {
|
|
|
|
perror("write");
|
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-08 06:56:15 +04:00
|
|
|
}
|
|
|
|
ret_i = c3_sync(fid_i);
|
|
|
|
if ( ret_i < 0 ) {
|
|
|
|
perror("sync");
|
|
|
|
}
|
|
|
|
ret_i = close(fid_i);
|
|
|
|
c3_assert(0 == ret_i);
|
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
/* u3_sist_has(): moronic key-value store existence check.
|
2014-03-08 06:56:15 +04:00
|
|
|
*/
|
|
|
|
ssize_t
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_sist_has(const c3_c* key_c)
|
2014-03-08 06:56:15 +04:00
|
|
|
{
|
|
|
|
c3_c ful_c[2048];
|
|
|
|
c3_i ret_i;
|
|
|
|
struct stat sat_u;
|
|
|
|
|
2014-11-16 04:10:15 +03:00
|
|
|
ret_i = snprintf(ful_c, 2048, "%s/.urb/sis/_%s", u3_Host.dir_c, key_c);
|
2014-03-08 06:56:15 +04:00
|
|
|
c3_assert(ret_i < 2048);
|
|
|
|
|
|
|
|
if ( (ret_i = stat(ful_c, &sat_u)) < 0 ) {
|
|
|
|
if ( errno == ENOENT ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uL(fprintf(uH, "sist: could not stat %s\n", key_c));
|
|
|
|
perror("stat");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-08 06:56:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return sat_u.st_size;
|
|
|
|
}
|
|
|
|
c3_assert(!"not reached");
|
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
/* u3_sist_get(): moronic key-value store get.
|
2014-03-08 06:56:15 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_sist_get(const c3_c* key_c, c3_y* val_y)
|
2014-03-08 06:56:15 +04:00
|
|
|
{
|
|
|
|
c3_c ful_c[2048];
|
|
|
|
c3_i ret_i;
|
|
|
|
c3_i fid_i;
|
|
|
|
struct stat sat_u;
|
|
|
|
|
2014-11-16 04:10:15 +03:00
|
|
|
ret_i = snprintf(ful_c, 2048, "%s/.urb/sis/_%s", u3_Host.dir_c, key_c);
|
2014-03-08 06:56:15 +04:00
|
|
|
c3_assert(ret_i < 2048);
|
|
|
|
|
|
|
|
if ( (fid_i = open(ful_c, O_RDONLY)) < 0 ) {
|
|
|
|
uL(fprintf(uH, "sist: could not get %s\n", key_c));
|
|
|
|
perror("open");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-08 06:56:15 +04:00
|
|
|
}
|
|
|
|
if ( (ret_i = fstat(fid_i, &sat_u)) < 0 ) {
|
|
|
|
uL(fprintf(uH, "sist: could not stat %s\n", key_c));
|
|
|
|
perror("fstat");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-08 06:56:15 +04:00
|
|
|
}
|
|
|
|
if ( (ret_i = read(fid_i, val_y, sat_u.st_size)) != sat_u.st_size ) {
|
|
|
|
uL(fprintf(uH, "sist: could not read %s\n", key_c));
|
|
|
|
if ( ret_i < 0 ) {
|
|
|
|
perror("read");
|
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-08 06:56:15 +04:00
|
|
|
}
|
|
|
|
ret_i = close(fid_i);
|
|
|
|
c3_assert(0 == ret_i);
|
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
/* u3_sist_nil(): moronic key-value store rm.
|
2014-03-08 06:56:15 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_sist_nil(const c3_c* key_c)
|
2014-03-08 06:56:15 +04:00
|
|
|
{
|
|
|
|
c3_c ful_c[2048];
|
|
|
|
c3_i ret_i;
|
|
|
|
|
2014-11-16 04:10:15 +03:00
|
|
|
ret_i = snprintf(ful_c, 2048, "%s/.urb/sis/_%s", u3_Host.dir_c, key_c);
|
2014-03-08 06:56:15 +04:00
|
|
|
c3_assert(ret_i < 2048);
|
|
|
|
|
|
|
|
if ( (ret_i = unlink(ful_c)) < 0 ) {
|
|
|
|
if ( errno == ENOENT ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uL(fprintf(uH, "sist: could not unlink %s\n", key_c));
|
|
|
|
perror("unlink");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-08 06:56:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:18:07 +04:00
|
|
|
/* _sist_suck(): past failure.
|
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
_sist_suck(u3_noun ovo, u3_noun gon)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
uL(fprintf(uH, "sing: ovum failed!\n"));
|
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
c3_c* hed_c = u3r_string(u3h(u3t(ovo)));
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
uL(fprintf(uH, "fail %s\n", hed_c));
|
|
|
|
free(hed_c);
|
|
|
|
}
|
|
|
|
|
2014-11-06 22:13:57 +03:00
|
|
|
u3_lo_punt(2, u3kb_flop(u3k(u3t(gon))));
|
2014-09-11 04:01:32 +04:00
|
|
|
// u3_loom_exit();
|
2015-05-20 01:43:12 +03:00
|
|
|
#if 1
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_exit();
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
exit(1);
|
2015-05-20 01:43:12 +03:00
|
|
|
#else
|
|
|
|
u3z(ovo); u3z(gon);
|
|
|
|
#endif
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_sing(): replay ovum from the past, time already set.
|
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
_sist_sing(u3_noun ovo)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
2014-11-06 03:20:01 +03:00
|
|
|
u3_noun gon = u3m_soft(0, u3v_poke, u3k(ovo));
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( u3_blip != u3h(gon) ) {
|
|
|
|
_sist_suck(ovo, gon);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun vir = u3k(u3h(u3t(gon)));
|
|
|
|
u3_noun cor = u3k(u3t(u3t(gon)));
|
|
|
|
u3_noun nug;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(gon);
|
2014-11-06 03:20:01 +03:00
|
|
|
nug = u3v_nick(vir, cor);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( u3_blip != u3h(nug) ) {
|
|
|
|
_sist_suck(ovo, nug);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-11 04:01:32 +04:00
|
|
|
vir = u3h(u3t(nug));
|
|
|
|
cor = u3k(u3t(u3t(nug)));
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
while ( u3_nul != vir ) {
|
|
|
|
u3_noun fex = u3h(vir);
|
|
|
|
u3_noun fav = u3t(fex);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2018-08-10 19:58:21 +03:00
|
|
|
if ( c3__init == u3h(fav) ) {
|
|
|
|
u3A->own = u3k(u3t(fav));
|
2018-10-09 20:35:25 +03:00
|
|
|
// note: c3__boot == u3h(u3t(ovo))
|
|
|
|
u3A->fak = ( c3__fake == u3h(u3t(u3t(ovo))) ) ? c3y : c3n;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2018-08-10 19:58:21 +03:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
vir = u3t(vir);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(nug);
|
|
|
|
u3z(u3A->roc);
|
|
|
|
u3A->roc = cor;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(ovo);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_cask(): ask for a passcode.
|
|
|
|
*/
|
2014-09-11 04:01:32 +04:00
|
|
|
static u3_noun
|
2014-11-06 06:10:22 +03:00
|
|
|
_sist_cask(c3_c* dir_c, u3_noun nun)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
c3_c paw_c[60];
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun key;
|
2018-09-27 08:24:50 +03:00
|
|
|
u3_utty* uty_u = calloc(1, sizeof(u3_utty));
|
|
|
|
uty_u->fid_i = 0;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
uH;
|
2018-09-27 08:24:50 +03:00
|
|
|
|
|
|
|
// disable terminal echo when typing in passcode
|
|
|
|
if ( 0 != tcgetattr(uty_u->fid_i, &uty_u->bak_u) ) {
|
|
|
|
c3_assert(!"init-tcgetattr");
|
|
|
|
}
|
|
|
|
uty_u->raw_u = uty_u->bak_u;
|
|
|
|
uty_u->raw_u.c_lflag &= ~ECHO;
|
|
|
|
if ( 0 != tcsetattr(uty_u->fid_i, TCSADRAIN, &uty_u->raw_u) ) {
|
|
|
|
c3_assert(!"init-tcsetattr");
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:18:07 +04:00
|
|
|
while ( 1 ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
printf("passcode for %s%s? ~", dir_c, (c3y == nun) ? " [none]" : "");
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
paw_c[0] = 0;
|
2014-03-25 19:41:09 +04:00
|
|
|
c3_fpurge(stdin);
|
2014-02-26 00:18:07 +04:00
|
|
|
fgets(paw_c, 59, stdin);
|
2018-09-27 08:24:50 +03:00
|
|
|
printf("\n");
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
if ( '\n' == paw_c[0] ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == nun ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
key = 0; break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-04-02 04:47:01 +04:00
|
|
|
c3_c* say_c = c3_malloc(strlen(paw_c) + 2);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun say;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
say_c[0] = '~';
|
|
|
|
say_c[1] = 0;
|
|
|
|
strncat(say_c, paw_c, strlen(paw_c) - 1);
|
|
|
|
|
2014-11-06 06:10:22 +03:00
|
|
|
say = u3do("slay", u3i_string(say_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( (u3_nul == say) ||
|
|
|
|
(u3_blip != u3h(u3t(say))) ||
|
|
|
|
('p' != u3h(u3t(u3t(say)))) )
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
printf("invalid passcode\n");
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
key = u3k(u3t(u3t(u3t(say))));
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(say);
|
2014-02-26 00:18:07 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-09-27 08:24:50 +03:00
|
|
|
if ( 0 != tcsetattr(uty_u->fid_i, TCSADRAIN, &uty_u->bak_u) ) {
|
|
|
|
c3_assert(!"init-tcsetattr");
|
|
|
|
}
|
|
|
|
free(uty_u);
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(0);
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_text(): ask for a name string.
|
|
|
|
*/
|
2014-09-11 04:01:32 +04:00
|
|
|
static u3_noun
|
|
|
|
_sist_text(c3_c* pom_c)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
2016-02-05 03:54:12 +03:00
|
|
|
c3_c paw_c[180];
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun say;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
uH;
|
|
|
|
while ( 1 ) {
|
|
|
|
printf("%s: ", pom_c);
|
|
|
|
|
|
|
|
paw_c[0] = 0;
|
|
|
|
fpurge(stdin);
|
2016-02-05 03:54:12 +03:00
|
|
|
fgets(paw_c, 179, stdin);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
if ( '\n' == paw_c[0] ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c3_w len_w = strlen(paw_c);
|
|
|
|
|
|
|
|
if ( paw_c[len_w - 1] == '\n' ) {
|
|
|
|
paw_c[len_w-1] = 0;
|
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
say = u3i_string(paw_c);
|
2014-02-26 00:18:07 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uL(0);
|
|
|
|
return say;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* _sist_bask(): ask a yes or no question.
|
|
|
|
*/
|
2014-11-06 06:10:22 +03:00
|
|
|
static u3_noun
|
|
|
|
_sist_bask(c3_c* pop_c, u3_noun may)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
2014-11-06 06:10:22 +03:00
|
|
|
u3_noun yam;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
uH;
|
|
|
|
while ( 1 ) {
|
|
|
|
c3_c ans_c[3];
|
|
|
|
|
|
|
|
printf("%s [y/n]? ", pop_c);
|
|
|
|
ans_c[0] = 0;
|
|
|
|
|
2014-03-25 19:41:09 +04:00
|
|
|
c3_fpurge(stdin);
|
2014-02-26 00:18:07 +04:00
|
|
|
fgets(ans_c, 2, stdin);
|
|
|
|
|
|
|
|
if ( (ans_c[0] != 'y') && (ans_c[0] != 'n') ) {
|
|
|
|
continue;
|
|
|
|
} else {
|
2014-11-05 04:18:47 +03:00
|
|
|
yam = (ans_c[0] != 'n') ? c3y : c3n;
|
2014-02-26 00:18:07 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uL(0);
|
|
|
|
return yam;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-11 20:22:26 +03:00
|
|
|
/* u3_sist_rand(): fill a 512-bit (16-word) buffer.
|
2014-02-26 00:18:07 +04:00
|
|
|
*/
|
2015-03-19 01:48:29 +03:00
|
|
|
void
|
|
|
|
u3_sist_rand(c3_w* rad_w)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
c3_i fid_i = open(DEVRANDOM, O_RDONLY);
|
|
|
|
|
2016-08-11 20:22:26 +03:00
|
|
|
if ( 64 != read(fid_i, (c3_y*) rad_w, 64) ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
c3_assert(!"lo_rand");
|
|
|
|
}
|
|
|
|
close(fid_i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_fast(): offer to save passcode by mug in home directory.
|
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
_sist_fast(u3_noun pas, c3_l key_l)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
c3_c ful_c[2048];
|
2014-11-16 04:10:15 +03:00
|
|
|
c3_c* hom_c = u3_Host.dir_c;
|
2014-11-06 06:10:22 +03:00
|
|
|
u3_noun gum = u3dc("scot", 'p', key_l);
|
2014-11-06 03:20:01 +03:00
|
|
|
c3_c* gum_c = u3r_string(gum);
|
2014-11-06 06:10:22 +03:00
|
|
|
u3_noun yek = u3dc("scot", 'p', pas);
|
2014-11-06 03:20:01 +03:00
|
|
|
c3_c* yek_c = u3r_string(yek);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-05-13 23:22:07 +04:00
|
|
|
printf("saving passcode in %s/.urb/code.%s\r\n", hom_c, gum_c);
|
2014-02-26 00:18:07 +04:00
|
|
|
printf("(for real security, write it down and delete the file...)\r\n");
|
|
|
|
{
|
|
|
|
c3_i fid_i;
|
|
|
|
|
2014-05-13 23:22:07 +04:00
|
|
|
snprintf(ful_c, 2048, "%s/.urb/code.%s", hom_c, gum_c);
|
2014-02-26 00:18:07 +04:00
|
|
|
if ( (fid_i = open(ful_c, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0 ) {
|
|
|
|
uL(fprintf(uH, "fast: could not save %s\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
write(fid_i, yek_c, strlen(yek_c));
|
|
|
|
close(fid_i);
|
|
|
|
}
|
|
|
|
free(gum_c);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(gum);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
free(yek_c);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(yek);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_staf(): try to load passcode by mug from home directory.
|
|
|
|
*/
|
2014-09-11 04:01:32 +04:00
|
|
|
static u3_noun
|
|
|
|
_sist_staf(c3_l key_l)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
c3_c ful_c[2048];
|
2014-11-16 04:10:15 +03:00
|
|
|
c3_c* hom_c = u3_Host.dir_c;
|
2014-11-06 06:10:22 +03:00
|
|
|
u3_noun gum = u3dc("scot", 'p', key_l);
|
2014-11-06 03:20:01 +03:00
|
|
|
c3_c* gum_c = u3r_string(gum);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun txt;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-05-13 23:22:07 +04:00
|
|
|
snprintf(ful_c, 2048, "%s/.urb/code.%s", hom_c, gum_c);
|
2014-02-26 00:18:07 +04:00
|
|
|
free(gum_c);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(gum);
|
|
|
|
txt = u3_walk_safe(ful_c);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
if ( 0 == txt ) {
|
|
|
|
uL(fprintf(uH, "staf: no passcode %s\n", ful_c));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
2014-11-06 03:20:01 +03:00
|
|
|
// c3_c* txt_c = u3r_string(txt);
|
2014-11-06 06:10:22 +03:00
|
|
|
u3_noun say = u3do("slay", txt);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun pas;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( (u3_nul == say) ||
|
|
|
|
(u3_blip != u3h(u3t(say))) ||
|
|
|
|
('p' != u3h(u3t(u3t(say)))) )
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
uL(fprintf(uH, "staf: %s is corrupt\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(say);
|
2014-02-26 00:18:07 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
uL(fprintf(uH, "loaded passcode from %s\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
pas = u3k(u3t(u3t(u3t(say))));
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(say);
|
2014-02-26 00:18:07 +04:00
|
|
|
return pas;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_fatt(): stretch a 64-bit passcode to make a 128-bit key.
|
|
|
|
*/
|
2014-09-11 04:01:32 +04:00
|
|
|
static u3_noun
|
|
|
|
_sist_fatt(c3_l sal_l, u3_noun pas)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
c3_w i_w;
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun key = pas;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
// XX use scrypt() - this is a stupid iterated hash
|
|
|
|
//
|
|
|
|
for ( i_w = 0; i_w < 32768; i_w++ ) {
|
2014-11-06 06:10:22 +03:00
|
|
|
key = u3dc("shaf", sal_l, key);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_zest(): create a new, empty record.
|
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
_sist_zest()
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
struct stat buf_b;
|
|
|
|
c3_i fid_i;
|
|
|
|
c3_c ful_c[8193];
|
|
|
|
c3_l sal_l;
|
|
|
|
|
|
|
|
// Create the record file.
|
|
|
|
{
|
2014-06-06 01:21:11 +04:00
|
|
|
c3_i pig_i = O_CREAT | O_WRONLY | O_EXCL;
|
|
|
|
#ifdef O_DSYNC
|
|
|
|
pig_i |= O_DSYNC;
|
|
|
|
#endif
|
2014-11-16 04:10:15 +03:00
|
|
|
snprintf(ful_c, 2048, "%s/.urb/egz.hope", u3_Host.dir_c);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-06-06 01:21:11 +04:00
|
|
|
if ( ((fid_i = open(ful_c, pig_i, 0600)) < 0) ||
|
2014-02-26 00:18:07 +04:00
|
|
|
(fstat(fid_i, &buf_b) < 0) )
|
|
|
|
{
|
|
|
|
uL(fprintf(uH, "can't create record (%s)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-06-06 01:21:11 +04:00
|
|
|
#ifdef F_NOCACHE
|
|
|
|
if ( -1 == fcntl(fid_i, F_NOCACHE, 1) ) {
|
|
|
|
uL(fprintf(uH, "zest: can't uncache %s: %s\n", ful_c, strerror(errno)));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-06-06 01:21:11 +04:00
|
|
|
}
|
|
|
|
#endif
|
2014-09-11 04:01:32 +04:00
|
|
|
u3Z->lug_u.fid_i = fid_i;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a 31-bit salt.
|
|
|
|
//
|
|
|
|
{
|
2016-08-11 20:22:26 +03:00
|
|
|
c3_w rad_w[16];
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2015-03-19 01:48:29 +03:00
|
|
|
c3_rand(rad_w);
|
2014-02-26 00:18:07 +04:00
|
|
|
sal_l = (0x7fffffff & rad_w[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create and save a passcode.
|
|
|
|
//
|
|
|
|
{
|
2016-08-11 20:22:26 +03:00
|
|
|
c3_w rad_w[16];
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun pas;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2015-03-19 01:48:29 +03:00
|
|
|
c3_rand(rad_w);
|
2014-11-06 03:20:01 +03:00
|
|
|
pas = u3i_words(2, rad_w);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
u3A->key = _sist_fatt(sal_l, u3k(pas));
|
2014-11-06 03:20:01 +03:00
|
|
|
_sist_fast(pas, u3r_mug(u3A->key));
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write the header.
|
|
|
|
{
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_uled led_u;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
led_u.mag_l = u3r_mug('g');
|
2015-01-27 03:25:27 +03:00
|
|
|
led_u.kno_w = 163;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( 0 == u3A->key ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
led_u.key_l = 0;
|
|
|
|
} else {
|
2014-11-06 03:20:01 +03:00
|
|
|
led_u.key_l = u3r_mug(u3A->key);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
c3_assert(!(led_u.key_l >> 31));
|
|
|
|
}
|
|
|
|
led_u.sal_l = sal_l;
|
2014-09-11 04:01:32 +04:00
|
|
|
led_u.sev_l = u3A->sev_l;
|
2014-02-26 00:18:07 +04:00
|
|
|
led_u.tno_l = 1;
|
|
|
|
|
|
|
|
if ( sizeof(led_u) != write(fid_i, &led_u, sizeof(led_u)) ) {
|
|
|
|
uL(fprintf(uH, "can't write record (%s)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
u3Z->lug_u.len_d = c3_wiseof(led_u);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Work through the boot events.
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_raft_work();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-03-11 03:13:19 +04:00
|
|
|
/* _sist_rest_nuu(): upgrade log from previous format.
|
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
_sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c)
|
2014-03-11 03:13:19 +04:00
|
|
|
{
|
|
|
|
c3_c nuu_c[2048];
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun roe = u3_nul;
|
2014-03-11 03:13:19 +04:00
|
|
|
c3_i fid_i = lug_u->fid_i;
|
|
|
|
c3_i fud_i;
|
|
|
|
c3_i ret_i;
|
|
|
|
c3_d end_d = lug_u->len_d;
|
|
|
|
|
2014-03-11 03:17:20 +04:00
|
|
|
uL(fprintf(uH, "rest: converting log from prior format\n"));
|
2014-03-11 03:13:19 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
c3_assert(led_u.mag_l == u3r_mug('f'));
|
2014-03-11 03:13:19 +04:00
|
|
|
|
|
|
|
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
|
|
|
|
uL(fprintf(uH, "rest_nuu failed (a)\n"));
|
|
|
|
perror("lseek64");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
while ( end_d != c3_wiseof(u3_uled) ) {
|
2014-03-11 03:13:19 +04:00
|
|
|
c3_d tar_d;
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_olar lar_u;
|
2014-03-11 03:13:19 +04:00
|
|
|
c3_w* img_w;
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun ron;
|
2014-03-11 03:13:19 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
tar_d = (end_d - (c3_d)c3_wiseof(u3_olar));
|
2014-03-11 03:13:19 +04:00
|
|
|
|
|
|
|
if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) {
|
|
|
|
uL(fprintf(uH, "rest_nuu failed (b)\n"));
|
|
|
|
perror("lseek64");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( sizeof(u3_olar) != read(fid_i, &lar_u, sizeof(u3_olar)) ) {
|
2014-03-11 03:13:19 +04:00
|
|
|
uL(fprintf(uH, "rest_nuu failed (c)\n"));
|
|
|
|
perror("read");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
2015-11-07 01:08:58 +03:00
|
|
|
if ( lar_u.syn_w != u3r_mug_d(tar_d) ) {
|
2014-03-11 03:13:19 +04:00
|
|
|
uL(fprintf(uH, "rest_nuu failed (d)\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
2014-04-02 04:47:01 +04:00
|
|
|
img_w = c3_malloc(4 * lar_u.len_w);
|
2014-03-11 03:13:19 +04:00
|
|
|
end_d = (tar_d - (c3_d)lar_u.len_w);
|
|
|
|
|
|
|
|
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
|
|
|
|
uL(fprintf(uH, "rest_nuu failed (e)\n"));
|
|
|
|
perror("lseek64");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) {
|
|
|
|
uL(fprintf(uH, "rest_nuu failed (f)\n"));
|
|
|
|
perror("read");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
ron = u3i_words(lar_u.len_w, img_w);
|
2014-03-11 03:13:19 +04:00
|
|
|
free(img_w);
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( lar_u.mug_w != u3r_mug(ron) ) {
|
2014-03-11 03:13:19 +04:00
|
|
|
uL(fprintf(uH, "rest_nuu failed (g)\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
roe = u3nc(ron, roe);
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( 0 != close(fid_i) ) {
|
|
|
|
uL(fprintf(uH, "rest: could not close\n"));
|
|
|
|
perror("close");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
2014-11-16 04:10:15 +03:00
|
|
|
ret_i = snprintf(nuu_c, 2048, "%s/.urb/ham.hope", u3_Host.dir_c);
|
2014-03-11 03:13:19 +04:00
|
|
|
c3_assert(ret_i < 2048);
|
|
|
|
|
|
|
|
if ( (fud_i = open(nuu_c, O_CREAT | O_TRUNC | O_RDWR, 0600)) < 0 ) {
|
|
|
|
uL(fprintf(uH, "rest: can't open record (%s)\n", nuu_c));
|
|
|
|
perror("open");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
led_u.mag_l = u3r_mug('g');
|
2014-03-11 03:13:19 +04:00
|
|
|
if ( (sizeof(led_u) != write(fud_i, &led_u, sizeof(led_u))) ) {
|
|
|
|
uL(fprintf(uH, "rest: can't write header\n"));
|
|
|
|
perror("write");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2014-04-08 20:25:49 +04:00
|
|
|
c3_d ent_d = 1;
|
2014-03-11 03:13:19 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
c3_assert(end_d == c3_wiseof(u3_uled));
|
|
|
|
while ( u3_nul != roe ) {
|
|
|
|
u3_noun ovo = u3k(u3h(roe));
|
|
|
|
u3_noun nex = u3k(u3t(roe));
|
|
|
|
u3_ular lar_u;
|
2014-03-11 03:13:19 +04:00
|
|
|
c3_w* img_w;
|
|
|
|
c3_d tar_d;
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
lar_u.len_w = u3r_met(5, ovo);
|
2014-03-11 03:13:19 +04:00
|
|
|
tar_d = end_d + lar_u.len_w;
|
2014-11-06 03:20:01 +03:00
|
|
|
lar_u.syn_w = u3r_mug(tar_d);
|
2014-04-08 20:25:49 +04:00
|
|
|
lar_u.ent_d = ent_d;
|
2014-03-11 03:13:19 +04:00
|
|
|
lar_u.tem_w = 0;
|
|
|
|
lar_u.typ_w = c3__ov;
|
2014-11-06 03:20:01 +03:00
|
|
|
lar_u.mug_w = u3r_mug_both(u3r_mug(ovo),
|
|
|
|
u3r_mug_both(u3r_mug(0),
|
|
|
|
u3r_mug(c3__ov)));
|
2014-03-11 03:13:19 +04:00
|
|
|
|
2014-04-02 04:47:01 +04:00
|
|
|
img_w = c3_malloc(lar_u.len_w << 2);
|
2014-11-06 03:20:01 +03:00
|
|
|
u3r_words(0, lar_u.len_w, img_w, ovo);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(ovo);
|
2014-03-11 03:13:19 +04:00
|
|
|
|
|
|
|
if ( (lar_u.len_w << 2) != write(fud_i, img_w, lar_u.len_w << 2) ) {
|
|
|
|
uL(fprintf(uH, "rest_nuu failed (h)\n"));
|
|
|
|
perror("write");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( sizeof(u3_ular) != write(fud_i, &lar_u, sizeof(u3_ular)) ) {
|
2014-03-11 03:13:19 +04:00
|
|
|
uL(fprintf(uH, "rest_nuu failed (i)\n"));
|
|
|
|
perror("write");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
|
2014-04-08 20:25:49 +04:00
|
|
|
ent_d++;
|
2014-09-11 04:01:32 +04:00
|
|
|
end_d = tar_d + c3_wiseof(u3_ular);
|
|
|
|
u3z(roe); roe = nex;
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( 0 != rename(nuu_c, old_c) ) {
|
|
|
|
uL(fprintf(uH, "rest_nuu failed (k)\n"));
|
|
|
|
perror("rename");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( -1 == lseek64(fud_i, sizeof(u3_uled), SEEK_SET) ) {
|
2014-03-11 03:13:19 +04:00
|
|
|
uL(fprintf(uH, "rest_nuu failed (l)\n"));
|
|
|
|
perror("lseek64");
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
|
|
|
lug_u->fid_i = fud_i;
|
|
|
|
lug_u->len_d = end_d;
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:18:07 +04:00
|
|
|
/* _sist_rest(): restore from record, or exit.
|
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
_sist_rest()
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
struct stat buf_b;
|
|
|
|
c3_i fid_i;
|
|
|
|
c3_c ful_c[2048];
|
2014-09-11 04:01:32 +04:00
|
|
|
c3_d old_d = u3A->ent_d;
|
2014-04-08 20:25:49 +04:00
|
|
|
c3_d las_d = 0;
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun roe = u3_nul;
|
2014-12-12 02:54:26 +03:00
|
|
|
u3_noun sev_l, key_l, sal_l;
|
2014-11-06 06:10:22 +03:00
|
|
|
u3_noun ohh = c3n;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( 0 != u3A->ent_d ) {
|
|
|
|
u3_noun ent;
|
2014-04-08 20:25:49 +04:00
|
|
|
c3_c* ent_c;
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
ent = u3i_chubs(1, &u3A->ent_d);
|
2014-11-06 06:10:22 +03:00
|
|
|
ent = u3dc("scot", c3__ud, ent);
|
2014-11-06 03:20:01 +03:00
|
|
|
ent_c = u3r_string(ent);
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(fprintf(uH, "rest: checkpoint to event %s\n", ent_c));
|
|
|
|
free(ent_c);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(ent);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Open the fscking file. Does it even exist?
|
|
|
|
{
|
2014-06-06 01:21:11 +04:00
|
|
|
c3_i pig_i = O_RDWR;
|
|
|
|
#ifdef O_DSYNC
|
|
|
|
pig_i |= O_DSYNC;
|
|
|
|
#endif
|
2014-11-16 04:10:15 +03:00
|
|
|
snprintf(ful_c, 2048, "%s/.urb/egz.hope", u3_Host.dir_c);
|
2014-06-06 01:21:11 +04:00
|
|
|
if ( ((fid_i = open(ful_c, pig_i)) < 0) || (fstat(fid_i, &buf_b) < 0) ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(fprintf(uH, "rest: can't open record (%s)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2014-06-06 01:21:11 +04:00
|
|
|
#ifdef F_NOCACHE
|
|
|
|
if ( -1 == fcntl(fid_i, F_NOCACHE, 1) ) {
|
|
|
|
uL(fprintf(uH, "rest: can't uncache %s: %s\n", ful_c, strerror(errno)));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-06-06 01:21:11 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-11 04:01:32 +04:00
|
|
|
u3Z->lug_u.fid_i = fid_i;
|
|
|
|
u3Z->lug_u.len_d = ((buf_b.st_size + 3ULL) >> 2ULL);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the fscking header. It's probably corrupt.
|
|
|
|
{
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_uled led_u;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
if ( sizeof(led_u) != read(fid_i, &led_u, sizeof(led_u)) ) {
|
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (a)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( u3r_mug('f') == led_u.mag_l ) {
|
2014-09-11 04:01:32 +04:00
|
|
|
_sist_rest_nuu(&u3Z->lug_u, led_u, ful_c);
|
|
|
|
fid_i = u3Z->lug_u.fid_i;
|
2014-03-11 03:13:19 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
else if (u3r_mug('g') != led_u.mag_l ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(fprintf(uH, "record (%s) is obsolete (or corrupt)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 03:25:27 +03:00
|
|
|
if ( led_u.kno_w != 163 ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
// XX perhaps we should actually do something here
|
|
|
|
//
|
|
|
|
uL(fprintf(uH, "rest: (not) translating events (old %d, now %d)\n",
|
|
|
|
led_u.kno_w,
|
2015-01-27 03:25:27 +03:00
|
|
|
163));
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
sev_l = led_u.sev_l;
|
|
|
|
sal_l = led_u.sal_l;
|
|
|
|
key_l = led_u.key_l;
|
|
|
|
|
|
|
|
{
|
2014-11-06 06:10:22 +03:00
|
|
|
u3_noun old = u3dc("scot", c3__uv, sev_l);
|
|
|
|
u3_noun nuu = u3dc("scot", c3__uv, u3A->sev_l);
|
2014-11-06 03:20:01 +03:00
|
|
|
c3_c* old_c = u3r_string(old);
|
|
|
|
c3_c* nuu_c = u3r_string(nuu);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
uL(fprintf(uH, "rest: old %s, new %s\n", old_c, nuu_c));
|
|
|
|
free(old_c); free(nuu_c);
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(old); u3z(nuu);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
c3_assert(sev_l != u3A->sev_l); // 1 in 2 billion, just retry
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Oh, and let's hope you didn't forget the fscking passcode.
|
|
|
|
{
|
|
|
|
if ( 0 != key_l ) {
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun pas = _sist_staf(key_l);
|
|
|
|
u3_noun key;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
while ( 1 ) {
|
2014-11-16 04:10:15 +03:00
|
|
|
pas = pas ? pas : _sist_cask(u3_Host.dir_c, c3n);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
key = _sist_fatt(sal_l, pas);
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( u3r_mug(key) != key_l ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(fprintf(uH, "incorrect passcode\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(key);
|
2014-02-26 00:18:07 +04:00
|
|
|
pas = 0;
|
|
|
|
}
|
|
|
|
else {
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(u3A->key);
|
|
|
|
u3A->key = key;
|
2014-02-26 00:18:07 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read in the fscking events. These are probably corrupt as well.
|
|
|
|
{
|
2014-04-22 06:06:16 +04:00
|
|
|
c3_d ent_d;
|
2014-04-22 05:52:43 +04:00
|
|
|
c3_d end_d;
|
2014-11-06 06:10:22 +03:00
|
|
|
u3_noun rup = c3n;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
end_d = u3Z->lug_u.len_d;
|
2014-04-08 20:25:49 +04:00
|
|
|
ent_d = 0;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
|
2014-11-29 23:36:33 +03:00
|
|
|
fprintf(stderr, "end_d %" PRIu64 "\n", end_d);
|
2014-02-26 00:18:07 +04:00
|
|
|
perror("lseek");
|
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (c)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
while ( end_d != c3_wiseof(u3_uled) ) {
|
|
|
|
c3_d tar_d = (end_d - (c3_d)c3_wiseof(u3_ular));
|
|
|
|
u3_ular lar_u;
|
2014-02-26 00:18:07 +04:00
|
|
|
c3_w* img_w;
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun ron;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-11-29 23:36:33 +03:00
|
|
|
// uL(fprintf(uH, "rest: reading event at %" PRIx64 "\n", end_d));
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) {
|
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (d)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( sizeof(u3_ular) != read(fid_i, &lar_u, sizeof(u3_ular)) ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (e)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2015-11-07 01:08:58 +03:00
|
|
|
if ( lar_u.syn_w != u3r_mug_d(tar_d) ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == rup ) {
|
2014-04-22 05:52:43 +04:00
|
|
|
uL(fprintf(uH, "corruption detected; attempting to fix\n"));
|
2014-11-05 04:18:47 +03:00
|
|
|
rup = c3y;
|
2014-04-22 05:52:43 +04:00
|
|
|
}
|
2015-11-07 01:08:58 +03:00
|
|
|
uL(fprintf(uH, "lar:%x mug:%x\n", lar_u.syn_w, u3r_mug_d(tar_d)));
|
2014-09-11 04:01:32 +04:00
|
|
|
end_d--; u3Z->lug_u.len_d--;
|
2014-04-22 05:52:43 +04:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-05 04:18:47 +03:00
|
|
|
else if ( c3y == rup ) {
|
2014-04-22 05:52:43 +04:00
|
|
|
uL(fprintf(uH, "matched at %x\n", lar_u.syn_w));
|
2014-11-05 04:18:47 +03:00
|
|
|
rup = c3n;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-04-08 20:25:49 +04:00
|
|
|
if ( lar_u.ent_d == 0 ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
ohh = c3y;
|
2014-03-11 06:50:28 +04:00
|
|
|
}
|
|
|
|
|
2014-02-26 00:18:07 +04:00
|
|
|
#if 0
|
2014-11-29 23:36:33 +03:00
|
|
|
uL(fprintf(uH, "log: read: at %d, %d: lar ent %" PRIu64 ", len %d, mug %x\n",
|
2014-02-26 00:18:07 +04:00
|
|
|
(tar_w - lar_u.len_w),
|
|
|
|
tar_w,
|
2014-04-08 20:25:49 +04:00
|
|
|
lar_u.ent_d,
|
2014-02-26 00:18:07 +04:00
|
|
|
lar_u.len_w,
|
|
|
|
lar_u.mug_w));
|
|
|
|
#endif
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( end_d == u3Z->lug_u.len_d ) {
|
2014-04-08 20:25:49 +04:00
|
|
|
ent_d = las_d = lar_u.ent_d;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-04-08 20:25:49 +04:00
|
|
|
if ( lar_u.ent_d != (ent_d - 1ULL) ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (g)\n", ful_c));
|
2014-11-29 23:36:33 +03:00
|
|
|
uL(fprintf(uH, "lar_u.ent_d %" PRIx64 ", ent_d %" PRIx64 "\n", lar_u.ent_d, ent_d));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-04-08 20:25:49 +04:00
|
|
|
ent_d -= 1ULL;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
end_d = (tar_d - (c3_d)lar_u.len_w);
|
|
|
|
|
2014-04-08 20:25:49 +04:00
|
|
|
if ( ent_d < old_d ) {
|
2016-08-04 03:30:28 +03:00
|
|
|
/* change to continue to check all events */
|
|
|
|
break;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-04-02 04:47:01 +04:00
|
|
|
img_w = c3_malloc(4 * lar_u.len_w);
|
2014-03-11 06:50:28 +04:00
|
|
|
|
2014-02-26 00:18:07 +04:00
|
|
|
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
|
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (h)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) {
|
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (i)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
ron = u3i_words(lar_u.len_w, img_w);
|
2014-02-26 00:18:07 +04:00
|
|
|
free(img_w);
|
|
|
|
|
2014-03-11 03:13:19 +04:00
|
|
|
if ( lar_u.mug_w !=
|
2014-11-06 03:20:01 +03:00
|
|
|
u3r_mug_both(u3r_mug(ron),
|
|
|
|
u3r_mug_both(u3r_mug(lar_u.tem_w),
|
|
|
|
u3r_mug(lar_u.typ_w))) )
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (j)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-03-11 03:13:19 +04:00
|
|
|
if ( c3__ov != lar_u.typ_w ) {
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(ron);
|
2014-03-11 03:13:19 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-09-28 03:28:11 +03:00
|
|
|
#if 0
|
|
|
|
// disable encryption for now
|
|
|
|
//
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( u3A->key ) {
|
|
|
|
u3_noun dep;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-11-06 06:10:22 +03:00
|
|
|
dep = u3dc("de:crua", u3k(u3A->key), ron);
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == u3du(dep) ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(fprintf(uH, "record (%s) is corrupt (k)\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-11 04:01:32 +04:00
|
|
|
ron = u3k(u3t(dep));
|
|
|
|
u3z(dep);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
}
|
2017-09-28 03:28:11 +03:00
|
|
|
#endif
|
2014-11-06 22:13:57 +03:00
|
|
|
roe = u3nc(u3ke_cue(ron), roe);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
u3A->ent_d = c3_max(las_d + 1ULL, old_d);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( u3_nul == roe ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
// Nothing in the log that was not also in the checkpoint.
|
|
|
|
//
|
2014-09-11 04:01:32 +04:00
|
|
|
c3_assert(u3A->ent_d == old_d);
|
2014-04-18 21:24:59 +04:00
|
|
|
if ( las_d + 1 != old_d ) {
|
2014-11-29 23:36:33 +03:00
|
|
|
uL(fprintf(uH, "checkpoint and log disagree! las:%" PRIu64 " old:%" PRIu64 "\n",
|
2014-04-18 21:24:59 +04:00
|
|
|
las_d + 1, old_d));
|
2014-04-17 22:40:00 +04:00
|
|
|
uL(fprintf(uH, "Some events appear to be missing from the log.\n"
|
|
|
|
"Please contact the authorities, "
|
|
|
|
"and do not delete your pier!\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-04-17 22:40:00 +04:00
|
|
|
}
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun rou = roe;
|
2014-02-26 00:18:07 +04:00
|
|
|
c3_w xno_w;
|
|
|
|
|
|
|
|
// Execute the fscking things. This is pretty much certain to crash.
|
|
|
|
//
|
2014-11-29 23:36:33 +03:00
|
|
|
uL(fprintf(uH, "rest: replaying through event %" PRIu64 "\n", las_d));
|
2014-02-26 00:18:07 +04:00
|
|
|
fprintf(uH, "---------------- playback starting----------------\n");
|
|
|
|
|
|
|
|
xno_w = 0;
|
2014-09-11 04:01:32 +04:00
|
|
|
while ( u3_nul != roe ) {
|
|
|
|
u3_noun i_roe = u3h(roe);
|
|
|
|
u3_noun t_roe = u3t(roe);
|
|
|
|
u3_noun now = u3h(i_roe);
|
|
|
|
u3_noun ovo = u3t(i_roe);
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
u3v_time(u3k(now));
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( (c3y == u3_Host.ops_u.vno) &&
|
2014-09-11 04:01:32 +04:00
|
|
|
( (c3__veer == u3h(u3t(ovo)) ||
|
|
|
|
(c3__vega == u3h(u3t(ovo)))) ) )
|
2014-06-03 09:07:32 +04:00
|
|
|
{
|
2014-03-28 23:00:04 +04:00
|
|
|
fprintf(stderr, "replay: skipped veer\n");
|
|
|
|
}
|
2014-02-26 00:18:07 +04:00
|
|
|
else {
|
2014-09-11 04:01:32 +04:00
|
|
|
_sist_sing(u3k(ovo));
|
2014-03-28 23:00:04 +04:00
|
|
|
fputc('.', stderr);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-03-28 23:00:04 +04:00
|
|
|
// fprintf(stderr, "playback: sing: %d\n", xno_w));
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
roe = t_roe;
|
|
|
|
xno_w++;
|
|
|
|
|
|
|
|
if ( 0 == (xno_w % 1000) ) {
|
|
|
|
uL(fprintf(uH, "{%d}\n", xno_w));
|
2014-11-06 02:36:30 +03:00
|
|
|
// u3_lo_grab("rest", rou, u3_none);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(rou);
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2018-10-09 20:35:25 +03:00
|
|
|
uL(fprintf(stderr, "\n---------------- playback complete----------------\r\n"));
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// If you see this error, your record is totally fscking broken!
|
|
|
|
// Which probably serves you right. Please consult a consultant.
|
|
|
|
{
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( u3_nul == u3A->own ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
uL(fprintf(uH, "record did not install a master!\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
u3A->our = u3k(u3h(u3A->own));
|
2014-11-06 06:10:22 +03:00
|
|
|
u3A->pod = u3dc("scot", 'p', u3k(u3A->our)));
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now, who the fsck are you? No, really.
|
|
|
|
{
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_noun who;
|
2014-02-26 00:18:07 +04:00
|
|
|
c3_c* fil_c;
|
|
|
|
c3_c* who_c;
|
|
|
|
|
2014-11-16 04:10:15 +03:00
|
|
|
if ( (fil_c = strrchr(u3_Host.dir_c, '/')) ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
fil_c++;
|
2014-11-16 04:10:15 +03:00
|
|
|
} else fil_c = u3_Host.dir_c;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-11-06 06:10:22 +03:00
|
|
|
who = u3dc("scot", 'p', u3k(u3A->our)));
|
2014-11-06 03:20:01 +03:00
|
|
|
who_c = u3r_string(who);
|
2014-09-11 04:01:32 +04:00
|
|
|
u3z(who);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
|
|
|
if ( strncmp(fil_c, who_c + 1, strlen(fil_c)) ) {
|
|
|
|
uL(fprintf(uH, "record master (%s) does not match filename!\n", who_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
free(who_c);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-11 06:50:28 +04:00
|
|
|
// Increment sequence numbers. New logs start at 1.
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == ohh ) {
|
2015-07-14 03:46:37 +03:00
|
|
|
uL(fprintf(uH, "rest: bumping ent_d\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_ular lar_u;
|
2014-03-11 06:50:28 +04:00
|
|
|
c3_d end_d;
|
|
|
|
c3_d tar_d;
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
u3A->ent_d++;
|
|
|
|
end_d = u3Z->lug_u.len_d;
|
|
|
|
while ( end_d != c3_wiseof(u3_uled) ) {
|
|
|
|
tar_d = end_d - c3_wiseof(u3_ular);
|
2014-03-11 06:50:28 +04:00
|
|
|
if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) {
|
|
|
|
uL(fprintf(uH, "bumping sequence numbers failed (a)\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 06:50:28 +04:00
|
|
|
}
|
|
|
|
if ( sizeof(lar_u) != read(fid_i, &lar_u, sizeof(lar_u)) ) {
|
|
|
|
uL(fprintf(uH, "bumping sequence numbers failed (b)\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 06:50:28 +04:00
|
|
|
}
|
2014-04-08 20:25:49 +04:00
|
|
|
lar_u.ent_d++;
|
2014-03-11 06:50:28 +04:00
|
|
|
if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) {
|
|
|
|
uL(fprintf(uH, "bumping sequence numbers failed (c)\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 06:50:28 +04:00
|
|
|
}
|
|
|
|
if ( sizeof(lar_u) != write(fid_i, &lar_u, sizeof(lar_u)) ) {
|
|
|
|
uL(fprintf(uH, "bumping sequence numbers failed (d)\n"));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-03-11 06:50:28 +04:00
|
|
|
}
|
|
|
|
end_d = tar_d - lar_u.len_w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:18:07 +04:00
|
|
|
// Rewrite the header. Will probably corrupt the record.
|
|
|
|
{
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_uled led_u;
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
led_u.mag_l = u3r_mug('g');
|
2014-02-26 00:18:07 +04:00
|
|
|
led_u.sal_l = sal_l;
|
2014-09-11 04:01:32 +04:00
|
|
|
led_u.sev_l = u3A->sev_l;
|
2014-11-06 03:20:01 +03:00
|
|
|
led_u.key_l = u3A->key ? u3r_mug(u3A->key) : 0;
|
2015-01-27 03:25:27 +03:00
|
|
|
led_u.kno_w = 163; // may need actual translation!
|
2014-02-26 00:18:07 +04:00
|
|
|
led_u.tno_l = 1;
|
|
|
|
|
|
|
|
if ( (-1 == lseek64(fid_i, 0, SEEK_SET)) ||
|
|
|
|
(sizeof(led_u) != write(fid_i, &led_u, sizeof(led_u))) )
|
|
|
|
{
|
|
|
|
uL(fprintf(uH, "record (%s) failed to rewrite\n", ful_c));
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_lo_bail();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hey, fscker! It worked.
|
|
|
|
{
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_term_ef_boil();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-07 04:35:17 +03:00
|
|
|
/* _sist_curl_alloc(): allocate a response buffer for curl
|
|
|
|
*/
|
|
|
|
static size_t
|
|
|
|
_sist_curl_alloc(void* dat_v, size_t uni_t, size_t mem_t, uv_buf_t* buf_u)
|
|
|
|
{
|
|
|
|
size_t siz_t = uni_t * mem_t;
|
|
|
|
buf_u->base = realloc(buf_u->base, 1 + siz_t + buf_u->len);
|
|
|
|
|
|
|
|
if ( 0 == buf_u->base ) {
|
|
|
|
fprintf(stderr, "out of memory\n");
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buf_u->base + buf_u->len, dat_v, siz_t);
|
|
|
|
buf_u->len += siz_t;
|
|
|
|
buf_u->base[buf_u->len] = 0;
|
|
|
|
|
|
|
|
return siz_t;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_post_json(): POST JSON to url_c
|
|
|
|
*/
|
|
|
|
static uv_buf_t
|
|
|
|
_sist_post_json(c3_c* url_c, uv_buf_t lod_u)
|
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
CURLcode result;
|
|
|
|
long cod_l;
|
|
|
|
struct curl_slist* hed_u = 0;
|
|
|
|
|
|
|
|
uv_buf_t buf_u = uv_buf_init(c3_malloc(1), 0);
|
|
|
|
|
|
|
|
if ( !(curl = curl_easy_init()) ) {
|
|
|
|
fprintf(stderr, "failed to initialize libcurl\n");
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
hed_u = curl_slist_append(hed_u, "Accept: application/json");
|
|
|
|
hed_u = curl_slist_append(hed_u, "Content-Type: application/json");
|
|
|
|
hed_u = curl_slist_append(hed_u, "charsets: utf-8");
|
|
|
|
|
2018-10-10 18:18:54 +03:00
|
|
|
// XX require TLS, pin default cert?
|
|
|
|
|
2018-09-07 04:35:17 +03:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url_c);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _sist_curl_alloc);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&buf_u);
|
2018-10-24 20:38:09 +03:00
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hed_u);
|
2018-09-07 04:35:17 +03:00
|
|
|
|
|
|
|
// note: must be terminated!
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, lod_u.base);
|
|
|
|
|
|
|
|
result = curl_easy_perform(curl);
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &cod_l);
|
|
|
|
|
|
|
|
// XX retry?
|
|
|
|
if ( CURLE_OK != result ) {
|
|
|
|
fprintf(stderr, "failed to fetch %s: %s\n",
|
|
|
|
url_c, curl_easy_strerror(result));
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
if ( 300 <= cod_l ) {
|
|
|
|
fprintf(stderr, "error fetching %s: HTTP %ld\n", url_c, cod_l);
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_easy_cleanup(curl);
|
2018-10-24 20:38:09 +03:00
|
|
|
curl_slist_free_all(hed_u);
|
2018-09-07 04:35:17 +03:00
|
|
|
|
|
|
|
return buf_u;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_oct_to_buf(): +octs to uv_buf_t
|
|
|
|
*/
|
|
|
|
static uv_buf_t
|
|
|
|
_sist_oct_to_buf(u3_noun oct)
|
|
|
|
{
|
|
|
|
if ( c3n == u3a_is_cat(u3h(oct)) ) {
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
c3_w len_w = u3h(oct);
|
|
|
|
c3_y* buf_y = c3_malloc(1 + len_w);
|
|
|
|
buf_y[len_w] = 0;
|
|
|
|
|
|
|
|
u3r_bytes(0, len_w, buf_y, u3t(oct));
|
|
|
|
|
|
|
|
u3z(oct);
|
|
|
|
return uv_buf_init((void*)buf_y, len_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_buf_to_oct(): uv_buf_t to +octs
|
|
|
|
*/
|
|
|
|
static u3_noun
|
|
|
|
_sist_buf_to_oct(uv_buf_t buf_u)
|
|
|
|
{
|
|
|
|
u3_noun len = u3i_words(1, (c3_w*)&buf_u.len);
|
|
|
|
|
|
|
|
if ( c3n == u3a_is_cat(len) ) {
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
return u3nc(len, u3i_bytes(buf_u.len, (const c3_y*)buf_u.base));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_eth_rpc(): ethereum JSON RPC with request/response as +octs
|
|
|
|
*/
|
|
|
|
static u3_noun
|
|
|
|
_sist_eth_rpc(c3_c* url_c, u3_noun oct)
|
|
|
|
{
|
|
|
|
return _sist_buf_to_oct(_sist_post_json(url_c, _sist_oct_to_buf(oct)));
|
|
|
|
}
|
|
|
|
|
2018-10-18 22:13:14 +03:00
|
|
|
/* _sist_dawn_fail(): pre-boot validation failed
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_sist_dawn_fail(u3_noun who, u3_noun rac, u3_noun sas)
|
|
|
|
{
|
|
|
|
u3_noun how = u3dc("scot", 'p', u3k(who));
|
|
|
|
c3_c* how_c = u3r_string(u3k(how));
|
|
|
|
|
|
|
|
c3_c* rac_c;
|
|
|
|
|
|
|
|
switch (rac) {
|
|
|
|
default: c3_assert(0);
|
|
|
|
case c3__czar: {
|
|
|
|
rac_c = "galaxy";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case c3__king: {
|
|
|
|
rac_c = "star";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case c3__duke: {
|
|
|
|
rac_c = "planet";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case c3__earl: {
|
|
|
|
rac_c = "moon";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case c3__pawn: {
|
|
|
|
rac_c = "comet";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "dawn: invalid keys for %s '%s'\r\n", rac_c, how_c);
|
|
|
|
|
|
|
|
// XX deconstruct sas, print helpful error messages
|
|
|
|
u3m_p("pre-boot error", u3t(sas));
|
|
|
|
|
|
|
|
u3z(how);
|
|
|
|
free(how_c);
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
2018-11-09 06:28:00 +03:00
|
|
|
/* _sist_dawn_turf(): override contract domains with -H
|
|
|
|
*/
|
|
|
|
static u3_noun
|
|
|
|
_sist_dawn_turf(c3_c* dns_c)
|
|
|
|
{
|
|
|
|
u3_noun tuf;
|
|
|
|
|
|
|
|
u3_noun par = u3v_wish("thos:de-purl:html");
|
|
|
|
u3_noun dns = u3i_string(dns_c);
|
|
|
|
u3_noun rul = u3dc("rush", u3k(dns), u3k(par));
|
|
|
|
|
|
|
|
if ( (u3_nul == rul) || (c3n == u3h(u3t(rul))) ) {
|
|
|
|
fprintf(stderr, "boot: invalid domain specified with -H %s\r\n", dns_c);
|
|
|
|
// bails, won't return
|
|
|
|
u3_lo_bail();
|
|
|
|
return u3_none;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "boot: overriding network domains with %s\r\n", dns_c);
|
|
|
|
u3_noun dom = u3t(u3t(rul));
|
|
|
|
tuf = u3nc(u3k(dom), u3_nul);
|
|
|
|
}
|
|
|
|
|
|
|
|
u3z(par); u3z(dns); u3z(rul);
|
|
|
|
|
|
|
|
return tuf;
|
|
|
|
}
|
|
|
|
|
2018-09-07 04:35:17 +03:00
|
|
|
/* _sist_dawn(): produce %dawn boot card - validate keys and query contract
|
|
|
|
*/
|
|
|
|
static u3_noun
|
2018-10-18 01:56:12 +03:00
|
|
|
_sist_dawn(u3_noun sed)
|
2018-09-07 04:35:17 +03:00
|
|
|
{
|
2018-11-01 01:19:42 +03:00
|
|
|
u3_noun url, bok, pon, zar, tuf, sap;
|
2018-10-18 01:56:12 +03:00
|
|
|
|
|
|
|
u3_noun who = u3h(sed);
|
2018-10-18 22:13:14 +03:00
|
|
|
u3_noun rac = u3do("clan:title", u3k(who));
|
2018-09-07 04:35:17 +03:00
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
// load snapshot if exists
|
|
|
|
if ( 0 != u3_Host.ops_u.ets_c ) {
|
|
|
|
fprintf(stderr, "boot: loading ethereum snapshot\r\n");
|
|
|
|
u3_noun raw_snap = u3ke_cue(u3m_file(u3_Host.ops_u.ets_c));
|
|
|
|
sap = u3nc(u3_nul, raw_snap);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sap = u3_nul;
|
|
|
|
}
|
2018-10-29 21:01:45 +03:00
|
|
|
|
2018-10-29 21:58:07 +03:00
|
|
|
// ethereum gateway as (unit purl)
|
|
|
|
if ( 0 == u3_Host.ops_u.eth_c ) {
|
|
|
|
if ( c3__czar == rac ) {
|
|
|
|
fprintf(stderr, "boot: galaxy requires ethereum gateway via -e\r\n");
|
|
|
|
// bails, won't return
|
|
|
|
u3_lo_bail();
|
|
|
|
return u3_none;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = u3_nul;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u3_noun par = u3v_wish("auru:de-purl:html");
|
|
|
|
u3_noun lur = u3i_string(u3_Host.ops_u.eth_c);
|
|
|
|
u3_noun rul = u3dc("rush", u3k(lur), u3k(par));
|
|
|
|
|
|
|
|
if ( u3_nul == rul ) {
|
|
|
|
if ( c3__czar == rac ) {
|
|
|
|
fprintf(stderr, "boot: galaxy requires ethereum gateway via -e\r\n");
|
|
|
|
// bails, won't return
|
|
|
|
u3_lo_bail();
|
|
|
|
return u3_none;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = u3_nul;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// auru:de-purl:html parses to (pair user purl)
|
|
|
|
// we need (unit purl)
|
|
|
|
// (we're using it to avoid the +hoke weirdness)
|
|
|
|
// XX revisit upon merging with release-candidate
|
|
|
|
url = u3nc(u3_nul, u3k(u3t(u3t(rul))));
|
|
|
|
}
|
|
|
|
|
|
|
|
u3z(par); u3z(lur); u3z(rul);
|
|
|
|
}
|
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
// XX require https?
|
|
|
|
c3_c* url_c = ( 0 != u3_Host.ops_u.eth_c ) ?
|
|
|
|
u3_Host.ops_u.eth_c :
|
|
|
|
"https://ropsten.infura.io/v3/196a7f37c7d54211b4a07904ec73ad87";
|
|
|
|
|
2018-10-29 21:01:45 +03:00
|
|
|
{
|
|
|
|
fprintf(stderr, "boot: retrieving latest block\r\n");
|
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
if ( c3y == u3_Host.ops_u.etn ) {
|
|
|
|
bok = u3do("bloq:snap:dawn", u3k(u3t(sap)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// @ud: block number
|
|
|
|
u3_noun oct = u3v_wish("bloq:give:dawn");
|
|
|
|
u3_noun kob = _sist_eth_rpc(url_c, u3k(oct));
|
|
|
|
bok = u3do("bloq:take:dawn", u3k(kob));
|
2018-10-29 21:01:45 +03:00
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
u3z(oct); u3z(kob);
|
|
|
|
}
|
2018-10-29 21:01:45 +03:00
|
|
|
}
|
2018-10-10 18:18:54 +03:00
|
|
|
|
2018-10-10 09:04:46 +03:00
|
|
|
{
|
|
|
|
// +hull:constitution:ethe: on-chain state
|
2018-10-18 22:24:04 +03:00
|
|
|
u3_noun hul;
|
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
if ( c3y == u3_Host.ops_u.etn ) {
|
|
|
|
hul = u3dc("hull:snap:dawn", u3k(who), u3k(u3t(sap)));
|
|
|
|
}
|
|
|
|
else {
|
2018-10-18 22:24:04 +03:00
|
|
|
if ( c3__pawn == rac ) {
|
|
|
|
// irrelevant, just bunt +hull
|
|
|
|
hul = u3v_wish("*hull:constitution:ethe");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u3_noun oct;
|
|
|
|
|
|
|
|
if ( c3__earl == rac ) {
|
|
|
|
u3_noun seg = u3do("^sein:title", u3k(who));
|
|
|
|
u3_noun ges = u3dc("scot", 'p', u3k(seg));
|
|
|
|
c3_c* seg_c = u3r_string(ges);
|
|
|
|
|
|
|
|
fprintf(stderr, "boot: retrieving %s's public keys (for %s)\r\n",
|
|
|
|
seg_c, u3_Host.ops_u.who_c);
|
2018-10-29 21:01:45 +03:00
|
|
|
oct = u3dc("hull:give:dawn", u3k(bok), u3k(seg));
|
2018-10-18 22:24:04 +03:00
|
|
|
|
|
|
|
free(seg_c);
|
|
|
|
u3z(seg); u3z(ges);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "boot: retrieving %s's public keys\r\n",
|
|
|
|
u3_Host.ops_u.who_c);
|
2018-10-29 21:01:45 +03:00
|
|
|
oct = u3dc("hull:give:dawn", u3k(bok), u3k(who));
|
2018-10-18 22:24:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
u3_noun luh = _sist_eth_rpc(url_c, u3k(oct));
|
|
|
|
hul = u3dc("hull:take:dawn", u3k(who), u3k(luh));
|
|
|
|
|
|
|
|
u3z(oct); u3z(luh);
|
|
|
|
}
|
|
|
|
}
|
2018-10-10 09:04:46 +03:00
|
|
|
|
|
|
|
// +live:dawn: network state
|
|
|
|
// XX actually make request
|
|
|
|
// u3_noun liv = _sist_get_json(parent, /some/url)
|
|
|
|
u3_noun liv = u3_nul;
|
|
|
|
|
2018-10-18 21:47:15 +03:00
|
|
|
fprintf(stderr, "boot: verifying keys\r\n");
|
|
|
|
|
2018-10-12 20:45:20 +03:00
|
|
|
// (each sponsor=(unit ship) error=@tas)
|
2018-10-10 09:04:46 +03:00
|
|
|
u3_noun sas = u3dt("veri:dawn", u3k(sed), u3k(hul), u3k(liv));
|
|
|
|
|
|
|
|
if ( c3n == u3h(sas) ) {
|
2018-10-18 22:13:14 +03:00
|
|
|
// bails, won't return
|
|
|
|
_sist_dawn_fail(who, rac, sas);
|
|
|
|
return u3_none;
|
2018-10-10 09:04:46 +03:00
|
|
|
}
|
2018-09-07 04:35:17 +03:00
|
|
|
|
2018-10-10 09:04:46 +03:00
|
|
|
// (unit ship): sponsor
|
|
|
|
// produced by +veri:dawn to avoid coupling to +hull structure
|
2018-10-12 20:45:20 +03:00
|
|
|
pon = u3k(u3t(sas));
|
2018-09-07 04:35:17 +03:00
|
|
|
|
2018-10-18 22:24:04 +03:00
|
|
|
u3z(hul); u3z(liv); u3z(sas);
|
2018-09-07 04:35:17 +03:00
|
|
|
}
|
|
|
|
|
2018-10-10 09:04:46 +03:00
|
|
|
{
|
2018-11-01 01:19:42 +03:00
|
|
|
if ( c3y == u3_Host.ops_u.etn ) {
|
|
|
|
zar = u3do("czar:snap:dawn", u3k(u3t(sap)));
|
2018-11-09 06:28:00 +03:00
|
|
|
|
|
|
|
if ( 0 != u3_Host.ops_u.dns_c ) {
|
|
|
|
tuf = _sist_dawn_turf(u3_Host.ops_u.dns_c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tuf = u3do("turf:snap:dawn", u3k(u3t(sap)));
|
|
|
|
}
|
2018-11-01 01:19:42 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
{
|
|
|
|
fprintf(stderr, "boot: retrieving galaxy table\r\n");
|
2018-10-18 21:47:15 +03:00
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
// (map ship [=life =pass]): galaxy table
|
|
|
|
u3_noun oct = u3do("czar:give:dawn", u3k(bok));
|
|
|
|
u3_noun raz = _sist_eth_rpc(url_c, u3k(oct));
|
|
|
|
zar = u3do("czar:take:dawn", u3k(raz));
|
2018-10-10 09:04:46 +03:00
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
u3z(oct); u3z(raz);
|
|
|
|
}
|
2018-09-07 04:35:17 +03:00
|
|
|
|
2018-11-09 06:28:00 +03:00
|
|
|
if ( 0 != u3_Host.ops_u.dns_c ) {
|
|
|
|
tuf = _sist_dawn_turf(u3_Host.ops_u.dns_c);
|
|
|
|
}
|
|
|
|
else {
|
2018-11-01 01:19:42 +03:00
|
|
|
fprintf(stderr, "boot: retrieving network domains\r\n");
|
2018-10-18 21:47:15 +03:00
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
// (list turf): ames domains
|
|
|
|
u3_noun oct = u3do("turf:give:dawn", u3k(bok));
|
|
|
|
u3_noun fut = _sist_eth_rpc(url_c, u3k(oct));
|
|
|
|
tuf = u3do("turf:take:dawn", u3k(fut));
|
2018-09-07 04:35:17 +03:00
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
u3z(oct); u3z(fut);
|
|
|
|
}
|
|
|
|
}
|
2018-10-10 09:04:46 +03:00
|
|
|
}
|
2018-09-07 04:35:17 +03:00
|
|
|
|
2018-10-18 22:13:14 +03:00
|
|
|
u3z(rac);
|
2018-10-29 21:01:45 +03:00
|
|
|
|
2018-11-01 01:19:42 +03:00
|
|
|
// [%dawn seed sponsor galaxies domains block eth-url snap]
|
|
|
|
return u3nc(c3__dawn, u3nq(sed, pon, zar, u3nq(tuf, bok, url, sap)));
|
2018-09-07 04:35:17 +03:00
|
|
|
}
|
|
|
|
|
2018-10-18 01:56:12 +03:00
|
|
|
/* _sist_zen(): get OS entropy.
|
|
|
|
*/
|
|
|
|
static u3_noun
|
|
|
|
_sist_zen(void)
|
|
|
|
{
|
|
|
|
c3_w rad_w[16];
|
|
|
|
|
|
|
|
c3_rand(rad_w);
|
|
|
|
return u3i_words(16, rad_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _sist_come(): mine a comet.
|
|
|
|
*/
|
|
|
|
static u3_noun
|
|
|
|
_sist_come(void)
|
|
|
|
{
|
|
|
|
u3_noun tar, eny, sed;
|
|
|
|
|
|
|
|
// XX choose from list, at random, &c
|
|
|
|
tar = u3dc("slav", 'p', u3i_string("~marzod"));
|
|
|
|
eny = _sist_zen();
|
|
|
|
|
|
|
|
{
|
|
|
|
u3_noun sar = u3dc("scot", 'p', u3k(tar));
|
|
|
|
c3_c* tar_c = u3r_string(sar);
|
|
|
|
|
|
|
|
fprintf(stderr, "boot: mining a comet under %s\r\n", tar_c);
|
|
|
|
free(tar_c);
|
|
|
|
u3z(sar);
|
|
|
|
}
|
|
|
|
|
|
|
|
sed = u3dc("come:dawn", u3k(tar), u3k(eny));
|
|
|
|
|
|
|
|
{
|
|
|
|
u3_noun who = u3dc("scot", 'p', u3k(u3h(sed)));
|
|
|
|
c3_c* who_c = u3r_string(who);
|
|
|
|
|
|
|
|
fprintf(stderr, "boot: found comet %s\r\n", who_c);
|
|
|
|
free(who_c);
|
|
|
|
u3z(who);
|
|
|
|
}
|
|
|
|
|
|
|
|
u3z(tar); u3z(eny);
|
|
|
|
|
|
|
|
return sed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sist_key(): parse a private key-file.
|
|
|
|
*/
|
|
|
|
static u3_noun
|
|
|
|
sist_key(u3_noun des)
|
|
|
|
{
|
|
|
|
u3_noun sed, who;
|
|
|
|
|
|
|
|
u3_noun eds = u3dc("slaw", c3__uw, u3k(des));
|
|
|
|
|
|
|
|
if ( u3_nul == eds ) {
|
|
|
|
c3_c* sed_c = u3r_string(des);
|
|
|
|
fprintf(stderr, "dawn: invalid private keys: %s\r\n", sed_c);
|
|
|
|
free(sed_c);
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 0 == u3_Host.ops_u.who_c ) {
|
|
|
|
fprintf(stderr, "dawn: -w required\r\n");
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
u3_noun woh = u3i_string(u3_Host.ops_u.who_c);
|
|
|
|
u3_noun whu = u3dc("slaw", 'p', u3k(woh));
|
|
|
|
|
|
|
|
if ( u3_nul == whu ) {
|
|
|
|
fprintf(stderr, "dawn: invalid ship specificed with -w %s\r\n",
|
|
|
|
u3_Host.ops_u.who_c);
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
// +seed:able:jael: private key file
|
|
|
|
sed = u3ke_cue(u3k(u3t(eds)));
|
|
|
|
who = u3h(sed);
|
|
|
|
|
|
|
|
if ( c3n == u3r_sing(who, u3t(whu)) ) {
|
|
|
|
u3_noun how = u3dc("scot", 'p', u3k(who));
|
|
|
|
c3_c* how_c = u3r_string(u3k(how));
|
|
|
|
fprintf(stderr, "dawn: mismatch between -w %s and -K %s\r\n",
|
|
|
|
u3_Host.ops_u.who_c, how_c);
|
|
|
|
|
|
|
|
u3z(how);
|
|
|
|
free(how_c);
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
u3z(woh); u3z(whu); u3z(des); u3z(eds);
|
|
|
|
|
|
|
|
return sed;
|
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
/* u3_sist_boot(): restore or create.
|
2014-02-26 00:18:07 +04:00
|
|
|
*/
|
|
|
|
void
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_sist_boot(void)
|
2014-02-26 00:18:07 +04:00
|
|
|
{
|
2018-10-10 09:04:46 +03:00
|
|
|
if ( c3n == u3_Host.ops_u.nuu ) {
|
|
|
|
_sist_rest();
|
|
|
|
|
|
|
|
if ( c3y == u3A->fak ) {
|
|
|
|
c3_c* who_c = u3r_string(u3dc("scot", 'p', u3k(u3A->own)));
|
|
|
|
fprintf(stderr, "fake: %s\r\n", who_c);
|
|
|
|
free(who_c);
|
|
|
|
|
2018-11-06 19:16:58 +03:00
|
|
|
// XX review persistent options
|
|
|
|
|
|
|
|
// disable networking
|
2018-10-10 09:04:46 +03:00
|
|
|
u3_Host.ops_u.net = c3n;
|
2018-11-06 19:16:58 +03:00
|
|
|
// disable battery hashes
|
|
|
|
u3_Host.ops_u.has = c3y;
|
|
|
|
u3C.wag_w |= u3o_hashless;
|
2018-10-10 09:04:46 +03:00
|
|
|
}
|
2018-11-27 00:31:55 +03:00
|
|
|
|
|
|
|
// process pending events
|
|
|
|
u3_raft_work();
|
2018-10-10 09:04:46 +03:00
|
|
|
}
|
|
|
|
else {
|
2018-10-17 00:26:41 +03:00
|
|
|
u3_noun pig, who;
|
2018-09-15 08:39:13 +03:00
|
|
|
|
2018-08-10 19:58:21 +03:00
|
|
|
if ( 0 != u3_Host.ops_u.fak_c ) {
|
|
|
|
u3_noun whu = u3dc("slaw", 'p', u3i_string(u3_Host.ops_u.fak_c));
|
2018-09-15 08:39:13 +03:00
|
|
|
|
|
|
|
if ( (u3_nul == whu) ) {
|
2018-08-10 19:58:21 +03:00
|
|
|
fprintf(stderr, "fake: invalid ship: %s\r\n", u3_Host.ops_u.fak_c);
|
2018-09-15 08:39:13 +03:00
|
|
|
u3_lo_bail();
|
|
|
|
}
|
2018-10-18 01:56:12 +03:00
|
|
|
else {
|
|
|
|
u3_noun rac = u3do("clan:title", u3k(u3t(whu)));
|
|
|
|
|
|
|
|
if ( c3__pawn == rac ) {
|
|
|
|
fprintf(stderr, "fake comets are disallowed\r\n");
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
|
|
|
u3z(rac);
|
|
|
|
}
|
2018-09-15 08:39:13 +03:00
|
|
|
|
2018-08-10 19:58:21 +03:00
|
|
|
fprintf(stderr, "fake: %s\r\n", u3_Host.ops_u.fak_c);
|
|
|
|
|
|
|
|
u3A->fak = c3y;
|
2018-10-17 00:26:41 +03:00
|
|
|
who = u3k(u3t(whu));
|
2018-10-10 09:04:46 +03:00
|
|
|
pig = u3nc(c3__fake, u3k(who));
|
|
|
|
|
2018-08-10 19:58:21 +03:00
|
|
|
u3z(whu);
|
2018-09-15 08:39:13 +03:00
|
|
|
}
|
|
|
|
else {
|
2018-10-18 01:56:12 +03:00
|
|
|
u3_noun sed;
|
2018-10-10 18:38:32 +03:00
|
|
|
|
|
|
|
if ( 0 != u3_Host.ops_u.key_c ) {
|
2018-10-18 01:56:12 +03:00
|
|
|
u3_noun des = u3m_file(u3_Host.ops_u.key_c);
|
|
|
|
sed = sist_key(des);
|
2018-10-10 18:38:32 +03:00
|
|
|
}
|
|
|
|
else if ( 0 != u3_Host.ops_u.gen_c ) {
|
2018-10-18 01:56:12 +03:00
|
|
|
u3_noun des = u3i_string(u3_Host.ops_u.gen_c);
|
|
|
|
sed = sist_key(des);
|
2018-10-10 18:38:32 +03:00
|
|
|
}
|
|
|
|
else {
|
2018-10-18 01:56:12 +03:00
|
|
|
sed = _sist_come();
|
2018-10-10 09:04:46 +03:00
|
|
|
}
|
|
|
|
|
2018-08-10 19:58:21 +03:00
|
|
|
u3A->fak = c3n;
|
2018-10-18 01:56:12 +03:00
|
|
|
pig = _sist_dawn(u3k(sed));
|
2018-10-17 00:26:41 +03:00
|
|
|
who = u3k(u3h(u3h(u3t(pig))));
|
2018-10-10 09:04:46 +03:00
|
|
|
|
2018-10-18 01:56:12 +03:00
|
|
|
u3z(sed);
|
2018-09-15 08:39:13 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 00:26:41 +03:00
|
|
|
u3A->own = who;
|
2018-10-09 20:35:25 +03:00
|
|
|
|
2018-10-17 18:56:37 +03:00
|
|
|
// initialize ames
|
|
|
|
{
|
2018-10-29 21:58:07 +03:00
|
|
|
u3_noun tuf = (c3y == u3A->fak) ? u3_nul : u3h(u3t(u3t(u3t(u3t(pig)))));
|
2018-10-17 18:56:37 +03:00
|
|
|
// with a fake event to bring up listeners and configure domains
|
|
|
|
u3_ames_ef_turf(u3k(tuf));
|
|
|
|
// and real effect to set the output duct
|
|
|
|
u3_ames_ef_bake();
|
|
|
|
}
|
|
|
|
|
2018-11-26 10:52:53 +03:00
|
|
|
// initialize %behn
|
|
|
|
u3_behn_ef_bake();
|
|
|
|
|
2018-10-10 09:04:46 +03:00
|
|
|
// Authenticate and initialize terminal.
|
|
|
|
u3_term_ef_bake(pig);
|
2018-08-10 19:58:21 +03:00
|
|
|
|
2018-12-04 08:54:56 +03:00
|
|
|
// queue initial filesystem sync
|
|
|
|
//
|
|
|
|
// from the Arvo directory if specified
|
|
|
|
if ( 0 != u3_Host.ops_u.arv_c ) {
|
|
|
|
u3_unix_ef_initial_into();
|
|
|
|
}
|
|
|
|
// otherwise from the pill
|
|
|
|
else {
|
|
|
|
c3_c ful_c[2048];
|
2018-10-17 18:56:37 +03:00
|
|
|
|
2018-12-04 08:54:56 +03:00
|
|
|
snprintf(ful_c, 2048, "%s/.urb/urbit.pill", u3_Host.dir_c);
|
|
|
|
|
|
|
|
{
|
|
|
|
u3_noun sys = u3ke_cue(u3m_file(ful_c));
|
|
|
|
u3_noun fil;
|
2018-10-17 18:56:37 +03:00
|
|
|
|
2018-12-04 08:54:56 +03:00
|
|
|
u3x_trel(sys, 0, 0, &fil);
|
|
|
|
u3v_plow(u3k(fil));
|
|
|
|
|
|
|
|
u3z(sys);
|
|
|
|
}
|
2018-10-17 18:56:37 +03:00
|
|
|
}
|
|
|
|
|
2018-10-29 04:29:50 +03:00
|
|
|
// Create the event log
|
2018-10-10 09:04:46 +03:00
|
|
|
_sist_zest();
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
}
|