1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Flags: --no-warnings
'use strict';
// This test ensures that when we don't define `preferredAddress`
// on the server while the `preferredAddressPolicy` on the client
// is `accept`, it works as expected.
const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');
const assert = require('assert');
const { key, cert, ca } = require('../common/quic');
const { createQuicSocket } = require('net');
const { once } = require('events');
const options = { key, cert, ca, alpn: 'zzz' };
(async () => {
const server = createQuicSocket({ server: options });
const client = createQuicSocket({ client: options });
server.on('session', common.mustCall((serverSession) => {
serverSession.on('stream', common.mustCall(async (stream) => {
stream.on('data', common.mustCall((data) => {
assert.strictEqual(data.toString('utf8'), 'hello');
}));
await once(stream, 'end');
stream.close();
client.close();
server.close();
}));
}));
await server.listen();
const clientSession = await client.connect({
address: common.localhostIPv4,
port: server.endpoints[0].address.port,
preferredAddressPolicy: 'accept',
});
const stream = await clientSession.openStream();
stream.end('hello');
await Promise.all([
once(stream, 'close'),
once(client, 'close'),
once(server, 'close')]);
})().then(common.mustCall());
|