diff --git a/pkg/urbit/include/c/motes.h b/pkg/urbit/include/c/motes.h index cbb4850b2..2871e7d20 100644 --- a/pkg/urbit/include/c/motes.h +++ b/pkg/urbit/include/c/motes.h @@ -601,6 +601,8 @@ # define c3__jet c3_s3('j','e','t') # define c3__jetd c3_s4('j','e','t','d') # define c3__just c3_s4('j','u','s','t') +# define c3__k c3_s1('k') +# define c3__khan c3_s4('k','h','a','n') # define c3__keep c3_s4('k','e','e','p') # define c3__kern c3_s4('k','e','r','n') # define c3__kgo c3_s3('k','g','o') diff --git a/pkg/urbit/include/vere/vere.h b/pkg/urbit/include/vere/vere.h index a0cab581c..880df3fa4 100644 --- a/pkg/urbit/include/vere/vere.h +++ b/pkg/urbit/include/vere/vere.h @@ -1199,6 +1199,13 @@ u3_auto* u3_cttp_io_init(u3_pier* pir_u); + /** Control plane. + **/ + /* u3_khan_io_init(): initialize control plane I/O. + */ + u3_auto* + u3_khan_io_init(u3_pier* pir_u); + /** fore, first events **/ /* u3_hind_io_init(): initialize fore diff --git a/pkg/urbit/vere/auto.c b/pkg/urbit/vere/auto.c index 5a56d22bc..2a4c3d5b6 100644 --- a/pkg/urbit/vere/auto.c +++ b/pkg/urbit/vere/auto.c @@ -408,6 +408,7 @@ u3_auto_init(u3_pier* pir_u) car_u = _auto_link(u3_hind_io_init(pir_u), pir_u, car_u); car_u = _auto_link(u3_behn_io_init(pir_u), pir_u, car_u); + car_u = _auto_link(u3_khan_io_init(pir_u), pir_u, car_u); car_u = _auto_link(u3_ames_io_init(pir_u), pir_u, car_u); car_u = _auto_link(u3_http_io_init(pir_u), pir_u, car_u); car_u = _auto_link(u3_cttp_io_init(pir_u), pir_u, car_u); diff --git a/pkg/urbit/vere/io/khan.c b/pkg/urbit/vere/io/khan.c new file mode 100644 index 000000000..2220f3b3a --- /dev/null +++ b/pkg/urbit/vere/io/khan.c @@ -0,0 +1,96 @@ +/* vere/khan.c +** +*/ +#include +#include +#include +#include +#include +#include + +#include "all.h" +#include "vere/vere.h" + +/* u3_khan: control plane socket +*/ + typedef struct _u3_khan { + u3_auto car_u; // driver + c3_l sev_l; // instance number + } u3_khan; + +/* _khan_io_talk(): notify %khan that we're live +*/ +static void +_khan_io_talk(u3_auto* car_u) +{ + u3_khan* cop_u = (u3_khan*)car_u; + + u3_noun wir = u3nt(c3__khan, + u3dc("scot", c3__uv, cop_u->sev_l), + u3_nul); + u3_noun cad = u3nc(c3__born, u3_nul); + + u3_auto_plan(car_u, u3_ovum_init(0, c3__k, wir, cad)); +} + +/* _khan_io_kick(): apply effects. +*/ +static c3_o +_khan_io_kick(u3_auto* car_u, u3_noun wir, u3_noun cad) +{ + u3_khan* cop_u = (u3_khan*)car_u; + + u3_noun tag, dat, i_wir; + c3_o ret_o; + + if ( (c3n == u3r_cell(wir, &i_wir, 0)) + || (c3n == u3r_cell(cad, &tag, &dat)) + || (c3__khan != i_wir) ) + { + ret_o = c3n; + } + else { + ret_o = c3y; + // TODO do something + } + + u3z(wir); u3z(cad); + return ret_o; +} + +/* _khan_io_exit(): close socket. +*/ +static void +_khan_io_exit(u3_auto* car_u) +{ + u3_khan* cop_u = (u3_khan*)car_u; + // TODO close socket +} + +/* u3_khan(): initialize control plane socket. +*/ +u3_auto* +u3_khan_io_init(u3_pier* pir_u) +{ + u3_khan* cop_u = c3_calloc(sizeof(*cop_u)); + + u3_auto* car_u = &cop_u->car_u; + car_u->nam_m = c3__khan; + car_u->io.talk_f = _khan_io_talk; + car_u->io.kick_f = _khan_io_kick; + car_u->io.exit_f = _khan_io_exit; + + // TODO open socket + + { + u3_noun now; + struct timeval tim_u; + gettimeofday(&tim_u, 0); + + now = u3_time_in_tv(&tim_u); + cop_u->sev_l = u3r_mug(now); + u3z(now); + } + + return car_u; +}