conn: add port request

Also make peel requests respond with $unit.
This commit is contained in:
Jōshin 2022-02-05 09:05:37 -06:00
parent f47b77faae
commit 3e3f9c553c
No known key found for this signature in database
GPG Key ID: A8BE5A9A521639D0

View File

@ -422,10 +422,10 @@ _conn_ovum_news(u3_ovum* egg_u, u3_ovum_news new_e)
static void static void
_conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y) _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y)
{ {
u3_weak jar; u3_weak jar;
u3_noun can, rid, tag, dat; u3_noun can, rid, tag, dat;
u3_chan* can_u = (u3_chan*)ptr_v; u3_chan* can_u = (u3_chan*)ptr_v;
u3_conn* con_u = can_u->san_u->con_u; u3_conn* con_u = can_u->san_u->con_u;
jar = u3s_cue_xeno_with(con_u->sil_u, len_d, byt_y); jar = u3s_cue_xeno_with(con_u->sil_u, len_d, byt_y);
if ( u3_none == jar ) { if ( u3_none == jar ) {
@ -439,9 +439,9 @@ _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y)
can_u->mor_u.bal_f(can_u, -2, "jar-bad"); can_u->mor_u.bal_f(can_u, -2, "jar-bad");
} }
else { else {
u3_atom rud = u3dc("scot", c3__uv, u3k(rid)); u3_atom rud = u3dc("scot", c3__uv, u3k(rid));
c3_c* tag_c = u3r_string(tag); c3_c* tag_c = u3r_string(tag);
c3_c* rid_c = u3r_string(rud); c3_c* rid_c = u3r_string(rud);
u3l_log("conn: %s %s\n", tag_c, rid_c); u3l_log("conn: %s %s\n", tag_c, rid_c);
c3_free(tag_c); c3_free(tag_c);
@ -459,11 +459,11 @@ _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y)
u3nt(u3k(rid), c3__fail, u3i_string("khan-miss"))); u3nt(u3k(rid), c3__fail, u3i_string("khan-miss")));
} }
else { else {
u3_noun wir = u3nc(c3__khan, u3_noun wir = u3nc(c3__khan,
u3nq(u3dc("scot", c3__uv, con_u->sev_l), u3nq(u3dc("scot", c3__uv, con_u->sev_l),
u3dc("scot", c3__ud, can_u->coq_l), u3dc("scot", c3__ud, can_u->coq_l),
u3dc("scot", c3__uv, u3k(rid)), u3dc("scot", c3__uv, u3k(rid)),
u3_nul)); u3_nul));
u3_auto_peer( u3_auto_peer(
u3_auto_plan(&con_u->car_u, u3_auto_plan(&con_u->car_u,
@ -474,8 +474,8 @@ _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y)
} }
case c3__peek: { case c3__peek: {
u3_cran* ran_u = c3_calloc(sizeof(u3_cran)); u3_cran* ran_u = c3_calloc(sizeof(u3_cran));
u3_noun gan = u3nc(u3_nul, u3_nul); // `~: read from self u3_noun gan = u3nc(u3_nul, u3_nul); // `~: read from self
ran_u->rid = u3k(rid); ran_u->rid = u3k(rid);
ran_u->can_u = can_u; ran_u->can_u = can_u;
@ -486,14 +486,14 @@ _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y)
} }
case c3__peel: { case c3__peel: {
u3_noun i_dat, t_dat; u3_noun i_dat, t_dat;
if ( (c3n == u3r_cell(dat, &i_dat, &t_dat)) || if ( (c3n == u3r_cell(dat, &i_dat, &t_dat)) ) {
(u3_nul != t_dat) )
{
can_u->mor_u.bal_f(can_u, -5, "peel-bad"); can_u->mor_u.bal_f(can_u, -5, "peel-bad");
} }
else { else {
// TODO require u3_nul == t_dat where appropriate
//
switch (i_dat) { switch (i_dat) {
default: { default: {
can_u->mor_u.bal_f(can_u, -6, "peel-unknown"); can_u->mor_u.bal_f(can_u, -6, "peel-unknown");
@ -502,19 +502,51 @@ _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y)
// simple health check. // simple health check.
// //
case c3__live: { case c3__live: {
_conn_send_noun(can_u, u3nc(u3k(rid), c3y)); _conn_send_noun(can_u, u3nt(u3k(rid), u3_nul, c3y));
break; break;
} }
// say whether the %khan vane is working. // say whether the %khan vane is working.
// //
case c3__khan: { case c3__khan: {
_conn_send_noun(can_u, u3nc(u3k(rid), con_u->kan_o)); _conn_send_noun(can_u, u3nt(u3k(rid), u3_nul, con_u->kan_o));
break; break;
} }
// get vere version. // get vere version.
// //
case c3__v: { case c3__v: {
_conn_send_noun(can_u, u3nc(u3k(rid), u3i_string(URBIT_VERSION))); _conn_send_noun(can_u, u3nt(u3k(rid), u3_nul,
u3i_string(URBIT_VERSION)));
break;
}
// get port.
//
case c3__port: {
u3_noun it_dat, tt_dat;
if ( (c3n == u3r_cell(t_dat, &it_dat, &tt_dat))
|| (u3_nul != tt_dat) )
{
can_u->mor_u.bal_f(can_u, -8, "port-bad");
}
else {
switch (it_dat) {
default: {
can_u->mor_u.bal_f(can_u, -9, "port-unknown");
break;
}
case c3__ames: {
_conn_send_noun(can_u, u3nt(u3k(rid), u3_nul,
u3_Host.ops_u.por_s));
break;
}
case c3__http: {
// TODO get http configuration
//
_conn_send_noun(can_u, u3nc(u3k(rid), u3_nul));
break;
}
}
}
break; break;
} }
// TODO: fill in rest of %peel namespace. // TODO: fill in rest of %peel namespace.
@ -525,13 +557,13 @@ _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y)
} }
case c3__ovum: { case c3__ovum: {
u3_noun tar, wir, cad; u3_noun tar, wir, cad;
if ( (c3n == u3r_trel(dat, &tar, &wir, &cad)) ) { if ( (c3n == u3r_trel(dat, &tar, &wir, &cad)) ) {
can_u->mor_u.bal_f(can_u, -6, "ovum-bad"); can_u->mor_u.bal_f(can_u, -6, "ovum-bad");
} }
else { else {
u3_cran* ran_u = c3_calloc(sizeof(u3_cran)); u3_cran* ran_u = c3_calloc(sizeof(u3_cran));
ran_u->rid = u3k(rid); ran_u->rid = u3k(rid);
ran_u->can_u = can_u; ran_u->can_u = can_u;