Skip to content

Commit

Permalink
update russh
Browse files Browse the repository at this point in the history
  • Loading branch information
lyang2821 committed Sep 18, 2024
1 parent 0c72237 commit 85d285d
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 129 deletions.
85 changes: 22 additions & 63 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ sqlx = { version = "0.7.3", default-features = false, features = ["sqlx-postgres
sea-orm = { version = "0.12.12", features = [ "sqlx-postgres", "sqlx-sqlite", "runtime-tokio-rustls", "macros" ] }
sea-orm-migration = { version = "0.12.6", features = [ "sqlx-postgres", "runtime-tokio-rustls" ] }
uuid = { version = "1.6.1", features = ["v4", "serde"] }
russh = {version = "0.44.1", features = ["vendored-openssl"] }
russh = {version = "0.45.0", features = ["vendored-openssl"] }
lapdev-api = { path = "./lapdev-api" }
lapdev-ws = { path = "./lapdev-ws" }
lapdev-db = { path = "./lapdev-db" }
Expand Down
19 changes: 7 additions & 12 deletions lapdev-api/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use serde::Deserialize;
use tokio::net::TcpListener;
use tokio_rustls::TlsAcceptor;
use tower::Service;
use tracing::error;
use tracing::{error, instrument::WithSubscriber};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

use crate::{cert::tls_config, router, state::CoreState};

Expand Down Expand Up @@ -96,7 +97,7 @@ async fn run(
)
.await
{
error!("ssh proxy error: {e}");
error!("ssh proxy error: {e:?}");
}
});
}
Expand Down Expand Up @@ -191,16 +192,10 @@ async fn setup_log(
.filename_prefix("lapdev.log")
.build(folder)?;
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
let filter = tracing_subscriber::EnvFilter::default()
.add_directive("lapdev=info".parse()?)
.add_directive("lapdev_api=info".parse()?)
.add_directive("lapdev_conductor=info".parse()?)
.add_directive("lapdev_rpc=info".parse()?)
.add_directive("lapdev_common=info".parse()?)
.add_directive("lapdev_db=info".parse()?)
.add_directive("lapdev_enterprise=info".parse()?)
.add_directive("lapdev_proxy_ssh=info".parse()?)
.add_directive("lapdev_proxy_http=info".parse()?);
let var = std::env::var("RUST_LOG").unwrap_or_default();
let var =
format!("error,lapdev=info,lapdev_api=info,lapdev_conductor=info,lapdev_rpc=info,lapdev_common=info,lapdev_db=info,lapdev_enterprise=info,lapdev_proxy_ssh=info,lapdev_proxy_http=info,{var}");
let filter = tracing_subscriber::EnvFilter::builder().parse_lossy(var);
tracing_subscriber::fmt()
.with_ansi(false)
.with_env_filter(filter)
Expand Down
4 changes: 4 additions & 0 deletions lapdev-conductor/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ impl Conductor {
.split('/')
.last()
.ok_or_else(|| ApiError::RepositoryInvalid("invalid repo path".to_string()))?;
let path = path
.split('?')
.next()
.ok_or_else(|| ApiError::RepositoryInvalid("invalid repo path".to_string()))?;
let repo_name = path.strip_suffix(".git").unwrap_or(path).to_string();

Ok(RepoDetails {
Expand Down
3 changes: 2 additions & 1 deletion lapdev-proxy-ssh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ impl russh::client::Handler for SshProxyClient {
impl ClientSession {
pub async fn connect(addr: &str, key: &KeyPair) -> Result<ClientSession> {
let config = russh::client::Config {
inactivity_timeout: Some(std::time::Duration::from_secs(5)),
inactivity_timeout: Some(std::time::Duration::from_secs(30)),
keepalive_interval: Some(std::time::Duration::from_secs(10)),
..<_>::default()
};
let config = Arc::new(config);
Expand Down
11 changes: 8 additions & 3 deletions lapdev-proxy-ssh/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::{borrow::Cow, sync::Arc};

use anyhow::Result;
use anyhow::{Context, Result};
use lapdev_conductor::Conductor;
use russh::{server::Server, MethodSet, Preferred};

use crate::{key::host_keys, proxy::SshProxy};

pub async fn run(conductor: Conductor, bind: &str, port: u16) -> Result<()> {
let keys = host_keys(&conductor.db).await?;
let keys = host_keys(&conductor.db)
.await
.with_context(|| "when get host keys")?;

let config = russh::server::Config {
inactivity_timeout: Some(std::time::Duration::from_secs(3600)),
Expand All @@ -32,7 +34,10 @@ pub async fn run(conductor: Conductor, bind: &str, port: u16) -> Result<()> {
db: conductor.db.clone(),
conductor: Arc::new(conductor),
};
proxy.run_on_address(config, (bind, port)).await?;
proxy
.run_on_address(config, (bind, port))
.await
.with_context(|| "when run proxy on address")?;

Ok(())
}
1 change: 1 addition & 0 deletions lapdev-ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license.workspace = true
description.workspace = true

[dependencies]
parking_lot = "0.12.3"
crossbeam-channel = "0.5.13"
notify = "6.1.1"
git2.workspace = true
Expand Down
Loading

0 comments on commit 85d285d

Please sign in to comment.