pipe / sctp4j

Pure Java implementation of SCTP with webRTC data channel support
38 stars 9 forks source link

SCTP over DTLS over UDP for client-server communication #6

Open cnudroid opened 4 years ago

cnudroid commented 4 years ago

I have a use case where I want to establish a java client-server communication via SCTP over DTLS over UDP similar to webrtc data channel. This library looks promising. I want to use it with java 11 and netty eventually. Can you please provide some pointers?

steely-glint commented 3 years ago

Ok, for the full webRTC datachannel you'll need 4 things: 1) ICE (I use https://github.com/steely-glint/slice but Jitsi's ICE4J works too) 2) DTLS (I use Bouncy castle - Java11 has DTLS built in, but I've never investigated it) 3) SCTP (I use this lib) 4) SDP layer that manages offer-answer and orchestrates the first 3 - ours is proprietary

I haven't looked at netty for a while, but this SCTP library needs to be able to create threads - so you may have to do some work to fit that into netty's view of the world.

If you are rolling your own SCTP over DTLS protocol then you may not need 1 and 4 which would make things a lot simpler.

cnudroid commented 3 years ago

Thanks for your inputs @steely-glint. I need to establish a client-server channel to transfer data and wanted to use SCTP over UDP instead of TCP. I am thinking we can use DTLS from bountycastle and for SCTP will use this library. Do we really need ICE and SDP layer?

steely-glint commented 3 years ago

No, you only need SDP if you want to interop with webRTC.

You only need ICE if you have NAT or other problems with network topology.

This stack calls it self a SCTP stack, but the API does assume webRTC datachannel - so instead of plain SCTP streams, you get labeled streams with names as in webRTC.

cnudroid commented 3 years ago

Here is an update:

As far so good till I tried to send data of larger lengths. With large data, I am getting the following error

_DTLS server raised alert: fatal(2), internalerror(80)

@steely-glint my understanding is that when we send data which is larger than MTU, the sctp protocol will break them into multiple data chunks and transfer. Please correct me if I got this wrong.

steely-glint commented 3 years ago

If you look at ThreadAssocationTest you can see that it tests sending and receiving large messages, which the stack breaks up into datachunks that are smaller than the DTLS MTU. It definitely sounds like the MTU isn't getting passed up to sctp correctly.

If you add Log.setLevel(Log.VERB); to your program and attach the output I can probably figure out what is happening.

cnudroid commented 3 years ago

Thanks @steely-glint The issue is that the getCapacity of DataChunk is hardcoded to 1024 and my DTLSTransport MTU is coming as 383. Things started working after changing the value of getCapacity to 256.

The system mtu shows 1500. Not sure why the Dtlstransport is returning it as 383. Currently checking it. Will keep you posted.