[Add] Client with session ID
This commit is contained in:
parent
989b6d2615
commit
ee3b2abf98
3 changed files with 12 additions and 3 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -3133,7 +3133,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ttp-core"
|
name = "ttp-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.methanium.net/Tensamin/TTP.git#82b71c1be1fa73aeb0f228c4af364206fda8d712"
|
source = "git+https://git.methanium.net/Tensamin/TTP.git#778f6d14c73e7eab45fc620f8daa095eea296840"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
|
@ -3145,7 +3145,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ttp-native"
|
name = "ttp-native"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.methanium.net/Tensamin/TTP.git#82b71c1be1fa73aeb0f228c4af364206fda8d712"
|
source = "git+https://git.methanium.net/Tensamin/TTP.git#778f6d14c73e7eab45fc620f8daa095eea296840"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quinn",
|
"quinn",
|
||||||
"rustls",
|
"rustls",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use uuid::Uuid;
|
||||||
|
|
||||||
pub struct ClientConnection {
|
pub struct ClientConnection {
|
||||||
pub user_id: u64,
|
pub user_id: u64,
|
||||||
|
pub session_id: u64,
|
||||||
|
|
||||||
pub sender: Arc<Sender>,
|
pub sender: Arc<Sender>,
|
||||||
pub receiver: Arc<Receiver>,
|
pub receiver: Arc<Receiver>,
|
||||||
|
|
@ -37,6 +38,7 @@ impl ClientConnection {
|
||||||
sender: general.sender.clone(),
|
sender: general.sender.clone(),
|
||||||
receiver: general.receiver.clone(),
|
receiver: general.receiver.clone(),
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
|
session_id: general.session_id.read().await.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn start(self: Arc<Self>) {
|
pub fn start(self: Arc<Self>) {
|
||||||
|
|
@ -573,6 +575,7 @@ impl Clone for ClientConnection {
|
||||||
sender: Arc::clone(&self.sender),
|
sender: Arc::clone(&self.sender),
|
||||||
receiver: Arc::clone(&self.receiver),
|
receiver: Arc::clone(&self.receiver),
|
||||||
user_id: self.user_id,
|
user_id: self.user_id,
|
||||||
|
session_id: self.session_id,
|
||||||
ping: Arc::clone(&self.ping),
|
ping: Arc::clone(&self.ping),
|
||||||
pub_key: Arc::clone(&self.pub_key),
|
pub_key: Arc::clone(&self.pub_key),
|
||||||
rho_connection: Arc::clone(&self.rho_connection),
|
rho_connection: Arc::clone(&self.rho_connection),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use rand::{Rng, distributions::Alphanumeric};
|
use rand::{Rng, distributions::Alphanumeric};
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, util::rand_u64};
|
||||||
use ttp_native::{Receiver, Sender};
|
use ttp_native::{Receiver, Sender};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -39,6 +39,7 @@ pub struct GeneralConnection {
|
||||||
connection_kind: Arc<RwLock<Option<ConnectionKind>>>,
|
connection_kind: Arc<RwLock<Option<ConnectionKind>>>,
|
||||||
pub rho_connection: Arc<RwLock<Option<Arc<RhoConnection>>>>,
|
pub rho_connection: Arc<RwLock<Option<Arc<RhoConnection>>>>,
|
||||||
id: Arc<RwLock<u64>>,
|
id: Arc<RwLock<u64>>,
|
||||||
|
pub session_id: Arc<RwLock<u64>>,
|
||||||
|
|
||||||
pub_key: Arc<RwLock<Option<Vec<u8>>>>,
|
pub_key: Arc<RwLock<Option<Vec<u8>>>>,
|
||||||
}
|
}
|
||||||
|
|
@ -53,6 +54,7 @@ impl GeneralConnection {
|
||||||
connection_kind: Arc::new(RwLock::new(None)),
|
connection_kind: Arc::new(RwLock::new(None)),
|
||||||
rho_connection: Arc::new(RwLock::new(None)),
|
rho_connection: Arc::new(RwLock::new(None)),
|
||||||
id: Arc::new(RwLock::new(0)),
|
id: Arc::new(RwLock::new(0)),
|
||||||
|
session_id: Arc::new(RwLock::new(0)),
|
||||||
pub_key: Arc::new(RwLock::new(None)),
|
pub_key: Arc::new(RwLock::new(None)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -156,6 +158,10 @@ impl GeneralConnection {
|
||||||
let _ = self.sender.send(&response).await;
|
let _ = self.sender.send(&response).await;
|
||||||
} else if let DataValue::Number(user_id) = cv.get_data(DataTypes::user_id) {
|
} else if let DataValue::Number(user_id) = cv.get_data(DataTypes::user_id) {
|
||||||
*self.id.write().await = *user_id as u64;
|
*self.id.write().await = *user_id as u64;
|
||||||
|
*self.session_id.write().await = match cv.get_data(DataTypes::session_id) {
|
||||||
|
DataValue::Number(s) => *s as u64,
|
||||||
|
_ => rand_u64(),
|
||||||
|
};
|
||||||
*self.connection_kind.write().await = Some(ConnectionKind::Client);
|
*self.connection_kind.write().await = Some(ConnectionKind::Client);
|
||||||
|
|
||||||
let get_pub_key_msg = CommunicationValue::new(CommunicationType::get_user_data)
|
let get_pub_key_msg = CommunicationValue::new(CommunicationType::get_user_data)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue