random client id
This commit is contained in:
Generated
+56
@@ -63,6 +63,17 @@ version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "chacha20"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "client"
|
||||
version = "0.1.0"
|
||||
@@ -129,6 +140,15 @@ dependencies = [
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.22"
|
||||
@@ -191,6 +211,18 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.1"
|
||||
@@ -570,6 +602,29 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80"
|
||||
dependencies = [
|
||||
"chacha20",
|
||||
"getrandom",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.18"
|
||||
@@ -673,6 +728,7 @@ dependencies = [
|
||||
name = "server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shared",
|
||||
|
||||
@@ -8,3 +8,4 @@ shared = { path = "../shared" }
|
||||
serde = { version = "1.0.229", features = ["derive"] }
|
||||
serde_json = "1.0.151"
|
||||
tokio = { version = "1.53.1", features = ["full"] }
|
||||
rand = "0.10.2"
|
||||
|
||||
+5
-8
@@ -6,9 +6,8 @@ use tokio::{
|
||||
net::{TcpListener, UdpSocket},
|
||||
sync::{RwLock, broadcast},
|
||||
};
|
||||
|
||||
// TODO: add auth to this
|
||||
struct Client {
|
||||
tcp_addr: SocketAddr,
|
||||
udp_addr: Option<SocketAddr>,
|
||||
audio_streams: Option<Vec<AudioStreamInfo>>,
|
||||
}
|
||||
@@ -70,8 +69,6 @@ async fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
let mut next_client_id: u32 = 1;
|
||||
|
||||
loop {
|
||||
let (mut tcp_stream, tcp_address) =
|
||||
tcp_listener.accept().await.expect("failed to accept tcp");
|
||||
@@ -82,7 +79,7 @@ async fn main() {
|
||||
let mut global_event_rx = global_event_tx.subscribe();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let mut current_client_id: u32 = 0;
|
||||
let current_client_id: u32 = rand::random();
|
||||
let mut tcp_buf = [0; 4096];
|
||||
|
||||
loop {
|
||||
@@ -97,12 +94,9 @@ async fn main() {
|
||||
Ok(n) => match serde_json::from_slice::<TcpRequest>(&tcp_buf[0..n]) {
|
||||
Ok(request) => match request.data {
|
||||
TcpRequestData::NewConnection => {
|
||||
current_client_id = next_client_id;
|
||||
next_client_id += 1;
|
||||
tcp_state.write().await.insert(
|
||||
current_client_id,
|
||||
Client {
|
||||
tcp_addr: tcp_address,
|
||||
udp_addr: None,
|
||||
audio_streams: None,
|
||||
},
|
||||
@@ -121,6 +115,9 @@ async fn main() {
|
||||
.as_bytes(),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
TcpRequestData::NewAudioStream { audio_stream_info } => {
|
||||
|
||||
}
|
||||
_ => eprintln!("i dont support other requests yet"),
|
||||
},
|
||||
|
||||
@@ -23,7 +23,6 @@ pub struct TcpRequest {
|
||||
#[serde(tag = "type")]
|
||||
pub enum TcpRequestData {
|
||||
NewConnection,
|
||||
DropConnection,
|
||||
NewAudioStream { audio_stream_info: AudioStreamInfo },
|
||||
DropAudioStream { audio_stream_id: u8 },
|
||||
}
|
||||
@@ -40,10 +39,6 @@ pub enum TcpResponseData {
|
||||
NewConnection {
|
||||
client_id: u32,
|
||||
},
|
||||
Updated,
|
||||
UserJoined {
|
||||
user_id: u32,
|
||||
},
|
||||
UserConnected {
|
||||
user_id: u32,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user