Skip to content

Commit

Permalink
sort-order and allow some extra time for spinup
Browse files Browse the repository at this point in the history
  • Loading branch information
OlofBlomqvist committed Apr 16, 2024
1 parent 862a746 commit 97bf73d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,7 +1,7 @@
[package]
name = "odd-box"
description = "dead simple reverse proxy server"
version = "0.0.12"
version = "0.0.13"
edition = "2021"
authors = ["Olof Blomqvist <olof@twnet.se>"]
repository = "https://github.com/OlofBlomqvist/odd-box"
Expand Down
2 changes: 2 additions & 0 deletions src/proc_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub (crate) async fn host(
}

const _CREATE_NO_WINDOW: u32 = 0x08000000;

#[cfg(target_os = "windows")]
const DETACHED_PROCESS: u32 = 0x00000008;

#[cfg(target_os = "windows")]
Expand Down
18 changes: 8 additions & 10 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn listen_http(
tokio::spawn( async move {
tokio::select!{
_ = handle_new_tcp_stream(None,service, tcp_stream, source_addr, targets, false,tx.clone(),state.clone()) => {
//tracing::info!("stream handled")
tracing::trace!("http tcp stream handled")
}
_ = shutdown_signal.notified() => {
eprintln!("stream aborted due to app shutdown.");
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn listen_https(
tokio::task::spawn(async move {
tokio::select!{
_ = handle_new_tcp_stream(Some(arced_tls_config),service, tcp_stream, source_addr, targets, true,tx.clone(),state.clone()) => {
tracing::info!("https tcp stream handled");
tracing::trace!("https tcp stream handled");

}
_ = shutdown_signal.notified() => {
Expand Down Expand Up @@ -289,8 +289,6 @@ async fn handle_new_tcp_stream(

let targets = targets.clone();

// OK SO IT TURNS OUT GOOGLE USES SNI ROUTING, AND SINCE WE ARRIVE WITH THE GOOGLE.LOCAL SNI, IT WONT WORK.
// THIS MEANS WE MUST ALLOW CONFIGURING TCP_MODE=ALWAYS|NEVER|ALLOW

match tcp_proxy::ReverseTcpProxy::peek_tcp_stream(&tcp_stream, source_addr).await {

Expand All @@ -307,9 +305,6 @@ async fn handle_new_tcp_stream(

if target.is_hosted {

// we rely on terminating proxy do trigger this instead of doing it here
//_ = tx.send(ProcMessage::Start(target.host_name.clone()));

let proc_state = {
let guard = state.read().await;
match guard.procs.get(&target.host_name) {
Expand All @@ -321,12 +316,15 @@ async fn handle_new_tcp_stream(
None => {
tracing::warn!("error 0001 has occurred")
},
Some(app_state::ProcState::Stopped) => {
Some(app_state::ProcState::Stopped)
| Some(app_state::ProcState::Starting) => {
_ = tx.send(ProcMessage::Start(target.host_name.clone()));
let thn = target.host_name.clone();
let mut has_started = false;
for _ in 0..5 {
tokio::time::sleep(Duration::from_secs(2)).await;
// done here to allow non-browser clients to reach the target socket without receiving unexpected loading screen html blobs
// as long as we are able to start the backing process within 10 seconds
for _ in 0..2 {
tokio::time::sleep(Duration::from_secs(5)).await;
tracing::debug!("handling an incoming request to a stopped target, waiting for up to 10 seconds for {thn} to spin up - after this we will release the request to the terminating proxy and show a 'please wait' page instaead.");
{
let guard = state.read().await;
Expand Down
5 changes: 4 additions & 1 deletion src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,10 @@ fn draw_ui<B: ratatui::backend::Backend>(f: &mut ratatui::Frame, app_state: &mut
let mut site_rects = vec![];

for (col_idx, col) in site_columns.iter().enumerate() {
let procly : Vec<(&String, &ProcState)> = app_state.procs.iter().collect();

let mut procly : Vec<(&String, &ProcState)> = app_state.procs.iter().collect();
procly.sort_by_key(|k| k.0);

let start_idx = col_idx * sites_area_height as usize;
let end_idx = ((col_idx + 1) * sites_area_height as usize).min(app_state.procs.len());
let items: Vec<ListItem> = procly[start_idx..end_idx].iter().enumerate().map(|(index,(id, state))| {
Expand Down

0 comments on commit 97bf73d

Please sign in to comment.