Skip to content

Commit

Permalink
Add toggle for host networking (#390)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes
Fixes HUB-300
<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Feb 1, 2024
1 parent a22d187 commit 2d37c3f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .github/actions/pre-init/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ runs:
EOF
cat << 'EOF' > namespaces/ci.toml
[rivet]
test = {}
[rivet.test]
# We set the public IP to localhost because we are running inside of a github action, therefore
# it is not reachable from the public.
Expand Down
9 changes: 9 additions & 0 deletions lib/bolt/config/src/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ pub struct Rivet {
pub cdn: Cdn,
#[serde(default)]
pub billing: Option<RivetBilling>,
#[serde(default)]
pub matchmaker: Option<RivetMatchmaker>,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
Expand All @@ -571,6 +573,13 @@ pub struct Telemetry {
pub disable: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(deny_unknown_fields)]
pub struct RivetMatchmaker {
#[serde(default)]
pub host_networking: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub enum RivetAccess {
Expand Down
12 changes: 12 additions & 0 deletions lib/bolt/core/src/context/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ impl ProjectContextData {
);
}
}

if self.ns().rivet.test.is_some()
&& !self.ns().pools.is_empty()
&& !self
.ns()
.rivet
.matchmaker
.as_ref()
.map_or(false, |mm| mm.host_networking)
{
panic!("must have host networking enabled if tests + pools are enabled (rivet.matchmaker.host_networking = true)");
}
}

// Traverses from FS root to CWD, returns first directory with Bolt.toml
Expand Down
6 changes: 6 additions & 0 deletions lib/bolt/core/src/context/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,12 @@ impl ServiceContextData {
env.push(("RIVET_ACCESS_TOKEN_LOGIN".into(), "1".into()));
}

if let Some(mm) = &project_ctx.ns().rivet.matchmaker {
if mm.host_networking {
env.push(("RIVET_HOST_NETWORKING".into(), "1".into()));
}
}

// Domains
if let Some(x) = project_ctx.domain_main() {
env.push(("RIVET_DOMAIN_MAIN".into(), x));
Expand Down
17 changes: 14 additions & 3 deletions svc/pkg/game/ops/version-validate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,14 +718,17 @@ async fn handle(
}
}

let network_mode = unwrap!(LobbyRuntimeNetworkMode::from_i32(
docker_config.network_mode
));
let host_networking_enabled =
std::env::var("RIVET_HOST_NETWORKING").map_or(false, |v| v == "1");
// Validate ports
if host_networking_enabled || !matches!(network_mode, LobbyRuntimeNetworkMode::Host)
{
let mut unique_port_labels = HashSet::<String>::new();
let mut unique_ports = HashSet::<(u32, i32)>::new();
let mut ranges = Vec::<PortRange>::new();
let network_mode = unwrap!(LobbyRuntimeNetworkMode::from_i32(
docker_config.network_mode
));

if docker_config.ports.len() > 16 {
errors.push(util::err_path![
Expand Down Expand Up @@ -955,6 +958,14 @@ async fn handle(
}
}
}
} else {
errors.push(util::err_path![
"config",
"matchmaker",
"game-modes",
lobby_group_label,
"host-networking-disabled",
]);
}
} else {
errors.push(util::err_path![
Expand Down

0 comments on commit 2d37c3f

Please sign in to comment.