aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgilles henaux <gill.henaux@gmail.com>2023-01-15 00:26:22 +0100
committergilles henaux <gill.henaux@gmail.com>2023-01-15 00:26:22 +0100
commit8b316885cbe5465864ce8dfb1752433e3bac63e7 (patch)
tree85c51192c70099abc4478070989884d712b342b3
parentb81ee06a892c9c196dff6635a36be8ec48babd08 (diff)
[channels] Return the default ChannelId when opening connection/endpoint
-rw-r--r--src/client.rs8
-rw-r--r--src/lib.rs4
-rw-r--r--src/server.rs39
3 files changed, 27 insertions, 24 deletions
diff --git a/src/client.rs b/src/client.rs
index 7e5680b..8a1eee5 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -430,11 +430,13 @@ impl Client {
}
/// Open a connection to a server with the given [ConnectionConfiguration] and [CertificateVerificationMode]. The connection will raise an event when fully connected, see [ConnectionEvent]
+ ///
+ /// Returns the [ConnectionId], and the default [ChannelId]
pub fn open_connection(
&mut self,
config: ConnectionConfiguration,
cert_mode: CertificateVerificationMode,
- ) -> Result<ConnectionId, QuinnetError> {
+ ) -> Result<(ConnectionId, ChannelId), QuinnetError> {
let (bytes_from_server_send, bytes_from_server_recv) =
mpsc::channel::<Bytes>(DEFAULT_MESSAGE_QUEUE_SIZE);
@@ -460,7 +462,7 @@ impl Client {
from_channels_recv,
};
// Create default channels
- connection.open_channel(ChannelType::OrderedReliable)?;
+ let ordered_reliable_id = connection.open_channel(ChannelType::OrderedReliable)?;
connection.open_channel(ChannelType::UnorderedReliable)?;
connection.open_channel(ChannelType::Unreliable)?;
@@ -485,7 +487,7 @@ impl Client {
self.default_connection_id = Some(connection_id);
}
- Ok(connection_id)
+ Ok((connection_id, ordered_reliable_id))
}
/// Set the default connection
diff --git a/src/lib.rs b/src/lib.rs
index cd155c2..bff2b7f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -219,7 +219,7 @@ mod tests {
// Server listens with a cert loaded from a file
{
let mut server = server_app.world.resource_mut::<Server>();
- let server_cert = server
+ let (server_cert, _) = server
.start_endpoint(
ServerConfigurationData::new(
SERVER_HOST.to_string(),
@@ -349,7 +349,7 @@ mod tests {
// Let the endpoint fully stop.
sleep(Duration::from_secs_f32(0.1));
- let server_cert = server_app
+ let (server_cert, _) = server_app
.world
.resource_mut::<Server>()
.start_endpoint(
diff --git a/src/server.rs b/src/server.rs
index eda7d18..50568f9 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -492,9 +492,10 @@ impl Endpoint {
}
fn open_default_channels(&mut self) -> Result<ChannelId, QuinnetError> {
- self.open_channel(ChannelType::OrderedReliable)?;
+ let ordered_reliable_id = self.open_channel(ChannelType::OrderedReliable)?;
self.open_channel(ChannelType::UnorderedReliable)?;
- self.open_channel(ChannelType::Unreliable)
+ self.open_channel(ChannelType::Unreliable)?;
+ Ok(ordered_reliable_id)
}
fn create_channel(&mut self, channel_id: ChannelId) -> Result<ChannelId, QuinnetError> {
@@ -562,11 +563,13 @@ impl Server {
}
/// Run the server with the given [ServerConfigurationData] and [CertificateRetrievalMode]
+ ///
+ /// Returns the [ServerCertificate] generated or loaded, and the default [ChannelId]
pub fn start_endpoint(
&mut self,
config: ServerConfigurationData,
cert_mode: CertificateRetrievalMode,
- ) -> Result<ServerCertificate, QuinnetError> {
+ ) -> Result<(ServerCertificate, ChannelId), QuinnetError> {
let server_adr_str = format!("{}:{}", config.local_bind_host, config.port);
let server_addr = server_adr_str.parse::<SocketAddr>()?;
@@ -603,22 +606,20 @@ impl Server {
.await;
});
- {
- let mut endpoint = Endpoint {
- clients: HashMap::new(),
- channels: HashSet::new(),
- default_channel: None,
- last_gen_id: 0,
- payloads_from_clients_recv,
- close_sender: endpoint_close_send,
- from_async_server_recv,
- to_async_server_send: to_async_server_send.clone(),
- };
- endpoint.open_default_channels()?;
- self.endpoint = Some(endpoint);
- }
-
- Ok(server_cert)
+ let mut endpoint = Endpoint {
+ clients: HashMap::new(),
+ channels: HashSet::new(),
+ default_channel: None,
+ last_gen_id: 0,
+ payloads_from_clients_recv,
+ close_sender: endpoint_close_send,
+ from_async_server_recv,
+ to_async_server_send: to_async_server_send.clone(),
+ };
+ let ordered_reliable_id = endpoint.open_default_channels()?;
+ self.endpoint = Some(endpoint);
+
+ Ok((server_cert, ordered_reliable_id))
}
pub fn stop_endpoint(&mut self) -> Result<(), QuinnetError> {