Skip to content

ames: libnatpmp for real this time#646

Merged
pkova merged 6 commits intodevelopfrom
pkova/natpmpv2
Jun 24, 2024
Merged

ames: libnatpmp for real this time#646
pkova merged 6 commits intodevelopfrom
pkova/natpmpv2

Conversation

@pkova
Copy link
Copy Markdown
Collaborator

@pkova pkova commented May 10, 2024

This is #593 that got reverted in #644 because it broke urbit/urbit CI. This PR fixes the issue which was unconditionally calling uv_poll_init on a socket that was initialized with initnatpmp without checking if initnatpmp returned an error first.

pkova and others added 2 commits May 10, 2024 17:00
Same as urbit/urbit#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.
@pkova pkova requested a review from a team as a code owner May 10, 2024 14:21
Copy link
Copy Markdown
Collaborator

@joemfb joemfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR never disposes of this new uv_poll_t and uv_timer_t handles. It should uv_close() them in _ames_io_exit(). The fact that we can't unconditionally init the uv_poll_t means we need some state to tell us if we should close it. It might be best to just heap allocate it so we can check if the pointer is null.

Comment thread pkg/vere/io/ames.c Outdated
return;
}

uv_poll_init(u3L, &sam_u->nat_u.pol_u, sam_u->nat_u.req_u.s);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like uv_poll_init() is categorically different from other libuv init functions, and we need to check for errors here.

Comment thread pkg/vere/io/ames.c
natpmp_cb(uv_poll_t* handle,
c3_i status,
c3_i events)
{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not checking status for errors here. And I'm not sure if readnatpmpresponseorretry() can/will handle all cases for us.

Comment thread pkg/vere/io/ames.c

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);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is quite right -- the definition of "active" for different handle types is fairly involved. What we actually want is just "has this handle every been initialized?". We can obviously track that ourselves, but I think this will also work:

if ( UV_UNKNOWN_HANDLE != uv_handle_get_type(&sam_u->nat_u.pol_u) ) {
  uv_close(...)
}

UV_UNKNOWN_HANDLE is 0, and we zero-initialize the uv_poll_t struct by virtue of allocating the u3_ames struct with c3_calloc().

@pkova pkova merged commit 2080cfb into develop Jun 24, 2024
@pkova pkova deleted the pkova/natpmpv2 branch June 24, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants