Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
60 changes: 60 additions & 0 deletions src/main/java/org/csource/common/ConfigureMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.csource.common;

import java.util.Properties;

/**
* Description: 在特殊的内外网环境下,如果fdfs配置在内网,但是想通过外网操作fdfs上传文件,可以使用本配置方法来做IP映射。
* 前提:外网映射的IP端口可达。
* 配置格式:内网ip=外网IP:外网端口
*
* @author kyq
* @version 1.0
* @Date 2020/9/4 9:41
*/
public class ConfigureMapper {
private static final String SYS_CONFIG_FILE = "fdfs_ip_mapper.properties";
private static Properties sysProperties = new Properties();

static {
try {
sysProperties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("fdfs_ip_mapper.properties"));
} catch (Exception var1) {
System.out.println("fdfs_ip_mapper.properties not found!");
}

}

public static String getProperty(String strKey) {
String strValue = "";

try {
strValue = sysProperties.getProperty(strKey);
} catch (Exception var3) {
System.out.println("Property <" + strKey + "> not found!");
}

return replaceNull(strValue);
}

public static String replaceNull(Object obj) {
return isEmpty(obj) ? "" : obj.toString();
}

public static boolean isEmpty(Object... objs) {
if (objs == null) {
return true;
} else {
Object[] var4 = objs;
int var3 = objs.length;

for(int var2 = 0; var2 < var3; ++var2) {
Object obj = var4[var2];
if (obj != null && !"".equals(obj)) {
return false;
}
}

return true;
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/csource/fastdfs/TrackerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.csource.fastdfs;

import org.csource.common.ConfigureMapper;
import org.csource.common.MyException;
import org.csource.fastdfs.pool.Connection;

Expand Down Expand Up @@ -248,6 +249,13 @@ public StorageServer[] getStoreStorages(TrackerServer trackerServer, String grou
port = (int) ProtoCommon.buff2long(pkgInfo.body, offset);
offset += ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE;

String mapper = ConfigureMapper.getProperty(ip_addr);
if (!ConfigureMapper.isEmpty(new Object[]{mapper})) {
String[] mappingIp = mapper.split(":");
ip_addr = mappingIp[0];
port = Integer.parseInt(mappingIp[1]);
}

results[i] = new StorageServer(ip_addr, port, store_path);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/fdfs_ip_mapper.properties.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Config intranet storage ip to the mapped internet ip and port
#10.0.11.244=113.204.217.100:22124