Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,22 @@
'use strict';
const common = require('../common.js');
const tls = require('tls');
const bench = common.createBenchmark(main, {
n: [1, 50000],
});
function main({ n }) {
const input = ['ABC', 'XYZ123', 'FOO'];
let m = {};
// First call dominates results
if (n > 1) {
tls.convertALPNProtocols(input, m);
m = {};
}
bench.start();
for (let i = 0; i < n; i++)
tls.convertALPNProtocols(input, m);
bench.end(n);
}

View File

@ -0,0 +1,97 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
dur: [5],
securing: ['TLSSocket', 'clear'],
size: [100, 1024, 1024 * 1024],
}, {
flags: ['--no-warnings'],
});
const fixtures = require('../../test/common/fixtures');
const tls = require('tls');
const net = require('net');
const REDIRECT_PORT = 28347;
function main({ dur, size, securing }) {
const chunk = Buffer.alloc(size, 'b');
const options = {
key: fixtures.readKey('rsa_private.pem'),
cert: fixtures.readKey('rsa_cert.crt'),
ca: fixtures.readKey('rsa_ca.crt'),
ciphers: 'AES256-GCM-SHA384',
isServer: true,
requestCert: true,
rejectUnauthorized: true,
maxVersion: 'TLSv1.2',
};
const server = net.createServer(onRedirectConnection);
server.listen(REDIRECT_PORT, () => {
const proxy = net.createServer(onProxyConnection);
proxy.listen(common.PORT, () => {
const clientOptions = {
port: common.PORT,
ca: options.ca,
key: options.key,
cert: options.cert,
isServer: false,
rejectUnauthorized: false,
maxVersion: options.maxVersion,
};
const network = securing === 'clear' ? net : tls;
const conn = network.connect(clientOptions, () => {
setTimeout(() => {
const mbits = (received * 8) / (1024 * 1024);
bench.end(mbits);
if (conn)
conn.destroy();
server.close();
proxy.close();
}, dur * 1000);
bench.start();
conn.on('drain', write);
write();
});
conn.on('error', (e) => {
throw new Error(`Client error: ${e}`);
});
function write() {
while (false !== conn.write(chunk));
}
});
});
function onProxyConnection(conn) {
const client = net.connect(REDIRECT_PORT, () => {
switch (securing) {
case 'TLSSocket':
secureTLSSocket(conn, client);
break;
case 'clear':
conn.pipe(client);
break;
default:
throw new Error('Invalid securing method');
}
});
}
function secureTLSSocket(conn, client) {
const serverSocket = new tls.TLSSocket(conn, options);
serverSocket.on('error', (e) => {
throw new Error(`Socket error: ${e}`);
});
serverSocket.pipe(client);
}
let received = 0;
function onRedirectConnection(conn) {
conn.on('data', (chunk) => {
received += chunk.length;
});
}
}

View File

@ -0,0 +1,70 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
dur: [5],
type: ['buf', 'asc', 'utf'],
size: [100, 1024, 1024 * 1024, 4 * 1024 * 1024, 16 * 1024 * 1024],
});
const fixtures = require('../../test/common/fixtures');
let options;
const tls = require('tls');
function main({ dur, type, size }) {
let encoding;
let chunk;
switch (type) {
case 'buf':
chunk = Buffer.alloc(size, 'b');
break;
case 'asc':
chunk = 'a'.repeat(size);
encoding = 'ascii';
break;
case 'utf':
chunk = 'ü'.repeat(size / 2);
encoding = 'utf8';
break;
default:
throw new Error('invalid type');
}
options = {
key: fixtures.readKey('rsa_private.pem'),
cert: fixtures.readKey('rsa_cert.crt'),
ca: fixtures.readKey('rsa_ca.crt'),
ciphers: 'AES256-GCM-SHA384',
maxVersion: 'TLSv1.2',
};
const server = tls.createServer(options, onConnection);
let conn;
server.listen(common.PORT, () => {
const opt = { port: common.PORT, rejectUnauthorized: false };
conn = tls.connect(opt, () => {
setTimeout(done, dur * 1000);
bench.start();
conn.on('drain', write);
write();
});
function write() {
while (false !== conn.write(chunk, encoding));
}
});
let received = 0;
function onConnection(conn) {
conn.on('data', (chunk) => {
received += chunk.length;
});
}
function done() {
const mbits = (received * 8) / (1024 * 1024);
bench.end(mbits);
if (conn)
conn.destroy();
server.close();
}
}

