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

Rework the transport upgrade API. #1240

Merged
merged 5 commits into from
Sep 10, 2019
Merged

Commits on Sep 5, 2019

  1. Rework the transport upgrade API.

    ALthough transport upgrades must follow a specific pattern
    in order fot the resulting transport to be usable with a
    `Network` or `Swarm`, that pattern is currently not well
    reflected in the transport upgrade API. Rather, transport
    upgrades are rather laborious and involve non-trivial code
    duplication.
    
    This commit introduces a `transport::upgrade::Builder` that is
    obtained from `Transport::upgrade`. The `Builder` encodes the
    previously implicit rules for transport upgrades:
    
      1. Authentication upgrades must happen first.
      2. Any number of upgrades may follow.
      3. A multiplexer upgrade must happen last.
    
    Since multiplexing is the last (regular) transport upgrade (because
    that upgrade yields a `StreamMuxer` which is no longer a `AsyncRead`
    / `AsyncWrite` resource, which the upgrade process is based on),
    the upgrade starts with `Transport::upgrade` and ends with
    `Builder::multiplex`, which drops back down to the `Transport`,
    providing a fluent API.
    
    Authentication and multiplexer upgrades must furthermore adhere
    to a minimal contract w.r.t their outputs:
    
      1. An authentication upgrade is given an (async) I/O resource `C`
         and must produce a pair `(I, D)` where `I: ConnectionInfo` and
         `D` is a new (async) I/O resource `D`.
      2. A multiplexer upgrade is given an (async) I/O resource `C`
         and must produce a `M: StreamMuxer`.
    
    To that end, two changes to the `secio` and `noise` protocols have been
    made:
    
      1. The `secio` upgrade now outputs a pair of `(PeerId, SecioOutput)`.
         The former implements `ConnectionInfo` and the latter `AsyncRead` /
         `AsyncWrite`, fulfilling the `Builder` contract.
    
      2. A new `NoiseAuthenticated` upgrade has been added that wraps around
         any noise upgrade (i.e. `NoiseConfig`) and has an output of
         `(PeerId, NoiseOutput)`, i.e. it checks if the `RemoteIdentity` from
         the handshake output is an `IdentityKey`, failing if that is not the
         case. This is the standard upgrade procedure one wants for integrating
         noise with libp2p-core/swarm.
    Roman S. Borschel committed Sep 5, 2019
    Configuration menu
    Copy the full SHA
    1d31ae6 View commit details
    Browse the repository at this point in the history
  2. Cleanup

    Roman S. Borschel committed Sep 5, 2019
    Configuration menu
    Copy the full SHA
    14faf43 View commit details
    Browse the repository at this point in the history

Commits on Sep 9, 2019

  1. Add a new integration test.

    Roman S. Borschel committed Sep 9, 2019
    Configuration menu
    Copy the full SHA
    ef1c49c View commit details
    Browse the repository at this point in the history

Commits on Sep 10, 2019

  1. Add missing license.

    Roman S. Borschel committed Sep 10, 2019
    Configuration menu
    Copy the full SHA
    620a549 View commit details
    Browse the repository at this point in the history
  2. Merge branch 'master' into upgrade-builder

    Roman S. Borschel committed Sep 10, 2019
    Configuration menu
    Copy the full SHA
    5c0e6d3 View commit details
    Browse the repository at this point in the history