From 0f805358673a09a36fbbf9cbf2086e90376312db Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 7 Jun 2018 22:54:57 -0400 Subject: [PATCH 1/7] removes orphaned telnet constants and forward declarations --- vere/term.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/vere/term.c b/vere/term.c index e69bf42aaf..c6409d5a72 100644 --- a/vere/term.c +++ b/vere/term.c @@ -21,19 +21,11 @@ #include "vere/vere.h" static void _term_spinner_cb(void*); -static void _term_read_tn_cb(uv_stream_t* tcp_u, - ssize_t siz_i, - const uv_buf_t * buf_u); static void _term_read_cb(uv_stream_t* tcp_u, ssize_t siz_i, const uv_buf_t * buf_u); static inline void _term_suck(u3_utty*, const c3_y*, ssize_t); - -#define _T_ECHO 1 // local echo -#define _T_CTIM 3 // suppress GA/char-at-a-time -#define _T_NAWS 31 // negotiate about window size - #define _SPIN_COOL_US 500000 // spinner activation delay when cool #define _SPIN_WARM_US 50000 // spinner activation delay when warm #define _SPIN_RATE_US 250000 // spinner rate (microseconds/frame) From 59a049b170c8cc41cd6ba614c7bf644534120d19 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 1 Jun 2018 21:02:54 -0400 Subject: [PATCH 2/7] removes tabs from http.c --- vere/http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vere/http.c b/vere/http.c index 0906f732f8..f41b98454d 100644 --- a/vere/http.c +++ b/vere/http.c @@ -792,7 +792,7 @@ u3_http_ef_thou(c3_l sev_l, else if ( !(req_u = _http_req_find(hon_u, seq_l)) ) { if ( bug_w ) { uL(fprintf(uH, "http: request not found: %x/%d/%d\r\n", - sev_l, coq_l, seq_l)); + sev_l, coq_l, seq_l)); } } else { From 78a0d7732fa19e555c51fba44051463e900ffd4b Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 18 Jun 2018 13:50:26 -0400 Subject: [PATCH 3/7] print error on failed syscall in _ce_patch_create() --- noun/events.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/noun/events.c b/noun/events.c index fa606b1d8a..002ba96160 100644 --- a/noun/events.c +++ b/noun/events.c @@ -276,11 +276,13 @@ _ce_patch_create(u3_ce_patch* pat_u) snprintf(ful_c, 8192, "%s/.urb/chk/control.bin", u3P.dir_c); if ( -1 == (pat_u->ctl_i = open(ful_c, O_RDWR | O_CREAT | O_EXCL, 0666)) ) { + perror(ful_c); c3_assert(0); } snprintf(ful_c, 8192, "%s/.urb/chk/memory.bin", u3P.dir_c); if ( -1 == (pat_u->mem_i = open(ful_c, O_RDWR | O_CREAT | O_EXCL, 0666)) ) { + perror(ful_c); c3_assert(0); } } From fbbe815996f00068ba4ac49a175d5c877d425ea2 Mon Sep 17 00:00:00 2001 From: Fang Date: Tue, 10 Jul 2018 02:07:34 +0200 Subject: [PATCH 4/7] Remove deprecated paths from gitignore We're no longer putting the binary into `/bin` (now into `/build` instead), so we don't need to ignore it anymore. --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index f2d1c81370..d5a38529c6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,6 @@ /outside/**/*.a /outside/re2/obj # build -/bin/urbit -/bin/test_hash /vere.pkg .tags .etags From f5867bfad5d62d804e176fff61c473b5c083f912 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 5 Jun 2018 16:21:08 -0400 Subject: [PATCH 5/7] fixes memory leak in failed cttp.c address resolution --- vere/cttp.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/vere/cttp.c b/vere/cttp.c index 9e4ec2551c..27c3943ee6 100644 --- a/vere/cttp.c +++ b/vere/cttp.c @@ -829,21 +829,22 @@ _cttp_creq_resolve_cb(uv_getaddrinfo_t* adr_u, u3_creq* ceq_u = adr_u->data; if ( u3_csat_quit == ceq_u->sat_e ) { - return _cttp_creq_quit(ceq_u);; + _cttp_creq_quit(ceq_u);; } - - if ( 0 != sas_i ) { - return _cttp_creq_fail(ceq_u, uv_strerror(sas_i)); + else if ( 0 != sas_i ) { + _cttp_creq_fail(ceq_u, uv_strerror(sas_i)); } + else { + // XX traverse struct a la _ames_czar_cb + ceq_u->ipf_w = ntohl(((struct sockaddr_in *)aif_u->ai_addr)->sin_addr.s_addr); + ceq_u->ipf_c = _cttp_creq_ip(ceq_u->ipf_w); - ceq_u->ipf_w = ntohl(((struct sockaddr_in *)aif_u->ai_addr)->sin_addr.s_addr); - ceq_u->ipf_c = _cttp_creq_ip(ceq_u->ipf_w); + ceq_u->sat_e = u3_csat_ripe; + _cttp_creq_connect(ceq_u); + } free(adr_u); uv_freeaddrinfo(aif_u); - - ceq_u->sat_e = u3_csat_ripe; - _cttp_creq_connect(ceq_u); } /* _cttp_creq_resolve(): resolve hostname to IP address @@ -864,6 +865,7 @@ _cttp_creq_resolve(u3_creq* ceq_u) hin_u.ai_socktype = SOCK_STREAM; hin_u.ai_protocol = IPPROTO_TCP; + // XX is this necessary? c3_c* por_c = ceq_u->por_c ? ceq_u->por_c : ( c3y == ceq_u->sec ) ? "443" : "80"; From e6b9dbda8d0bb68f70ba342a049a1308c1d79ec3 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 7 Jun 2018 22:56:01 -0400 Subject: [PATCH 6/7] moves u3_pact to vere.h, replacing the unused u3_apac --- include/vere/vere.h | 16 +++++++++------- vere/ames.c | 24 +++++++----------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/include/vere/vere.h b/include/vere/vere.h index ab72c7c4f3..db5dfcebb4 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -146,15 +146,17 @@ void* tls_u; // client SSL_CTX* } u3_cttp; - /* u3_apac: ames packet, coming or going. + /* u3_pact: ames packet, coming or going. */ - typedef struct _u3_apac { - struct _u3_apac* nex_u; // next in queue - c3_w pip_w; // IPv4 address, to - c3_s por_s; // IPv4 port, to + typedef struct _u3_pact { + uv_udp_send_t snd_u; // udp send request + c3_w pip_w; // target IPv4 address + c3_s por_s; // target port c3_w len_w; // length in bytes - c3_y hun_y[0]; // data - } u3_apac; + c3_y* hun_y; // packet buffer + c3_y imp_y; // galaxy number (optional) + c3_c* dns_c; // galaxy fqdn (optional) + } u3_pact; /* u3_ames: ames networking. */ diff --git a/vere/ames.c b/vere/ames.c index a389a125b8..3a9fc0f166 100644 --- a/vere/ames.c +++ b/vere/ames.c @@ -22,18 +22,6 @@ #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 @@ -60,7 +48,7 @@ _ames_free(void* ptr_v) static void _ames_pact_free(u3_pact* pac_u) { - free(pac_u->buf_y); + free(pac_u->hun_y); free(pac_u->dns_c); free(pac_u); } @@ -88,7 +76,7 @@ _ames_send(u3_pact* pac_u) { u3_ames* sam_u = &u3_Host.sam_u; - if ( !pac_u->buf_y ) { + if ( !pac_u->hun_y ) { _ames_pact_free(pac_u); return; } @@ -100,7 +88,7 @@ _ames_send(u3_pact* pac_u) 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); + uv_buf_t buf_u = uv_buf_init((c3_c*)pac_u->hun_y, pac_u->len_w); c3_i sas_i; @@ -222,6 +210,7 @@ _ames_czar(u3_pact* pac_u, c3_c* bos_c) (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); + // XX remove extra byte for '~' 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); @@ -302,9 +291,9 @@ u3_ames_ef_send(u3_noun lan, u3_noun 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); + pac_u->hun_y = c3_malloc(pac_u->len_w); - u3r_bytes(0, pac_u->len_w, pac_u->buf_y, pac); + u3r_bytes(0, pac_u->len_w, pac_u->hun_y, pac); if ( 0 == pac_u->pip_w ) { pac_u->pip_w = 0x7f000001; @@ -477,6 +466,7 @@ u3_ames_io_exit() { u3_ames* sam_u = &u3_Host.sam_u; + // XX close wax_u instead uv_close(&sam_u->had_u, 0); } From 123a9c728993281272601f6f31738e18e2a07719 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 17 Jul 2018 12:55:16 -0400 Subject: [PATCH 7/7] adds an http request timer to ensure connections are always closed --- include/vere/vere.h | 1 + vere/http.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/vere/vere.h b/include/vere/vere.h index db5dfcebb4..42c4beb27c 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -50,6 +50,7 @@ h2o_req_t* rec_u; // h2o request c3_w seq_l; // sequence within connection u3_rsat sat_e; // request state + uv_timer_t* tim_u; // timeout struct _u3_hcon* hon_u; // connection backlink struct _u3_hreq* nex_u; // next in connection's list } u3_hreq; diff --git a/vere/http.c b/vere/http.c index f41b98454d..ed9c690433 100644 --- a/vere/http.c +++ b/vere/http.c @@ -221,6 +221,11 @@ _http_req_unlink(u3_hreq* req_u) static void _http_req_free(u3_hreq* req_u) { + if ( 0 != req_u->tim_u ) { + uv_close((uv_handle_t*)req_u->tim_u, (uv_close_cb)free); + req_u->tim_u = 0; + } + _http_req_unlink(req_u); free(req_u); } @@ -233,6 +238,8 @@ _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; + req_u->tim_u = 0; + _http_req_link(hon_u, req_u); return req_u; @@ -259,6 +266,22 @@ _http_req_kill(u3_hreq* req_u) u3v_plan(pox, u3nc(c3__thud, u3_nul)); } +/* _http_req_timer_cb(): request timeout callback +*/ +static void +_http_req_timer_cb(uv_timer_t* tim_u) +{ + u3_hreq* req_u = tim_u->data; + + if ( u3_rsat_plan == req_u->sat_e ) { + _http_req_kill(req_u); + req_u->sat_e = u3_rsat_ripe; + + c3_c* msg_c = "gateway timeout"; + h2o_send_error_generic(req_u->rec_u, 504, msg_c, msg_c, 0); + } +} + /* _http_req_dispatch(): dispatch http request to %eyre */ static void @@ -309,6 +332,8 @@ _http_req_respond(u3_hreq* req_u, u3_noun sas, u3_noun hed, u3_noun bod) req_u->sat_e = u3_rsat_ripe; + uv_timer_stop(req_u->tim_u); + h2o_req_t* rec_u = req_u->rec_u; rec_u->res.status = sas; @@ -411,6 +436,12 @@ _http_rec_accept(h2o_handler_t* han_u, h2o_req_t* rec_u) c3_assert(hon_u->sok_u == &noc_u->suv_u->sok_u); u3_hreq* req_u = _http_req_new(hon_u, 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, 30 * 1000, 0); + _http_req_dispatch(req_u, req); }