This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quic: ensure callbacks of QuicSocket.connect() get called
1. The callbacks of QuicSocket.connect() won't get called after QuicSocket binding. To fix this issue, This PR calls QuicSession[kReady]() directly when QuicSocket bound. 2. This PR also modify SocketAddress::Hash and SocketAddress::Compare to accept struct values instead of pointers because SocketAddress might get freed firstly which would cause the values aren't safe to use. For example, the test added in this PR is likely to abort before this PR.
- Loading branch information
1 parent
1c316ac
commit 21377c1
Showing
8 changed files
with
124 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasQuic) | ||
common.skip('missing quic'); | ||
|
||
const { createSocket } = require('quic'); | ||
const fixtures = require('../common/fixtures'); | ||
const Countdown = require('../common/countdown'); | ||
const key = fixtures.readKey('agent1-key.pem', 'binary'); | ||
const cert = fixtures.readKey('agent1-cert.pem', 'binary'); | ||
const ca = fixtures.readKey('ca1-cert.pem', 'binary'); | ||
|
||
const kServerName = 'agent2'; | ||
const kALPN = 'zzz'; | ||
const kIdleTimeout = 0; | ||
const kConnections = 5; | ||
|
||
// After QuicSocket bound, the callback of QuicSocket.connect() | ||
// should still get called. | ||
{ | ||
let client; | ||
const server = createSocket({ | ||
port: 0, | ||
}); | ||
|
||
server.listen({ | ||
key, | ||
cert, | ||
ca, | ||
alpn: kALPN, | ||
idleTimeout: kIdleTimeout, | ||
}); | ||
|
||
const countdown = new Countdown(kConnections, () => { | ||
client.close(); | ||
server.close(); | ||
}); | ||
|
||
server.on('ready', common.mustCall(() => { | ||
const options = { | ||
key, | ||
cert, | ||
ca, | ||
address: common.localhostIPv4, | ||
port: server.address.port, | ||
servername: kServerName, | ||
alpn: kALPN, | ||
idleTimeout: kIdleTimeout, | ||
}; | ||
|
||
client = createSocket({ | ||
port: 0, | ||
}); | ||
|
||
const session = client.connect(options, common.mustCall(() => { | ||
session.close(common.mustCall(() => { | ||
// After a session being ready, the socket should have bound | ||
// and we could start the test. | ||
testConnections(); | ||
})); | ||
})); | ||
|
||
const testConnections = common.mustCall(() => { | ||
for (let i = 0; i < kConnections; i += 1) { | ||
client.connect(options, common.mustCall(() => { | ||
countdown.dec(); | ||
})); | ||
} | ||
}); | ||
})); | ||
} |