Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

fix: fix block bug of InetAddressValidator.getInstance() #64

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
public class HostNameResolver {

private static final org.slf4j.Logger logger =
org.slf4j.LoggerFactory.getLogger(HostNameResolver.class);

public rpc_address[] resolve(String hostPort) throws IllegalArgumentException {
String[] pairs = hostPort.split(":");
if (pairs.length != 2) {
Expand All @@ -26,10 +29,12 @@ public rpc_address[] resolve(String hostPort) throws IllegalArgumentException {
InetAddress[] resolvedAddresses = InetAddress.getAllByName(pairs[0]);
rpc_address[] results = new rpc_address[resolvedAddresses.length];
int size = 0;
logger.info("get all ip from the host {}", pairs[0]);
neverchanje marked this conversation as resolved.
Show resolved Hide resolved
for (InetAddress addr : resolvedAddresses) {
rpc_address rpcAddr = new rpc_address();
int ip = ByteBuffer.wrap(addr.getAddress()).order(ByteOrder.BIG_ENDIAN).getInt();
rpcAddr.address = ((long) ip << 32) + ((long) port << 16) + 1;
logger.info("ip:{}", rpcAddr);
neverchanje marked this conversation as resolved.
Show resolved Hide resolved
results[size++] = rpcAddr;
}
return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// can be found in the LICENSE file in the root directory of this source tree.
package com.xiaomi.infra.pegasus.rpc.async;

import com.google.common.net.InetAddresses;
import com.xiaomi.infra.pegasus.base.error_code.error_types;
import com.xiaomi.infra.pegasus.base.rpc_address;
import com.xiaomi.infra.pegasus.operator.client_operator;
Expand All @@ -14,7 +15,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import org.apache.commons.validator.routines.InetAddressValidator;

public class MetaSession extends HostNameResolver {
public MetaSession(
Expand All @@ -27,7 +27,7 @@ public MetaSession(
clusterManager = manager;
metaList = new ArrayList<ReplicaSession>();

if (addrList.length == 1 && !InetAddressValidator.getInstance().isValid(addrList[0])) {
if (addrList.length == 1 && !InetAddresses.isInetAddress(addrList[0])) {
// if the given string is not a valid ip address,
// then take it as a hostname for a try.
resolveHost(addrList[0]);
Expand Down Expand Up @@ -279,6 +279,7 @@ void resolveHost(String hostPort) throws IllegalArgumentException {
metaList.add(clusterManager.getReplicaSession(addr));
logger.info("add {} as meta server", addr);
}
logger.info("resolve host completed!");
neverchanje marked this conversation as resolved.
Show resolved Hide resolved
}

// Only for test.
Expand Down