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

dev/proc: Module preparation #1

Merged
merged 55 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c75e6b9
Restructure code before merge
hironichu Sep 15, 2023
1f66147
Working code
hironichu Sep 15, 2023
a4e926f
Working demo recv,send
hironichu Sep 15, 2023
12ec1fa
Starting bench and fixes
hironichu Sep 16, 2023
916f07e
Fixes and speed
hironichu Sep 16, 2023
18bbd32
Cleaning architecture for client integration
hironichu Sep 16, 2023
3de8d06
fmt
hironichu Sep 16, 2023
2146c88
fix: arm support
hironichu Sep 16, 2023
04f25e7
fix: try on hard CPU hits...
hironichu Sep 16, 2023
db3e72b
feat: CI
hironichu Sep 17, 2023
1ac4338
fix: remove deno.lock file
hironichu Sep 17, 2023
def6c0a
feat: more config and stuff
hironichu Sep 17, 2023
852327f
Fixed configuration for CI (not tested)
hironichu Sep 17, 2023
d7d7b32
fix clean, ci
hironichu Sep 17, 2023
9212765
fix fmt cmd
hironichu Sep 17, 2023
c28c831
fix ci syntax
hironichu Sep 17, 2023
6ae1101
fix ci syntax
hironichu Sep 17, 2023
f676908
fix ci
hironichu Sep 17, 2023
87f087b
fix ci
hironichu Sep 17, 2023
0cd3cd9
fix ci
hironichu Sep 17, 2023
51726f8
fix ci
hironichu Sep 17, 2023
442dee0
fix ci windows/linux builds
hironichu Sep 17, 2023
2a6b3cb
fix ci windows/linux builds
hironichu Sep 17, 2023
b358a96
fix ci syntax
hironichu Sep 17, 2023
f8e5bfd
Testing/ci : Added CI (#2)
hironichu Sep 17, 2023
e909cfa
added dev/ to CI
hironichu Sep 17, 2023
6aab994
lot of work, restructure client/server code, types and other stuff
hironichu Sep 17, 2023
7c6b392
Removed trash
hironichu Sep 17, 2023
2557fb3
fmt
hironichu Sep 17, 2023
57182e4
Working code!
hironichu Sep 17, 2023
6f7fe2e
Added working client (first try btw)
hironichu Sep 17, 2023
456608a
lint
hironichu Sep 17, 2023
e2839b8
Added more detail to readme
hironichu Sep 17, 2023
9bbae39
added classes to global scope
hironichu Sep 17, 2023
95fca83
Trying test
hironichu Sep 17, 2023
1a58800
Fixes CI env variable
hironichu Sep 17, 2023
f68340c
Fixes CI cache
hironichu Sep 17, 2023
707fc1e
Fixes CI cache
hironichu Sep 17, 2023
b27e136
Fixes CI...
hironichu Sep 17, 2023
e61c837
Fixes CI...
hironichu Sep 17, 2023
d52a1ec
ci: trying new CI config (#3)
hironichu Sep 19, 2023
9a7418a
Added safety and fixes
hironichu Sep 19, 2023
c23ef68
Re-Writen Connection (rust side) and fixed Lib loading without Plug.
hironichu Sep 20, 2023
2827620
Rm useless file
hironichu Sep 20, 2023
2a51b7f
fix ci : Lib loading in CI
hironichu Sep 20, 2023
2c7aa8f
Removed env from CI
hironichu Sep 20, 2023
9782b34
Trying to fix custom lib loading in CI
hironichu Sep 20, 2023
80b3d6b
fix
hironichu Sep 20, 2023
4ae2e7d
fix aarch64
hironichu Sep 20, 2023
2016ec6
fix aarch64 2
hironichu Sep 20, 2023
8a37adb
Removed _
hironichu Sep 20, 2023
4940693
Re-added Macos and windows CI, if it works it works..
hironichu Sep 20, 2023
47f724a
Getting WebTransport closer to 'standards'
hironichu Sep 21, 2023
450edcc
Pre-Releases/0.0.2 (#8)
hironichu Sep 27, 2023
48cc1d8
Merge branch 'main' into dev/proc
hironichu Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,7 @@ jobs:
target/${{matrix.profile}}/libwebtransport.so
target/${{matrix.profile}}/libwebtransport_aarch64.so
target/${{matrix.profile}}/libwebtransport.dylib
- name: Upload release to GitHub
uses: softprops/action-gh-release@59c3b4891632ff9a897f99a91d7bc557467a3a22
if: |
(matrix.job == 'build' && matrix.profile == 'release') &&
github.repository == 'hironichu/webtransport' &&
github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
target/${{matrix.profile}}/webtransport.dll
target/${{matrix.profile}}/libwebtransport.so
target/${{matrix.profile}}/libwebtransport_aarch64.so
target/${{matrix.profile}}/libwebtransport.dylib
draft: true

test:
needs: build
if: |
Expand Down Expand Up @@ -203,4 +189,33 @@ jobs:
BUILD_TARGET: release
CI_BUILD: true
run: |
deno task test
publish:
name: "Publish to Github"
needs: [test, build]
if: |
github.event_name == 'push' || !startsWith(github.event.pull_request.head.label, 'hironichu:') && ((github.ref == 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/')))
runs-on: "ubuntu-latest"
steps:
- name: Creating target structure
run: |
mkdir -p target
- name: Download artifact
uses: actions/download-artifact@master
with:
# name: release
path: target
- name: Get artifact from build
uses: softprops/action-gh-release@59c3b4891632ff9a897f99a91d7bc557467a3a22
if: |
github.repository == 'hironichu/webtransport' &&
github.ref == 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
target/release/webtransport.dll
target/release/libwebtransport.so
target/release/libwebtransport_aarch64.so
target/release/libwebtransport.dylib
draft: true

83 changes: 64 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,44 @@
This library implements a very WIP version of the
[WebTransport](https://w3c.github.io/webtransport/) API for Deno.

> This does not follow perfectly the web standards and is not production ready.
> basically just a PoC

> This implementation tries to follow the web standards but has some differences
> ⚠️ This is not production ready ⚠️

# TODO

- [x] Implement the client API
- [x] Implement the server API
- [x] Implement Streams
- [x] Implement BidirectionalStream
- [x] Implement UniDirectionalStream
- [x] Implement Datagrams
- [ ] Implement closes and errors :
- [x] Implement closes and errors for the client
- [ ] Implement closes and errors for the server

For now, the server doesnt really close gracefully, it will try to close any
connection to it, but it might never stop running.. this needs way more work in
order to be usable.

Most of the code has been tested without unit tests, so there will be a lot of
bugs.

# NOTICE

This library is no way near production ready, and should never be used without
throughly testing it.

Feel free to open issues and PRs.

# IMPORTANT

The module add declaration to the global namespace, so you can use the API
without importing the classes

This might not be practical for some people, but for now wont be changed.



## Usage

Expand All @@ -16,41 +52,56 @@ has not been defined).
```ts
import "https://deno.land/x/webtransport/mod.ts";

const encoder = new TextEncoder();
//Client
const transport = new WebTransport("https://localhost:4433");
/**
* Please note that this example above will not work if you have self validated certificates
* use the following to disable certificate verification.. (Warning this is not secure)
* const transport = new WebTransport("https://localhost:4433", {
* maxTimeout: 10,
* keepAlive: 3,
* validateCertificate: false,
* });
*/

await transport.ready;

// Send Datagram packet

const encoder = new TextEncoder();
const data = encoder.encode("Hello World");
const writer = await transport.datagrams.writable.getWriter();
await writer.write(data);

/// Create a bidirectional stream and send data
/// The bidirectional stream is a duplex stream, so you can read and write from it.
/// it also sends data in order and is reliable. (unlike datagrams)
const stream = await transport.createBidirectionalStream();
const writer = stream.writable.getWriter();
const data = encoder.encode("Hello World");
await writer.write(data);

/// Read incoming data from the stream
/// You can also loop over the readable stream using a for await loop
/// NOTE : The api for looping over the readable stream is not yet implemented in the browser
const reader = stream.readable.getReader();
const decoder = new TextDecoder();
const { value, done } = await reader.read();
console.log(decoder.decode(value));
```

### Server example :

This server tries to be as close to the client api but has some differences.
You can reuse the same api as the client because they share the same
implementation for streams.

```ts
import "https://deno.land/x/webtransport/mod.ts";

//Client
//Server
const transport = new WebTransportServer(4433, {
keyFile: "./certs/key.pem",
certFile: "./certs/cert.pem",
maxTimeout: 10,
keepAlive: 3,
});


//Required to make sure the server is listening for new connections.
await transport.ready;

transport.on("connection", async (conn) => {
//To get the datagrams from the client you can just look over the datagram stream
for await (const datagram of conn.datagrams.readable) {
Expand All @@ -65,9 +116,3 @@ transport.on("connection", async (conn) => {
});
```

# IMPORTANT

The module add declaration to the global namespace, so you can use the API
without importing the classes

This might not be practical for some people, but for now wont be changed.
24 changes: 23 additions & 1 deletion examples/web_server/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,29 @@ <h2>Server IP : HOST_IP</h2>
window.transport.onstatechange = (event) => {
console.log("EVENT : ", event);
}
// let incomignUNi = await window.transport.incomingUnidirectionalStreams

window.stream = await transport.createBidirectionalStream();
//get reader
window.reader = stream.readable.getReader();
//read data
Promise.all([(async () => {
while (true) {
let {
done,
value
} = await reader.read()
if (done) {
break
}
console.log("Received : ", decoder.decode(value))
}
})()])
// for await (const data of stream.readable) {
// console.log("Recevied : ", decoder.decode(data));
// }
window.sender = stream.writable.getWriter();
// const decoder = new TextDecoder();

// for await (const stream of incomignUNi) {
// console.log("INCOMING UNI : ", stream)
// stream.readableStreamClosed.then(() => {
Expand Down
4 changes: 2 additions & 2 deletions mod/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class WebTransportBidirectionalStream {
undefined,
errorCB,
);
console.log(this.ptr);

this.writable = WebTransportSendStream.from(this.ptr, errorCB);
}
}
Expand All @@ -111,7 +111,7 @@ export class WebTransportReceiveStream {
DEFAULT_CHUNK_SIZE = 1024,
cb: Deno.PointerValue<unknown>,
) {
console.log("BIDI READER");

return new ReadableStream({
type: "bytes",
start(controller) {
Expand Down
1 change: 1 addition & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub unsafe extern "C" fn proc_server_close(server_ptr: *mut WebTransportServer)
}
0
}

#[no_mangle]
pub unsafe extern "C" fn proc_server_close_clients(server_ptr: *mut WebTransportServer) -> usize {
assert!(!server_ptr.is_null());
Expand Down