config: Refactor IPCidr and use of InetAddress

Use a canonically-named utility class to tack on methods to the existing
InetAddress class. Rename IPCidr to InetNetwork so it better matches
InetAddress and is more pronouceable :) While here, simplify the
constructor and toString() functions, and properly implement hashCode().

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland
2018-06-19 21:59:44 -05:00
parent 4acee49d4b
commit b9991e4229
7 changed files with 118 additions and 90 deletions
@@ -28,7 +28,7 @@ import java.util.Locale;
*/
public class Peer {
private final List<IPCidr> allowedIPsList;
private final List<InetNetwork> allowedIPsList;
private InetSocketAddress endpoint;
private int persistentKeepalive;
private String preSharedKey;
@@ -41,13 +41,13 @@ public class Peer {
private void addAllowedIPs(final String[] allowedIPs) {
if (allowedIPs != null && allowedIPs.length > 0) {
for (final String allowedIP : allowedIPs) {
allowedIPsList.add(new IPCidr(allowedIP));
allowedIPsList.add(new InetNetwork(allowedIP));
}
}
}
public IPCidr[] getAllowedIPs() {
return allowedIPsList.toArray(new IPCidr[allowedIPsList.size()]);
public InetNetwork[] getAllowedIPs() {
return allowedIPsList.toArray(new InetNetwork[allowedIPsList.size()]);
}
private String getAllowedIPsString() {