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

Follow-up commits for AutoNATv2 #2

Merged

Conversation

thomaseizinger
Copy link

Opening this as a separate PR because I don't have permissions to push to your branch directly.

I had some time on the plane and the WiFi connection was shit so I figured it is a better use of time to just write some code instead of more comments :)
Have a read through and let me know what you think. For most commits, I explained the reasoning of the change but if anything is unclear, please let me know.

Through the use of let-else, we can early-exit on the unhappy-path.
We also update the log message to remove the "cause" as there can
be a multitude of reasons, why we received a nonce that we didn't
expect, e.g. it could also be a bug in the client or the server
implementation so we don't want to jump to conclusions here.
Fix the event handling to only update the flag for the connection
that the event originated from.
Connections are always scoped to a particular peer and the PeerId
is reported with every event sent from the handler to the behaviour.
We don't need to include it in the event.
This is now handled in the `AddressInfo` struct.
We filter straight after this for the same conditions.
An AutoNAT server will always only dial a single address. Thus,
we are more likely to get a quicker results for all our candidates
if we send each candidate to a different server.
We only ever insert into the `peer_info` map for established
connections. We either establish a connection or receive a `DialFailure`.

Thus, there will never be any state in `peer_info` for a failed
connection so there is nothing to be cleaned up.
The nonce of a probe is essentially like a primary key that is
decided by the client. Thus, any event emitted by the handler
should be indexed by the provided nonce.

We can achieve this by using a `FuturesMap` instead of a `FuturesSet`.
This gives us access to the nonce even in the case that the actual
protocol times out.

With the nonce in place, we had to re-model the event returned to
the behaviour. Most importantly. we need to separate the different
kinds of errors:

- Complete execution of the protocol but address is not reachable
- Protocol was aborted mid-way
- Server does not support the protocol

We can't really do anything if the protocols is aborted so we just
represent this case with an `io::Error` that gets logged further up.

As a result, this means we can remove the `Option` from the event
emitted to the user and _always_ give them a `Multiaddr`.
Copy link
Owner

@umgefahren umgefahren left a comment

Choose a reason for hiding this comment

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

That looks very good to me. Thanks for the changes. It sped up the process.

}

// FIXME: We don't want test-only APIs in our public API.
Copy link
Owner

Choose a reason for hiding this comment

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

I tried using #[cfg(test)]. But that didn't work in integration tests.

@umgefahren umgefahren merged commit 88b1092 into umgefahren:implement-autonat-v2 Dec 30, 2023
22 of 69 checks 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.

2 participants