Skip to content

Commit

Permalink
2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iamlinhui committed Apr 19, 2022
1 parent 06ef446 commit 2523cf5
Show file tree
Hide file tree
Showing 28 changed files with 285 additions and 3,279 deletions.
13 changes: 9 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cn.promptness</groupId>
<artifactId>rpt</artifactId>
<packaging>pom</packaging>
<version>2.1.0</version>
<version>2.2.0</version>
<modules>
<module>rpt-base</module>
<module>rpt-server</module>
Expand All @@ -34,9 +34,14 @@
<version>2.0.51.Final</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.19.4</version>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
Expand Down
10 changes: 7 additions & 3 deletions rpt-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>rpt</artifactId>
<groupId>cn.promptness</groupId>
<version>2.1.0</version>
<version>2.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -27,8 +27,12 @@
<artifactId>netty-tcnative-boringssl-static</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cn.promptness.rpt.base.coder;

import cn.promptness.rpt.base.config.ClientConfig;
import cn.promptness.rpt.base.config.ClientConfigProto;
import cn.promptness.rpt.base.protocol.Message;
import cn.promptness.rpt.base.protocol.MessageType;
import cn.promptness.rpt.base.protocol.Meta;
import cn.promptness.rpt.base.utils.MetaUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
Expand All @@ -22,18 +22,15 @@ protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteB

int protobufLength = byteBuf.readInt();
if (protobufLength > 0) {
byte[] clientConfigByte = new byte[protobufLength];
byteBuf.readBytes(clientConfigByte);
ClientConfigProto.ClientConfig clientConfig = ClientConfigProto.ClientConfig.parseFrom(clientConfigByte);
proxyMessage.setClientConfig(new ClientConfig().fromProtobuf(clientConfig));
byte[] metaByte = new byte[protobufLength];
byteBuf.readBytes(metaByte);
Meta meta = MetaUtils.deserialize(metaByte);
proxyMessage.setMeta(meta);
}

byte[] data = null;
if (byteBuf.isReadable()) {
data = ByteBufUtil.getBytes(byteBuf);
byte[] data = ByteBufUtil.getBytes(byteBuf);
proxyMessage.setData(data);
}
proxyMessage.setData(data);

list.add(proxyMessage);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cn.promptness.rpt.base.coder;

