Skip to content

Commit 5459f68

Browse files
committed
feat(web-keyvalue): add support for all transports
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent a36e5c5 commit 5459f68

7 files changed

Lines changed: 507 additions & 132 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rust/hello-web-client/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ clap = { workspace = true, features = [
1919
"suggestions",
2020
"usage",
2121
] }
22-
quinn = { workspace = true }
2322
rustls = { workspace = true }
2423
tokio = { workspace = true, features = ["rt-multi-thread"] }
2524
tracing-subscriber = { workspace = true, features = ["ansi", "fmt"] }

examples/rust/hello-web-client/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::sync::Arc;
22

33
use anyhow::Context as _;
44
use clap::Parser;
5-
use quinn::rustls::version::TLS13;
65
use rustls::client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier};
76
use rustls::pki_types::{CertificateDer, ServerName, UnixTime};
7+
use rustls::version::TLS13;
88
use rustls::{DigitallySignedStruct, SignatureScheme};
99
use url::Url;
1010
use wtransport::{ClientConfig, Endpoint};

examples/rust/hello-web-server/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ clap = { workspace = true, features = [
2020
"usage",
2121
] }
2222
futures = { workspace = true }
23-
quinn = { workspace = true, features = ["rustls"] }
2423
rcgen = { workspace = true, features = ["crypto", "ring", "zeroize"] }
2524
rustls = { workspace = true }
2625
tokio = { workspace = true, features = ["rt-multi-thread", "signal", "net"] }

examples/web/rust/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repository.workspace = true
1111

