From 89c949febf28188066e40a6a75cbb2605342603a Mon Sep 17 00:00:00 2001 From: mycxu <836549522@qq.com> Date: Mon, 21 Oct 2024 21:39:34 +0800 Subject: [PATCH 1/5] fix: Obtain the correct IP address for the static worker --- .../server/component/CurrentStaticWorker.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java index 1f7e9989..c59e79c4 100644 --- a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java +++ b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java @@ -50,7 +50,7 @@ public CurrentStaticWorker(StaticWorkerRepo staticWorkerRepo, @PostConstruct private void init() throws IOException { - InetAddress localHost = InetAddress.getLocalHost(); + InetAddress localHost = getLocalHostExactAddress(); String hostAddress = localHost.getHostAddress(); current = this.staticWorkerRepo.findByHostAddress(hostAddress).orElseGet(() -> { StaticWorkerEntity worker = new StaticWorkerEntity(); @@ -78,4 +78,26 @@ private void updateStorageSpace() throws IOException { current.setTotalSpace(storageService.getTotalSpace()); current = staticWorkerRepo.save(current); } + + private InetAddress getLocalHostExactAddress() { + try { + Enumeration allNetworkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (allNetworkInterfaces.hasMoreElements()) { + NetworkInterface networkInterface = allNetworkInterfaces.nextElement(); + if (!networkInterface.isLoopback() && !networkInterface.isVirtual() && networkInterface.isUp()) { + Enumeration addresses = networkInterface.getInetAddresses(); + while (addresses.hasMoreElements()) { + InetAddress inetAddress = addresses.nextElement(); + if (inetAddress instanceof Inet4Address) { + return inetAddress; + } + } + } + } + return InetAddress.getLocalHost(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } } From f9cbd7f59c919d9ea07955694aabdc84f2e9ebd9 Mon Sep 17 00:00:00 2001 From: mycxu <836549522@qq.com> Date: Tue, 22 Oct 2024 13:17:50 +0800 Subject: [PATCH 2/5] fix: Obtain the correct IP address for the static worker --- .../server/component/CurrentStaticWorker.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java index c59e79c4..0c52eeb6 100644 --- a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java +++ b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java @@ -50,8 +50,7 @@ public CurrentStaticWorker(StaticWorkerRepo staticWorkerRepo, @PostConstruct private void init() throws IOException { - InetAddress localHost = getLocalHostExactAddress(); - String hostAddress = localHost.getHostAddress(); + String hostAddress = getLocalHostExactAddress(); current = this.staticWorkerRepo.findByHostAddress(hostAddress).orElseGet(() -> { StaticWorkerEntity worker = new StaticWorkerEntity(); worker.setHostAddress(hostAddress); @@ -79,25 +78,20 @@ private void updateStorageSpace() throws IOException { current = staticWorkerRepo.save(current); } - private InetAddress getLocalHostExactAddress() { - try { - Enumeration allNetworkInterfaces = NetworkInterface.getNetworkInterfaces(); - while (allNetworkInterfaces.hasMoreElements()) { - NetworkInterface networkInterface = allNetworkInterfaces.nextElement(); - if (!networkInterface.isLoopback() && !networkInterface.isVirtual() && networkInterface.isUp()) { - Enumeration addresses = networkInterface.getInetAddresses(); - while (addresses.hasMoreElements()) { - InetAddress inetAddress = addresses.nextElement(); - if (inetAddress instanceof Inet4Address) { - return inetAddress; - } + public String getLocalHostExactAddress() throws SocketException, UnknownHostException { + Enumeration allNetworkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (allNetworkInterfaces.hasMoreElements()) { + NetworkInterface networkInterface = allNetworkInterfaces.nextElement(); + if (!networkInterface.isLoopback() && !networkInterface.isVirtual() && networkInterface.isUp()) { + Enumeration addresses = networkInterface.getInetAddresses(); + while (addresses.hasMoreElements()) { + InetAddress inetAddress = addresses.nextElement(); + if (inetAddress instanceof Inet4Address) { + return inetAddress.getHostAddress(); } } } - return InetAddress.getLocalHost(); - } catch (Exception e) { - e.printStackTrace(); } - return null; + return InetAddress.getLocalHost().getHostAddress(); } } From 36d13ed114e3412162f3406984e20aed0d86196e Mon Sep 17 00:00:00 2001 From: mycxu <836549522@qq.com> Date: Tue, 22 Oct 2024 15:44:18 +0800 Subject: [PATCH 3/5] fix: Obtain the correct IP address for the static worker --- .../org/eclipse/jifa/server/component/CurrentStaticWorker.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java index 0c52eeb6..d13602d4 100644 --- a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java +++ b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java @@ -26,6 +26,8 @@ import java.net.InetAddress; import java.time.Duration; import java.time.Instant; +import java.net.*; +import java.util.Enumeration; @StaticWorker @Component From 322ad901a16ac01ebe06af80c373746c79d1293b Mon Sep 17 00:00:00 2001 From: mycxu <836549522@qq.com> Date: Tue, 22 Oct 2024 16:19:07 +0800 Subject: [PATCH 4/5] fix: Obtain the correct IP address for the static worker --- .../org/eclipse/jifa/server/component/CurrentStaticWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java index d13602d4..c590c2c1 100644 --- a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java +++ b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java @@ -80,7 +80,7 @@ private void updateStorageSpace() throws IOException { current = staticWorkerRepo.save(current); } - public String getLocalHostExactAddress() throws SocketException, UnknownHostException { + public String getLocalHostExactAddress() throws IOException { Enumeration allNetworkInterfaces = NetworkInterface.getNetworkInterfaces(); while (allNetworkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = allNetworkInterfaces.nextElement(); From 3897dd13cc45c60346ca0aeb48923fcd3897c9e3 Mon Sep 17 00:00:00 2001 From: mycxu <836549522@qq.com> Date: Tue, 22 Oct 2024 18:02:07 +0800 Subject: [PATCH 5/5] fix: Obtain the correct IP address for the static worker --- .../org/eclipse/jifa/server/component/CurrentStaticWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java index c590c2c1..ce2554ca 100644 --- a/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java +++ b/server/src/main/java/org/eclipse/jifa/server/component/CurrentStaticWorker.java @@ -80,7 +80,7 @@ private void updateStorageSpace() throws IOException { current = staticWorkerRepo.save(current); } - public String getLocalHostExactAddress() throws IOException { + private String getLocalHostExactAddress() throws IOException { Enumeration allNetworkInterfaces = NetworkInterface.getNetworkInterfaces(); while (allNetworkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = allNetworkInterfaces.nextElement();