diff --git a/network-poc/.dockerignore b/network-poc/.dockerignore new file mode 100644 index 0000000..cf09a1b --- /dev/null +++ b/network-poc/.dockerignore @@ -0,0 +1,5 @@ +target/ +target-native/ +static/pkg/ +.git/ +*.md diff --git a/network-poc/Caddyfile.prod b/network-poc/Caddyfile.prod index 8b860c2..733aaa3 100644 --- a/network-poc/Caddyfile.prod +++ b/network-poc/Caddyfile.prod @@ -1,3 +1,5 @@ kipina.studio { - reverse_proxy hub:3000 + reverse_proxy hub:3000 { + header_up X-Forwarded-For {remote_host} + } } diff --git a/network-poc/Dockerfile.prod b/network-poc/Dockerfile.prod index 63d427f..e486f85 100644 --- a/network-poc/Dockerfile.prod +++ b/network-poc/Dockerfile.prod @@ -7,7 +7,29 @@ RUN apt-get update && apt-get install -y \ RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh WORKDIR /app -COPY . . + +# 1. Kopioi vain Cargo-tiedostot → riippuvuudet cacheen +COPY Cargo.toml Cargo.lock ./ +COPY hub/Cargo.toml hub/Cargo.toml +COPY node/Cargo.toml node/Cargo.toml +COPY native-node/Cargo.toml native-node/Cargo.toml + +# Tyhjät lähteet riippuvuuksien esikääntämistä varten +RUN mkdir -p hub/src node/src native-node/src \ + && echo "fn main(){}" > hub/src/main.rs \ + && echo "" > node/src/lib.rs \ + && mkdir -p node/src && touch node/src/storage.rs \ + && echo "fn main(){}" > native-node/src/main.rs \ + && cargo build --release -p hub 2>/dev/null || true \ + && wasm-pack build node --target web --out-dir ../static/pkg 2>/dev/null || true + +# 2. Kopioi oikea lähdekoodi → vain src käännetään uudelleen +COPY hub/src hub/src +COPY node/src node/src +COPY static static + +# Pakota uudelleenkäännös +RUN touch hub/src/main.rs node/src/lib.rs # Rakenna Wasm-paketti RUN cd node && wasm-pack build --target web --out-dir ../static/pkg diff --git a/network-poc/hub/src/main.rs b/network-poc/hub/src/main.rs index d615abc..125461d 100644 --- a/network-poc/hub/src/main.rs +++ b/network-poc/hub/src/main.rs @@ -142,11 +142,11 @@ async fn ws_handler( { let conns = state.ip_connections.lock().unwrap(); let count = conns.get(&ip).copied().unwrap_or(0); - if count >= 2 { - tracing::warn!("IP {} ylitti yhteysrajan ({}/2) — estetty", ip, count); + if count >= 4 { + tracing::warn!("IP {} ylitti yhteysrajan ({}/4) — estetty", ip, count); return ( axum::http::StatusCode::TOO_MANY_REQUESTS, - "Max 2 yhteyttä per IP", + "Max 4 yhteyttä per IP", ).into_response(); } }