1212
[dependencies]
1313
anyhow = { workspace = true }
14+
async-nats = { workspace = true }
1415
axum = { workspace = true, features = ["tokio", "http1", "http2"] }
1516
bytes = { workspace = true }
1617
clap = { workspace = true, features = [
@@ -23,6 +24,14 @@ clap = { workspace = true, features = [
2324
"usage",
2425
] }
2526
futures = { workspace = true }
27+
quinn = { workspace = true, features = [
28+
"log",
29+
"platform-verifier",
30+
"ring",
31+
"runtime-tokio",
32+
"rustls",
33+
] }
34+
rustls = { workspace = true }
2635
tokio = { workspace = true, features = [
2736
"macros",
2837
"rt-multi-thread",

examples/web/rust/index.html

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,61 +24,87 @@
2424
const formData = new FormData(form);
2525
const obj = Object.fromEntries(formData);
2626

27-
let url;
27+
let identifier;
2828
let conn = obj.connection;
2929
console.log("transport " + conn);
3030
if (conn === 'mem') {
31-
url = '';
31+
identifier = '';
3232
} else if (conn === 'nats') {
33-
let nurl = obj['nats-url'];
34-
if (nurl == null || nurl === '') {
33+
let addr = obj['nats-addr'];
34+
if (addr == null || addr === '') {
3535
alert("NATS.io server URL must be set");
3636
return
3737
}
38-
url = 'wrpc+nats://' + nurl;
39-
let prefix = obj['nats-url'];
38+
identifier = 'wrpc+nats://' + addr;
39+
40+
let prefix = obj['nats-prefix'];
4041
if (prefix != null && prefix != '') {
41-
url = url + "/" + prefix;
42+
identifier = identifier + "/" + prefix;
43+
}
44+
45+
let bucket = obj['nats-bucket'];
46+
if (bucket != null && bucket != '') {
47+
identifier = identifier + ";" + bucket;
4248
}
4349
} else if (conn === 'quic') {
44-
let addr = obj['connection-string'];
50+
let addr = obj.addr;
4551
if (addr == null || addr === '') {
4652
alert("QUIC address must be set");
4753
return
4854
}
49-
url = 'wrpc+quic://' + addr;
55+
identifier = 'wrpc+quic://' + identifier;
56+
57+
let bucket = obj.bucket;
58+
if (bucket != null && bucket != '') {
59+
identifier = identifier + ";" + bucket;
60+
}
5061
} else if (conn === 'tcp') {
5162
let addr = obj['tcp-addr'];
5263
if (addr == null || addr === '') {
5364
alert("TCP address must be set");
5465
return
5566
}
56-
url = 'wrpc+tcp://' + addr;
67+
identifier = 'wrpc+tcp://' + addr;
68+
69+
let bucket = obj.bucket;
70+
if (bucket != null && bucket != '') {
71+
identifier = identifier + ";" + bucket;
72+
}
5773
} else if (conn === 'uds') {
58-
let addr = obj['connection-string'];
74+
let addr = obj.addr;
5975
if (addr == null || addr === '') {
6076
alert("Unix Domain Socket address must be set");
6177
return
6278
}
63-
url = 'wrpc+uds://' + addr;
79+
identifier = 'wrpc+uds://' + addr;
80+
81+
let bucket = obj.bucket;
82+
if (bucket != null && bucket != '') {
83+
identifier = identifier + ";" + bucket;
84+
}
6485
} else if (conn === 'web') {
65-
let addr = obj['connection-string'];
86+
let addr = obj.addr;
6687
if (addr == null || addr === '') {
6788
alert("WebTransport address must be set");
6889
return
6990
}
70-
url = 'wrpc+web://' + addr;
91+
identifier = 'wrpc+web://' + addr;
92+
93+
let bucket = obj.bucket;
94+
if (bucket != null && bucket != '') {
95+
identifier = identifier + ";" + bucket;
96+
}
7197
} else {
7298
alert("transport not supported yet")
7399
}
74-
if (url.length >= 127) {
75-
alert("this demo does not support URLs longer than 127 bytes - open a PR!");
100+
if (identifier.length >= 127) {
101+
alert("this demo does not support identifiers longer than 127 bytes - open a PR!");
76102
return
77103
}
78104

79105
// TODO: cache the bucket by URL (it should not persist across server restarts)
80106

81-
console.log('creating `open` stream for URL `' + url + '`...');
107+
console.log('creating `open` stream for identifier `' + identifier + '`...');
82108
let stream = await transport.createBidirectionalStream();
83109

84110
console.log('writing invocation...');
@@ -91,9 +117,9 @@
91117
await tx.write(new Uint8Array(["open".length]));
92118
await tx.write(new TextEncoder().encode("open"));
93119
await tx.write(new Uint8Array([0]));
94-
await tx.write(new Uint8Array([1 + url.length]));
95-
await tx.write(new Uint8Array([url.length]));
96-
await tx.write(new TextEncoder().encode(url));
120+
await tx.write(new Uint8Array([1 + identifier.length]));
121+
await tx.write(new Uint8Array([identifier.length]));
122+
await tx.write(new TextEncoder().encode(identifier));
97123
tx.close();
98124

99125
console.log('reading `open` response...');
@@ -217,8 +243,6 @@
217243
alert("failed to set value")
218244
return;
219245
}
220-
221-
document.querySelector('#set-response').textContent = JSON.stringify(res, null, 2);
222246
}
223247

224248
function init() {
@@ -307,15 +331,19 @@ <h1 class="title">wRPC WebTransport demo</h1>
307331
<div class="section pt-0">
308332
<form id="settings">
309333
<div id="template-output">
310-
<!-- templates from below will show here -->
311334
</div>
312335

313336
<template class="form-fields" data-option="default">
314-
<!-- shows when no other specific option is selected -->
315337
<div class="field">
316-
<label class="label">Connection String</label>
338+
<label class="label">Bucket identifier</label>
317339
<div class="control">
318-
<input class="input" type="text" name="connection-string">
340+
<input class="input" type="text" name="bucket">
341+
</div>
342+
</div>
343+
<div class="field">
344+
<label class="label">Target address</label>
345+
<div class="control">
346+
<input class="input" type="text" name="addr" placeholder="localhost:1234">
319347
</div>
320348
</div>
321349
</template>
@@ -325,10 +353,15 @@ <h1 class="title">wRPC WebTransport demo</h1>
325353

326354
<template class="form-fields" data-option="nats">
327355
<div class="field">
328-
<label class="label">NATS.io server URL</label>
356+
<label class="label">Bucket identifier</label>
357+
<div class="control">
358+
<input class="input" type="text" name="nats-bucket">
359+
</div>
360+
</div>
361+
<div class="field">
362+
<label class="label">NATS.io server address</label>
329363
<div class="control">
330-
<input class="input" type="text" name="nats-url" placeholder="nats://localhost:4222"
331-
value="nats://localhost:4222">
364+
<input class="input" type="text" name="nats-addr" placeholder="localhost:4222" value="localhost:4222">
332365
</div>
333366
</div>
334367
<div class="field">
@@ -340,6 +373,12 @@ <h1 class="title">wRPC WebTransport demo</h1>
340373
</template>
341374

342375
<template class="form-fields" data-option="tcp">
376+
<div class="field">
377+
<label class="label">Bucket identifier</label>
378+
<div class="control">
379+
<input class="input" type="text" name="tcp-bucket">
380+
</div>
381+
</div>
343382
<div class="field">
344383
<label class="label">TCP socket address</label>
345384
<div class="control">
@@ -390,11 +429,8 @@ <h2 class="title is-4 has-text-centered">Set</h2>
390429
</div>
391430
</div>
392431
</form>
393-
<div class="mt-6">
394-
<pre><code id="set-response"></code></pre>
395-
</div>
396432
</div>
397433
</div>
398434
</body>
399435

400-
</html>
436+
</html>

0 commit comments

Comments
 (0)