| 162 | // raw bytes transferred. The proxy counts bytes to measure the on-the-wire |
| 163 | // handshake size (which reflects certificate compression savings). |
| 164 | async function measureHandshakeBytes(serverOpts, clientOpts) { |
| 165 | const { promise: serverConnected, resolve: onServerConn } = Promise.withResolvers(); |
| 166 | const server = tls.createServer(serverOpts, common.mustCall((socket) => { |
| 167 | onServerConn(); |
| 168 | socket.destroy(); |
| 169 | })); |
| 170 | server.listen(0); |
| 171 | await once(server, 'listening'); |
| 172 | |
| 173 | let proxyClientConn; |
| 174 | const proxy = net.createServer(common.mustCall((clientConn) => { |
| 175 | proxyClientConn = clientConn; |
| 176 | const serverConn = net.connect(server.address().port); |
| 177 | clientConn.pipe(serverConn); |
| 178 | serverConn.pipe(clientConn); |
| 179 | serverConn.on('error', () => {}); |
| 180 | clientConn.on('error', () => {}); |
| 181 | })); |
| 182 | proxy.listen(0); |
| 183 | await once(proxy, 'listening'); |
| 184 | |
| 185 | const client = tls.connect({ |
| 186 | port: proxy.address().port, |
| 187 | rejectUnauthorized: false, |
| 188 | minVersion: 'TLSv1.3', |
| 189 | ...clientOpts, |
| 190 | }); |
| 191 | await serverConnected; |
| 192 | |
| 193 | const totalBytes = proxyClientConn.bytesRead + proxyClientConn.bytesWritten; |
| 194 | |
| 195 | client.destroy(); |
| 196 | server.close(); |
| 197 | proxy.close(); |
| 198 | |
| 199 | return totalBytes; |
| 200 | } |
| 201 | |
| 202 | const baseline = await measureHandshakeBytes( |
| 203 | { key, cert, minVersion: 'TLSv1.3' }, |