diff --git a/include/c/motes.h b/include/c/motes.h index 7914354ca1..8cb2dbbc7d 100644 --- a/include/c/motes.h +++ b/include/c/motes.h @@ -1141,6 +1141,7 @@ # define c3__tung c3_s4('t','u','n','g') # define c3__tupl c3_s4('t','u','p','l') # define c3__turd c3_s4('t','u','r','d') +# define c3__turf c3_s4('t','u','r','f') # define c3__turn c3_s4('t','u','r','n') # define c3__twig c3_s4('t','w','i','g') # define c3__twix c3_s4('t','w','i','x') diff --git a/include/vere/vere.h b/include/vere/vere.h index ced7474fdd..2183d483e3 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -254,9 +254,11 @@ uv_handle_t had_u; }; uv_timer_t tim_u; // network timer + c3_o liv; // listener on c3_o alm; // alarm on c3_w law_w; // last wakeup, unix time c3_s por_s; // public IPv4 port + c3_c* dns_c; // domain XX multiple/fallback c3_w imp_w[256]; // imperial IPs time_t imp_t[256]; // imperial IP timestamps } u3_ames; @@ -578,7 +580,6 @@ */ typedef struct _u3_opts { c3_c* arv_c; // -A, initial sync from - c3_c* dns_c; // -H, ames bootstrap domain c3_c* gen_c; // -G, czar generator c3_c* imp_c; // -I, czar name c3_c* nam_c; // -n, unix hostname @@ -938,6 +939,11 @@ u3_ames_ef_send(u3_noun lan, u3_noun pac); + /* u3_ames_ef_turf(): initialize ames I/O on domain(s). + */ + void + u3_ames_ef_turf(u3_noun tuf); + /* u3_ames_io_init(): initialize ames I/O. */ void diff --git a/vere/ames.c b/vere/ames.c index 3a9fc0f166..b04d64ecda 100644 --- a/vere/ames.c +++ b/vere/ames.c @@ -197,6 +197,8 @@ _ames_czar(u3_pact* pac_u, c3_c* bos_c) return; } + c3_assert( 0 != bos_c ); + time_t now = time(0); // backoff @@ -269,6 +271,8 @@ _ames_lane_ip(u3_noun lan, c3_s* por_s, c3_w* pip_w) return c3n; } +/* u3_ames_ef_bake(): notify %ames that we're live. +*/ void u3_ames_ef_bake(void) { @@ -303,7 +307,7 @@ u3_ames_ef_send(u3_noun lan, u3_noun pac) if ( (0 == (pac_u->pip_w >> 16)) && (1 == (pac_u->pip_w >> 8)) ) { pac_u->imp_y = (pac_u->pip_w & 0xff); - _ames_czar(pac_u, u3_Host.ops_u.dns_c); + _ames_czar(pac_u, u3_Host.sam_u.dns_c); } else if ( (c3y == u3_Host.ops_u.net) || (0x7f000001 == pac_u->pip_w) ) { _ames_send(pac_u); @@ -326,15 +330,22 @@ static void _ames_time_cb(uv_timer_t* tim_uo) { u3_ames* sam_u = &u3_Host.sam_u; - u3_lo_open(); - sam_u->law_w = time(0); - { - u3v_plan - (u3nt(u3_blip, c3__ames, u3_nul), - u3nc(c3__wake, u3_nul)); + // defer until started via u3_ames_ef_turf() + if ( c3n == sam_u->liv ) { + uv_timer_start(&sam_u->tim_u, _ames_time_cb, 1000, 0); + } + else { + u3_lo_open(); + + sam_u->law_w = time(0); + { + u3v_plan + (u3nt(u3_blip, c3__ames, u3_nul), + u3nc(c3__wake, u3_nul)); + } + u3_lo_shut(c3n); } - u3_lo_shut(c3n); } /* _ames_recv_cb(): receive callback. @@ -376,15 +387,15 @@ _ames_recv_cb(uv_udp_t* wax_u, } } -/* u3_ames_io_init(): initialize ames I/O. +/* _ames_io_start(): initialize ames I/O. */ -void -u3_ames_io_init() +static void +_ames_io_start() { u3_ames* sam_u = &u3_Host.sam_u; - c3_s por_s; + c3_s por_s = u3_Host.ops_u.por_s; - por_s = u3_Host.ops_u.por_s; + // XX use clan:title u3A->own if ( 0 != u3_Host.ops_u.imp_c ) { u3_noun imp = u3i_string(u3_Host.ops_u.imp_c); u3_noun num = u3dc("slaw", 'p', imp); @@ -442,10 +453,103 @@ u3_ames_io_init() sam_u->por_s = ntohs(add_u.sin_port); } - // Timer too. - { - uv_timer_init(u3L, &sam_u->tim_u); + + // uL(fprintf(uH, "ames: on localhost, UDP %d.\n", sam_u->por_s)); + uv_udp_recv_start(&sam_u->wax_u, _ames_alloc, _ames_recv_cb); + + sam_u->liv = c3y; +} + +/* _cttp_mcut_char(): measure/cut character. +*/ +static c3_w +_cttp_mcut_char(c3_c* buf_c, c3_w len_w, c3_c chr_c) +{ + if ( buf_c ) { + buf_c[len_w] = chr_c; } + return len_w + 1; +} + +/* _cttp_mcut_cord(): measure/cut cord. +*/ +static c3_w +_cttp_mcut_cord(c3_c* buf_c, c3_w len_w, u3_noun san) +{ + c3_w ten_w = u3r_met(3, san); + + if ( buf_c ) { + u3r_bytes(0, ten_w, (c3_y *)(buf_c + len_w), san); + } + u3z(san); + return (len_w + ten_w); +} + +/* _cttp_mcut_path(): measure/cut cord list. +*/ +static c3_w +_cttp_mcut_path(c3_c* buf_c, c3_w len_w, c3_c sep_c, u3_noun pax) +{ + u3_noun axp = pax; + + while ( u3_nul != axp ) { + u3_noun h_axp = u3h(axp); + + len_w = _cttp_mcut_cord(buf_c, len_w, u3k(h_axp)); + axp = u3t(axp); + + if ( u3_nul != axp ) { + len_w = _cttp_mcut_char(buf_c, len_w, sep_c); + } + } + u3z(pax); + return len_w; +} + +/* _cttp_mcut_host(): measure/cut host. +*/ +static c3_w +_cttp_mcut_host(c3_c* buf_c, c3_w len_w, u3_noun hot) +{ + len_w = _cttp_mcut_path(buf_c, len_w, '.', u3kb_flop(u3k(hot))); + u3z(hot); + return len_w; +} + +/* u3_ames_ef_turf(): initialize ames I/O on domain(s). +*/ +void +u3_ames_ef_turf(u3_noun tuf) +{ + if ( u3_nul != tuf ) { + // XX save all for fallback, not just first + u3_noun hot = u3k(u3h(tuf)); + c3_w len_w = _cttp_mcut_host(0, 0, u3k(hot)); + + u3_Host.sam_u.dns_c = c3_malloc(1 + len_w); + _cttp_mcut_host(u3_Host.sam_u.dns_c, 0, hot); + u3_Host.sam_u.dns_c[len_w] = 0; + + u3z(tuf); + } + else if ( c3n == u3A->fak ) { + // XX assert? + uL(fprintf(uH, "ames: turf: no domains\n")); + } + + if ( c3n == u3_Host.sam_u.liv ) { + _ames_io_start(); + } +} + +/* u3_ames_io_init(): initialize ames I/O. +*/ +void +u3_ames_io_init() +{ + u3_ames* sam_u = &u3_Host.sam_u; + sam_u->liv = c3n; + uv_timer_init(u3L, &sam_u->tim_u); } /* u3_ames_io_talk(): start receiving ames traffic. @@ -453,10 +557,6 @@ u3_ames_io_init() void u3_ames_io_talk() { - u3_ames* sam_u = &u3_Host.sam_u; - - uL(fprintf(uH, "ames: on localhost, UDP %d.\n", sam_u->por_s)); - uv_udp_recv_start(&sam_u->wax_u, _ames_alloc, _ames_recv_cb); } /* u3_ames_io_exit(): terminate ames I/O. @@ -466,8 +566,12 @@ u3_ames_io_exit() { u3_ames* sam_u = &u3_Host.sam_u; - // XX close wax_u instead - uv_close(&sam_u->had_u, 0); + uv_close((uv_handle_t*)&sam_u->tim_u, 0); + + if ( c3y == sam_u->liv ) { + // XX remove had_u/wax_u union, cast and close wax_u + uv_close(&sam_u->had_u, 0); + } } /* u3_ames_io_poll(): update ames IO state. diff --git a/vere/http.c b/vere/http.c index ea2b006da1..14d5fd4afe 100644 --- a/vere/http.c +++ b/vere/http.c @@ -1231,6 +1231,7 @@ _http_release_ports_file(c3_c *pax_c) free(paf_c); } + /* _http_czar_host(): galaxy hostname as (unit host:eyre) */ static u3_noun @@ -1238,6 +1239,8 @@ _http_czar_host(void) { u3_noun dom = u3_nul; + // XX revisit +#if 0 if ( (0 == u3_Host.ops_u.imp_c) || (c3n == u3_Host.ops_u.net) ) { return dom; } @@ -1272,6 +1275,7 @@ _http_czar_host(void) } } } +#endif if ( u3_nul == dom ) { return dom; @@ -2424,12 +2428,15 @@ _proxy_ward_resolve(u3_warc* cli_u) hin_u.ai_protocol = IPPROTO_TCP; if ( 0 == cli_u->hot_c ) { + // XX revisit + c3_assert( 0 != u3_Host.sam_u.dns_c ); + u3_noun sip = u3dc("scot", 'p', u3k(cli_u->sip)); c3_c* sip_c = u3r_string(sip); - c3_w len_w = 1 + strlen(sip_c) + strlen(u3_Host.ops_u.dns_c); + c3_w len_w = 1 + strlen(sip_c) + strlen(u3_Host.sam_u.dns_c); cli_u->hot_c = c3_malloc(len_w); // incremented to skip '~' - snprintf(cli_u->hot_c, len_w, "%s.%s", sip_c + 1, u3_Host.ops_u.dns_c); + snprintf(cli_u->hot_c, len_w, "%s.%s", sip_c + 1, u3_Host.sam_u.dns_c); free(sip_c); u3z(sip); @@ -2541,11 +2548,14 @@ _proxy_parse_ship(c3_c* hot_c) return sip; } + // XX revisit + c3_assert( 0 != u3_Host.sam_u.dns_c ); + c3_w dif_w = dom_c - hot_c; - c3_w dns_w = strlen(u3_Host.ops_u.dns_c); + c3_w dns_w = strlen(u3_Host.sam_u.dns_c); if ( (dns_w != strlen(hot_c) - (dif_w + 1)) || - (0 != strncmp(dom_c + 1, u3_Host.ops_u.dns_c, dns_w)) ) { + (0 != strncmp(dom_c + 1, u3_Host.sam_u.dns_c, dns_w)) ) { return sip; } diff --git a/vere/loop.c b/vere/loop.c index d3362efb31..cac36d6ffc 100644 --- a/vere/loop.c +++ b/vere/loop.c @@ -667,7 +667,12 @@ u3_lo_lead(void) // Further server configuration. // { + u3_ames_ef_bake(); u3_http_ef_bake(); + + if ( (c3y == u3_Host.ops_u.nuu) && (0 != u3_Host.ops_u.imp_c) ) { + u3_unix_ef_initial_into(); + } } _lo_talk(); diff --git a/vere/main.c b/vere/main.c index eced433643..0f60f735b1 100644 --- a/vere/main.c +++ b/vere/main.c @@ -91,7 +91,7 @@ _main_getopt(c3_i argc, c3_c** argv) u3_Host.ops_u.veb = c3n; u3_Host.ops_u.kno_w = DefaultKernel; - while ( (ch_i=getopt(argc, argv,"G:B:K:A:H:I:w:u:f:F:k:l:n:p:r:NabcdgqsvxMPDXRS")) != -1 ) { + while ( (ch_i=getopt(argc, argv,"G:B:K:A:I:w:u:f:F:k:l:n:p:r:NabcdgqsvxMPDXRS")) != -1 ) { switch ( ch_i ) { case 'M': { u3_Host.ops_u.mem = c3y; @@ -109,10 +109,6 @@ _main_getopt(c3_i argc, c3_c** argv) u3_Host.ops_u.arv_c = strdup(optarg); break; } - case 'H': { - u3_Host.ops_u.dns_c = strdup(optarg); - break; - } // XX remove in deference to -K case 'I': { u3_Host.ops_u.imp_c = _main_presig(optarg); @@ -282,10 +278,6 @@ _main_getopt(c3_i argc, c3_c** argv) return c3n; } - if ( u3_Host.ops_u.dns_c == 0 ) { - u3_Host.ops_u.dns_c = "urbit.org"; - } - if ( u3_Host.ops_u.pil_c != 0 ) { struct stat s; if ( stat(u3_Host.ops_u.pil_c, &s) != 0 ) { @@ -358,7 +350,6 @@ u3_ve_usage(c3_i argc, c3_c** argv) "-F ship Fake keys; also disables networking\n", "-f Fuzz testing\n", "-g Set GC flag\n", - "-H domain Set ames bootstrap domain (default urbit.org)\n", "-I galaxy Start as ~galaxy\n", "-k stage Start at Hoon kernel version stage\n", "-l port Initial peer port\n", diff --git a/vere/reck.c b/vere/reck.c index 3a44f29703..3515c32686 100644 --- a/vere/reck.c +++ b/vere/reck.c @@ -208,6 +208,11 @@ _reck_kick_newt(u3_noun pox, u3_noun fav) u3_ames_ef_send(lan, pac); u3z(pox); u3z(fav); return c3y; } break; + + case c3__turf: { + u3_ames_ef_turf(u3k(u3t(fav))); + u3z(pox); u3z(fav); return c3y; + } break; } u3z(pox); u3z(fav); return c3n; } diff --git a/vere/sist.c b/vere/sist.c index 0e1a09c3b0..9986b45a26 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -277,21 +277,6 @@ _sist_sing(u3_noun ovo) } } - -/* _sist_home(): remains of "create ship directory" after refactor to u3m_boot(). -*/ -static void -_sist_home() -{ -#if 1 - // Copy zod files, if we're generating a carrier. - // - if ( u3_Host.ops_u.imp_c ) { - u3_unix_ef_initial_into(); - } -#endif -} - /* _sist_cask(): ask for a passcode. */ static u3_noun @@ -518,10 +503,6 @@ _sist_zest() c3_c ful_c[8193]; c3_l sal_l; - // Create the ship directory. - // - _sist_home(); - // Create the record file. { c3_i pig_i = O_CREAT | O_WRONLY | O_EXCL; @@ -602,9 +583,6 @@ _sist_zest() static void _sist_make(u3_noun fav) { - // Initialize ames - u3_ames_ef_bake(); - // Authenticate and initialize terminal. // u3_term_ef_bake(fav);