@nodertc/sctp v0.1.0
@nodertc/sctp
SCTP network protocol RFC4960 in plain js
Install
npm i @nodertc/sctp
Usage
const securesocket = dtls.connect(/*...*/);
const socket = sctp.connect({
localPort: 5000,
port: 5000,
transport: securesocket,
});
socket.on('connect', socket => {
console.log('socket connected')
socket.write(Buffer.from('010003010000001000110008000003ea', 'hex'))
})
socket.on('data', buffer => {
console.log('socket received data from server', buffer.toString())
socket.end()
})
In UDP mode host and localAddress will be ignored, because addressing is provided by underlying transport.
Also note that in most cases "passive" connect is a better alternative to creating server.
passive option disables active connect to remote peer. Socket waits for remote connection, allowing it only from indicated remote port. This unusual option doesn't exist in TCP API.
new net.Socket(options)
- options Object
For SCTP socketss, available options are:
- ppid number Payload protocol id (see below)
- stream_id number SCTP stream id. Default: 0
- unordered boolean Indicate unordered mode. Default: false
- no_bundle boolean Disable chunk bundling. Default: false
Note: SCTP does not support a half-open state (like TCP) wherein one side may continue sending data while the other end is closed.
socket.connect(options, connectListener)
- options Object
- connectListener Function Common parameter of socket.connect() methods. Will be added as a listener for the 'connect' event once.
For SCTP connections, available options are:
- port number Required. Port the socket should connect to.
- host string Host the socket should connect to. Default: 'localhost'
- localAddress string Local address the socket should connect from.
- localPort number Local port the socket should connect from.
- MIS number Maximum inbound streams. Default: 2
- OS number Requested outbound streams. Default: 2
- passive boolean Indicates passive mode. Socket will not connect, but allow connection of remote socket from host:port. Default: false
- transport stream.Duplex Any valid Duplex stream.
socket.createStream(id)
Creates SCTP stream with stream id. Those are SCTP socket sub-streams.
After the association is initialized, the valid outbound stream identifier range for either endpoint shall be 0 to min(local OS, remote MIS)-1.
You can check this negotiated value by referring to socket.OS
after 'connect' event. id should be less the socket.OS.
Result is stream.Writable.
const stream = socket.createStream(1)
stream.write('some data')
Socket events
See Net module documentation.
For SCTP additional event 'stream' is defined. It signals that incoming data chunk were noticed with new SCTP stream id.
socket.on('stream', (stream, id) => {
stream.on('data', data => {
// Incoming data
})
})
sctp.defaults(options)
Function sets default module parameters. Names follow net.sctp conventions. Returns current default parameters.
See sysctl -a | grep sctp
Example:
sctp.defaults({
rto_initial: 500,
rto_min: 300,
rto_max: 1000,
sack_timeout: 150,
sack_freq: 2,
})
sctp.PPID
sctp.PPID is an object with SCTP Payload Protocol Identifiers
{
SCTP: 0,
IUA: 1,
M2UA: 2,
M3UA: 3,
SUA: 4,
M2PA: 5,
V5UA: 6,
H248: 7,
BICC: 8,
...
}
RFC to implement
- 3758 Partial Reliability Extension
- 4820 Padding Chunk and Parameter
- 4895 Authenticated Chunks
- 5061 Dynamic Address Reconfiguration
- 5062 Security Attacks Found Against SCTP and Current Countermeasures
- 6525 Stream Reconfiguration
- 7053 SACK-IMMEDIATELY Extension (I-bit)
- 7496 Additional Policies for the Partially Reliable Extension
- 7829 SCTP-PF: A Quick Failover Algorithm
- 8260 Stream Schedulers and User Message Interleaving (I-DATA Chunk)
- Draft: ECN for Stream Control Transmission Protocol
License
- MIT, 2017-2018 © Vladimir Latyshev
- MIT, 2018 © Dmitriy Tsvettsikh
6 years ago