Crate lyanne

Crate lyanne 

Source
Expand description

Efficient, tick-oriented communication library for server-client architectures.

Lyanne is an abstraction for communication between client and server, greatly simplifying the process, maintaining low latency and low resource usage.

Moves the most resource-intensive work to asynchronous operations, but both client and server calls, such as sending/receiving packets, can be used in synchronous contexts.

Being highly customizable, Lyanne supports:

  • Multiple runtimes.
  • Different ways of serializing/deserializing packages.
  • Different authenticators, including the required/optional use of tls with rustls.

All within features, keeping compilation time fast.

§Examples

Adding lyanne dependency in server:

[dependencies]
lyanne = { version = "0.5", features = [
    "rt_smol", # We need one runtime.
    "sd_bincode", # Serde + Bincode will help our packet serialization/deserialization.
    "server", # Server exclusive feature.
] }

# Our runtime.
smol = "^2.0.0"

# Our serializer.
serde = { version = "^1.0.0", features = ["derive"] }
bincode = "^1.0.0"

Adding lyanne dependency in client:

[dependencies]
lyanne = { version = "0.5", features = [
    # ...
    "client", # Same as the server, but using "client" instead of "server".
] }

Creating packets with sd_bincode:

use lyanne::packets::Packet;
use serde::{Deserialize, Serialize};

#[derive(Packet, Deserialize, Serialize, Debug)]
struct HelloPacket {
    player_name: String,
}

#[derive(Packet, Deserialize, Serialize, Debug)]
struct MessagePacket {
    message: String,
}

§Cargo Features

No feature is enabled by default, but at least one runtime feature is required.

Each feature is being used by at least one example inside examples, see README for more information.

featuredescription
clientEnable client exclusive module
serverEnable server exclusive module
rt_async_executorUses async-executor as runtime
rt_async_stdUses async-std as runtime
rt_bevyUses bevy_tasks as runtime
rt_smolUses smol as runtime
rt_tokioUses tokio as runtime
sd_bincodeUses serde + bincode as packet serializer/deserializer
auth_tcpUses Tcp socket to exchange keys to encrypt the udp communication. Warning: this feature alone is not responsible to encrypt the entire connection, some additional cryptography in that Tcp port is needed,such as a reverse proxy, like nginx.
auth_tlsUses Tcp socket with tls (using rustls) to exchange keys to encrypt the udp communication. Warning: The encryption of the crate with rustls has not yet been subjected to a series of tests.
bevy_packet_schedulesCreates Scheduled Labels for structs that derive from Packet.
deserialized_message_mapReceived packets will be read in maps (with the keys being the packet IDs), instead of being stored in a list. This does not affect communication, only the way the data is stored for reading.
store_unexpectedStores unexpected communication errors in each tick, such as incorrect communication. It is generally a debugging tool and adds a small overhead.
no_panicsRemoves the public crate functions that cause panic, leaving only the versions of the same that use the try_ prefix and have the return being a Result. The panic of those functions are usually related to unusual scenarios, such as incorrect use of server::AuthEntry, incorrect use of tick cycle, sending unregistered packets…

Modules§

clientclient
Client exclusive module.
packets
Sets of data that are transferred over the communication.
serverserver
Server exclusive module.

Macros§

add_essential_packets
Adds essential packages

Structs§

DeserializedMessage
Represents a packet collection.
LimitedMessage
Message limited by maximum socket send/receive bytes.
MessagingProperties
General properties for the communication messaging.
ReadHandlerProperties
Properties for reading data via UdpSocket.

Type Aliases§

MessagePartId