diff --git a/backend/src/controller/crypto.rs b/backend/src/controller/crypto.rs index 174fa0e7..dc01762f 100644 --- a/backend/src/controller/crypto.rs +++ b/backend/src/controller/crypto.rs @@ -59,7 +59,7 @@ impl CryptoController { let signing_key = SigningKey::random(&mut OsRng); - let verifying_key = signing_key.verifying_key().clone(); + let verifying_key = *signing_key.verifying_key(); Self { salt, diff --git a/backend/src/controller/judger/route/direct.rs b/backend/src/controller/judger/route/direct.rs index 5f4e7af1..13579233 100644 --- a/backend/src/controller/judger/route/direct.rs +++ b/backend/src/controller/judger/route/direct.rs @@ -2,18 +2,19 @@ use super::{ConnectionDetail, Error, Routable, RouteStatus}; use crate::init::config::Judger; use tonic::transport::Uri; -pub struct StaticRouter { +pub struct StaticRouter { uri: Option, secret: Option, } #[tonic::async_trait] -impl Routable for StaticRouter { +impl Routable for StaticRouter { async fn route(&mut self) -> Result { Ok(match self.uri.take() { Some(x) => RouteStatus::NewConnection(ConnectionDetail { uri: x, secret: self.secret.clone(), + reuse: REUSE, }), None => RouteStatus::Never, }) diff --git a/backend/src/controller/judger/route/mod.rs b/backend/src/controller/judger/route/mod.rs index 07f3e0e5..2e94fd22 100644 --- a/backend/src/controller/judger/route/mod.rs +++ b/backend/src/controller/judger/route/mod.rs @@ -52,6 +52,7 @@ impl Interceptor for BasicAuthInterceptor { pub struct ConnectionDetail { pub uri: String, pub secret: Option, + pub reuse: bool, } impl ConnectionDetail { @@ -72,6 +73,7 @@ impl ConnectionDetail { pub struct ConnGuard { upstream: Arc, conn: Option, + reuse: bool, } impl ConnGuard { @@ -99,7 +101,9 @@ impl std::ops::Deref for ConnGuard { impl Drop for ConnGuard { fn drop(&mut self) { self.upstream.healthy.fetch_add(-2, Ordering::Acquire); - self.upstream.clients.push(self.conn.take().unwrap()); + if self.reuse{ + self.upstream.clients.push(self.conn.take().unwrap()); + } } } @@ -170,7 +174,13 @@ impl Router { )); } config::JudgerType::Static => { - tokio::spawn(discover::( + tokio::spawn(discover::>( + config, + Arc::downgrade(&self_), + )); + } + config::JudgerType::LoadBalanced => { + tokio::spawn(discover::>( config, Arc::downgrade(&self_), )); @@ -250,6 +260,7 @@ impl Upstream { }; Ok(ConnGuard { + reuse: self.connection.reuse, upstream: self, conn: Some(conn), }) diff --git a/backend/src/controller/judger/route/swarm.rs b/backend/src/controller/judger/route/swarm.rs index 3e0205cb..924873ff 100644 --- a/backend/src/controller/judger/route/swarm.rs +++ b/backend/src/controller/judger/route/swarm.rs @@ -36,6 +36,7 @@ impl Routable for DockerRouter { return Ok(RouteStatus::NewConnection(ConnectionDetail { uri, secret: self.secret.clone(), + reuse:true, })); } } diff --git a/backend/src/init/config.rs b/backend/src/init/config.rs index 532ca477..55e19bd7 100644 --- a/backend/src/init/config.rs +++ b/backend/src/init/config.rs @@ -60,6 +60,7 @@ pub struct Judger { pub enum JudgerType { Docker, Static, + LoadBalanced } impl Default for JudgerType {