From 0128239c0f8829bb20edd1df257840dcbfa37c0e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 7 Sep 2021 16:43:54 -0700 Subject: handle ipv6 addresses --- .../client/src/main/java/seaweedfs/client/FilerGrpcClient.java | 2 +- .../client/src/main/java/seaweedfs/client/SeaweedUtil.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'other/java/client/src/main') diff --git a/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java b/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java index 6c57e2e0d..56aa35876 100644 --- a/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java +++ b/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java @@ -54,7 +54,7 @@ public class FilerGrpcClient { .negotiationType(NegotiationType.TLS) .sslContext(sslContext)); - filerAddress = String.format("%s:%d", host, grpcPort - 10000); + filerAddress = SeaweedUtil.joinHostPort(host, grpcPort - 10000); FilerProto.GetFilerConfigurationResponse filerConfigurationResponse = this.getBlockingStub().getFilerConfiguration( diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedUtil.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedUtil.java index 66ea9a98d..027e49b96 100644 --- a/other/java/client/src/main/java/seaweedfs/client/SeaweedUtil.java +++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedUtil.java @@ -43,4 +43,14 @@ public class SeaweedUtil { String name = fullpath.substring(sep + 1); return new String[]{parent, name}; } + + public static String joinHostPort(String host, int port) { + if (host.startsWith("[") && host.endsWith("]")) { + return host + ":" + port; + } + if (host.indexOf(':')>=0) { + return "[" + host + "]:" + port; + } + return host + ":" + port; + } } -- cgit v1.2.3