转向native-image;并入反代服务器;log4j更换为slf4j;

This commit is contained in:
chuzhongzai 2023-12-06 12:56:52 +08:00
parent cd6920b05a
commit b185be1a1c
9 changed files with 275 additions and 63 deletions

91
pom.xml
View File

@ -9,8 +9,8 @@
<version>1.0</version> <version>1.0</version>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
@ -40,11 +40,19 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>log4j</artifactId> <artifactId>slf4j-api</artifactId>
<version>1.2.17</version> <version>2.0.9</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.7</version>
</dependency>
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
@ -60,56 +68,47 @@
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>lion.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- <plugin>--> <!-- <plugin>-->
<!-- <groupId>org.graalvm.buildtools</groupId>--> <!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>native-maven-plugin</artifactId>--> <!-- <artifactId>maven-assembly-plugin</artifactId>-->
<!-- <version>0.9.28</version>--> <!-- <version>3.4.2</version>-->
<!-- <executions>--> <!-- <executions>-->
<!-- <execution>--> <!-- <execution>-->
<!-- <id>native</id>-->
<!-- <goals>-->
<!-- <goal>compile-no-fork</goal>-->
<!-- </goals>-->
<!-- <phase>package</phase>--> <!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>single</goal>-->
<!-- </goals>-->
<!-- </execution>--> <!-- </execution>-->
<!-- </executions>--> <!-- </executions>-->
<!-- <configuration>--> <!-- <configuration>-->
<!-- <mainClass>lion.Main</mainClass>--> <!-- <descriptorRefs>-->
<!-- <imageName>storageNode</imageName>--> <!-- <descriptorRef>jar-with-dependencies</descriptorRef>-->
<!-- <fallback>false</fallback>--> <!-- </descriptorRefs>-->
<!-- <verbose>true</verbose>--> <!-- <archive>-->
<!-- <quickBuild>true</quickBuild>--> <!-- <manifest>-->
<!-- <buildArgs>--> <!-- <mainClass>lion.Main</mainClass>-->
<!-- <arg>-H:+ReportExceptionStackTraces</arg>--> <!-- </manifest>-->
<!-- </buildArgs>--> <!-- </archive>-->
<!-- <metadataRepository>-->
<!-- <enabled>true</enabled>-->
<!-- </metadataRepository>-->
<!-- </configuration>--> <!-- </configuration>-->
<!-- </plugin>--> <!-- </plugin>-->
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.28</version>
<configuration>
<mainClass>lion.Main</mainClass>
<imageName>storageNode</imageName>
<buildArgs>
<arg>-H:+ReportExceptionStackTraces</arg>
<arg>--gc=G1</arg>
<arg>--enable-url-protocols=https</arg>
<arg>-H:ReflectionConfigurationFiles=src/main/resources/reflect-config.json</arg>
</buildArgs>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@ -5,11 +5,7 @@ import lombok.Data;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Data @Data
@ -17,6 +13,8 @@ public class CustomUtil {
public static AtomicInteger counter = new AtomicInteger(); public static AtomicInteger counter = new AtomicInteger();
public static ObjectMapper objectMapper = new ObjectMapper();
/** /**
* 寻找一定数量的可用端口 * 寻找一定数量的可用端口
* *

View File

@ -0,0 +1,26 @@
package lion.Extranel;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
public class AESUtils {
private static final String ALGORITHM = "AES";
private static final String TRANSFORMATION = "AES/ECB/PKCS5Padding";
private static final byte[] keyBytes = "ThisIsA128BitKey".getBytes();
public static byte[] encrypt(byte[] data) throws Exception {
Key key = new SecretKeySpec(keyBytes, ALGORITHM);
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(data);
}
public static byte[] decrypt(byte[] encryptedData) throws Exception {
Key key = new SecretKeySpec(keyBytes, ALGORITHM);
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher.doFinal(encryptedData);
}
}

View File

@ -0,0 +1,65 @@
package lion.Extranel;
import com.fasterxml.jackson.databind.ObjectMapper;
import lion.CustomUtil;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Slf4j
public class Server {
ExecutorService thread_pool;
ObjectMapper objectMapper;
public static void main(String[] args) {
new Server();
}
public Server(){
log.info("开始监听:55555");
objectMapper = CustomUtil.objectMapper;
thread_pool = Executors.newFixedThreadPool(2);
thread_pool.submit(() -> {
try(ServerSocket server = new ServerSocket(55555)){
server.setSoTimeout(1000000);
while (true){
Socket socket = server.accept();
thread_pool.submit(() -> handleSocket(socket));
}
}catch (IOException e){
log.error(e.getMessage());
}
});
}
public void handleSocket(Socket socket){
try{
BufferedInputStream inputStream = new BufferedInputStream(socket.getInputStream());
Thread.sleep(500);
byte[] buf = new byte[inputStream.available()];
inputStream.read(buf);
byte[] bytes = AESUtils.decrypt(buf);
HashMap<String, String> map = (HashMap<String, String>) objectMapper.readValue(bytes, HashMap.class);
URL url = new URI(map.get("path")).toURL();
log.info("处理反代 ip: {},路径: {}", socket.getInetAddress().getHostAddress(), map.get("path"));
bytes = url.openConnection().getInputStream().readAllBytes();
socket.getOutputStream().write(AESUtils.encrypt(bytes));
socket.getOutputStream().flush();
socket.getOutputStream().close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,14 +1,20 @@
package lion; package lion;
import lombok.extern.log4j.Log4j; import io.netty.bootstrap.Bootstrap;
import lion.Extranel.Server;
import lombok.extern.slf4j.Slf4j;
@Log4j @Slf4j
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
boot();
new Thread(() -> MultiThreadedHTTPServer.main(null)).start(); new Thread(() -> MultiThreadedHTTPServer.main(null)).start();
new Thread(() -> Server.main(null)).start();
new storageNode(); new storageNode();
} }
public static void boot(){
new Bootstrap();
}
} }

View File

@ -5,20 +5,21 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageCodec; import io.netty.handler.codec.ByteToMessageCodec;
import lion.CustomUtil;
import lion.Message.Acclerator.FileTransferMessage; import lion.Message.Acclerator.FileTransferMessage;
import lion.Message.Main.*; import lion.Message.Main.*;
import lombok.extern.log4j.Log4j; import lombok.extern.slf4j.Slf4j;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
@Log4j @Slf4j
public class MessageCodec extends ByteToMessageCodec<AbstractMessage> { public class MessageCodec extends ByteToMessageCodec<AbstractMessage> {
ObjectMapper objectMapper; ObjectMapper objectMapper;
public MessageCodec(){ public MessageCodec(){
objectMapper = new ObjectMapper(); objectMapper = CustomUtil.objectMapper;
} }
@Override @Override

View File

@ -13,7 +13,7 @@ import cn.hutool.core.util.ZipUtil;
import lion.Message.AbstractMessage; import lion.Message.AbstractMessage;
import lion.Message.Acclerator.FileTransferMessage; import lion.Message.Acclerator.FileTransferMessage;
import lombok.Data; import lombok.Data;
import lombok.extern.log4j.Log4j; import lombok.extern.slf4j.Slf4j;
import org.im4java.core.ConvertCmd; import org.im4java.core.ConvertCmd;
import org.im4java.core.IM4JavaException; import org.im4java.core.IM4JavaException;
import org.im4java.core.IMOperation; import org.im4java.core.IMOperation;
@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@Log4j @Slf4j
@Data @Data
public class DownloadCheckService { public class DownloadCheckService {
ArrayList<GalleryTask> queue; ArrayList<GalleryTask> queue;

View File

@ -15,7 +15,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import lombok.extern.log4j.Log4j; import lombok.extern.slf4j.Slf4j;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -27,7 +27,7 @@ import java.util.HashMap;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@Log4j @Slf4j
public class storageNode { public class storageNode {
ChannelFuture channelFuture; ChannelFuture channelFuture;
@ -46,8 +46,6 @@ public class storageNode {
HashMap<Integer, Promise<AbstractMessage>> promises; HashMap<Integer, Promise<AbstractMessage>> promises;
EventLoop eventLoop;
int counter; int counter;
ReentrantLock lock; ReentrantLock lock;

View File

@ -0,0 +1,119 @@
[
{
"name": "lion.Message.Acclerator.FileTransferMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.DeleteGalleryMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.DownloadPostMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.DownloadStatusMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.GalleryPageQueryMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.GalleryRequestMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.IdentityMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.MaintainMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.ResponseMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.Main.UpdateGalleryMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Message.AbstractMessage",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "lion.Domain.GalleryTask",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name": "com.fasterxml.jackson.databind.ObjectMapper",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}
]