Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 365895e

Browse files
committed
Close connection if no transport ID is received after 10s.
1 parent b24bf33 commit 365895e

File tree

2 files changed

+72
-16
lines changed

2 files changed

+72
-16
lines changed

source/agent/quic/webtransport/quicTransportServer.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const zeroUuid = '00000000000000000000000000000000';
1717
* streamadded - A new stream is added, and ready to be attached to a stream
1818
* pipeline. Argument: a string for publication or subscription ID.
1919
*/
20+
21+
// Connection will be closed if no transport ID is received after
22+
// `authenticationTimeout` seconds.
23+
const authenticationTimeout = 10;
24+
2025
module.exports = class QuicTransportServer extends EventEmitter {
2126
constructor(addon, port) {
2227
super();
@@ -28,6 +33,12 @@ module.exports = class QuicTransportServer extends EventEmitter {
2833
this._assignedTransportIds = []; // Transport channels assigned to this server.
2934
this._server.onconnection = (connection) => {
3035
this._unAuthenticatedConnections.push(connection);
36+
setTimeout(() => {
37+
// Must be authenticated in `authenticationTimeout` seconds.
38+
if (!connection.transportId) {
39+
connection.close();
40+
}
41+
}, authenticationTimeout * 1000);
3142
connection.onincomingstream = (stream) => {
3243
stream.oncontentsessionid = (id) => {
3344
const streamId = this._uuidBytesToString(new Uint8Array(id))
@@ -46,11 +57,17 @@ module.exports = class QuicTransportServer extends EventEmitter {
4657
this.emit('streamadded', stream);
4758
}
4859
};
49-
stream.ondata=(data)=>{
60+
stream.ondata = (data) => {
5061
if (stream.contentSessionId === zeroUuid) {
51-
connection.transportId = data.toString('utf8');
62+
const transportId = data.toString('utf8');
63+
if (!this._assignedTransportIds.includes(transportId)) {
64+
log.info(JSON.stringify(connection));
65+
connection.close();
66+
}
67+
connection.transportId = transportId;
68+
stream.transportId = transportId;
5269
this._connections.set(connection.transportId, connection);
53-
log.info('Transport ID: ' + connection.transportId);
70+
log.info('New connection for transport ID: ' + transportId);
5471
}
5572
}
5673
}
@@ -110,7 +127,6 @@ module.exports = class QuicTransportServer extends EventEmitter {
110127
for (let i = 0; i < 16; i++) {
111128
uuidArray[i] = parseInt(uuidString.substring(i * 2, i * 2 + 2), 16);
112129
}
113-
console.log(uuidArray);
114130
return uuidArray;
115131
}
116132
};

source/agent/quic/webtransport/test/quicTransportServerTest.js

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
'use strict';
88

9-
const expect = require('chai').use(require('chai-as-promised')).expect;
9+
const assert = require('chai').use(require('chai-as-promised')).assert;
1010
const QuicTransportServer = require('../quicTransportServer.js');
1111
const sinon = require('sinon');
1212

@@ -48,18 +48,58 @@ describe('Test QuicTransportServer.', () => {
4848
const transportid1 = 'transportid1';
4949
const transportid2 = 'transportid2';
5050
server.addTransportId(transportid1);
51-
expect(server.createSendStream(transportid2)).to.be.undefined;
51+
assert.equal(server.createSendStream(transportid2), undefined);
5252
done();
5353
});
5454

55-
it('Test UUID convertions.',
56-
(done) => {
57-
const uuidString0='';
58-
const uuidString1='';
59-
const uuidString2='';
60-
const uuidArray0='';
61-
const uuidArray1='';
62-
const uuidArray2='';
63-
done();
64-
});
55+
it('UUID convertions.', (done) => {
56+
const uuidStrings = [
57+
'00000000000000000000000000000000', 'd8bc24a9360b4320bf42704353d906db',
58+
'e6fc9b708b96418ab996c50bed964eb2'
59+
];
60+
const uuidArrays = [
61+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
62+
new Uint8Array([
63+
216, 188, 36, 169, 54, 11, 67, 32, 191, 66, 112, 67, 83, 217, 6, 219
64+
]),
65+
new Uint8Array([
66+
230, 252, 155, 112, 139, 150, 65, 138, 185, 150, 197, 11, 237, 150, 78,
67+
178
68+
])
69+
];
70+
assert.equal(uuidStrings.length, uuidArrays.length);
71+
for (let i = 0; i < uuidStrings.length; i++) {
72+
assert.deepEqual(
73+
uuidArrays[i], server._uuidStringToUint8Array(uuidStrings[i]));
74+
assert.deepEqual(
75+
uuidStrings[i], server._uuidBytesToString(uuidArrays[i]));
76+
}
77+
done();
78+
});
79+
80+
it('Correctly identify transport ID and content session ID.', (done) => {
81+
const connection1 = {close: sinon.stub()};
82+
const connection2 = {close: sinon.stub()};
83+
const stream10 = {};
84+
const stream20 = {};
85+
const transportId = '0123456789';
86+
const unauthenticatedTransportId = '1234567890';
87+
server.addTransportId(transportId);
88+
fakeAddonServer.onconnection(connection1);
89+
connection1.onincomingstream(stream10);
90+
stream10.oncontentsessionid(
91+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
92+
stream10.ondata(Buffer.from(transportId, 'utf8'));
93+
assert.equal(connection1.transportId, transportId);
94+
assert.equal(stream10.transportId, transportId);
95+
fakeAddonServer.onconnection(connection2);
96+
connection2.onincomingstream(stream20);
97+
stream20.oncontentsessionid(
98+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
99+
stream20.ondata(Buffer.from(unauthenticatedTransportId, 'utf8'));
100+
sinon.assert.notCalled(connection1.close);
101+
// connection2 doesn't have an authenticated transport ID. Thus, it should be closed.
102+
sinon.assert.calledOnce(connection2.close);
103+
done();
104+
});
65105
});

0 commit comments

Comments
 (0)