-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add use_srtp extension #30
Comments
This is rfc5764. To be clear, SRTP I/O should do any other package. This package only for dtls. The dtls/src/node_modules/lib/socket.js Lines 281 to 289 in 626c5bb
Anyway, SRTP is a part of Media API which is not my priority. I focused only on datachannels. Only any business interests and support may change my internal priority 😸 . |
Let my clarify that I'm not asking for this Now, sorry for the off-topic: What it comes to my mind when I see all these const ice = require('@nodertc/ice');
const dtls = require('@nodertc/dtls');
const rtp = require('@foo/rtp');
const srtp = require('@foo/srtp');
const is_rtp = require('is-rtp');
// Create a ICE connection.
const iceConnection = ice.connect(
{
remoteCandidates : [ {}, {}, {}... ],
userFrag : 'iaasdgjahsdgjh',
password : '1234'
});
// Wait for ICE to be established.
await new Promise((resolve) => iceConnection.on('connected', resolve));
// Create a DTLS association on top of the ICE connection.
// Note that iceConnection.getSocket() does not return a net.Socket
// but a special object with similar interface. This is because ICE
// may move to a different ip:port tuple at any time due to reconnections
// after ICE disconnections.
const dtlsConnection = dtls.connect(
{
socket : iceConnection.getSocket(),
useSrtp : true
});
// Wait for DTLS to be connected.
await new Promise((resolve) => dtlsConnection.on('connected', resolve));
// Create a SRTP session with the material negotiated via DTLS.
const srtpSession = srtp.createSession(
{
keys : dtlsConnection.getSrtpKeys()
});
// Create a dummy RTP packet.
const rtpPacket = rtp.createPacket(
{
payloadType : 111,
seq : 12345,
timestamp : Date.now(),
payload : new Buffer(...)
});
// Encrypt the packet with SRTP.
const srtpPacket = srtpSession.encrypt(rtpPacket);
// Send the SRTP packet.
iceConnection.send(srtpPacket.getRaw());
// Listen for incoming SRTP packets.
iceConnection.on('packet', (packet) =>
{
if (is_rtp(packet))
{
const srtpPacket = rtp.parse(packet);
const rtpPacket = srtpSession.decrypt(srtpPacket);
console.log(
'received RTP packet [payloadType:%d, seq:%d]',
rtpPacket.getPayloadType(), rtpPacket.getSeq());
}
}); Do you have something like this in mind? Jjust ignore the RTP/SRTP stuff above, please, it can be done by a 3rd party library. |
Yes, you're right. It may look somethings like this. One note: //...
dtlsConnection.once('connect', () => {
// ready for any i/o.
});
//... |
Yes, I already waited for DTLS connection in my pseudo code above: // Wait for DTLS to be connected.
await new Promise((resolve) => dtlsConnection.on('connect', resolve)); :) |
Let me just one question more, please. I'm looking for the best way to implement DataChannel in my SFU mediasoup. mediasoup is Node with C++ subprocesses that handle media (UDP, TCP, ICE, DTLS, SRTP, etc). The Node layer controls those C++ subprocesses via UnixSocket. Once the DTLS is established, I already have a C++ API to send and receive "DTLS application data":
If we assume that those "DTLS application data" are SCTP packets, I can push them verbatim to the mediasoup Node.js layer and use your Assuming that, it's not clear to me how to combine both Is my use case possible using your libs? Perhaps the P.S. I do not see any API in |
First,
This module may have bugs and do not follow my standards of code quality. You may ask @latysheff as original author sctp about stability. As i sayd before, after my fixes https://github.com/nodertc/nodertc/blob/a7bd7aca00bd389723f3cdc665653459667c408a/index.js#L328-L350 for details. It's nodertc prototype. |
The API of sctp module is the same as Node's Net module. That is, use |
Thanks to both for your comments. So now there are two Node SCTP implementations that can run over DTLS:
@reklatsmasters, if you are building a complete DataChannel stack I assume you'll have to eventually work on |
@ibc yes.See https://github.com/nodertc/nodertc/blob/a7bd7aca00bd389723f3cdc665653459667c408a/index.js to understand how it’s work. |
It would be super cool if the
Socket
class would include:Of course, a Node RTP parser/factory library would aso be needed. I've found this one (which seems to be unmaintained). SRTP encryption/decryption capabilities would also be needed obviously (and that would be a hard work).
The text was updated successfully, but these errors were encountered: