Răsfoiți Sursa

add random channel id for debugging info

narodnik 4 ani în urmă
părinte
comite
bc0f0e381f
1 a modificat fișierele cu 16 adăugiri și 9 ștergeri
  1. 16 9
      src/net/channel.rs

+ 16 - 9
src/net/channel.rs

@@ -1,19 +1,19 @@
 use async_std::sync::Mutex;
 use async_std::sync::Mutex;
-use std::{
-    net::{SocketAddr, TcpStream},
-    sync::{
-        atomic::{AtomicBool, Ordering},
-        Arc,
-    },
-};
-
 use futures::{
 use futures::{
     io::{ReadHalf, WriteHalf},
     io::{ReadHalf, WriteHalf},
     AsyncReadExt,
     AsyncReadExt,
 };
 };
 use log::{debug, error, info};
 use log::{debug, error, info};
+use rand::Rng;
 use serde_json::json;
 use serde_json::json;
 use smol::{Async, Executor};
 use smol::{Async, Executor};
+use std::{
+    net::{SocketAddr, TcpStream},
+    sync::{
+        atomic::{AtomicBool, Ordering},
+        Arc,
+    },
+};
 
 
 use crate::{
 use crate::{
     system::{StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr, Subscription},
     system::{StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr, Subscription},
@@ -29,6 +29,7 @@ use super::{
 pub type ChannelPtr = Arc<Channel>;
 pub type ChannelPtr = Arc<Channel>;
 
 
 struct ChannelInfo {
 struct ChannelInfo {
+    random_id: u32,
     last_msg: String,
     last_msg: String,
     last_status: String,
     last_status: String,
     // Message log which is cleared on querying get_info
     // Message log which is cleared on querying get_info
@@ -37,11 +38,17 @@ struct ChannelInfo {
 
 
 impl ChannelInfo {
 impl ChannelInfo {
     fn new() -> Self {
     fn new() -> Self {
-        Self { last_msg: String::new(), last_status: String::new(), log: Mutex::new(Vec::new()) }
+        Self {
+            random_id: rand::thread_rng().gen(),
+            last_msg: String::new(),
+            last_status: String::new(),
+            log: Mutex::new(Vec::new()),
+        }
     }
     }
 
 
     async fn get_info(&self) -> serde_json::Value {
     async fn get_info(&self) -> serde_json::Value {
         let result = json!({
         let result = json!({
+            "random_id": self.random_id,
             "last_msg": self.last_msg,
             "last_msg": self.last_msg,
             "last_status": self.last_status,
             "last_status": self.last_status,
             "log": self.log.lock().await.clone(),
             "log": self.log.lock().await.clone(),