Merge branch 'lighter-than-eyre' into bs/uterm

This commit is contained in:
Elliot Glaysher 2019-05-23 16:02:39 -07:00
commit ee1938f6fe
19 changed files with 966 additions and 349 deletions

View File

@ -1 +0,0 @@
6d6ec85d6aa9200d366d0998326726ef1965d092

View File

@ -1,4 +1,4 @@
.PHONY: build build-all install cross release test clean
.PHONY: build build-all install cross release test pills clean
build:
nix-build -A urbit -A herb --no-out-link
@ -18,6 +18,10 @@ release:
test:
sh/test
pills:
sh/update-solid-pill
sh/update-brass-pill
clean:
rm -rf ./cross ./release
rm -f result result-*

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a79ceaa44b0c056dc34b15e759757fe3dc470be01530d96a4bc6f44098f73220
size 5503628
oid sha256:2b7ee602f18661a07c88f2fbb2297f2d8e6fd329db0afc760ad334a845e73c9c
size 4601348

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3487ad86985d61dcd3106e7114167d0d6c071ffab645c6c9bfe131ec8bd6dd3c
size 8133778
oid sha256:cdf8ed31292285c9dda789a8ac313babb4d9ce98f19ace4a813d821a9861d685
size 7168503

View File

@ -15,7 +15,7 @@ worker_objs = $(shell echo $(worker) | sed 's/\.c/.o/g')
all_objs = $(common_objs) $(daemon_objs) $(worker_objs)
all_srcs = $(common) $(daemon) $(worker)
all_exes = ./hash_tests ./hashtable_tests ./urbit ./urbit-worker
all_exes = ./mug_tests jam_tests ./hashtable_tests ./urbit ./urbit-worker
# -Werror promotes all warnings that are enabled into errors (this is on)
@ -29,11 +29,12 @@ CFLAGS := $(CFLAGS)
################################################################################
all: urbit urbit-worker hashtable_tests hash_tests
all: urbit urbit-worker hashtable_tests jam_tests mug_tests
test: hashtable_tests hash_tests
test: hashtable_tests jam_tests mug_tests
./hashtable_tests
./hash_tests
./jam_tests
./mug_tests
clean:
rm -f ./tags $(all_objs) $(all_exes)
@ -47,7 +48,11 @@ hashtable_tests: $(common_objs) tests/hashtable_tests.o
@echo CC -o $@
@$(CC) $^ $(LDFLAGS) -o $@
hash_tests: $(common_objs) tests/hash_tests.o
jam_tests: $(common_objs) tests/jam_tests.o
@echo CC -o $@
@$(CC) $^ $(LDFLAGS) -o $@
mug_tests: $(common_objs) tests/mug_tests.o
@echo CC -o $@
@$(CC) $^ $(LDFLAGS) -o $@

View File

@ -467,6 +467,8 @@ report(void)
printf("argon2: 0x%x\n", ARGON2_VERSION_NUMBER);
}
/* _stop_exit(): exit immediately.
*/
static void
_stop_exit(c3_i int_i)
{
@ -476,6 +478,18 @@ _stop_exit(c3_i int_i)
u3_daemon_bail();
}
/* _stop_trace(): print trace on SIGABRT.
*/
static void
_stop_trace(c3_i int_i)
{
// if we have a pier, unmap the event log before dumping core
//
if ( 0 != u3K.len_w ) {
u3_pier_db_shutdown(u3_pier_stub());
}
}
/*
This is set to the the write-end of a pipe when Urbit is started in
daemon mode. It's meant to be used as a signal to the parent process
@ -626,6 +640,10 @@ main(c3_i argc,
//
signal(SIGTSTP, _stop_exit);
// Cleanup on SIGABRT.
//
signal(SIGABRT, _stop_trace);
printf("~\n");
// printf("welcome.\n");
printf("urbit %s\n", URBIT_VERSION);

View File

@ -580,6 +580,7 @@
# define c3__into c3_s4('i','n','t','o')
# define c3__intr c3_s4('i','n','t','r')
# define c3__inuk c3_s4('i','n','u','k')
# define c3__ipv4 c3_s4('i','p','v','4')
# define c3__iron c3_s4('i','r','o','n')
# define c3__is c3_s2('i','s')
# define c3__item c3_s4('i','t','e','m')
@ -1203,6 +1204,7 @@
# define c3__wail c3_s4('w','a','i','l')
# define c3__wake c3_s4('w','a','k','e')
# define c3__wamp c3_s4('w','a','m','p')
# define c3__want c3_s4('w','a','n','t')
# define c3__warm c3_s4('w','a','r','m')
# define c3__warn c3_s4('w','a','r','n')
# define c3__warx c3_s4('w','a','r','x')
@ -1224,6 +1226,7 @@
# define c3__with c3_s4('w','i','t','h')
# define c3__wnut c3_s4('w','n','u','t')
# define c3__wood c3_s4('w','o','o','d')
# define c3__woot c3_s4('w','o','o','t')
# define c3__work c3_s4('w','o','r','k')
# define c3__wost c3_s4('w','o','s','t')
# define c3__wrap c3_s4('w','r','a','p')

View File

@ -139,6 +139,11 @@
c3_o
u3r_sing(u3_noun a, u3_noun b);
/* u3rz_sing(): transferring u3r_sing
*/
c3_o
u3rz_sing(u3_noun a, u3_noun b);
/* u3r_sung(): yes iff (a) and (b) are the same noun, unifying equals.
**
** Make sure you have no live, uncounted pointers to any noun

View File

@ -51,6 +51,7 @@
c3_w seq_l; // sequence within connection
u3_rsat sat_e; // request state
uv_timer_t* tim_u; // timeout
void* gen_u; // response generator
struct _u3_hcon* hon_u; // connection backlink
struct _u3_hreq* nex_u; // next in connection's list
struct _u3_hreq* pre_u; // next in connection's list
@ -205,7 +206,7 @@
c3_c* hot_c; // host
c3_s por_s; // port
c3_c* por_c; // port (string)
c3_m met_m; // method
c3_c* met_c; // method
c3_c* url_c; // url
u3_hhed* hed_u; // headers
u3_hbod* bod_u; // body
@ -1102,21 +1103,15 @@
/* u3_http_ef_that: send %that effect to http.
*/
void
u3_http_ef_that(u3_noun tat);
u3_http_ef_that(u3_noun sip, u3_noun tat);
/* u3_http_ef_thou(): send %thou effect to http.
/* u3_http_ef_http_server(): dispatch an %http-server effect from %light.
*/
void
u3_http_ef_thou(c3_l sev_l,
c3_l coq_l,
c3_l seq_l,
u3_noun rep);
/* u3_cttp_ef_thus(): send %thus effect to cttp.
*/
void
u3_cttp_ef_thus(c3_l num_l,
u3_noun req);
u3_http_ef_http_server(c3_l sev_l,
c3_l coq_l,
c3_l seq_l,
u3_noun cad);
/* u3_http_ef_bake(): create new http server.
*/
@ -1141,11 +1136,17 @@
/** HTTP client.
**/
/* u3_cttp_ef_thus(): send %thus effect to cttp.
/** HTTP client.
**/
/* u3_cttp_ef_http_client(): send %http-client effect to cttp.
*/
void
u3_cttp_ef_thus(c3_l num_l,
u3_noun req);
u3_cttp_ef_http_client(u3_noun fav);
/* u3_cttp_ef_back(): initialization event on restart.
*/
void
u3_cttp_ef_bake();
/* u3_cttp_io_init(): initialize cttp I/O.
*/
@ -1174,6 +1175,11 @@
/** Pier control.
**/
/* u3_pier_db_shutdown(): close the log.
*/
void
u3_pier_db_shutdown(u3_pier* pir_u);
/* u3_pier_interrupt(): interrupt running process.
*/
void

View File

