1 /* include/v/vere.h
2 **
3 ** This file is in the public domain.
4 */
5 
6 #include "h2o.h"
7 
8   /** Quasi-tunable parameters.
9   **/
10     /* First kernel this executable can boot.
11     */
12 #     define FirstKernel   164
13 #     define DefaultKernel 164
14 
15 #define RECK
16 
17   /** Data types.
18   **/
19     struct _u3_http;
20 
21     /* u3_hhed: http header.
22     */
23       typedef struct _u3_hhed {
24         struct _u3_hhed* nex_u;
25         c3_w             nam_w;
26         c3_c*            nam_c;
27         c3_w             val_w;
28         c3_c*            val_c;
29       } u3_hhed;
30 
31     /* u3_hbod: http body block.  Also used for responses.
32     */
33       typedef struct _u3_hbod {
34         struct _u3_hbod* nex_u;
35         c3_w             len_w;
36         c3_y             hun_y[0];
37       } u3_hbod;
38 
39     /* u3_rsat: http request state.
40     */
41       typedef enum {
42         u3_rsat_init = 0,                   //  initialized
43         u3_rsat_plan = 1,                   //  planned
44         u3_rsat_ripe = 2                    //  responded
45       } u3_rsat;
46 
47     /* u3_hreq: incoming http request.
48     */
49       typedef struct _u3_hreq {
50         h2o_req_t*       rec_u;             //  h2o request
51         c3_w             seq_l;             //  sequence within connection
52         u3_rsat          sat_e;             //  request state
53         struct _u3_hcon* hon_u;             //  connection backlink
54         struct _u3_hreq* nex_u;             //  next in connection's list
55       } u3_hreq;
56 
57     /* u3_hcon: incoming http connection.
58     */
59       typedef struct _u3_hcon {
60         uv_tcp_t         wax_u;             //  client stream handler
61         h2o_conn_t*      con_u;             //  h2o connection
62         h2o_socket_t*    sok_u;             //  h2o connection socket
63         c3_w             ipf_w;             //  client ipv4
64         c3_w             coq_l;             //  connection number
65         c3_w             seq_l;             //  next request number
66         struct _u3_http* htp_u;             //  server backlink
67         struct _u3_hreq* req_u;             //  request list
68         struct _u3_hcon* nex_u;             //  next in server's list
69       } u3_hcon;
70 
71     /* u3_http: http server.
72     */
73       typedef struct _u3_http {
74         uv_tcp_t         wax_u;             //  server stream handler
75         h2o_globalconf_t* fig_u;            //  h2o global config
76         h2o_context_t*   ctx_u;             //  h2o ctx
77         h2o_accept_ctx_t* cep_u;            //  h2o accept ctx (wat for?)
78         h2o_hostconf_t*  hos_u;             //  h2o host config
79         h2o_handler_t*   han_u;             //  h2o request handler
80         c3_w             sev_l;             //  server number
81         c3_w             coq_l;             //  next connection number
82         c3_w             por_w;             //  running port
83         c3_o             sec;               //  logically secure
84         c3_o             lop;               //  loopback-only
85         struct _u3_hcon* hon_u;             //  connection list
86         struct _u3_http* nex_u;             //  next in list
87       } u3_http;
88 
89     /* u3_csat: client connection state.
90     */
91       typedef enum {
92         u3_csat_init = 0,                   //  initialized
93         u3_csat_addr = 1,                   //  address resolution begun
94         u3_csat_quit = 2,                   //  cancellation requested
95         u3_csat_ripe = 3                    //  passed to libh2o
96       } u3_csat;
97 
98     /* u3_cres: response to http client.
99     */
100       typedef struct _u3_cres {
101         c3_w             sas_w;             //  status code
102         u3_noun          hed;               //  headers
103         u3_hbod*         bod_u;             //  exit of body queue
104         u3_hbod*         dob_u;             //  entry of body queue
105       } u3_cres;
106 
107     /* u3_creq: outgoing http request.
108     */
109       typedef struct _u3_creq {             //  client request
110         c3_l             num_l;             //  request number
111         h2o_http1client_t* cli_u;           //  h2o client
112         u3_csat          sat_e;             //  connection state
113         c3_o             sec;               //  yes == https
114         c3_w             ipf_w;             //  IP
115         c3_c*            ipf_c;             //  IP (string)
116         c3_c*            hot_c;             //  host
117         c3_s             por_s;             //  port
118         c3_c*            por_c;             //  port (string)
119         c3_m             met_m;             //  method
120         c3_c*            url_c;             //  url
121         u3_hhed*         hed_u;             //  headers
122         u3_hbod*         bod_u;             //  body
123         u3_hbod*         rub_u;             //  exit of send queue
124         u3_hbod*         bur_u;             //  entry of send queue
125         h2o_iovec_t*     vec_u;             //  send-buffer array
126         u3_cres*         res_u;             //  nascent response
127         struct _u3_creq* nex_u;             //  next in list
128         struct _u3_creq* pre_u;             //  previous in list
129       } u3_creq;
130 
131     /* u3_chot: foreign host (not yet used).
132     */
133       typedef struct _u3_chot {
134         c3_w             ipf_w;             //  ip address (or 0)
135         c3_c*            hot_c;             //  hostname (no port) (or 0)
136         void*            ins_u;             //  insecure connection (or 0)
137         void*            sec_u;             //  secure connection (or 0)
138       } u3_chot;
139 
140     /* u3_cttp: http client.
141     */
142       typedef struct _u3_cttp {
143         u3_creq*         ceq_u;             //  request list
144         h2o_http1client_ctx_t*              //
145                          ctx_u;             //  h2o client ctx
146         void*            tls_u;             //  client SSL_CTX*
147       } u3_cttp;
148 
149     /* u3_apac: ames packet, coming or going.
150     */
151       typedef struct _u3_apac {
152         struct _u3_apac* nex_u;             //  next in queue
153         c3_w             pip_w;             //  IPv4 address, to
154         c3_s             por_s;             //  IPv4 port, to
155         c3_w             len_w;             //  length in bytes
156         c3_y             hun_y[0];          //  data
157       } u3_apac;
158 
159     /* u3_ames: ames networking.
160     */
161       typedef struct _u3_ames {             //  packet network state
162         union {
163           uv_udp_t    wax_u;
164           uv_handle_t had_u;
165         };
166         uv_timer_t    tim_u;                //  network timer
167         c3_o          alm;                  //  alarm on
168         c3_w          law_w;                //  last wakeup, unix time
169         c3_s          por_s;                //  public IPv4 port
170         c3_w          imp_w[256];           //  imperial IPs
171         time_t        imp_t[256];           //  imperial IP timestamps
172       } u3_ames;
173 
174     /* u3_save: checkpoint control.
175     */
176       typedef struct _u3_save {
177         uv_timer_t  tim_u;                  //  checkpoint timer
178         uv_signal_t sil_u;                  //  child signal
179         c3_d        ent_d;                  //  event number
180         c3_w        pid_w;                  //  pid of checkpoint process
181       } u3_save;
182 
183     /* u3_ubuf: unix tty i/o buffer.
184     */
185       typedef struct _u3_ubuf {
186         struct _u3_ubuf* nex_u;
187         c3_w             len_w;
188         c3_y             hun_y[0];          //  bytes to send
189       } u3_ubuf;
190 
191     /* u3_utat: unix terminal state.
192     */
193       typedef struct {
194         struct {
195           c3_l  col_l;                      //  columns
196           c3_l  row_l;                      //  rows
197         } siz;
198 
199         struct {
200           c3_w* lin_w;                      //  current line (utf32)
201           c3_w  len_w;                      //  length of current line
202           c3_w  cus_w;                      //  cursor position
203         } mir;
204 
205         struct {                            //  escape code control
206           c3_o    ape;                      //  escape received
207           c3_o    bra;                      //  bracket or O received
208         } esc;
209 
210         struct {
211           c3_y syb_y[5];                    //  utf8 code buffer
212           c3_w len_w;                       //  present length
213           c3_w wid_w;                       //  total width
214         } fut;
215 
216         struct {
217           uv_thread_t* sit_u;               //  spinner thread
218           c3_o         diz_o;               //  spinner activated
219           c3_d         eve_d;               //  spinner start tick (unix μs)
220           c3_d         end_d;               //  spinner end tick (unix μs)
221           c3_c*        why_c;               //  spinner event wire (root only)
222         } sun;
223 
224         uv_mutex_t     mex_u;               //  mutex for non-daemon term state
225       } u3_utat;
226 
227     /* u3_uled: event log header.
228     */
229       typedef struct {
230         c3_l mag_l;                         //  mug of log format, 'a', 'b'...
231         c3_w kno_w;                         //  kernel number validated with
232         c3_l sal_l;                         //  salt for passcode
233         c3_l key_l;                         //  mug of crypto key, or 0
234         c3_l sev_l;                         //  host process identity
235         c3_l tno_l;                         //  terminal count in host
236       } u3_uled;
237 
238     /* u3_olar: event log trailer, old version.
239     */
240       typedef struct {
241         c3_w syn_w;                         //  must equal mug of address
242         c3_w ent_w;                         //  event sequence number
243         c3_w len_w;                         //  word length of this event
244         c3_w mug_w;                         //  mug of entry
245       } u3_olar;
246 
247     /* u3_ular: event log trailer.
248     */
249       typedef struct {
250         c3_w syn_w;                         //  must equal mug of address
251         c3_d ent_d;                         //  event sequence number
252         c3_w len_w;                         //  word length of this event
253         c3_w mug_w;                         //  mug of entry
254         c3_w tem_w;                         //  raft term of event
255         c3_w typ_w;                         //  type of event, %ra|%ov
256       } u3_ular;
257 
258     /* u3_ulog: unix event log.
259     */
260       typedef struct {
261         c3_i fid_i;                         //  file descriptor
262         c3_d len_d;                         //  length in words
263       } u3_ulog;
264 
265       struct _u3_umon;
266       struct _u3_udir;
267       struct _u3_ufil;
268 
269     /* u3_unod: file or directory.
270     */
271       typedef struct _u3_unod {
272         uv_fs_event_t     was_u;            //  stat watcher
273         c3_o              dir;              //  c3y if dir, c3n if file
274         c3_o              dry;              //  ie, unmodified
275         c3_c*             pax_c;            //  absolute path
276         struct _u3_udir*  par_u;            //  parent
277         struct _u3_unod*  nex_u;            //  internal list
278       } u3_unod;
279 
280     /* u3_ufil: synchronized file.
281     */
282       typedef struct _u3_ufil {
283         uv_fs_event_t     was_u;            //  stat watcher
284         c3_o              dir;              //  c3y if dir, c3n if file
285         c3_o              dry;              //  ie, unmodified
286         c3_c*             pax_c;            //  absolute path
287         struct _u3_udir*  par_u;            //  parent
288         struct _u3_unod*  nex_u;            //  internal list
289         c3_w              mug_w;            //  mug of last %into
290         c3_w              gum_w;            //  mug of last %ergo
291       } u3_ufil;
292 
293     /* u3_ufil: synchronized directory.
294     */
295       typedef struct _u3_udir {
296         uv_fs_event_t     was_u;            //  stat watcher
297         c3_o              dir;              //  c3y if dir, c3n if file
298         c3_o              dry;              //  ie, unmodified
299         c3_c*             pax_c;            //  absolute path
300         struct _u3_udir*  par_u;            //  parent
301         struct _u3_unod*  nex_u;            //  internal list
302         u3_unod*          kid_u;            //  subnodes
303       } u3_udir;
304 
305     /* u3_ufil: synchronized mount point.
306     */
307       typedef struct _u3_umon {
308         u3_udir          dir_u;             //  root directory, must be first
309         c3_c*            nam_c;             //  mount point name
310         struct _u3_umon* nex_u;             //  internal list
311       } u3_umon;
312 
313     /* u3_usig: receive signals.
314     */
315       typedef struct _u3_usig {
316         uv_signal_t      sil_u;
317         c3_i             num_i;
318         struct _u3_usig* nex_u;
319       } u3_usig;
320 
321     /* u3_unix: clay support system, also
322     */
323       typedef struct _u3_unix {
324         uv_check_t  syn_u;                  //  fs sync check
325         uv_timer_t  tim_u;                  //  timer
326         u3_umon*    mon_u;                  //  mount points
327         u3_usig*    sig_u;                  //  signal list
328         c3_o        alm;                    //  timer set
329         c3_o        dyr;                    //  ready to update
330 #ifdef SYNCLOG
331         c3_w         lot_w;                 //  sync-slot
332         struct _u3_sylo {
333           c3_o     unx;                     //  from unix
334           c3_m     wer_m;                   //  mote saying where
335           c3_m     wot_m;                   //  mote saying what
336           c3_c*    pax_c;                   //  path
337         } sylo[1024];
338 #endif
339       } u3_unix;
340 
341     /* u3_behn: just a timer for ever
342     */
343       typedef struct _u3_behn {
344         uv_timer_t tim_u;                   //  behn timer
345         c3_w       run_w;                   //  run of consecutive alarms
346         c3_o       alm;                     //  alarm
347       } u3_behn;
348 
349     /* u2_utfo: unix terminfo strings.
350     */
351       typedef struct {
352         struct {
353           const c3_y* kcuu1_y;              //  key_up
354           const c3_y* kcud1_y;              //  key_down
355           const c3_y* kcub1_y;              //  key_back
356           const c3_y* kcuf1_y;              //  key_forward
357           c3_w        max_w;                //  maximum input sequence length
358         } inn;
359         struct {
360           const c3_y* clear_y;              //  clear_screen
361           const c3_y* el_y;                 //  clr_bol clear to beginning
362           // const c3_y* el1_y;                //  clr_eol clear to end
363           const c3_y* ed_y;                 //  clear to end of screen
364           const c3_y* bel_y;                //  bel sound bell
365           const c3_y* cub1_y;               //  parm_left
366           const c3_y* cuf1_y;               //  parm_right
367           const c3_y* cuu1_y;               //  parm_up
368           const c3_y* cud1_y;               //  parm_down
369           // const c3_y* cub_y;                //  parm_left_cursor #num
370           // const c3_y* cuf_y;                //  parm_right_cursor #num
371         } out;
372       } u3_utfo;
373 
374 #if 0
375     /* u3_uwen: unix alarm.
376     */
377       typedef struct _u3_uwen {
378         c3_y* pax_y;                        //  printed path
379         c3_d  wen_d[2];                     //  timer expire
380       };
381 
382     /* u3_utim: unix timer control.
383     */
384       typedef struct _u3_utim {
385         uv_timer_t wat_u;                   //  timer control
386         u3_uwen*   wen_u;                   //  timers in ascending order
387       };
388 #endif
389 
390     /* u3_utty: unix tty.
391     */
392       typedef struct _u3_utty {
393         union {
394           uv_pipe_t      pop_u;
395           uv_tcp_t       wax_u;
396         };
397         struct _u3_utty* nex_u;             //  next in host list
398         c3_i             fid_i;             //  file descriptor
399         c3_w             tid_l;             //  terminal identity number
400         u3_utfo          ufo_u;             //  terminfo strings
401         c3_i             cug_i;             //  blocking fcntl flags
402         c3_i             nob_i;             //  nonblocking fcntl flags
403         u3_utat          tat_u;             //  control state
404         struct termios   bak_u;             //  cooked terminal state
405         struct termios   raw_u;             //  raw terminal state
406       } u3_utty;
407 
408     /* u3_utel: unix telnet listener.
409     */
410       typedef struct _u3_utel {
411         struct _u3_utty uty_t;             //  pseudo-tty
412         c3_s            por_s;             //  file descriptor
413         void*           tel_u;             //  telnet context
414       } u3_utel;
415 
416     /* u3_raty: raft server type.
417     */
418       typedef enum {
419         u3_raty_none,
420         u3_raty_foll,
421         u3_raty_cand,
422         u3_raty_lead
423       } u3_raty;
424 
425     /* u3_raft: raft state.
426     */
427       typedef struct {
428         uv_tcp_t         wax_u;             //  TCP listener
429         uv_timer_t       tim_u;             //  election/heartbeat timer
430         u3_ulog          lug_u;             //  event log
431         c3_d             ent_d;             //  last log index
432         c3_w             lat_w;             //  last log term
433         u3_raty          typ_e;             //  server type
434         struct _u3_rnam* nam_u;             //  list of peers
435         struct _u3_rcon* run_u;             //  unknown connections
436         c3_w             pop_w;             //  population count
437         c3_w             vot_w;             //  votes in this election
438         c3_c*            str_c;             //  our name
439         //  persistent state
440         c3_w             tem_w;             //  current term
441         c3_c*            vog_c;             //  who we voted for this term
442         //  end persistent state
443       } u3_raft;
444 
445     /* u3_rreq: raft request.
446     */
447       typedef struct _u3_rreq {
448         struct _u3_rmsg* msg_u;
449         struct _u3_rreq* nex_u;
450         struct _u3_rcon* ron_u;
451       } u3_rreq;
452 
453     /* u3_rbuf: raft input buffer.
454     */
455       typedef struct _u3_rbuf {
456         c3_w                len_w;
457         c3_w                cap_w;
458         c3_y                buf_y[0];
459       } u3_rbuf;
460 
461     /* u3_rcon: raft connection.
462     */
463       typedef struct _u3_rcon {
464         uv_tcp_t         wax_u;             //  TCP handle
465         struct _u3_rnam* nam_u;             //  peer we're connected to
466         u3_rbuf*         red_u;             //  read buffer
467         c3_o             red;               //  u3_yes on new data
468         u3_rbuf*         wri_u;             //  write buffer
469         u3_raft*         raf_u;             //  back-reference to server
470         u3_rreq*         out_u;             //  exit of request queue
471         u3_rreq*         tou_u;             //  entry of request queue
472         struct _u3_rcon* nex_u;             //  pointer to next con
473         c3_o             liv;               //  are we live?
474       } u3_rcon;
475 
476     /* u3_rnam: raft peer name.
477     */
478       typedef struct _u3_rnam {
479         c3_c*            str_c;             //  our name
480         c3_c*            nam_c;             //  hostname
481         c3_c*            por_c;             //  port
482         u3_rcon*         ron_u;             //  connection
483         struct _u3_rnam* nex_u;             //  pointer to next peer
484         c3_o             vog;               //  did they vote for us?
485       } u3_rnam;
486 
487     /* u3_opts: command line configuration.
488     */
489       typedef struct _u3_opts {
490         c3_c*   arv_c;                      //  -A, initial sync from
491         c3_c*   dns_c;                      //  -H, ames bootstrap domain
492         c3_c*   gen_c;                      //  -G, czar generator
493         c3_c*   imp_c;                      //  -I, czar name
494         c3_c*   nam_c;                      //  -n, unix hostname
495         c3_c*   pil_c;                      //  -B, bootstrap from
496         c3_c*   raf_c;                      //  -r, raft flotilla
497         c3_c*   tic_c;                      //  -t, ticket value
498         c3_c*   url_c;                      //  -u, pill url
499         c3_c*   who_c;                      //  -w, begin with ticket
500         c3_o    abo;                        //  -a
501         c3_o    bat;                        //  -b, batch create
502         c3_o    dem;                        //  -d, daemon
503         c3_o    dry;                        //  -D, dry compute
504         c3_o    fak;                        //  -F, fake carrier
505         c3_o    fog;                        //  -X, skip last event
506         c3_o    gab;                        //  -g, run with garbage collector
507         c3_o    git;                        //  -s, pill url from arvo git hash
508         c3_o    mem;                        //  -M, memory madness
509         c3_o    net;                        //  -N, remote networking in -F mode
510         c3_o    nuu;                        //  -c, new pier
511         c3_o    pro;                        //  -P, profile
512         c3_o    qui;                        //  -q, quiet
513         c3_o    rep;                        //  -R, report build info
514         c3_o    tex;                        //  -x, exit after loading
515         c3_o    veb;                        //  -v, verbose (inverse of -q)
516         c3_o    vno;                        //  -V, replay without reboots
517         c3_s    por_s;                      //  -p, ames port
518         c3_s    rop_s;                      //  -l, raft port
519         c3_w    fuz_w;                      //  -f, fuzz testing
520         c3_w    kno_w;                      //  -k, kernel version
521       } u3_opts;
522 
523     /* u3_host: entire host.
524     */
525       typedef struct _u3_host {
526         c3_w       kno_w;                   //  current executing stage
527         c3_c*      dir_c;                   //  pier path (no trailing /)
528         c3_d       now_d;                   //  event tick
529         uv_loop_t* lup_u;                   //  libuv event loop
530         u3_http*   htp_u;                   //  http servers
531         u3_cttp    ctp_u;                   //  http clients
532         u3_utel    tel_u;                   //  telnet listener
533         u3_utty*   uty_u;                   //  linked terminal list
534         u3_ames    sam_u;                   //  packet interface
535         u3_save    sav_u;                   //  autosave
536         u3_opts    ops_u;                   //  commandline options
537         u3_unix    unx_u;                   //  sync and clay
538         u3_behn    teh_u;                   //  behn timer
539         c3_o       liv;                     //  if u3_no, shut down
540         c3_i       xit_i;                   //  exit code for shutdown
541         void*      tls_u;                   //  server SSL_CTX*
542       } u3_host;                            //  host == computer == process
543 
544 #     define u3L  u3_Host.lup_u             //  global event loop
545 #     define u3Z  (&(u3_Raft))
546 
547   /** Global variables.
548   **/
549     c3_global  u3_host  u3_Host;
550     c3_global  u3_raft  u3_Raft;
551     c3_global  c3_c*    u3_Local;
552 
553   /** Functions.
554   **/
555     /*  Urbit time: 128 bits, leap-free.
556     **
557     **  High 64 bits: 0x8000.000c.cea3.5380 + Unix time at leap 25 (Jul 2012)
558     **  Low 64 bits: 1/2^64 of a second.
559     **
560     **  Seconds per Gregorian 400-block: 12.622.780.800
561     **  400-blocks from 0 to 0AD: 730.692.561
562     **  Years from 0 to 0AD: 292.277.024.400
563     **  Seconds from 0 to 0AD: 9.223.372.029.693.628.800
564     **  Seconds between 0A and Unix epoch: 62.167.219.200
565     **  Seconds before Unix epoch: 9.223.372.091.860.848.000
566     **  The same, in C hex notation: 0x8000000cce9e0d80ULL
567     **
568     **  New leap seconds after July 2012 (leap second 25) are ignored.  The
569     **  platform OS will not ignore them, of course, so they must be detected
570     **  and counteracted.  Perhaps this phenomenon will soon find an endpoint.
571     */
572       /* u3_time_sec_in(): urbit seconds from unix time.
573       **
574       ** Adjust (externally) for future leap secs!
575       */
576         c3_d
577         u3_time_sec_in(c3_w unx_w);
578 
579       /* u3_time_sec_out(): unix time from urbit seconds.
580       **
581       ** Adjust (externally) for future leap secs!
582       */
583         c3_w
584         u3_time_sec_out(c3_d urs_d);
585 
586       /* u3_time_fsc_in(): urbit fracto-seconds from unix microseconds.
587       */
588         c3_d
589         u3_time_fsc_in(c3_w usc_w);
590 
591       /* u3_time_fsc_out: unix microseconds from urbit fracto-seconds.
592       */
593         c3_w
594         u3_time_fsc_out(c3_d ufc_d);
595 
596       /* u3_time_in_tv(): urbit time from struct timeval.
597       */
598         u3_atom
599         u3_time_in_tv(struct timeval* tim_tv);
600 
601       /* u3_time_out_tv(): struct timeval from urbit time.
602       */
603         void
604         u3_time_out_tv(struct timeval* tim_tv, u3_noun now);
605 
606       /* u3_time_in_ts(): urbit time from struct timespec.
607       */
608         u3_atom
609         u3_time_in_ts(struct timespec* tim_ts);
610 #if defined(U3_OS_linux)
611       /* u3_time_t_in_ts(): urbit time from time_t.
612        */
613          u3_atom
614          u3_time_t_in_ts(time_t tim);
615 #endif
616 
617       /* u3_time_out_ts(): struct timespec from urbit time.
618       */
619         void
620         u3_time_out_ts(struct timespec* tim_ts, u3_noun now);
621 
622       /* u3_time_gap_ms(): (wen - now) in ms.
623       */
624         c3_d
625         u3_time_gap_ms(u3_noun now, u3_noun wen);
626 
627     /**  Filesystem (new api).
628     **/
629       /* u3_walk_load(): load file or bail.
630       */
631         u3_noun
632         u3_walk_load(c3_c* pas_c);
633 
634       /* u3_walk_safe(): load file or 0.
635       */
636         u3_noun
637         u3_walk_safe(c3_c* pas_c);
638 
639       /* u3_walk_save(): save file or bail.
640       */
641         void
642         u3_walk_save(c3_c* pas_c, u3_noun tim, u3_atom pad, c3_c* bas_c, u3_noun pax);
643 
644       /* u3_sync_reck(): traverse filesystem for changes -> lamb
645       */
646         u3_noun
647         u3_sync_reck(void);
648 
649       /* u3_walk(): traverse `dir_c` to produce an arch, updating `old`.
650       */
651         u3_noun
652         u3_walk(const c3_c* dir_c, u3_noun old);
653 
654       /* u3_path(): C unix path in computer for file or directory.
655       */
656         c3_c*
657         u3_path(c3_o    fyl, u3_noun pax);
658 
659     /**  Filesystem (old api).
660     **/
661       /* u3_ve_file(): load internal file as atom from local or system.
662       */
663         u3_weak
664         u3_ve_file(c3_c* ext_c, u3_noun tah);
665 
666       /* u3_ve_frep(): load [.~ %rep myp {now} tah].
667       **
668       **   File is either ~ or [nbytes mdate atom].
669       */
670         u3_noun
671         u3_ve_frep(u3_noun myp, u3_noun tah);
672 
673       /* u3_ve_date(): date internal file.
674       */
675         c3_d
676         u3_ve_date(c3_c* ext_c, u3_noun tah);
677 
678       /* u3_ve_save(): save internal file as atom.
679       */
680         c3_o
681         u3_ve_save(c3_c* ext_c, u3_noun tah, u3_noun dat);
682 
683       /* u3_ve_zeus(): prayer to internal file path.  Return unit.
684       */
685         u3_noun
686         u3_ve_zeus(u3_noun hap);
687 
688     /**  Output.
689     **/
690       /* u3_ve_tank(): print a tank at `tab`.
691       */
692         void
693         u3_ve_tank(c3_l tab_l, u3_noun tac);
694 
695       /* u3_reck_kick(): handle effect.
696       */
697         void
698         u3_reck_kick(u3_noun ovo);
699 
700 
701     /**  Main loop, new style.
702     **/
703       /* u3_lo_loop(): enter main event loop.
704       */
705         void
706         u3_lo_loop(void);
707 
708       /* u3_lo_lead(): actions on promotion to leader.
709       */
710         void
711         u3_lo_lead(void);
712 
713       /* u3_lo_exit(): shut down io across pier.
714       */
715         void
716         u3_lo_exit(void);
717 
718       /* u3_lo_show(): print typeless noun.
719       */
720         void
721         u3_lo_show(c3_c* cap_c, u3_noun nun);
722 #define   u3ls(cap_c, nun) u3_lo_show(cap_c, nun)
723 
724       /* u3_lo_bail(): clean up all event state.
725       */
726         void
727         u3_lo_bail(void);
728 
729       /* u3_lo_tank(): dump single tank.
730       */
731         void
732         u3_lo_tank(c3_l tab_l, u3_noun tac);
733 
734       /* u3_lo_punt(): dump tank list.
735       */
736         void
737         u3_lo_punt(c3_l tab_l, u3_noun tac);
738 
739       /* u3_lo_sway(): print trace.
740       */
741         void
742         u3_lo_sway(c3_l tab_l, u3_noun tax);
743 
744       /* u3_lo_grab(): garbage-collect the world, plus roots; end with u3_none
745       */
746         void
747         u3_lo_grab(c3_c* cap_c, u3_noun som, ...);
748 
749       /* u3_lo_open(): begin callback processing.
750       */
751         void
752         u3_lo_open(void);
753 
754       /* u3_lo_shut(): end callback processing.
755       */
756         void
757         u3_lo_shut(c3_o);
758 
759 
760     /**  Terminal, new style.
761     **/
762       /* u3_term_get_blew(): return window size [columns rows].
763       */
764         u3_noun
765         u3_term_get_blew(c3_l tid_l);
766 
767       /* u3_term_ef_boil(): initial effects for restored server.
768       */
769         void
770         u3_term_ef_boil();
771 
772       /* u3_term_ef_ticket(): initial effects for new ticket.
773       */
774         void
775         u3_term_ef_ticket(c3_c* who_c, c3_c* tic_c);
776 
777       /* u3_term_ef_verb(): initial effects for verbose events.
778       */
779         void
780         u3_term_ef_verb(void);
781 
782       /* u3_term_ef_winc(): window change.
783       */
784         void
785         u3_term_ef_winc(void);
786 
787       /* u3_term_ef_ctlc(): send ^C.
788       */
789         void
790         u3_term_ef_ctlc(void);
791 
792       /* u3_term_ef_bake(): initial effects for new server.
793       */
794         void
795         u3_term_ef_bake(u3_noun  fav);
796 
797       /* u3_term_ef_blit(): send %blit effect to terminal.
798       */
799         void
800         u3_term_ef_blit(c3_l    tid_l,
801                         u3_noun blt);
802 
803       /* u3_term_io_init(): initialize terminal I/O.
804       */
805         void
806         u3_term_io_init(void);
807 
808       /* u3_term_io_talk(): start terminal listener.
809       */
810         void
811         u3_term_io_talk(void);
812 
813       /* u3_term_io_exit(): terminate terminal I/O.
814       */
815         void
816         u3_term_io_exit(void);
817 
818       /* u3_term_io_poll(): update terminal IO state.
819       */
820         void
821         u3_term_io_poll(void);
822 
823       /* u3_term_io_hija(): hijack console for cooked print.
824       */
825         FILE*
826         u3_term_io_hija(void);
827 
828       /* u3_term_io_loja(): release console from cooked print.
829       */
830         void
831         u3_term_io_loja(int x);
832 
833       /* uL, uH: wrap hijack/lojack around fprintf.
834       **
835       **  uL(fprintf(uH, ...));
836       */
837 #       define uH    u3_term_io_hija()
838 #       define uL(x) u3_term_io_loja(x)
839 
840 
841     /**  Ames, packet networking.
842     **/
843       /* u3_ames_ef_bake(): create ames duct.
844       */
845         void
846         u3_ames_ef_bake(void);
847 
848       /* u3_ames_ef_send(): send packet to network.
849       */
850         void
851         u3_ames_ef_send(u3_noun lan,
852                         u3_noun pac);
853 
854       /* u3_ames_io_init(): initialize ames I/O.
855       */
856         void
857         u3_ames_io_init(void);
858 
859       /* u3_ames_io_talk(): bring up listener.
860       */
861         void
862         u3_ames_io_talk(void);
863 
864       /* u3_ames_io_exit(): terminate ames I/O.
865       */
866         void
867         u3_ames_io_exit(void);
868 
869       /* u3_ames_io_poll(): update ames IO state.
870       */
871         void
872         u3_ames_io_poll(void);
873 
874     /**  Autosave.
875     **/
876       /* u3_save_ef_chld(): report SIGCHLD.
877       */
878         void
879         u3_save_ef_chld(void);
880 
881       /* u3_save_io_init(): initialize autosave.
882       */
883         void
884         u3_save_io_init(void);
885 
886       /* u3_save_io_exit(): terminate autosave.
887       */
888         void
889         u3_save_io_exit(void);
890 
891       /* u3_save_io_poll(): update autosave state.
892       */
893         void
894         u3_save_io_poll(void);
895 
896     /**  Storage, new school.
897     **/
898       /* u3_unix_ef_hold():
899       */
900         void
901         u3_unix_ef_hold();
902 
903       /* u3_unix_ef_move():
904       */
905         void
906         u3_unix_ef_move();
907 
908       /* u3_unix_initial_into(): intialize filesystem from urb/zod
909       */
910         void
911         u3_unix_ef_initial_into();
912 
913       /* u3_unix_ef_look(): update filesystem from unix
914       */
915         void
916         u3_unix_ef_look(u3_noun all);
917 
918       /* u3_unix_ef_ergo(): update filesystem from urbit
919       */
920         void
921         u3_unix_ef_ergo(u3_noun mon, u3_noun can);
922 
923       /* u3_unix_ef_ogre(): delete mount point
924       */
925         void
926         u3_unix_ef_ogre(u3_noun mon);
927 
928       /* u3_unix_ef_hill(): enumerate mount points
929       */
930         void
931         u3_unix_ef_hill(u3_noun hil);
932 
933       /* u3_unix_io_init(): initialize storage.
934       */
935         void
936         u3_unix_io_init(void);
937 
938       /* u3_unix_io_talk(): start listening for fs events.
939       */
940         void
941         u3_unix_io_talk(void);
942 
943       /* u3_unix_io_exit(): terminate storage.
944       */
945         void
946         u3_unix_io_exit(void);
947 
948       /* u3_unix_io_poll(): update storage state.
949       */
950         void
951         u3_unix_io_poll(void);
952 
953 
954     /**  behn, just a timer.
955     **/
956       /* u2_behn_io_init(): initialize behn timer.
957       */
958         void
959         u2_behn_io_init(void);
960 
961       /* u2_behn_io_exit(): terminate timer.
962       */
963         void
964         u2_behn_io_exit(void);
965 
966       /* u2_behn_io_poll(): update behn IO state.
967       */
968         void
969         u2_behn_io_poll(void);
970 
971 
972     /**  HTTP server.
973     **/
974       /* u3_http_ef_thou(): send %thou effect to http.
975       */
976         void
977         u3_http_ef_thou(c3_l     sev_l,
978                         c3_l     coq_l,
979                         c3_l     seq_l,
980                         u3_noun  rep);
981 
982       /* u3_cttp_ef_thus(): send %thus effect to cttp.
983       */
984         void
985         u3_cttp_ef_thus(c3_l    num_l,
986                         u3_noun req);
987 
988       /* u3_http_ef_bake(): create new http server.
989       */
990         void
991         u3_http_ef_bake(void);
992 
993       /* u3_http_io_init(): initialize http I/O.
994       */
995         void
996         u3_http_io_init(void);
997 
998       /* u3_http_io_talk(): start http listener.
999       */
1000         void
1001         u3_http_io_talk(void);
1002 
1003       /* u3_http_io_exit(): terminate http I/O.
1004       */
1005         void
1006         u3_http_io_exit(void);
1007 
1008       /* u3_http_io_poll(): update http IO state.
1009       */
1010         void
1011         u3_http_io_poll(void);
1012 
1013     /** Raft log syncing.
1014     **/
1015       /* u3_raft_readopt(): parse command line options.
1016       */
1017         u3_rnam*
1018         u3_raft_readopt(const c3_c* arg_c, c3_c* our_c, c3_s oup_s);
1019 
1020       /* u3_raft_init(): start Raft process.
1021       */
1022         void
1023         u3_raft_init(void);
1024 
1025       /* u3_raft_work(): poke, kick, and push pending events.
1026       */
1027         void
1028         u3_raft_work(void);
1029 
1030 
1031     /**  Disk persistence.
1032     **/
1033       /* u3_sist_boot(): restore or create pier from disk.
1034       */
1035         void
1036         u3_sist_boot(void);
1037 
1038       /* u3_sist_pack(): write a log entry to disk.
1039       **
1040       ** XX Synchronous.
1041       **
1042       ** typ_w is a mote describing the entry type: %ov for Arvo
1043       ** logs, %ra for Raft events.
1044       **
1045       ** Returns the entry's sequence number.
1046       */
1047         c3_d
1048         u3_sist_pack(c3_w tem_w,
1049                      c3_w typ_w,
1050                      c3_w* bob_w,
1051                      c3_w len_w);
1052 
1053       /* u3_sist_put(): moronic key-value store put.
1054       **
1055       ** u3_sist_put will do its best to associate the passed key with
1056       ** the passed value in a way that will persist across process
1057       ** restarts. It will probably do so by writing a file named for
1058       ** the key with contents identical to the value. To rely on it
1059       ** for anything heavy-duty would be a mistake.
1060       **
1061       ** Why would we even have something like this? Because sometimes
1062       ** we need to maintain files completely independently of the
1063       ** noun state.
1064       */
1065         void
1066         u3_sist_put(const c3_c* key_c, const c3_y* val_y, size_t siz_i);
1067 
1068       /* u3_sist_nil(): moronic key-value store rm.
1069       **
1070       ** Does its best to expunge all records on the given key. Has
1071       ** no effect if the key doesn't exist.
1072       */
1073         void
1074         u3_sist_nil(const c3_c* key_c);
1075 
1076       /* u3_sist_has(): moronic key-value store existence check.
1077       **
1078       ** Returns the byte length of the value previously stored via
1079       ** u3_sist_put, or -1 if it couldn't find one.
1080       */
1081         ssize_t
1082         u3_sist_has(const c3_c* key_c);
1083 
1084       /* u3_sist_get(): moronic key-value store get.
1085       **
1086       ** u3_sist_get is the mirror of u3_sist_put. It writes to val_y,
1087       ** which had better be at least as big as the return value from
1088       ** u3_sist_has, the value that you previously put.
1089       **
1090       ** Needless to say, u3_sist_get crashes if it can't find your
1091       ** value.
1092       */
1093         void
1094         u3_sist_get(const c3_c* key_c, c3_y* val_y);
1095 
1096       /* u3_sist_rand(): fill 8 words (32 bytes) with high-quality entropy.
1097       */
1098         void
1099         u3_sist_rand(c3_w* rad_w);
1100 
1101     /**  New timer system.
1102     **/
1103       /* u3_behn_io_init(): initialize time timer.
1104       */
1105         void
1106         u3_behn_io_init(void);
1107 
1108       /* u3_behn_io_exit(): terminate timer.
1109       */
1110         void
1111         u3_behn_io_exit(void);
1112 
1113       /* u3_behn_io_poll(): update behn IO state.
1114       */
1115         void
1116         u3_behn_io_poll(void);
1117 
1118 
1119     /**  HTTP client.
1120     **/
1121       /* u3_cttp_ef_thus(): send %thus effect to cttp.
1122       */
1123         void
1124         u3_cttp_ef_thus(c3_l    num_l,
1125                         u3_noun req);
1126 
1127       /* u3_cttp_io_init(): initialize cttp I/O.
1128       */
1129         void
1130         u3_cttp_io_init(void);
1131 
1132       /* u3_cttp_io_exit(): terminate cttp I/O.
1133       */
1134         void
1135         u3_cttp_io_exit(void);
1136 
1137       /* u3_cttp_io_poll(): update cttp IO state.
1138       */
1139         void
1140         u3_cttp_io_poll(void);
1141