转向native-image;并入反代服务器;log4j更换为slf4j;
This commit is contained in:
@@ -5,11 +5,7 @@ import lombok.Data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
@Data
|
||||
@@ -17,6 +13,8 @@ public class CustomUtil {
|
||||
|
||||
public static AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
public static ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 寻找一定数量的可用端口
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
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 static void main(String[] args) {
|
||||
|
||||
boot();
|
||||
new Thread(() -> MultiThreadedHTTPServer.main(null)).start();
|
||||
|
||||
new Thread(() -> Server.main(null)).start();
|
||||
new storageNode();
|
||||
}
|
||||
|
||||
public static void boot(){
|
||||
new Bootstrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,20 +5,21 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageCodec;
|
||||
import lion.CustomUtil;
|
||||
import lion.Message.Acclerator.FileTransferMessage;
|
||||
import lion.Message.Main.*;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@Log4j
|
||||
@Slf4j
|
||||
public class MessageCodec extends ByteToMessageCodec<AbstractMessage> {
|
||||
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
public MessageCodec(){
|
||||
objectMapper = new ObjectMapper();
|
||||
objectMapper = CustomUtil.objectMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,7 @@ import cn.hutool.core.util.ZipUtil;
|
||||
import lion.Message.AbstractMessage;
|
||||
import lion.Message.Acclerator.FileTransferMessage;
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.im4java.core.ConvertCmd;
|
||||
import org.im4java.core.IM4JavaException;
|
||||
import org.im4java.core.IMOperation;
|
||||
@@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
|
||||
@Log4j
|
||||
@Slf4j
|
||||
@Data
|
||||
public class DownloadCheckService {
|
||||
ArrayList<GalleryTask> queue;
|
||||
|
||||
@@ -15,7 +15,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Log4j
|
||||
@Slf4j
|
||||
public class storageNode {
|
||||
|
||||
ChannelFuture channelFuture;
|
||||
@@ -46,8 +46,6 @@ public class storageNode {
|
||||
|
||||
HashMap<Integer, Promise<AbstractMessage>> promises;
|
||||
|
||||
EventLoop eventLoop;
|
||||
|
||||
int counter;
|
||||
|
||||
ReentrantLock lock;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user