WIP connection factory #262
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After some refactoring has been done, "connection manager" as was proposed here #246 became irrelevant, but instead, a much powerful abstraction became available.
This PR proposes a new trait
ConnectionFactory, that basically allows a library user to provide its own, connection implementation.Now all core traits, from bottom-up, looks like this:
Connection- allows implementing an actual connection, also defines what user events it can receive, and what connection events it can send back to a user. This is a core component that actually is able to send packets and events to the user.ConnectionFactory- Defines aConnectiontype, decides when to accept or discard a connection, and provides conversion from user event to an actual connection address (SocketAddr). It cannot send any packets or events directly, but it can track and change the connection state.ConnectionManager- a core component that manages active connections and is generic onDatagramSocketandConnectionFactory. Types for event channels (used to communicate with a user) depends on a ConnectionFactory type.Current
Socketimplementation only creates socket and connection factory instance and pass it toConnectionManager, which provides all the needed functionality.This PR is a minimum implementation (with some basic DDoS protection implemented in a factory), to start a discussion on how to organize code further so that it would provide convenient and flexible utilities for the user, to write more sophisticated connection implementations.
I suggest this course of action to prepare for multiple connection implementations:
src/connections/simpleand moveconnection_impl.rs,events.rs,factory_impl.rs,socket.rs->simple.rs,virtual_connection.rsto it.SockettoSimpleConnectionand add appropriate module definitions so that from the user perspective it could use it like this:use laminar::connections::SimpleConnection;simple_connectioninexamplesandtestsdirectories and move appropriate files in it.VirtualConnectionso other connections could use it as well.E.g. it would be nice to provide a process_incoming/outgoing functions, but with custom StandardHeader implementation.