From 8b8d9b60f64141a769f1b99ef12ef4e122363792 Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 29 Jan 2024 15:16:30 +0200 Subject: [PATCH 01/32] ames: add libnatpmp for automatic port forwarding --- WORKSPACE.bazel | 9 +++++ bazel/third_party/natpmp/BUILD.bazel | 0 bazel/third_party/natpmp/natpmp.BUILD | 21 ++++++++++ pkg/vere/BUILD.bazel | 1 + pkg/vere/io/ames.c | 55 +++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 bazel/third_party/natpmp/BUILD.bazel create mode 100644 bazel/third_party/natpmp/natpmp.BUILD diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 39ddfe03e9..dca6750619 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -217,6 +217,15 @@ versioned_http_file( version = "721fa05", ) +versioned_http_archive( + name = "natpmp", + build_file = "//bazel/third_party/natpmp:natpmp.BUILD", + sha256 = "0684ed2c8406437e7519a1bd20ea83780db871b3a3a5d752311ba3e889dbfc70", + strip_prefix = "libnatpmp-{version}", + url = "http://miniupnp.free.fr/files/libnatpmp-{version}.tar.gz", + version = "20230423", +) + versioned_http_file( name = "solid_pill", sha256 = "8b658fcee6978e2b19004a54233cab953e77ea0bb6c3a04d1bfda4ddc6be63c5", diff --git a/bazel/third_party/natpmp/BUILD.bazel b/bazel/third_party/natpmp/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/natpmp/natpmp.BUILD b/bazel/third_party/natpmp/natpmp.BUILD new file mode 100644 index 0000000000..f002ccafcc --- /dev/null +++ b/bazel/third_party/natpmp/natpmp.BUILD @@ -0,0 +1,21 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +make( + name = "natpmp", + out_static_libs = ["libnatpmp.a"], + out_lib_dir = "/usr/lib", + out_include_dir = "/usr/include", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + copts = ["-O3"], + lib_source = ":all", + visibility = ["//visibility:public"], + postfix_script = "cp $BUILD_TMPDIR/natpmp_declspec.h $INSTALLDIR/usr/include/natpmp_declspec.h", +) \ No newline at end of file diff --git a/pkg/vere/BUILD.bazel b/pkg/vere/BUILD.bazel index f50642ab89..0be1facfdf 100644 --- a/pkg/vere/BUILD.bazel +++ b/pkg/vere/BUILD.bazel @@ -139,6 +139,7 @@ vere_library( "@lmdb", "@openssl", "@uv", + "@natpmp", ] + select({ "@platforms//os:macos": [], "@platforms//os:linux": [ diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 412a310e32..3ce9cc4f90 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -7,6 +7,7 @@ #include "ur.h" #include "zlib.h" +#include "natpmp.h" #include @@ -71,6 +72,11 @@ typedef enum u3_stun_state { u3_lane sef_u; // our lane, if we know it c3_o wok_o; // STUN worked, set on first success } sun_u; // + struct { + natpmp_t req_u; // libnatpmp struct for mapping request + uv_poll_t pol_u; // handle waits on libnatpmp socket + uv_timer_t tim_u; // every two hours if mapping succeeds + } nat_u; // libnatpmp stuff for port forwarding c3_o nal_o; // lane cache backcompat flag struct { // config: c3_o net_o; // can send @@ -2752,6 +2758,48 @@ _ames_recv_cb(uv_udp_t* wax_u, } } +static void natpmp_init(uv_timer_t* handle); + +static void natpmp_cb(uv_poll_t* handle, int status, int events) { + u3_ames* sam_u = handle->data; + + natpmpresp_t response; + c3_w r = readnatpmpresponseorretry(&sam_u->nat_u.req_u, &response); + if ( NATPMP_TRYAGAIN == r ) { + return; + } + if ( 0 != r ) { + u3l_log("ames: natpmp error %i", r); + uv_poll_stop(handle); + closenatpmp(&sam_u->nat_u.req_u); + return; + } + uv_poll_stop(handle); + + u3l_log("ames: mapped public port %hu to localport %hu lifetime %u", + response.pnu.newportmapping.mappedpublicport, + response.pnu.newportmapping.privateport, + response.pnu.newportmapping.lifetime); + + closenatpmp(&sam_u->nat_u.req_u); + sam_u->nat_u.tim_u.data = sam_u; + uv_timer_init(u3L, &sam_u->nat_u.tim_u); + uv_timer_start(&sam_u->nat_u.tim_u, natpmp_init, 7200000, 0); +} + +static void natpmp_init(uv_timer_t* handle) { + + u3_ames* sam_u = handle->data; + c3_s por_s = sam_u->pir_u->por_s; + + initnatpmp(&sam_u->nat_u.req_u, 0, 0); + sendnewportmappingrequest(&sam_u->nat_u.req_u, NATPMP_PROTOCOL_UDP, por_s, por_s, 7200); + + sam_u->nat_u.pol_u.data = sam_u; + uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); + uv_poll_start(&sam_u->nat_u.pol_u, UV_READABLE, natpmp_cb); +} + static void _mdns_dear_bail(u3_ovum* egg_u, u3_noun lud) { @@ -2872,6 +2920,13 @@ _ames_io_start(u3_ames* sam_u) u3z(our); mdns_init(por_s, !sam_u->pir_u->fak_o, our_s, _ames_put_dear, (void *)sam_u); + + if ( c3n == sam_u->pir_u->fak_o ) { + sam_u->nat_u.tim_u.data = sam_u; + uv_timer_init(u3L, &sam_u->nat_u.tim_u); + uv_timer_start(&sam_u->nat_u.tim_u, natpmp_init, 0, 0); + } + c3_free(our_s); } From 8d320c6e9976a17e2cf8b7c360b2cf33fc69a555 Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 29 Jan 2024 16:12:46 +0200 Subject: [PATCH 02/32] bazel: make libnatpmp import better --- bazel/third_party/natpmp/natpmp.BUILD | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/bazel/third_party/natpmp/natpmp.BUILD b/bazel/third_party/natpmp/natpmp.BUILD index f002ccafcc..b3a7edd7e0 100644 --- a/bazel/third_party/natpmp/natpmp.BUILD +++ b/bazel/third_party/natpmp/natpmp.BUILD @@ -1,21 +1,8 @@ -load("@rules_foreign_cc//foreign_cc:defs.bzl", "make") - -filegroup( - name = "all", - srcs = glob(["**"]), -) - -make( +cc_library( name = "natpmp", - out_static_libs = ["libnatpmp.a"], - out_lib_dir = "/usr/lib", - out_include_dir = "/usr/include", - args = select({ - "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], - "//conditions:default": ["--jobs=`nproc`"], - }), + srcs = ["natpmp.c", "getgateway.c"], + hdrs = ["natpmp.h", "getgateway.h", "natpmp_declspec.h"], copts = ["-O3"], - lib_source = ":all", + linkstatic = True, visibility = ["//visibility:public"], - postfix_script = "cp $BUILD_TMPDIR/natpmp_declspec.h $INSTALLDIR/usr/include/natpmp_declspec.h", -) \ No newline at end of file +) From c774a317010052bbaf2e2f472fff7efb35d42409 Mon Sep 17 00:00:00 2001 From: Josh Lehman Date: Tue, 16 Apr 2024 05:57:18 -0700 Subject: [PATCH 03/32] add more helpful chop message --- pkg/vere/disk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/vere/disk.c b/pkg/vere/disk.c index 18fdf31fec..319403566f 100644 --- a/pkg/vere/disk.c +++ b/pkg/vere/disk.c @@ -1632,7 +1632,7 @@ u3_disk_chop(u3_disk* log_u, c3_d eve_d) u3_disk_epoc_list(log_u, sot_d); if ( len_z <= 2 ) { - fprintf(stderr, "chop: nothing to do, have a great day\r\n"); + fprintf(stderr, "chop: nothing to do, try running roll first\r\n"); exit(0); // enjoy } From 27e5c33304e60d822a2a1b1cbf5352273bcc8fd4 Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 22 Apr 2024 19:56:20 +0300 Subject: [PATCH 04/32] ames: address review comments for natpmp --- pkg/vere/io/ames.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 3ce9cc4f90..341f65d23c 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -2760,7 +2760,11 @@ _ames_recv_cb(uv_udp_t* wax_u, static void natpmp_init(uv_timer_t* handle); -static void natpmp_cb(uv_poll_t* handle, int status, int events) { +static void +natpmp_cb(uv_poll_t* handle, + int status, + int events) +{ u3_ames* sam_u = handle->data; natpmpresp_t response; @@ -2768,13 +2772,14 @@ static void natpmp_cb(uv_poll_t* handle, int status, int events) { if ( NATPMP_TRYAGAIN == r ) { return; } + + uv_poll_stop(handle); + if ( 0 != r ) { u3l_log("ames: natpmp error %i", r); - uv_poll_stop(handle); closenatpmp(&sam_u->nat_u.req_u); return; } - uv_poll_stop(handle); u3l_log("ames: mapped public port %hu to localport %hu lifetime %u", response.pnu.newportmapping.mappedpublicport, @@ -2783,20 +2788,18 @@ static void natpmp_cb(uv_poll_t* handle, int status, int events) { closenatpmp(&sam_u->nat_u.req_u); sam_u->nat_u.tim_u.data = sam_u; - uv_timer_init(u3L, &sam_u->nat_u.tim_u); uv_timer_start(&sam_u->nat_u.tim_u, natpmp_init, 7200000, 0); } -static void natpmp_init(uv_timer_t* handle) { - +static void +natpmp_init(uv_timer_t *handle) +{ u3_ames* sam_u = handle->data; c3_s por_s = sam_u->pir_u->por_s; - initnatpmp(&sam_u->nat_u.req_u, 0, 0); sendnewportmappingrequest(&sam_u->nat_u.req_u, NATPMP_PROTOCOL_UDP, por_s, por_s, 7200); sam_u->nat_u.pol_u.data = sam_u; - uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); uv_poll_start(&sam_u->nat_u.pol_u, UV_READABLE, natpmp_cb); } @@ -2922,8 +2925,6 @@ _ames_io_start(u3_ames* sam_u) mdns_init(por_s, !sam_u->pir_u->fak_o, our_s, _ames_put_dear, (void *)sam_u); if ( c3n == sam_u->pir_u->fak_o ) { - sam_u->nat_u.tim_u.data = sam_u; - uv_timer_init(u3L, &sam_u->nat_u.tim_u); uv_timer_start(&sam_u->nat_u.tim_u, natpmp_init, 0, 0); } @@ -3270,6 +3271,12 @@ u3_ames_io_init(u3_pier* pir_u) sam_u->sun_u.tim_u.data = sam_u; sam_u->sun_u.dns_u.data = sam_u; + // initialize libnatpmp + sam_u->nat_u.tim_u.data = sam_u; + initnatpmp(&sam_u->nat_u.req_u, 0, 0); + uv_timer_init(u3L, &sam_u->nat_u.tim_u); + uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); + // enable forwarding on galaxies only u3_noun who = u3i_chubs(2, sam_u->pir_u->who_d); u3_noun rac = u3do("clan:title", who); From 68429f65b96b67d042a5aebbbdf9a8fa41c620b0 Mon Sep 17 00:00:00 2001 From: pkova Date: Tue, 23 Apr 2024 13:42:20 +0300 Subject: [PATCH 05/32] ames: address more libnatpmp nits --- pkg/vere/io/ames.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 341f65d23c..b1e473189c 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -2762,21 +2762,21 @@ static void natpmp_init(uv_timer_t* handle); static void natpmp_cb(uv_poll_t* handle, - int status, - int events) + c3_i status, + c3_i events) { u3_ames* sam_u = handle->data; natpmpresp_t response; - c3_w r = readnatpmpresponseorretry(&sam_u->nat_u.req_u, &response); - if ( NATPMP_TRYAGAIN == r ) { + c3_i res_i = readnatpmpresponseorretry(&sam_u->nat_u.req_u, &response); + if ( NATPMP_TRYAGAIN == res_i ) { return; } uv_poll_stop(handle); - if ( 0 != r ) { - u3l_log("ames: natpmp error %i", r); + if ( 0 != res_i ) { + u3l_log("ames: natpmp error %i", res_i); closenatpmp(&sam_u->nat_u.req_u); return; } From 46d20eaa0300312ea4a8d86f2544e378f3ce81fd Mon Sep 17 00:00:00 2001 From: Tinnus Napbus Date: Thu, 25 Apr 2024 03:44:51 +1200 Subject: [PATCH 06/32] events: add docs link to no-chop printf --- pkg/vere/disk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/vere/disk.c b/pkg/vere/disk.c index 319403566f..b60253fb1c 100644 --- a/pkg/vere/disk.c +++ b/pkg/vere/disk.c @@ -1632,7 +1632,9 @@ u3_disk_chop(u3_disk* log_u, c3_d eve_d) u3_disk_epoc_list(log_u, sot_d); if ( len_z <= 2 ) { - fprintf(stderr, "chop: nothing to do, try running roll first\r\n"); + fprintf(stderr, "chop: nothing to do, try running roll first\r\n" + "chop: for more info see " + "https://docs.urbit.org/manual/running/vere#chop\r\n"); exit(0); // enjoy } From 175c2d1a8d931e47ab9b5b4683419aaa7174b2b9 Mon Sep 17 00:00:00 2001 From: Pyry Kovanen Date: Wed, 1 May 2024 19:50:20 +0300 Subject: [PATCH 07/32] disk: fix broken chop error message --- pkg/vere/disk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/vere/disk.c b/pkg/vere/disk.c index b60253fb1c..4576f0662f 100644 --- a/pkg/vere/disk.c +++ b/pkg/vere/disk.c @@ -1632,9 +1632,7 @@ u3_disk_chop(u3_disk* log_u, c3_d eve_d) u3_disk_epoc_list(log_u, sot_d); if ( len_z <= 2 ) { - fprintf(stderr, "chop: nothing to do, try running roll first\r\n" - "chop: for more info see " - "https://docs.urbit.org/manual/running/vere#chop\r\n"); + fprintf(stderr, "chop: nothing to do, try running roll first\r\nchop: for more info see https://docs.urbit.org/manual/running/vere#chop\r\n"); exit(0); // enjoy } From 7323954d798f7f3cefe1228ee0b77820398526c7 Mon Sep 17 00:00:00 2001 From: Pyry Kovanen Date: Wed, 1 May 2024 21:09:39 +0300 Subject: [PATCH 08/32] Revert "disk: fix broken chop error message" --- pkg/vere/disk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/vere/disk.c b/pkg/vere/disk.c index 4576f0662f..b60253fb1c 100644 --- a/pkg/vere/disk.c +++ b/pkg/vere/disk.c @@ -1632,7 +1632,9 @@ u3_disk_chop(u3_disk* log_u, c3_d eve_d) u3_disk_epoc_list(log_u, sot_d); if ( len_z <= 2 ) { - fprintf(stderr, "chop: nothing to do, try running roll first\r\nchop: for more info see https://docs.urbit.org/manual/running/vere#chop\r\n"); + fprintf(stderr, "chop: nothing to do, try running roll first\r\n" + "chop: for more info see " + "https://docs.urbit.org/manual/running/vere#chop\r\n"); exit(0); // enjoy } From 385bdf9b852ed994e1a8efb5118a9594db15354f Mon Sep 17 00:00:00 2001 From: Pyry Kovanen Date: Wed, 1 May 2024 21:54:36 +0300 Subject: [PATCH 09/32] Revert "ames: add libnatpmp for automatic port forwarding" --- WORKSPACE.bazel | 9 ---- bazel/third_party/natpmp/BUILD.bazel | 0 bazel/third_party/natpmp/natpmp.BUILD | 8 ---- pkg/vere/BUILD.bazel | 1 - pkg/vere/io/ames.c | 62 --------------------------- 5 files changed, 80 deletions(-) delete mode 100644 bazel/third_party/natpmp/BUILD.bazel delete mode 100644 bazel/third_party/natpmp/natpmp.BUILD diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index dca6750619..39ddfe03e9 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -217,15 +217,6 @@ versioned_http_file( version = "721fa05", ) -versioned_http_archive( - name = "natpmp", - build_file = "//bazel/third_party/natpmp:natpmp.BUILD", - sha256 = "0684ed2c8406437e7519a1bd20ea83780db871b3a3a5d752311ba3e889dbfc70", - strip_prefix = "libnatpmp-{version}", - url = "http://miniupnp.free.fr/files/libnatpmp-{version}.tar.gz", - version = "20230423", -) - versioned_http_file( name = "solid_pill", sha256 = "8b658fcee6978e2b19004a54233cab953e77ea0bb6c3a04d1bfda4ddc6be63c5", diff --git a/bazel/third_party/natpmp/BUILD.bazel b/bazel/third_party/natpmp/BUILD.bazel deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bazel/third_party/natpmp/natpmp.BUILD b/bazel/third_party/natpmp/natpmp.BUILD deleted file mode 100644 index b3a7edd7e0..0000000000 --- a/bazel/third_party/natpmp/natpmp.BUILD +++ /dev/null @@ -1,8 +0,0 @@ -cc_library( - name = "natpmp", - srcs = ["natpmp.c", "getgateway.c"], - hdrs = ["natpmp.h", "getgateway.h", "natpmp_declspec.h"], - copts = ["-O3"], - linkstatic = True, - visibility = ["//visibility:public"], -) diff --git a/pkg/vere/BUILD.bazel b/pkg/vere/BUILD.bazel index 6303b87201..e736d0e8e1 100644 --- a/pkg/vere/BUILD.bazel +++ b/pkg/vere/BUILD.bazel @@ -140,7 +140,6 @@ vere_library( "@lmdb", "@openssl", "@uv", - "@natpmp", ] + select({ "@platforms//os:macos": [], "@platforms//os:linux": [ diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index a92a38d019..7cd462b7d6 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -7,7 +7,6 @@ #include "ur.h" #include "zlib.h" -#include "natpmp.h" #include @@ -72,11 +71,6 @@ typedef enum u3_stun_state { u3_lane sef_u; // our lane, if we know it c3_o wok_o; // STUN worked, set on first success } sun_u; // - struct { - natpmp_t req_u; // libnatpmp struct for mapping request - uv_poll_t pol_u; // handle waits on libnatpmp socket - uv_timer_t tim_u; // every two hours if mapping succeeds - } nat_u; // libnatpmp stuff for port forwarding c3_o nal_o; // lane cache backcompat flag struct { // config: c3_o net_o; // can send @@ -2771,51 +2765,6 @@ _ames_recv_cb(uv_udp_t* wax_u, } } -static void natpmp_init(uv_timer_t* handle); - -static void -natpmp_cb(uv_poll_t* handle, - c3_i status, - c3_i events) -{ - u3_ames* sam_u = handle->data; - - natpmpresp_t response; - c3_i res_i = readnatpmpresponseorretry(&sam_u->nat_u.req_u, &response); - if ( NATPMP_TRYAGAIN == res_i ) { - return; - } - - uv_poll_stop(handle); - - if ( 0 != res_i ) { - u3l_log("ames: natpmp error %i", res_i); - closenatpmp(&sam_u->nat_u.req_u); - return; - } - - u3l_log("ames: mapped public port %hu to localport %hu lifetime %u", - response.pnu.newportmapping.mappedpublicport, - response.pnu.newportmapping.privateport, - response.pnu.newportmapping.lifetime); - - closenatpmp(&sam_u->nat_u.req_u); - sam_u->nat_u.tim_u.data = sam_u; - uv_timer_start(&sam_u->nat_u.tim_u, natpmp_init, 7200000, 0); -} - -static void -natpmp_init(uv_timer_t *handle) -{ - u3_ames* sam_u = handle->data; - c3_s por_s = sam_u->pir_u->por_s; - - sendnewportmappingrequest(&sam_u->nat_u.req_u, NATPMP_PROTOCOL_UDP, por_s, por_s, 7200); - - sam_u->nat_u.pol_u.data = sam_u; - uv_poll_start(&sam_u->nat_u.pol_u, UV_READABLE, natpmp_cb); -} - static void _mdns_dear_bail(u3_ovum* egg_u, u3_noun lud) { @@ -2936,11 +2885,6 @@ _ames_io_start(u3_ames* sam_u) u3z(our); mdns_init(por_s, !sam_u->pir_u->fak_o, our_s, _ames_put_dear, (void *)sam_u); - - if ( c3n == sam_u->pir_u->fak_o ) { - uv_timer_start(&sam_u->nat_u.tim_u, natpmp_init, 0, 0); - } - c3_free(our_s); } @@ -3284,12 +3228,6 @@ u3_ames_io_init(u3_pier* pir_u) sam_u->sun_u.tim_u.data = sam_u; sam_u->sun_u.dns_u.data = sam_u; - // initialize libnatpmp - sam_u->nat_u.tim_u.data = sam_u; - initnatpmp(&sam_u->nat_u.req_u, 0, 0); - uv_timer_init(u3L, &sam_u->nat_u.tim_u); - uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); - // enable forwarding on galaxies only u3_noun who = u3i_chubs(2, sam_u->pir_u->who_d); u3_noun rac = u3do("clan:title", who); From 14be6deff89a7dadd1651347e523ca3ffc63723b Mon Sep 17 00:00:00 2001 From: Pyry Kovanen Date: Wed, 24 Apr 2024 19:15:04 +0300 Subject: [PATCH 10/32] ames: add libnatpmp for automatic port forwarding (#593) Same as https://github.com/urbit/urbit/pull/3261 but for vere. From what I can tell this NAT-PMP stuff is fairly well supported by routers, works on my machine at least. --- WORKSPACE.bazel | 9 ++++ bazel/third_party/natpmp/BUILD.bazel | 0 bazel/third_party/natpmp/natpmp.BUILD | 8 ++++ pkg/vere/BUILD.bazel | 1 + pkg/vere/io/ames.c | 62 +++++++++++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 bazel/third_party/natpmp/BUILD.bazel create mode 100644 bazel/third_party/natpmp/natpmp.BUILD diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 39ddfe03e9..dca6750619 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -217,6 +217,15 @@ versioned_http_file( version = "721fa05", ) +versioned_http_archive( + name = "natpmp", + build_file = "//bazel/third_party/natpmp:natpmp.BUILD", + sha256 = "0684ed2c8406437e7519a1bd20ea83780db871b3a3a5d752311ba3e889dbfc70", + strip_prefix = "libnatpmp-{version}", + url = "http://miniupnp.free.fr/files/libnatpmp-{version}.tar.gz", + version = "20230423", +) + versioned_http_file( name = "solid_pill", sha256 = "8b658fcee6978e2b19004a54233cab953e77ea0bb6c3a04d1bfda4ddc6be63c5", diff --git a/bazel/third_party/natpmp/BUILD.bazel b/bazel/third_party/natpmp/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/natpmp/natpmp.BUILD b/bazel/third_party/natpmp/natpmp.BUILD new file mode 100644 index 0000000000..b3a7edd7e0 --- /dev/null +++ b/bazel/third_party/natpmp/natpmp.BUILD @@ -0,0 +1,8 @@ +cc_library( + name = "natpmp", + srcs = ["natpmp.c", "getgateway.c"], + hdrs = ["natpmp.h", "getgateway.h", "natpmp_declspec.h"], + copts = ["-O3"], + linkstatic = True, + visibility = ["//visibility:public"], +) diff --git a/pkg/vere/BUILD.bazel b/pkg/vere/BUILD.bazel index e736d0e8e1..6303b87201 100644 --- a/pkg/vere/BUILD.bazel +++ b/pkg/vere/BUILD.bazel @@ -140,6 +140,7 @@ vere_library( "@lmdb", "@openssl", "@uv", + "@natpmp", ] + select({ "@platforms//os:macos": [], "@platforms//os:linux": [ diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 7cd462b7d6..a92a38d019 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -7,6 +7,7 @@ #include "ur.h" #include "zlib.h" +#include "natpmp.h" #include @@ -71,6 +72,11 @@ typedef enum u3_stun_state { u3_lane sef_u; // our lane, if we know it c3_o wok_o; // STUN worked, set on first success } sun_u; // + struct { + natpmp_t req_u; // libnatpmp struct for mapping request + uv_poll_t pol_u; // handle waits on libnatpmp socket + uv_timer_t tim_u; // every two hours if mapping succeeds + } nat_u; // libnatpmp stuff for port forwarding c3_o nal_o; // lane cache backcompat flag struct { // config: c3_o net_o; // can send @@ -2765,6 +2771,51 @@ _ames_recv_cb(uv_udp_t* wax_u, } } +static void natpmp_init(uv_timer_t* handle); + +static void +natpmp_cb(uv_poll_t* handle, + c3_i status, + c3_i events) +{ + u3_ames* sam_u = handle->data; + + natpmpresp_t response; + c3_i res_i = readnatpmpresponseorretry(&sam_u->nat_u.req_u, &response); + if ( NATPMP_TRYAGAIN == res_i ) { + return; + } + + uv_poll_stop(handle); + + if ( 0 != res_i ) { + u3l_log("ames: natpmp error %i", res_i); + closenatpmp(&sam_u->nat_u.req_u); + return; + } + + u3l_log("ames: mapped public port %hu to localport %hu lifetime %u", + response.pnu.newportmapping.mappedpublicport, + response.pnu.newportmapping.privateport, + response.pnu.newportmapping.lifetime); + + closenatpmp(&sam_u->nat_u.req_u); + sam_u->nat_u.tim_u.data = sam_u; + uv_timer_start(&sam_u->nat_u.tim_u, natpmp_init, 7200000, 0); +} + +static void +natpmp_init(uv_timer_t *handle) +{ + u3_ames* sam_u = handle->data; + c3_s por_s = sam_u->pir_u->por_s; + + sendnewportmappingrequest(&sam_u->nat_u.req_u, NATPMP_PROTOCOL_UDP, por_s, por_s, 7200); + + sam_u->nat_u.pol_u.data = sam_u; + uv_poll_start(&sam_u->nat_u.pol_u, UV_READABLE, natpmp_cb); +} + static void _mdns_dear_bail(u3_ovum* egg_u, u3_noun lud) { @@ -2885,6 +2936,11 @@ _ames_io_start(u3_ames* sam_u) u3z(our); mdns_init(por_s, !sam_u->pir_u->fak_o, our_s, _ames_put_dear, (void *)sam_u); + + if ( c3n == sam_u->pir_u->fak_o ) { + uv_timer_start(&sam_u->nat_u.tim_u, natpmp_init, 0, 0); + } + c3_free(our_s); } @@ -3228,6 +3284,12 @@ u3_ames_io_init(u3_pier* pir_u) sam_u->sun_u.tim_u.data = sam_u; sam_u->sun_u.dns_u.data = sam_u; + // initialize libnatpmp + sam_u->nat_u.tim_u.data = sam_u; + initnatpmp(&sam_u->nat_u.req_u, 0, 0); + uv_timer_init(u3L, &sam_u->nat_u.tim_u); + uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); + // enable forwarding on galaxies only u3_noun who = u3i_chubs(2, sam_u->pir_u->who_d); u3_noun rac = u3do("clan:title", who); From c496367699fc109fae2c189b4ab95c1cd220fedc Mon Sep 17 00:00:00 2001 From: pkova Date: Fri, 10 May 2024 17:15:28 +0300 Subject: [PATCH 11/32] ames: fix libnatpmp initialization problems --- pkg/vere/io/ames.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index a92a38d019..635c6f3665 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -2781,15 +2781,16 @@ natpmp_cb(uv_poll_t* handle, u3_ames* sam_u = handle->data; natpmpresp_t response; - c3_i res_i = readnatpmpresponseorretry(&sam_u->nat_u.req_u, &response); - if ( NATPMP_TRYAGAIN == res_i ) { + c3_i err_i = readnatpmpresponseorretry(&sam_u->nat_u.req_u, &response); + if ( NATPMP_TRYAGAIN == err_i ) { return; } uv_poll_stop(handle); - if ( 0 != res_i ) { - u3l_log("ames: natpmp error %i", res_i); + if ( 0 != err_i ) { + u3l_log("ames: natpmp error %i", err_i); + uv_poll_stop(&sam_u->nat_u.pol_u); closenatpmp(&sam_u->nat_u.req_u); return; } @@ -2810,6 +2811,14 @@ natpmp_init(uv_timer_t *handle) u3_ames* sam_u = handle->data; c3_s por_s = sam_u->pir_u->por_s; + c3_i err_i = initnatpmp(&sam_u->nat_u.req_u, 0, 0); + + if (err_i != 0) { + return; + } + + uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); + sendnewportmappingrequest(&sam_u->nat_u.req_u, NATPMP_PROTOCOL_UDP, por_s, por_s, 7200); sam_u->nat_u.pol_u.data = sam_u; @@ -3286,9 +3295,7 @@ u3_ames_io_init(u3_pier* pir_u) // initialize libnatpmp sam_u->nat_u.tim_u.data = sam_u; - initnatpmp(&sam_u->nat_u.req_u, 0, 0); uv_timer_init(u3L, &sam_u->nat_u.tim_u); - uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); // enable forwarding on galaxies only u3_noun who = u3i_chubs(2, sam_u->pir_u->who_d); From d02c620f20ab0a016e5fc859ea1012ae5be41a87 Mon Sep 17 00:00:00 2001 From: pkova Date: Fri, 10 May 2024 18:52:59 +0300 Subject: [PATCH 12/32] ames: check uv_poll_init for errors in natpmp codepath --- pkg/vere/io/ames.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 635c6f3665..24ee237754 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -2817,7 +2817,11 @@ natpmp_init(uv_timer_t *handle) return; } - uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); + err_i = uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s); + + if (err_i != 0) { + return; + } sendnewportmappingrequest(&sam_u->nat_u.req_u, NATPMP_PROTOCOL_UDP, por_s, por_s, 7200); From cca7582774065b0667dd47f5f74961a01f9d122a Mon Sep 17 00:00:00 2001 From: pkova Date: Fri, 10 May 2024 19:45:35 +0300 Subject: [PATCH 13/32] ames: check status in natpmp_cb --- pkg/vere/io/ames.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 24ee237754..d13d7a9d7d 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -2778,6 +2778,11 @@ natpmp_cb(uv_poll_t* handle, c3_i status, c3_i events) { + + if (status != 0) { + return; + } + u3_ames* sam_u = handle->data; natpmpresp_t response; From 879e86d628f11c1f3f5aaeef383bccc63e916485 Mon Sep 17 00:00:00 2001 From: pkova Date: Tue, 14 May 2024 14:38:25 +0300 Subject: [PATCH 14/32] ames: clean up libnatpmp stuff in _ames_io_exit --- pkg/vere/io/ames.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index d13d7a9d7d..2da7f743c8 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -3200,6 +3200,11 @@ _ames_io_exit(u3_auto* car_u) uv_close(&sam_u->had_u, _ames_exit_cb); uv_close((uv_handle_t*)&sam_u->sun_u.dns_u, 0); uv_close((uv_handle_t*)&sam_u->sun_u.tim_u, 0); + uv_close((uv_handle_t*)&sam_u->nat_u.tim_u, 0); + + if (uv_is_active((uv_handle_t*)&sam_u->nat_u.pol_u)) { + uv_close((uv_handle_t*)&sam_u->nat_u.pol_u, 0); + } } /* _ames_io_info(): produce status info. From 0602d1d65ca44be712830611d5b83043b2b5e299 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 24 May 2024 12:21:29 -0400 Subject: [PATCH 15/32] play: replay in a subprocess --- pkg/vere/main.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 2222f87dd1..f48c8dc9ba 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -18,6 +18,7 @@ #include "db/lmdb.h" #include "getopt.h" #include "libgen.h" +#include "spawn.h" #include "ca_bundle.h" #include "pace.h" @@ -2315,6 +2316,28 @@ _cw_play_impl(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) return pay_d; } +/* _cw_play_fork(): spawn a subprocess for event replay. +*/ +static c3_i +_cw_play_fork(c3_c *pax_c) // XX use --serf-bin +{ + pid_t pid; + c3_i sat_i; + c3_c *argv[] = { u3_Host.wrk_c, "play", u3_Host.dir_c }; // XX parameterize args + + if ( 0 != posix_spawn(&pid, pax_c, 0, 0, argv, 0) ) { + fprintf(stderr, "play: posix_spawn: %d\r\n", errno); + return 1; + } + + if ( -1 == waitpid(pid, &sat_i, 0) ) { + fprintf(stderr, "play: waitpid: %d\r\n", errno); + return 1; + } + + return WEXITSTATUS(sat_i); +} + /* _cw_play(): replay events, but better. */ static void @@ -3110,7 +3133,11 @@ main(c3_i argc, // we need the current snapshot's latest event number to // validate whether we can execute disk migration if ( u3_Host.ops_u.nuu == c3n ) { - _cw_play_impl(0, 0, c3n, c3n, c3n); + c3_i sat_i = _cw_play_fork(u3_Host.dem_c); + if ( sat_i ) { + fprintf(stderr, "play: replay failed: %d\r\n", sat_i); + exit(sat_i); + } // XX unmap loom, else parts of the snapshot could be left in memory } From 53223be13e04199def835181c10d338740604e22 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 24 May 2024 12:23:29 -0400 Subject: [PATCH 16/32] Revert "Revert "vere: add --serf-bin option to provide path to serf"" This reverts commit a37f05248056fc580551d6e23414a7f4d75a8a55. --- pkg/vere/main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index f48c8dc9ba..e54f68b708 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -292,12 +292,13 @@ _main_getopt(c3_i argc, c3_c** argv) { "prop-url", required_argument, NULL, 2 }, { "prop-name", required_argument, NULL, 3 }, // - { "urth-loom", required_argument, NULL, 5 }, - { "no-demand", no_argument, NULL, 6 }, - { "swap", no_argument, NULL, 7 }, - { "swap-to", required_argument, NULL, 8 }, - { "toss", required_argument, NULL, 9 }, + { "urth-loom", required_argument, NULL, 5 }, + { "no-demand", no_argument, NULL, 6 }, + { "swap", no_argument, NULL, 7 }, + { "swap-to", required_argument, NULL, 8 }, + { "toss", required_argument, NULL, 9 }, { "behn-allow-blocked", no_argument, NULL, 10 }, + { "serf-bin", required_argument, NULL, 11 }, // { NULL, 0, NULL, 0 }, }; @@ -341,6 +342,10 @@ _main_getopt(c3_i argc, c3_c** argv) u3_Host.ops_u.beb = c3y; break; } + case 11: { // serf-bin + u3_Host.wrk_c = strdup(optarg); + break; + } // special args // case c3__loom: { From 206e03c5485a92cccca1dd5096708de1ab032884 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 24 May 2024 12:35:00 -0400 Subject: [PATCH 17/32] play: use `u3_Host` strings --- pkg/vere/main.c | 14 ++++++++------ pkg/vere/vere.h | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index e54f68b708..645ce38a1a 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -343,7 +343,7 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case 11: { // serf-bin - u3_Host.wrk_c = strdup(optarg); + u3_Host.sef_c = strdup(optarg); break; } // special args @@ -2324,13 +2324,13 @@ _cw_play_impl(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) /* _cw_play_fork(): spawn a subprocess for event replay. */ static c3_i -_cw_play_fork(c3_c *pax_c) // XX use --serf-bin +_cw_play_fork() { pid_t pid; c3_i sat_i; c3_c *argv[] = { u3_Host.wrk_c, "play", u3_Host.dir_c }; // XX parameterize args - if ( 0 != posix_spawn(&pid, pax_c, 0, 0, argv, 0) ) { + if ( 0 != posix_spawn(&pid, u3_Host.sef_c, 0, 0, argv, 0) ) { fprintf(stderr, "play: posix_spawn: %d\r\n", errno); return 1; } @@ -2994,8 +2994,6 @@ main(c3_i argc, _main_self_path(); - // XX add argument - // if ( !u3_Host.wrk_c ) { u3_Host.wrk_c = bin_c; } @@ -3003,6 +3001,10 @@ main(c3_i argc, c3_free(bin_c); } + if ( !u3_Host.sef_c ) { + u3_Host.sef_c = u3_Host.dem_c; + } + if ( c3y == u3_Host.ops_u.dem ) { // In daemon mode, run the urbit as a background process, but don't // exit from the parent process until the ship is finished booting. @@ -3138,7 +3140,7 @@ main(c3_i argc, // we need the current snapshot's latest event number to // validate whether we can execute disk migration if ( u3_Host.ops_u.nuu == c3n ) { - c3_i sat_i = _cw_play_fork(u3_Host.dem_c); + c3_i sat_i = _cw_play_fork(); if ( sat_i ) { fprintf(stderr, "play: replay failed: %d\r\n", sat_i); exit(sat_i); diff --git a/pkg/vere/vere.h b/pkg/vere/vere.h index f97a76f142..b28679ee7b 100644 --- a/pkg/vere/vere.h +++ b/pkg/vere/vere.h @@ -329,7 +329,8 @@ c3_c* dir_c; // pier path (no trailing /) c3_d eve_d; // initial current snapshot c3_c* dem_c; // daemon executable path - c3_c* wrk_c; // worker executable path + c3_c* wrk_c; // worker executable name + c3_c* sef_c; // worker executable path c3_d now_d; // event tick uv_loop_t* lup_u; // libuv event loop u3_usig* sig_u; // signal list From 837799b4a2e767a55b9636429f3d9c304ee77e93 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 24 May 2024 12:55:48 -0400 Subject: [PATCH 18/32] play: use `u3_Host.wrk_c` --- pkg/vere/main.c | 10 ++++------ pkg/vere/vere.h | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 645ce38a1a..c9ca613204 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -343,7 +343,7 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case 11: { // serf-bin - u3_Host.sef_c = strdup(optarg); + u3_Host.wrk_c = strdup(optarg); break; } // special args @@ -2330,7 +2330,9 @@ _cw_play_fork() c3_i sat_i; c3_c *argv[] = { u3_Host.wrk_c, "play", u3_Host.dir_c }; // XX parameterize args - if ( 0 != posix_spawn(&pid, u3_Host.sef_c, 0, 0, argv, 0) ) { + fprintf(stderr, "wrk_c: %s\r\n", u3_Host.wrk_c); + + if ( 0 != posix_spawn(&pid, u3_Host.wrk_c, 0, 0, argv, 0) ) { fprintf(stderr, "play: posix_spawn: %d\r\n", errno); return 1; } @@ -3001,10 +3003,6 @@ main(c3_i argc, c3_free(bin_c); } - if ( !u3_Host.sef_c ) { - u3_Host.sef_c = u3_Host.dem_c; - } - if ( c3y == u3_Host.ops_u.dem ) { // In daemon mode, run the urbit as a background process, but don't // exit from the parent process until the ship is finished booting. diff --git a/pkg/vere/vere.h b/pkg/vere/vere.h index b28679ee7b..f97a76f142 100644 --- a/pkg/vere/vere.h +++ b/pkg/vere/vere.h @@ -329,8 +329,7 @@ c3_c* dir_c; // pier path (no trailing /) c3_d eve_d; // initial current snapshot c3_c* dem_c; // daemon executable path - c3_c* wrk_c; // worker executable name - c3_c* sef_c; // worker executable path + c3_c* wrk_c; // worker executable path c3_d now_d; // event tick uv_loop_t* lup_u; // libuv event loop u3_usig* sig_u; // signal list From 798aa3fa532c9a625cfe9c291107ed406ede741a Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 24 May 2024 12:57:36 -0400 Subject: [PATCH 19/32] play: remove print --- pkg/vere/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index c9ca613204..3173ef7d5a 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -2330,8 +2330,6 @@ _cw_play_fork() c3_i sat_i; c3_c *argv[] = { u3_Host.wrk_c, "play", u3_Host.dir_c }; // XX parameterize args - fprintf(stderr, "wrk_c: %s\r\n", u3_Host.wrk_c); - if ( 0 != posix_spawn(&pid, u3_Host.wrk_c, 0, 0, argv, 0) ) { fprintf(stderr, "play: posix_spawn: %d\r\n", errno); return 1; From d67090b6e59397782def36d0e281c85483aa20e4 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 24 May 2024 13:32:16 -0400 Subject: [PATCH 20/32] disk: parameterize lmdb map size --- pkg/vere/disk.c | 21 ++++++--------------- pkg/vere/main.c | 17 +++++++++++++++++ pkg/vere/vere.h | 1 + 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/pkg/vere/disk.c b/pkg/vere/disk.c index b60253fb1c..58cb2f822f 100644 --- a/pkg/vere/disk.c +++ b/pkg/vere/disk.c @@ -31,15 +31,6 @@ struct _u3_disk_walk { c3_o liv_o; }; -// for u3_lmdb_init() calls -static const size_t siz_i = -#if (defined(U3_CPU_aarch64) && defined(U3_OS_linux)) - // 500 GiB is as large as musl on aarch64 wants to allow - 0x7d00000000; -#else - 0x10000000000; -#endif - #undef VERBOSE_DISK #undef DISK_TRACE_JAM #undef DISK_TRACE_CUE @@ -680,7 +671,7 @@ u3_disk_save_meta_meta(c3_c* log_c, { MDB_env* dbm_u; - if ( 0 == (dbm_u = u3_lmdb_init(log_c, siz_i)) ) { + if ( 0 == (dbm_u = u3_lmdb_init(log_c, u3_Host.ops_u.siz_i)) ) { fprintf(stderr, "disk: failed to initialize meta-lmdb\r\n"); return c3n; } @@ -1240,7 +1231,7 @@ _disk_epoc_roll(u3_disk* log_u, c3_d epo_d) log_u->mdb_u = 0; // initialize db of new epoch - if ( 0 == (log_u->mdb_u = u3_lmdb_init(epo_c, siz_i)) ) { + if ( 0 == (log_u->mdb_u = u3_lmdb_init(epo_c, u3_Host.ops_u.siz_i)) ) { fprintf(stderr, "disk: failed to initialize database\r\n"); c3_free(log_u); goto fail3; @@ -1499,7 +1490,7 @@ _disk_migrate(u3_disk* log_u, c3_d eve_d) return c3n; } - if ( 0 == (log_u->mdb_u = u3_lmdb_init(tmp_c, siz_i)) ) { + if ( 0 == (log_u->mdb_u = u3_lmdb_init(tmp_c, u3_Host.ops_u.siz_i)) ) { fprintf(stderr, "disk: failed to initialize database at %s\r\n", tmp_c); return c3n; @@ -1533,7 +1524,7 @@ _disk_migrate(u3_disk* log_u, c3_d eve_d) strerror(errno)); } - if ( 0 == (log_u->mdb_u = u3_lmdb_init(epo_c, siz_i)) ) { + if ( 0 == (log_u->mdb_u = u3_lmdb_init(epo_c, u3_Host.ops_u.siz_i)) ) { fprintf(stderr, "disk: failed to initialize database at %s\r\n", epo_c); return c3n; @@ -1736,7 +1727,7 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d) snprintf(epo_c, 8192, "%s/0i%" PRIc3_d, log_u->com_u->pax_c, lat_d); // initialize latest epoch's db - if ( 0 == (log_u->mdb_u = u3_lmdb_init(epo_c, siz_i)) ) { + if ( 0 == (log_u->mdb_u = u3_lmdb_init(epo_c, u3_Host.ops_u.siz_i)) ) { fprintf(stderr, "disk: failed to initialize database at %s\r\n", epo_c); return _epoc_fail; @@ -1880,7 +1871,7 @@ u3_disk_init(c3_c* pax_c, u3_disk_cb cb_u) if ( c3y == exs_o ) { // load the old data.mdb file - if ( 0 == (log_u->mdb_u = u3_lmdb_init(log_c, siz_i)) ) { + if ( 0 == (log_u->mdb_u = u3_lmdb_init(log_c, u3_Host.ops_u.siz_i)) ) { fprintf(stderr, "disk: failed to initialize lmdb\r\n"); c3_free(log_u); return 0; diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 2222f87dd1..beac31ddde 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -297,6 +297,7 @@ _main_getopt(c3_i argc, c3_c** argv) { "swap-to", required_argument, NULL, 8 }, { "toss", required_argument, NULL, 9 }, { "behn-allow-blocked", no_argument, NULL, 10 }, + { "lmdb-map-size", required_argument, NULL, 12 }, // { NULL, 0, NULL, 0 }, }; @@ -340,6 +341,12 @@ _main_getopt(c3_i argc, c3_c** argv) u3_Host.ops_u.beb = c3y; break; } + case 12: { // lmdb-map-size + if ( 1 != sscanf(optarg, "%" SCNu32, &u3_Host.ops_u.siz_i) ) { + return c3n; + } + break; + } // special args // case c3__loom: { @@ -2991,6 +2998,16 @@ main(c3_i argc, u3_Host.bot_f = _stop_on_boot_completed_cb; } + if ( !u3_Host.ops_u.siz_i ) { + u3_Host.ops_u.siz_i = +#if (defined(U3_CPU_aarch64) && defined(U3_OS_linux)) + // 500 GiB is as large as musl on aarch64 wants to allow + 0x7d00000000; +#else + 0x10000000000; +#endif + } + #if 0 if ( 0 == getuid() ) { chroot(u3_Host.dir_c); diff --git a/pkg/vere/vere.h b/pkg/vere/vere.h index f97a76f142..b26ad4b27e 100644 --- a/pkg/vere/vere.h +++ b/pkg/vere/vere.h @@ -320,6 +320,7 @@ u3_even* vex_u; // --prop-*, boot enhancements c3_o beb; // --behn-allow-blocked + c3_z siz_i; // --lmdb-map-size } u3_opts; /* u3_host: entire host. From 41fa70ec38f36b2ccfe3d5ebd5d9304683640f6f Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 24 May 2024 15:15:22 -0400 Subject: [PATCH 21/32] cli: add `--lmdb-map-size` to subcommands; always init `siz_i`; use correct format specifier --- pkg/vere/main.c | 132 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 39 deletions(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index beac31ddde..24cf65746d 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -193,6 +193,14 @@ _main_init(void) u3_Host.ops_u.lut_y = 31; /* aka 2G */ u3_Host.ops_u.lom_y = 31; + u3_Host.ops_u.siz_i = +#if (defined(U3_CPU_aarch64) && defined(U3_OS_linux)) + // 500 GiB is as large as musl on aarch64 wants to allow + 0x7d00000000; +#else + 0x10000000000; +#endif + u3C.eph_c = 0; u3C.tos_w = 0; } @@ -342,7 +350,7 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case 12: { // lmdb-map-size - if ( 1 != sscanf(optarg, "%" SCNu32, &u3_Host.ops_u.siz_i) ) { + if ( 1 != sscanf(optarg, "%" SCNuMAX, &u3_Host.ops_u.siz_i) ) { return c3n; } break; @@ -1576,10 +1584,11 @@ _cw_info(c3_i argc, c3_c* argv[]) c3_w arg_w; static struct option lop_u[] = { - { "loom", required_argument, NULL, c3__loom }, - { "no-demand", no_argument, NULL, 6 }, - { "swap", no_argument, NULL, 7 }, - { "swap-to", required_argument, NULL, 8 }, + { "loom", required_argument, NULL, c3__loom }, + { "no-demand", no_argument, NULL, 6 }, + { "swap", no_argument, NULL, 7 }, + { "swap-to", required_argument, NULL, 8 }, + { "lmdb-map-size", required_argument, NULL, 9 }, { NULL, 0, NULL, 0 } }; @@ -1610,6 +1619,13 @@ _cw_info(c3_i argc, c3_c* argv[]) break; } + case 9: { // lmdb-map-size + if ( 1 != sscanf(optarg, "%" SCNuMAX, &u3_Host.ops_u.siz_i) ) { + exit(1); + } + break; + } + case '?': { fprintf(stderr, "invalid argument\r\n"); exit(1); @@ -1751,10 +1767,11 @@ _cw_cram(c3_i argc, c3_c* argv[]) c3_w arg_w; static struct option lop_u[] = { - { "loom", required_argument, NULL, c3__loom }, - { "no-demand", no_argument, NULL, 6 }, - { "swap", no_argument, NULL, 7 }, - { "swap-to", required_argument, NULL, 8 }, + { "loom", required_argument, NULL, c3__loom }, + { "no-demand", no_argument, NULL, 6 }, + { "swap", no_argument, NULL, 7 }, + { "swap-to", required_argument, NULL, 8 }, + { "lmdb-map-size", required_argument, NULL, 9 }, { NULL, 0, NULL, 0 } }; @@ -1785,6 +1802,13 @@ _cw_cram(c3_i argc, c3_c* argv[]) break; } + case 9: { // lmdb-map-size + if ( 1 != sscanf(optarg, "%" SCNuMAX, &u3_Host.ops_u.siz_i) ) { + exit(1); + } + break; + } + case '?': { fprintf(stderr, "invalid argument\r\n"); exit(1); @@ -1847,11 +1871,12 @@ _cw_queu(c3_i argc, c3_c* argv[]) c3_c* roc_c = 0; static struct option lop_u[] = { - { "loom", required_argument, NULL, c3__loom }, - { "no-demand", no_argument, NULL, 6 }, - { "swap", no_argument, NULL, 7 }, - { "swap-to", required_argument, NULL, 8 }, - { "replay-from", required_argument, NULL, 'r' }, + { "loom", required_argument, NULL, c3__loom }, + { "no-demand", no_argument, NULL, 6 }, + { "swap", no_argument, NULL, 7 }, + { "swap-to", required_argument, NULL, 8 }, + { "lmdb-map-size", required_argument, NULL, 9 }, + { "replay-from", required_argument, NULL, 'r' }, { NULL, 0, NULL, 0 } }; @@ -1882,6 +1907,13 @@ _cw_queu(c3_i argc, c3_c* argv[]) break; } + case 9: { // lmdb-map-size + if ( 1 != sscanf(optarg, "%" SCNuMAX, &u3_Host.ops_u.siz_i) ) { + exit(1); + } + break; + } + case 'r': { roc_c = strdup(optarg); } break; @@ -1955,11 +1987,12 @@ _cw_meld(c3_i argc, c3_c* argv[]) c3_w arg_w; static struct option lop_u[] = { - { "loom", required_argument, NULL, c3__loom }, - { "no-demand", no_argument, NULL, 6 }, - { "swap", no_argument, NULL, 7 }, - { "swap-to", required_argument, NULL, 8 }, - { "gc-early", no_argument, NULL, 9 }, + { "loom", required_argument, NULL, c3__loom }, + { "no-demand", no_argument, NULL, 6 }, + { "swap", no_argument, NULL, 7 }, + { "swap-to", required_argument, NULL, 8 }, + { "gc-early", no_argument, NULL, 9 }, + { "lmdb-map-size", required_argument, NULL, 10 }, { NULL, 0, NULL, 0 } }; @@ -1995,6 +2028,13 @@ _cw_meld(c3_i argc, c3_c* argv[]) break; } + case 10: { // lmdb-map-size + if ( 1 != sscanf(optarg, "%" SCNuMAX, &u3_Host.ops_u.siz_i) ) { + exit(1); + } + break; + } + case '?': { fprintf(stderr, "invalid argument\r\n"); exit(1); @@ -2123,11 +2163,12 @@ _cw_pack(c3_i argc, c3_c* argv[]) c3_w arg_w; static struct option lop_u[] = { - { "loom", required_argument, NULL, c3__loom }, - { "no-demand", no_argument, NULL, 6 }, - { "swap", no_argument, NULL, 7 }, - { "swap-to", required_argument, NULL, 8 }, - { "gc-early", no_argument, NULL, 9 }, + { "loom", required_argument, NULL, c3__loom }, + { "no-demand", no_argument, NULL, 6 }, + { "swap", no_argument, NULL, 7 }, + { "swap-to", required_argument, NULL, 8 }, + { "gc-early", no_argument, NULL, 9 }, + { "lmdb-map-size", required_argument, NULL, 10 }, { NULL, 0, NULL, 0 } }; @@ -2163,6 +2204,13 @@ _cw_pack(c3_i argc, c3_c* argv[]) break; } + case 10: { // lmdb-map-size + if ( 1 != sscanf(optarg, "%" SCNuMAX, &u3_Host.ops_u.siz_i) ) { + exit(1); + } + break; + } + case '?': { fprintf(stderr, "invalid argument\r\n"); exit(1); @@ -2504,10 +2552,11 @@ _cw_chop(c3_i argc, c3_c* argv[]) c3_w arg_w; static struct option lop_u[] = { - { "loom", required_argument, NULL, c3__loom }, - { "no-demand", no_argument, NULL, 6 }, - { "swap", no_argument, NULL, 7 }, - { "swap-to", required_argument, NULL, 8 }, + { "loom", required_argument, NULL, c3__loom }, + { "no-demand", no_argument, NULL, 6 }, + { "swap", no_argument, NULL, 7 }, + { "swap-to", required_argument, NULL, 8 }, + { "lmdb-map-size", required_argument, NULL, 9 }, { NULL, 0, NULL, 0 } }; @@ -2538,6 +2587,13 @@ _cw_chop(c3_i argc, c3_c* argv[]) break; } + case 9: { // lmdb-map-size + if ( 1 != sscanf(optarg, "%" SCNuMAX, &u3_Host.ops_u.siz_i) ) { + exit(1); + } + break; + } + case '?': { fprintf(stderr, "invalid argument\r\n"); exit(1); @@ -2585,7 +2641,8 @@ _cw_roll(c3_i argc, c3_c* argv[]) c3_w arg_w; static struct option lop_u[] = { - { "loom", required_argument, NULL, c3__loom }, + { "loom", required_argument, NULL, c3__loom }, + { "lmdb-map-size", required_argument, NULL, 6 }, { NULL, 0, NULL, 0 } }; @@ -2593,6 +2650,13 @@ _cw_roll(c3_i argc, c3_c* argv[]) while ( -1 != (ch_i=getopt_long(argc, argv, "", lop_u, &lid_i)) ) { switch ( ch_i ) { + case 6: { // lmdb-map-size + if ( 1 != sscanf(optarg, "%" SCNuMAX, &u3_Host.ops_u.siz_i) ) { + exit(1); + } + break; + } + case c3__loom: { if (_main_readw_loom("loom", &u3_Host.ops_u.lom_y)) { exit(1); @@ -2998,16 +3062,6 @@ main(c3_i argc, u3_Host.bot_f = _stop_on_boot_completed_cb; } - if ( !u3_Host.ops_u.siz_i ) { - u3_Host.ops_u.siz_i = -#if (defined(U3_CPU_aarch64) && defined(U3_OS_linux)) - // 500 GiB is as large as musl on aarch64 wants to allow - 0x7d00000000; -#else - 0x10000000000; -#endif - } - #if 0 if ( 0 == getuid() ) { chroot(u3_Host.dir_c); From b0de3aac5511ef8f1a7ea7706ab08653b7b9c225 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Sat, 25 May 2024 21:11:47 -0400 Subject: [PATCH 22/32] play: add args to `_cw_play_fork` --- pkg/vere/main.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 3173ef7d5a..0bef9e4b1e 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -2324,11 +2324,28 @@ _cw_play_impl(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) /* _cw_play_fork(): spawn a subprocess for event replay. */ static c3_i -_cw_play_fork() +_cw_play_fork(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) { pid_t pid; c3_i sat_i; - c3_c *argv[] = { u3_Host.wrk_c, "play", u3_Host.dir_c }; // XX parameterize args + c3_c eve_c[21], sap_c[21] = { 0 }; + sprintf(eve_c, "%" PRIu64, eve_d); + sprintf(sap_c, "%" PRIu64, sap_d); + // if ( 0 < sprintf(eve_c, "%" PRIu64, eve_d) || + // 0 < sprintf(sap_c, "%" PRIu64, sap_d) ) + // { + // fprintf(stderr, "play: error parsing args\r\n"); + // return 1; + // } + c3_c *argv[] = { + u3_Host.wrk_c, "play", u3_Host.dir_c, + "--replay-to", eve_c, + "--snap-at", sap_c, + _(mel_o) ? "--auto-meld" : 0, // + _(sof_o) ? "--soft-mugs" : 0, // + _(ful_o) ? "--full" : 0, // XX + 0 + }; if ( 0 != posix_spawn(&pid, u3_Host.wrk_c, 0, 0, argv, 0) ) { fprintf(stderr, "play: posix_spawn: %d\r\n", errno); @@ -3136,7 +3153,7 @@ main(c3_i argc, // we need the current snapshot's latest event number to // validate whether we can execute disk migration if ( u3_Host.ops_u.nuu == c3n ) { - c3_i sat_i = _cw_play_fork(); + c3_i sat_i = _cw_play_fork(0, 0, c3n, c3n, c3y); if ( sat_i ) { fprintf(stderr, "play: replay failed: %d\r\n", sat_i); exit(sat_i); From 5ba82e80b4c4c5ad2fc246bc3581831a2d6208ec Mon Sep 17 00:00:00 2001 From: Pyry Kovanen Date: Mon, 27 May 2024 16:02:16 +0300 Subject: [PATCH 23/32] main: restore SIGTSTP handler after replay --- pkg/vere/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 2222f87dd1..37de90f882 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -3111,6 +3111,7 @@ main(c3_i argc, // validate whether we can execute disk migration if ( u3_Host.ops_u.nuu == c3n ) { _cw_play_impl(0, 0, c3n, c3n, c3n); + signal(SIGTSTP, _stop_exit); // XX unmap loom, else parts of the snapshot could be left in memory } From 8dd289942cc7ff008f99b3cb1df70f65435eeada Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Tue, 28 May 2024 10:55:29 -0400 Subject: [PATCH 24/32] play: produce args better --- pkg/vere/main.c | 53 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 0bef9e4b1e..047b511290 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -2328,25 +2328,46 @@ _cw_play_fork(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) { pid_t pid; c3_i sat_i; + c3_c eve_c[21], sap_c[21] = { 0 }; - sprintf(eve_c, "%" PRIu64, eve_d); - sprintf(sap_c, "%" PRIu64, sap_d); - // if ( 0 < sprintf(eve_c, "%" PRIu64, eve_d) || - // 0 < sprintf(sap_c, "%" PRIu64, sap_d) ) - // { - // fprintf(stderr, "play: error parsing args\r\n"); - // return 1; - // } - c3_c *argv[] = { - u3_Host.wrk_c, "play", u3_Host.dir_c, - "--replay-to", eve_c, - "--snap-at", sap_c, - _(mel_o) ? "--auto-meld" : 0, // - _(sof_o) ? "--soft-mugs" : 0, // - _(ful_o) ? "--full" : 0, // XX - 0 + if ( 0 > sprintf(eve_c, "%" PRIu64, eve_d) || + 0 > sprintf(sap_c, "%" PRIu64, sap_d) ) + { + fprintf(stderr, "play: error parsing args\r\n"); + return 1; + } + + c3_c *argv[11] = { + u3_Host.wrk_c, + "play", + u3_Host.dir_c, + "--replay-to", + eve_c, + "--snap-at", + sap_c, }; + c3_z i = 7; + + if _(mel_o) { + argv[i++] = "--auto-meld"; + } + + if _(sof_o) { + argv[i++] = "--soft-mugs"; + } + + if _(ful_o) { + argv[i++] = "--full"; + } + + argv[i] = NULL; + + for (c3_i j = 0; j < i; j++) { + fprintf(stderr, "%s ", argv[j]); + } + fprintf(stderr, "\r\n"); + if ( 0 != posix_spawn(&pid, u3_Host.wrk_c, 0, 0, argv, 0) ) { fprintf(stderr, "play: posix_spawn: %d\r\n", errno); return 1; From da773cf6b2f36b91832ffe3d91c330470c740e59 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 30 May 2024 12:31:37 -0400 Subject: [PATCH 25/32] play: serf commits sudoku when king dies --- pkg/vere/main.c | 65 +++++++++++++++++++++++++++++++++++++++---------- pkg/vere/mars.c | 1 + 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 047b511290..4e7ae85b45 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -18,6 +18,7 @@ #include "db/lmdb.h" #include "getopt.h" #include "libgen.h" +#include "pthread.h" #include "spawn.h" #include "ca_bundle.h" @@ -2321,14 +2322,31 @@ _cw_play_impl(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) return pay_d; } +/* _cw_play_fork_heed(): wait for EOF on STDIN or until canceled. +*/ +void* _cw_play_fork_heed(void* arg) { + c3_c buf[1]; + c3_zs red; + + do { + pthread_testcancel(); + red = read(STDIN_FILENO, buf, sizeof(buf)); + if ( 0 == red ) { + fprintf(stderr, "play: god save the king! committing sudoku...\r\n"); + exit(1); + } + } while ( 0 < red ); + + return NULL; +} + /* _cw_play_fork(): spawn a subprocess for event replay. */ static c3_i _cw_play_fork(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) { - pid_t pid; - c3_i sat_i; - + // prepare args + // c3_c eve_c[21], sap_c[21] = { 0 }; if ( 0 > sprintf(eve_c, "%" PRIu64, eve_d) || 0 > sprintf(sap_c, "%" PRIu64, sap_d) ) @@ -2348,31 +2366,47 @@ _cw_play_fork(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) }; c3_z i = 7; - if _(mel_o) { argv[i++] = "--auto-meld"; } - if _(sof_o) { argv[i++] = "--soft-mugs"; } - if _(ful_o) { argv[i++] = "--full"; } - argv[i] = NULL; - for (c3_i j = 0; j < i; j++) { - fprintf(stderr, "%s ", argv[j]); + // prepare a pipe for ipc with the subprocess + // + c3_i pipefd[2]; + if ( 0 != pipe(pipefd) ) { + fprintf(stderr, "play: failed to open pipe\r\n"); + return 1; } - fprintf(stderr, "\r\n"); - if ( 0 != posix_spawn(&pid, u3_Host.wrk_c, 0, 0, argv, 0) ) { - fprintf(stderr, "play: posix_spawn: %d\r\n", errno); - return 1; + // set the child process' stdin to read from the pipe + // + posix_spawn_file_actions_t action; + posix_spawn_file_actions_init(&action); + posix_spawn_file_actions_addclose(&action, pipefd[1]); + posix_spawn_file_actions_adddup2(&action, pipefd[0], STDIN_FILENO); + + // spawn a new serf process and call its play subcommand + // + pid_t pid; + if ( 0 != posix_spawn(&pid, u3_Host.wrk_c, &action, 0, argv, 0) ) { + fprintf(stderr, "play: posix_spawn: %d\r\n", errno); + return 1; } + // close the read end of the pipe in the parent + // + close(pipefd[0]); + + // wait for the child to exit + // + c3_i sat_i; if ( -1 == waitpid(pid, &sat_i, 0) ) { fprintf(stderr, "play: waitpid: %d\r\n", errno); return 1; @@ -2473,9 +2507,14 @@ _cw_play(c3_i argc, c3_c* argv[]) exit(1); } + pthread_t ted; + pthread_create(&ted, NULL, _cw_play_fork_heed, NULL); + if ( !_cw_play_impl(eve_d, sap_d, mel_o, sof_o, ful_o) ) { fprintf(stderr, "mars: nothing to do!\r\n"); } + + pthread_cancel(ted); } /* _cw_prep(): prepare for upgrade diff --git a/pkg/vere/mars.c b/pkg/vere/mars.c index db9056a0ab..dc592093b4 100644 --- a/pkg/vere/mars.c +++ b/pkg/vere/mars.c @@ -384,5 +384,6 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d) u3l_log("---------------- playback complete ----------------"); u3m_save(); + fprintf(stderr, "mars: play finishing\r\n"); return pay_d; } From 5f41711ce2a9f37a661df91cf32bee81414338bb Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 30 May 2024 12:34:11 -0400 Subject: [PATCH 26/32] play: flip loob --- pkg/vere/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 4e7ae85b45..0fd9609f57 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -3213,7 +3213,7 @@ main(c3_i argc, // we need the current snapshot's latest event number to // validate whether we can execute disk migration if ( u3_Host.ops_u.nuu == c3n ) { - c3_i sat_i = _cw_play_fork(0, 0, c3n, c3n, c3y); + c3_i sat_i = _cw_play_fork(0, 0, c3n, c3n, c3n); if ( sat_i ) { fprintf(stderr, "play: replay failed: %d\r\n", sat_i); exit(sat_i); From 585fad2a190d9826a39af174c003630bdd06554c Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 30 May 2024 12:40:08 -0400 Subject: [PATCH 27/32] mars: remove printf --- pkg/.DS_Store | Bin 0 -> 6148 bytes pkg/vere/mars.c | 1 - 2 files changed, 1 deletion(-) create mode 100644 pkg/.DS_Store diff --git a/pkg/.DS_Store b/pkg/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a22dbf756329df139a451c4e0b25a8948eadc384 GIT binary patch literal 6148 zcmeHK%}T>S5Z<-XrW7Fug&r5Y7OYx|;w8lT0!H+pQWFw17_%j5n?ot&tS{t~_&m<+ zZp31}ir5+0{pNQ!`$6`HF~+@VbikOy7_*@va#U6bx>traOfn+JF~YJKhp7y~elxMZ z4*2aBo3WVXEdKia;W$l-Nw4?LHyYOFR?}|UZTrrDl%+ojCey+T@*A`+rA)(G55lV? zE=SJJnan0ZlEt|yNTL{0Zm*LplBFl7SyZT6UkB`#-5NQa`TY2>*A@Lif6*256Qv&w z7K@g>ySIOOF?vd$Gx?$k<-oU+ZG$zug7UeZnV)B=%pSm3=hu0J!~iis3=jkB%YZo( z?DqOnKr1H(h=Cs%!2Ll$Lv#&R8r9YT9bTU?ZXu$8j&BJ>VbC>LX@m#}*QJ2El$$38 z*X7_BCeJlkY1HM6tC?XOGjsiT;c9m93zg2etC4zQfEZY2prK6%&;N7yWmZ1&mrKYZ z28e-w#sIg5{?LO(nX~oV^6;z`(C(q3U|xj^28PNN3)CUcHCSoHQP8i- Q0qG*32%(M`_yq<&050}QVgLXD literal 0 HcmV?d00001 diff --git a/pkg/vere/mars.c b/pkg/vere/mars.c index dc592093b4..db9056a0ab 100644 --- a/pkg/vere/mars.c +++ b/pkg/vere/mars.c @@ -384,6 +384,5 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d) u3l_log("---------------- playback complete ----------------"); u3m_save(); - fprintf(stderr, "mars: play finishing\r\n"); return pay_d; } From 5212f9a266ddd738959311444e031d7591555ccd Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Wed, 5 Jun 2024 11:30:16 -0400 Subject: [PATCH 28/32] play: handle termination cases --- pkg/vere/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/vere/main.c b/pkg/vere/main.c index 0fd9609f57..42b344bb7e 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -2412,7 +2412,21 @@ _cw_play_fork(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o) return 1; } - return WEXITSTATUS(sat_i); + if ( WIFEXITED(sat_i) ) { + c3_i ret_i = WEXITSTATUS(sat_i); + if ( 0 != ret_i ) { + fprintf(stderr, "play: exited with %d\r\n", ret_i); + } + return ret_i; + } + else if ( WIFSIGNALED(sat_i) ) { + fprintf(stderr, "play: terminated by signal %d\r\n", WTERMSIG(sat_i)); + return 1; + } + else { + fprintf(stderr, "play: strange termination\r\n"); + return 1; + } } /* _cw_play(): replay events, but better. From 9ab5c7e6b7289fc7c0da5660798f35ae36a51ffa Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 7 Jun 2024 11:16:31 -0400 Subject: [PATCH 29/32] ames: free packet on successful galaxy dns resolution --- pkg/vere/io/ames.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 7cd462b7d6..5400c26887 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -1135,6 +1135,7 @@ _ames_czar_cb(uv_getaddrinfo_t* adr_u, if ( sas_i == 0 ) { _ames_czar_here(pac_u, now, (struct sockaddr_in *)rai_u->ai_addr); + _ames_pact_free(pac_u); } else { _ames_czar_gone(pac_u->sam_u, now, pac_u->rut_u.imp_y, From 55eb4852cc608785ea71f6ddd5baadaac10caf2b Mon Sep 17 00:00:00 2001 From: ~dozreg-toplud Date: Thu, 20 Jun 2024 16:23:37 -0400 Subject: [PATCH 30/32] fix nock 9 crashing pier if axis is cell --- pkg/noun/nock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/noun/nock.c b/pkg/noun/nock.c index 452b04c309..eb459d17f7 100644 --- a/pkg/noun/nock.c +++ b/pkg/noun/nock.c @@ -1400,7 +1400,7 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) case 9: u3x_cell(arg, &hed, &tel); - if ( (1 == hed) || (3 == u3qc_cap(hed)) ) { + if ( (1 == hed) || (3 == u3qc_cap(u3x_atom(hed))) ) { u3_noun mac = u3nq(7, u3k(tel), 2, u3nt(u3nc(0, 1), 0, u3k(hed))); tot_w += _n_comp(ops, mac, los_o, tel_o); u3z(mac); From 00f659e77b48d3d40cd0053351f119e410abf0aa Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 24 Jun 2024 15:54:58 +0300 Subject: [PATCH 31/32] ames: more accurate condition for cleaning up libnatpmp handle --- pkg/vere/io/ames.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 2da7f743c8..12466e0054 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -3202,7 +3202,8 @@ _ames_io_exit(u3_auto* car_u) uv_close((uv_handle_t*)&sam_u->sun_u.tim_u, 0); uv_close((uv_handle_t*)&sam_u->nat_u.tim_u, 0); - if (uv_is_active((uv_handle_t*)&sam_u->nat_u.pol_u)) { + uv_handle_type handle = uv_handle_get_type((uv_handle_t *)&sam_u->nat_u.pol_u); + if ( UV_UNKNOWN_HANDLE != handle) { uv_close((uv_handle_t*)&sam_u->nat_u.pol_u, 0); } } From 34809cd534b52156fd848d634e888b6bde7cffea Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Mon, 24 Jun 2024 11:26:26 -0400 Subject: [PATCH 32/32] remove `pkg/.DS_Store` --- pkg/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 pkg/.DS_Store diff --git a/pkg/.DS_Store b/pkg/.DS_Store deleted file mode 100644 index a22dbf756329df139a451c4e0b25a8948eadc384..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z<-XrW7Fug&r5Y7OYx|;w8lT0!H+pQWFw17_%j5n?ot&tS{t~_&m<+ zZp31}ir5+0{pNQ!`$6`HF~+@VbikOy7_*@va#U6bx>traOfn+JF~YJKhp7y~elxMZ z4*2aBo3WVXEdKia;W$l-Nw4?LHyYOFR?}|UZTrrDl%+ojCey+T@*A`+rA)(G55lV? zE=SJJnan0ZlEt|yNTL{0Zm*LplBFl7SyZT6UkB`#-5NQa`TY2>*A@Lif6*256Qv&w z7K@g>ySIOOF?vd$Gx?$k<-oU+ZG$zug7UeZnV)B=%pSm3=hu0J!~iis3=jkB%YZo( z?DqOnKr1H(h=Cs%!2Ll$Lv#&R8r9YT9bTU?ZXu$8j&BJ>VbC>LX@m#}*QJ2El$$38 z*X7_BCeJlkY1HM6tC?XOGjsiT;c9m93zg2etC4zQfEZY2prK6%&;N7yWmZ1&mrKYZ z28e-w#sIg5{?LO(nX~oV^6;z`(C(q3U|xj^28PNN3)CUcHCSoHQP8i- Q0qG*32%(M`_yq<&050}QVgLXD