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

Add Transport layer based on memory channels #117

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

OleStrohm
Copy link
Contributor

Overview

This pull request implements a transport layer based on the stdlib mpsc channel.
This allows the renet server and clients to communicate efficiently within a single program.
This is especially useful for testing networking code, where you want to be able to guarantee that messages arrive immediately, without having to go through the OS network layer.
This should also hopefully allow benchmarks to be more consistent.

It also allows more efficient emulation of a locally hosted server that actually runs within the same binary.

Notes

As this can only be used within the same program, I decided to only expose a way to create new clients from an already existing server. I think this method simplifies the API significantly, and doesn't diminish the ergonomics in the scenarios I am able of thinking of.

I'm not very happy with the current state of the Connection struct, so any advice on that would be very welcome. The problem arises from Sender/Receiver being !Sync, but bevy resources need to be Sync. Bevy therefore provides a SyncCell which can turn Send types into Sync types by only allowing access through a &mut SyncCell<T>. However if this is used outside bevy, then SyncCell is not available. Thus in the current implementation the Transports are !Sync when used standalone.
The only good solution I can think of to remedy this would be to copy a barebones version of Bevy's SyncCell and use that. This isn't a great solution, but this struct isn't public outside of renet_channel, so it might be okay.

I also wasn't sure what to do about the example, since this layer only runs within the same process you can't make a proper echo example, so I just added a whole bunch of tests.

@lucaspoffo lucaspoffo self-requested a review October 11, 2023 00:39
renet_channel/src/client.rs Outdated Show resolved Hide resolved
renet_channel/src/server.rs Show resolved Hide resolved
renet_channel/src/server.rs Outdated Show resolved Hide resolved
@OleStrohm
Copy link
Contributor Author

I added a method to create a client with a specific client id in case people want to test reconnection strategies that rely on the client id.

@UkoeHB
Copy link
Contributor

UkoeHB commented Apr 21, 2024

@OleStrohm I implemented memory channels as a netcode socket option in renet2. The channel part was re-implemented from scratch (not that many lines), but I did use your test suite from this PR.

Here's the exact commit.

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.

2 participants