Skip to content

Commit

Permalink
Rename parse method on InetAddressUtils to createCidrBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoreliovlabs committed Aug 23, 2023
1 parent 73b9118 commit e0d0f00
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions rskj-core/src/main/java/co/rsk/scoring/InetAddressUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static InetAddress getAddressForBan(@CheckForNull String hostname) throws
* @return the text converted to an InetAddressBlock
* @throws InvalidInetAddressException if the text is invalid
*/
public static InetAddressCidrBlock parse(String text) throws InvalidInetAddressException {
public static InetAddressCidrBlock createCidrBlock(String text) throws InvalidInetAddressException {
//TODO(mmarquez): should we validate address format ??
String[] parts = text.split("/");

Expand All @@ -90,11 +90,11 @@ public static InetAddressCidrBlock parse(String text) throws InvalidInetAddressE
throw new InvalidInetAddressBlockException("Invalid mask", ex);
}

return parse(address, nbits);
return createCidrBlock(address, nbits);
}


public static InetAddressCidrBlock parse(InetAddress address, int nbits) throws InvalidInetAddressException {
public static InetAddressCidrBlock createCidrBlock(InetAddress address, int nbits) throws InvalidInetAddressException {
if (nbits <= 0 || nbits > address.getAddress().length * 8) {
throw new InvalidInetAddressBlockException("Invalid mask", null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void banAddress(InetAddress address) {
public void banAddress(String address) throws InvalidInetAddressException {
boolean isAddressBlock = InetAddressUtils.hasMask(address);
if (isAddressBlock) {
this.banAddressBlock(InetAddressUtils.parse(address));
this.banAddressBlock(InetAddressUtils.createCidrBlock(address));
} else {
this.banAddress(InetAddressUtils.getAddressForBan(address));
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public void unbanAddress(InetAddress address) {
public void unbanAddress(String address) throws InvalidInetAddressException {
boolean isAddressBlock = InetAddressUtils.hasMask(address);
if (isAddressBlock) {
this.unbanAddressBlock(InetAddressUtils.parse(address));
this.unbanAddressBlock(InetAddressUtils.createCidrBlock(address));
} else {
this.unbanAddress(InetAddressUtils.getAddressForBan(address));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public boolean isAddressBlockAvailable(InetAddress inetAddress) {
return activePeers.values().stream()
.map(ch -> {
try {
return InetAddressUtils.parse(ch.getInetSocketAddress().getAddress(), networkCIDR);
return InetAddressUtils.createCidrBlock(ch.getInetSocketAddress().getAddress(), networkCIDR);
} catch (InvalidInetAddressException e) {
logger.error(e.getMessage(), e);
}
Expand Down
10 changes: 5 additions & 5 deletions rskj-core/src/test/java/co/rsk/scoring/InetAddressUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void getAnyLocalAddress() {

@Test
void parseAddressBlock() throws InvalidInetAddressException, InvalidInetAddressBlockException, UnknownHostException {
InetAddressCidrBlock result = InetAddressUtils.parse("192.162.12.0/24");
InetAddressCidrBlock result = InetAddressUtils.createCidrBlock("192.162.12.0/24");

Assertions.assertNotNull(result);
Assertions.assertArrayEquals(InetAddress.getByName("192.162.12.0").getAddress(), result.getBytes());
Expand All @@ -127,7 +127,7 @@ void parseAddressBlock() throws InvalidInetAddressException, InvalidInetAddressB
@Test
void parseAddressBlockWithNonNumericBits() throws InvalidInetAddressException {
try {
InetAddressUtils.parse("192.162.12.0/a");
InetAddressUtils.createCidrBlock("192.162.12.0/a");
Assertions.fail();
}
catch (InvalidInetAddressBlockException ex) {
Expand All @@ -138,7 +138,7 @@ void parseAddressBlockWithNonNumericBits() throws InvalidInetAddressException {
@Test
void parseAddressBlockWithNegativeNumberOfBits() throws UnknownHostException, InvalidInetAddressException {
try {
InetAddressUtils.parse("192.162.12.0/-10");
InetAddressUtils.createCidrBlock("192.162.12.0/-10");
Assertions.fail();
}
catch (InvalidInetAddressBlockException ex) {
Expand All @@ -149,7 +149,7 @@ void parseAddressBlockWithNegativeNumberOfBits() throws UnknownHostException, In
@Test
void parseAddressBlockWithZeroBits() throws InvalidInetAddressException {
try {
InetAddressUtils.parse("192.162.12.0/0");
InetAddressUtils.createCidrBlock("192.162.12.0/0");
Assertions.fail();
}
catch (InvalidInetAddressBlockException ex) {
Expand All @@ -160,7 +160,7 @@ void parseAddressBlockWithZeroBits() throws InvalidInetAddressException {
@Test
void parseAddressBlockWithTooBigNumberOfBits() throws InvalidInetAddressException {
try {
InetAddressUtils.parse("192.162.12.0/1000");
InetAddressUtils.createCidrBlock("192.162.12.0/1000");
Assertions.fail();
}
catch (InvalidInetAddressBlockException ex) {
Expand Down

0 comments on commit e0d0f00

Please sign in to comment.