-
Notifications
You must be signed in to change notification settings - Fork 74
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
Implement WebRTC messages framing #2896
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.
twiggy diff reportDifference in .wasm size before and after this pull request.
|
This PR turned into a bit of a "fix every WebRTC issue" PR, but it is much more productive to just push everything onto a branch instead of analyze each bug individually. |
"o=- 0 0 IN IP" + ipVersion + " " + targetIp + "\n" + | ||
// Name for the session. We are allowed to pass a dummy `-`. (RFC8866) | ||
"s=-" + "\n" + | ||
// Start and end of the validity of the session. `0 0` means that the session never | ||
// expires. (RFC8866) | ||
"t=0 0" + "\n" + | ||
// A lite implementation is only appropriate for devices that will | ||
// *always* be connected to the public Internet and have a public | ||
// A non-lite implementation is only appropriate for devices that will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??? This was a copy from the specification. Did something change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? The specification doesn't contain this text. It's me who wrote it. It has a mistake in it, it says that lite implementations are only for publicly-accessible devices. But no, it's non-lite implementations that are for public devices. We're not a public device, so we use the lite implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Certain ICE agents will always be connected to the public Internet
and have a public IP address at which it can receive packets from any
correspondent. To make it easier for these devices to support ICE,
ICE defines a special type of implementation called "lite" (in
contrast to the normal full implementation). Lite agents only use
host candidates and do not generate connectivity checks or run state
machines, though they need to be able to respond to connectivity
checks." https://datatracker.ietf.org/doc/rfc8445/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By specifying ice-lite
in server's SDP (that we're pretending we've received through some channel, but instead construct manually), we're saying that server is publicly accessible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest this text doesn't make sense to me no matter whether it says "lite" or "not lite", so I've just reverted it 🤷
@@ -303,8 +304,9 @@ export function start(options?: ClientOptions): Client { | |||
// (UDP or TCP) | |||
"a=sctp-port:5000" + "\n" + | |||
// The maximum SCTP user message size (in bytes) (RFC8841) | |||
"a=max-message-size:100000" + "\n" + | |||
// A transport address for a candidate that can be used for connectivity checks (RFC8839). | |||
"a=max-message-size:16384" + "\n" + // TODO: should this be part of the spec? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subject to a change, but yes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc libp2p/specs#412
cc #1712
This PR finishes implementing the WebRTC spec by adding the last remaining item: the messages framing.
Implementing this messages framing while minimizing the amount of data copies is rather challenging.
Instead of going for the complicated solution, I went for the more easy solution of having an intermediate read buffer where data is first copied.
Going for the simple solution decreases the chances of bugs and increases the ease of debugging, so it's preferable at the moment.
In the future, once WebRTC is fully working, we can rewrite this messages framing code in a more optimized way.