Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add public
Endpoint::new
constructor
This can be used to construct new peer endpoints, which is positioned as the 'default' by naming the method simply `new`. This roughly follows the logic of the crate private `new` that it replaces (renamed to `_new`, to be removed in future), with some differences: - Errors that occur when establishing the public address or port forwarding are returned to the user. As a library, it's been deemed preferable that callers handle this and retry, with the relevant configuration altered, if desired. - Configured external IP/port are now combined with the steps to query our public address from a peer. This is intended to simplify the logic around public address handling – there's now a single sequence of steps: 1. Start with `public_addr = local_addr`. 2. If we bootstrapped to a peer, get our `visible_addr` from them. 3. If we configured a specific `external_ip`, override that in `public_addr`. 1. Otherwise, if we have a `visible_addr`, override the IP in `public_addr`. 4. If we configured a specific `external_port`, override that in `public_addr`. 1. Otherwise, if we have a `visible_addr`, override the port in `public_addr`. Still not exactly "simple", but easier to follow. - If we bootstrapped to a peer, we always test reachability of our determined `public_addr`. There's no reason not to do this – even if the endpoint is local-only, it verifies the expectation of the caller that the given contacts can reach us (which will work if they are also local).
- Loading branch information