TimonPost / laminar

A simple semi-reliable UDP protocol for multiplayer games
821 stars 66 forks source link

WIP connection factory #262

Closed fraillt closed 4 years ago

fraillt commented 4 years ago

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:

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:

  1. create a new folder src/connections/simple and move connection_impl.rs, events.rs, factory_impl.rs, socket.rs->simple.rs, virtual_connection.rs to it.
  2. rename Socket to SimpleConnection and add appropriate module definitions so that from the user perspective it could use it like this: use laminar::connections::SimpleConnection;
  3. create simple_connection in examples and tests directories and move appropriate files in it.
  4. extract useful bits and interfaces from VirtualConnection so 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.
fraillt commented 4 years ago

After discussion in discord, it was decided that this additional abstraction is not required, because it doesn't solve any direct problems for now.