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

Adding the rest of WebTransport into Kestrel #42097

Merged

Conversation

Daniel-Genkin-MS-2
Copy link
Contributor

@Daniel-Genkin-MS-2 Daniel-Genkin-MS-2 commented Jun 8, 2022

This is step two in my implementation of WebTransport support in Kestrel. This PR makes WebTransport functional and will provide a basic API for using it. Step three will be integration tests and maybe adding more features.

Goals of the PR

This PR builds upon my previous one (#41877 ) to add an API that interfaces with the existing Http3 layer in Kestrel and allows the application layer to:

  • Receive a WebTransport session
  • Open and receive/accept streams
  • Send and Receive data over the streams
  • Add some unit tests to support the new functionality
  • Add a new sample app to show how to use WebTransport in Kestrel

Non-Goals of this PR

  • Datagrams (hopefully will be added in some future PRs but it will require substantial amounts of work)
  • Integration/Functional tests (these will be added in a follow up PR. The testing infrastructure is not setup yet, so it will add significant scope to this PR if it were to be done here)

Non-goals are tracked in #42788

Inadvertent results of the PR

#42097 (comment)

How to use:

C#: https://github.com/dotnet/aspnetcore/blob/c5e66c255c0254a9be191ee53031cec6b79def48/docs/WebTransport.md
JS: #42097 (comment)

OR

Use the interactive sample called WebTransportInteractiveSample in src\Middleware\WebTransport\samples\WebTransportInteractiveSampleApp

Contributes to: #39583

@ghost ghost added the area-runtime label Jun 8, 2022
@Daniel-Genkin-MS-2 Daniel-Genkin-MS-2 changed the title Adding the rest of WebTransport into Kestrel [WIP] Adding the rest of WebTransport into Kestrel Jun 8, 2022
@Daniel-Genkin-MS-2
Copy link
Contributor Author

Daniel-Genkin-MS-2 commented Jun 10, 2022

Start a webtransport connection

  1. Start the WebTransportSampleApp
  2. Go to file:///C:/users/ in edge or chrome (or some other local directory to avoid CORS errors)
  3. Open devtools and execute commands

Supported JS client operations

  1. Create a webtransport connection
let CERTIFICATE = ""; // TODO UPDATE THIS to the certificate hash that the sample app prints out

let encoder = new TextEncoder('utf-8');

let transport = new WebTransport("https://127.0.0.1:5007", {
    serverCertificateHashes:[
      {
            algorithm: "sha-256",
            value: Uint8Array.from(atob(CERTIFICATE), c => c.charCodeAt(0))
        }]
    })

await transport.ready;
  1. Create a unidirectional stream and send data
const stream1 = await transport.createUnidirectionalStream();
const writer1 = stream1.getWriter();
writer1.write(new Uint8Array([65, 66, 67, 68, 69, 70, 71, 72, 73, 74]));
  1. Create a bidirectional stream and send data
const stream2 = await transport.createBidirectionalStream();
const writer2 = stream2.writable.getWriter();
writer2.write(new Uint8Array([66, 67, 68, 69, 70, 71, 72, 73, 74, 75]));
  1. Accept a unidirectional stream from the server
const streamReader = await transport.incomingUnidirectionalStreams.getReader();
const streamResult = await reader.read();
const stream = streamResult.value;
  1. Read from a unidirectional stream
const reader1 = stream1.getReader();
await reader1.read();
  1. Read from a bidirectional stream
const reader2 = stream2.readable.getReader();
await reader2.read();

@adityamandaleeka adityamandaleeka added the blog-candidate Consider mentioning this in the release blog post label Jul 18, 2022
@ghost
Copy link

ghost commented Jul 18, 2022

@Daniel-Genkin-MS-2, this change will be considered for inclusion in the blog post for the release it'll ship in. Nice work!

Please ensure that the original comment in this thread contains a clear explanation of what the change does, why it's important (what problem does it solve?), and, if relevant, include things like code samples and/or performance numbers.

This content may not be exactly what goes into the blog post, but it will help the team putting together the announcement.

Thanks!

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

I still need to try out the samples, but don't wait on me.

src/Middleware/Middleware.slnf Outdated Show resolved Hide resolved
Co-authored-by: Aditya Mandaleeka <adityamandaleeka@users.noreply.github.com>
Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

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

Just a few minor comments left. Great job!

@Daniel-Genkin-MS-2 Daniel-Genkin-MS-2 enabled auto-merge (squash) July 20, 2022 18:41
@Daniel-Genkin-MS-2 Daniel-Genkin-MS-2 merged commit b120cef into dotnet:main Jul 20, 2022
@ghost ghost modified the milestones: 7.0-preview7, 7.0-rc1 Jul 20, 2022
@Pilchie
Copy link
Member

Pilchie commented Jul 20, 2022

Yay! :shipit:

cheers

@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions blog-candidate Consider mentioning this in the release blog post
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants