From f5a5eb3f9a699093ff01cb7a6c40be60cf8ccd46 Mon Sep 17 00:00:00 2001 From: lowzj Date: Thu, 13 Jun 2019 15:42:29 +0800 Subject: [PATCH] feature: make the download port configurable supernode(java): -Dsupernode.downloadPort=xxx the default value is 8001 Signed-off-by: lowzj --- .../dragonfly/supernode/config/SupernodeProperties.java | 9 ++++++++- .../supernode/service/impl/PeerRegistryServiceImpl.java | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/supernode/src/main/java/com/dragonflyoss/dragonfly/supernode/config/SupernodeProperties.java b/src/supernode/src/main/java/com/dragonflyoss/dragonfly/supernode/config/SupernodeProperties.java index 841091af3..011329321 100644 --- a/src/supernode/src/main/java/com/dragonflyoss/dragonfly/supernode/config/SupernodeProperties.java +++ b/src/supernode/src/main/java/com/dragonflyoss/dragonfly/supernode/config/SupernodeProperties.java @@ -16,7 +16,6 @@ package com.dragonflyoss.dragonfly.supernode.config; -import javax.annotation.PostConstruct; import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; @@ -25,10 +24,12 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; +import javax.annotation.PostConstruct; import com.alibaba.fastjson.JSON; import com.dragonflyoss.dragonfly.supernode.common.Constants; + import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -79,6 +80,12 @@ public class SupernodeProperties { */ private String advertiseIp; + /** + * The downloadPort is used for clients to download file pieces from supernode. + * By default, the value is 8001. + */ + private int downloadPort = Constants.PORT; + @PostConstruct public void init() { String cdnHome = baseHome + "/repo"; diff --git a/src/supernode/src/main/java/com/dragonflyoss/dragonfly/supernode/service/impl/PeerRegistryServiceImpl.java b/src/supernode/src/main/java/com/dragonflyoss/dragonfly/supernode/service/impl/PeerRegistryServiceImpl.java index df05f4b99..8bed61267 100644 --- a/src/supernode/src/main/java/com/dragonflyoss/dragonfly/supernode/service/impl/PeerRegistryServiceImpl.java +++ b/src/supernode/src/main/java/com/dragonflyoss/dragonfly/supernode/service/impl/PeerRegistryServiceImpl.java @@ -30,6 +30,7 @@ import com.dragonflyoss.dragonfly.supernode.common.view.ResultCode; import com.dragonflyoss.dragonfly.supernode.common.view.ResultInfo; import com.dragonflyoss.dragonfly.supernode.common.view.TaskRegistryResult; +import com.dragonflyoss.dragonfly.supernode.config.SupernodeProperties; import com.dragonflyoss.dragonfly.supernode.service.PeerRegistryService; import com.dragonflyoss.dragonfly.supernode.service.PeerService; import com.dragonflyoss.dragonfly.supernode.service.PeerTaskService; @@ -60,6 +61,8 @@ public class PeerRegistryServiceImpl implements PeerRegistryService { private DataGcService dataGcService; @Autowired private LockService lockService; + @Autowired + private SupernodeProperties properties; @Override public ResultInfo registryTask(String sourceUrl, String taskUrl, String md5, String bizId, String port, @@ -153,7 +156,7 @@ public ResultInfo registryCdnNode(Task task) { String taskId = task.getTaskId(); String cid = Constants.getSuperCid(taskId); - int port = Constants.PORT; + int port = properties.getDownloadPort(); String path = PathUtil.getHttpPath(taskId); PeerInfo peerInfo = new PeerInfo(); peerInfo.setIp(Constants.localIp);