Skip to content

Commit

Permalink
refactor: Move network servers under publish flags
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Jan 22, 2025
1 parent b346e89 commit b9601a6
Show file tree
Hide file tree
Showing 40 changed files with 1,459 additions and 1,415 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

111 changes: 111 additions & 0 deletions bacon.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# This is a configuration file for the bacon tool
#
# Complete help on configuration: https://dystroy.org/bacon/config/
#
# You may check the current default at
# https://github.com/Canop/bacon/blob/main/defaults/default-bacon.toml

default_job = "clippy-all"
env.CARGO_TERM_COLOR = "always"

[jobs.check]
command = ["cargo", "check"]
need_stdout = false

[jobs.check-all]
command = ["cargo", "check", "--all-targets"]
need_stdout = false

# Run clippy on the default target
[jobs.clippy]
command = ["cargo", "clippy"]
need_stdout = false

# Run clippy on all targets
# To disable some lints, you may change the job this way:
# [jobs.clippy-all]
# command = [
# "cargo", "clippy",
# "--all-targets",
# "--",
# "-A", "clippy::bool_to_int_with_if",
# "-A", "clippy::collapsible_if",
# "-A", "clippy::derive_partial_eq_without_eq",
# ]
# need_stdout = false
[jobs.clippy-all]
command = ["cargo", "clippy", "--all-targets", "--workspace"]
need_stdout = false

# This job lets you run
# - all tests: bacon test
# - a specific test: bacon test -- config::test_default_files
# - the tests of a package: bacon test -- -- -p config
[jobs.test]
command = ["cargo", "test"]
need_stdout = true

[jobs.nextest]
command = [
"cargo", "nextest", "run",
"--hide-progress-bar", "--failure-output", "final"
]
need_stdout = true
analyzer = "nextest"

[jobs.doc]
command = ["cargo", "doc", "--no-deps"]
need_stdout = false

# If the doc compiles, then it opens in your browser and bacon switches
# to the previous job
[jobs.doc-open]
command = ["cargo", "doc", "--no-deps", "--open"]
need_stdout = false
on_success = "back" # so that we don't open the browser at each change

# You can run your application and have the result displayed in bacon,
# if it makes sense for this crate.
[jobs.run]
command = [
"cargo", "run",
# put launch parameters for your program behind a `--` separator
]
need_stdout = true
allow_warnings = true
background = true

# Run your long-running application (eg server) and have the result displayed in bacon.
# For programs that never stop (eg a server), `background` is set to false
# to have the cargo run output immediately displayed instead of waiting for
# program's end.
# 'on_change_strategy' is set to `kill_then_restart` to have your program restart
# on every change (an alternative would be to use the 'F5' key manually in bacon).
# If you often use this job, it makes sense to override the 'r' key by adding
# a binding `r = job:run-long` at the end of this file .
[jobs.run-long]
command = [
"cargo", "run",
# put launch parameters for your program behind a `--` separator
]
need_stdout = true
allow_warnings = true
background = false
on_change_strategy = "kill_then_restart"

# This parameterized job runs the example of your choice, as soon
# as the code compiles.
# Call it as
# bacon ex -- my-example
[jobs.ex]
command = ["cargo", "run", "--example"]
need_stdout = true
allow_warnings = true

# You may define here keybindings that would be specific to
# a project, for example a shortcut to launch a specific job.
# Shortcuts to internal functions (scrolling, toggling, etc.)
# should go in your personal global prefs.toml file instead.
[keybindings]
# alt-m = "job:my-job"
c = "job:clippy-all" # comment this to have 'c' run clippy on only the default target
25 changes: 9 additions & 16 deletions benches/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,15 @@ impl QuilkinLoop {
.insert_default([quilkin::net::endpoint::Endpoint::new(endpoint.into())].into())
});

let proxy = quilkin::cli::Proxy {
port,
qcmp_port: runtime
.block_on(quilkin::test::available_addr(
quilkin::test::AddressType::Random,
))
.port(),
..<_>::default()
};

