Expand description
Network Protocol
a I/O-Free protocol for the veloren network crate.
This crate defines multiple different protocols over UnreliableDrain
and
UnreliableSink
traits, which allows it to define the behavior of a
protocol separated from the actual io.
For example we define the TCP protocol on top of Drains and Sinks that can send chunks of bytes. You can now implement your own Drain And Sink that sends the data via tokio’s or std’s implementation. Or you just use a std::mpsc::channel for unit tests without needing a actual tcp socket.
This crate currently defines:
- TCP
- MPSC
- QUIC
eventually a pure UDP implementation will follow
warning: don’t mix protocol, using the TCP variant for actual UDP socket will result in dropped data using UDP with a TCP socket will be a waste of resources.
A channel in this crate is defined as a combination of read and write protocol.
§adding a protocol
We start by defining our DataFormat. For most this is prob Vec<u8>
or
Bytes
. MPSC can directly send a msg without serialisation.
Create 2 structs, one for the receiving and sending end. Based on a generic
Drain/Sink with your required DataFormat.
Implement the SendProtocol
and RecvProtocol
traits respectively.
Implement the Handshake: InitProtocol
, alternatively you can also
implement ReliableDrain
and ReliableSink
, by this, you use the default
Handshake.
This crate also contains consts and definitions for the network protocol.
For an example see TcpDrain
and TcpSink
in the tcp.rs
Modules§
- _internal
- use at own risk, might change any time, for internal benchmarks
- error 🔒
- event 🔒
- frame 🔒
- handshake 🔒
- message 🔒
- metrics 🔒
- mpsc 🔒
- prio 🔒
- quic 🔒
- tcp 🔒
- types 🔒
- util 🔒
Structs§
- Mpsc
Recv Protocol - MPSC implementation of
RecvProtocol
- Mpsc
Send Protocol - MPSC implementation of
SendProtocol
- Pid
- Support struct used for uniquely identifying
Participant
over theNetwork
. - Promises
- use promises to modify the behavior of
Streams
. see the consts in thisstruct
for - Protocol
Metric Cache - Cache for
ProtocolMetrics
, more optimized and cleared up after channel disconnect. - Protocol
Metrics - Use 1
ProtocolMetrics
perNetwork
. I will contain all protocol relatedprometheus
information - Quic
Data Format - Quic
Recv Protocol - QUIC implementation of
RecvProtocol
- Quic
Send Protocol - QUIC implementation of
SendProtocol
- Sid
- Unique ID per Stream, in one Channel. one side will always start with 0, while the other start with u64::MAX / 2. number increases for each created Stream.
- TcpRecv
Protocol - TCP implementation of
RecvProtocol
- TcpSend
Protocol - TCP implementation of
SendProtocol
Enums§
- Init
Protocol Error - All possible Errors that can happen during Handshake
InitProtocol
- MpscMsg
- used for implementing your own MPSC
Sink
andDrain
- Protocol
Error - When you return closed you must stay closed!
- Protocol
Event - used for communication with
SendProtocol
andRecvProtocol
- Quic
Data Format Stream
Constants§
- HIGHEST_
PRIO - Maximal possible Prio to choose (for performance reasons)
- VELOREN_
NETWORK_ VERSION - When this semver differs, 2 Networks can’t communicate.
Traits§
- Init
Protocol - Handshake: Used to connect 2 Channels.
- Recv
Protocol - Generic Network Recv Protocol. See:
SendProtocol
- Send
Protocol - Generic Network Send Protocol.
Implement this for your Protocol of choice ( tcp, udp, mpsc, quic)
Allows the creation/deletions of
Streams
and sending messages viaProtocolEvent
. - Unreliable
Drain - This crate makes use of UnreliableDrains, they are expected to provide the
same guarantees like their IO-counterpart. E.g. ordered messages for TCP and
nothing for UDP. The respective Protocol needs then to handle this.
This trait is an abstraction above multiple Drains, e.g.
tokio
async-std
std
or evenasync-channel
- Unreliable
Sink - Sink counterpart of
UnreliableDrain
Type Aliases§
- Bandwidth
- guaranteed
Bandwidth
. SeePrio
- Cid
- ChannelID, unique ID per Channel (Protocol)
- Prio
- Every Stream has a
Prio
and guaranteedBandwidth
. Every send, the guarantees part is used first. If there is still bandwidth left, it will be shared by all Streams with the same priority. Prio 0 will be send first, then 1, … till the last prio 7 is send. Prio must be < 8!