diff --git a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs index 867b9bf..533698a 100644 --- a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs +++ b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs @@ -29,20 +29,30 @@ namespace CodexPlugin var config = startupConfig.Get(); - AddExposedPortAndVar("CODEX_API_PORT", ApiPortTag); + var apiPort = CreateApiPort(config, ApiPortTag); + AddEnvVar("CODEX_API_PORT", apiPort); AddEnvVar("CODEX_API_BINDADDR", "0.0.0.0"); var dataDir = $"datadir{ContainerNumber}"; AddEnvVar("CODEX_DATA_DIR", dataDir); AddVolume($"codex/{dataDir}", GetVolumeCapacity(config)); - AddExposedPortAndVar("CODEX_DISC_PORT", DiscoveryPortTag); + var discPort = CreateP2pPort(config, DiscoveryPortTag); + AddEnvVar("CODEX_DISC_PORT", discPort); AddEnvVar("CODEX_LOG_LEVEL", config.LogLevelWithTopics()); - // This makes the node announce itself to its local (pod) IP address. - AddEnvVar("NAT_IP_AUTO", "true"); + if (config.IsPublicTestNet) + { + todo + AddEnvVar("CODEX_NAT", "required"); + } + else + { + // This makes the node announce itself to its local (pod) IP address. + AddEnvVar("NAT_IP_AUTO", "true"); + } - var listenPort = AddExposedPort(ListenPortTag); + var listenPort = CreateP2pPort(config, ListenPortTag); AddEnvVar("CODEX_LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{listenPort.Number}"); if (!string.IsNullOrEmpty(config.BootstrapSpr)) @@ -67,7 +77,7 @@ namespace CodexPlugin } if (config.MetricsEnabled) { - var metricsPort = AddInternalPort(MetricsPortTag); + var metricsPort = CreateApiPort(config, MetricsPortTag); AddEnvVar("CODEX_METRICS", "true"); AddEnvVar("CODEX_METRICS_ADDRESS", "0.0.0.0"); AddEnvVar("CODEX_METRICS_PORT", metricsPort); @@ -124,5 +134,23 @@ namespace CodexPlugin if (!string.IsNullOrEmpty(DockerImageOverride)) return DockerImageOverride; return DefaultDockerImage; } + + private Port CreateP2pPort(CodexStartupConfig config, string tag) + { + if (config.IsPublicTestNet) + { + return AddExposedPort(tag); + } + return AddInternalPort(tag); + } + + private Port CreateApiPort(CodexStartupConfig config, string tag) + { + if (config.IsPublicTestNet) + { + return AddInternalPort(tag); + } + return AddExposedPort(tag); + } } } diff --git a/ProjectPlugins/CodexPlugin/CodexSetup.cs b/ProjectPlugins/CodexPlugin/CodexSetup.cs index 0f9f37f..6240fb8 100644 --- a/ProjectPlugins/CodexPlugin/CodexSetup.cs +++ b/ProjectPlugins/CodexPlugin/CodexSetup.cs @@ -22,6 +22,7 @@ namespace CodexPlugin /// Provides an invalid proof every N proofs /// ICodexSetup WithSimulateProofFailures(uint failEveryNProofs); + ICodexSetup AsPublicTestNet(); } public class CodexLogCustomTopics @@ -118,6 +119,12 @@ namespace CodexPlugin return this; } + public ICodexSetup AsPublicTestNet() + { + IsPublicTestNet = true; + return this; + } + public string Describe() { var args = string.Join(',', DescribeArgs()); @@ -126,6 +133,7 @@ namespace CodexPlugin private IEnumerable DescribeArgs() { + if (IsPublicTestNet) yield return "Public TestNet"; yield return $"LogLevel={LogLevelWithTopics()}"; if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}"; if (StorageQuota != null) yield return $"StorageQuota={StorageQuota}"; diff --git a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs index 709fad9..3de9c4b 100644 --- a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs +++ b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs @@ -18,6 +18,7 @@ namespace CodexPlugin public bool? EnableValidator { get; set; } public TimeSpan? BlockMaintenanceInterval { get; set; } public int? BlockMaintenanceNumber { get; set; } + public bool IsPublicTestNet { get; set; } = false; public string LogLevelWithTopics() {