Skip to content

Commit

Permalink
feat: Add public Endpoint::new constructor
Browse files Browse the repository at this point in the history
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
Chris Connelly authored and connec committed Aug 27, 2021
1 parent d9413de commit c448df2
Show file tree
Hide file tree
Showing 6 changed files with 486 additions and 80 deletions.
Loading

0 comments on commit c448df2

Please sign in to comment.