Skip to content
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

Feature: implement EngineIO V3 (closes #22) #24

Merged
merged 45 commits into from
Jul 2, 2023

Conversation

sleeyax
Copy link
Contributor

@sleeyax sleeyax commented Jun 18, 2023

Here's some initial progress on the V3 implementation. Please provide detailed feedback if you can, I don't consider myself proficient in Rust yet.

Protocol implementation steps:

  • Use counting of characters instead of a record separator (\x1e)
  • Reverse ping/pong mechanism
  • Support non-base64-encoded binary payload

E2E tests: socketio/engine.io-protocol#45

@sleeyax sleeyax marked this pull request as draft June 18, 2023 19:51
@sleeyax
Copy link
Contributor Author

sleeyax commented Jun 18, 2023

Marked this as draft because I still need to implement the rest for the protocol to work properly. I'm moving on with the reverse ping/pong mechanism. Feel free to check the code in the meantime though.

@sleeyax sleeyax changed the title Feature: implement EngineIO V3 counting of characters Feature: implement EngineIO V3 Jun 18, 2023
@Totodore
Copy link
Owner

Totodore commented Jun 18, 2023

Thanks for starting all of this !

I have just one suggestion, I think it is much better to have feature flags for versions (with v4,v3), and a default feature flag set on v4 and that you do all your version conditions on those feature flags. It would allow to remove useless code at compile time and also to have the information everywhere in the codebase without having a ProtocolVersion enum.

Also, don't forget to rebase from main regularly

Copy link
Owner

@Totodore Totodore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start, I think the feature flag solution would be better for the codebase.

engineioxide/src/engine.rs Show resolved Hide resolved
engineioxide/src/engine.rs Outdated Show resolved Hide resolved
@Totodore
Copy link
Owner

Totodore commented Jun 18, 2023

I think end to end test-suites are very important, therefore if I have the time I'll try to make one for the v3 version (by copying v4) and modifing things according to changes between v3 & v4. It could be tested with the official engine.io v3 to be sure it is ok.

We would then be sure that this implementation is correct

@sleeyax
Copy link
Contributor Author

sleeyax commented Jun 18, 2023

Agreed, feature flags make more sense for this project. I'll make adjustments.

@biryukovmaxim
Copy link
Contributor

Currently ts version has option allowEI3 and it works with both versions.
So I would suggest to have ProtocolVersion as param in case of V3 flag is enabled.

@Totodore
Copy link
Owner

I agree but it should be a separate feature for when eio3 is already supported.

@sleeyax sleeyax changed the base branch from ft-engineio-v3-support to main June 25, 2023 12:50
@sleeyax sleeyax changed the title Feature: implement EngineIO V3 Feature: implement EngineIO V3 (closes #22) Jun 25, 2023
@sleeyax sleeyax linked an issue Jun 25, 2023 that may be closed by this pull request
The V3 protocol handles transport upgrades slightly different. This commit solves an issue where the transport would be forever stuck in a polling state, even though the client thinks it has already been upgraded to websocket.
@sleeyax
Copy link
Contributor Author

sleeyax commented Jun 29, 2023

I think end to end test-suites are very important, therefore if I have the time I'll try to make one for the v3 version (by copying v4) and modifing things according to changes between v3 & v4. It could be tested with the official engine.io v3 to be sure it is ok.

We would then be sure that this implementation is correct

Just got started on this as well, feel free to suggest adjustments: socketio/engine.io-protocol#45

@Totodore
Copy link
Owner

Sure ! I totally agree with you

engineioxide/src/engine.rs Fixed Show fixed Hide fixed
@sleeyax
Copy link
Contributor Author

sleeyax commented Jul 2, 2023

I've addressed everything now :)

@sleeyax sleeyax requested a review from Totodore July 2, 2023 09:22
@Totodore
Copy link
Owner

Totodore commented Jul 2, 2023

I can't comment on unchanged lines but I think you should rename this part to heartbeat_rx and heartbeat_tx in socket.rs because in v3 it would be ping_rx and ping_tx so it is better to have an agnostic name (and also change comments accordingly) :

    /// Internal channel to receive Pong [`Packets`](Packet) in the heartbeat job
    /// which is running in a separate task
    pong_rx: Mutex<mpsc::Receiver<()>>,
    /// Channel to send Ping [`Packets`](Packet) from the connexion to the heartbeat job
    /// which is running in a separate task
    pub(crate) pong_tx: mpsc::Sender<()>,

engineioxide/src/service.rs Outdated Show resolved Hide resolved
engineioxide/src/service.rs Outdated Show resolved Hide resolved
engineioxide/src/payload.rs Show resolved Hide resolved
engineioxide/src/payload.rs Outdated Show resolved Hide resolved
engineioxide/src/engine.rs Outdated Show resolved Hide resolved
@sleeyax
Copy link
Contributor Author

sleeyax commented Jul 2, 2023

Round 2 of the PR review : ✔️

Please let me know if more changes are required. I'd be happy to see this merged soon :)

Copy link
Owner

@Totodore Totodore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, however the action e2e_v3 seems to fail...
I'm going to merge it and maybe we could make another PR to fix if there is still an action error

@Totodore Totodore merged commit 3b802d9 into Totodore:main Jul 2, 2023
@biryukovmaxim
Copy link
Contributor

biryukovmaxim commented Jul 2, 2023

@Totodore oops

match self.reader.read_until(b':', &mut self.buffer) {

there is a security issue:
if there is no separator and a client send a lot of data it will increase buffer until memory is running out.

in case of getting the length it mustn't exceed 8 bytes.
in case of reading until separator(v4) it mustn't exceed configured size.

@Totodore
Copy link
Owner

Totodore commented Jul 2, 2023

Right, let's fix that in another PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add EngineIo v3 support
3 participants