diff --git a/Makefile b/Makefile index a3a531327..8c670c4c9 100644 --- a/Makefile +++ b/Makefile @@ -357,6 +357,7 @@ V_OFILES=\ vere/unix.o \ vere/save.o \ vere/serf.o \ + vere/king.o \ vere/pier.o \ vere/foil.o \ vere/walk.o \ @@ -365,12 +366,21 @@ V_OFILES=\ MAIN_FILE =\ vere/main.o +BOOTER_FILE=\ + vere/booter.o + VERE_OFILES=\ $(OUT_OFILES) \ $(BASE_OFILES) \ $(MAIN_FILE) \ $(V_OFILES) +BOOTER_OFILES=\ + $(OUT_OFILES) \ + $(BASE_OFILES) \ + $(BOOTER_FILE) \ + $(V_OFILES) + VERE_DFILES=$(VERE_OFILES:%.o=.d/%.d) -include $(VERE_DFILES) @@ -391,7 +401,7 @@ TAGS=\ GPATH GTAGS GRTAGS \ cscope.in.out cscope.po.out cscope.out -all: urbit links +all: urbit links booter .MAKEFILE-VERSION: Makefile .make.conf @echo "Makefile update." @@ -404,6 +414,7 @@ links: urbit $(LN) $(BIN)/urbit $(BIN)/urbit-worker urbit: $(BIN)/urbit +booter: $(BIN)/booter $(LIBED25519): $(MAKE) -C outside/ed25519 @@ -433,6 +444,11 @@ $(BIN)/urbit: $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBED25519) $(LIBANACHRONISM) $( @$(CLD) $(CLDOSFLAGS) -o $(BIN)/urbit $(VERE_OFILES) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) $(LIBSOFTFLOAT) endif +$(BIN)/booter: $(LIBCOMMONMARK) $(BOOTER_OFILES) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) $(LIBSOFTFLOAT) + @echo " CCLD $(BIN)/booter" + @mkdir -p $(BIN) + @$(CLD) $(CLDOSFLAGS) -o $(BIN)/booter $(BOOTER_OFILES) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) $(LIBSOFTFLOAT) + tags: ctags etags gtags cscope ctags: diff --git a/include/c/motes.h b/include/c/motes.h index 446994766..c6cd7ad54 100644 --- a/include/c/motes.h +++ b/include/c/motes.h @@ -25,6 +25,7 @@ # define c3__ash c3_s3('a','s','h') # define c3__at c3_s2('a','t') # define c3__atom c3_s4('a','t','o','m') +# define c3__auth c3_s4('a','u','t','h') # define c3__axe c3_s3('a','x','e') # define c3__axil c3_s4('a','x','i','l') # define c3__axis c3_s4('a','x','i','s') @@ -312,6 +313,7 @@ # define c3__dojo c3_s4('d','o','j','o') # define c3__dome c3_s4('d','o','m','e') # define c3__done c3_s4('d','o','n','e') +# define c3__doom c3_s4('d','o','o','m') # define c3__door c3_s4('d','o','o','r') # define c3__dorn c3_s4('d','o','r','n') # define c3__dost c3_s4('d','o','s','t') @@ -800,6 +802,7 @@ # define c3__pesk c3_s4('p','e','s','k') # define c3__pfix c3_s4('p','f','i','x') # define c3__pick c3_s4('p','i','c','k') +# define c3__pier c3_s4('p','i','e','r') # define c3__pike c3_s4('p','i','k','e') # define c3__pile c3_s4('p','i','l','e') # define c3__pill c3_s4('p','i','l','l') @@ -1030,6 +1033,7 @@ # define c3__sub c3_s3('s','u','b') # define c3__sunt c3_s4('s','u','n','t') # define c3__sure c3_s4('s','u','r','e') +# define c3__susp c3_s4('s','u','s','p') # define c3__sym c3_s3('s','y','m') # define c3__sync c3_s4('s','y','n','c') # define c3__sys c3_s3('s','y','s') diff --git a/include/vere/vere.h b/include/vere/vere.h index 655cfa658..34181ff77 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -232,9 +232,9 @@ */ typedef struct _u3_moat { uv_pipe_t pyp_u; // input stream + u3_bail bal_f; // error response function void* vod_p; // callback pointer u3_poke pok_f; // action function - u3_bail bal_f; // error response function struct _u3_mess* mes_u; // message in progress c3_d len_d; // length of stray bytes c3_y* rag_y; // stray bytes @@ -247,6 +247,18 @@ u3_bail bal_f; // error response function } u3_mojo; + /* u3_moor: two-way message stream, linked list */ + typedef struct _u3_moor { + uv_pipe_t pyp_u; + u3_bail bal_f; + void* vod_p; + u3_poke pok_f; + struct _u3_mess* mes_u; + c3_d len_d; + c3_y* rag_y; + struct _u3_moor* nex_u; + } u3_moor; + /* u3_foil: abstract chub-addressed file. */ typedef struct _u3_foil { @@ -733,10 +745,10 @@ c3_w len_w; // number of lords used c3_w all_w; // number of lords allocated u3_pier** tab_u; // lord table + uv_pipe_t cmd_u; // command socket + u3_moor* cli_u; // connected clients } u3_king; - static u3_king u3K; - # define u3L u3_Host.lup_u // global event loop # define u3Z (&(u3_Raft)) # define u3S u3_Host.ssl_u @@ -1482,7 +1494,8 @@ */ void u3_pier_boot(c3_c* pax_c, // pier path - c3_c* sys_c); // path to boot pill + c3_c* sys_c, // path to boot pill + uv_prepare_t *pep_u); /* u3_pier_tank(): dump single tank. */ @@ -1498,3 +1511,6 @@ */ void u3_pier_sway(c3_l tab_l, u3_noun tax); + + void + u3_king_commence(); diff --git a/vere/booter.c b/vere/booter.c new file mode 100644 index 000000000..492addf72 --- /dev/null +++ b/vere/booter.c @@ -0,0 +1,63 @@ +#include +#include +#include "all.h" +#include "vere/vere.h" + +u3_moor moj_u; +uv_connect_t conn; + +c3_c *argv1; +c3_c *argv2; + +void _nop_bail(void *vod_p, const c3_c *err) +{ + fprintf(stderr, "_nop_bail: %s\r\n", err); + exit(1); +} + +void _nop_noun(void *vod_p, u3_noun mat) +{ +} + +void _nop_conn(uv_connect_t *conn, int status) +{ + u3_atom doom; + u3_atom pax, sys; + + pax = u3i_string(argv1); + sys = u3i_string(argv2); + + doom = u3ke_jam(u3nt(c3__doom, + u3_nul, + u3nc(c3__boot, + u3nq(0, pax, sys, 0)))); + u3_newt_write(&moj_u, doom, 0); +} + +c3_i main(c3_i argc, c3_c **argv) +{ + argv1 = argv[1]; + argv2 = argv[2]; + u3_Host.ops_u.dem = c3n; + u3_Host.lup_u = uv_default_loop(); + + moj_u.pok_f = _nop_noun; + moj_u.bal_f = _nop_bail; + uv_pipe_init(u3_Host.lup_u, &moj_u.pyp_u, 0); + uv_pipe_connect(&conn, &moj_u.pyp_u, "/tmp/urbit.sock", _nop_conn); + + u3m_boot_pier(); + { + extern c3_w u3_Ivory_length_w; + extern c3_y u3_Ivory_pill_y[]; + u3_noun lit; + + lit = u3i_bytes(u3_Ivory_length_w, u3_Ivory_pill_y); + u3v_boot_lite(lit); + } + + u3_newt_read(&moj_u); + + uv_run(u3L, UV_RUN_DEFAULT); + return 0; +} diff --git a/vere/king.c b/vere/king.c new file mode 100644 index 000000000..f85e0d657 --- /dev/null +++ b/vere/king.c @@ -0,0 +1,231 @@ +#include +#include "all.h" +#include "vere/vere.h" + +/* +++ fate :: client to lord + $% $: $wyrd :: send a card + p/ship :: target ship + q/ovum :: action + == :: + $: $doom :: control the daemon + p/(unit ship) :: who to command + q/doom :: the command + == :: + == :: +:: :: +++ cede :: lord to client + $@ $? $firm :: accept command + $deny :: reject command + == :: + $% $: $cede :: send cards + p/ship :: sending ship + q/(list ovum) :: actions + == :: + == :: +:: :: +++ doom :: daemon command + $@ $? $susp :: release a pier + $exit :: end the daemon + == :: + $% $: $auth :: auth this client + p/@ :: auth secret + == :: + $: $boot :: boot new pier + p/@ :: generator or ticket + q/(unit @t) :: unix path to arvo + r/(unit @t) :: unix path to pill + s/(map @t *) :: debug options + == :: + $: $pier :: acquire a pier + p/(unit @t) :: unix path + == :: + == :: +*/ + +void _king_defy_fate() +{ + exit(1); +} + +void _king_wyrd(u3_noun wyrd) +{ +} + +void _king_boot(u3_noun boot) +{ + u3_noun pax_n, sys_n; + c3_c *pax_c, *sys_c; + + pax_n = u3k(u3h(u3t(boot))); + sys_n = u3k(u3h(u3t(u3t(boot)))); + u3z(boot); + + pax_c = u3r_string(pax_n); + u3z(pax_n); + sys_c = u3r_string(sys_n); + u3z(sys_n); + + fprintf(stderr, "boot %s %s\r\n", pax_c, sys_c); +} + +void _king_doom(u3_noun doom) +{ + u3_noun load; + if ( c3y == u3ud(doom) ) { + c3_assert(_(u3a_is_cat(doom))); + switch ( doom ) { + case c3__susp: + break; + case c3__exit: + break; + default: + _king_defy_fate(); + } + } else { + switch ( u3h(doom) ) { + case c3__auth: + break; + case c3__boot: + load = u3k(u3t(doom)); + u3z(doom); + _king_boot(load); + break; + case c3__pier: + break; + default: + _king_defy_fate(); + } + } +} + +void _king_fate(void *vod_p, u3_noun mat) +{ + u3_noun fate = u3ke_cue(u3k(mat)); + u3_noun load; + c3_assert(_(u3a_is_cat(u3h(fate)))); + c3_assert(_(u3a_is_cell(u3t(fate)))); + switch ( u3h(fate) ) { + case c3__wyrd: + load = u3k(u3t(u3t(fate))); + u3z(fate); + _king_wyrd(load); + break; + case c3__doom: + load = u3k(u3t(u3t(fate))); + u3z(fate); + _king_doom(load); + break; + default: + _king_defy_fate(); + } +} + +void _king_bail(u3_moor *vod_p, const c3_c *err_c) +{ + u3_moor *free_p; + fprintf(stderr, "_king_bail: %s\r\n", err_c); + if ( vod_p == 0 ) { + free_p = u3K.cli_u; + u3K.cli_u = u3K.cli_u->nex_u; + u3a_free(free_p); + } else { + free_p = vod_p->nex_u; + vod_p->nex_u = vod_p->nex_u->nex_u; + u3a_free(free_p); + } +} + +void _king_socket_connect(uv_stream_t *sock, int status) +{ + u3_moor *mor_u; + if ( u3K.cli_u == 0 ) { + u3K.cli_u = u3a_malloc(sizeof(u3_moor)); + mor_u = u3K.cli_u; + mor_u->vod_p = 0; + mor_u->nex_u = 0; + } else { + for (mor_u = u3K.cli_u; mor_u->nex_u; mor_u = mor_u->nex_u); + mor_u->nex_u = u3a_malloc(sizeof(u3_moor)); + mor_u->nex_u->vod_p = mor_u; + mor_u = mor_u->nex_u; + mor_u->nex_u = 0; + } + + uv_pipe_init(u3L, &mor_u->pyp_u, 0); + mor_u->pok_f = _king_fate; + mor_u->bal_f = (u3_bail)_king_bail; + + uv_accept(sock, (uv_stream_t *)&mor_u->pyp_u); + u3_newt_read((u3_moat *)mor_u); +} + +void _king_loop_init() +{ +} + +void _king_loop_exit() +{ + c3_l cod_l; + + cod_l = u3a_lush(c3__unix); + u3_unix_io_exit(); + u3a_lop(cod_l); + + cod_l = u3a_lush(c3__ames); + u3_ames_io_exit(u3_pier_stub()); + u3a_lop(cod_l); + + cod_l = u3a_lush(c3__term); + u3_term_io_exit(); + u3a_lop(cod_l); + + cod_l = u3a_lush(c3__http); + u3_http_io_exit(); + u3a_lop(cod_l); + + cod_l = u3a_lush(c3__cttp); + u3_cttp_io_exit(); + u3a_lop(cod_l); + + cod_l = u3a_lush(c3__save); + u3_save_io_exit(); + u3a_lop(cod_l); + + cod_l = u3a_lush(c3__behn); + u3_behn_io_exit(); + u3a_lop(cod_l); +} + +void u3_king_commence() +{ + u3_Host.lup_u = uv_default_loop(); + + /* start up a "fast-compile" arvo for internal use only + */ + u3m_boot_pier(); + { + extern c3_w u3_Ivory_length_w; + extern c3_y u3_Ivory_pill_y[]; + u3_noun lit; + + lit = u3i_bytes(u3_Ivory_length_w, u3_Ivory_pill_y); + u3v_boot_lite(lit); + } + + /* listen on command socket */ + uv_pipe_init(u3L, &u3K.cmd_u, 0); + uv_pipe_bind(&u3K.cmd_u, "/tmp/urbit.sock"); + uv_listen((uv_stream_t *)&u3K.cmd_u, 128, _king_socket_connect); + fprintf(stderr, "cmd socket up\r\n"); + + _king_loop_init(); + + uv_prepare_t *pep_u = u3a_malloc(sizeof(uv_prepare_t)); /* put in u3_pier? */ + u3_pier_boot(u3_Host.dir_c, u3_Host.ops_u.pil_c, pep_u); + + uv_run(u3L, UV_RUN_DEFAULT); + + _king_loop_exit(); + exit(0); +} diff --git a/vere/main.c b/vere/main.c index c39affce3..c9a4ec8d5 100644 --- a/vere/main.c +++ b/vere/main.c @@ -545,7 +545,7 @@ main(c3_i argc, } } - u3_pier_boot(u3_Host.dir_c, u3_Host.ops_u.pil_c); + u3_king_commence(); } return 0; } diff --git a/vere/pier.c b/vere/pier.c index b0e0ae9f7..deeb0a758 100644 --- a/vere/pier.c +++ b/vere/pier.c @@ -1818,41 +1818,21 @@ _pier_boot_make(c3_c* pax_c, */ void u3_pier_boot(c3_c* pax_c, // pier path - c3_c* sys_c) // path to boot pill + c3_c* sys_c, // path to boot pill + uv_prepare_t *pep_u) { - uv_prepare_t pep_u; - - u3_Host.lup_u = uv_default_loop(); - - /* start up a "fast-compile" arvo for internal use only - */ - u3m_boot_pier(); - { - extern c3_w u3_Ivory_length_w; - extern c3_y u3_Ivory_pill_y[]; - u3_noun lit; - - lit = u3i_bytes(u3_Ivory_length_w, u3_Ivory_pill_y); - u3v_boot_lite(lit); - } - /* make initial pier */ _pier_boot_make(pax_c, sys_c); /* initialize polling handle */ - uv_prepare_init(u3_Host.lup_u, &pep_u); - uv_prepare_start(&pep_u, _pier_loop_prepare); + uv_prepare_init(u3_Host.lup_u, pep_u); + uv_prepare_start(pep_u, _pier_loop_prepare); /* initialize loop - move to _pier_boot_make(). */ _pier_loop_init(); - /* enter loop - */ - uv_run(u3L, UV_RUN_DEFAULT); - - _pier_loop_exit(); - exit(0); + /* remember to deal with _pier_loop_exit stuff */ }