Merge branch 'master' into hashboard

This commit is contained in:
Paul Driver 2018-06-04 14:15:53 -07:00
commit da051310df
14 changed files with 244 additions and 151 deletions

View File

@ -56,7 +56,7 @@ are included as git submodules. To build urbit from source, perform the followin
To configure project, enter the build directory and enter
`meson configure`. Without any arguments this command will display available
options. For example, to compile debug build of urbit, use
`meson configure -Ddebug=true`.
`meson configure -Dbuildtype=debug`.
To set the prefix for installation use
`meson configure -Dprefix=/usr`, and so on.

View File

@ -36,11 +36,20 @@
c3_y hun_y[0];
} u3_hbod;
/* u3_rsat: http request state.
*/
typedef enum {
u3_rsat_init = 0, // initialized
u3_rsat_plan = 1, // planned
u3_rsat_ripe = 2 // responded
} u3_rsat;
/* u3_hreq: incoming http request.
*/
typedef struct _u3_hreq {
h2o_req_t* rec_u; // h2o request
c3_w seq_l; // sequence within connection
u3_rsat sat_e; // request state
struct _u3_hcon* hon_u; // connection backlink
struct _u3_hreq* nex_u; // next in connection's list
} u3_hreq;

View File

@ -306,17 +306,10 @@ softfloat3_dep = dependency('softfloat3', version: '>=3.0.0', fallback: ['softfl
libuv_dep = dependency('libuv', version: '>=1.8.0', fallback:['libuv', 'libuv_dep'])
libh2o_dep = dependency('libh2o', version: '>=0.13.3', fallback: ['libh2o', 'libh2o_dep'])
opt_flags = []
if get_option('debug')
opt_flags = ['-g']
else
opt_flags = ['-O3']
endif
executable('urbit',
sources : sources,
include_directories : incdir,
c_args : opt_flags + os_c_flags,
c_args : os_c_flags,
link_args: os_link_flags,
dependencies: [openssl_dep,
curl_dep,

View File

@ -1 +0,0 @@
option('debug', type:'boolean', value: false)

View File

@ -370,15 +370,12 @@ u3a_reflux(void)
void
u3a_reclaim(void)
{
c3_w old_w;
if ( (0 == u3R->cax.har_p) ||
(0 == u3to(u3h_root, u3R->cax.har_p)->use_w) )
{
fprintf(stderr, "allocate: reclaim: memo cache: empty\r\n");
u3m_bail(c3__meme);
}
old_w = u3a_open(u3R) + u3R->all.fre_w;
#if 1
fprintf(stderr, "allocate: reclaim: half of %d entries\r\n",

View File

@ -1,5 +1,5 @@
#!/bin/bash
mkdir ./build &> /dev/null
meson . ./build
meson . ./build -Dbuildtype=release
ninja -C build

@ -1 +1 @@
Subproject commit 84731d522f43bad833ef9e66a7004017447889f1
Subproject commit fc17dd0778083a484c60bf9b27ecbf6bcfcd759a

@ -1 +1 @@
Subproject commit fcf8df4af0c31477e05c55c380c4d7324311368d
Subproject commit 9698340d8d0a3f02a96867b2d02623f05e517156

@ -1 +1 @@
Subproject commit 984fec910a9df81bc645edea3002440c0ddd9b36
Subproject commit 15a52c10ae665ee6e1e3cd275bc292a343fb3394

@ -1 +1 @@
Subproject commit a599f229a794d4d20ce96c073c5bd24fd51908c5
Subproject commit 9e3aece8147d28246c57b84731dad26130c7d1c1

@ -1 +1 @@
Subproject commit 467680fc088268207e9049bb3caf243bd5f2bc03
Subproject commit 4d9f3d1f29b88661aec70179dd405773f3515249

@ -1 +1 @@
Subproject commit ba248daf121925c62207011115f3bd7e7eb9bd80
Subproject commit 9d4342099a54cefc3a4117ce0d0c71cff4e48783

View File

@ -22,6 +22,18 @@
#include "all.h"
#include "vere/vere.h"
/* u3_pact: ames packet struct.
*/
typedef struct {
uv_udp_send_t snd_u;
c3_y* buf_y;
c3_w len_w;
c3_s por_s;
c3_w pip_w;
c3_y imp_y;
c3_c* dns_c;
} u3_pact;
/* _ames_alloc(): libuv buffer allocator.
*/
static void
@ -43,90 +55,200 @@ _ames_free(void* ptr_v)
free(ptr_v);
}
/* _ames_czar(): quasi-static route to emperor.
/* _ames_pact_free(): free packet struct.
*/
static c3_w
_ames_czar(c3_y imp_y, c3_s* por_s, c3_c* bos_c)
static void
_ames_pact_free(u3_pact* pac_u)
{
free(pac_u->buf_y);
free(pac_u->dns_c);
free(pac_u);
}
/* _ames_send_cb(): send callback.
*/
static void
_ames_send_cb(uv_udp_send_t* req_u, c3_i sas_i)
{
u3_pact* pac_u = (u3_pact*)req_u;
#if 0
if ( 0 != sas_i ) {
uL(fprintf(uH, "ames: send_cb: %s\n", uv_strerror(sas_i)));
}
#endif
_ames_pact_free(pac_u);
}
/* _ames_send(): send buffer to address on port.
*/
static void
_ames_send(u3_pact* pac_u)
{
u3_ames* sam_u = &u3_Host.sam_u;
if ( !pac_u->buf_y ) {
_ames_pact_free(pac_u);
return;
}
struct sockaddr_in add_u;
memset(&add_u, 0, sizeof(add_u));
add_u.sin_family = AF_INET;
add_u.sin_addr.s_addr = htonl(pac_u->pip_w);
add_u.sin_port = htons(pac_u->por_s);
uv_buf_t buf_u = uv_buf_init((c3_c*)pac_u->buf_y, pac_u->len_w);
c3_i sas_i;
if ( 0 != (sas_i = uv_udp_send(&pac_u->snd_u,
&sam_u->wax_u,
&buf_u, 1,
(const struct sockaddr*)&add_u,
_ames_send_cb)) ) {
uL(fprintf(uH, "ames: send: %s\n", uv_strerror(sas_i)));
}
}
/* _ames_czar_port(): udp port for galaxy.
*/
static c3_s
_ames_czar_port(c3_y imp_y)
{
if ( c3n == u3_Host.ops_u.net ) {
*por_s = 31337 + imp_y;
return 0x7f000001;
return 31337 + imp_y;
}
else {
time_t now = time(0);
*por_s = 13337 + imp_y;
return 13337 + imp_y;
}
}
if ( 0xffffffff == sam_u->imp_w[imp_y]
&& (now - sam_u -> imp_t[imp_y]) < 300 ) {
return 0;
/* _ames_czar_gone(): galaxy address resolution failed.
*/
static void
_ames_czar_gone(u3_pact* pac_u, time_t now)
{
u3_ames* sam_u = &u3_Host.sam_u;
uL(fprintf(uH, "ames: czar at %s: not found (b)\n", pac_u->dns_c));
if ( (0 == sam_u->imp_w[pac_u->imp_y]) ||
(0xffffffff == sam_u->imp_w[pac_u->imp_y]) ) {
sam_u->imp_w[pac_u->imp_y] = 0xffffffff;
} /* else keep existing ip for 5 more minutes */
sam_u->imp_t[pac_u->imp_y] = now;
_ames_pact_free(pac_u);
}
/* _ames_czar_cb(): galaxy address resolution callback.
*/
static void
_ames_czar_cb(uv_getaddrinfo_t* adr_u,
c3_i sas_i,
struct addrinfo* aif_u)
{
u3_ames* sam_u = &u3_Host.sam_u;
u3_pact* pac_u = (u3_pact*)adr_u->data;
time_t now = time(0);
struct addrinfo* rai_u = aif_u;
while ( 1 ) {
if ( !rai_u ) {
_ames_czar_gone(pac_u, now);
break;
}
else if ( 0 == sam_u->imp_w[imp_y]
|| (now - sam_u->imp_t[imp_y]) > 300 ) { /* 5 minute TTL */
u3_noun nam = u3dc("scot", 'p', imp_y);
c3_c* nam_c = u3r_string(nam);
c3_c dns_c[256];
snprintf(dns_c, 256, "%s.%s", nam_c + 1, bos_c);
// uL(fprintf(uH, "czar %s, dns %s\n", nam_c, dns_c));
if ( (AF_INET == rai_u->ai_family) ) {
struct sockaddr_in* add_u = (struct sockaddr_in *)rai_u->ai_addr;
c3_w old_w = sam_u->imp_w[pac_u->imp_y];
free(nam_c);
u3z(nam);
sam_u->imp_w[pac_u->imp_y] = ntohl(add_u->sin_addr.s_addr);
sam_u->imp_t[pac_u->imp_y] = now;
{
struct addrinfo* air_u;
if ( 0 != getaddrinfo(dns_c, 0, 0, &air_u) ) {
uL(fprintf(uH, "ames: czar at %s: not found (a)\n", dns_c));
if ( sam_u->imp_w[imp_y] == 0
|| sam_u->imp_w[imp_y] == 0xffffffff ) {
sam_u->imp_w[imp_y] = 0xffffffff;
} /* else keep existing ip for 5 more minutes */
sam_u->imp_t[imp_y] = now;
return 0;
}
{
struct addrinfo* rai_u = air_u;
while ( 1 ) {
if ( !rai_u ) {
uL(fprintf(uH, "ames: czar at %s: not found (b)\n", dns_c));
if ( sam_u->imp_w[imp_y] == 0
|| sam_u->imp_w[imp_y] == 0xffffffff ) {
sam_u->imp_w[imp_y] = 0xffffffff;
} /* else keep existing ip for 5 more minutes */
sam_u->imp_t[imp_y] = now;
return 0;
}
if ( (AF_INET == rai_u->ai_family) ) {
struct sockaddr_in* add_u = (struct sockaddr_in *)rai_u->ai_addr;
c3_w old_w = sam_u->imp_w[imp_y];
sam_u->imp_w[imp_y] = ntohl(add_u->sin_addr.s_addr);
sam_u->imp_t[imp_y] = now;
#if 1
if ( sam_u->imp_w[imp_y] != old_w
&& sam_u->imp_w[imp_y] != 0xffffffff ) {
u3_noun wad = u3i_words(1, &sam_u->imp_w[imp_y]);
u3_noun nam = u3dc("scot", c3__if, wad);
c3_c* nam_c = u3r_string(nam);
if ( sam_u->imp_w[pac_u->imp_y] != old_w
&& sam_u->imp_w[pac_u->imp_y] != 0xffffffff ) {
u3_noun wad = u3i_words(1, &sam_u->imp_w[pac_u->imp_y]);
u3_noun nam = u3dc("scot", c3__if, wad);
c3_c* nam_c = u3r_string(nam);
uL(fprintf(uH, "ames: czar %s: ip %s\n", dns_c, nam_c));
uL(fprintf(uH, "ames: czar %s: ip %s\n", pac_u->dns_c, nam_c));
free(nam_c); u3z(nam);
}
free(nam_c); u3z(nam);
}
#endif
break;
}
rai_u = rai_u->ai_next;
}
}
freeaddrinfo(air_u);
_ames_send(pac_u);
break;
}
rai_u = rai_u->ai_next;
}
free(adr_u);
uv_freeaddrinfo(aif_u);
}
/* _ames_czar(): galaxy address resolution.
*/
static void
_ames_czar(u3_pact* pac_u, c3_c* bos_c)
{
u3_ames* sam_u = &u3_Host.sam_u;
pac_u->por_s = _ames_czar_port(pac_u->imp_y);
if ( c3n == u3_Host.ops_u.net ) {
pac_u->pip_w = 0x7f000001;
_ames_send(pac_u);
return;
}
time_t now = time(0);
// backoff
if ( (0xffffffff == sam_u->imp_w[pac_u->imp_y]) &&
(now - sam_u->imp_t[pac_u->imp_y]) < 300 ) {
_ames_pact_free(pac_u);
return;
}
if ( (0 == sam_u->imp_w[pac_u->imp_y]) ||
(now - sam_u->imp_t[pac_u->imp_y]) > 300 ) { /* 5 minute TTL */
u3_noun nam = u3dc("scot", 'p', pac_u->imp_y);
c3_c* nam_c = u3r_string(nam);
pac_u->dns_c = c3_malloc(1 + strlen(bos_c) + 1 + strlen(nam_c));
snprintf(pac_u->dns_c, 256, "%s.%s", nam_c + 1, bos_c);
// uL(fprintf(uH, "czar %s, dns %s\n", nam_c, pac_u->dns_c));
free(nam_c);
u3z(nam);
{
uv_getaddrinfo_t* adr_u = c3_malloc(sizeof(*adr_u));
adr_u->data = pac_u;
c3_i sas_i;
if ( 0 != (sas_i = uv_getaddrinfo(u3L, adr_u,
_ames_czar_cb,
pac_u->dns_c, 0, 0)) ) {
uL(fprintf(uH, "ames: %s\n", uv_strerror(sas_i)));
_ames_czar_gone(pac_u, now);
return;
}
}
return sam_u->imp_w[imp_y];
}
else {
pac_u->pip_w = sam_u->imp_w[pac_u->imp_y];
_ames_send(pac_u);
return;
}
}
@ -158,30 +280,6 @@ _ames_lane_ip(u3_noun lan, c3_s* por_s, c3_w* pip_w)
return c3n;
}
/* An unusual lameness in libuv.
*/
typedef struct {
uv_udp_send_t snd_u;
c3_y* buf_y;
} _u3_udp_send_t;
/* _ames_send_cb(): send callback.
*/
static void
_ames_send_cb(uv_udp_send_t* req_u, c3_i sas_i)
{
_u3_udp_send_t* ruq_u = (void*)req_u;
#if 0
if ( 0 != sas_i ) {
uL(fprintf(uH, "ames: send_cb: %s\n", uv_strerror(uv_last_error(u3L))));
}
#endif
// fprintf(stderr, "ames: tx\r\n");
free(ruq_u->buf_y);
free(ruq_u);
}
void
u3_ames_ef_bake(void)
{
@ -195,58 +293,41 @@ u3_ames_ef_bake(void)
void
u3_ames_ef_send(u3_noun lan, u3_noun pac)
{
u3_ames* sam_u = &u3_Host.sam_u;
c3_s por_s;
c3_w pip_w;
if ( u3_Host.ops_u.fuz_w && ((rand() % 100) < u3_Host.ops_u.fuz_w) ) {
u3z(lan); u3z(pac);
return;
}
if ( c3y == _ames_lane_ip(lan, &por_s, &pip_w) ) {
c3_w len_w = u3r_met(3, pac);
c3_y* buf_y = c3_malloc(len_w);
u3_pact* pac_u = c3_calloc(sizeof(*pac_u));
u3r_bytes(0, len_w, buf_y, pac);
if ( c3y == _ames_lane_ip(lan, &pac_u->por_s, &pac_u->pip_w) ) {
pac_u->len_w = u3r_met(3, pac);
pac_u->buf_y = c3_malloc(pac_u->len_w);
if ( 0 == pip_w ) {
pip_w = 0x7f000001;
por_s = u3_Host.sam_u.por_s;
u3r_bytes(0, pac_u->len_w, pac_u->buf_y, pac);
if ( 0 == pac_u->pip_w ) {
pac_u->pip_w = 0x7f000001;
pac_u->por_s = u3_Host.sam_u.por_s;
}
{
struct sockaddr_in add_u;
if ( (0 == (pip_w >> 16)) && (1 == (pip_w >> 8)) ) {
c3_y imp_y = (pip_w & 0xff);
if ( (0 == (pac_u->pip_w >> 16)) && (1 == (pac_u->pip_w >> 8)) ) {
pac_u->imp_y = (pac_u->pip_w & 0xff);
pip_w = _ames_czar(imp_y, &por_s, u3_Host.ops_u.dns_c);
}
if ( (0 != pip_w) &&
( (c3y == u3_Host.ops_u.net) || (0x7f000001 == pip_w) ) ) {
uv_buf_t buf_u = uv_buf_init((c3_c*)buf_y, len_w);
_u3_udp_send_t* ruq_u = c3_malloc(sizeof(_u3_udp_send_t));
ruq_u->buf_y = buf_y;
memset(&add_u, 0, sizeof(add_u));
add_u.sin_family = AF_INET;
add_u.sin_addr.s_addr = htonl(pip_w);
add_u.sin_port = htons(por_s);
int ret;
if ( 0 != (ret = uv_udp_send(&ruq_u->snd_u,
&sam_u->wax_u,
&buf_u, 1,
(const struct sockaddr*) & add_u, // IS THIS RIGHT ?!?!?
_ames_send_cb)) ) {
uL(fprintf(uH, "ames: send: %s\n", uv_strerror(ret)));
}
// fprintf(stderr, "ames: send\r\n");
}
_ames_czar(pac_u, u3_Host.ops_u.dns_c);
}
else if ( (c3y == u3_Host.ops_u.net) || (0x7f000001 == pac_u->pip_w) ) {
_ames_send(pac_u);
}
else {
// networking disabled
_ames_pact_free(pac_u);
}
}
else {
_ames_pact_free(pac_u);
}
u3z(lan); u3z(pac);
}
@ -325,8 +406,8 @@ u3_ames_io_init()
exit(1);
}
num_y = u3r_byte(0, u3t(num));
por_s = _ames_czar_port(num_y);
_ames_czar(num_y, &por_s, u3_Host.ops_u.dns_c);
if ( c3y == u3_Host.ops_u.net ) {
uL(fprintf(uH, "ames: czar: %s on %d\n", u3_Host.ops_u.imp_c, por_s));
}

View File

@ -232,6 +232,7 @@ _http_req_new(u3_hcon* hon_u, h2o_req_t* rec_u)
{
u3_hreq* req_u = c3_malloc(sizeof(*req_u));
req_u->rec_u = rec_u;
req_u->sat_e = u3_rsat_init;
_http_req_link(hon_u, req_u);
return req_u;
@ -263,6 +264,9 @@ _http_req_kill(u3_hreq* req_u)
static void
_http_req_dispatch(u3_hreq* req_u, u3_noun req)
{
c3_assert(u3_rsat_init == req_u->sat_e);
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;
@ -295,6 +299,16 @@ _http_hgen_dispose(void* ptr_v)
static void
_http_req_respond(u3_hreq* req_u, u3_noun sas, u3_noun hed, u3_noun bod)
{
// XX ideally
//c3_assert(u3_rsat_plan == req_u->sat_e);
if ( u3_rsat_plan != req_u->sat_e ) {
//uL(fprintf(uH, "duplicate response\n"));
return;
}
req_u->sat_e = u3_rsat_ripe;
h2o_req_t* rec_u = req_u->rec_u;
rec_u->res.status = sas;