@ -3,94 +3,239 @@
*/
#include "all.h"
#define CUE_ROOT 0
#define CUE_HEAD 1
#define CUE_TAIL 2
static u3_noun
_cue_in(u3p(u3h_root) har_p,
u3_atom a,
u3_atom b)
// stack frame for record head vs tail iteration
//
// In Hoon, this structure would be as follows:
//
// $% [%root ~]
// [%head cell-cursor=@]
// [%tail cell-cursor=@ hed-width=@ hed-value=@]
// ==
//
typedef struct cueframe
{
c3_y tag_y;
u3_atom cur;
u3_atom wid;
u3_noun hed;
} cueframe;
static inline void
_cue_push(c3_ys mov,
c3_ys off,
c3_y tag_y,
u3_atom cur,
u3_atom wid,
u3_noun hed)
{
u3R->cap_p += mov;
// ensure we haven't overflowed the stack
// (off==0 means we're on a north road)
//
if ( 0 == off ) {
c3_assert(u3R->cap_p > u3R->hat_p);
}
else {
c3_assert(u3R->cap_p < u3R->hat_p);
}
cueframe* fam_u = u3to(cueframe, u3R->cap_p + off);
fam_u->tag_y = tag_y;
fam_u->cur = cur;
fam_u->wid = wid;
fam_u->hed = hed;
}
static inline cueframe
_cue_pop(c3_ys mov, c3_ys off)
{
cueframe* fam_u = u3to(cueframe, u3R->cap_p + off);
u3R->cap_p -= mov;
return *fam_u;
}
u3_noun
u3qe_cue(u3_atom a)
{
// initialize signed stack offsets (relative to north/south road)
//
c3_ys mov, off;
{
u3_noun p, q;
c3_y wis_y = c3_wiseof(cueframe);
c3_o nor_o = u3a_is_north(u3R);
mov = ( c3y == nor_o ? -wis_y : wis_y );
off = ( c3y == nor_o ? 0 : -wis_y );
}
if ( 0 == u3qc_cut(0, b, 1, a) ) {
u3_noun x = u3qa_inc(b);
u3_noun c = u3qe_rub(x, a);
// initialize a hash table for dereference backrefs
//
u3p(u3h_root) har_p = u3h_new();
p = u3qa_inc(u3k(u3h(c)));
q = u3k(u3t(c));
// stash the current stack post
//
u3p(cueframe) cap_p = u3R->cap_p;
u3h_put(har_p, u3k(b), u3k(q));
// push the (only) ROOT stack frame (our termination condition)
//
_cue_push(mov, off, CUE_ROOT, 0, 0, 0);
u3z(c);
// initialize cursor to bit-position 0
//
u3_atom cur = 0;
// the bitwidth and product from reading at cursor
//
u3_atom wid, pro;
// read from atom at cursor
//
// TRANSFER .cur
//
pass: {
// read tag bit at cur
//
c3_y tag_y = u3qc_cut(0, cur, 1, a);
// low bit unset, (1 + cur) points to an atom
//
// produce atom and the width we read
//
if ( 0 == tag_y ) {
u3_noun bur;
{
u3_noun x = u3qa_inc(cur);
bur = u3qe_rub(x, a);
u3z(x);
}
pro = u3k(u3t(bur));
u3h_put(har_p, cur, u3k(pro));
wid = u3qa_inc(u3h(bur));
u3z(bur);
goto give;
}
// read tag bit at (1 + cur)
//
{
u3_noun x = u3qa_inc(cur);
tag_y = u3qc_cut(0, x, 1, a);
u3z(x);
}
else {
u3_noun c = u3qa_add(2, b);
u3_noun l = u3qa_inc(b);
if ( 0 == u3qc_cut(0, l, 1, a) ) {
u3_noun u, v, w;
u3_noun x, y;
u = _cue_in(har_p, a, c);
x = u3qa_add(u3h(u), c);
v = _cue_in(har_p, a, x);
w = u3nc(u3k(u3h(u3t(u))), u3k(u3h(u3t(v))));
y = u3qa_add(u3h(u), u3h(v));
p = u3qa_add(2, y);
q = w;
u3h_put(har_p, u3k(b), u3k(q));
u3z(u); u3z(v); u3z(x); u3z(y);
// next bit set, (2 + cur) points to a backref
//
// produce referenced value and the width we read
//
if ( 1 == tag_y ) {
u3_noun bur;
{
u3_noun x = u3ka_add(2, cur);
bur = u3qe_rub(x, a);
u3z(x);
}
else {
u3_noun d = u3qe_rub(c, a);
u3_noun x = u3h_get(har_p, u3k(u3t(d)));
p = u3qa_add(2, u3h(d));
if ( u3_none == x ) {
return u3m_bail(c3__exit);
}
q = x;
u3z(d);
pro = u3h_get(har_p, u3k(u3t(bur)));
if ( u3_none == pro ) {
return u3m_bail(c3__exit);
}
u3z(l);
u3z(c);
wid = u3qa_add(2, u3h(bur));
u3z(bur);
goto give;
}
return u3nt(p, q, 0);
}
u3_noun
u3qe_cue(u3_atom a)
{
u3p(u3h_root) har_p = u3h_new();
// next bit unset, (2 + cur) points to the head of a cell
//
// push a frame to mark HEAD recursion and read the head
//
{
_cue_push(mov, off, CUE_HEAD, cur, 0, 0);
u3_noun x = _cue_in(har_p, a, 0);
u3_noun y = u3k(u3h(u3t(x)));
u3h_free(har_p);
u3z(x);
return y;
}
u3_noun
u3we_cue(u3_noun cor)
{
u3_noun a;
if ( (u3_none == (a = u3r_at(u3x_sam, cor))) ) {
return u3m_bail(c3__fail);
} else {
return u3qe_cue(a);
cur = u3qa_add(2, cur);
goto pass;
}
}
u3_noun
u3ke_cue(u3_atom a)
{
u3_noun b = u3qe_cue(a);
u3z(a);
return b;
// consume: popped stack frame, .wid and .pro from above.
//
// TRANSFER .wid, .pro, and contents of .fam_u
// (.cur is in scope, but we have already lost our reference to it)
//
give: {
cueframe fam_u = _cue_pop(mov, off);
switch ( fam_u.tag_y ) {
default: {
c3_assert(0);
}
// fam_u is our stack root, we're done.
//
case CUE_ROOT: {
break;
}
// .wid and .pro are the head of the cell at fam_u.cur.
// save them (and the cell cursor) in a TAIL frame,
// set the cursor to the tail and read there.
//
case CUE_HEAD: {
_cue_push(mov, off, CUE_TAIL, fam_u.cur, wid, pro);
cur = u3ka_add(2, u3qa_add(wid, fam_u.cur));
goto pass;
}
// .wid and .pro are the tail of the cell at fam_u.cur,
// construct the cell, memoize it, and produce it along with
// its total width (as if it were a read from above).
//
case CUE_TAIL: {
pro = u3nc(fam_u.hed, pro);
u3h_put(har_p, fam_u.cur, u3k(pro));
wid = u3ka_add(2, u3ka_add(wid, fam_u.wid));
goto give;
}
}
}
u3z(wid);
u3h_free(har_p);
// sanity check
//
c3_assert( u3R->cap_p == cap_p );
return pro;
}
u3_noun
u3we_cue(u3_noun cor)
{
u3_noun a;
if ( (u3_none == (a = u3r_at(u3x_sam, cor))) ) {
return u3m_bail(c3__fail);
} else {
return u3qe_cue(a);
}
}
u3_noun
u3ke_cue(u3_atom a)
{
u3_noun b = u3qe_cue(a);
u3z(a);
return b;
}

View File

@ -633,6 +633,16 @@ u3r_sing(u3_noun a, u3_noun b)
}
}
/* u3rz_sing(): transferring u3r_sing
*/
c3_o
u3rz_sing(u3_noun a, u3_noun b)
{
c3_o ret_o = u3r_sing(a, b);
u3z(a); u3z(b);
return ret_o;
}
/* u3r_sung(): yes iff (a) and (b) are the same noun, unifying equals.
*/
c3_o

113
pkg/urbit/tests/jam_tests.c Normal file
View File

@ -0,0 +1,113 @@
#include "all.h"
/* _setup(): prepare for tests.
*/
static void
_setup(void)
{
u3m_init();
u3m_pave(c3y, c3n);
}
/* _test_jam(): spot check jam/cue
*/
static void
_test_jam(void)
{
if ( 0xc != u3qe_jam(1) ) {
fprintf(stderr, "jam: fail (a)\r\n");
exit(1);
}
if ( 1 != u3ke_cue(u3qe_jam(1)) ) {
fprintf(stderr, "jam: fail (b)\r\n");
exit(1);
}
{
u3_noun a = u3nc(1, 2);
if ( 0x1231 != u3qe_jam(a) ) {
fprintf(stderr, "jam: fail (c)\r\n");
exit(1);
}
if ( c3y != u3r_sing(a, u3ke_cue(u3qe_jam(a))) ) {
fprintf(stderr, "jam: fail (d)\r\n");
exit(1);
}
}
{
u3_noun a = u3nt(1, 2, 3);
if ( 0x344871 != u3qe_jam(a) ) {
fprintf(stderr, "jam: fail (e)\r\n");
exit(1);
}
if ( c3y != u3r_sing(a, u3ke_cue(u3qe_jam(a))) ) {
fprintf(stderr, "jam: fail (f)\r\n");
exit(1);
}
}
{
u3_noun a = u3nc(u3nc(1, 2), 3);
// fprintf(stderr, "%x\n", u3qe_jam(a));
if ( 0x3448c5 != u3qe_jam(a) ) {
fprintf(stderr, "jam: fail (g)\r\n");
exit(1);
}
if ( c3y != u3r_sing(a, u3ke_cue(u3qe_jam(a))) ) {
fprintf(stderr, "jam: fail (h)\r\n");
exit(1);
}
}
{
u3_noun b = u3nc(1, 2);
u3_noun a = u3nt(b, b, b);
if ( c3y != u3r_sing(a, u3ke_cue(u3qe_jam(a))) ) {
fprintf(stderr, "jam: fail (j)\r\n");
exit(1);
}
}
{
u3_noun b = u3i_string("abcdefjhijklmnopqrstuvwxyz");
u3_noun a = u3nq(b, 2, 3, b);
if ( c3y != u3r_sing(a, u3ke_cue(u3qe_jam(a))) ) {
fprintf(stderr, "jam: fail (k)\r\n");
exit(1);
}
}
{
u3_noun a = u3nc(u3nc(u3nc(1, u3nc(u3nc(2, u3nc(u3nc(3, u3nc(u3nc(4, u3nc(u3nt(5, 6, u3nc(7, u3nc(u3nc(8, 0), 0))), 0)), 0)), 0)), 0)), 0), 0);
if ( c3y != u3r_sing(a, u3ke_cue(u3qe_jam(a))) ) {
fprintf(stderr, "jam: fail (l)\r\n");
exit(1);
}
}
fprintf(stderr, "test_jam: ok\n");
}
/* main(): run all test cases.
*/
int
main(int argc, char* argv[])
{
_setup();
_test_jam();
return 0;
}

View File

@ -90,6 +90,8 @@ _test_mug(void)
exit(1);
}
}
fprintf(stderr, "test_mug: ok\n");
}
/* main(): run all test cases.

View File

@ -208,29 +208,23 @@ _cttp_hed_new(u3_atom nam, u3_atom val)
return hed_u;
}
// XX vv similar to _http_heds_from_noun
/* _cttp_heds_math(): create headers from +math
// XX deduplicate with _http_heds_from_noun
/* _cttp_heds_from_noun(): convert (list (pair @t @t)) to u3_hhed
*/
static u3_hhed*
_cttp_heds_math(u3_noun mah)
_cttp_heds_from_noun(u3_noun hed)
{
u3_noun hed = u3kdi_tap(mah);
u3_noun deh = hed;
u3_noun i_hed;
u3_hhed* hed_u = 0;
while ( u3_nul != hed ) {
u3_noun nam = u3h(u3h(hed));
u3_noun lit = u3t(u3h(hed));
while ( u3_nul != lit ) {
u3_hhed* nex_u = _cttp_hed_new(nam, u3h(lit));
nex_u->nex_u = hed_u;
hed_u = nex_u;
lit = u3t(lit);
}
i_hed = u3h(hed);
u3_hhed* nex_u = _cttp_hed_new(u3h(i_hed), u3t(i_hed));
nex_u->nex_u = hed_u;
hed_u = nex_u;
hed = u3t(hed);
}
@ -529,27 +523,42 @@ _cttp_creq_free(u3_creq* ceq_u)
free(ceq_u->hot_c);
free(ceq_u->por_c);
free(ceq_u->met_c);
free(ceq_u->url_c);
free(ceq_u->vec_u);
free(ceq_u);
}
/* _cttp_creq_new(): create a request from a +hiss noun
*/
/* _cttp_creq_new(): create a u3_creq from an +http-request
*
* If we were rewriting all of this from scratch, this isn't how we'd do it.
*
* We start with the (?? - JB)
*/
static u3_creq*
_cttp_creq_new(c3_l num_l, u3_noun hes)
{
u3_creq* ceq_u = c3_calloc(sizeof(*ceq_u));
u3_noun pul = u3h(hes); // +purl
u3_noun method, url, headers, body;
if (c3n == u3r_qual(hes, &method, &url, &headers, &body)) {
u3z(hes);
return 0;
}
// Parse the url out of the new style url passed to us.
u3_noun unit_pul = u3do("de-purl:html", u3k(url));
if (c3n == u3r_du(unit_pul)) {
u3l_log("cttp: url parsing failed\n");
u3z(hes);
return 0;
}
u3_noun pul = u3t(unit_pul);
u3_noun hat = u3h(pul); // +hart
u3_noun sec = u3h(hat);
u3_noun por = u3h(u3t(hat));
u3_noun hot = u3t(u3t(hat)); // +host
u3_noun moh = u3t(hes); // +moth
u3_noun met = u3h(moh); // +meth
u3_noun mah = u3h(u3t(moh)); // +math
u3_noun bod = u3t(u3t(moh));
ceq_u->sat_e = u3_csat_init;
ceq_u->num_l = num_l;
@ -567,17 +576,23 @@ _cttp_creq_new(c3_l num_l, u3_noun hes)
ceq_u->por_c = _cttp_creq_port(ceq_u->por_s);
}
ceq_u->met_m = met;
// XX this should be checked against a whitelist
//
c3_assert( c3y == u3ud(method) );
ceq_u->met_c = u3r_string(method);
ceq_u->url_c = _cttp_creq_url(u3k(pul));
ceq_u->hed_u = _cttp_heds_math(u3k(mah));
if ( u3_nul != bod ) {
ceq_u->bod_u = _cttp_bod_from_octs(u3k(u3t(bod)));
ceq_u->hed_u = _cttp_heds_from_noun(u3k(headers));
if ( u3_nul != body ) {
ceq_u->bod_u = _cttp_bod_from_octs(u3k(u3t(body)));
}
_cttp_creq_link(ceq_u);
u3z(unit_pul);
u3z(hes);
return ceq_u;
}
@ -621,19 +636,15 @@ _cttp_creq_fire_heds(u3_creq* ceq_u, u3_hhed* hed_u)
static void
_cttp_creq_fire(u3_creq* ceq_u)
{
switch ( ceq_u->met_m ) {
default: c3_assert(0);
case c3__get: _cttp_creq_fire_str(ceq_u, "GET "); break;
case c3__put: _cttp_creq_fire_str(ceq_u, "PUT "); break;
case c3__post: _cttp_creq_fire_str(ceq_u, "POST "); break;
case c3__head: _cttp_creq_fire_str(ceq_u, "HEAD "); break;
case c3__conn: _cttp_creq_fire_str(ceq_u, "CONNECT "); break;
case c3__delt: _cttp_creq_fire_str(ceq_u, "DELETE "); break;
case c3__opts: _cttp_creq_fire_str(ceq_u, "OPTIONS "); break;
case c3__trac: _cttp_creq_fire_str(ceq_u, "TRACE "); break;
{
c3_w len_w = strlen(ceq_u->met_c) + 1 + strlen(ceq_u->url_c) + 12;
c3_c* lin_c = c3_malloc(len_w);
len_w = snprintf(lin_c, len_w, "%s %s HTTP/1.1\r\n",
ceq_u->met_c,
ceq_u->url_c);
_cttp_creq_fire_str(ceq_u, lin_c);
}
_cttp_creq_fire_str(ceq_u, ceq_u->url_c);
_cttp_creq_fire_str(ceq_u, " HTTP/1.1\r\n");
{
c3_c* hot_c = ceq_u->hot_c ? ceq_u->hot_c : ceq_u->ipf_c;
@ -687,18 +698,23 @@ _cttp_creq_quit(u3_creq* ceq_u)
_cttp_creq_free(ceq_u);
}
/* _cttp_httr(): dispatch http response to %eyre
*/
static void
_cttp_httr(c3_l num_l, c3_w sas_w, u3_noun mes, u3_noun uct)
_cttp_http_client_receive(c3_l num_l, c3_w sas_w, u3_noun mes, u3_noun uct)
{
u3_noun htr = u3nt(sas_w, mes, uct);
u3_noun pox = u3nt(u3_blip, c3__http, u3_nul);
// TODO: We want to eventually deal with partial responses, but I don't know
// how to get that working right now.
u3_noun pox = u3nq(u3_blip, u3i_string("http-client"), u3k(u3A->sen), u3_nul);
u3_pier_plan(pox, u3nt(c3__they, num_l, htr));
u3_pier_plan(pox,
u3nt(u3i_string("receive"),
num_l,
u3nq(u3i_string("start"),
u3nc(sas_w, mes),
uct,
c3y)));
}
/* _cttp_creq_quit(): dispatch error response
/* _cttp_creq_fail(): dispatch error response
*/
static void
_cttp_creq_fail(u3_creq* ceq_u, const c3_c* err_c)
@ -709,18 +725,18 @@ _cttp_creq_fail(u3_creq* ceq_u, const c3_c* err_c)
u3l_log("http: fail (%d, %d): %s\r\n", ceq_u->num_l, cod_w, err_c);
// XX include err_c as response body?
_cttp_httr(ceq_u->num_l, cod_w, u3_nul, u3_nul);
_cttp_http_client_receive(ceq_u->num_l, cod_w, u3_nul, u3_nul);
_cttp_creq_free(ceq_u);
}
/* _cttp_creq_quit(): dispatch response
/* _cttp_creq_respond(): dispatch response
*/
static void
_cttp_creq_respond(u3_creq* ceq_u)
{
u3_cres* res_u = ceq_u->res_u;
_cttp_httr(ceq_u->num_l, res_u->sas_w, res_u->hed,
_cttp_http_client_receive(ceq_u->num_l, res_u->sas_w, res_u->hed,
( !res_u->bod_u ) ? u3_nul :
u3nc(u3_nul, _cttp_bods_to_octs(res_u->bod_u)));
@ -748,6 +764,8 @@ _cttp_creq_on_body(h2o_http1client_t* cli_u, const c3_c* err_c)
h2o_buffer_consume(&cli_u->sock->input, buf_u->size);
}
// We're using the end of stream thing here to queue event to urbit. we'll
// need to separate this into our own timer for partial progress sends.
if ( h2o_http1client_error_is_eos == err_c ) {
_cttp_creq_respond(ceq_u);
}
@ -798,7 +816,7 @@ _cttp_creq_on_connect(h2o_http1client_t* cli_u, const c3_c* err_c,
ceq_u->vec_u = _cttp_bods_to_vec(ceq_u->rub_u, &len_w);
*vec_t = len_w;
*vec_p = ceq_u->vec_u;
*hed_i = c3__head == ceq_u->met_m;
*hed_i = (0 == strcmp(ceq_u->met_c, "HEAD"));
}
return _cttp_creq_on_head;
@ -945,29 +963,47 @@ _cttp_init_h2o()
return ctx_u;
};
/* u3_cttp_ef_thus(): send %thus effect (outgoing request) to cttp.
-- zuse will have a type for this
/* u3_cttp_ef_http_client(): send an %http-client (outgoing request) to cttp.
*/
void
u3_cttp_ef_thus(c3_l num_l,
u3_noun cuq)
u3_cttp_ef_http_client(u3_noun fav)
{
u3_creq* ceq_u;
if ( u3_nul == cuq ) {
ceq_u = _cttp_creq_find(num_l);
if ( c3y == u3rz_sing(u3i_string("request"), u3k(u3h(fav))) ) {
u3_noun p_fav, q_fav;
u3x_cell(u3t(fav), &p_fav, &q_fav);
ceq_u = _cttp_creq_new(u3r_word(0, p_fav), u3k(q_fav));
if ( ceq_u ) {
_cttp_creq_start(ceq_u);
}
else {
u3l_log("cttp: strange request (unparsable url)\n");
}
}
else if ( c3y == u3rz_sing(u3i_string("cancel-request"), u3k(u3h(fav))) ) {
ceq_u =_cttp_creq_find(u3r_word(0, u3t(fav)));
if ( ceq_u ) {
_cttp_creq_quit(ceq_u);
}
}
else {
ceq_u = _cttp_creq_new(num_l, u3k(u3t(cuq)));
_cttp_creq_start(ceq_u);
u3l_log("cttp: strange request (unknown type)\n");
}
u3z(cuq);
u3z(fav);
}
/* u3_cttp_ef_bake(): notify that we're live.
*/
void
u3_cttp_ef_bake()
{
u3_noun pax = u3nq(u3_blip, u3i_string("http-client"), u3k(u3A->sen), u3_nul);
u3_pier_plan(pax, u3nc(c3__born, u3_nul));
}
/* u3_cttp_io_init(): initialize http client I/O.

View File

@ -601,7 +601,7 @@ _boothack_key(u3_noun kef)
u3_noun whu = u3dc("slaw", 'p', u3k(woh));
if ( u3_nul == whu ) {
u3l_log("dawn: invalid ship specificed with -w %s\r\n",
u3l_log("dawn: invalid ship specified with -w %s\r\n",
u3_Host.ops_u.who_c);
exit(1);
}

View File

@ -506,6 +506,30 @@ _dawn_come(u3_noun stars)
c3_c* who_c = u3r_string(who);
u3l_log("boot: found comet %s\r\n", who_c);
// enable to print and save comet private key for future reuse
//
#if 0
{
u3_noun key = u3dc("scot", c3__uw, u3qe_jam(seed));
c3_c* key_c = u3r_string(key);
u3l_log("boot: comet private key\n %s\n", key_c);
{
c3_c pat_c[64];
snprintf(pat_c, 64, "%s.key", who_c + 1);
FILE* fil_u = fopen(pat_c, "w");
fprintf(fil_u, "%s\n", key_c);
fclose(fil_u);
}
free(key_c);
u3z(key);
}
#endif
free(who_c);
u3z(who);
}

View File

@ -46,14 +46,14 @@ static const c3_i TCP_BACKLOG = 16;
static u3_weak
_http_vec_to_meth(h2o_iovec_t vec_u)
{
return ( 0 == strncmp(vec_u.base, "GET", vec_u.len) ) ? c3__get :
( 0 == strncmp(vec_u.base, "PUT", vec_u.len) ) ? c3__put :
( 0 == strncmp(vec_u.base, "POST", vec_u.len) ) ? c3__post :
( 0 == strncmp(vec_u.base, "HEAD", vec_u.len) ) ? c3__head :
( 0 == strncmp(vec_u.base, "CONNECT", vec_u.len) ) ? c3__conn :
( 0 == strncmp(vec_u.base, "DELETE", vec_u.len) ) ? c3__delt :
( 0 == strncmp(vec_u.base, "OPTIONS", vec_u.len) ) ? c3__opts :
( 0 == strncmp(vec_u.base, "TRACE", vec_u.len) ) ? c3__trac :
return ( 0 == strncmp(vec_u.base, "GET", vec_u.len) ) ? u3i_string("GET") :
( 0 == strncmp(vec_u.base, "PUT", vec_u.len) ) ? u3i_string("PUT") :
( 0 == strncmp(vec_u.base, "POST", vec_u.len) ) ? u3i_string("POST") :
( 0 == strncmp(vec_u.base, "HEAD", vec_u.len) ) ? u3i_string("HEAD") :
( 0 == strncmp(vec_u.base, "CONNECT", vec_u.len) ) ? u3i_string("CONNECT") :
( 0 == strncmp(vec_u.base, "DELETE", vec_u.len) ) ? u3i_string("DELETE") :
( 0 == strncmp(vec_u.base, "OPTIONS", vec_u.len) ) ? u3i_string("OPTIONS") :
( 0 == strncmp(vec_u.base, "TRACE", vec_u.len) ) ? u3i_string("TRACE") :
// TODO ??
// ( 0 == strncmp(vec_u.base, "PATCH", vec_u.len) ) ? c3__patc :
u3_none;
@ -81,28 +81,74 @@ _http_vec_to_octs(h2o_iovec_t vec_u)
_http_vec_to_atom(vec_u));
}
/* _http_vec_from_octs(): convert (unit octs) to h2o_iovec_t
/* _cttp_bods_free(): free body structure.
*/
static h2o_iovec_t
_http_vec_from_octs(u3_noun oct)
static void
_cttp_bods_free(u3_hbod* bod_u)
{
if ( u3_nul == oct ) {
return h2o_iovec_init(0, 0);
while ( bod_u ) {
u3_hbod* nex_u = bod_u->nex_u;
free(bod_u);
bod_u = nex_u;
}
}
/* _cttp_bod_from_octs(): translate octet-stream noun into body.
*/
static u3_hbod*
_cttp_bod_from_octs(u3_noun oct)
{
c3_w len_w;
if ( !_(u3a_is_cat(u3h(oct))) ) { // 2GB max
u3m_bail(c3__fail); return 0;
}
len_w = u3h(oct);
{
u3_hbod* bod_u = c3_malloc(1 + len_w + sizeof(*bod_u));
bod_u->hun_y[len_w] = 0;
bod_u->len_w = len_w;
u3r_bytes(0, len_w, bod_u->hun_y, u3t(oct));
bod_u->nex_u = 0;
u3z(oct);
return bod_u;
}
}
/* _cttp_bods_to_vec(): translate body buffers to array of h2o_iovec_t
*/
static h2o_iovec_t*
_cttp_bods_to_vec(u3_hbod* bod_u, c3_w* tot_w)
{
h2o_iovec_t* vec_u;
c3_w len_w;
{
u3_hbod* bid_u = bod_u;
len_w = 0;
while( bid_u ) {
len_w++;
bid_u = bid_u->nex_u;
}
}
// 2GB max
if ( c3n == u3a_is_cat(u3h(u3t(oct))) ) {
u3m_bail(c3__fail);
vec_u = c3_malloc(sizeof(h2o_iovec_t) * len_w);
len_w = 0;
while( bod_u ) {
vec_u[len_w] = h2o_iovec_init(bod_u->hun_y, bod_u->len_w);
len_w++;
bod_u = bod_u->nex_u;
}
c3_w len_w = u3h(u3t(oct));
c3_y* buf_y = c3_malloc(1 + len_w);
buf_y[len_w] = 0;
*tot_w = len_w;
u3r_bytes(0, len_w, buf_y, u3t(u3t(oct)));
u3z(oct);
return h2o_iovec_init(buf_y, len_w);
return vec_u;
}
/* _http_heds_to_noun(): convert h2o_header_t to (list (pair @t @t))
@ -244,7 +290,7 @@ _http_req_unlink(u3_hreq* req_u)
static u3_noun
_http_req_to_duct(u3_hreq* req_u)
{
return u3nt(u3_blip, c3__http,
return u3nt(u3_blip, u3i_string("http-server"),
u3nq(u3dc("scot", c3_s2('u','v'), req_u->hon_u->htp_u->sev_l),
u3dc("scot", c3_s2('u','d'), req_u->hon_u->coq_l),
u3dc("scot", c3_s2('u','d'), req_u->seq_l),
@ -257,9 +303,21 @@ static void
_http_req_kill(u3_hreq* req_u)
{
u3_noun pox = _http_req_to_duct(req_u);
u3_pier_plan(pox, u3nc(c3__thud, u3_nul));
u3_pier_plan(pox, u3nc(u3i_string("cancel-request"),
u3_nul));
}
typedef struct _u3_hgen {
h2o_generator_t neg_u; // response callbacks
c3_o red; // ready to send
c3_o dun; // done sending
u3_hbod* bod_u; // pending body
u3_hbod* nud_u; // pending free
u3_hhed* hed_u; // pending free
u3_hreq* req_u; // originating request
} u3_hgen;
/* _http_req_done(): request finished, deallocation callback
*/
static void
@ -268,7 +326,8 @@ _http_req_done(void* ptr_v)
u3_hreq* req_u = (u3_hreq*)ptr_v;
// client canceled request
if ( u3_rsat_plan == req_u->sat_e ) {
if ( (u3_rsat_plan == req_u->sat_e ) ||
(0 != req_u->gen_u && c3n == ((u3_hgen*)req_u->gen_u)->dun )) {
_http_req_kill(req_u);
}
@ -306,6 +365,7 @@ _http_req_new(u3_hcon* hon_u, h2o_req_t* rec_u)
req_u->rec_u = rec_u;
req_u->sat_e = u3_rsat_init;
req_u->tim_u = 0;
req_u->gen_u = 0;
req_u->pre_u = 0;
_http_req_link(hon_u, req_u);
@ -322,20 +382,26 @@ _http_req_dispatch(u3_hreq* req_u, u3_noun req)
req_u->sat_e = u3_rsat_plan;
u3_noun pox = _http_req_to_duct(req_u);
u3_noun typ = _(req_u->hon_u->htp_u->lop) ? c3__chis : c3__this;
u3_pier_plan(pox, u3nq(typ,
req_u->hon_u->htp_u->sec,
u3nc(c3y, u3i_words(1, &req_u->hon_u->ipf_w)),
req));
if ( c3y == req_u->hon_u->htp_u->lop ) {
u3_pier_plan(pox, u3nq(u3i_string("request-local"),
// XX automatically secure too?
//
req_u->hon_u->htp_u->sec,
u3nc(c3__ipv4,
u3i_words(1, &req_u->hon_u->ipf_w)),
req));
}
else {
u3_pier_plan(pox, u3nq(u3i_string("request"),
req_u->hon_u->htp_u->sec,
u3nc(c3__ipv4,
u3i_words(1, &req_u->hon_u->ipf_w)),
req));
}
}
typedef struct _u3_hgen {
h2o_generator_t neg_u;
h2o_iovec_t bod_u;
u3_hhed* hed_u;
} u3_hgen;
/* _http_hgen_dispose(): dispose response generator and buffers
*/
static void
@ -343,16 +409,91 @@ _http_hgen_dispose(void* ptr_v)
{
u3_hgen* gen_u = (u3_hgen*)ptr_v;
_http_heds_free(gen_u->hed_u);
free(gen_u->bod_u.base);
gen_u->hed_u = 0;
_cttp_bods_free(gen_u->nud_u);
gen_u->nud_u = 0;
_cttp_bods_free(gen_u->bod_u);
gen_u->bod_u = 0;
}
/* _http_req_respond(): write httr to h2o_req_t->res and send
static void
_http_hgen_send(u3_hgen* gen_u)
{
c3_assert( c3y == gen_u->red );
c3_assert( 0 == gen_u->nud_u );
u3_hreq* req_u = gen_u->req_u;
h2o_req_t* rec_u = req_u->rec_u;
c3_w len_w;
h2o_iovec_t* vec_u = _cttp_bods_to_vec(gen_u->bod_u, &len_w);
if ( c3n == gen_u->dun ) {
h2o_send(rec_u, vec_u, len_w, H2O_SEND_STATE_IN_PROGRESS);
// Restart the timer
uv_timer_start(req_u->tim_u, _http_req_timer_cb, 45 * 1000, 0);
}
else {
h2o_send(rec_u, vec_u, len_w, H2O_SEND_STATE_FINAL);
u3_h2o_serv* h2o_u = req_u->hon_u->htp_u->h2o_u;
if ( 0 != h2o_u->ctx_u.shutdown_requested ) {
rec_u->http1_is_persistent = 0;
}
}
// not ready again until _proceed
gen_u->red = c3n;
// stash bod_u to be free'd later
gen_u->nud_u = gen_u->bod_u;
gen_u->bod_u = 0;
free(vec_u);
}
/* _http_hgen_stop(): h2o is closing an in-progress response.
*/
static void
_http_req_respond(u3_hreq* req_u, u3_noun sas, u3_noun hed, u3_noun bod)
_http_hgen_stop(h2o_generator_t* neg_u, h2o_req_t* rec_u)
{
// XX ideally
//c3_assert(u3_rsat_plan == req_u->sat_e);
// kill request in %light
}
/* _http_hgen_proceed(): h2o is ready for more response data.
*/
static void
_http_hgen_proceed(h2o_generator_t* neg_u, h2o_req_t* rec_u)
{
u3_hgen* gen_u = (u3_hgen*)neg_u;
u3_hreq* req_u = gen_u->req_u;
// sanity check
c3_assert( rec_u == req_u->rec_u );
gen_u->red = c3y;
_http_heds_free(gen_u->hed_u);
gen_u->hed_u = 0;
_cttp_bods_free(gen_u->nud_u);
gen_u->nud_u = 0;
if ( 0 != gen_u->bod_u ) {
_http_hgen_send(gen_u);
}
}
/* _http_start_respond(): write a [%http-response %start ...] to h2o_req_t->res
*/
static void
_http_start_respond(u3_hreq* req_u,
u3_noun status,
u3_noun headers,
u3_noun data,
u3_noun complete)
{
// u3l_log("start\n");
if ( u3_rsat_plan != req_u->sat_e ) {
//u3l_log("duplicate response\n");
@ -365,19 +506,14 @@ _http_req_respond(u3_hreq* req_u, u3_noun sas, u3_noun hed, u3_noun bod)
h2o_req_t* rec_u = req_u->rec_u;
rec_u->res.status = sas;
rec_u->res.reason = (sas < 200) ? "weird" :
(sas < 300) ? "ok" :
(sas < 400) ? "moved" :
(sas < 500) ? "missing" :
rec_u->res.status = status;
rec_u->res.reason = (status < 200) ? "weird" :
(status < 300) ? "ok" :
(status < 400) ? "moved" :
(status < 500) ? "missing" :
"hosed";
u3_hhed* hed_u = _http_heds_from_noun(u3k(hed));
u3_hgen* gen_u = h2o_mem_alloc_shared(&rec_u->pool, sizeof(*gen_u),
_http_hgen_dispose);
gen_u->neg_u = (h2o_generator_t){0, 0};
gen_u->hed_u = hed_u;
u3_hhed* hed_u = _http_heds_from_noun(u3k(headers));
while ( 0 != hed_u ) {
h2o_add_header_by_str(&rec_u->pool, &rec_u->res.headers,
@ -386,21 +522,82 @@ _http_req_respond(u3_hreq* req_u, u3_noun sas, u3_noun hed, u3_noun bod)
hed_u = hed_u->nex_u;
}
gen_u->bod_u = _http_vec_from_octs(u3k(bod));
rec_u->res.content_length = gen_u->bod_u.len;
u3_hgen* gen_u = h2o_mem_alloc_shared(&rec_u->pool, sizeof(*gen_u),
_http_hgen_dispose);
gen_u->neg_u = (h2o_generator_t){ _http_hgen_proceed, _http_hgen_stop };
gen_u->red = c3y;
gen_u->dun = complete;
gen_u->bod_u = ( u3_nul == data ) ?
0 : _cttp_bod_from_octs(u3k(u3t(data)));
gen_u->nud_u = 0;
gen_u->hed_u = hed_u;
gen_u->req_u = req_u;
req_u->gen_u = gen_u;
h2o_start_response(rec_u, &gen_u->neg_u);
h2o_send(rec_u, &gen_u->bod_u, 1, H2O_SEND_STATE_FINAL);
{
u3_h2o_serv* h2o_u = req_u->hon_u->htp_u->h2o_u;
_http_hgen_send(gen_u);
if ( 0 != h2o_u->ctx_u.shutdown_requested ) {
rec_u->http1_is_persistent = 0;
u3z(status); u3z(headers); u3z(data); u3z(complete);
}
/* _http_continue_respond(): write a [%http-response %continue ...] to
* h2o_req_t->res
*/
static void
_http_continue_respond(u3_hreq* req_u,
/* u3_noun status, */
/* u3_noun headers, */
u3_noun data,
u3_noun complete)
{
// u3l_log("continue\n");
// XX add sequence numbers for %continue effects?
// Arvo does not (currently) guarantee effect idempotence!!
// response has not yet been started
if ( u3_rsat_ripe != req_u->sat_e ) {
// u3l_log("duplicate response\n");
return;
}
u3_hgen* gen_u = req_u->gen_u;
uv_timer_stop(req_u->tim_u);
// XX proposed sequence number safety check
// if ( sequence <= gen_u->sequence ) {
// return;
// }
//
// c3_assert( sequence == ++gen_u->sequence );
gen_u->dun = complete;
if ( u3_nul != data ) {
u3_hbod* bod_u = _cttp_bod_from_octs(u3k(u3t(data)));
if ( 0 == gen_u->bod_u ) {
gen_u->bod_u = bod_u;
}
else {
u3_hbod* pre_u = gen_u->bod_u;
while ( 0 != pre_u->nex_u ) {
pre_u = pre_u->nex_u;
}
pre_u->nex_u = bod_u;
}
}
u3z(sas); u3z(hed); u3z(bod);
if ( c3y == gen_u->red ) {
_http_hgen_send(gen_u);
}
u3z(data); u3z(complete);
}
/* _http_rec_to_httq(): convert h2o_req_t to httq
@ -461,7 +658,7 @@ _http_rec_accept(h2o_handler_t* han_u, h2o_req_t* rec_u)
req_u->tim_u = c3_malloc(sizeof(*req_u->tim_u));
req_u->tim_u->data = req_u;
uv_timer_init(u3L, req_u->tim_u);
uv_timer_start(req_u->tim_u, _http_req_timer_cb, 900 * 1000, 0);
uv_timer_start(req_u->tim_u, _http_req_timer_cb, 600 * 1000, 0);
_http_req_dispatch(req_u, req);
}
@ -640,6 +837,9 @@ static void
_http_serv_unlink(u3_http* htp_u)
{
// XX link elsewhere initially, relink on start?
#if 0
u3l_log("http serv unlink %d\n", htp_u->sev_l);
#endif
if ( u3_Host.htp_u == htp_u ) {
u3_Host.htp_u = htp_u->nex_u;
@ -747,6 +947,10 @@ http_serv_free_cb(uv_timer_t* tim_u)
{
u3_http* htp_u = tim_u->data;
#if 0
u3l_log("http serv free cb %d\n", htp_u->sev_l);
#endif
_http_serv_really_free(htp_u);
uv_close((uv_handle_t*)tim_u, (uv_close_cb)free);
@ -1125,7 +1329,7 @@ _http_init_tls(uv_buf_t key_u, uv_buf_t cer_u)
"RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS");
// enable ALPN for HTTP 2 support
#if H2O_USE_ALPN
#if 0 //H2O_USE_ALPN
{
SSL_CTX_set_ecdh_auto(tls_u, 1);
h2o_ssl_register_alpn_protocols(tls_u, h2o_http2_alpn_protocols);
@ -1321,18 +1525,15 @@ u3_http_ef_bake(void)
u3z(hot);
}
u3_noun pax = u3nq(u3_blip, c3__http, u3k(u3A->sen), u3_nul);
u3_noun pax = u3nq(u3_blip, u3i_string("http-server"), u3k(u3A->sen), u3_nul);
u3_pier_plan(pax, u3nc(c3__born, ipf));
}
/* u3_http_ef_thou(): send %thou from %eyre as http response.
*/
void
u3_http_ef_thou(c3_l sev_l,
c3_l coq_l,
c3_l seq_l,
u3_noun rep)
static u3_hreq*
_http_search_req(c3_l sev_l,
c3_l coq_l,
c3_l seq_l)
{
u3_http* htp_u;
u3_hcon* hon_u;
@ -1343,30 +1544,81 @@ u3_http_ef_thou(c3_l sev_l,
if ( bug_w ) {
u3l_log("http: server not found: %x\r\n", sev_l);
}
return 0;
}
else if ( !(hon_u = _http_conn_find(htp_u, coq_l)) ) {
if ( bug_w ) {
u3l_log("http: connection not found: %x/%d\r\n", sev_l, coq_l);
}
return 0;
}
else if ( !(req_u = _http_req_find(hon_u, seq_l)) ) {
if ( bug_w ) {
u3l_log("http: request not found: %x/%d/%d\r\n",
sev_l, coq_l, seq_l);
}
return 0;
}
else {
u3_noun p_rep, q_rep, r_rep;
if ( c3n == u3r_trel(rep, &p_rep, &q_rep, &r_rep) ) {
u3l_log("http: strange response\n");
return req_u;
}
/* u3_http_ef_http_server(): dispatch an %http-server effect from %light.
*/
void
u3_http_ef_http_server(c3_l sev_l,
c3_l coq_l,
c3_l seq_l,
u3_noun cad)
{
u3_hreq* req_u;
u3_noun tag, dat;
u3x_cell(cad, &tag, &dat);
// sets server configuration
//
if ( c3y == u3rz_sing(u3i_string("set-config"), u3k(tag)) ) {
u3_http_ef_form(u3k(dat));
}
// responds to an open request
//
else if ( 0 != (req_u = _http_search_req(sev_l, coq_l, seq_l)) ) {
if ( c3y == u3rz_sing(u3i_string("response"), u3k(tag)) ) {
u3_noun response = dat;
if ( c3y == u3rz_sing(u3i_string("start"), u3k(u3h(response))) ) {
// Separate the %start message into its components.
//
u3_noun response_header, data, complete;
u3_noun status, headers;
u3x_trel(u3t(response), &response_header, &data, &complete);
u3x_cell(response_header, &status, &headers);
_http_start_respond(req_u, u3k(status), u3k(headers), u3k(data),
u3k(complete));
}
else if ( c3y == u3rz_sing(u3i_string("continue"), u3k(u3h(response))) ) {
// Separate the %continue message into its components.
//
u3_noun data, complete;
u3x_cell(u3t(response), &data, &complete);
_http_continue_respond(req_u, u3k(data), u3k(complete));
}
else if (c3y == u3rz_sing(u3i_string("cancel"), u3k(u3h(response)))) {
u3l_log("http: %%cancel not handled yet\n");
}
else {
u3l_log("http: strange response\n");
}
}
else {
_http_req_respond(req_u, u3k(p_rep), u3k(q_rep), u3k(r_rep));
u3l_log("http: strange response\n");
}
}
u3z(rep);
u3z(cad);
}
/* _http_serv_start_all(): initialize and start servers based on saved config.
@ -1436,7 +1688,10 @@ _http_serv_start_all(void)
{
c3_assert( u3_none != non );
u3_noun pax = u3nq(u3_blip, c3__http, u3k(u3A->sen), u3_nul);
u3_noun pax = u3nq(u3_blip,
u3i_string("http-server"),
u3k(u3A->sen),
u3_nul);
u3_pier_plan(pax, u3nt(c3__live, non, sec));
}
@ -1535,6 +1790,18 @@ u3_http_ef_form(u3_noun fig)
u3_Host.fig_u.for_u = for_u;
_http_serv_restart();
// The control server has now started.
//
// If we're in daemon mode, we need to inform the parent process
// that we've finished booting.
//
// XX using this effect is a terrible heuristic;
// "fully booted" should be formalized.
//
if (u3_Host.bot_f) {
u3_Host.bot_f();
}
}
/* u3_http_io_init(): initialize http I/O.
@ -2285,7 +2552,7 @@ _proxy_ward_timer_cb(uv_timer_t* tim_u)
static void
_proxy_ward_plan(u3_ward* rev_u)
{
u3_noun non;
u3_noun non, cad;
{
c3_w* non_w = c3_malloc(64);
@ -2302,15 +2569,19 @@ _proxy_ward_plan(u3_ward* rev_u)
rev_u->non_u = uv_buf_init((c3_c*)non_w, len_w);
}
// XX confirm duct
u3_noun pax = u3nq(u3_blip, c3__http, c3__prox,
u3nc(u3k(u3A->sen), u3_nul));
{
u3_noun who = u3i_chubs(2, rev_u->who_d);
u3_noun cha = u3nq(c3__a, c3__give, c3__prox, u3_nul);
u3_noun dat = u3nc(c3__that, u3nt(rev_u->por_s,
u3k(rev_u->con_u->sec),
non));
u3_noun wis = u3nc(c3__wise, u3nq(u3i_chubs(2, rev_u->who_d),
rev_u->por_s,
u3k(rev_u->con_u->sec),
non));
u3_pier_plan(pax, wis);
cad = u3nq(c3__want, who, cha, dat);
}
// XX s/b c3__ames?
//
u3_pier_plan(u3nt(u3_blip, c3__newt, u3_nul), cad);
}
/* _proxy_ward_start(): start ward (ship-specific listener).
@ -2359,7 +2630,7 @@ _proxy_ward_start(u3_pcon* con_u, u3_noun sip)
// XX how long?
//
uv_timer_init(u3L, &rev_u->tim_u);
uv_timer_start(&rev_u->tim_u, _proxy_ward_timer_cb, 300 * 1000, 0);
uv_timer_start(&rev_u->tim_u, _proxy_ward_timer_cb, 600 * 1000, 0);
}
u3z(sip);
@ -2860,18 +3131,19 @@ _proxy_serv_start(u3_prox* lis_u)
/* u3_http_ef_that(): reverse proxy requested connection notification.
*/
void
u3_http_ef_that(u3_noun tat)
u3_http_ef_that(u3_noun sip, u3_noun tat)
{
u3_noun sip, por, sec, non;
u3_noun por, sec, non;
if ( ( c3n == u3r_qual(tat, &sip, &por, &sec, &non) ) ||
( c3n == u3ud(sip) ) ||
( c3n == u3a_is_cat(por) ) ||
!( c3y == sec || c3n == sec ) ||
( c3n == u3ud(non) ) ) {
u3l_log("http: that: invalid card\n");
}
else {
u3x_trel(tat, &por, &sec, &non);
c3_assert( c3y == u3a_is_cat(por) );
c3_assert( c3y == sec || c3n == sec );
c3_assert( c3y == u3ud(non) );
// XX sip s/b validated -- could be *any* ship
//
{
u3_http* htp_u;
u3_warc* cli_u;
@ -2904,5 +3176,6 @@ u3_http_ef_that(u3_noun tat)
}
}
u3z(sip);
u3z(tat);
}

View File

@ -79,10 +79,10 @@ _pier_db_bail(void* vod_p, const c3_c* err_c)
u3l_log("disk error: %s\r\n", err_c);
}
/* _pier_db_shutdown(): close the log.
/* u3_pier_db_shutdown(): close the log.
*/
static void
_pier_db_shutdown(u3_pier* pir_u)
void
u3_pier_db_shutdown(u3_pier* pir_u)
{
u3_lmdb_shutdown(pir_u->log_u->db_u);
}
@ -508,7 +508,7 @@ _pier_work_boot(u3_pier* pir_u, c3_o sav_o)
u3_noun len = u3i_chubs(1, &pir_u->lif_d);
if ( c3y == sav_o ) {
_pier_db_write_header(pir_u, who, u3k(pir_u->fak_o), len);
_pier_db_write_header(pir_u, u3k(who), pir_u->fak_o, u3k(len));
}
u3_noun msg = u3nq(c3__boot, who, pir_u->fak_o, len);
@ -844,7 +844,7 @@ _pier_work_exit(uv_process_t* req_u,
u3l_log("pier: exit: status %" PRIu64 ", signal %d\r\n", sas_i, sig_i);
uv_close((uv_handle_t*) req_u, 0);
_pier_db_shutdown(pir_u);
u3_pier_db_shutdown(pir_u);
_pier_work_shutdown(pir_u);
}
@ -1218,6 +1218,7 @@ _pier_loop_wake(u3_pier* pir_u)
cod_l = u3a_lush(c3__http);
u3_http_io_talk();
u3_http_ef_bake();
u3_cttp_ef_bake();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__term);
@ -1787,7 +1788,7 @@ _pier_exit_done(u3_pier* pir_u)
{
u3l_log("pier: exit\r\n");
_pier_db_shutdown(pir_u);
u3_pier_db_shutdown(pir_u);
_pier_work_shutdown(pir_u);
_pier_loop_exit(pir_u);

View File

@ -142,66 +142,6 @@ _reck_kick_term(u3_pier* pir_u, u3_noun pox, c3_l tid_l, u3_noun fav)
c3_assert(!"not reached"); return 0;
}
/* _reck_kick_http(): apply http effects.
*/
static u3_noun
_reck_kick_http(u3_pier* pir_u,
u3_noun pox,
c3_l sev_l,
c3_l coq_l,
c3_l seq_l,
u3_noun fav)
{
u3_noun p_fav, q_fav;
if ( c3n == u3du(fav) ) {
u3z(pox); u3z(fav); return c3n;
}
else switch ( u3h(fav) ) {
default: u3z(pox); u3z(fav); return c3n;
case c3__form: p_fav = u3t(fav);
{
u3_http_ef_form(u3k(p_fav));
// The control server has now started.
//
// If we're in daemon mode, we need to inform the parent process
// that we've finished booting.
if (u3_Host.bot_f) {
u3_Host.bot_f();
}
u3z(pox); u3z(fav);
return c3y;
}
case c3__that: p_fav = u3t(fav);
{
u3_http_ef_that(u3k(p_fav));
u3z(pox); u3z(fav);
return c3y;
}
case c3__thus: p_fav = u3h(u3t(fav)); q_fav = u3t(u3t(fav));
{
u3_cttp_ef_thus(u3r_word(0, p_fav), u3k(q_fav));
u3z(pox); u3z(fav);
return c3y;
}
case c3__thou: p_fav = u3t(fav);
{
u3_http_ef_thou(sev_l, coq_l, seq_l, u3k(p_fav));
u3z(pox); u3z(fav);
return c3y;
} break;
}
c3_assert(!"not reached"); return c3n;
}
/* _reck_kick_behn(): apply packet network outputs.
*/
static u3_noun
@ -258,6 +198,7 @@ _reck_kick_newt(u3_pier* pir_u, u3_noun pox, u3_noun fav)
{
switch ( u3h(fav) ) {
default: break;
case c3__send: {
u3_noun lan = u3k(u3h(u3t(fav)));
u3_noun pac = u3k(u3t(u3t(fav)));
@ -291,7 +232,31 @@ _reck_kick_ames(u3_pier* pir_u, u3_noun pox, u3_noun fav)
// u3l_log("kick: init: %d\n", p_fav);
u3z(pox); u3z(fav); return c3y;
} break;
case c3__west: {
u3_noun who, cha, dat;
u3x_trel(u3t(fav), &who, &cha, &dat);
// XX route by cha path?
// s/b //give/prox
//
switch ( u3h(dat) ) {
default: break;
case c3__that: {
u3_http_ef_that(u3k(who), u3k(u3t(dat)));
u3z(pox); u3z(fav); return c3y;
}
}
}
case c3__woot: {
// XX print tang if nack?
//
u3z(pox); u3z(fav); return c3y;
}
}
u3z(pox); u3z(fav); return c3n;
}
@ -315,43 +280,51 @@ _reck_kick_spec(u3_pier* pir_u, u3_noun pox, u3_noun fav)
if ( (c3n == u3r_cell(t_pox, &it_pox, &tt_pox)) ) {
u3z(pox); u3z(fav); return c3n;
}
else switch ( it_pox ) {
default: u3z(pox); u3z(fav); return c3n;
else if ( c3y == u3rz_sing(u3i_string("http-server"), u3k(it_pox)) ) {
u3_noun pud = tt_pox;
u3_noun p_pud, t_pud, tt_pud, q_pud, r_pud, s_pud;
c3_l sev_l, coq_l, seq_l;
case c3__http: {
u3_noun pud = tt_pox;
u3_noun p_pud, t_pud, tt_pud, q_pud, r_pud, s_pud;
c3_l sev_l, coq_l, seq_l;
if ( (c3n == u3r_cell(pud, &p_pud, &t_pud)) ||
(c3n == _reck_lily(c3__uv, u3k(p_pud), &sev_l)) )
{
u3z(pox); u3z(fav); return c3n;
}
if ( (c3n == u3r_cell(pud, &p_pud, &t_pud)) ||
(c3n == _reck_lily(c3__uv, u3k(p_pud), &sev_l)) )
if ( u3_nul == t_pud ) {
coq_l = seq_l = 0;
}
else {
if ( (c3n == u3r_cell(t_pud, &q_pud, &tt_pud)) ||
(c3n == _reck_lily(c3__ud, u3k(q_pud), &coq_l)) )
{
u3z(pox); u3z(fav); return c3n;
}
if ( u3_nul == t_pud ) {
coq_l = seq_l = 0;
}
else {
if ( (c3n == u3r_cell(t_pud, &q_pud, &tt_pud)) ||
(c3n == _reck_lily(c3__ud, u3k(q_pud), &coq_l)) )
if ( u3_nul == tt_pud ) {
seq_l = 0;
} else {
if ( (c3n == u3r_cell(tt_pud, &r_pud, &s_pud)) ||
(u3_nul != s_pud) ||
(c3n == _reck_lily(c3__ud, u3k(r_pud), &seq_l)) )
{
u3z(pox); u3z(fav); return c3n;
}
if ( u3_nul == tt_pud ) {
seq_l = 0;
} else {
if ( (c3n == u3r_cell(tt_pud, &r_pud, &s_pud)) ||
(u3_nul != s_pud) ||
(c3n == _reck_lily(c3__ud, u3k(r_pud), &seq_l)) )
{
u3z(pox); u3z(fav); return c3n;
}
}
}
return _reck_kick_http(pir_u, pox, sev_l, coq_l, seq_l, fav);
} break;
}
u3_http_ef_http_server(sev_l, coq_l, seq_l, u3k(fav));
u3z(pox); u3z(fav);
return c3y;
}
else if ( c3y == u3rz_sing(u3i_string("http-client"), u3k(it_pox)) ) {
u3_cttp_ef_http_client(u3k(fav));
u3z(pox); u3z(fav);
return c3y;
}
else switch ( it_pox ) {
default: u3z(pox); u3z(fav); return c3n;
case c3__behn: {
return _reck_kick_behn(pir_u, pox, fav);