Explorar el Código

service/sol: Expire subscriptions after 10 minutes.

parazyd hace 4 años
padre
commit
9af7ce3ca6
Se han modificado 1 ficheros con 11 adiciones y 0 borrados
  1. 11 0
      src/service/sol.rs

+ 11 - 0
src/service/sol.rs

@@ -164,11 +164,22 @@ impl SolClient {
 
         let ping_payload: Vec<u8> = vec![42, 33, 31, 42];
 
+        let mut sub_iter = 0;
+
         loop {
             let message = read.next().await.ok_or(Error::TungsteniteError)?;
             let message = message?;
 
             if let Message::Pong(_) = message.clone() {
+                if sub_iter > 60 * 10 {
+                    // 10 minutes
+                    self.unsubscribe(&mut write, &pubkey, &sub_id).await?;
+                    return Err(SolFailed::RpcError(format!(
+                        "Deposit for {:?} expired",
+                        pubkey
+                    )));
+                }
+                sub_iter += 1;
                 async_std::task::sleep(Duration::from_secs(1)).await;
                 write.send(Message::Ping(ping_payload.clone())).await?;
                 continue;