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

Commit 1d52eea

Browse files
committed
Fix QUIC agent for internal transport router.
A recent commit (773cfe4) for internal transport introduced breaking changes. This commit updates QUIC agent to work with updated internal transport APIs.
1 parent 90c290e commit 1d52eea

File tree

5 files changed

+79
-87
lines changed

5 files changed

+79
-87
lines changed

source/agent/addons/quic/QuicTransportStream.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ NAN_METHOD(QuicTransportStream::close)
113113
NAN_METHOD(QuicTransportStream::addDestination)
114114
{
115115
QuicTransportStream* obj = Nan::ObjectWrap::Unwrap<QuicTransportStream>(info.Holder());
116-
if (info.Length() != 1) {
116+
if (info.Length() != 2) {
117117
Nan::ThrowTypeError("Invalid argument length for addDestination.");
118118
return;
119119
}
120120
// TODO: Check if info[0] is an Nan wrapped object.
121-
auto framePtr = Nan::ObjectWrap::Unwrap<QuicTransportStream>(info[0]->ToObject());
121+
auto framePtr = Nan::ObjectWrap::Unwrap<QuicTransportStream>(info[1]->ToObject());
122122
// void* ptr = info[0]->ToObject()->GetAlignedPointerFromInternalField(0);
123123
// auto framePtr=static_cast<owt_base::FrameDestination*>(ptr);
124124
obj->addDataDestination(framePtr);

source/agent/quic/dist.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"../connections.js",
3030
"../InternalConnectionFactory.js",
3131
"../../common/makeRPC.js",
32-
"../../common/rpcChannel.js"
32+
"../../common/rpcChannel.js",
33+
"../internalConnectionRouter.js"
3334
],
3435
"quic/webtransport": [
3536
"webtransport/quicTransportServer.js",

source/agent/quic/index.js

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// all agents. They are defined in base-agent.js.
1616

1717
'use strict';
18-
const Connections = require('./connections');
1918
const InternalConnectionFactory = require('./InternalConnectionFactory');
2019
const logger = require('../logger').logger;
2120
const QuicTransportServer = require('./webtransport/quicTransportServer');
@@ -25,6 +24,7 @@ const log = logger.getLogger('QuicNode');
2524
const addon = require('./build/Release/quic');
2625
const cipher = require('../cipher');
2726
const path = require('path');
27+
const {InternalConnectionRouter} = require('./internalConnectionRouter');
2828

2929
log.info('QUIC transport node.')
3030

@@ -34,7 +34,7 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
3434
agentID: parentRpcId,
3535
clusterIP: clusterWorkerIP
3636
};
37-
const connections = new Connections;
37+
const router = new InternalConnectionRouter(global.config.internal);
3838
const internalConnFactory = new InternalConnectionFactory;
3939
const incomingStreamPipelines =
4040
new Map(); // Key is publication ID, value is stream pipeline.
@@ -100,18 +100,22 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
100100
password, validateToken);
101101
quicTransportServer.start();
102102
quicTransportServer.on('streamadded', (stream) => {
103-
log.debug('A stream with session ID '+stream.contentSessionId+' is added.');
104-
const conn = connections.getConnection(stream.contentSessionId);
105-
if (conn) {
106-
// TODO: verify transport ID.
107-
conn.connection.quicStream(stream);
108-
// TODO: Make RPC call to conference node for session-established.
103+
log.debug(
104+
'A stream with session ID ' + stream.contentSessionId +
105+
' is added.');
106+
let pipeline = null;
107+
if (outgoingStreamPipelines.has(stream.contentSessionId)) {
108+
pipeline = outgoingStreamPipelines.get(stream.contentSessionId);
109+
} else if (incomingStreamPipelines.has(stream.contentSessionId)) {
110+
pipeline = incomingStreamPipelines.get(stream.contentSessionId);
109111
} else {
110112
log.warn(
111113
'Cannot find a pipeline for QUIC stream. Content session ID: ' +
112114
stream.contentSessionId);
113115
stream.close();
116+
return;
114117
}
118+
pipeline.quicStream(stream);
115119
});
116120
quicTransportServer.on('connectionadded', (connection) => {
117121
log.debug(
@@ -159,32 +163,21 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
159163
};
160164
};
161165

162-
that.createInternalConnection = function (connectionId, direction, internalOpt, callback) {
163-
internalOpt.minport = global.config.internal.minport;
164-
internalOpt.maxport = global.config.internal.maxport;
165-
var portInfo = internalConnFactory.create(connectionId, direction, internalOpt);
166-
callback('callback', {ip: that.clusterIP, port: portInfo});
167-
};
168-
169-
that.destroyInternalConnection = function (connectionId, direction, callback) {
170-
internalConnFactory.destroy(connectionId, direction);
171-
callback('callback', 'ok');
166+
that.getInternalAddress = function(callback) {
167+
const ip = global.config.internal.ip_address;
168+
const port = router.internalPort;
169+
callback('callback', {ip, port});
172170
};
173171

174172
// functions: publish, unpublish, subscribe, unsubscribe, linkup, cutoff
175173
that.publish = function(connectionId, connectionType, options, callback) {
176174
log.debug('publish, connectionId:', connectionId, 'connectionType:', connectionType, 'options:', options);
177-
if (connections.getConnection(connectionId)) {
175+
if (router.getConnection(connectionId)) {
178176
return callback('callback', {type: 'failed', reason: 'Connection already exists:'+connectionId});
179177
}
180178

181179
var conn = null;
182180
switch (connectionType) {
183-
case 'internal':
184-
conn = internalConnFactory.fetch(connectionId, 'in');
185-
if (conn)
186-
conn.connect(options);
187-
break;
188181
case 'quic':
189182
conn = createStreamPipeline(connectionId, 'in', options, callback);
190183
if (!conn) {
@@ -198,14 +191,16 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
198191
log.error('Create connection failed', connectionId, connectionType);
199192
return callback('callback', {type: 'failed', reason: 'Create Connection failed'});
200193
}
201-
connections.addConnection(connectionId, connectionType, options.controller, conn, 'in')
202-
.then(onSuccess(callback), onError(callback));
194+
conn.bindRouterAsSourceCallback = function(stream) {
195+
router.addLocalSource(connectionId, connectionType, stream);
196+
}
197+
onSuccess(callback)();
203198
};
204199

205200
that.unpublish = function (connectionId, callback) {
206201
log.debug('unpublish, connectionId:', connectionId);
207-
var conn = connections.getConnection(connectionId);
208-
connections.removeConnection(connectionId).then(function(ok) {
202+
var conn = router.getConnection(connectionId);
203+
router.removeConnection(connectionId).then(function(ok) {
209204
if (conn && conn.type === 'internal') {
210205
internalConnFactory.destroy(connectionId, 'in');
211206
} else if (conn) {
@@ -225,17 +220,12 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
225220
if(!options.data){
226221
log.error('Subscription request does not include data field.');
227222
}
228-
if (connections.getConnection(connectionId)) {
223+
if (router.getConnection(connectionId)) {
229224
return callback('callback', {type: 'failed', reason: 'Connection already exists:'+connectionId});
230225
}
231226

232227
var conn = null;
233228
switch (connectionType) {
234-
case 'internal':
235-
conn = internalConnFactory.fetch(connectionId, 'out');
236-
if (conn)
237-
conn.connect(options);//FIXME: May FAIL here!!!!!
238-
break;
239229
case 'quic':
240230
conn = createStreamPipeline(connectionId, 'out', options, callback);
241231
const stream = quicTransportServer.createSendStream(options.transport.id, connectionId);
@@ -252,14 +242,14 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
252242
return callback('callback', {type: 'failed', reason: 'Create Connection failed'});
253243
}
254244

255-
connections.addConnection(connectionId, connectionType, options.controller, conn, 'out')
245+
router.addLocalDestination(connectionId, connectionType, conn)
256246
.then(onSuccess(callback), onError(callback));
257247
};
258248

259249
that.unsubscribe = function (connectionId, callback) {
260250
log.debug('unsubscribe, connectionId:', connectionId);
261-
var conn = connections.getConnection(connectionId);
262-
connections.removeConnection(connectionId).then(function(ok) {
251+
var conn = router.getConnection(connectionId);
252+
router.removeConnection(connectionId).then(function(ok) {
263253
if (conn && conn.type === 'internal') {
264254
internalConnFactory.destroy(connectionId, 'out');
265255
} else if (conn) {
@@ -269,19 +259,19 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
269259
}, onError(callback));
270260
};
271261

272-
that.linkup = function (connectionId, audioFrom, videoFrom, dataFrom, callback) {
273-
log.debug('linkup.');
274-
connections.linkupConnection(connectionId, audioFrom, videoFrom, dataFrom).then(onSuccess(callback), onError(callback));
262+
that.linkup = function (connectionId, from, callback) {
263+
log.debug('linkup, connectionId:', connectionId, 'from:', from);
264+
router.linkup(connectionId, from).then(onSuccess(callback), onError(callback));
275265
};
276266

277267
that.cutoff = function (connectionId, callback) {
278268
log.debug('cutoff, connectionId:', connectionId);
279-
connections.cutoffConnection(connectionId).then(onSuccess(callback), onError(callback));
269+
router.cutoff(connectionId).then(onSuccess(callback), onError(callback));
280270
};
281271

282272
that.mediaOnOff = function (connectionId, track, direction, action, callback) {
283273
log.debug('mediaOnOff, connection id:', connectionId, 'track:', track, 'direction:', direction, 'action:', action);
284-
var conn = connections.getConnection(connectionId);
274+
var conn = router.getConnection(connectionId);
285275
if (conn) {
286276
if (conn.type === 'quic') {//NOTE: Only webrtc connection supports media-on-off
287277
conn.connection.onTrackControl(track,
@@ -304,21 +294,11 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
304294
};
305295

306296
that.close = function() {
307-
log.debug('close called');
308-
var connIds = connections.getIds();
309-
for (let connectionId of connIds) {
310-
var conn = connections.getConnection(connectionId);
311-
connections.removeConnection(connectionId);
312-
if (conn && conn.type === 'internal') {
313-
internalConnFactory.destroy(connectionId, conn.direction);
314-
} else if (conn && conn.connection) {
315-
conn.connection.close();
316-
}
317-
}
297+
router.clear();
318298
};
319299

320300
that.onFaultDetected = function (message) {
321-
connections.onFaultDetected(message);
301+
router.onFaultDetected(message);
322302
};
323303

324304
return that;

source/agent/quic/log4cxx.properties

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ log4j.appender.A1.layout.ConversionPattern=%d - %p: %c - %m%n
1212
# The utility to handle the received RTP packets from the browser,
1313
# to handle the FEC/RED packets, generate NACK requests upon packet loss, and
1414
# count receive statistics (packet loss etc.) for RTCP Receiver feedback generation, etc.
15-
log4j.logger.woogeen.ProtectedRTPReceiver=INFO
15+
log4j.logger.owt.ProtectedRTPReceiver=INFO
1616

1717
# The utility to handle the RTP packets sent to the browser,
1818
# to construct the FEC/RED packets if necessary, resend lost packets, and
1919
# count send statistics (bitrate etc.) for internal QoS parameters adjustment, etc.
20-
log4j.logger.woogeen.ProtectedRTPSender=INFO
20+
log4j.logger.owt.ProtectedRTPSender=INFO
2121

2222
# The raw UDP and TCP transports which are used for the connection between the Gateway and AVS.
23-
log4j.logger.woogeen.RawTransport=INFO
23+
log4j.logger.owt.RawTransport=INFO
24+
log4j.logger.owt.TransportSession=INFO
25+
log4j.logger.owt.TransportServer=INFO
26+
log4j.logger.owt.TransportClient=INFO
2427
# If the SctpTransport log is set to debug, heavy IO would affact the connections
25-
log4j.logger.woogeen.SctpTransport=INFO
28+
log4j.logger.owt.SctpTransport=INFO
2629

2730
# The VideoFeedbackReactor is used to connect the WebRTCFeedbackProcessor and
2831
# the ProtectedRTPSender; the WebRTCFeedbackProcessor handles the received RTCP
@@ -31,20 +34,20 @@ log4j.logger.woogeen.SctpTransport=INFO
3134
# information to the VideoFeedbackReactor, which will adjust the (FEC) protection parameters
3235
# according to the RTT, the target send bitrate and the actual bitrate from the
3336
# ProtectedRTPSender statistics, and notify ProtectedRTPSender about the new parameters.
34-
log4j.logger.woogeen.VideoFeedbackReactor=INFO
35-
log4j.logger.woogeen.WebRTCFeedbackProcessor=INFO
37+
log4j.logger.owt.VideoFeedbackReactor=INFO
38+
log4j.logger.owt.WebRTCFeedbackProcessor=INFO
3639

37-
log4j.logger.woogeen.AudioFrameConstructor=INFO
38-
log4j.logger.woogeen.AudioFramePacketizer=INFO
40+
log4j.logger.owt.AudioFrameConstructor=INFO
41+
log4j.logger.owt.AudioFramePacketizer=INFO
3942

40-
log4j.logger.woogeen.VideoFrameConstructor=INFO
41-
log4j.logger.woogeen.VideoFramePacketizer=INFO
43+
log4j.logger.owt.VideoFrameConstructor=INFO
44+
log4j.logger.owt.VideoFramePacketizer=INFO
4245

43-
log4j.logger.woogeen.LiveStreamIn=INFO
44-
log4j.logger.woogeen.LiveStreamIn.JitterBuffer=INFO
45-
log4j.logger.woogeen.AVStreamOut=INFO
46-
log4j.logger.woogeen.MediaFileOut=INFO
47-
log4j.logger.woogeen.LiveStreamOut=INFO
46+
log4j.logger.owt.LiveStreamIn=INFO
47+
log4j.logger.owt.LiveStreamIn.JitterBuffer=INFO
48+
log4j.logger.owt.AVStreamOut=INFO
49+
log4j.logger.owt.MediaFileOut=INFO
50+
log4j.logger.owt.LiveStreamOut=INFO
4851

4952
log4j.logger.mcu.media.AudioMixer=INFO
5053
log4j.logger.mcu.media.AcmmFrameMixer=INFO
@@ -66,19 +69,19 @@ log4j.logger.mcu.media.SoftVideoCompositor.AvatarManager=INFO
6669
log4j.logger.mcu.media.SoftVideoCompositor.SoftInput=INFO
6770
log4j.logger.mcu.media.SoftVideoCompositor.SoftFrameGenerator=INFO
6871

69-
log4j.logger.woogeen.VCMFrameDecoder=INFO
70-
log4j.logger.woogeen.VCMFrameEncoder=INFO
71-
log4j.logger.woogeen.SVTHEVCEncoder=INFO
72-
log4j.logger.woogeen.FrameProcesser=INFO
72+
log4j.logger.owt.VCMFrameDecoder=INFO
73+
log4j.logger.owt.VCMFrameEncoder=INFO
74+
log4j.logger.owt.SVTHEVCEncoder=INFO
75+
log4j.logger.owt.FrameProcesser=INFO
7376

7477
# Msdk media pipeline
75-
log4j.logger.woogeen.MsdkBase=INFO
76-
log4j.logger.woogeen.MsdkFrame=INFO
77-
log4j.logger.woogeen.MsdkFramePool=INFO
78-
log4j.logger.woogeen.MsdkScaler=INFO
79-
log4j.logger.woogeen.MsdkFrameDecoder=INFO
80-
log4j.logger.woogeen.StreamEncoder=INFO
81-
log4j.logger.woogeen.MsdkFrameEncoder=INFO
78+
log4j.logger.owt.MsdkBase=INFO
79+
log4j.logger.owt.MsdkFrame=INFO
80+
log4j.logger.owt.MsdkFramePool=INFO
81+
log4j.logger.owt.MsdkScaler=INFO
82+
log4j.logger.owt.MsdkFrameDecoder=INFO
83+
log4j.logger.owt.StreamEncoder=INFO
84+
log4j.logger.owt.MsdkFrameEncoder=INFO
8285

8386
log4j.logger.mcu.media.MsdkVideoCompositor=INFO
8487
log4j.logger.mcu.media.MsdkVideoCompositor.MsdkAvatarManager=INFO

source/agent/quic/webtransport/quicTransportStreamPipeline.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ module.exports = class QuicTransportStreamPipeline {
2525
this._quicStream = null;
2626
this._notifiedReady = false;
2727

28-
this.quicStream = function (stream) {
28+
this.quicStream = function(stream) {
2929
this._quicStream = stream;
30+
if (this.bindRouterAsSourceCallback) {
31+
this.bindRouterAsSourceCallback(stream);
32+
}
3033
if (!this._notifiedReady) {
3134
updateStatus({
3235
type: 'ready',
@@ -39,7 +42,7 @@ module.exports = class QuicTransportStreamPipeline {
3942
};
4043

4144
this.addDestination = function(name, dst) {
42-
this._quicStream.addDestination(dst);
45+
this._quicStream.addDestination(name, dst);
4346
};
4447

4548
this.receiver = function(kind) {
@@ -50,8 +53,13 @@ module.exports = class QuicTransportStreamPipeline {
5053
return this._quicStream;
5154
};
5255

53-
this.close = function(){
56+
this.close = function() {
5457
this._quicStream.close();
55-
}
58+
};
59+
60+
// https://github.com/open-webrtc-toolkit/owt-server/pull/988 changed the
61+
// dataflow of frames. Since this object is not a native backed JavaScript
62+
// object, router.addLocalSource should be called for this._quicStream.
63+
this.bindRouterAsSourceCallback = null;
5664
}
5765
};

0 commit comments

Comments
 (0)