From c2c5c50a48730f7d74104460631778d89ccf9921 Mon Sep 17 00:00:00 2001 From: chuzhongzai Date: Mon, 14 Aug 2023 22:23:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E9=A2=84=E8=A7=88=E5=8A=A0?= =?UTF-8?q?=E5=85=A5gif;=E7=A6=81=E6=AD=A2=E9=9D=9E=E5=8F=8D=E4=BB=A3ip?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6;=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=BF=9B=E5=BA=A6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/lion/MultiThreadedHTTPServer.java | 16 +++++++++++++--- src/main/java/lion/Service/DeliveryService.java | 4 ++-- .../java/lion/Service/DownloadCheckService.java | 5 +++-- src/main/java/lion/storageNode.java | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index ed567a5..7e1cf4c 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ cn.hutool hutool-all - 5.8.16 + 5.8.18 diff --git a/src/main/java/lion/MultiThreadedHTTPServer.java b/src/main/java/lion/MultiThreadedHTTPServer.java index 59fec3e..274d1a3 100644 --- a/src/main/java/lion/MultiThreadedHTTPServer.java +++ b/src/main/java/lion/MultiThreadedHTTPServer.java @@ -3,6 +3,7 @@ package lion; import java.io.*; import java.net.ServerSocket; import java.net.Socket; +import java.net.SocketException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -21,9 +22,16 @@ public class MultiThreadedHTTPServer { System.out.println("Server listening on port " + PORT); while (true) { Socket clientSocket = serverSocket.accept(); - System.out.println("Client connected: " + clientSocket.getInetAddress().getHostAddress()); - // 线程池处理下载请求 - threadPool.submit(() -> handleClientRequest(clientSocket)); + String ip = clientSocket.getInetAddress().getHostAddress(); + if(ip.equals("100.42.234.138")){ + System.out.println("Client connected: " + ip); + // 线程池处理下载请求 + threadPool.submit(() -> handleClientRequest(clientSocket)); + }else{ + System.out.println("unknown ip: " + ip); + clientSocket.close(); + } + } } catch (IOException e) { e.printStackTrace(); @@ -104,6 +112,8 @@ public class MultiThreadedHTTPServer { responseStream.write(buffer, 0, bytesRead); bytesRemaining -= bytesRead; } + }catch (SocketException ignore){ + } // Close the response output stream diff --git a/src/main/java/lion/Service/DeliveryService.java b/src/main/java/lion/Service/DeliveryService.java index 1344e4b..25827d4 100644 --- a/src/main/java/lion/Service/DeliveryService.java +++ b/src/main/java/lion/Service/DeliveryService.java @@ -50,7 +50,7 @@ public class DeliveryService { return ErrorCode.FILE_NOT_FOUND; singleThreadPool.submit(() -> { - try(SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("194.36.27.28", port)); + try(SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("100.42.234.138", port)); FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.READ)) { ByteBuffer buffer = ByteBuffer.allocate(1024); while (fileChannel.read(buffer)!=-1){ @@ -86,7 +86,7 @@ public class DeliveryService { if(!directory.isDirectory()) return ErrorCode.FILE_NOT_FOUND; ArrayList pageList = new ArrayList<>(); - File[] files = directory.listFiles(((dir, name1) -> name1.contains(".webp") && !name1.equals("thumbnail.webp"))); + File[] files = directory.listFiles(((dir, name1) -> !name1.equals("galleryinfo.txt") && !name1.equals("thumbnail.webp"))); if(files == null) return ErrorCode.FILE_NOT_FOUND; diff --git a/src/main/java/lion/Service/DownloadCheckService.java b/src/main/java/lion/Service/DownloadCheckService.java index 9d2b3fa..5e3d62b 100644 --- a/src/main/java/lion/Service/DownloadCheckService.java +++ b/src/main/java/lion/Service/DownloadCheckService.java @@ -104,7 +104,7 @@ public class DownloadCheckService { continue; } - if(galleryTask.getType() == GalleryTask.DOWNLOAD_ALL || galleryTask.getType() == GalleryTask.DOWNLOAD_PREVIEW) + if((galleryTask.getType() & GalleryTask.DOWNLOAD_PREVIEW) != 0) for (File image : images) { log.info("文件" + image.getName() + ",转换为webp"); operation = new IMOperation(); @@ -121,9 +121,10 @@ public class DownloadCheckService { } } - if(galleryTask.getType() == GalleryTask.DOWNLOAD_ALL || galleryTask.getType() == GalleryTask.DOWNLOAD_SOURCE) + if((galleryTask.getType() & GalleryTask.DOWNLOAD_SOURCE) != 0) ZipUtil.zip(galleryTask.getPath(), storagePath + galleryTask.getName() + "/" + galleryTask.getName() + ".zip"); FileUtil.del(galleryTask.getPath()); + galleryTask.setStatus(GalleryTask.DOWNLOAD_COMPLETE); } return true; diff --git a/src/main/java/lion/storageNode.java b/src/main/java/lion/storageNode.java index 661c11d..93b29cb 100644 --- a/src/main/java/lion/storageNode.java +++ b/src/main/java/lion/storageNode.java @@ -64,7 +64,7 @@ public class storageNode { log.info("listen port:8080"); try(Socket socket = new Socket()) { - socket.connect(new InetSocketAddress("194.36.27.28", 26322));; + socket.connect(new InetSocketAddress("100.42.234.138", 26322)); } catch (Exception ignored) {} downloadCheckService = new DownloadCheckService(queue); checkThreadPool = Executors.newScheduledThreadPool(1);