Switches to automatic public IP address for codex and geth containers.

This commit is contained in:
benbierens 2023-11-15 14:53:25 +01:00
parent 485e3cf02e
commit b90c47a994
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
10 changed files with 16 additions and 26 deletions

View File

@ -5,9 +5,10 @@ namespace CodexPlugin
public class CodexDebugResponse
{
public string id { get; set; } = string.Empty;
public string[] addrs { get; set; } = new string[0];
public string[] addrs { get; set; } = Array.Empty<string>();
public string repo { get; set; } = string.Empty;
public string spr { get; set; } = string.Empty;
public string[] announceAddresses { get; set; } = Array.Empty<string>();
public EnginePeerResponse[] enginePeers { get; set; } = Array.Empty<EnginePeerResponse>();
public SwitchPeerResponse[] switchPeers { get; set; } = Array.Empty<SwitchPeerResponse>();
public CodexDebugVersionResponse codex { get; set; } = new();

View File

@ -47,13 +47,15 @@ namespace CodexPlugin
if (config.PublicTestNet != null)
{
AddEnvVar("CODEX_NAT", config.PublicTestNet.PublicNatIP);
// This makes the node announce itself to its public IP address.
AddEnvVar("NAT_IP_AUTO", "false");
AddEnvVar("NAT_PUBLIC_IP_AUTO", "true");
}
else
{
// This makes the node announce itself to its local (pod) IP address.
AddEnvVar("NAT_IP_AUTO", "true");
AddEnvVar("NAT_PUBLIC_IP_AUTO", "false");
}
var listenPort = CreateListenPort(config);

View File

@ -133,7 +133,7 @@ namespace CodexPlugin
private IEnumerable<string> DescribeArgs()
{
if (PublicTestNet != null) yield return $"<!>Public TestNet at {PublicTestNet.PublicNatIP}:{PublicTestNet.PublicListenPort}<!>";
if (PublicTestNet != null) yield return $"<!>Public TestNet with listenPort: {PublicTestNet.PublicListenPort}<!>";
yield return $"LogLevel={LogLevelWithTopics()}";
if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}";
if (StorageQuota != null) yield return $"StorageQuota={StorageQuota}";

View File

@ -65,7 +65,6 @@ namespace CodexPlugin
public class CodexTestNetConfig
{
public string PublicNatIP { get; set; } = string.Empty;
public int PublicDiscoveryPort { get; set; }
public int PublicListenPort { get; set; }
}

View File

@ -40,7 +40,7 @@ namespace GethPlugin
var authRpc = CreateP2pPort(config, tag: AuthRpcPortTag);
var wsPort = CreateP2pPort(config, tag: WsPortTag);
var args = $"--http.addr 0.0.0.0 --http.port {httpPort.Number} --port {listen.Number} --discovery.port {discovery.Number} {GetTestNetArgs(config)} {defaultArgs}";
var args = $"--http.addr 0.0.0.0 --http.port {httpPort.Number} --port {listen.Number} --discovery.port {discovery.Number} {defaultArgs}";
if (config.BootstrapNode != null)
{
@ -50,6 +50,14 @@ namespace GethPlugin
var bootstrapArg = $" --bootnodes enode://{bootPubKey}@{bootIp}:{bootPort} --nat=extip:{bootIp}";
args += bootstrapArg;
}
if (config.IsPublicTestNet != null)
{
AddEnvVar("NAT_PUBLIC_IP_AUTO", "true");
}
else
{
AddEnvVar("NAT_PUBLIC_IP_AUTO", "false");
}
return args + $" --authrpc.port {authRpc.Number} --ws --ws.addr 0.0.0.0 --ws.port {wsPort.Number}";
}
@ -64,13 +72,6 @@ namespace GethPlugin
AddEnvVar("UNLOCK_NUMBER", numberOfAccounts.ToString());
}
private string GetTestNetArgs(GethStartupConfig config)
{
if (config.IsPublicTestNet == null) return string.Empty;
return $"--nat=extip:{config.IsPublicTestNet.PublicIp}";
}
private Port CreateDiscoveryPort(GethStartupConfig config)
{
if (config.IsPublicTestNet == null) return AddInternalPort(DiscoveryPortTag);

View File

@ -42,14 +42,12 @@
public class GethTestNetConfig
{
public GethTestNetConfig(string publicIp, int discoveryPort, int listenPort)
public GethTestNetConfig(int discoveryPort, int listenPort)
{
PublicIp = publicIp;
DiscoveryPort = discoveryPort;
ListenPort = listenPort;
}
public string PublicIp { get; }
public int DiscoveryPort { get; }
public int ListenPort { get; }
}

View File

@ -105,7 +105,6 @@ namespace CodexNetDeployer
return new CodexTestNetConfig
{
PublicNatIP = config.PublicIP,
PublicDiscoveryPort = Convert.ToInt32(discPort),
PublicListenPort = Convert.ToInt32(listenPort)
};

View File

@ -86,18 +86,12 @@ namespace CodexNetDeployer
[Uniform("public-testnet", "ptn", "PUBLICTESTNET", false, "If true, deployment is created for public exposure. Default is false.")]
public bool IsPublicTestNet { get; set; } = false;
[Uniform("public-ip", "pip", "PUBLICIP", false, "Required if public-testnet is true. Public IP address used by nodes for network annoucements.")]
public string PublicIP { get; set; } = string.Empty;
[Uniform("public-discports", "pdps", "PUBLICDISCPORTS", false, "Required if public-testnet is true. Comma-separated port numbers used for discovery. Number must match number of nodes.")]
public string PublicDiscPorts { get; set; } = string.Empty;
[Uniform("public-listenports", "plps", "PUBLICLISTENPORTS", false, "Required if public-testnet is true. Comma-separated port numbers used for listening. Number must match number of nodes.")]
public string PublicListenPorts { get; set; } = string.Empty;
[Uniform("public-gethip", "pgdp", "PUBLICGETHIP", false, "Required if public-testnet is true. Geth's public IP address.")]
public string PublicGethIP { get; set; } = string.Empty;
[Uniform("public-gethdiscport", "pgdp", "PUBLICGETHDISCPORT", false, "Required if public-testnet is true. Single port number used for Geth's public discovery port.")]
public int PublicGethDiscPort { get; set; }
@ -150,7 +144,6 @@ namespace CodexNetDeployer
if (IsPublicTestNet)
{
if (string.IsNullOrEmpty(PublicIP)) errors.Add("Public IP required when deploying public testnet.");
if (PublicDiscPorts.Split(",").Length != NumberOfCodexNodes) errors.Add("Number of public discovery-ports provided does not match number of codex nodes.");
if (PublicListenPorts.Split(",").Length != NumberOfCodexNodes) errors.Add("Number of public listen-ports provided does not match number of codex nodes.");
if (PublicGethDiscPort == 0) errors.Add("Geth public discovery port is not set.");

View File

@ -113,7 +113,6 @@ namespace CodexNetDeployer
if (config.IsPublicTestNet)
{
s.AsPublicTestNet(new GethTestNetConfig(
publicIp: config.PublicGethIP,
discoveryPort: config.PublicGethDiscPort,
listenPort: config.PublicGethListenPort
));

View File

@ -16,10 +16,8 @@ dotnet run \
--check-connect=0 \
\
--public-testnet=1 \
--public-ip=1.2.3.4 \
--public-discports=30010,30020,30030 \
--public-listenports=30011,30021,30031 \
--public-gethip=1.2.3.5 \
--public-gethdiscport=30040 \
--public-gethlistenport=30041 \
\