runtime.block_on(async move {
proxy
.run(config, Default::default(), None, shutdown_rx)
.await
.unwrap();
});
runtime
.block_on(
quilkin::cli::Publish::default()
.udp()
.udp_port(port)
.spawn_publishers(&config, &shutdown_rx)
.unwrap(),
)
.unwrap();
});

Self {
Expand Down
2 changes: 2 additions & 0 deletions crates/agones/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ pub async fn quilkin_proxy_deployment(
let mut container = quilkin_container(
client,
Some(vec![
"--publish.udp".into(),
"--publish.qcmp".into(),
"proxy".into(),
format!("--management-server={management_server}"),
]),
Expand Down
3 changes: 3 additions & 0 deletions crates/agones/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ mod tests {

// Setup the relay
let args = [
"--publish.mds",
"--publish.xds",
"relay",
"agones",
"--config-namespace",
Expand Down Expand Up @@ -347,6 +349,7 @@ mod tests {

// agent deployment
let args = [
"--publish.qcmp",
"agent",
"--relay",
&format!("http://{relay_name}:7900"),
Expand Down
8 changes: 6 additions & 2 deletions crates/agones/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#[cfg(test)]
mod tests {
use crate::{game_server, is_gameserver_ready, quilkin_config_map, quilkin_container, Client};
use crate::{
debug_pods, game_server, is_gameserver_ready, quilkin_config_map, quilkin_container, Client,
};
use k8s_openapi::api::core::v1::{ConfigMap, ConfigMapVolumeSource, Volume};
use kube::{api::PostParams, runtime::wait::await_condition, Api, ResourceExt};
use quilkin::{config::providers::k8s::agones::GameServer, test::TestHelper};
Expand Down Expand Up @@ -98,7 +100,7 @@ clusters:
let mount_name = "config".to_string();
template.containers.push(quilkin_container(
&client,
Some(vec!["proxy".into()]),
Some(vec!["--publish.udp".into(), "proxy".into()]),
Some(mount_name.clone()),
true,
));
Expand Down Expand Up @@ -133,6 +135,8 @@ clusters:
.await
.expect("should receive packet")
.unwrap();
debug_pods(&client, "role=proxy".into()).await;
debug_pods(&client, "{name}".into()).await;
assert_eq!("ACK: hellosidecar\n", response);
}
}
1 change: 1 addition & 0 deletions crates/nmap-service-probes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ pub enum MatchKind {
mod tests {
use super::*;

use alloc::vec;
use pretty_assertions::assert_eq;

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/nmap-service-probes/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ pub fn fallback<'i, E: ParserError<Stream<'i>> + AddContext<Stream<'i>, StrConte
#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;

#[test]
fn exclude() -> PResult<()> {
Expand Down
74 changes: 49 additions & 25 deletions crates/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use quilkin::{
Config, ShutdownTx,
};
pub use serde_json::json;
use std::{net::SocketAddr, num::NonZeroUsize, path::PathBuf, sync::Arc};
use std::{net::SocketAddr, path::PathBuf, sync::Arc};
use tokio::sync::mpsc;

pub static BUFFER_POOL: once_cell::sync::Lazy<Arc<BufferPool>> =
Expand Down Expand Up @@ -75,7 +75,9 @@ macro_rules! trace_test {

let _guard = init_logging($crate::Level::DEBUG, mname);

$body
tokio::spawn(async move {
$body
});
}
};
}
Expand Down Expand Up @@ -307,11 +309,8 @@ impl Pail {
PailConfig::Relay(rpc) => {
use components::relay;

let xds_listener = TcpListener::bind(None).unwrap();
let mds_listener = TcpListener::bind(None).unwrap();

let xds_port = xds_listener.port();
let mds_port = mds_listener.port();
let xds_port = TcpListener::bind(None).unwrap().port();
let mds_port = TcpListener::bind(None).unwrap().port();

let path = td.join(spc.name);
let mut tc = rpc.config.unwrap_or_default();
Expand All @@ -326,10 +325,17 @@ impl Pail {
let config = Arc::new(Config::default_non_agent());
config.id.store(Arc::new(spc.name.into()));

let _task = tokio::spawn(
quilkin::cli::Publish::default()
.xds()
.xds_port(xds_port)
.mds()
.mds_port(mds_port)
.spawn_publishers(&config, &shutdown_rx)
.unwrap(),
);
let task = tokio::spawn(
relay::Relay {
xds_listener,
mds_listener,
provider: Some(Providers::File { path }),
}
.run(RunArgs {
Expand Down Expand Up @@ -392,21 +398,28 @@ impl Pail {
let (shutdown, shutdown_rx) =
quilkin::make_shutdown_channel(quilkin::ShutdownKind::Testing);

let qcmp_socket =
quilkin::net::raw_socket_with_reuse(0).expect("failed to bind qcmp socket");
let qcmp_port = quilkin::net::socket_port(&qcmp_socket);
let qcmp_port = quilkin::net::socket_port(
&quilkin::net::raw_socket_with_reuse(0).expect("failed to bind qcmp socket"),
);

let config_path = path.clone();
let config = Arc::new(Config::default_agent());
config.id.store(Arc::new(spc.name.into()));
let acfg = config.clone();

let _task = tokio::spawn(
quilkin::cli::Publish::default()
.qcmp()
.qcmp_port(qcmp_port)
.spawn_publishers(&config, &shutdown_rx)
.unwrap(),
);

let task = tokio::spawn(async move {
components::agent::Agent {
locality: None,
icao_code: Some(apc.icao_code),
relay_servers,
qcmp_socket,
provider: Some(Providers::File { path }),
address_selector: None,
}
Expand All @@ -430,14 +443,18 @@ impl Pail {
})
}
PailConfig::Proxy(ppc) => {
let socket = quilkin::net::raw_socket_with_reuse(0).expect("failed to bind socket");
let qcmp =
quilkin::net::raw_socket_with_reuse(0).expect("failed to bind qcmp socket");
let qcmp_port = quilkin::net::socket_port(&qcmp);
let phoenix = TcpListener::bind(None).expect("failed to bind phoenix socket");
let phoenix_port = phoenix.port();

let port = quilkin::net::socket_port(&socket);
let port = {
let socket =
quilkin::net::raw_socket_with_reuse(0).expect("failed to bind socket");
quilkin::net::socket_port(&socket)
};

let qcmp_port = quilkin::net::socket_port(
&quilkin::net::raw_socket_with_reuse(0).expect("failed to bind qcmp socket"),
);
let phoenix_port = TcpListener::bind(None)
.expect("failed to bind phoenix socket")
.port();

let management_servers = spc
.dependencies
Expand Down Expand Up @@ -496,13 +513,20 @@ impl Pail {

let (rttx, rtrx) = tokio::sync::mpsc::unbounded_channel();

let _task = tokio::spawn(
quilkin::cli::Publish::default()
.udp()
.udp_port(port)
.qcmp()
.qcmp_port(qcmp_port)
.phoenix()
.phoenix_port(phoenix_port)
.spawn_publishers(&config, &shutdown_rx)
.unwrap(),
);
let task = tokio::spawn(async move {
components::proxy::Proxy {
num_workers: NonZeroUsize::new(1).unwrap(),
management_servers,
socket: Some(socket),
qcmp,
phoenix,
notifier: Some(rttx),
..Default::default()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/test/tests/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ trace_test!(
config,
socket,
pending_sends,
&sessions,
sessions,
BUFFER_POOL.clone(),
)
.await
Expand Down
3 changes: 1 addition & 2 deletions crates/xdp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ aya-log = "0.2.1"
libc.workspace = true
thiserror.workspace = true
tracing.workspace = true
xdp = { git = "https://github.com/Jake-Shadle/xdp", branch = "impl" }
#xdp = { path = "../../../xdp" }
xdp = "0.1"

[lints]
workspace = true
Loading

0 comments on commit b9601a6

Please sign in to comment.