├── doc.png ├── test.png ├── proxy ├── src │ └── main │ │ ├── resources │ │ ├── META-INF │ │ │ └── native-image │ │ │ │ ├── proxy-config.json │ │ │ │ ├── predefined-classes-config.json │ │ │ │ ├── serialization-config.json │ │ │ │ ├── resource-config.json │ │ │ │ ├── jni-config.json │ │ │ │ └── reflect-config.json │ │ └── config.json │ │ └── java │ │ └── com │ │ └── github │ │ └── wormhole │ │ └── proxy │ │ ├── processor │ │ ├── ProxyRegisterAckProcessor.java │ │ ├── DisconnectClientProcessor.java │ │ ├── DataTransAckProcessor.java │ │ └── DataChannelProcessor.java │ │ └── Proxy.java └── pom.xml ├── server ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── native-image │ │ │ ├── proxy-config.json │ │ │ ├── predefined-classes-config.json │ │ │ ├── serialization-config.json │ │ │ ├── resource-config.json │ │ │ ├── jni-config.json │ │ │ └── reflect-config.json │ │ └── java │ │ └── com │ │ └── github │ │ └── wormhole │ │ └── server │ │ ├── processor │ │ ├── SignalChannelContext.java │ │ ├── DisconnectClientPocessor.java │ │ ├── ProxyRegisterProcessor.java │ │ ├── DataTransAckProcessor.java │ │ └── BuildDataChannelProcessor.java │ │ ├── DataTransHandler.java │ │ ├── DataTransServer.java │ │ ├── ProxyServer.java │ │ ├── ClientHandler.java │ │ └── Server.java └── pom.xml ├── common ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── wormhole │ │ │ └── common │ │ │ ├── utils │ │ │ ├── Holder.java │ │ │ ├── Connection.java │ │ │ ├── IDUtil.java │ │ │ ├── Task.java │ │ │ ├── TaskExecutor.java │ │ │ ├── ConfigLoader.java │ │ │ ├── RetryUtil.java │ │ │ └── NetworkUtil.java │ │ │ ├── App.java │ │ │ └── config │ │ │ └── ProxyServiceConfig.java │ └── test │ │ └── java │ │ └── com │ │ └── github │ │ └── AppTest.java ├── .editorconfig └── pom.xml ├── client ├── src │ └── main │ │ └── java │ │ └── com │ │ └── github │ │ └── wormhole │ │ └── client │ │ ├── Context.java │ │ ├── Processor.java │ │ ├── SignalHandler.java │ │ ├── DataTransHandler.java │ │ ├── SignalClient.java │ │ ├── ack │ │ └── AckHandler.java │ │ ├── DataClient.java │ │ ├── DataClientPool.java │ │ └── Client.java └── pom.xml ├── config.json ├── serialize ├── src │ └── main │ │ └── java │ │ └── com │ │ └── github │ │ └── wormhole │ │ └── serialize │ │ ├── Serialization.java │ │ ├── FrameEncoder.java │ │ ├── FrameDecoder.java │ │ ├── Constant.java │ │ ├── Frame.java │ │ ├── PackageDecoder.java │ │ ├── PackageEncoder.java │ │ └── FrameSerialization.java └── pom.xml ├── .vscode └── settings.json ├── README.md ├── .github └── workflows │ └── release.yml ├── .gitignore ├── pom.xml └── LICENSE /doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevenkin/wormhole/HEAD/doc.png -------------------------------------------------------------------------------- /test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevenkin/wormhole/HEAD/test.png -------------------------------------------------------------------------------- /proxy/src/main/resources/META-INF/native-image/proxy-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | ] 3 | -------------------------------------------------------------------------------- /server/src/main/resources/META-INF/native-image/proxy-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | ] 3 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/utils/Holder.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.utils; 2 | 3 | public class Holder { 4 | public T t; 5 | } 6 | -------------------------------------------------------------------------------- /proxy/src/main/resources/META-INF/native-image/predefined-classes-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type":"agent-extracted", 4 | "classes":[ 5 | ] 6 | } 7 | ] 8 | 9 | -------------------------------------------------------------------------------- /proxy/src/main/resources/META-INF/native-image/serialization-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "types":[ 3 | ], 4 | "lambdaCapturingTypes":[ 5 | ], 6 | "proxies":[ 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /server/src/main/resources/META-INF/native-image/predefined-classes-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type":"agent-extracted", 4 | "classes":[ 5 | ] 6 | } 7 | ] 8 | 9 | -------------------------------------------------------------------------------- /server/src/main/resources/META-INF/native-image/serialization-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "types":[ 3 | ], 4 | "lambdaCapturingTypes":[ 5 | ], 6 | "proxies":[ 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /proxy/src/main/resources/META-INF/native-image/resource-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources":{ 3 | "includes":[{ 4 | "pattern":"\\Qorg/slf4j/impl/StaticLoggerBinder.class\\E" 5 | }]}, 6 | "bundles":[] 7 | } 8 | -------------------------------------------------------------------------------- /server/src/main/resources/META-INF/native-image/resource-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources":{ 3 | "includes":[{ 4 | "pattern":"\\Qorg/slf4j/impl/StaticLoggerBinder.class\\E" 5 | }]}, 6 | "bundles":[] 7 | } 8 | -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/Context.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client; 2 | 3 | public interface Context { 4 | void write(Object msg); 5 | 6 | Object read(); 7 | 8 | String id(); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/utils/Connection.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.utils; 2 | 3 | import io.netty.channel.ChannelFuture; 4 | 5 | public interface Connection { 6 | ChannelFuture write(Object msg); 7 | } 8 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "http": { 3 | "ip": "127.0.0.1", 4 | "port": "8080", 5 | "mappingPort": "8090" 6 | }, 7 | "serverHost": "127.0.0.1", 8 | "serverPort": 9000, 9 | "dataTransPort": 9100, 10 | "username":"wjg", 11 | "password": "123456" 12 | } -------------------------------------------------------------------------------- /proxy/src/main/resources/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "http": { 3 | "ip": "127.0.0.1", 4 | "port": "8080", 5 | "mappingPort": "8090" 6 | }, 7 | "serverHost": "127.0.0.1", 8 | "serverPort": 9000, 9 | "dataTransPort": 9100, 10 | "username":"wjg", 11 | "password": "123456" 12 | } -------------------------------------------------------------------------------- /serialize/src/main/java/com/github/wormhole/serialize/Serialization.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.serialize; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | 5 | public interface Serialization { 6 | ByteBuf serialize(T msg, ByteBuf byteBuf); 7 | 8 | T deserialize(ByteBuf byteBuf); 9 | } 10 | -------------------------------------------------------------------------------- /serialize/src/main/java/com/github/wormhole/serialize/FrameEncoder.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.serialize; 2 | 3 | import io.netty.handler.codec.LengthFieldPrepender; 4 | 5 | public class FrameEncoder extends LengthFieldPrepender { 6 | public FrameEncoder() { 7 | super(2); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /serialize/src/main/java/com/github/wormhole/serialize/FrameDecoder.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.serialize; 2 | 3 | import io.netty.handler.codec.LengthFieldBasedFrameDecoder; 4 | 5 | public class FrameDecoder extends LengthFieldBasedFrameDecoder { 6 | public FrameDecoder() { 7 | super(10240, 0, 2, 0, 2); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/utils/IDUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.utils; 2 | 3 | import org.apache.commons.lang3.RandomStringUtils; 4 | 5 | public class IDUtil { 6 | public static String genRequestId() { 7 | return System.currentTimeMillis() + RandomStringUtils.randomAlphabetic(8); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /common/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | max_line_length = 80 11 | 12 | [*.sh] 13 | end_of_line = lf 14 | 15 | [*.java] 16 | indent_size = 4 17 | max_line_length = 120 18 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.configuration.updateBuildConfiguration": "automatic", 3 | "java.debug.settings.onBuildFailureProceed": true, 4 | "java.dependency.packagePresentation": "hierarchical", 5 | "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable" 6 | } -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/Processor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client; 2 | 3 | import com.github.wormhole.serialize.Frame; 4 | 5 | import io.netty.channel.ChannelHandlerContext; 6 | 7 | public interface Processor { 8 | boolean isSupport(Frame frame); 9 | 10 | void process(ChannelHandlerContext ctx, Frame msg) throws Exception; 11 | } 12 | -------------------------------------------------------------------------------- /common/src/test/java/com/github/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.github; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | class AppTest { 11 | /** 12 | * Rigorous Test. 13 | */ 14 | @Test 15 | void testApp() { 16 | assertEquals(1, 1); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/App.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common; 2 | 3 | /** 4 | * Hello world! 5 | */ 6 | public final class App { 7 | private App() { 8 | } 9 | 10 | /** 11 | * Says hello to the world. 12 | * @param args The arguments of the program. 13 | */ 14 | public static void main(String[] args) { 15 | System.out.println("Hello World!"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/utils/Task.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.utils; 2 | 3 | import io.netty.channel.Channel; 4 | 5 | public class Task implements Runnable{ 6 | private Channel channel; 7 | 8 | private Object msg; 9 | 10 | public Task(Channel channel, Object msg) { 11 | this.channel = channel; 12 | this.msg = msg; 13 | } 14 | 15 | @Override 16 | public void run() { 17 | channel.writeAndFlush(msg); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /serialize/src/main/java/com/github/wormhole/serialize/Constant.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.serialize; 2 | 3 | public interface Constant { 4 | String CLIENT_PUBLIC_KEY = "client_public_key"; 5 | 6 | byte[] BUSINESS_MAGIC = {(byte) 0xc3, (byte) 0x11, (byte) 0xa3, (byte) 0x65}; 7 | 8 | byte[] PING_MAGIC = {(byte) 0xc3, (byte) 0x15, (byte) 0xa7, (byte) 0x65}; 9 | 10 | byte[] PONG_MAGIC = {(byte) 0xc3, (byte) 0x17, (byte) 0xab, (byte) 0x65}; 11 | 12 | int opContinuation = 0; 13 | 14 | int opText = 1; 15 | 16 | int opBinary = 2; 17 | 18 | int opClose = 8; 19 | 20 | int opPing = 9; 21 | 22 | int opPong = 10; 23 | 24 | String SEND_SUCCESS = "SEND_SUCCESS"; 25 | 26 | String SEND_FAILED = "send_failed"; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /serialize/src/main/java/com/github/wormhole/serialize/Frame.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.serialize; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @NoArgsConstructor 10 | @AllArgsConstructor 11 | public class Frame { 12 | /** 13 | * 0x1 代理发起注册 14 | * 0x10 代理注册成功 15 | * -0x1 统一失败码 16 | * 0x2 创建数据传输通道 17 | * 0x20 创建数据传输通道成功 18 | * 0x3 数据传输ack 19 | * 0x4 通知对端断开 20 | * 0x40 对端断开后的响应 21 | */ 22 | private int opCode; 23 | 24 | private String requestId; 25 | 26 | private String proxyId; 27 | 28 | private String serviceKey; 29 | 30 | private String realClientAddress; 31 | 32 | private ByteBuf payload; 33 | } 34 | -------------------------------------------------------------------------------- /serialize/src/main/java/com/github/wormhole/serialize/PackageDecoder.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.serialize; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.handler.codec.MessageToMessageDecoder; 6 | import io.netty.util.Attribute; 7 | import io.netty.util.AttributeKey; 8 | 9 | import java.util.List; 10 | 11 | public class PackageDecoder extends MessageToMessageDecoder { 12 | private Serialization serialization = new FrameSerialization(); 13 | 14 | public PackageDecoder() { 15 | } 16 | 17 | @Override 18 | protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List out) throws Exception { 19 | Frame pkg = serialization.deserialize(byteBuf); 20 | out.add(pkg); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /serialize/src/main/java/com/github/wormhole/serialize/PackageEncoder.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.serialize; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.handler.codec.MessageToMessageEncoder; 6 | import io.netty.util.ReferenceCountUtil; 7 | 8 | import java.util.List; 9 | 10 | public class PackageEncoder extends MessageToMessageEncoder { 11 | private Serialization serialization = new FrameSerialization(); 12 | 13 | public PackageEncoder() { 14 | } 15 | 16 | @Override 17 | protected void encode(ChannelHandlerContext ctx, Frame pkg, List out) throws Exception { 18 | ByteBuf buffer = ctx.alloc().buffer(); 19 | ByteBuf buf = serialization.serialize(pkg, buffer); 20 | out.add(buf); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/processor/SignalChannelContext.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server.processor; 2 | 3 | import com.github.wormhole.client.Context; 4 | 5 | import io.netty.channel.Channel; 6 | 7 | public class SignalChannelContext implements Context{ 8 | private Channel signalChannel; 9 | 10 | public SignalChannelContext(Channel signalChannel) { 11 | this.signalChannel = signalChannel; 12 | } 13 | 14 | @Override 15 | public void write(Object msg) { 16 | signalChannel.writeAndFlush(msg); 17 | } 18 | 19 | @Override 20 | public Object read() { 21 | throw new UnsupportedOperationException("Unimplemented method 'read'"); 22 | } 23 | 24 | @Override 25 | public String id() { 26 | throw new UnsupportedOperationException("Unimplemented method 'id'"); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /proxy/src/main/java/com/github/wormhole/proxy/processor/ProxyRegisterAckProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.proxy.processor; 2 | 3 | import com.github.wormhole.client.Processor; 4 | import com.github.wormhole.proxy.Proxy; 5 | import com.github.wormhole.serialize.Frame; 6 | 7 | import io.netty.channel.ChannelHandlerContext; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | @Slf4j 11 | public class ProxyRegisterAckProcessor implements Processor{ 12 | private Proxy proxy; 13 | 14 | public ProxyRegisterAckProcessor(Proxy proxy) { 15 | this.proxy = proxy; 16 | } 17 | 18 | @Override 19 | public boolean isSupport(Frame frame) { 20 | return frame.getOpCode() == 0x10; 21 | } 22 | 23 | @Override 24 | public void process(ChannelHandlerContext ctx, Frame msg) throws Exception { 25 | log.info("代理注册成功{}", msg); 26 | proxy.setProxyId(msg.getProxyId()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wormhole 2 | 内网穿透工具 3 | 4 | ### 功能特性 5 | 将内网的端口映射到公网,从而达到内网穿透的目的 6 | 7 | ### 项目结构 8 | * server 运行在公网的服务端,接受内网代理的连接,并把内网的端口映射到公网服务器上,客户端通过访问公网端口来访问内网服务 9 | * proxy 运行在内网,与公网服务建立连接,发送配置,把来自公网的流量转发到内网服务 10 | * serialize 提供公网服务与内网代理数据的序列化和反序列化功能 11 | 12 | ### 使用 13 | 14 | 1. 在公网服务器运行server 15 | ```shell 16 | java -jar server-1.0.0-SNAPSHOT-jar-with-dependencies.jar --port 8090 17 | ``` 18 | * --port 接受内网代理连接请求的端口 19 | 20 | 2. 在内网服务器运行proxy 21 | ```shell 22 | java -jar proxy-1.0.0-SNAPSHOT-jar-with-dependencies.jar --serverHost 127.0.0.1 --serverPort 8090 --configPath ./config.json 23 | ``` 24 | * --serverHost 公网服务的ip 25 | * --serverPort 公网服务的端口 26 | * --configPath 内网服务配置文件 27 | 28 | 3. 内网服务配置 29 | ```json 30 | { 31 | "mysql": { 32 | "ip": "127.0.0.1", 33 | "port": "3306", 34 | "mappingPort": "3307" 35 | }, 36 | "ssh": { 37 | "ip": "127.0.0.1", 38 | "port": "22", 39 | "mappingPort": "2200" 40 | } 41 | } 42 | ``` 43 | 44 | ### 设计 45 | ![这是图片](./doc.png "这是图片") 46 | 47 | ### 性能测试 48 | ![这是图片](./test.png "这是图片") 49 | 50 | 51 | -------------------------------------------------------------------------------- /proxy/src/main/resources/META-INF/native-image/jni-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"com.github.wormhole.proxy.Proxy", 4 | "methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }] 5 | }, 6 | { 7 | "name":"java.lang.Boolean", 8 | "methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }] 9 | }, 10 | { 11 | "name":"java.lang.String", 12 | "methods":[{"name":"lastIndexOf","parameterTypes":["int"] }, {"name":"substring","parameterTypes":["int"] }] 13 | }, 14 | { 15 | "name":"java.lang.System", 16 | "methods":[{"name":"getProperty","parameterTypes":["java.lang.String"] }, {"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] }] 17 | }, 18 | { 19 | "name":"sun.management.VMManagementImpl", 20 | "fields":[{"name":"compTimeMonitoringSupport"}, {"name":"currentThreadCpuTimeSupport"}, {"name":"objectMonitorUsageSupport"}, {"name":"otherThreadCpuTimeSupport"}, {"name":"remoteDiagnosticCommandsSupport"}, {"name":"synchronizerUsageSupport"}, {"name":"threadAllocatedMemorySupport"}, {"name":"threadContentionMonitoringSupport"}] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /server/src/main/resources/META-INF/native-image/jni-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"com.github.wormhole.server.Server", 4 | "methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }] 5 | }, 6 | { 7 | "name":"java.lang.Boolean", 8 | "methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }] 9 | }, 10 | { 11 | "name":"java.lang.String", 12 | "methods":[{"name":"lastIndexOf","parameterTypes":["int"] }, {"name":"substring","parameterTypes":["int"] }] 13 | }, 14 | { 15 | "name":"java.lang.System", 16 | "methods":[{"name":"getProperty","parameterTypes":["java.lang.String"] }, {"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] }] 17 | }, 18 | { 19 | "name":"sun.management.VMManagementImpl", 20 | "fields":[{"name":"compTimeMonitoringSupport"}, {"name":"currentThreadCpuTimeSupport"}, {"name":"objectMonitorUsageSupport"}, {"name":"otherThreadCpuTimeSupport"}, {"name":"remoteDiagnosticCommandsSupport"}, {"name":"synchronizerUsageSupport"}, {"name":"threadAllocatedMemorySupport"}, {"name":"threadContentionMonitoringSupport"}] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/config/ProxyServiceConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.config; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | @Data 9 | public class ProxyServiceConfig { 10 | @Data 11 | public static class ServiceConfig { 12 | private String ip; 13 | private Integer port; 14 | private Integer mappingPort; 15 | } 16 | 17 | private Map map = new HashMap<>(); 18 | 19 | private String serverHost; 20 | 21 | private Integer serverPort; 22 | 23 | private String username; 24 | 25 | private String password; 26 | 27 | private Integer dataTransPort; 28 | 29 | public ServiceConfig getServiceConfig(String serviceKey) { 30 | return map.get(serviceKey); 31 | } 32 | 33 | public Map getServiceConfigMap() { 34 | return new HashMap<>(map); 35 | } 36 | 37 | public void addConfig(String key, ServiceConfig config) { 38 | map.put(key, config); 39 | } 40 | 41 | public void setDataTransPort(Integer integer) { 42 | this.dataTransPort = integer; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /serialize/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | wormhole 7 | com.github 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.github.wormhole 13 | serialize 14 | 15 | 16 | 17 | io.netty 18 | netty-all 19 | 20 | 21 | commons-io 22 | commons-io 23 | 2.11.0 24 | 25 | 26 | com.github.wormhole 27 | common 28 | 1.0.0-SNAPSHOT 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/utils/TaskExecutor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.utils; 2 | 3 | import java.util.concurrent.*; 4 | 5 | public class TaskExecutor { 6 | private static TaskExecutor taskExecutor = new TaskExecutor(); 7 | private ExecutorService executorService; 8 | 9 | private BlockingQueue queue; 10 | 11 | public TaskExecutor() { 12 | this.executorService = Executors.newSingleThreadExecutor(); 13 | this.executorService.submit(() -> { 14 | try { 15 | for (;;) { 16 | Task task = this.queue.poll(100, TimeUnit.MICROSECONDS); 17 | if (task != null) { 18 | try { 19 | task.run(); 20 | } catch (Exception e) { 21 | 22 | } 23 | } 24 | } 25 | } catch (Exception e) { 26 | 27 | } 28 | }); 29 | this.queue = new LinkedBlockingQueue<>(); 30 | } 31 | 32 | public void addTask(Task task) { 33 | this.queue.add(task); 34 | } 35 | 36 | public static TaskExecutor get() { 37 | return taskExecutor; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a package using Maven and then publish it to GitHub packages when a release is created 2 | # For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path 3 | 4 | name: Release 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | release-please: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: GoogleCloudPlatform/release-please-action@v3 16 | id: release 17 | with: 18 | token: ${{ secrets.RELEASE_TOKEN }} 19 | release-type: node 20 | package-name: standard-version 21 | changelog-types: '[{"type": "types", "section":"Types", "hidden": false},{"type": "revert", "section":"Reverts", "hidden": false},{"type": "feat", "section": "Features", "hidden": false},{"type": "fix", "section": "Bug Fixes", "hidden": false},{"type": "improvement", "section": "Feature Improvements", "hidden": false},{"type": "docs", "section":"Docs", "hidden": false},{"type": "style", "section":"Styling", "hidden": false},{"type": "refactor", "section":"Code Refactoring", "hidden": false},{"type": "perf", "section":"Performance Improvements", "hidden": false},{"type": "test", "section":"Tests", "hidden": false},{"type": "build", "section":"Build System", "hidden": false},{"type": "ci", "section":"CI", "hidden":false}]' 22 | -------------------------------------------------------------------------------- /client/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github 6 | wormhole 7 | 1.0.0-SNAPSHOT 8 | 9 | com.github.wormhole 10 | client 11 | 1.0.0-SNAPSHOT 12 | Archetype - proxy 13 | http://maven.apache.org 14 | 15 | 16 | 17 | io.netty 18 | netty-all 19 | 20 | 21 | 22 | com.github.wormhole 23 | serialize 24 | 1.0.0-SNAPSHOT 25 | 26 | 27 | 28 | com.github.wormhole 29 | common 30 | 1.0.0-SNAPSHOT 31 | 32 | 33 | 34 | commons-io 35 | commons-io 36 | 2.11.0 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/SignalHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.github.wormhole.common.utils.RetryUtil; 7 | import com.github.wormhole.serialize.Frame; 8 | 9 | import io.netty.channel.ChannelHandlerContext; 10 | import io.netty.channel.SimpleChannelInboundHandler; 11 | import io.netty.channel.ChannelHandler.Sharable; 12 | 13 | @Sharable 14 | public class SignalHandler extends SimpleChannelInboundHandler{ 15 | private List list = new ArrayList<>(); 16 | 17 | public SignalHandler register(Processor signalProcessor) { 18 | this.list.add(signalProcessor); 19 | return this; 20 | } 21 | 22 | @Override 23 | public void channelRegistered(ChannelHandlerContext ctx) throws Exception { 24 | ctx.fireChannelRegistered(); 25 | } 26 | 27 | @Override 28 | protected void channelRead0(ChannelHandlerContext ctx, Frame msg) throws Exception { 29 | try { 30 | for (Processor processor : list) { 31 | if (processor.isSupport(msg)) { 32 | processor.process(ctx, msg); 33 | } 34 | } 35 | } catch (Exception e) { 36 | msg.setOpCode(-0X1); 37 | RetryUtil.write(ctx.channel(), msg); 38 | } 39 | } 40 | 41 | public Processor getProcessor(Class clazzClass) { 42 | for (Processor processor : list) { 43 | if (processor.getClass().equals(clazzClass)) { 44 | return processor; 45 | } 46 | } 47 | return null; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/processor/DisconnectClientPocessor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server.processor; 2 | 3 | import com.github.wormhole.client.Processor; 4 | import com.github.wormhole.serialize.Frame; 5 | import com.github.wormhole.server.ProxyServer; 6 | import com.github.wormhole.server.Server; 7 | 8 | import io.netty.channel.Channel; 9 | import io.netty.channel.ChannelHandlerContext; 10 | import io.netty.channel.socket.SocketChannel; 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | @Slf4j 14 | public class DisconnectClientPocessor implements Processor{ 15 | private Server server; 16 | 17 | public DisconnectClientPocessor(Server server) { 18 | this.server = server; 19 | } 20 | 21 | @Override 22 | public boolean isSupport(Frame frame) { 23 | return frame.getOpCode() == 0x4; 24 | } 25 | 26 | @Override 27 | public void process(ChannelHandlerContext ctx, Frame msg) throws Exception { 28 | log.info("关闭客户端链接{}", msg); 29 | ProxyServer proxyServer = server.getProxyServer(msg.getProxyId()); 30 | if (proxyServer != null) { 31 | Channel channel = proxyServer.getClientHandler().getClientChannelMap().get(msg.getRealClientAddress()); 32 | if (channel != null && channel.isActive()) { 33 | ((SocketChannel)channel).shutdownOutput(); 34 | msg.setOpCode(0x40); 35 | Channel channel2 = server.getProxyIdChannelMap().get(msg.getProxyId()); 36 | if(channel2 != null) { 37 | channel2.writeAndFlush(msg); 38 | } 39 | } 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /proxy/src/main/java/com/github/wormhole/proxy/processor/DisconnectClientProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.proxy.processor; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | import com.github.wormhole.client.DataClient; 6 | import com.github.wormhole.client.DataClientPool; 7 | import com.github.wormhole.client.Processor; 8 | import com.github.wormhole.proxy.Proxy; 9 | import com.github.wormhole.serialize.Frame; 10 | 11 | import io.netty.buffer.ByteBuf; 12 | import io.netty.channel.ChannelHandlerContext; 13 | import io.netty.channel.socket.SocketChannel; 14 | import lombok.extern.slf4j.Slf4j; 15 | 16 | @Slf4j 17 | public class DisconnectClientProcessor implements Processor{ 18 | private Proxy proxy; 19 | 20 | public DisconnectClientProcessor(Proxy proxy) { 21 | this.proxy = proxy; 22 | } 23 | 24 | @Override 25 | public boolean isSupport(Frame frame) { 26 | return frame.getOpCode() == 0x4; 27 | } 28 | 29 | @Override 30 | public void process(ChannelHandlerContext ctx, Frame msg) throws Exception { 31 | log.info("关闭代理与内网服务的链接{}", msg); 32 | ByteBuf payload = msg.getPayload(); 33 | String realClientAddress = msg.getRealClientAddress(); 34 | String serviceKey = msg.getServiceKey(); 35 | DataClientPool dataClientPool = proxy.getDataChannelProcessor().getServiceClientPool().get(serviceKey); 36 | if (dataClientPool != null) { 37 | String string = dataClientPool.getDataClientAssignedPeerMap().get(realClientAddress); 38 | if (string != null) { 39 | DataClient assignedDataClient = dataClientPool.getAssignedDataClient(string); 40 | if (assignedDataClient != null) { 41 | ((SocketChannel)(assignedDataClient.getChannel())).shutdownOutput(); 42 | } 43 | } 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /proxy/src/main/java/com/github/wormhole/proxy/processor/DataTransAckProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.proxy.processor; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | import com.alibaba.fastjson.JSON; 6 | import com.alibaba.fastjson.JSONObject; 7 | import com.github.wormhole.client.DataClient; 8 | import com.github.wormhole.client.DataClientPool; 9 | import com.github.wormhole.client.Processor; 10 | import com.github.wormhole.proxy.Proxy; 11 | import com.github.wormhole.serialize.Frame; 12 | 13 | import io.netty.buffer.ByteBuf; 14 | import io.netty.channel.ChannelHandlerContext; 15 | import lombok.extern.slf4j.Slf4j; 16 | 17 | @Slf4j 18 | public class DataTransAckProcessor implements Processor{ 19 | private Proxy proxy; 20 | 21 | public DataTransAckProcessor(Proxy proxy) { 22 | this.proxy = proxy; 23 | } 24 | 25 | @Override 26 | public boolean isSupport(Frame frame) { 27 | return frame.getOpCode() == 0x3; 28 | } 29 | 30 | @Override 31 | public void process(ChannelHandlerContext ctx, Frame msg) throws Exception { 32 | log.info("代理ack{}", msg); 33 | String proxyId = msg.getProxyId(); 34 | ByteBuf payload = msg.getPayload(); 35 | String serviceKey = msg.getServiceKey(); 36 | String string = payload.readCharSequence(payload.readableBytes(), Charset.forName("UTF-8")).toString(); 37 | JSONObject parseObject = JSONObject.parseObject(string); 38 | String string2 = parseObject.getString("channelId"); 39 | Long long1 = parseObject.getLong("ackSize"); 40 | DataClientPool dataClientPool = proxy.getDataChannelProcessor().getServiceClientPool().get(serviceKey); 41 | if (dataClientPool != null) { 42 | DataClient assignedDataClient = dataClientPool.getAssignedDataClient(string2); 43 | if (assignedDataClient != null) { 44 | assignedDataClient.getAckHandler().setAck(long1); 45 | } 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/processor/ProxyRegisterProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server.processor; 2 | 3 | import java.io.IOException; 4 | import java.nio.charset.Charset; 5 | import java.nio.charset.StandardCharsets; 6 | import java.util.Map; 7 | 8 | import org.apache.commons.lang3.RandomStringUtils; 9 | 10 | import com.github.wormhole.client.Processor; 11 | import com.github.wormhole.common.config.ProxyServiceConfig; 12 | import com.github.wormhole.common.utils.ConfigLoader; 13 | import com.github.wormhole.common.utils.IDUtil; 14 | import com.github.wormhole.common.utils.RetryUtil; 15 | import com.github.wormhole.serialize.Frame; 16 | import com.github.wormhole.server.ProxyServer; 17 | import com.github.wormhole.server.Server; 18 | 19 | import io.netty.buffer.ByteBuf; 20 | import io.netty.buffer.PooledByteBufAllocator; 21 | import io.netty.channel.Channel; 22 | import io.netty.channel.ChannelHandlerContext; 23 | import lombok.extern.slf4j.Slf4j; 24 | 25 | @Slf4j 26 | public class ProxyRegisterProcessor implements Processor{ 27 | private Server server; 28 | 29 | public ProxyRegisterProcessor(Server server) { 30 | this.server = server; 31 | } 32 | 33 | @Override 34 | public boolean isSupport(Frame frame) { 35 | return frame.getOpCode() == 0x1; 36 | } 37 | 38 | @Override 39 | public void process(ChannelHandlerContext ctx, Frame msg) throws Exception { 40 | String s = msg.getPayload().toString(StandardCharsets.UTF_8); 41 | ProxyServiceConfig proxyServiceConfig = ConfigLoader.parse(s); 42 | String proxyId = server.buildProxyServer(proxyServiceConfig, ctx.channel()); 43 | server.getProxyIdChannelMap().put(proxyId, ctx.channel()); 44 | Frame frame = new Frame(); 45 | frame.setOpCode(0x10); 46 | frame.setRequestId(IDUtil.genRequestId()); 47 | frame.setProxyId(proxyId); 48 | RetryUtil.write(ctx.channel(), frame); 49 | log.info("内网代理与服务器建立连接{}", frame); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/processor/DataTransAckProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server.processor; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | import com.alibaba.fastjson.JSON; 6 | import com.alibaba.fastjson.JSONObject; 7 | import com.github.wormhole.client.DataClient; 8 | import com.github.wormhole.client.DataClientPool; 9 | import com.github.wormhole.client.Processor; 10 | import com.github.wormhole.client.ack.AckHandler; 11 | import com.github.wormhole.serialize.Frame; 12 | import com.github.wormhole.server.ProxyServer; 13 | import com.github.wormhole.server.Server; 14 | 15 | import io.netty.buffer.ByteBuf; 16 | import io.netty.channel.Channel; 17 | import io.netty.channel.ChannelHandlerContext; 18 | import lombok.extern.slf4j.Slf4j; 19 | 20 | @Slf4j 21 | public class DataTransAckProcessor implements Processor{ 22 | private Server server; 23 | 24 | public DataTransAckProcessor(Server server) { 25 | this.server = server; 26 | } 27 | 28 | @Override 29 | public boolean isSupport(Frame frame) { 30 | return frame.getOpCode() == 0x3; 31 | } 32 | 33 | @Override 34 | public void process(ChannelHandlerContext ctx, Frame msg) throws Exception { 35 | log.info("服务器ack{}", msg); 36 | String proxyId = msg.getProxyId(); 37 | ByteBuf payload = msg.getPayload(); 38 | String serviceKey = msg.getServiceKey(); 39 | String string = payload.readCharSequence(payload.readableBytes(), Charset.forName("UTF-8")).toString(); 40 | JSONObject parseObject = JSONObject.parseObject(string); 41 | String string2 = parseObject.getString("channelId"); 42 | Long long1 = parseObject.getLong("ackSize"); 43 | ProxyServer proxyServer = server.getProxyServer(proxyId); 44 | if (proxyServer != null) { 45 | Channel channel = proxyServer.getClientHandler().getClientChannelMap().get(string2); 46 | if (channel != null) { 47 | AckHandler ackHandler = proxyServer.getAckHandlerMap().get(channel); 48 | if (ackHandler != null) { 49 | ackHandler.setAck(long1); 50 | } 51 | } 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/DataTransHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client; 2 | 3 | import java.util.Queue; 4 | import java.util.concurrent.ArrayBlockingQueue; 5 | import java.util.concurrent.BlockingQueue; 6 | 7 | import com.github.wormhole.client.ack.AckHandler; 8 | import com.github.wormhole.common.utils.IDUtil; 9 | import com.github.wormhole.serialize.Frame; 10 | 11 | import io.netty.buffer.ByteBuf; 12 | import io.netty.channel.ChannelHandlerContext; 13 | import io.netty.channel.ChannelInboundHandlerAdapter; 14 | import io.netty.channel.ChannelPromise; 15 | import io.netty.channel.SimpleChannelInboundHandler; 16 | import lombok.extern.slf4j.Slf4j; 17 | 18 | @Slf4j 19 | public class DataTransHandler extends ChannelInboundHandlerAdapter { 20 | private DataClient dataClient; 21 | 22 | public DataTransHandler(DataClient dataClient) { 23 | this.dataClient = dataClient; 24 | } 25 | 26 | @Override 27 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 28 | log.info("转发对端传来的数据{}-{}", dataClient, dataClient.getDirectClient()); 29 | dataClient.getDirectClient().send((ByteBuf) msg); 30 | } 31 | 32 | @Override 33 | public void channelReadComplete(ChannelHandlerContext ctx) { 34 | if (dataClient.getConnType() != 2) { 35 | return; 36 | } 37 | Frame closePeer = closePeer(); 38 | AckHandler ackHandler = dataClient.getAckHandler(); 39 | 40 | if (ackHandler.isAckComplate()) { 41 | log.info("内网服务关闭连接{}", closePeer); 42 | dataClient.getContext().write(closePeer); 43 | return; 44 | } 45 | ChannelPromise newPromise = ctx.channel().newPromise(); 46 | ackHandler.setPromise(newPromise); 47 | newPromise.addListener(f -> { 48 | log.info("内网服务关闭连接{}", closePeer); 49 | dataClient.getContext().write(closePeer); 50 | }); 51 | } 52 | 53 | private Frame closePeer() { 54 | Frame frame = new Frame(); 55 | frame.setOpCode(0x4); 56 | frame.setProxyId(dataClient.getContext().id()); 57 | frame.setServiceKey(dataClient.getDataClientPool().getServiceKey()); 58 | frame.setRealClientAddress(dataClient.getPeerClientAddress()); 59 | frame.setRequestId(IDUtil.genRequestId()); 60 | return frame; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/SignalClient.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client; 2 | 3 | import java.nio.charset.Charset; 4 | import java.util.Map; 5 | import java.util.concurrent.ConcurrentHashMap; 6 | 7 | import org.apache.commons.lang3.RandomStringUtils; 8 | 9 | import com.github.wormhole.common.utils.RetryUtil; 10 | import com.github.wormhole.serialize.Frame; 11 | import com.github.wormhole.serialize.FrameDecoder; 12 | import com.github.wormhole.serialize.FrameEncoder; 13 | import com.github.wormhole.serialize.PackageDecoder; 14 | import com.github.wormhole.serialize.PackageEncoder; 15 | 16 | import io.netty.buffer.ByteBuf; 17 | import io.netty.buffer.PooledByteBufAllocator; 18 | import io.netty.channel.ChannelFuture; 19 | import io.netty.channel.ChannelPipeline; 20 | import io.netty.channel.ChannelPromise; 21 | import io.netty.handler.logging.LoggingHandler; 22 | import io.netty.util.concurrent.GenericFutureListener; 23 | import lombok.extern.slf4j.Slf4j; 24 | 25 | @Slf4j 26 | public class SignalClient extends Client{ 27 | private Map reqMap = new ConcurrentHashMap<>(); 28 | 29 | private SignalHandler signalHandler = new SignalHandler(); 30 | 31 | public SignalClient(String ip, Integer port, Context context) { 32 | super(ip, port, context); 33 | } 34 | 35 | public SignalClient register(Processor signalProcessor) { 36 | this.signalHandler.register(signalProcessor); 37 | return this; 38 | } 39 | 40 | public Processor getProcessor(Class clazzClass) { 41 | return signalHandler.getProcessor(clazzClass); 42 | 43 | } 44 | 45 | @Override 46 | public void initChannelPipeline(ChannelPipeline pipeline) { 47 | pipeline.addLast(new FrameDecoder()); 48 | pipeline.addLast(new FrameEncoder()); 49 | pipeline.addLast(new PackageDecoder()); 50 | pipeline.addLast(new PackageEncoder()); 51 | pipeline.addLast(signalHandler); 52 | } 53 | 54 | @Override 55 | public ChannelFuture send(Frame msg) { 56 | String key = System.currentTimeMillis() + RandomStringUtils.randomAlphabetic(8); 57 | msg.setRequestId(key); 58 | ChannelPromise newPromise = channel.newPromise(); 59 | if (key != null) { 60 | reqMap.put(key, newPromise); 61 | } 62 | RetryUtil.write(channel, msg); 63 | return newPromise; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/utils/ConfigLoader.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.utils; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | 6 | import org.apache.commons.io.IOUtils; 7 | 8 | import java.io.FileInputStream; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.nio.charset.StandardCharsets; 12 | import java.util.Map; 13 | 14 | import com.github.wormhole.common.config.ProxyServiceConfig; 15 | import com.github.wormhole.common.config.ProxyServiceConfig.ServiceConfig; 16 | 17 | public class ConfigLoader { 18 | public static ProxyServiceConfig load(String path) throws IOException { 19 | InputStream inputStream = new FileInputStream(path); 20 | byte[] bytes = IOUtils.toByteArray(inputStream); 21 | String s = new String(bytes, StandardCharsets.UTF_8); 22 | ProxyServiceConfig parse = parse(s); 23 | return parse; 24 | } 25 | 26 | public static ProxyServiceConfig parse(String data) throws IOException { 27 | String s = data; 28 | JSONObject jsonObject = JSON.parseObject(s); 29 | ProxyServiceConfig proxyServiceConfig = new ProxyServiceConfig(); 30 | for (Map.Entry entry : jsonObject.entrySet()) { 31 | if (entry.getValue() instanceof JSONObject) { 32 | proxyServiceConfig.addConfig(entry.getKey(), ((JSONObject) entry.getValue()).toJavaObject(ProxyServiceConfig.ServiceConfig.class)); 33 | } 34 | } 35 | proxyServiceConfig.setServerHost(jsonObject.getString("serverHost")); 36 | proxyServiceConfig.setServerPort(jsonObject.getInteger("serverPort")); 37 | proxyServiceConfig.setDataTransPort(jsonObject.getInteger("dataTransPort")); 38 | proxyServiceConfig.setUsername(jsonObject.getString("username")); 39 | proxyServiceConfig.setPassword(jsonObject.getString("password")); 40 | return proxyServiceConfig; 41 | } 42 | 43 | public static String serialize(ProxyServiceConfig config) { 44 | JSONObject jsonObject = new JSONObject(); 45 | jsonObject.put("serverHost", config.getServerHost()); 46 | jsonObject.put("serverPort", config.getServerPort()); 47 | Map map = config.getMap(); 48 | map.forEach((k, v) -> jsonObject.put(k, JSONObject.toJSON(v))); 49 | return jsonObject.toJSONString(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | wormhole 6 | com.github 7 | 1.0.0-SNAPSHOT 8 | 9 | com.github.wormhole 10 | common 11 | 1.0.0-SNAPSHOT 12 | 13 | 1.8 14 | 1.8 15 | UTF-8 16 | 5.6.0 17 | 3.0.0-M3 18 | 3.1.2 19 | 8.45.1 20 | 3.0.0-M5 21 | 0.8.4 22 | 3.0.0 23 | 24 | 0% 25 | 0% 26 | 20 27 | 5 28 | 29 | 30 | 31 | org.junit.jupiter 32 | junit-jupiter-api 33 | ${junit.version} 34 | test 35 | 36 | 37 | org.junit.jupiter 38 | junit-jupiter-engine 39 | ${junit.version} 40 | test 41 | 42 | 43 | io.netty 44 | netty-all 45 | 46 | 47 | commons-io 48 | commons-io 49 | 2.11.0 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/DataTransHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server; 2 | 3 | import java.nio.charset.Charset; 4 | import java.util.Map; 5 | import java.util.concurrent.ConcurrentHashMap; 6 | import java.util.concurrent.atomic.AtomicLong; 7 | 8 | import com.alibaba.fastjson.JSONObject; 9 | import com.github.wormhole.serialize.Frame; 10 | 11 | import io.netty.buffer.ByteBuf; 12 | import io.netty.buffer.PooledByteBufAllocator; 13 | import io.netty.channel.Channel; 14 | import io.netty.channel.ChannelHandlerAdapter; 15 | import io.netty.channel.ChannelHandlerContext; 16 | import io.netty.channel.ChannelInboundHandler; 17 | import io.netty.channel.ChannelInboundHandlerAdapter; 18 | import io.netty.channel.ChannelPipeline; 19 | import io.netty.channel.ChannelHandler.Sharable; 20 | import lombok.extern.slf4j.Slf4j; 21 | 22 | @Sharable 23 | @Slf4j 24 | public class DataTransHandler extends ChannelInboundHandlerAdapter{ 25 | private Map channalMap = new ConcurrentHashMap<>(); 26 | 27 | private Map clientChannelMap = new ConcurrentHashMap<>(); 28 | 29 | private Server server; 30 | 31 | public DataTransHandler(Server server) { 32 | this.server = server; 33 | } 34 | 35 | @Override 36 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 37 | ctx.fireChannelActive(); 38 | Channel channel = ctx.channel(); 39 | String key = channel.remoteAddress().toString() + "-" + channel.localAddress().toString(); 40 | channalMap.put(key, channel); 41 | log.info("内网代理与服务器建立数据传输通道{}", key); 42 | } 43 | 44 | @Override 45 | public void channelInactive(ChannelHandlerContext ctx) throws Exception { 46 | ctx.fireChannelInactive(); 47 | Channel channel = ctx.channel(); 48 | channalMap.remove(channel.id().toString()); 49 | log.info("内网代理与服务器关闭数据传输通道{}", channel); 50 | } 51 | 52 | public Channel getDataTransChannel(String channelId) { 53 | return channalMap.get(channelId); 54 | } 55 | 56 | public void buildDataClientChannelMap(Channel dataChannel, Channel clientChannel) { 57 | clientChannelMap.put(dataChannel, clientChannel); 58 | } 59 | 60 | @Override 61 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 62 | Channel channel = ctx.channel(); 63 | Channel channel2 = clientChannelMap.get(channel); 64 | channel2.writeAndFlush(msg); 65 | log.info("读取来自内网代理的数据,并发送给客户端{},{}", channel, channel2); 66 | } 67 | 68 | public void clear(String clientAddress) { 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/utils/RetryUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.utils; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.channel.ChannelFuture; 5 | import io.netty.channel.ChannelHandlerContext; 6 | import io.netty.util.concurrent.GenericFutureListener; 7 | 8 | public class RetryUtil { 9 | 10 | public static void write( Channel channel, T msg) { 11 | Holder holder = new Holder<>(); 12 | GenericFutureListener listener = f -> { 13 | Object obj = msg; 14 | if (!f.isSuccess()) { 15 | Thread.sleep(100); 16 | channel.writeAndFlush(obj).addListener(holder.t); 17 | } 18 | }; 19 | holder.t = listener; 20 | channel.writeAndFlush(msg).addListener(holder.t); 21 | } 22 | 23 | public static void writeLimitTime(Connection conn, T msg, int num) { 24 | Holder holder = new Holder<>(); 25 | Holder holder2 = new Holder<>(); 26 | holder2.t = num; 27 | GenericFutureListener listener = f -> { 28 | if (!f.isSuccess() && holder2.t > 0) { 29 | Thread.sleep(100); 30 | ChannelFuture write = conn.write(msg); 31 | if (write != null) { 32 | write.addListener(holder.t); 33 | } 34 | holder2.t--; 35 | } 36 | }; 37 | holder.t = listener; 38 | ChannelFuture write = conn.write(msg); 39 | if (write != null) { 40 | write.addListener(holder.t); 41 | } 42 | holder2.t--; 43 | } 44 | 45 | public static void writeLimitNumThen(Connection conn, T msg, int num, Runnable runnable) { 46 | Holder holder = new Holder<>(); 47 | Holder holder2 = new Holder<>(); 48 | holder2.t = num; 49 | GenericFutureListener listener = f -> { 50 | if (!f.isSuccess() && holder2.t > 0) { 51 | Thread.sleep(100); 52 | ChannelFuture write = conn.write(msg); 53 | if (write != null) { 54 | write.addListener(holder.t); 55 | } 56 | holder2.t--; 57 | } else { 58 | runnable.run(); 59 | } 60 | }; 61 | holder.t = listener; 62 | ChannelFuture write = conn.write(msg); 63 | if (write != null) { 64 | write.addListener(holder.t); 65 | } 66 | holder2.t--; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | *.iml 6 | 7 | # Log file 8 | *.log 9 | 10 | # BlueJ files 11 | *.ctxt 12 | 13 | # Mobile Tools for Java (J2ME) 14 | .mtj.tmp/ 15 | 16 | # Package Files # 17 | *.jar 18 | *.war 19 | *.ear 20 | *.zip 21 | *.tar.gz 22 | *.rar 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | ### JetBrains template 27 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 28 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 29 | 30 | # User-specific stuff: 31 | .idea/**/workspace.xml 32 | .idea/**/tasks.xml 33 | .idea/dictionaries 34 | 35 | # Sensitive or high-churn files: 36 | .idea/**/dataSources/ 37 | .idea/**/dataSources.ids 38 | .idea/**/dataSources.xml 39 | .idea/**/dataSources.local.xml 40 | .idea/**/sqlDataSources.xml 41 | .idea/**/dynamic.xml 42 | .idea/**/uiDesigner.xml 43 | 44 | # Gradle: 45 | .idea/**/gradle.xml 46 | .idea/**/libraries 47 | 48 | # Mongo Explorer plugin: 49 | .idea/**/mongoSettings.xml 50 | 51 | ## File-based project format: 52 | *.iws 53 | 54 | ## Plugin-specific files: 55 | 56 | # IntelliJ 57 | /target/ 58 | .idea/ 59 | target/ 60 | 61 | #vscode 62 | target/ 63 | .vscode 64 | 65 | # mpeltonen/sbt-idea plugin 66 | .idea_modules/ 67 | 68 | # JIRA plugin 69 | atlassian-ide-plugin.xml 70 | 71 | # Crashlytics plugin (for Android Studio and IntelliJ) 72 | com_crashlytics_export_strings.xml 73 | crashlytics.properties 74 | crashlytics-build.properties 75 | fabric.properties 76 | ### Eclipse template 77 | 78 | .metadata 79 | bin/ 80 | tmp/ 81 | *.tmp 82 | *.bak 83 | *.swp 84 | *~.nib 85 | local.properties 86 | .settings/ 87 | .loadpath 88 | .recommenders 89 | 90 | # Eclipse Core 91 | .project 92 | 93 | # External tool builders 94 | .externalToolBuilders/ 95 | 96 | # Locally stored "Eclipse launch configurations" 97 | *.launch 98 | 99 | # PyDev specific (Python IDE for Eclipse) 100 | *.pydevproject 101 | 102 | # CDT-specific (C/C++ Development Tooling) 103 | .cproject 104 | 105 | # JDT-specific (Eclipse Java Development Tools) 106 | .classpath 107 | 108 | # Java annotation processor (APT) 109 | .factorypath 110 | 111 | # PDT-specific (PHP Development Tools) 112 | .buildpath 113 | 114 | # sbteclipse plugin 115 | .target 116 | 117 | # Tern plugin 118 | .tern-project 119 | 120 | # TeXlipse plugin 121 | .texlipse 122 | 123 | # STS (Spring Tool Suite) 124 | .springBeans 125 | 126 | # Code Recommenders 127 | .recommenders/ 128 | 129 | # Scala IDE specific (Scala & Java development for Eclipse) 130 | .cache-main 131 | .scala_dependencies 132 | .worksheet 133 | *-workspace 134 | 135 | proxy/.DS_Store 136 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/processor/BuildDataChannelProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server.processor; 2 | 3 | import java.nio.charset.Charset; 4 | import java.util.Set; 5 | import java.util.concurrent.ConcurrentSkipListSet; 6 | 7 | import com.github.wormhole.client.Processor; 8 | import com.github.wormhole.client.ack.AckHandler; 9 | import com.github.wormhole.serialize.Frame; 10 | import com.github.wormhole.server.ProxyServer; 11 | import com.github.wormhole.server.Server; 12 | 13 | import io.netty.buffer.ByteBuf; 14 | import io.netty.channel.Channel; 15 | import io.netty.channel.ChannelHandlerContext; 16 | import io.netty.util.internal.ConcurrentSet; 17 | import lombok.extern.slf4j.Slf4j; 18 | 19 | @Slf4j 20 | public class BuildDataChannelProcessor implements Processor{ 21 | private Server server; 22 | 23 | public BuildDataChannelProcessor(Server server) { 24 | this.server = server; 25 | } 26 | 27 | @Override 28 | public boolean isSupport(Frame frame) { 29 | return frame.getOpCode() == 0x20 || frame.getOpCode() == -0x20; 30 | } 31 | 32 | @Override 33 | public void process(ChannelHandlerContext ctx, Frame msg) throws Exception { 34 | log.info("内网代理与服务器建立数据通道成功{}", msg); 35 | int opCode = msg.getOpCode(); 36 | String realClientAddress = msg.getRealClientAddress(); 37 | String requestId = msg.getRequestId(); 38 | String proxyId = msg.getProxyId(); 39 | ByteBuf payload = msg.getPayload(); 40 | ProxyServer proxyServer = server.getProxyServer(proxyId); 41 | String serviceKey = msg.getServiceKey(); 42 | if (opCode == 0x20) { 43 | String dataChannelId = payload.getCharSequence(0, payload.readableBytes(), Charset.forName("UTF-8")).toString(); 44 | if (proxyServer != null) { 45 | Channel clientChannel = proxyServer.getClientHandler().getClientChannelMap().get(realClientAddress); 46 | Channel dataTransChannel = server.getDataTransServer().getDataTransHandler().getDataTransChannel(dataChannelId); 47 | if (clientChannel != null && dataTransChannel != null) { 48 | server.getDataTransServer().getDataTransHandler().buildDataClientChannelMap(dataTransChannel, clientChannel); 49 | proxyServer.getClientHandler().getDataChannelMap().put(clientChannel, dataTransChannel); 50 | server.getDataChannelProxyIdMap().put(dataChannelId, proxyId); 51 | proxyServer.getClientHandler().success(realClientAddress); 52 | } else { 53 | proxyServer.getClientHandler().fail(realClientAddress); 54 | } 55 | } 56 | } else { 57 | if (proxyServer != null) { 58 | proxyServer.refuse(realClientAddress); 59 | } 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /proxy/src/main/java/com/github/wormhole/proxy/processor/DataChannelProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.proxy.processor; 2 | 3 | import java.nio.charset.Charset; 4 | import java.util.Map; 5 | import java.util.concurrent.ConcurrentHashMap; 6 | 7 | import com.github.wormhole.client.DataClient; 8 | import com.github.wormhole.client.DataClientPool; 9 | import com.github.wormhole.client.Processor; 10 | import com.github.wormhole.common.config.ProxyServiceConfig.ServiceConfig; 11 | import com.github.wormhole.proxy.Proxy; 12 | import com.github.wormhole.serialize.Frame; 13 | 14 | import io.netty.buffer.ByteBuf; 15 | import io.netty.buffer.PooledByteBufAllocator; 16 | import io.netty.channel.Channel; 17 | import io.netty.channel.ChannelHandlerContext; 18 | import lombok.extern.slf4j.Slf4j; 19 | 20 | @Slf4j 21 | public class DataChannelProcessor implements Processor{ 22 | private Proxy proxy; 23 | 24 | private Map serviceClientPool = new ConcurrentHashMap<>(); 25 | 26 | public DataChannelProcessor(Proxy proxy) { 27 | this.proxy = proxy; 28 | } 29 | 30 | @Override 31 | public boolean isSupport(Frame frame) { 32 | return frame.getOpCode() == 0x2; 33 | } 34 | 35 | @Override 36 | public void process(ChannelHandlerContext ctx, Frame msg) throws Exception { 37 | String serviceKey = msg.getServiceKey(); 38 | DataClient dataClient = proxy.getDataClientPool().take(); 39 | dataClient.setPeerClientAddress(msg.getRealClientAddress()); 40 | log.info("内网代理与服务器建立数据传输通道{}", dataClient); 41 | DataClientPool dataClientPool = serviceClientPool.get(serviceKey); 42 | ServiceConfig serviceConfig = proxy.getConfig().getMap().get(serviceKey); 43 | if (dataClientPool == null) { 44 | serviceClientPool.put(serviceKey, new DataClientPool(serviceConfig.getIp(), serviceConfig.getPort(), 2, proxy)); 45 | dataClientPool = serviceClientPool.get(serviceKey); 46 | dataClientPool.setServiceKey(serviceKey); 47 | } 48 | DataClient serviceClient = dataClientPool.take(); 49 | serviceClient.setPeerClientAddress(msg.getRealClientAddress()); 50 | serviceClient.refresh(dataClient); 51 | dataClient.refresh(serviceClient); 52 | log.info("内网代理与内网服务建立数据传输通道{}", serviceClient); 53 | msg.setOpCode(0x20); 54 | msg.setProxyId(proxy.getProxyId()); 55 | ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); 56 | Channel channel = dataClient.getChannel(); 57 | String key = channel.localAddress().toString() + "-" + channel.remoteAddress().toString(); 58 | buffer.writeCharSequence(key, Charset.forName("UTF-8")); 59 | msg.setPayload(buffer); 60 | ctx.writeAndFlush(msg); 61 | log.info("DataChannelProcessor {}", msg); 62 | } 63 | 64 | public Proxy getProxy() { 65 | return proxy; 66 | } 67 | 68 | public Map getServiceClientPool() { 69 | return serviceClientPool; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github 6 | wormhole 7 | 1.0.0-SNAPSHOT 8 | 9 | com.github.wormhole 10 | server 11 | Archetype - server 12 | http://maven.apache.org 13 | 14 | 15 | 16 | io.netty 17 | netty-all 18 | 19 | 20 | 21 | com.github.wormhole 22 | serialize 23 | 1.0.0-SNAPSHOT 24 | 25 | 26 | 27 | com.github.wormhole 28 | client 29 | 1.0.0-SNAPSHOT 30 | 31 | 32 | 33 | 60 | 61 | 62 | 63 | org.apache.maven.plugins 64 | maven-assembly-plugin 65 | 3.0.0 66 | 67 | 68 | 69 | com.github.wormhole.server.Server 70 | 71 | 72 | 73 | jar-with-dependencies 74 | 75 | 76 | 77 | 78 | make-assembly 79 | package 80 | 81 | single 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/ack/AckHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client.ack; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.github.wormhole.client.Context; 7 | import com.github.wormhole.client.DataClient; 8 | import com.github.wormhole.common.utils.IDUtil; 9 | import com.github.wormhole.serialize.Frame; 10 | 11 | import io.netty.buffer.ByteBuf; 12 | import io.netty.buffer.PooledByteBufAllocator; 13 | import io.netty.channel.Channel; 14 | import io.netty.channel.ChannelDuplexHandler; 15 | import io.netty.channel.ChannelHandlerContext; 16 | import io.netty.channel.ChannelPromise; 17 | import lombok.extern.slf4j.Slf4j; 18 | 19 | @Slf4j 20 | public class AckHandler extends ChannelDuplexHandler{ 21 | private long writeByteCount; 22 | 23 | private long readByteCount; 24 | 25 | private long ackCount; 26 | 27 | private Context context; 28 | 29 | private String proxyId; 30 | 31 | private String serviceKey; 32 | 33 | private Channel channel; 34 | 35 | private String peerClientAddress; 36 | 37 | private ChannelPromise promise; 38 | 39 | public AckHandler(Channel channel,Context context, String proxyId, String serviceKey, String peerClientAddress) { 40 | this.context = context; 41 | this.proxyId = proxyId; 42 | this.serviceKey = serviceKey; 43 | this.channel = channel; 44 | this.peerClientAddress = peerClientAddress; 45 | } 46 | 47 | @Override 48 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 49 | ByteBuf buf = (ByteBuf) msg; 50 | readByteCount += buf.readableBytes(); 51 | log.info("收到{}数据{}", peerClientAddress, readByteCount); 52 | ctx.fireChannelRead(msg); 53 | } 54 | 55 | @Override 56 | public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { 57 | ctx.write(msg, promise); 58 | ByteBuf buf = (ByteBuf) msg; 59 | writeByteCount += buf.readableBytes(); 60 | Frame frame = new Frame(); 61 | frame.setOpCode(0x3); 62 | frame.setRequestId(IDUtil.genRequestId()); 63 | frame.setServiceKey(serviceKey); 64 | ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); 65 | JSONObject jsonObject = new JSONObject(); 66 | jsonObject.put("channelId", peerClientAddress); 67 | jsonObject.put("ackSize", writeByteCount); 68 | String jsonString = jsonObject.toJSONString(); 69 | buffer.writeCharSequence(jsonString, Charset.forName("UTF-8")); 70 | frame.setPayload(buffer); 71 | context.write(frame); 72 | log.info("发送给{}数据{}", peerClientAddress, writeByteCount); 73 | } 74 | 75 | public void setAck(long ack) { 76 | channel.eventLoop().submit(() -> { 77 | AckHandler.this.ackCount = ack; 78 | if (AckHandler.this.ackCount == AckHandler.this.readByteCount) { 79 | if (promise != null) { 80 | promise.setSuccess(); 81 | } 82 | } 83 | }); 84 | } 85 | 86 | public boolean isAckComplate() { 87 | return ackCount == readByteCount; 88 | } 89 | 90 | public void setPromise(ChannelPromise promise) { 91 | this.promise = promise; 92 | } 93 | 94 | public void setPeerClientAddress(String peerClientAddress) { 95 | this.peerClientAddress = peerClientAddress; 96 | } 97 | 98 | public void clear() { 99 | this.writeByteCount = 0; 100 | this.readByteCount = 0; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /serialize/src/main/java/com/github/wormhole/serialize/FrameSerialization.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.serialize; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.buffer.PooledByteBufAllocator; 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import java.nio.charset.StandardCharsets; 8 | 9 | public class FrameSerialization implements Serialization { 10 | 11 | @Override 12 | public ByteBuf serialize(Frame msg, ByteBuf byteBuf) { 13 | int opCode = msg.getOpCode(); 14 | byteBuf.writeInt(opCode); 15 | String sessionId = msg.getRequestId(); 16 | if (StringUtils.isNotEmpty(sessionId)) { 17 | byte[] bytes = msg.getRequestId().getBytes(StandardCharsets.UTF_8); 18 | byteBuf.writeInt(bytes.length); 19 | byteBuf.writeBytes(bytes); 20 | } else { 21 | byteBuf.writeInt(0); 22 | } 23 | String proxyId = msg.getProxyId(); 24 | if (StringUtils.isNotEmpty(proxyId)) { 25 | byte[] bytes = proxyId.getBytes(StandardCharsets.UTF_8); 26 | byteBuf.writeInt(bytes.length); 27 | byteBuf.writeBytes(bytes); 28 | } else { 29 | byteBuf.writeInt(0); 30 | } 31 | String serviceKey = msg.getServiceKey(); 32 | if (StringUtils.isNotEmpty(serviceKey)) { 33 | byte[] bytes = msg.getServiceKey().getBytes(StandardCharsets.UTF_8); 34 | byteBuf.writeInt(bytes.length); 35 | byteBuf.writeBytes(bytes); 36 | } else { 37 | byteBuf.writeInt(0); 38 | } 39 | if (StringUtils.isNotEmpty(msg.getRealClientAddress())) { 40 | byte[] bytes = msg.getRealClientAddress().getBytes(StandardCharsets.UTF_8); 41 | byteBuf.writeInt(bytes.length); 42 | byteBuf.writeBytes(bytes); 43 | } else { 44 | byteBuf.writeInt(0); 45 | } 46 | if (msg.getPayload() != null) { 47 | byteBuf.writeInt(msg.getPayload().readableBytes()); 48 | byteBuf.writeBytes(msg.getPayload()); 49 | } else { 50 | byteBuf.writeInt(0); 51 | } 52 | return byteBuf; 53 | } 54 | 55 | @Override 56 | public Frame deserialize(ByteBuf byteBuf) { 57 | Frame frame = new Frame(); 58 | frame.setOpCode(byteBuf.readInt()); 59 | int n = byteBuf.readInt(); 60 | byte[] bytes = null; 61 | if (n > 0) { 62 | bytes = new byte[n]; 63 | byteBuf.readBytes(bytes, 0, n); 64 | String sessionId = new String(bytes, StandardCharsets.UTF_8); 65 | frame.setRequestId(sessionId); 66 | } 67 | n = byteBuf.readInt(); 68 | if (n > 0) { 69 | bytes = new byte[n]; 70 | byteBuf.readBytes(bytes, 0, n); 71 | String proxyId = new String(bytes, StandardCharsets.UTF_8); 72 | frame.setProxyId(proxyId); 73 | } 74 | n = byteBuf.readInt(); 75 | if (n > 0) { 76 | bytes = new byte[n]; 77 | byteBuf.readBytes(bytes, 0, n); 78 | String serviceKey = new String(bytes, StandardCharsets.UTF_8); 79 | frame.setServiceKey(serviceKey); 80 | } 81 | n = byteBuf.readInt(); 82 | if (n > 0) { 83 | bytes = new byte[n]; 84 | byteBuf.readBytes(bytes, 0, n); 85 | String realClientAddress = new String(bytes, StandardCharsets.UTF_8); 86 | frame.setRealClientAddress(realClientAddress); 87 | } 88 | n = byteBuf.readInt(); 89 | if (n > 0) { 90 | ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(n); 91 | buffer.writeBytes(byteBuf, n); 92 | frame.setPayload(buffer); 93 | } 94 | return frame; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/DataTransServer.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import com.github.wormhole.client.ack.AckHandler; 7 | import com.github.wormhole.serialize.FrameDecoder; 8 | import com.github.wormhole.serialize.FrameEncoder; 9 | import com.github.wormhole.serialize.PackageDecoder; 10 | import com.github.wormhole.serialize.PackageEncoder; 11 | 12 | import io.netty.bootstrap.ServerBootstrap; 13 | import io.netty.channel.Channel; 14 | import io.netty.channel.ChannelFuture; 15 | import io.netty.channel.ChannelInitializer; 16 | import io.netty.channel.ChannelOption; 17 | import io.netty.channel.ChannelPipeline; 18 | import io.netty.channel.EventLoopGroup; 19 | import io.netty.channel.nio.NioEventLoopGroup; 20 | import io.netty.channel.socket.nio.NioServerSocketChannel; 21 | import io.netty.channel.socket.nio.NioSocketChannel; 22 | import io.netty.handler.logging.LogLevel; 23 | import io.netty.handler.logging.LoggingHandler; 24 | 25 | public class DataTransServer { 26 | private int port; 27 | 28 | private ChannelFuture channelFuture; 29 | 30 | private EventLoopGroup boss; 31 | private EventLoopGroup worker; 32 | 33 | private DataTransHandler dataTransHandler; 34 | 35 | private Server server; 36 | 37 | public DataTransServer(int port, EventLoopGroup boss, EventLoopGroup worker, Server server) { 38 | this.port = port; 39 | this.boss = boss; 40 | this.worker = worker; 41 | this.server = server; 42 | this.dataTransHandler = new DataTransHandler(server); 43 | } 44 | 45 | public void open() { 46 | ServerBootstrap bootstrap = new ServerBootstrap(); 47 | 48 | bootstrap.group(boss, worker) 49 | .option(ChannelOption.AUTO_READ, true) 50 | .channel(NioServerSocketChannel.class) 51 | .handler(new LoggingHandler(LogLevel.DEBUG)) 52 | .childHandler(new ChannelInitializer() { 53 | protected void initChannel(NioSocketChannel ch) throws Exception { 54 | ChannelPipeline pipeline = ch.pipeline(); 55 | pipeline.addLast(dataTransHandler); 56 | pipeline.addLast(new LoggingHandler(LogLevel.DEBUG)); 57 | } 58 | }); 59 | 60 | try { 61 | channelFuture = bootstrap.bind(port).sync(); 62 | } catch (InterruptedException e) { 63 | throw new RuntimeException(e); 64 | } 65 | 66 | channelFuture.addListener((future) -> { 67 | if (!future.isSuccess()) { 68 | future.cause().printStackTrace(); 69 | } 70 | 71 | }); 72 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 73 | boss.shutdownGracefully().syncUninterruptibly(); 74 | worker.shutdownGracefully().syncUninterruptibly(); 75 | })); 76 | } 77 | 78 | public void close() { 79 | if (channelFuture != null) { 80 | channelFuture.channel().close(); 81 | } 82 | } 83 | 84 | public int getPort() { 85 | return port; 86 | } 87 | 88 | public ChannelFuture getChannelFuture() { 89 | return channelFuture; 90 | } 91 | 92 | public EventLoopGroup getBoss() { 93 | return boss; 94 | } 95 | 96 | public EventLoopGroup getWorker() { 97 | return worker; 98 | } 99 | 100 | public DataTransHandler getDataTransHandler() { 101 | return dataTransHandler; 102 | } 103 | 104 | public Server getServer() { 105 | return server; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /proxy/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github 6 | wormhole 7 | 1.0.0-SNAPSHOT 8 | 9 | com.github 10 | proxy 11 | 1.0.0-SNAPSHOT 12 | Archetype - proxy 13 | http://maven.apache.org 14 | 15 | 16 | 17 | io.netty 18 | netty-all 19 | 20 | 21 | 22 | com.github.wormhole 23 | serialize 24 | 1.0.0-SNAPSHOT 25 | 26 | 27 | 28 | com.github.wormhole 29 | client 30 | 1.0.0-SNAPSHOT 31 | 32 | 33 | 34 | commons-io 35 | commons-io 36 | 2.11.0 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-assembly-plugin 45 | 3.0.0 46 | 47 | 48 | 49 | com.github.wormhole.proxy.Proxy 50 | 51 | 52 | 53 | jar-with-dependencies 54 | 55 | 56 | 57 | 58 | make-assembly 59 | package 60 | 61 | single 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 96 | 97 | -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/DataClient.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client; 2 | 3 | import io.netty.channel.Channel; 4 | 5 | import io.netty.channel.ChannelFuture; 6 | import io.netty.channel.ChannelPipeline; 7 | 8 | import com.github.wormhole.client.ack.AckHandler; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import lombok.Data; 12 | import lombok.ToString; 13 | 14 | public class DataClient extends Client{ 15 | private volatile DataClient directClient; 16 | 17 | private DataTransHandler dataTransHandler = new DataTransHandler(this); 18 | 19 | /** 20 | * 连接类型(1.连接到代理服务器, 2.连接到内网服务) 21 | */ 22 | private int connType; 23 | 24 | private String peerClientAddress; 25 | 26 | private DataClientPool dataClientPool; 27 | 28 | private AckHandler ackHandler; 29 | 30 | private Context context; 31 | 32 | public DataClient(String ip, Integer port, int connType, Context context, DataClientPool dataClientPool) { 33 | super(ip, port, context); 34 | this.connType = connType; 35 | this.dataClientPool = dataClientPool; 36 | this.context = context; 37 | } 38 | 39 | @Override 40 | public void initChannelPipeline(ChannelPipeline pipeline) { 41 | if (connType == 2) { 42 | this.ackHandler = new AckHandler(channel, context, context.id(), dataClientPool.getServiceKey(), peerClientAddress); 43 | pipeline.addLast(ackHandler); 44 | } 45 | pipeline.addLast(dataTransHandler); 46 | } 47 | 48 | @Override 49 | public ChannelFuture send(ByteBuf msg) { 50 | return channel.writeAndFlush(msg); 51 | } 52 | 53 | public void refresh(DataClient directClient) { 54 | this.directClient = directClient; 55 | } 56 | 57 | public void revert() { 58 | dataClientPool.revert(this); 59 | } 60 | 61 | public DataClient getDirectClient() { 62 | return directClient; 63 | } 64 | 65 | public int getConnType() { 66 | return connType; 67 | } 68 | 69 | public DataTransHandler getDataTransHandler() { 70 | return dataTransHandler; 71 | } 72 | 73 | // public void setAck(long num) { 74 | // channel.eventLoop().submit(() -> { 75 | // dataTransHandler.setAck(num); 76 | // }); 77 | // } 78 | 79 | public String getPeerClientAddress() { 80 | return peerClientAddress; 81 | } 82 | 83 | public void setDirectClient(DataClient directClient) { 84 | this.directClient = directClient; 85 | } 86 | 87 | public void setDataTransHandler(DataTransHandler dataTransHandler) { 88 | this.dataTransHandler = dataTransHandler; 89 | } 90 | 91 | public void setConnType(int connType) { 92 | this.connType = connType; 93 | } 94 | 95 | public void setPeerClientAddress(String peerClientAddress) { 96 | this.peerClientAddress = peerClientAddress; 97 | dataClientPool.setClientAssignedPeer(peerClientAddress, getId()); 98 | if (connType == 1) { 99 | return; 100 | } 101 | ackHandler.setPeerClientAddress(peerClientAddress); 102 | this.ackHandler.clear(); 103 | } 104 | 105 | public DataClientPool getDataClientPool() { 106 | return dataClientPool; 107 | } 108 | 109 | public void setDataClientPool(DataClientPool dataClientPool) { 110 | this.dataClientPool = dataClientPool; 111 | } 112 | 113 | public AckHandler getAckHandler() { 114 | return ackHandler; 115 | } 116 | 117 | public Context getContext() { 118 | return context; 119 | } 120 | 121 | @Override 122 | public String toString() { 123 | return "dataClient(" + connType + ":" + peerClientAddress + ")"; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.github 5 | wormhole 6 | 1.0.0-SNAPSHOT 7 | pom 8 | wormhole 9 | 内网穿透工具 10 | 11 | server 12 | serialize 13 | proxy 14 | client 15 | common 16 | 17 | 18 | 1.18.24 19 | 1.2.59 20 | 11 21 | 11 22 | 21.3.0 23 | 24 | 25 | 26 | native 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-maven-plugin 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.apache.commons 43 | commons-lang3 44 | 3.8 45 | 46 | 47 | org.graalvm.sdk 48 | graal-sdk 49 | 21.0.0 50 | provided 51 | 52 | 53 | 54 | com.alibaba 55 | fastjson 56 | ${fastjson.version} 57 | 58 | 59 | 60 | org.projectlombok 61 | lombok 62 | ${lombok.version} 63 | 64 | 65 | 66 | 67 | org.slf4j 68 | slf4j-api 69 | 1.7.12 70 | 71 | 72 | 73 | 74 | org.slf4j 75 | slf4j-api 76 | 1.7.12 77 | 78 | 79 | ch.qos.logback 80 | logback-core 81 | 1.1.1 82 | 83 | 84 | 85 | ch.qos.logback 86 | logback-classic 87 | 1.1.1 88 | 89 | 90 | 91 | 92 | 93 | 94 | io.netty 95 | netty-all 96 | 4.1.48.Final 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/DataClientPool.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client; 2 | 3 | import javax.xml.crypto.Data; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Optional; 7 | import java.util.Queue; 8 | import java.util.Map.Entry; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | import java.util.concurrent.LinkedBlockingQueue; 11 | 12 | public class DataClientPool { 13 | private String ip; 14 | 15 | private Integer port; 16 | 17 | /** 18 | * 连接类型(1.连接到代理服务器, 2.连接到内网服务) 19 | */ 20 | private int connType; 21 | 22 | private Map assignedDataClients = new ConcurrentHashMap<>(); 23 | 24 | private Map dataClientAssignedPeerMap = new ConcurrentHashMap<>(); 25 | 26 | private Context context; 27 | 28 | private String serviceKey; 29 | 30 | public DataClientPool(String ip, Integer port, int connType, Context context) { 31 | this.ip = ip; 32 | this.port = port; 33 | this.connType = connType; 34 | this.context = context; 35 | } 36 | private Queue dataClientQueue = new LinkedBlockingQueue<>(); 37 | 38 | public void init() { 39 | for (int i = 0; i < 1; i++) { 40 | DataClient dataClient = new DataClient(ip, port, connType, context, this); 41 | try { 42 | dataClient.connect(); 43 | dataClientQueue.add(dataClient); 44 | } catch (Exception e) { 45 | // TODO Auto-generated catch block 46 | e.printStackTrace(); 47 | } 48 | } 49 | } 50 | 51 | public DataClient take() { 52 | DataClient client = dataClientQueue.poll(); 53 | if (client == null) { 54 | for (;;) { 55 | DataClient dataClient = new DataClient(ip, port, connType, context, this); 56 | try { 57 | dataClient.connect(); 58 | client = dataClient; 59 | if (client != null) { 60 | assignedDataClients.put(client.getId(), client); 61 | return client; 62 | } 63 | } catch (Exception e) { 64 | } 65 | } 66 | } 67 | if (client != null) { 68 | assignedDataClients.put(client.getId(), client); 69 | } 70 | return client; 71 | } 72 | 73 | public void revert(DataClient dataClient) { 74 | dataClientQueue.add(dataClient); 75 | assignedDataClients.remove(dataClient.getId()); 76 | Optional> findFirst = dataClientAssignedPeerMap.entrySet().stream().filter(e -> e.getValue().equals(dataClient.getId())).findFirst(); 77 | findFirst.ifPresent(e -> dataClientAssignedPeerMap.remove(e.getKey())); 78 | } 79 | 80 | public DataClient getAssignedDataClient(String id) { 81 | return assignedDataClients.get(id); 82 | } 83 | 84 | public String getIp() { 85 | return ip; 86 | } 87 | 88 | public Integer getPort() { 89 | return port; 90 | } 91 | 92 | public int getConnType() { 93 | return connType; 94 | } 95 | 96 | public Map getAssignedDataClients() { 97 | return assignedDataClients; 98 | } 99 | 100 | public Context getContext() { 101 | return context; 102 | } 103 | 104 | public String getServiceKey() { 105 | return serviceKey; 106 | } 107 | 108 | public Queue getDataClientQueue() { 109 | return dataClientQueue; 110 | } 111 | 112 | public void setServiceKey(String serviceKey) { 113 | this.serviceKey = serviceKey; 114 | } 115 | 116 | public void setClientAssignedPeer(String peerAddress, String id) { 117 | this.dataClientAssignedPeerMap.put(peerAddress, id); 118 | } 119 | 120 | public Map getDataClientAssignedPeerMap() { 121 | return dataClientAssignedPeerMap; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /client/src/main/java/com/github/wormhole/client/Client.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.client; 2 | 3 | import com.github.wormhole.common.utils.IDUtil; 4 | import com.github.wormhole.common.utils.NetworkUtil; 5 | 6 | import io.netty.bootstrap.Bootstrap; 7 | import io.netty.channel.Channel; 8 | import io.netty.channel.ChannelFuture; 9 | import io.netty.channel.ChannelInitializer; 10 | import io.netty.channel.ChannelOption; 11 | import io.netty.channel.ChannelPipeline; 12 | import io.netty.channel.nio.NioEventLoopGroup; 13 | import io.netty.channel.socket.SocketChannel; 14 | import io.netty.channel.socket.nio.NioSocketChannel; 15 | import io.netty.handler.logging.LogLevel; 16 | import io.netty.handler.logging.LoggingHandler; 17 | import lombok.extern.slf4j.Slf4j; 18 | 19 | @Slf4j 20 | public abstract class Client { 21 | private String id; 22 | 23 | private Bootstrap clientBootstrap; 24 | 25 | private NioEventLoopGroup clientGroup; 26 | 27 | private String ip; 28 | 29 | private Integer port; 30 | 31 | protected Channel channel; 32 | 33 | private Context context; 34 | 35 | public Client(String ip, Integer port, Context context) { 36 | this.ip = ip; 37 | this.port = port; 38 | this.context = context; 39 | this.clientBootstrap = new Bootstrap(); 40 | this.clientGroup = new NioEventLoopGroup(); 41 | clientBootstrap.group(clientGroup) 42 | .option(ChannelOption.AUTO_READ, true) 43 | .channel(NioSocketChannel.class) 44 | .option(ChannelOption.TCP_NODELAY, true) 45 | .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) 46 | .handler(new ChannelInitializer() { 47 | //初始化时将handler设置到ChannelPipeline 48 | @Override 49 | public void initChannel(SocketChannel ch) { 50 | initChannelPipeline(ch.pipeline()); 51 | ch.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG)); 52 | } 53 | }); 54 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 55 | channel.close(); 56 | clientGroup.shutdownGracefully().syncUninterruptibly(); 57 | })); 58 | } 59 | 60 | public abstract void initChannelPipeline(ChannelPipeline pipeline); 61 | 62 | public abstract ChannelFuture send(T msg); 63 | 64 | public Channel connect() throws Exception { 65 | /** 66 | * 最多尝试5次和服务端连接 67 | */ 68 | this.channel = doConnect(ip, port, 5); 69 | this.id = this.channel.id().toString(); 70 | return channel; 71 | } 72 | 73 | private Channel doConnect(String ip, int port, int retry) throws InterruptedException { 74 | ChannelFuture future = null; 75 | for (int i = retry; i > 0; i--) { 76 | try { 77 | future = clientBootstrap.connect(ip, port).sync(); 78 | } catch (InterruptedException e) { 79 | log.debug("debug:connect business server fail, client " + NetworkUtil.getLocalHost() + ", server " + ip + ":" + port); 80 | } 81 | if (future.isSuccess()) { 82 | return future.channel(); 83 | } 84 | Thread.sleep(5000); 85 | } 86 | throw new RuntimeException("connect business server fail, client " + NetworkUtil.getLocalHost() + ", server " + ip + ":" + port); 87 | } 88 | 89 | public void disconnect() throws Exception { 90 | channel.close().sync(); 91 | } 92 | 93 | public void reconnect() throws Exception { 94 | disconnect(); 95 | connect(); 96 | } 97 | 98 | public void shutdown() throws Exception { 99 | disconnect(); 100 | clientGroup.shutdownGracefully().syncUninterruptibly(); 101 | } 102 | 103 | public static org.slf4j.Logger getLog() { 104 | return log; 105 | } 106 | 107 | public Bootstrap getClientBootstrap() { 108 | return clientBootstrap; 109 | } 110 | 111 | public NioEventLoopGroup getClientGroup() { 112 | return clientGroup; 113 | } 114 | 115 | public String getIp() { 116 | return ip; 117 | } 118 | 119 | public Integer getPort() { 120 | return port; 121 | } 122 | 123 | public Channel getChannel() { 124 | return channel; 125 | } 126 | 127 | public String getId() { 128 | return channel.localAddress().toString() + "-" + channel.remoteAddress().toString(); 129 | } 130 | 131 | public Context getContext() { 132 | return context; 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/ProxyServer.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | 9 | import com.github.wormhole.client.DataClientPool; 10 | import com.github.wormhole.client.ack.AckHandler; 11 | import com.github.wormhole.common.config.ProxyServiceConfig; 12 | import com.github.wormhole.common.config.ProxyServiceConfig.ServiceConfig; 13 | import com.github.wormhole.common.utils.RetryUtil; 14 | import com.github.wormhole.serialize.Frame; 15 | import com.github.wormhole.serialize.FrameDecoder; 16 | import com.github.wormhole.serialize.FrameEncoder; 17 | import com.github.wormhole.serialize.PackageDecoder; 18 | import com.github.wormhole.serialize.PackageEncoder; 19 | import com.github.wormhole.server.processor.SignalChannelContext; 20 | 21 | import io.netty.bootstrap.ServerBootstrap; 22 | import io.netty.channel.Channel; 23 | import io.netty.channel.ChannelFuture; 24 | import io.netty.channel.ChannelInitializer; 25 | import io.netty.channel.ChannelOption; 26 | import io.netty.channel.ChannelPipeline; 27 | import io.netty.channel.EventLoopGroup; 28 | import io.netty.channel.nio.NioEventLoopGroup; 29 | import io.netty.channel.socket.nio.NioServerSocketChannel; 30 | import io.netty.channel.socket.nio.NioSocketChannel; 31 | import io.netty.handler.logging.LogLevel; 32 | import io.netty.handler.logging.LoggingHandler; 33 | 34 | public class ProxyServer { 35 | private ChannelFuture channelFuture; 36 | 37 | private EventLoopGroup boss; 38 | private EventLoopGroup worker; 39 | 40 | private ProxyServiceConfig config; 41 | private Channel proxyChannel; 42 | private String proxyId; 43 | private Map portServiceMap = new HashMap<>(); 44 | 45 | private List serverChannels = new ArrayList<>(); 46 | 47 | private ClientHandler clientHandler; 48 | 49 | private Map ackHandlerMap = new ConcurrentHashMap<>(); 50 | 51 | private Server server; 52 | 53 | public ProxyServer(EventLoopGroup boss, EventLoopGroup worker, String proxyId, ProxyServiceConfig config, Channel channel, Server server) { 54 | this.boss = boss; 55 | this.worker = worker; 56 | this.config = config; 57 | this.proxyChannel = channel; 58 | this.proxyId = proxyId; 59 | this.server = server; 60 | this.clientHandler = new ClientHandler(this); 61 | } 62 | 63 | public void open() throws Exception { 64 | ServerBootstrap bootstrap = new ServerBootstrap(); 65 | 66 | bootstrap.group(boss, worker) 67 | .option(ChannelOption.AUTO_READ, true) 68 | .handler(new LoggingHandler(LogLevel.DEBUG)) 69 | .channel(NioServerSocketChannel.class) 70 | .childHandler(new ChannelInitializer() { 71 | protected void initChannel(NioSocketChannel ch) throws Exception { 72 | ChannelPipeline pipeline = ch.pipeline(); 73 | int port = ch.localAddress().getPort(); 74 | String string = portServiceMap.get(port); 75 | AckHandler ackHandler = new AckHandler(ch, new SignalChannelContext(proxyChannel), proxyId, string, ch.remoteAddress().toString()); 76 | ackHandlerMap.put(ch, ackHandler); 77 | pipeline.addLast(ackHandler); 78 | pipeline.addLast(clientHandler); 79 | pipeline.addLast(new LoggingHandler(LogLevel.DEBUG)); 80 | } 81 | }); 82 | Map map = config.getMap(); 83 | for (Map.Entry entry : map.entrySet()) { 84 | portServiceMap.put(entry.getValue().getMappingPort(), entry.getKey()); 85 | Channel channel = bootstrap.bind(entry.getValue().getMappingPort()).sync().channel(); 86 | serverChannels.add(channel); 87 | } 88 | 89 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 90 | serverChannels.forEach(Channel::close); 91 | boss.shutdownGracefully().syncUninterruptibly(); 92 | worker.shutdownGracefully().syncUninterruptibly(); 93 | })); 94 | } 95 | 96 | public void close() { 97 | if (channelFuture != null) { 98 | channelFuture.channel().close(); 99 | } 100 | } 101 | 102 | public void sendToProxy(Frame frame) { 103 | RetryUtil.write(proxyChannel, frame); 104 | } 105 | 106 | public String getServiceKey(Integer port) { 107 | return portServiceMap.get(port); 108 | } 109 | 110 | public ChannelFuture getChannelFuture() { 111 | return channelFuture; 112 | } 113 | 114 | public EventLoopGroup getBoss() { 115 | return boss; 116 | } 117 | 118 | public EventLoopGroup getWorker() { 119 | return worker; 120 | } 121 | 122 | public ProxyServiceConfig getConfig() { 123 | return config; 124 | } 125 | 126 | public Channel getProxyChannel() { 127 | return proxyChannel; 128 | } 129 | 130 | public String getProxyId() { 131 | return proxyId; 132 | } 133 | 134 | public Map getPortServiceMap() { 135 | return portServiceMap; 136 | } 137 | 138 | public List getServerChannels() { 139 | return serverChannels; 140 | } 141 | 142 | public ClientHandler getClientHandler() { 143 | return clientHandler; 144 | } 145 | 146 | public void refuse(String realClientAddress) { 147 | clientHandler.refuse(realClientAddress); 148 | } 149 | 150 | public Server getServer() { 151 | return server; 152 | } 153 | 154 | public Map getAckHandlerMap() { 155 | return ackHandlerMap; 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /proxy/src/main/java/com/github/wormhole/proxy/Proxy.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.proxy; 2 | 3 | import java.net.InetSocketAddress; 4 | import java.nio.charset.StandardCharsets; 5 | import java.util.Map; 6 | 7 | import com.alibaba.fastjson.JSON; 8 | import com.alibaba.fastjson.JSONObject; 9 | import com.github.wormhole.client.Context; 10 | import com.github.wormhole.client.DataClientPool; 11 | import com.github.wormhole.client.SignalClient; 12 | import com.github.wormhole.common.config.ProxyServiceConfig; 13 | import com.github.wormhole.common.utils.ConfigLoader; 14 | import com.github.wormhole.common.utils.Connection; 15 | import com.github.wormhole.common.utils.IDUtil; 16 | import com.github.wormhole.common.utils.RetryUtil; 17 | import com.github.wormhole.proxy.processor.DataChannelProcessor; 18 | import com.github.wormhole.proxy.processor.DataTransAckProcessor; 19 | import com.github.wormhole.proxy.processor.DisconnectClientProcessor; 20 | import com.github.wormhole.proxy.processor.ProxyRegisterAckProcessor; 21 | import com.github.wormhole.serialize.Frame; 22 | 23 | import io.netty.buffer.ByteBuf; 24 | import io.netty.buffer.PooledByteBufAllocator; 25 | import io.netty.channel.Channel; 26 | import io.netty.channel.ChannelFuture; 27 | import lombok.extern.slf4j.Slf4j; 28 | import org.apache.commons.lang3.StringUtils; 29 | 30 | @Slf4j 31 | public class Proxy implements Context{ 32 | private static Proxy proxy; 33 | 34 | private String serverHost; 35 | 36 | private Integer serverPort; 37 | 38 | private ProxyServiceConfig config; 39 | 40 | private Channel channel; 41 | 42 | private SignalClient signalClient; 43 | 44 | private DataClientPool dataClientPool; 45 | 46 | private String proxyId; 47 | 48 | private DataTransAckProcessor dataTransAckProcessor; 49 | 50 | private DataChannelProcessor dataChannelProcessor; 51 | 52 | public Proxy(String configPath) throws Exception { 53 | if (StringUtils.isEmpty(configPath)) { 54 | throw new RuntimeException("must exist config file"); 55 | } 56 | this.config = ConfigLoader.load(configPath); 57 | this.serverHost = config.getServerHost(); 58 | this.serverPort = config.getServerPort(); 59 | this.dataClientPool = new DataClientPool(serverHost, config.getDataTransPort(), 1, this); 60 | this.signalClient = new SignalClient(serverHost, serverPort, this); 61 | } 62 | 63 | public void start() throws Exception { 64 | this.dataTransAckProcessor = new DataTransAckProcessor(this); 65 | this.dataChannelProcessor = new DataChannelProcessor(this); 66 | signalClient.register(dataChannelProcessor) 67 | .register(dataTransAckProcessor) 68 | .register(new DisconnectClientProcessor(this)) 69 | .register(new ProxyRegisterAckProcessor(this)); 70 | channel = signalClient.connect(); 71 | online(channel); 72 | dataClientPool.init(); 73 | } 74 | 75 | private void online(Channel channel) { 76 | String string = ConfigLoader.serialize(config); 77 | ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); 78 | buffer.writeCharSequence(string, StandardCharsets.UTF_8); 79 | Frame frame = new Frame(); 80 | frame.setOpCode(0x1); 81 | frame.setPayload(buffer); 82 | frame.setRequestId(IDUtil.genRequestId()); 83 | RetryUtil.writeLimitTime(new Connection() { 84 | @Override 85 | public ChannelFuture write(Object msg) { 86 | log.info("内网代理发送给服务器建立连接请求{}", msg); 87 | return channel.writeAndFlush(msg); 88 | } 89 | }, frame, 3); 90 | } 91 | 92 | public static void main(String[] args) throws Exception { 93 | String path = null; 94 | if (args != null && args.length > 0) { 95 | for (int i = 0; i < args.length; i++) { 96 | if (StringUtils.isNotEmpty(args[i]) && args[i].equals("--configPath")) { 97 | if (i + 1 < args.length) { 98 | String arg = args[i + 1]; 99 | if (StringUtils.isNotEmpty(arg)) { 100 | path = arg; 101 | } 102 | } 103 | } 104 | } 105 | if (StringUtils.isNotEmpty(path)) { 106 | proxy = new Proxy(path); 107 | proxy.start(); 108 | } 109 | } 110 | } 111 | 112 | public String getServerHost() { 113 | return serverHost; 114 | } 115 | 116 | public Integer getServerPort() { 117 | return serverPort; 118 | } 119 | 120 | public ProxyServiceConfig getConfig() { 121 | return config; 122 | } 123 | 124 | public Channel getChannel() { 125 | return channel; 126 | } 127 | 128 | public SignalClient getSignalClient() { 129 | return signalClient; 130 | } 131 | 132 | public DataClientPool getDataClientPool() { 133 | return dataClientPool; 134 | } 135 | 136 | public String getProxyId() { 137 | return proxyId; 138 | } 139 | 140 | @Override 141 | public void write(Object msg) { 142 | signalClient.send((Frame) msg); 143 | } 144 | 145 | @Override 146 | public Object read() { 147 | // TODO Auto-generated method stub 148 | throw new UnsupportedOperationException("Unimplemented method 'read'"); 149 | } 150 | 151 | @Override 152 | public String id() { 153 | return proxyId; 154 | } 155 | 156 | public void setProxyId(String id) { 157 | this.proxyId = id; 158 | } 159 | 160 | public static Proxy getProxy() { 161 | return proxy; 162 | } 163 | 164 | public DataTransAckProcessor getDataTransAckProcessor() { 165 | return dataTransAckProcessor; 166 | } 167 | 168 | public DataChannelProcessor getDataChannelProcessor() { 169 | return dataChannelProcessor; 170 | } 171 | 172 | 173 | } 174 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/ClientHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server; 2 | 3 | import java.net.InetSocketAddress; 4 | import java.nio.charset.Charset; 5 | import java.util.Map; 6 | import java.util.concurrent.ConcurrentHashMap; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import com.github.wormhole.client.DataClient; 10 | import com.github.wormhole.client.ack.AckHandler; 11 | import com.github.wormhole.common.utils.Connection; 12 | import com.github.wormhole.common.utils.IDUtil; 13 | import com.github.wormhole.common.utils.RetryUtil; 14 | import com.github.wormhole.serialize.Frame; 15 | 16 | import io.netty.buffer.ByteBuf; 17 | import io.netty.buffer.PooledByteBufAllocator; 18 | import io.netty.channel.Channel; 19 | import io.netty.channel.ChannelFuture; 20 | import io.netty.channel.ChannelHandlerContext; 21 | import io.netty.channel.ChannelInboundHandlerAdapter; 22 | import io.netty.channel.ChannelPromise; 23 | import io.netty.channel.ChannelHandler.Sharable; 24 | import lombok.extern.slf4j.Slf4j; 25 | 26 | @Sharable 27 | @Slf4j 28 | public class ClientHandler extends ChannelInboundHandlerAdapter { 29 | private ProxyServer proxyServer; 30 | 31 | private Map resMap = new ConcurrentHashMap<>(); 32 | 33 | private Map dataClientMap = new ConcurrentHashMap<>(); 34 | 35 | private Map clientChannelMap = new ConcurrentHashMap<>(); 36 | 37 | private Map dataChannelMap = new ConcurrentHashMap<>(); 38 | 39 | public ClientHandler(ProxyServer proxyServer) { 40 | this.proxyServer = proxyServer; 41 | } 42 | 43 | @Override 44 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 45 | Frame frame = new Frame(); 46 | frame.setOpCode(0x2); 47 | frame.setRealClientAddress(ctx.channel().remoteAddress().toString()); 48 | frame.setRequestId(IDUtil.genRequestId()); 49 | InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress(); 50 | int port = localAddress.getPort(); 51 | frame.setServiceKey(proxyServer.getServiceKey(port)); 52 | resMap.put(frame.getRealClientAddress(), ctx.channel().newPromise()); 53 | clientChannelMap.put(frame.getRealClientAddress(), ctx.channel()); 54 | proxyServer.sendToProxy(frame); 55 | log.info("客户端连接{}", frame); 56 | ctx.fireChannelActive(); 57 | } 58 | 59 | @Override 60 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 61 | log.info("收到客户端数据{}", ctx.channel().remoteAddress().toString()); 62 | String string = ctx.channel().remoteAddress().toString(); 63 | ChannelFuture channelFuture = resMap.get(string); 64 | if (channelFuture != null) { 65 | channelFuture.addListener(f -> { 66 | if (f.isSuccess()) { 67 | Channel channel = dataChannelMap.get(ctx.channel()); 68 | if (channel != null && channel.isActive()) { 69 | log.info("发送给代理{}", channel); 70 | channel.writeAndFlush(msg).addListener(f1 -> { 71 | resMap.remove(string); 72 | }); 73 | } 74 | } 75 | }); 76 | } 77 | } 78 | 79 | @Override 80 | public void channelInactive(ChannelHandlerContext ctx) throws Exception { 81 | ctx.fireChannelInactive(); 82 | } 83 | 84 | @Override 85 | public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { 86 | ctx.fireChannelReadComplete(); 87 | log.info("ReadComplete{}", ctx.channel().remoteAddress().toString()); 88 | ctx.fireChannelReadComplete(); 89 | String address = ctx.channel().remoteAddress().toString(); 90 | clear(address); 91 | 92 | proxyServer.getServer().getDataTransServer().getDataTransHandler().clear(address); 93 | 94 | Frame frame = new Frame(); 95 | frame.setOpCode(0x4); 96 | frame.setRealClientAddress(address); 97 | frame.setRequestId(IDUtil.genRequestId()); 98 | InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress(); 99 | int port = localAddress.getPort(); 100 | frame.setServiceKey(proxyServer.getServiceKey(port)); 101 | 102 | AckHandler ackHandler = proxyServer.getAckHandlerMap().get(ctx.channel()); 103 | if (ackHandler != null) { 104 | if (ackHandler.isAckComplate()) { 105 | log.info("数据已全部发给内网服务{}", frame); 106 | proxyServer.sendToProxy(frame); 107 | return; 108 | } 109 | ChannelPromise newPromise = ctx.channel().newPromise(); 110 | ackHandler.setPromise(newPromise); 111 | newPromise.addListener(f -> { 112 | log.info("数据已全部发给内网服务{}", frame); 113 | proxyServer.sendToProxy(frame); 114 | }); 115 | } 116 | } 117 | 118 | public void success(String id) { 119 | ChannelPromise remove = resMap.get(id); 120 | if (remove != null) { 121 | remove.setSuccess(); 122 | } 123 | } 124 | 125 | public void fail(String address) { 126 | ChannelPromise remove = resMap.get(address); 127 | if (remove != null) { 128 | remove.setFailure(null); 129 | } 130 | refuse(address); 131 | } 132 | 133 | public ProxyServer getProxyServer() { 134 | return proxyServer; 135 | } 136 | 137 | public Map getResMap() { 138 | return resMap; 139 | } 140 | 141 | public Map getDataClientMap() { 142 | return dataClientMap; 143 | } 144 | 145 | public Map getClientChannelMap() { 146 | return clientChannelMap; 147 | } 148 | 149 | public void refuse(String realClientAddress) { 150 | Channel channel = clientChannelMap.remove(realClientAddress); 151 | if (channel != null && channel.isActive()) { 152 | channel.close(); 153 | } 154 | } 155 | 156 | public Map getDataChannelMap() { 157 | return dataChannelMap; 158 | } 159 | 160 | public void clear(String clientAddress) { 161 | 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /server/src/main/java/com/github/wormhole/server/Server.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.server; 2 | 3 | import com.github.wormhole.serialize.FrameEncoder; 4 | import com.github.wormhole.serialize.PackageDecoder; 5 | import com.github.wormhole.serialize.PackageEncoder; 6 | import com.github.wormhole.server.processor.BuildDataChannelProcessor; 7 | import com.github.wormhole.server.processor.DisconnectClientPocessor; 8 | import com.github.wormhole.server.processor.ProxyRegisterProcessor; 9 | 10 | import java.util.Map; 11 | import java.util.Set; 12 | import java.util.UUID; 13 | import java.util.concurrent.ConcurrentHashMap; 14 | 15 | import org.apache.commons.lang3.StringUtils; 16 | 17 | import com.github.wormhole.serialize.FrameDecoder; 18 | 19 | import io.netty.bootstrap.ServerBootstrap; 20 | import io.netty.channel.Channel; 21 | import io.netty.channel.ChannelFuture; 22 | import io.netty.channel.ChannelInitializer; 23 | import io.netty.channel.ChannelOption; 24 | import io.netty.channel.ChannelPipeline; 25 | import io.netty.channel.EventLoopGroup; 26 | import io.netty.channel.nio.NioEventLoopGroup; 27 | import io.netty.channel.socket.nio.NioServerSocketChannel; 28 | import io.netty.channel.socket.nio.NioSocketChannel; 29 | import io.netty.handler.logging.LogLevel; 30 | import io.netty.handler.logging.LoggingHandler; 31 | 32 | import com.github.wormhole.client.SignalHandler; 33 | import com.github.wormhole.common.config.ProxyServiceConfig; 34 | 35 | public class Server { 36 | private int port; 37 | 38 | private int dataTransPort; 39 | 40 | private ChannelFuture channelFuture; 41 | 42 | private EventLoopGroup boss = new NioEventLoopGroup(); 43 | private EventLoopGroup worker = new NioEventLoopGroup(); 44 | 45 | private SignalHandler signalHandler; 46 | 47 | private Map proxyServerMap = new ConcurrentHashMap<>(); 48 | 49 | private DataTransServer dataTransServer; 50 | 51 | private Map proxyDataChannelMap = new ConcurrentHashMap<>(); 52 | 53 | private Map proxyIdChannelMap = new ConcurrentHashMap<>(); 54 | 55 | public Server(int port, int dataTransPort) { 56 | this.port = port; 57 | this.dataTransPort = dataTransPort; 58 | } 59 | 60 | public void open() { 61 | buildSignalHandler(); 62 | dataTransServer = new DataTransServer(dataTransPort, boss, worker, this); 63 | dataTransServer.open(); 64 | 65 | ServerBootstrap bootstrap = new ServerBootstrap(); 66 | bootstrap.group(boss, worker) 67 | .option(ChannelOption.AUTO_READ, true) 68 | .channel(NioServerSocketChannel.class) 69 | .handler(new LoggingHandler(LogLevel.DEBUG)) 70 | .childHandler(new ChannelInitializer() { 71 | protected void initChannel(NioSocketChannel ch) throws Exception { 72 | ChannelPipeline pipeline = ch.pipeline(); 73 | pipeline.addLast(new FrameDecoder()); 74 | pipeline.addLast(new FrameEncoder()); 75 | pipeline.addLast(new PackageDecoder()); 76 | pipeline.addLast(new PackageEncoder()); 77 | pipeline.addLast(signalHandler); 78 | pipeline.addLast(new LoggingHandler(LogLevel.DEBUG)); 79 | } 80 | }); 81 | 82 | try { 83 | channelFuture = bootstrap.bind(port).sync(); 84 | } catch (InterruptedException e) { 85 | throw new RuntimeException(e); 86 | } 87 | 88 | channelFuture.addListener((future) -> { 89 | if (!future.isSuccess()) { 90 | future.cause().printStackTrace(); 91 | } 92 | 93 | }); 94 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 95 | boss.shutdownGracefully().syncUninterruptibly(); 96 | worker.shutdownGracefully().syncUninterruptibly(); 97 | })); 98 | } 99 | 100 | public String buildProxyServer(ProxyServiceConfig config, Channel channel) throws Exception { 101 | String proxyId = UUID.randomUUID().toString(); 102 | ProxyServer proxyServer = new ProxyServer(boss, worker, proxyId, config, channel, this); 103 | proxyServer.open(); 104 | proxyServerMap.put(proxyId, proxyServer); 105 | return proxyId; 106 | } 107 | 108 | private void buildSignalHandler() { 109 | signalHandler = new SignalHandler(); 110 | signalHandler.register(new ProxyRegisterProcessor(this)) 111 | .register(new BuildDataChannelProcessor(this)) 112 | .register(new DisconnectClientPocessor(this)); 113 | } 114 | 115 | public void close() { 116 | if (channelFuture != null) { 117 | channelFuture.channel().close(); 118 | } 119 | } 120 | 121 | public static void main(String[] args) { 122 | String port = null; 123 | Integer dataTransPort = null; 124 | if (args != null && args.length > 0) { 125 | for (int i = 0; i < args.length; i++) { 126 | if (StringUtils.isNotEmpty(args[i]) && args[i].equals("--port")) { 127 | if (i + 1 < args.length) { 128 | String arg = args[i + 1]; 129 | if (StringUtils.isNotEmpty(arg)) { 130 | port = arg; 131 | } 132 | } 133 | } else if (StringUtils.isNotEmpty(args[i]) && args[i].equals("--dataTransPort")) { 134 | if (i + 1 < args.length) { 135 | String arg = args[i + 1]; 136 | if (StringUtils.isNotEmpty(arg)) { 137 | dataTransPort = Integer.parseInt(arg); 138 | } 139 | } 140 | } 141 | } 142 | if (port != null && dataTransPort != null) { 143 | new Server(Integer.parseInt(port), dataTransPort).open(); 144 | } 145 | } 146 | } 147 | 148 | public int getPort() { 149 | return port; 150 | } 151 | 152 | public int getDataTransPort() { 153 | return dataTransPort; 154 | } 155 | 156 | public ChannelFuture getChannelFuture() { 157 | return channelFuture; 158 | } 159 | 160 | public EventLoopGroup getBoss() { 161 | return boss; 162 | } 163 | 164 | public EventLoopGroup getWorker() { 165 | return worker; 166 | } 167 | 168 | public SignalHandler getSignalHandler() { 169 | return signalHandler; 170 | } 171 | 172 | public ProxyServer getProxyServer(String proxyId) { 173 | return proxyServerMap.get(proxyId); 174 | } 175 | 176 | public DataTransServer getDataTransServer() { 177 | return dataTransServer; 178 | } 179 | 180 | public Map getProxyServerMap() { 181 | return proxyServerMap; 182 | } 183 | 184 | public Map getDataChannelProxyIdMap() { 185 | return proxyDataChannelMap; 186 | } 187 | 188 | public Map getProxyIdChannelMap() { 189 | return proxyIdChannelMap; 190 | } 191 | 192 | 193 | } 194 | -------------------------------------------------------------------------------- /common/src/main/java/com/github/wormhole/common/utils/NetworkUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.wormhole.common.utils; 2 | 3 | 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.PooledByteBufAllocator; 6 | import io.netty.buffer.UnpooledByteBufAllocator; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.apache.commons.lang3.StringUtils; 9 | 10 | import java.io.IOException; 11 | import java.net.*; 12 | import java.util.*; 13 | import java.util.regex.Pattern; 14 | 15 | import static java.util.Collections.emptyList; 16 | 17 | @Slf4j 18 | public class NetworkUtil { 19 | private static volatile String HOST_ADDRESS; 20 | private static final String LOCALHOST_VALUE = "127.0.0.1"; 21 | private static volatile InetAddress LOCAL_ADDRESS = null; 22 | private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$"); 23 | private static final String ANYHOST_VALUE = "0.0.0.0"; 24 | 25 | private static final String PREFERRED_NETWORK_INTERFACE = "network.interface.preferred"; 26 | 27 | private static final String IGNORED_NETWORK_INTERFACE_REGEX = "network.interface.ignored"; 28 | 29 | /** 30 | * 获取本机 IP 地址 31 | * @return 本机 IP 地址 32 | */ 33 | public static String getLocalHost() { 34 | if (HOST_ADDRESS != null) { 35 | return HOST_ADDRESS; 36 | } 37 | 38 | InetAddress address = getLocalAddress(); 39 | if (address != null) { 40 | return HOST_ADDRESS = address.getHostAddress(); 41 | } 42 | return LOCALHOST_VALUE; 43 | } 44 | 45 | /** 46 | * Find first valid IP from local network card 47 | * 48 | * @return first valid local IP 49 | */ 50 | public static InetAddress getLocalAddress() { 51 | if (LOCAL_ADDRESS != null) { 52 | return LOCAL_ADDRESS; 53 | } 54 | InetAddress localAddress = getLocalAddress0(); 55 | LOCAL_ADDRESS = localAddress; 56 | return localAddress; 57 | } 58 | private static InetAddress getLocalAddress0() { 59 | InetAddress localAddress = null; 60 | 61 | // @since 2.7.6, choose the {@link NetworkInterface} first 62 | try { 63 | NetworkInterface networkInterface = findNetworkInterface(); 64 | Enumeration addresses = networkInterface.getInetAddresses(); 65 | while (addresses.hasMoreElements()) { 66 | Optional addressOp = toValidAddress(addresses.nextElement()); 67 | if (addressOp.isPresent()) { 68 | try { 69 | if (addressOp.get().isReachable(100)) { 70 | return addressOp.get(); 71 | } 72 | } catch (IOException e) { 73 | // ignore 74 | } 75 | } 76 | } 77 | } catch (Throwable e) { 78 | log.warn("[Net] getLocalAddress0 failed.", e); 79 | } 80 | 81 | try { 82 | localAddress = InetAddress.getLocalHost(); 83 | Optional addressOp = toValidAddress(localAddress); 84 | if (addressOp.isPresent()) { 85 | return addressOp.get(); 86 | } 87 | } catch (Throwable e) { 88 | log.warn("[Net] getLocalAddress0 failed.", e); 89 | } 90 | 91 | 92 | return localAddress; 93 | } 94 | 95 | /** 96 | * Get the suitable {@link NetworkInterface} 97 | * 98 | * @return If no {@link NetworkInterface} is available , return null 99 | * @since 2.7.6 100 | */ 101 | public static NetworkInterface findNetworkInterface() { 102 | 103 | List validNetworkInterfaces = emptyList(); 104 | try { 105 | validNetworkInterfaces = getValidNetworkInterfaces(); 106 | } catch (Throwable e) { 107 | log.warn("[Net] findNetworkInterface failed", e); 108 | } 109 | 110 | NetworkInterface result = null; 111 | 112 | // Try to find the preferred one 113 | for (NetworkInterface networkInterface : validNetworkInterfaces) { 114 | if (isPreferredNetworkInterface(networkInterface)) { 115 | result = networkInterface; 116 | log.info("[Net] use preferred network interface: {}", networkInterface.getDisplayName()); 117 | break; 118 | } 119 | } 120 | 121 | if (result == null) { // If not found, try to get the first one 122 | for (NetworkInterface networkInterface : validNetworkInterfaces) { 123 | Enumeration addresses = networkInterface.getInetAddresses(); 124 | while (addresses.hasMoreElements()) { 125 | Optional addressOp = toValidAddress(addresses.nextElement()); 126 | if (addressOp.isPresent()) { 127 | try { 128 | if (addressOp.get().isReachable(100)) { 129 | result = networkInterface; 130 | break; 131 | } 132 | } catch (IOException e) { 133 | // ignore 134 | } 135 | } 136 | } 137 | } 138 | } 139 | 140 | if (result == null) { 141 | result = first(validNetworkInterfaces); 142 | } 143 | 144 | return result; 145 | } 146 | 147 | private static Optional toValidAddress(InetAddress address) { 148 | if (address instanceof Inet6Address) { 149 | Inet6Address v6Address = (Inet6Address) address; 150 | if (isPreferIPV6Address()) { 151 | return Optional.ofNullable(normalizeV6Address(v6Address)); 152 | } 153 | } 154 | if (isValidV4Address(address)) { 155 | return Optional.of(address); 156 | } 157 | return Optional.empty(); 158 | } 159 | 160 | /** 161 | * Check if an ipv6 address 162 | * 163 | * @return true if it is reachable 164 | */ 165 | static boolean isPreferIPV6Address() { 166 | return Boolean.getBoolean("java.net.preferIPv6Addresses"); 167 | } 168 | 169 | static boolean isValidV4Address(InetAddress address) { 170 | if (address == null || address.isLoopbackAddress()) { 171 | return false; 172 | } 173 | 174 | String name = address.getHostAddress(); 175 | return (name != null 176 | && IP_PATTERN.matcher(name).matches() 177 | && !ANYHOST_VALUE.equals(name) 178 | && !LOCALHOST_VALUE.equals(name)); 179 | } 180 | 181 | /** 182 | * normalize the ipv6 Address, convert scope name to scope id. 183 | * e.g. 184 | * convert 185 | * fe80:0:0:0:894:aeec:f37d:23e1%en0 186 | * to 187 | * fe80:0:0:0:894:aeec:f37d:23e1%5 188 | *

189 | * The %5 after ipv6 address is called scope id. 190 | * see java doc of {@link Inet6Address} for more details. 191 | * 192 | * @param address the input address 193 | * @return the normalized address, with scope id converted to int 194 | */ 195 | static InetAddress normalizeV6Address(Inet6Address address) { 196 | String addr = address.getHostAddress(); 197 | int i = addr.lastIndexOf('%'); 198 | if (i > 0) { 199 | try { 200 | return InetAddress.getByName(addr.substring(0, i) + '%' + address.getScopeId()); 201 | } catch (UnknownHostException e) { 202 | // ignore 203 | log.debug("Unknown IPV6 address: ", e); 204 | } 205 | } 206 | return address; 207 | } 208 | 209 | /** 210 | * Get the valid {@link NetworkInterface network interfaces} 211 | * 212 | * @return non-null 213 | * @throws SocketException SocketException if an I/O error occurs. 214 | * @since 2.7.6 215 | */ 216 | private static List getValidNetworkInterfaces() throws SocketException { 217 | List validNetworkInterfaces = new LinkedList<>(); 218 | Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); 219 | while (interfaces.hasMoreElements()) { 220 | NetworkInterface networkInterface = interfaces.nextElement(); 221 | if (ignoreNetworkInterface(networkInterface)) { // ignore 222 | continue; 223 | } 224 | // 根据用户 -D 参数忽略网卡 225 | if (ignoreInterfaceByConfig(networkInterface.getDisplayName())) { 226 | continue; 227 | } 228 | validNetworkInterfaces.add(networkInterface); 229 | } 230 | return validNetworkInterfaces; 231 | } 232 | 233 | /** 234 | * @param networkInterface {@link NetworkInterface} 235 | * @return if the specified {@link NetworkInterface} should be ignored, return true 236 | * @throws SocketException SocketException if an I/O error occurs. 237 | * @since 2.7.6 238 | */ 239 | private static boolean ignoreNetworkInterface(NetworkInterface networkInterface) throws SocketException { 240 | return networkInterface == null 241 | || networkInterface.isLoopback() 242 | || networkInterface.isVirtual() 243 | || !networkInterface.isUp(); 244 | } 245 | 246 | /** 247 | * Take the first element from the specified collection 248 | * 249 | * @param values the collection object 250 | * @param the type of element of collection 251 | * @return if found, return the first one, or null 252 | * @since 2.7.6 253 | */ 254 | public static T first(Collection values) { 255 | if (values == null || values.isEmpty()) { 256 | return null; 257 | } 258 | if (values instanceof List) { 259 | List list = (List) values; 260 | return list.get(0); 261 | } else { 262 | return values.iterator().next(); 263 | } 264 | } 265 | 266 | 267 | public static boolean isPreferredNetworkInterface(NetworkInterface networkInterface) { 268 | String preferredNetworkInterface = System.getProperty(PREFERRED_NETWORK_INTERFACE); 269 | return Objects.equals(networkInterface.getDisplayName(), preferredNetworkInterface); 270 | } 271 | 272 | static boolean ignoreInterfaceByConfig(String interfaceName) { 273 | String regex = System.getProperty(IGNORED_NETWORK_INTERFACE_REGEX); 274 | if (StringUtils.isBlank(regex)) { 275 | return false; 276 | } 277 | if (interfaceName.matches(regex)) { 278 | log.info("[Net] ignore network interface: {} by regex({})", interfaceName, regex); 279 | return true; 280 | } 281 | return false; 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /proxy/src/main/resources/META-INF/native-image/reflect-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"ch.qos.logback.classic.pattern.DateConverter", 4 | "methods":[{"name":"","parameterTypes":[] }] 5 | }, 6 | { 7 | "name":"ch.qos.logback.classic.pattern.LevelConverter", 8 | "methods":[{"name":"","parameterTypes":[] }] 9 | }, 10 | { 11 | "name":"ch.qos.logback.classic.pattern.LineSeparatorConverter", 12 | "methods":[{"name":"","parameterTypes":[] }] 13 | }, 14 | { 15 | "name":"ch.qos.logback.classic.pattern.LoggerConverter", 16 | "methods":[{"name":"","parameterTypes":[] }] 17 | }, 18 | { 19 | "name":"ch.qos.logback.classic.pattern.MessageConverter", 20 | "methods":[{"name":"","parameterTypes":[] }] 21 | }, 22 | { 23 | "name":"ch.qos.logback.classic.pattern.ThreadConverter", 24 | "methods":[{"name":"","parameterTypes":[] }] 25 | }, 26 | { 27 | "name":"com.alibaba.fastjson.parser.deserializer.FastjsonASMDeserializer_1_ServiceConfig", 28 | "methods":[{"name":"","parameterTypes":["com.alibaba.fastjson.parser.ParserConfig","com.alibaba.fastjson.util.JavaBeanInfo"] }] 29 | }, 30 | { 31 | "name":"com.alibaba.fastjson.serializer.ASMSerializer_1_ServiceConfig", 32 | "methods":[{"name":"","parameterTypes":["com.alibaba.fastjson.serializer.SerializeBeanInfo"] }] 33 | }, 34 | { 35 | "name":"com.github.wormhole.client.Client" 36 | }, 37 | { 38 | "name":"com.github.wormhole.client.Client$1" 39 | }, 40 | { 41 | "name":"com.github.wormhole.client.DataTransHandler", 42 | "methods":[{"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 43 | }, 44 | { 45 | "name":"com.github.wormhole.client.SignalClient" 46 | }, 47 | { 48 | "name":"com.github.wormhole.client.SignalHandler", 49 | "methods":[{"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }] 50 | }, 51 | { 52 | "name":"com.github.wormhole.client.ack.AckHandler", 53 | "methods":[{"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"write","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object","io.netty.channel.ChannelPromise"] }] 54 | }, 55 | { 56 | "name":"com.github.wormhole.common.config.ProxyServiceConfig$ServiceConfig", 57 | "allDeclaredFields":true, 58 | "allPublicFields":true, 59 | "queryAllPublicMethods":true, 60 | "queryAllDeclaredConstructors":true, 61 | "methods":[{"name":"getIp","parameterTypes":[] }, {"name":"getMappingPort","parameterTypes":[] }, {"name":"getPort","parameterTypes":[] }, {"name":"setMappingPort","parameterTypes":["java.lang.Integer"] }, {"name":"setPort","parameterTypes":["java.lang.Integer"] }] 62 | }, 63 | { 64 | "name":"com.github.wormhole.proxy.Proxy" 65 | }, 66 | { 67 | "name":"com.github.wormhole.serialize.FrameDecoder" 68 | }, 69 | { 70 | "name":"com.github.wormhole.serialize.FrameEncoder" 71 | }, 72 | { 73 | "name":"com.github.wormhole.serialize.PackageDecoder" 74 | }, 75 | { 76 | "name":"com.github.wormhole.serialize.PackageEncoder" 77 | }, 78 | { 79 | "name":"io.netty.buffer.AbstractByteBufAllocator", 80 | "queryAllDeclaredMethods":true 81 | }, 82 | { 83 | "name":"io.netty.buffer.AbstractReferenceCountedByteBuf", 84 | "fields":[{"name":"refCnt"}] 85 | }, 86 | { 87 | "name":"io.netty.channel.AbstractChannelHandlerContext", 88 | "fields":[{"name":"handlerState"}] 89 | }, 90 | { 91 | "name":"io.netty.channel.ChannelDuplexHandler", 92 | "methods":[{"name":"bind","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"close","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"connect","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"deregister","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"disconnect","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"flush","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"read","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }] 93 | }, 94 | { 95 | "name":"io.netty.channel.ChannelHandlerAdapter", 96 | "methods":[{"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }] 97 | }, 98 | { 99 | "name":"io.netty.channel.ChannelInboundHandlerAdapter", 100 | "methods":[{"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelUnregistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelWritabilityChanged","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 101 | }, 102 | { 103 | "name":"io.netty.channel.ChannelInitializer", 104 | "methods":[{"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }] 105 | }, 106 | { 107 | "name":"io.netty.channel.ChannelOutboundBuffer", 108 | "fields":[{"name":"totalPendingSize"}, {"name":"unwritable"}] 109 | }, 110 | { 111 | "name":"io.netty.channel.ChannelOutboundHandlerAdapter", 112 | "methods":[{"name":"bind","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"close","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"connect","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"deregister","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"disconnect","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"flush","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"read","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }] 113 | }, 114 | { 115 | "name":"io.netty.channel.DefaultChannelConfig", 116 | "fields":[{"name":"autoRead"}, {"name":"writeBufferWaterMark"}] 117 | }, 118 | { 119 | "name":"io.netty.channel.DefaultChannelPipeline", 120 | "fields":[{"name":"estimatorHandle"}] 121 | }, 122 | { 123 | "name":"io.netty.channel.DefaultChannelPipeline$HeadContext", 124 | "methods":[{"name":"bind","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelUnregistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelWritabilityChanged","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"close","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"connect","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"deregister","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"disconnect","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }, {"name":"flush","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"read","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"write","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object","io.netty.channel.ChannelPromise"] }] 125 | }, 126 | { 127 | "name":"io.netty.channel.DefaultChannelPipeline$TailContext", 128 | "methods":[{"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelUnregistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelWritabilityChanged","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 129 | }, 130 | { 131 | "name":"io.netty.channel.MultithreadEventLoopGroup" 132 | }, 133 | { 134 | "name":"io.netty.channel.SimpleChannelInboundHandler", 135 | "methods":[{"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 136 | }, 137 | { 138 | "name":"io.netty.channel.nio.NioEventLoop" 139 | }, 140 | { 141 | "name":"io.netty.channel.nio.NioEventLoopGroup" 142 | }, 143 | { 144 | "name":"io.netty.channel.socket.nio.NioSocketChannel", 145 | "methods":[{"name":"","parameterTypes":[] }] 146 | }, 147 | { 148 | "name":"io.netty.handler.codec.ByteToMessageDecoder", 149 | "methods":[{"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 150 | }, 151 | { 152 | "name":"io.netty.handler.codec.MessageToMessageDecoder", 153 | "methods":[{"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 154 | }, 155 | { 156 | "name":"io.netty.handler.codec.MessageToMessageEncoder", 157 | "methods":[{"name":"write","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object","io.netty.channel.ChannelPromise"] }] 158 | }, 159 | { 160 | "name":"io.netty.handler.logging.LoggingHandler", 161 | "methods":[{"name":"bind","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelUnregistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelWritabilityChanged","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"close","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"connect","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"deregister","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"disconnect","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }, {"name":"flush","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"write","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object","io.netty.channel.ChannelPromise"] }] 162 | }, 163 | { 164 | "name":"io.netty.util.DefaultAttributeMap", 165 | "fields":[{"name":"attributes"}] 166 | }, 167 | { 168 | "name":"io.netty.util.ReferenceCountUtil", 169 | "queryAllDeclaredMethods":true 170 | }, 171 | { 172 | "name":"io.netty.util.ResourceLeakDetector$DefaultResourceLeak", 173 | "fields":[{"name":"droppedRecords"}, {"name":"head"}] 174 | }, 175 | { 176 | "name":"io.netty.util.concurrent.DefaultPromise", 177 | "fields":[{"name":"result"}] 178 | }, 179 | { 180 | "name":"io.netty.util.concurrent.MultithreadEventExecutorGroup" 181 | }, 182 | { 183 | "name":"io.netty.util.concurrent.SingleThreadEventExecutor", 184 | "fields":[{"name":"state"}, {"name":"threadProperties"}] 185 | }, 186 | { 187 | "name":"io.netty.util.internal.PlatformDependent" 188 | }, 189 | { 190 | "name":"io.netty.util.internal.PlatformDependent0" 191 | }, 192 | { 193 | "name":"io.netty.util.internal.PlatformDependent0$4" 194 | }, 195 | { 196 | "name":"io.netty.util.internal.PlatformDependent0$6" 197 | }, 198 | { 199 | "name":"io.netty.util.internal.ReflectionUtil" 200 | }, 201 | { 202 | "name":"io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields", 203 | "fields":[{"name":"producerLimit"}] 204 | }, 205 | { 206 | "name":"io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields", 207 | "fields":[{"name":"consumerIndex"}] 208 | }, 209 | { 210 | "name":"io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields", 211 | "fields":[{"name":"producerIndex"}] 212 | }, 213 | { 214 | "name":"io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField", 215 | "fields":[{"name":"consumerIndex"}] 216 | }, 217 | { 218 | "name":"io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField", 219 | "fields":[{"name":"producerIndex"}] 220 | }, 221 | { 222 | "name":"io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField", 223 | "fields":[{"name":"producerLimit"}] 224 | }, 225 | { 226 | "name":"java.awt.Color" 227 | }, 228 | { 229 | "name":"java.awt.Font" 230 | }, 231 | { 232 | "name":"java.awt.Point" 233 | }, 234 | { 235 | "name":"java.awt.Rectangle" 236 | }, 237 | { 238 | "name":"java.beans.Transient" 239 | }, 240 | { 241 | "name":"java.io.FilePermission" 242 | }, 243 | { 244 | "name":"java.lang.AutoCloseable" 245 | }, 246 | { 247 | "name":"java.lang.RuntimePermission" 248 | }, 249 | { 250 | "name":"java.lang.Thread", 251 | "fields":[{"name":"threadLocalRandomProbe"}] 252 | }, 253 | { 254 | "name":"java.lang.Throwable", 255 | "methods":[{"name":"getSuppressed","parameterTypes":[] }] 256 | }, 257 | { 258 | "name":"java.lang.management.ManagementFactory", 259 | "methods":[{"name":"getRuntimeMXBean","parameterTypes":[] }] 260 | }, 261 | { 262 | "name":"java.lang.management.RuntimeMXBean", 263 | "methods":[{"name":"getInputArguments","parameterTypes":[] }, {"name":"getName","parameterTypes":[] }] 264 | }, 265 | { 266 | "name":"java.lang.reflect.AccessibleObject" 267 | }, 268 | { 269 | "name":"java.lang.reflect.Method" 270 | }, 271 | { 272 | "name":"java.net.NetPermission" 273 | }, 274 | { 275 | "name":"java.net.SocketPermission" 276 | }, 277 | { 278 | "name":"java.net.URLPermission", 279 | "methods":[{"name":"","parameterTypes":["java.lang.String","java.lang.String"] }] 280 | }, 281 | { 282 | "name":"java.nio.Bits", 283 | "fields":[{"name":"UNALIGNED"}] 284 | }, 285 | { 286 | "name":"java.nio.Buffer", 287 | "fields":[{"name":"address"}] 288 | }, 289 | { 290 | "name":"java.nio.DirectByteBuffer", 291 | "methods":[{"name":"","parameterTypes":["long","int"] }] 292 | }, 293 | { 294 | "name":"java.nio.file.Path" 295 | }, 296 | { 297 | "name":"java.security.AccessController" 298 | }, 299 | { 300 | "name":"java.security.AllPermission" 301 | }, 302 | { 303 | "name":"java.security.SecurityPermission" 304 | }, 305 | { 306 | "name":"java.sql.Clob" 307 | }, 308 | { 309 | "name":"java.util.Collections$UnmodifiableMap" 310 | }, 311 | { 312 | "name":"java.util.PropertyPermission" 313 | }, 314 | { 315 | "name":"java.util.concurrent.ConcurrentSkipListMap" 316 | }, 317 | { 318 | "name":"java.util.concurrent.ConcurrentSkipListSet" 319 | }, 320 | { 321 | "name":"java.util.concurrent.atomic.AtomicBoolean", 322 | "fields":[{"name":"value"}] 323 | }, 324 | { 325 | "name":"java.util.concurrent.atomic.AtomicReference", 326 | "fields":[{"name":"value"}] 327 | }, 328 | { 329 | "name":"java.util.concurrent.atomic.Striped64", 330 | "fields":[{"name":"base"}, {"name":"cellsBusy"}] 331 | }, 332 | { 333 | "name":"javax.persistence.ManyToMany" 334 | }, 335 | { 336 | "name":"javax.persistence.OneToMany" 337 | }, 338 | { 339 | "name":"javax.smartcardio.CardPermission" 340 | }, 341 | { 342 | "name":"javax.xml.bind.annotation.XmlAccessorType" 343 | }, 344 | { 345 | "name":"jdk.internal.misc.Unsafe", 346 | "methods":[{"name":"getUnsafe","parameterTypes":[] }] 347 | }, 348 | { 349 | "name":"jdk.internal.reflect.Reflection" 350 | }, 351 | { 352 | "name":"kotlin.Metadata" 353 | }, 354 | { 355 | "name":"org.springframework.cache.support.NullValue" 356 | }, 357 | { 358 | "name":"org.springframework.remoting.support.RemoteInvocation" 359 | }, 360 | { 361 | "name":"org.springframework.remoting.support.RemoteInvocationResult" 362 | }, 363 | { 364 | "name":"org.springframework.security.authentication.UsernamePasswordAuthenticationToken" 365 | }, 366 | { 367 | "name":"org.springframework.security.core.authority.SimpleGrantedAuthority" 368 | }, 369 | { 370 | "name":"org.springframework.security.core.context.SecurityContextImpl" 371 | }, 372 | { 373 | "name":"org.springframework.security.core.userdetails.User" 374 | }, 375 | { 376 | "name":"org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken" 377 | }, 378 | { 379 | "name":"org.springframework.security.oauth2.common.DefaultOAuth2AccessToken" 380 | }, 381 | { 382 | "name":"org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken" 383 | }, 384 | { 385 | "name":"org.springframework.security.web.authentication.WebAuthenticationDetails" 386 | }, 387 | { 388 | "name":"org.springframework.security.web.csrf.DefaultCsrfToken" 389 | }, 390 | { 391 | "name":"org.springframework.security.web.savedrequest.DefaultSavedRequest" 392 | }, 393 | { 394 | "name":"org.springframework.security.web.savedrequest.SavedCookie" 395 | }, 396 | { 397 | "name":"org.springframework.util.LinkedCaseInsensitiveMap" 398 | }, 399 | { 400 | "name":"org.springframework.util.LinkedMultiValueMap" 401 | }, 402 | { 403 | "name":"sun.misc.Unsafe", 404 | "fields":[{"name":"theUnsafe"}], 405 | "methods":[{"name":"copyMemory","parameterTypes":["java.lang.Object","long","java.lang.Object","long","long"] }, {"name":"getAndAddLong","parameterTypes":["java.lang.Object","long","long"] }, {"name":"getAndSetObject","parameterTypes":["java.lang.Object","long","java.lang.Object"] }, {"name":"invokeCleaner","parameterTypes":["java.nio.ByteBuffer"] }] 406 | }, 407 | { 408 | "name":"sun.misc.VM" 409 | }, 410 | { 411 | "name":"sun.nio.ch.SelectorImpl", 412 | "fields":[{"name":"publicSelectedKeys"}, {"name":"selectedKeys"}] 413 | } 414 | ] 415 | -------------------------------------------------------------------------------- /server/src/main/resources/META-INF/native-image/reflect-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"ch.qos.logback.classic.pattern.DateConverter", 4 | "methods":[{"name":"","parameterTypes":[] }] 5 | }, 6 | { 7 | "name":"ch.qos.logback.classic.pattern.LevelConverter", 8 | "methods":[{"name":"","parameterTypes":[] }] 9 | }, 10 | { 11 | "name":"ch.qos.logback.classic.pattern.LineSeparatorConverter", 12 | "methods":[{"name":"","parameterTypes":[] }] 13 | }, 14 | { 15 | "name":"ch.qos.logback.classic.pattern.LoggerConverter", 16 | "methods":[{"name":"","parameterTypes":[] }] 17 | }, 18 | { 19 | "name":"ch.qos.logback.classic.pattern.MessageConverter", 20 | "methods":[{"name":"","parameterTypes":[] }] 21 | }, 22 | { 23 | "name":"ch.qos.logback.classic.pattern.ThreadConverter", 24 | "methods":[{"name":"","parameterTypes":[] }] 25 | }, 26 | { 27 | "name":"com.alibaba.fastjson.parser.deserializer.FastjsonASMDeserializer_1_ServiceConfig", 28 | "methods":[{"name":"","parameterTypes":["com.alibaba.fastjson.parser.ParserConfig","com.alibaba.fastjson.util.JavaBeanInfo"] }] 29 | }, 30 | { 31 | "name":"com.github.wormhole.client.SignalHandler", 32 | "methods":[{"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }] 33 | }, 34 | { 35 | "name":"com.github.wormhole.client.ack.AckHandler", 36 | "methods":[{"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"write","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object","io.netty.channel.ChannelPromise"] }] 37 | }, 38 | { 39 | "name":"com.github.wormhole.common.config.ProxyServiceConfig$ServiceConfig", 40 | "allDeclaredFields":true, 41 | "allPublicFields":true, 42 | "queryAllPublicMethods":true, 43 | "queryAllDeclaredConstructors":true 44 | }, 45 | { 46 | "name":"com.github.wormhole.serialize.FrameDecoder" 47 | }, 48 | { 49 | "name":"com.github.wormhole.serialize.FrameEncoder" 50 | }, 51 | { 52 | "name":"com.github.wormhole.serialize.PackageDecoder" 53 | }, 54 | { 55 | "name":"com.github.wormhole.serialize.PackageEncoder" 56 | }, 57 | { 58 | "name":"com.github.wormhole.server.ClientHandler", 59 | "methods":[{"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 60 | }, 61 | { 62 | "name":"com.github.wormhole.server.DataTransHandler", 63 | "methods":[{"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 64 | }, 65 | { 66 | "name":"com.github.wormhole.server.DataTransServer$1" 67 | }, 68 | { 69 | "name":"com.github.wormhole.server.ProxyServer$1" 70 | }, 71 | { 72 | "name":"com.github.wormhole.server.Server" 73 | }, 74 | { 75 | "name":"com.github.wormhole.server.Server$1" 76 | }, 77 | { 78 | "name":"io.netty.bootstrap.ServerBootstrap$1" 79 | }, 80 | { 81 | "name":"io.netty.bootstrap.ServerBootstrap$ServerBootstrapAcceptor", 82 | "methods":[{"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }] 83 | }, 84 | { 85 | "name":"io.netty.buffer.AbstractByteBuf" 86 | }, 87 | { 88 | "name":"io.netty.buffer.AbstractByteBufAllocator", 89 | "queryAllDeclaredMethods":true 90 | }, 91 | { 92 | "name":"io.netty.buffer.AbstractReferenceCountedByteBuf", 93 | "fields":[{"name":"refCnt"}] 94 | }, 95 | { 96 | "name":"io.netty.buffer.PooledByteBuf" 97 | }, 98 | { 99 | "name":"io.netty.channel.AbstractChannelHandlerContext", 100 | "fields":[{"name":"handlerState"}] 101 | }, 102 | { 103 | "name":"io.netty.channel.ChannelDuplexHandler", 104 | "methods":[{"name":"bind","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"close","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"connect","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"deregister","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"disconnect","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"flush","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"read","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }] 105 | }, 106 | { 107 | "name":"io.netty.channel.ChannelHandlerAdapter", 108 | "methods":[{"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }] 109 | }, 110 | { 111 | "name":"io.netty.channel.ChannelInboundHandlerAdapter", 112 | "methods":[{"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelUnregistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelWritabilityChanged","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 113 | }, 114 | { 115 | "name":"io.netty.channel.ChannelInitializer", 116 | "methods":[{"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }] 117 | }, 118 | { 119 | "name":"io.netty.channel.ChannelOutboundBuffer", 120 | "fields":[{"name":"totalPendingSize"}, {"name":"unwritable"}] 121 | }, 122 | { 123 | "name":"io.netty.channel.ChannelOutboundHandlerAdapter", 124 | "methods":[{"name":"bind","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"close","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"connect","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"deregister","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"disconnect","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"flush","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"read","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }] 125 | }, 126 | { 127 | "name":"io.netty.channel.DefaultChannelConfig", 128 | "fields":[{"name":"autoRead"}, {"name":"writeBufferWaterMark"}] 129 | }, 130 | { 131 | "name":"io.netty.channel.DefaultChannelPipeline", 132 | "fields":[{"name":"estimatorHandle"}] 133 | }, 134 | { 135 | "name":"io.netty.channel.DefaultChannelPipeline$HeadContext", 136 | "methods":[{"name":"bind","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelUnregistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelWritabilityChanged","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"close","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"connect","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"deregister","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"disconnect","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }, {"name":"flush","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"read","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"write","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object","io.netty.channel.ChannelPromise"] }] 137 | }, 138 | { 139 | "name":"io.netty.channel.DefaultChannelPipeline$TailContext", 140 | "methods":[{"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelUnregistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelWritabilityChanged","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 141 | }, 142 | { 143 | "name":"io.netty.channel.MultithreadEventLoopGroup" 144 | }, 145 | { 146 | "name":"io.netty.channel.SimpleChannelInboundHandler", 147 | "methods":[{"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 148 | }, 149 | { 150 | "name":"io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe" 151 | }, 152 | { 153 | "name":"io.netty.channel.nio.NioEventLoop" 154 | }, 155 | { 156 | "name":"io.netty.channel.nio.NioEventLoopGroup" 157 | }, 158 | { 159 | "name":"io.netty.channel.socket.nio.NioServerSocketChannel", 160 | "methods":[{"name":"","parameterTypes":[] }] 161 | }, 162 | { 163 | "name":"io.netty.channel.socket.nio.NioSocketChannel" 164 | }, 165 | { 166 | "name":"io.netty.handler.codec.ByteToMessageDecoder", 167 | "methods":[{"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 168 | }, 169 | { 170 | "name":"io.netty.handler.codec.MessageToMessageDecoder", 171 | "methods":[{"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }] 172 | }, 173 | { 174 | "name":"io.netty.handler.codec.MessageToMessageEncoder", 175 | "methods":[{"name":"write","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object","io.netty.channel.ChannelPromise"] }] 176 | }, 177 | { 178 | "name":"io.netty.handler.logging.LoggingHandler", 179 | "methods":[{"name":"bind","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"channelActive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelInactive","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRead","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"channelReadComplete","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelRegistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelUnregistered","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"channelWritabilityChanged","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"close","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"connect","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.net.SocketAddress","java.net.SocketAddress","io.netty.channel.ChannelPromise"] }, {"name":"deregister","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"disconnect","parameterTypes":["io.netty.channel.ChannelHandlerContext","io.netty.channel.ChannelPromise"] }, {"name":"exceptionCaught","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Throwable"] }, {"name":"flush","parameterTypes":["io.netty.channel.ChannelHandlerContext"] }, {"name":"userEventTriggered","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object"] }, {"name":"write","parameterTypes":["io.netty.channel.ChannelHandlerContext","java.lang.Object","io.netty.channel.ChannelPromise"] }] 180 | }, 181 | { 182 | "name":"io.netty.util.DefaultAttributeMap", 183 | "fields":[{"name":"attributes"}] 184 | }, 185 | { 186 | "name":"io.netty.util.ReferenceCountUtil", 187 | "queryAllDeclaredMethods":true 188 | }, 189 | { 190 | "name":"io.netty.util.ResourceLeakDetector$DefaultResourceLeak", 191 | "fields":[{"name":"droppedRecords"}, {"name":"head"}] 192 | }, 193 | { 194 | "name":"io.netty.util.concurrent.DefaultPromise", 195 | "fields":[{"name":"result"}] 196 | }, 197 | { 198 | "name":"io.netty.util.concurrent.FastThreadLocalRunnable" 199 | }, 200 | { 201 | "name":"io.netty.util.concurrent.MultithreadEventExecutorGroup" 202 | }, 203 | { 204 | "name":"io.netty.util.concurrent.SingleThreadEventExecutor", 205 | "fields":[{"name":"state"}, {"name":"threadProperties"}] 206 | }, 207 | { 208 | "name":"io.netty.util.concurrent.SingleThreadEventExecutor$4" 209 | }, 210 | { 211 | "name":"io.netty.util.internal.PlatformDependent" 212 | }, 213 | { 214 | "name":"io.netty.util.internal.PlatformDependent0" 215 | }, 216 | { 217 | "name":"io.netty.util.internal.PlatformDependent0$4" 218 | }, 219 | { 220 | "name":"io.netty.util.internal.PlatformDependent0$6" 221 | }, 222 | { 223 | "name":"io.netty.util.internal.ReflectionUtil" 224 | }, 225 | { 226 | "name":"io.netty.util.internal.ThreadExecutorMap$2" 227 | }, 228 | { 229 | "name":"io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields", 230 | "fields":[{"name":"producerLimit"}] 231 | }, 232 | { 233 | "name":"io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields", 234 | "fields":[{"name":"consumerIndex"}] 235 | }, 236 | { 237 | "name":"io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields", 238 | "fields":[{"name":"producerIndex"}] 239 | }, 240 | { 241 | "name":"io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField", 242 | "fields":[{"name":"consumerIndex"}] 243 | }, 244 | { 245 | "name":"io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField", 246 | "fields":[{"name":"producerIndex"}] 247 | }, 248 | { 249 | "name":"io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField", 250 | "fields":[{"name":"producerLimit"}] 251 | }, 252 | { 253 | "name":"java.awt.Color" 254 | }, 255 | { 256 | "name":"java.awt.Font" 257 | }, 258 | { 259 | "name":"java.awt.Point" 260 | }, 261 | { 262 | "name":"java.awt.Rectangle" 263 | }, 264 | { 265 | "name":"java.beans.Transient" 266 | }, 267 | { 268 | "name":"java.io.FilePermission" 269 | }, 270 | { 271 | "name":"java.lang.AutoCloseable" 272 | }, 273 | { 274 | "name":"java.lang.RuntimePermission" 275 | }, 276 | { 277 | "name":"java.lang.Thread", 278 | "fields":[{"name":"threadLocalRandomProbe"}] 279 | }, 280 | { 281 | "name":"java.lang.Throwable", 282 | "methods":[{"name":"getSuppressed","parameterTypes":[] }] 283 | }, 284 | { 285 | "name":"java.lang.management.ManagementFactory", 286 | "methods":[{"name":"getRuntimeMXBean","parameterTypes":[] }] 287 | }, 288 | { 289 | "name":"java.lang.management.RuntimeMXBean", 290 | "methods":[{"name":"getInputArguments","parameterTypes":[] }, {"name":"getName","parameterTypes":[] }] 291 | }, 292 | { 293 | "name":"java.lang.reflect.AccessibleObject" 294 | }, 295 | { 296 | "name":"java.lang.reflect.Method" 297 | }, 298 | { 299 | "name":"java.net.NetPermission" 300 | }, 301 | { 302 | "name":"java.net.SocketPermission" 303 | }, 304 | { 305 | "name":"java.net.URLPermission", 306 | "methods":[{"name":"","parameterTypes":["java.lang.String","java.lang.String"] }] 307 | }, 308 | { 309 | "name":"java.nio.Bits", 310 | "fields":[{"name":"UNALIGNED"}] 311 | }, 312 | { 313 | "name":"java.nio.Buffer", 314 | "fields":[{"name":"address"}] 315 | }, 316 | { 317 | "name":"java.nio.DirectByteBuffer", 318 | "methods":[{"name":"","parameterTypes":["long","int"] }] 319 | }, 320 | { 321 | "name":"java.security.AccessController" 322 | }, 323 | { 324 | "name":"java.security.AllPermission" 325 | }, 326 | { 327 | "name":"java.security.SecureRandomParameters" 328 | }, 329 | { 330 | "name":"java.security.SecurityPermission" 331 | }, 332 | { 333 | "name":"java.util.Collections$UnmodifiableMap" 334 | }, 335 | { 336 | "name":"java.util.PropertyPermission" 337 | }, 338 | { 339 | "name":"java.util.concurrent.ConcurrentSkipListMap" 340 | }, 341 | { 342 | "name":"java.util.concurrent.ConcurrentSkipListSet" 343 | }, 344 | { 345 | "name":"java.util.concurrent.atomic.AtomicBoolean", 346 | "fields":[{"name":"value"}] 347 | }, 348 | { 349 | "name":"java.util.concurrent.atomic.AtomicReference", 350 | "fields":[{"name":"value"}] 351 | }, 352 | { 353 | "name":"java.util.concurrent.atomic.Striped64", 354 | "fields":[{"name":"base"}, {"name":"cellsBusy"}] 355 | }, 356 | { 357 | "name":"javax.smartcardio.CardPermission" 358 | }, 359 | { 360 | "name":"javax.xml.bind.annotation.XmlAccessorType" 361 | }, 362 | { 363 | "name":"jdk.internal.misc.Unsafe", 364 | "methods":[{"name":"getUnsafe","parameterTypes":[] }] 365 | }, 366 | { 367 | "name":"jdk.internal.reflect.Reflection" 368 | }, 369 | { 370 | "name":"kotlin.Metadata" 371 | }, 372 | { 373 | "name":"org.springframework.cache.support.NullValue" 374 | }, 375 | { 376 | "name":"org.springframework.remoting.support.RemoteInvocation" 377 | }, 378 | { 379 | "name":"org.springframework.remoting.support.RemoteInvocationResult" 380 | }, 381 | { 382 | "name":"org.springframework.security.authentication.UsernamePasswordAuthenticationToken" 383 | }, 384 | { 385 | "name":"org.springframework.security.core.authority.SimpleGrantedAuthority" 386 | }, 387 | { 388 | "name":"org.springframework.security.core.context.SecurityContextImpl" 389 | }, 390 | { 391 | "name":"org.springframework.security.core.userdetails.User" 392 | }, 393 | { 394 | "name":"org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken" 395 | }, 396 | { 397 | "name":"org.springframework.security.oauth2.common.DefaultOAuth2AccessToken" 398 | }, 399 | { 400 | "name":"org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken" 401 | }, 402 | { 403 | "name":"org.springframework.security.web.authentication.WebAuthenticationDetails" 404 | }, 405 | { 406 | "name":"org.springframework.security.web.csrf.DefaultCsrfToken" 407 | }, 408 | { 409 | "name":"org.springframework.security.web.savedrequest.DefaultSavedRequest" 410 | }, 411 | { 412 | "name":"org.springframework.security.web.savedrequest.SavedCookie" 413 | }, 414 | { 415 | "name":"org.springframework.util.LinkedCaseInsensitiveMap" 416 | }, 417 | { 418 | "name":"org.springframework.util.LinkedMultiValueMap" 419 | }, 420 | { 421 | "name":"sun.misc.Unsafe", 422 | "fields":[{"name":"theUnsafe"}], 423 | "methods":[{"name":"copyMemory","parameterTypes":["java.lang.Object","long","java.lang.Object","long","long"] }, {"name":"getAndAddLong","parameterTypes":["java.lang.Object","long","long"] }, {"name":"getAndSetObject","parameterTypes":["java.lang.Object","long","java.lang.Object"] }, {"name":"invokeCleaner","parameterTypes":["java.nio.ByteBuffer"] }] 424 | }, 425 | { 426 | "name":"sun.misc.VM" 427 | }, 428 | { 429 | "name":"sun.nio.ch.SelectorImpl", 430 | "fields":[{"name":"publicSelectedKeys"}, {"name":"selectedKeys"}] 431 | }, 432 | { 433 | "name":"sun.nio.ch.SocketChannelImpl" 434 | }, 435 | { 436 | "name":"sun.security.provider.NativePRNG", 437 | "methods":[{"name":"","parameterTypes":[] }, {"name":"","parameterTypes":["java.security.SecureRandomParameters"] }] 438 | }, 439 | { 440 | "name":"sun.security.provider.SHA", 441 | "methods":[{"name":"","parameterTypes":[] }] 442 | } 443 | ] 444 | --------------------------------------------------------------------------------