Skip to content

Commit

Permalink
docs(examples): add some examples to track the memory usage
Browse files Browse the repository at this point in the history
Related: fc21c4a
  • Loading branch information
darrachequesne committed Jun 13, 2024
1 parent fc21c4a commit 8955eb7
Show file tree
Hide file tree
Showing 11 changed files with 806 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/memory-usage-webtransport/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pem
*.log
35 changes: 35 additions & 0 deletions examples/memory-usage-webtransport/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Socket } from "engine.io-client";
import { X509Certificate } from "crypto";
import { readFileSync } from "node:fs";
import { WebTransport } from "@fails-components/webtransport";

const cert = readFileSync("./cert.pem");
const CLIENTS_COUNT = 100;

global.WebTransport = WebTransport;

for (let i = 0; i < CLIENTS_COUNT; i++) {
const socket = new Socket("ws://localhost:3000", {
transports: ["webtransport"],
transportOptions: {
webtransport: {
serverCertificateHashes: [
{
algorithm: "sha-256",
value: Buffer.from(
new X509Certificate(cert).fingerprint256
.split(":")
.map((el) => parseInt(el, 16))
),
},
],
},
},
});

socket.on("open", () => {});

socket.on("message", () => {});

socket.on("close", (reason) => {});
}
6 changes: 6 additions & 0 deletions examples/memory-usage-webtransport/generate_cert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
openssl req -new -x509 -nodes \
-newkey ec -pkeyopt ec_paramgen_curve:prime256v1 \
-days 14 \
-out cert.pem -keyout key.pem \
-subj '/CN=127.0.0.1'
Loading

0 comments on commit 8955eb7

Please sign in to comment.