Skip to content

Commit

Permalink
feat: ✨ add ability to deploy to serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Dec 22, 2023
1 parent 4094f3a commit 1cabec5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/src/controller/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions backend/src/controller/judger/route/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const REUSE:bool> {
uri: Option<String>,
secret: Option<String>,
}

#[tonic::async_trait]
impl Routable for StaticRouter {
impl<const REUSE:bool> Routable for StaticRouter<REUSE> {
async fn route(&mut self) -> Result<RouteStatus, Error> {
Ok(match self.uri.take() {
Some(x) => RouteStatus::NewConnection(ConnectionDetail {
uri: x,
secret: self.secret.clone(),
reuse: REUSE,
}),
None => RouteStatus::Never,
})
Expand Down
15 changes: 13 additions & 2 deletions backend/src/controller/judger/route/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl Interceptor for BasicAuthInterceptor {
pub struct ConnectionDetail {
pub uri: String,
pub secret: Option<String>,
pub reuse: bool,
}

impl ConnectionDetail {
Expand All @@ -72,6 +73,7 @@ impl ConnectionDetail {
pub struct ConnGuard {
upstream: Arc<Upstream>,
conn: Option<JudgerIntercept>,
reuse: bool,
}

impl ConnGuard {
Expand Down Expand Up @@ -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());
}
}
}

Expand Down Expand Up @@ -170,7 +174,13 @@ impl Router {
));
}
config::JudgerType::Static => {
tokio::spawn(discover::<direct::StaticRouter>(
tokio::spawn(discover::<direct::StaticRouter<true>>(
config,
Arc::downgrade(&self_),
));
}
config::JudgerType::LoadBalanced => {
tokio::spawn(discover::<direct::StaticRouter<false>>(
config,
Arc::downgrade(&self_),
));
Expand Down Expand Up @@ -250,6 +260,7 @@ impl Upstream {
};

Ok(ConnGuard {
reuse: self.connection.reuse,
upstream: self,
conn: Some(conn),
})
Expand Down
1 change: 1 addition & 0 deletions backend/src/controller/judger/route/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Routable for DockerRouter {
return Ok(RouteStatus::NewConnection(ConnectionDetail {
uri,
secret: self.secret.clone(),
reuse:true,
}));
}
}
Expand Down
1 change: 1 addition & 0 deletions backend/src/init/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct Judger {
pub enum JudgerType {
Docker,
Static,
LoadBalanced
}

impl Default for JudgerType {
Expand Down

0 comments on commit 1cabec5

Please sign in to comment.