Skip to content

Commit

Permalink
change to cli option
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jul 1, 2024
1 parent 19723b7 commit f545f93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,27 +170,27 @@ public Builder isDiscoveryEnabled(final Boolean discoveryEnabled) {
}

public Builder listenUdpPort(final int listenUdpPort) {
validatePort(listenUdpPort, "listenUdpPort");
validatePort(listenUdpPort, "--p2p-udp-port");
this.listenUdpPort = OptionalInt.of(listenUdpPort);
return this;
}

public Builder listenUdpPortDefault(final int listenUdpPort) {
validatePort(listenUdpPort, "listenUdpPortDefault");
validatePort(listenUdpPort, "--p2p-udp-port");
if (this.listenUdpPort.isEmpty()) {
this.listenUdpPort = OptionalInt.of(listenUdpPort);
}
return this;
}

public Builder listenUdpPortIpv6(final int listenUdpPortIpv6) {
validatePort(listenUdpPortIpv6, "listenUdpPortIpv6");
validatePort(listenUdpPortIpv6, "--Xp2p-udp-port-ipv6");
this.listenUdpPortIpv6 = OptionalInt.of(listenUdpPortIpv6);
return this;
}

public Builder listenUdpPortIpv6Default(final int listenUdpPortIpv6) {
validatePort(listenUdpPortIpv6, "listenUdpPortIpv6Default");
validatePort(listenUdpPortIpv6, "--Xp2p-udp-port-ipv6");
if (this.listenUdpPortIpv6.isEmpty()) {
this.listenUdpPortIpv6 = OptionalInt.of(listenUdpPortIpv6);
}
Expand All @@ -200,7 +200,7 @@ public Builder listenUdpPortIpv6Default(final int listenUdpPortIpv6) {
public Builder advertisedUdpPort(final OptionalInt advertisedUdpPort) {
checkNotNull(advertisedUdpPort);
if (advertisedUdpPort.isPresent()) {
validatePort(advertisedUdpPort.getAsInt(), "advertisedUdpPort");
validatePort(advertisedUdpPort.getAsInt(), "--p2p-advertised-udp-port");
}
this.advertisedUdpPort = advertisedUdpPort;
return this;
Expand All @@ -209,7 +209,7 @@ public Builder advertisedUdpPort(final OptionalInt advertisedUdpPort) {
public Builder advertisedUdpPortDefault(final OptionalInt advertisedUdpPort) {
checkNotNull(advertisedUdpPort);
if (advertisedUdpPort.isPresent()) {
validatePort(advertisedUdpPort.getAsInt(), "advertisedUdpPortDefault");
validatePort(advertisedUdpPort.getAsInt(), "--p2p-advertised-udp-port");
}
if (this.advertisedUdpPort.isEmpty()) {
this.advertisedUdpPort = advertisedUdpPort;
Expand All @@ -220,7 +220,7 @@ public Builder advertisedUdpPortDefault(final OptionalInt advertisedUdpPort) {
public Builder advertisedUdpPortIpv6(final OptionalInt advertisedUdpPortIpv6) {
checkNotNull(advertisedUdpPortIpv6);
if (advertisedUdpPortIpv6.isPresent()) {
validatePort(advertisedUdpPortIpv6.getAsInt(), "advertisedUdpPortIpv6");
validatePort(advertisedUdpPortIpv6.getAsInt(), "--Xp2p-advertised-udp-port-ipv6");
}
this.advertisedUdpPortIpv6 = advertisedUdpPortIpv6;
return this;
Expand All @@ -229,7 +229,7 @@ public Builder advertisedUdpPortIpv6(final OptionalInt advertisedUdpPortIpv6) {
public Builder advertisedUdpPortIpv6Default(final OptionalInt advertisedUdpPortIpv6) {
checkNotNull(advertisedUdpPortIpv6);
if (advertisedUdpPortIpv6.isPresent()) {
validatePort(advertisedUdpPortIpv6.getAsInt(), "advertisedUdpPortIpv6Default");
validatePort(advertisedUdpPortIpv6.getAsInt(), "--Xp2p-advertised-udp-port-ipv6");
}
if (this.advertisedUdpPortIpv6.isEmpty()) {
this.advertisedUdpPortIpv6 = advertisedUdpPortIpv6;
Expand Down Expand Up @@ -290,9 +290,9 @@ public Builder siteLocalAddressesEnabled(final boolean siteLocalAddressesEnabled
return this;
}

private void validatePort(final int port, final String parameter) {
private void validatePort(final int port, final String cliOption) {
if (!PortAvailability.isPortValid(port)) {
throw new InvalidConfigurationException(String.format("Invalid %s: %d", parameter, port));
throw new InvalidConfigurationException(String.format("Invalid %s: %d", cliOption, port));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,27 +307,27 @@ public Builder advertisedIps(final Optional<List<String>> advertisedIps) {
}

public Builder listenPort(final int listenPort) {
validatePort(listenPort, "listenPort");
validatePort(listenPort, "--p2p-port");
this.listenPort = listenPort;
return this;
}

public Builder listenPortIpv6(final int listenPortIpv6) {
validatePort(listenPortIpv6, "listenPortIpv6");
validatePort(listenPortIpv6, "-Xp2p-port-ipv6");
this.listenPortIpv6 = listenPortIpv6;
return this;
}

public Builder advertisedPort(final OptionalInt advertisedPort) {
checkNotNull(advertisedPort);
advertisedPort.ifPresent(port -> validatePort(port, "advertisedPort"));
advertisedPort.ifPresent(port -> validatePort(port, "--p2p-advertised-ip"));
this.advertisedPort = advertisedPort;
return this;
}

public Builder advertisedPortIpv6(final OptionalInt advertisedPortIpv6) {
checkNotNull(advertisedPortIpv6);
advertisedPortIpv6.ifPresent(port -> validatePort(port, "advertisedPortIpv6"));
advertisedPortIpv6.ifPresent(port -> validatePort(port, "--Xp2p-advertised-port-ipv6"));
this.advertisedPortIpv6 = advertisedPortIpv6;
return this;
}
Expand Down Expand Up @@ -362,9 +362,9 @@ private void validateAddresses(final List<String> addresses, final String cliOpt
}
}

private void validatePort(final int port, final String parameter) {
private void validatePort(final int port, final String cliOption) {
if (!PortAvailability.isPortValid(port)) {
throw new InvalidConfigurationException(String.format("Invalid %s: %d", parameter, port));
throw new InvalidConfigurationException(String.format("Invalid %s: %d", cliOption, port));
}
}
}
Expand Down

0 comments on commit f545f93

Please sign in to comment.