aboutsummaryrefslogtreecommitdiff
path: root/src/client.rs
diff options
context:
space:
mode:
authorgilles henaux <gill.henaux@gmail.com>2023-01-07 17:45:27 +0100
committergilles henaux <gill.henaux@gmail.com>2023-01-11 14:47:33 +0100
commit828ba5e7fffb5275c3f15185703c7b7bbf43c6af (patch)
treed7393c6abec77675fd82b6c26bb7cfd5ccfc7f42 /src/client.rs
parent14a26107031ddf10a86980e0f8ee588ac8b20d85 (diff)
[channels] Homegenize open_channel and close_channel interface
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/client.rs b/src/client.rs
index 842db6b..69a8a62 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -30,7 +30,7 @@ use tokio::{
use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec};
use crate::shared::{
- channel::{Channel, ChannelId, OrdRelChannelId},
+ channel::{Channel, ChannelId, ChannelType, OrdRelChannelId},
AsyncRuntime, QuinnetError, DEFAULT_KILL_MESSAGE_QUEUE_SIZE, DEFAULT_MESSAGE_QUEUE_SIZE,
};
@@ -297,12 +297,38 @@ impl Connection {
}
}
- pub fn open_ordered_reliable_channel(&mut self) -> Result<ChannelId, QuinnetError> {
+ pub fn open_channel(&mut self, channel_type: ChannelType) -> Result<ChannelId, QuinnetError> {
+ match channel_type {
+ ChannelType::OrderedReliable => {
+ self.last_gen_id += 1;
+ let channel_id = ChannelId::OrderedReliable(self.last_gen_id);
+ self.create_channel(channel_id)
+ }
+ ChannelType::UnorderedReliable => {
+ let channel_id = ChannelId::UnorderedReliable;
+ match self.channels.contains_key(&channel_id) {
+ true => Ok(channel_id),
+ false => self.create_channel(channel_id),
+ }
+ }
+ ChannelType::Unreliable => {
+ let channel_id = ChannelId::Unreliable;
+ match self.channels.contains_key(&channel_id) {
+ true => Ok(channel_id),
+ false => self.create_channel(channel_id),
+ }
+ }
+ }
+ }
+
+ pub fn close_channel(&mut self, channel_id: ChannelId) {
+ todo!()
+ }
+
+ fn create_channel(&mut self, channel_id: ChannelId) -> Result<ChannelId, QuinnetError> {
let (to_server_sender, to_server_receiver) =
mpsc::channel::<Bytes>(DEFAULT_MESSAGE_QUEUE_SIZE);
- self.last_gen_id += 1;
- let channel_id = ChannelId::OrderedReliable(self.last_gen_id);
match self
.internal_sender
.try_send(InternalSyncMessage::CreateChannel {
@@ -412,10 +438,10 @@ impl Client {
internal_receiver: from_async_client,
internal_sender: to_async_client,
};
- // Create a default channel
- if let Err(err) = connection.open_ordered_reliable_channel() {
- return Err(err);
- }
+ // Create default channels
+ connection.open_channel(ChannelType::OrderedReliable)?;
+ connection.open_channel(ChannelType::UnorderedReliable)?;
+ connection.open_channel(ChannelType::Unreliable)?;
// Async connection
self.runtime.spawn(async move {