Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection established and closed callbacks #40

Merged
merged 7 commits into from Sep 18, 2023

Conversation

tewinget
Copy link
Collaborator

@tewinget tewinget commented Sep 6, 2023

builds on #39

tewinget and others added 3 commits September 14, 2023 14:09
Connection established is called when the connection has confirmed the
TLS handshake; server does this on ngtcp2 handshake "complete" after
sending the final packet for the handshake to the client which will then
call ngtcp2 handshake "confirmed".

Connection closed callback is called when a connection closes for any
reason, including that it timed out and was never actually established
(thus acting as a "connection attempt failed" signal as well).

In order to have a connection timeout call connection closed, a
handshake timeout needed to be set in ngtcp2 (the default was
funtionally infinite).  5s should be sufficient, but this can be made
configurable at a later time.

Tests which were confirming connection establishment or failure have
been updated to use the new callbacks.
- no structs for open/close callbacks
- added `error.hpp`
- reworked bool_waiter in unit tests
- little bit of template magic from jason
- Sometimes when ngtcp2 does not want a connection close packet written, we delete the connection from the endpoint's internal map
- In these cases, we still want to notify the calling endpoint that the connection was closed
@tewinget tewinget force-pushed the conn-state-callbacks branch 2 times, most recently from e7d4074 to 5e618a4 Compare September 18, 2023 17:45
src/connection.cpp Outdated Show resolved Hide resolved
src/endpoint.cpp Outdated Show resolved Hide resolved
For whatever reason, sometimes ngtcp2 gives a time point in the past
when asked when to wake it up; this was resulting in us never waking it.
Normally this is fine, as an incoming packet wakes it and we do't notice,
but if no packets come in, new connections we make can fail to timeout
correctly.  This works around that issue by doing a 0µs timeout if the
timeout would be negative.
we need to keep 'closing' connections around for a bit so we can drop
any straggler packets.  also, if we 'drop connection' here we get multiple
calls to the connection closed callback, which is not ideal
also use ngtcp2_ccerr_set_application_error rather then ...set_liberr if the
close is an application requested close rather than protocol error or similar

supply connection close error code to user-defined connection closed cb

adds connection close callback test
src/endpoint.cpp Outdated Show resolved Hide resolved
src/endpoint.cpp Outdated Show resolved Hide resolved
src/endpoint.cpp Outdated Show resolved Hide resolved
src/endpoint.cpp Outdated Show resolved Hide resolved
@tewinget tewinget merged commit 2c6b877 into oxen-io:dev Sep 18, 2023
1 check passed
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.

None yet

3 participants