View File

@ -0,0 +1,105 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
dur: [5],
type: ['buf', 'asc', 'utf'],
sendchunklen: [256, 32 * 1024, 128 * 1024, 16 * 1024 * 1024],
recvbuflen: [0, 64 * 1024, 1024 * 1024],
recvbufgenfn: ['true', 'false'],
});
const fixtures = require('../../test/common/fixtures');
let options;
let recvbuf;
let received = 0;
const tls = require('tls');
function main({ dur, type, sendchunklen, recvbuflen, recvbufgenfn }) {
if (isFinite(recvbuflen) && recvbuflen > 0)
recvbuf = Buffer.alloc(recvbuflen);
let encoding;
let chunk;
switch (type) {
case 'buf':
chunk = Buffer.alloc(sendchunklen, 'b');
break;
case 'asc':
chunk = 'a'.repeat(sendchunklen);
encoding = 'ascii';
break;
case 'utf':
chunk = 'ü'.repeat(sendchunklen / 2);
encoding = 'utf8';
break;
default:
throw new Error('invalid type');
}
options = {
key: fixtures.readKey('rsa_private.pem'),
cert: fixtures.readKey('rsa_cert.crt'),
ca: fixtures.readKey('rsa_ca.crt'),
ciphers: 'AES256-GCM-SHA384',
maxVersion: 'TLSv1.2',
};
let socketOpts;
if (recvbuf === undefined) {
socketOpts = { port: common.PORT, rejectUnauthorized: false };
} else {
let buffer = recvbuf;
if (recvbufgenfn === 'true') {
let bufidx = -1;
const bufpool = [
recvbuf,
Buffer.from(recvbuf),
Buffer.from(recvbuf),
];
buffer = () => {
bufidx = (bufidx + 1) % bufpool.length;
return bufpool[bufidx];
};
}
socketOpts = {
port: common.PORT,
rejectUnauthorized: false,
onread: {
buffer,
callback: function(nread, buf) {
received += nread;
},
},
};
}
const server = tls.createServer(options, (socket) => {
socket.on('data', (buf) => {
socket.on('drain', write);
write();
});
function write() {
while (false !== socket.write(chunk, encoding));
}
});
let conn;
server.listen(common.PORT, () => {
conn = tls.connect(socketOpts, () => {
setTimeout(done, dur * 1000);
bench.start();
conn.write('hello');
});
conn.on('data', (chunk) => {
received += chunk.length;
});
});
function done() {
const mbits = (received * 8) / (1024 * 1024);
bench.end(mbits);
process.exit(0);
}
}

View File

@ -0,0 +1,67 @@
'use strict';
const fixtures = require('../../test/common/fixtures');
const tls = require('tls');
const common = require('../common.js');
const bench = common.createBenchmark(main, {
concurrency: [1, 10],
dur: [5],
});
let clientConn = 0;
let serverConn = 0;
let dur;
let concurrency;
let running = true;
function main(conf) {
dur = conf.dur;
concurrency = conf.concurrency;
const options = {
key: fixtures.readKey('rsa_private.pem'),
cert: fixtures.readKey('rsa_cert.crt'),
ca: fixtures.readKey('rsa_ca.crt'),
ciphers: 'AES256-GCM-SHA384',
maxVersion: 'TLSv1.2',
};
const server = tls.createServer(options, onConnection);
server.listen(common.PORT, onListening);
}
function onListening() {
setTimeout(done, dur * 1000);
bench.start();
for (let i = 0; i < concurrency; i++)
makeConnection();
}
function onConnection(conn) {
serverConn++;
}
function makeConnection() {
const options = {
port: common.PORT,
rejectUnauthorized: false,
};
const conn = tls.connect(options, () => {
clientConn++;
conn.on('error', (er) => {
console.error('client error', er);
throw er;
});
conn.end();
if (running) makeConnection();
});
}
function done() {
running = false;
// It's only an established connection if they both saw it.
// because we destroy the server somewhat abruptly, these
// don't always match. Generally, serverConn will be
// the smaller number, but take the min just to be sure.
bench.end(Math.min(serverConn, clientConn));
process.exit(0);
}