generated from PlexSheep/rs-base
feat: host challenges on different ports #8
cargo devel CI / cargo CI (push) Has been cancelled
Details
cargo devel CI / cargo CI (push) Has been cancelled
Details
This commit is contained in:
parent
fb10ca1464
commit
5f29c42aeb
|
@ -3,6 +3,8 @@
|
||||||
//! This challenge is designed to be simple and straightforward, requiring the contestant to only
|
//! This challenge is designed to be simple and straightforward, requiring the contestant to only
|
||||||
//! establish a TCP connection to the server to receive the secret.
|
//! establish a TCP connection to the server to receive the secret.
|
||||||
|
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use libpt::log::warn;
|
use libpt::log::warn;
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
|
@ -42,8 +44,8 @@ impl ChallengeLike for C1 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn serve(&self) -> anyhow::Result<()> {
|
async fn serve(&self, addr: SocketAddr) -> anyhow::Result<()> {
|
||||||
let listener = TcpListener::bind(self.config.addr).await?;
|
let listener = TcpListener::bind(addr).await?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let vault = self.vault.clone();
|
let vault = self.vault.clone();
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
//! This challenge is designed to be simple and straightforward, but still requires some thinkering
|
//! This challenge is designed to be simple and straightforward, but still requires some thinkering
|
||||||
//! for newbies, especially those that sill only think in text.
|
//! for newbies, especially those that sill only think in text.
|
||||||
|
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use libpt::log::{info, warn};
|
use libpt::log::{info, warn};
|
||||||
|
@ -69,8 +71,8 @@ impl ChallengeLike for C2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn serve(&self) -> anyhow::Result<()> {
|
async fn serve(&self, addr: SocketAddr) -> anyhow::Result<()> {
|
||||||
let listener = TcpListener::bind(self.config.addr).await?;
|
let listener = TcpListener::bind(addr).await?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let vault = self.vault.clone();
|
let vault = self.vault.clone();
|
||||||
|
|
|
@ -231,9 +231,9 @@ impl ChallengeLike for C3 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn serve(&self) -> anyhow::Result<()> {
|
async fn serve(&self, addr: SocketAddr) -> anyhow::Result<()> {
|
||||||
info!("serving challenge 3");
|
info!("serving challenge 3");
|
||||||
let listener = TcpListener::bind(self.config.addr).await?;
|
let listener = TcpListener::bind(addr).await?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let vault = self.vault.clone();
|
let vault = self.vault.clone();
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
//! This module is the core of the Wooly Vault application, as it defines the interface that all
|
//! This module is the core of the Wooly Vault application, as it defines the interface that all
|
||||||
//! challenges must implement, and contains the challenge modules themselves.
|
//! challenges must implement, and contains the challenge modules themselves.
|
||||||
|
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use libpt::log::{error, info};
|
use libpt::log::{error, info};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -120,7 +122,7 @@ where
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Will error when the challenge errors, for example when the network adress cannot be bound.
|
/// Will error when the challenge errors, for example when the network adress cannot be bound.
|
||||||
async fn serve(&self) -> anyhow::Result<()>;
|
async fn serve(&self, addr: SocketAddr) -> anyhow::Result<()>;
|
||||||
/// Serves a challenge and sets up the hint and monitoring service for the admin.
|
/// Serves a challenge and sets up the hint and monitoring service for the admin.
|
||||||
///
|
///
|
||||||
/// This method not only serves the challenge, but it also sets up a small webservice for the
|
/// This method not only serves the challenge, but it also sets up a small webservice for the
|
||||||
|
@ -135,11 +137,11 @@ where
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// A result indicating whether the challenge and the admin interface were successfully served.
|
/// A result indicating whether the challenge and the admin interface were successfully served.
|
||||||
async fn start(&self) -> anyhow::Result<()> {
|
async fn start(&self, addr: SocketAddr) -> anyhow::Result<()> {
|
||||||
let c = self.clone();
|
let c = self.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
info!("starting C{}", Self::text().id());
|
info!("starting C{}", Self::text().id());
|
||||||
if let Err(e) = c.serve().await {
|
if let Err(e) = c.serve(addr).await {
|
||||||
error!("challenge {} has crashed! {e:#?}", Self::text().title());
|
error!("challenge {} has crashed! {e:#?}", Self::text().title());
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
29
src/lib.rs
29
src/lib.rs
|
@ -14,6 +14,8 @@
|
||||||
//! Wooly Vault is programmed asynchronously with [tokio] to be able to handle many contestants at
|
//! Wooly Vault is programmed asynchronously with [tokio] to be able to handle many contestants at
|
||||||
//! once if needed.
|
//! once if needed.
|
||||||
|
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use libpt::log::info;
|
use libpt::log::info;
|
||||||
|
|
||||||
|
@ -60,9 +62,21 @@ pub async fn select_and_start_single(
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
info!("select+start");
|
info!("select+start");
|
||||||
match index {
|
match index {
|
||||||
1 => challenge::c1::C1::new(config, vault).start().await?,
|
1 => {
|
||||||
2 => challenge::c2::C2::new(config, vault).start().await?,
|
challenge::c1::C1::new(config.clone(), vault)
|
||||||
3 => challenge::c3::C3::new(config, vault).start().await?,
|
.start(config.addr)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
challenge::c2::C2::new(config.clone(), vault)
|
||||||
|
.start(config.addr)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
challenge::c3::C3::new(config.clone(), vault)
|
||||||
|
.start(config.addr)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"no challenge with index {index} does currently exist"
|
"no challenge with index {index} does currently exist"
|
||||||
|
@ -74,13 +88,16 @@ pub async fn select_and_start_single(
|
||||||
|
|
||||||
// TODO: actually use different vaults for the challenges #7
|
// TODO: actually use different vaults for the challenges #7
|
||||||
pub async fn start_all(config: Config, vault: VaultRef) -> anyhow::Result<()> {
|
pub async fn start_all(config: Config, vault: VaultRef) -> anyhow::Result<()> {
|
||||||
|
let ip = config.addr.ip();
|
||||||
|
let start_port = config.addr.port();
|
||||||
|
|
||||||
let c1 = challenge::c1::C1::new(config.clone(), vault.clone());
|
let c1 = challenge::c1::C1::new(config.clone(), vault.clone());
|
||||||
let c2 = challenge::c2::C2::new(config.clone(), vault.clone());
|
let c2 = challenge::c2::C2::new(config.clone(), vault.clone());
|
||||||
let c3 = challenge::c3::C3::new(config.clone(), vault.clone());
|
let c3 = challenge::c3::C3::new(config.clone(), vault.clone());
|
||||||
|
|
||||||
c1.start().await?;
|
c1.start(SocketAddr::new(ip, start_port)).await?;
|
||||||
c2.start().await?;
|
c2.start(SocketAddr::new(ip, start_port + 1)).await?;
|
||||||
c3.start().await?;
|
c3.start(SocketAddr::new(ip, start_port + 2)).await?;
|
||||||
|
|
||||||
meta::serve(
|
meta::serve(
|
||||||
vec![
|
vec![
|
||||||
|
|
Loading…
Reference in New Issue