import cn.promptness.rpt.base.config.ClientConfig;
import cn.promptness.rpt.base.protocol.Message;
import cn.promptness.rpt.base.protocol.MessageType;
import cn.promptness.rpt.base.protocol.Meta;
import cn.promptness.rpt.base.utils.MetaUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
Expand All @@ -16,8 +17,8 @@ protected void encode(ChannelHandlerContext channelHandlerContext, Message messa
MessageType type = message.getType();
out.writeInt(type.getCode());

ClientConfig clientConfig = message.getClientConfig();
byte[] protobuf = clientConfig == null ? EmptyArrays.EMPTY_BYTES : clientConfig.toProtobuf();
Meta meta = message.getMeta();
byte[] protobuf = meta == null ? EmptyArrays.EMPTY_BYTES : MetaUtils.serialize(meta);
out.writeInt(protobuf.length);
out.writeBytes(protobuf);

Expand Down
136 changes: 16 additions & 120 deletions rpt-base/src/main/java/cn/promptness/rpt/base/config/ClientConfig.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package cn.promptness.rpt.base.config;

import cn.promptness.rpt.base.protocol.ProxyType;
import com.google.protobuf.ProtocolStringList;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand All @@ -16,80 +12,19 @@ public class ClientConfig implements Serializable {
private int serverPort;
private int clientLimit;
private String clientKey;
private boolean connection;
private String channelId;

private List<RemoteConfig> config;
private List<String> remoteResult;

public byte[] toProtobuf() {
ClientConfigProto.ClientConfig.Builder clientConfigBuilder = ClientConfigProto.ClientConfig.newBuilder();
clientConfigBuilder.setServerPort(serverPort).setConnection(connection);
if (serverIp != null) {
clientConfigBuilder.setServerIp(serverIp);
}
if (clientKey != null) {
clientConfigBuilder.setClientKey(clientKey);
}
if (channelId != null) {
clientConfigBuilder.setChannelId(channelId);
}
if (config != null && !config.isEmpty()) {
for (RemoteConfig remoteConfig : config) {
ClientConfigProto.ClientConfig.RemoteConfig.Builder remoteBuilder = ClientConfigProto.ClientConfig.RemoteConfig.newBuilder();
remoteBuilder.setRemotePort(remoteConfig.getRemotePort()).setLocalPort(remoteConfig.getLocalPort());
if (remoteConfig.getLocalIp() != null) {
remoteBuilder.setLocalIp(remoteConfig.getLocalIp());
}
if (remoteConfig.getDescription() != null) {
remoteBuilder.setDescription(remoteConfig.getDescription());
}
if (remoteConfig.getDomain() != null) {
remoteBuilder.setDomain(remoteConfig.getDomain());
}
if (remoteConfig.getProxyType() != null) {
remoteBuilder.setProxyTypeValue(remoteConfig.getProxyType().getCode());
}
clientConfigBuilder.addConfig(remoteBuilder.build());
}
}
if (remoteResult != null && !remoteResult.isEmpty()) {
for (String result : remoteResult) {
if (result != null) {
clientConfigBuilder.addRemoteResult(result);
}
}
public RemoteConfig getHttpConfig(String domain) {
if (config == null || config.isEmpty()) {
return null;
}
return clientConfigBuilder.build().toByteArray();
}

public ClientConfig fromProtobuf(ClientConfigProto.ClientConfig clientConfig) {

serverIp = clientConfig.getServerIp();
serverPort = clientConfig.getServerPort();
clientKey = clientConfig.getClientKey();
connection = clientConfig.getConnection();
channelId = clientConfig.getChannelId();
List<ClientConfigProto.ClientConfig.RemoteConfig> configList = clientConfig.getConfigList();
if (!configList.isEmpty()) {
config = new ArrayList<>();
for (ClientConfigProto.ClientConfig.RemoteConfig remoteConfigProto : configList) {
RemoteConfig remoteConfig = new RemoteConfig();
remoteConfig.setRemotePort(remoteConfigProto.getRemotePort());
remoteConfig.setLocalPort(remoteConfigProto.getLocalPort());
remoteConfig.setLocalIp(remoteConfigProto.getLocalIp());
remoteConfig.setDescription(remoteConfigProto.getDescription());
remoteConfig.setProxyType(ProxyType.getInstance(remoteConfigProto.getProxyType().getNumber()));
remoteConfig.setDomain(remoteConfigProto.getDomain());
config.add(remoteConfig);
for (RemoteConfig remoteConfig : config) {
ProxyType proxyType = remoteConfig.getProxyType();
if (Objects.equals(ProxyType.HTTP, proxyType) && Objects.equals(domain, remoteConfig.getDomain())) {
return remoteConfig;
}
}
ProtocolStringList remoteResultList = clientConfig.getRemoteResultList();
if (!remoteResultList.isEmpty()) {
remoteResult = new ArrayList<>();
remoteResult.addAll(remoteResultList);
}
return this;
return null;
}

public String getServerIp() {
Expand All @@ -108,6 +43,14 @@ public void setServerPort(int serverPort) {
this.serverPort = serverPort;
}

public int getClientLimit() {
return clientLimit;
}

public void setClientLimit(int clientLimit) {
this.clientLimit = clientLimit;
}

public String getClientKey() {
return clientKey;
}
Expand All @@ -123,51 +66,4 @@ public List<RemoteConfig> getConfig() {
public void setConfig(List<RemoteConfig> config) {
this.config = config;
}

public boolean isConnection() {
return connection;
}

public ClientConfig setConnection(boolean connection) {
this.connection = connection;
return this;
}

public String getChannelId() {
return channelId;
}

public void setChannelId(String channelId) {
this.channelId = channelId;
}

public ClientConfig setRemoteResult(List<String> remoteResult) {
this.remoteResult = remoteResult;
return this;
}

public List<String> getRemoteResult() {
return remoteResult;
}

public RemoteConfig getHttpConfig(String domain) {
for (RemoteConfig remoteConfig : config) {
ProxyType proxyType = remoteConfig.getProxyType();
if (proxyType == null) {
continue;
}
if (Objects.equals(ProxyType.HTTP, proxyType) && Objects.equals(domain, remoteConfig.getDomain())) {
return remoteConfig;
}
}
return null;
}

public int getClientLimit() {
return clientLimit;
}

public void setClientLimit(int clientLimit) {
this.clientLimit = clientLimit;
}
}

This file was deleted.

Loading

0 comments on commit 2523cf5

Please sign in to comment.