Skip to content

Commit

Permalink
Revert "ames: add libnatpmp for automatic port forwarding"
Browse files Browse the repository at this point in the history
  • Loading branch information
pkova authored May 1, 2024
1 parent 639d032 commit 385bdf9
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 80 deletions.
9 changes: 0 additions & 9 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file.
8 changes: 0 additions & 8 deletions bazel/third_party/natpmp/natpmp.BUILD

This file was deleted.

1 change: 0 additions & 1 deletion pkg/vere/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ vere_library(
"@lmdb",
"@openssl",
"@uv",
"@natpmp",
] + select({
"@platforms//os:macos": [],
"@platforms//os:linux": [
Expand Down
62 changes: 0 additions & 62 deletions pkg/vere/io/ames.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "ur.h"

#include "zlib.h"
#include "natpmp.h"

#include <ent.h>

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 385bdf9

Please sign in to comment.