mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-16 18:35:05 +08:00
【fix】添加虚拟路由管理
This commit is contained in:
@ -80,13 +80,17 @@ public class NettyHttpProxyHandler extends ChannelInboundHandlerAdapter {
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
NettyProxyMsg proxyMsg = new NettyProxyMsg();
|
||||
|
||||
|
||||
ProxyRoute route = RouteContext.getRoute(host, String.valueOf(port));
|
||||
String targetIp = route.getTargetIp();
|
||||
String targetPort = route.getTargetPort();
|
||||
proxyMsg.setVisitorId(visitorId);
|
||||
proxyMsg.setClientTargetIp(host);
|
||||
proxyMsg.setClientTargetPort(port);
|
||||
proxyMsg.setClientTargetIp(targetIp);
|
||||
proxyMsg.setClientTargetPort(Integer.valueOf(targetPort));
|
||||
proxyMsg.setData(bytes);
|
||||
|
||||
|
||||
ProxyRoute route = RouteContext.getRoute(host, String.valueOf(port));
|
||||
|
||||
if(ObjectUtils.isEmpty(route)){
|
||||
proxyMsg.setType(ProxyMessageType.HTTP_LOCAL_PROXY);
|
||||
}else {
|
||||
@ -94,14 +98,14 @@ public class NettyHttpProxyHandler extends ChannelInboundHandlerAdapter {
|
||||
proxyMsg.setType(ProxyMessageType.HTTP_LOCAL_PROXY);
|
||||
}else if (RouteType.CLIENT_PROXY_CLIENT.equals(route.getRouteType())){
|
||||
ClientProxyRoute clientProxyRoute= (ClientProxyRoute) route;
|
||||
String clientId = clientProxyRoute.getClientId();
|
||||
String clientId = clientProxyRoute.getTargetClientId();
|
||||
proxyMsg.setClientId(clientId);
|
||||
proxyMsg.setType(ProxyMessageType.HTTP_CLIENT_PROXY_CLIENT_);
|
||||
}else if (RouteType.CLIENT_PROXY_SEVER.equals(route.getRouteType())){
|
||||
proxyMsg.setType(ProxyMessageType.HTTP_CLIENT_PROXY_SERVER_);
|
||||
}else if (RouteType.SERVER_PROXY_CLIENT.equals(route.getRouteType())){
|
||||
ClientProxyRoute clientProxyRoute= (ClientProxyRoute) route;
|
||||
String clientId = clientProxyRoute.getClientId();
|
||||
String clientId = clientProxyRoute.getTargetClientId();
|
||||
proxyMsg.setClientId(clientId);
|
||||
proxyMsg.setType(ProxyMessageType.HTTP_SERVER_PROXY_CLIENT_);
|
||||
}
|
||||
|
@ -58,10 +58,13 @@ public class NettySocks5CommandRequestHandler extends SimpleChannelInboundHandle
|
||||
NettyProxyMsg proxyMsg = new NettyProxyMsg();
|
||||
|
||||
proxyMsg.setVisitorId(visitorId);
|
||||
proxyMsg.setClientTargetIp(host);
|
||||
proxyMsg.setClientTargetPort(port);
|
||||
|
||||
ProxyRoute route = RouteContext.getRoute(host, String.valueOf(port));
|
||||
String targetIp = route.getTargetIp();
|
||||
String targetPort = route.getTargetPort();
|
||||
proxyMsg.setClientTargetIp(targetIp);
|
||||
proxyMsg.setClientTargetPort(Integer.parseInt(targetPort));
|
||||
|
||||
|
||||
if(ObjectUtils.isEmpty(route)){
|
||||
proxyMsg.setType(ProxyMessageType.SOCKET_LOCAL_PROXY);
|
||||
}else {
|
||||
@ -69,14 +72,14 @@ public class NettySocks5CommandRequestHandler extends SimpleChannelInboundHandle
|
||||
proxyMsg.setType(ProxyMessageType.SOCKET_LOCAL_PROXY);
|
||||
}else if (RouteType.CLIENT_PROXY_CLIENT.equals(route.getRouteType())){
|
||||
ClientProxyRoute clientProxyRoute= (ClientProxyRoute) route;
|
||||
String clientId = clientProxyRoute.getClientId();
|
||||
String clientId = clientProxyRoute.getTargetClientId();
|
||||
proxyMsg.setClientId(clientId);
|
||||
proxyMsg.setType(ProxyMessageType.SOCKET_CLIENT_PROXY_CLIENT_);
|
||||
}else if (RouteType.CLIENT_PROXY_SEVER.equals(route.getRouteType())){
|
||||
proxyMsg.setType(ProxyMessageType.SOCKET_CLIENT_PROXY_SERVER_);
|
||||
}else if (RouteType.SERVER_PROXY_CLIENT.equals(route.getRouteType())){
|
||||
ClientProxyRoute clientProxyRoute= (ClientProxyRoute) route;
|
||||
String clientId = clientProxyRoute.getClientId();
|
||||
String clientId = clientProxyRoute.getTargetClientId();
|
||||
proxyMsg.setClientId(clientId);
|
||||
proxyMsg.setType(ProxyMessageType.SOCKET_SERVER_PROXY_CLIENT_);
|
||||
}
|
||||
|
@ -11,19 +11,29 @@ public class ClientProxyRoute implements ProxyRoute{
|
||||
|
||||
/**
|
||||
*
|
||||
* 客户端ID
|
||||
* 目标客户端ID
|
||||
*/
|
||||
private String clientId;
|
||||
private String targetClientId;
|
||||
|
||||
/**
|
||||
*
|
||||
* 虚拟IP
|
||||
*/
|
||||
private String virtualIp;
|
||||
/**
|
||||
* 虚拟端口
|
||||
*/
|
||||
private String virtualPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 路由IP
|
||||
*/
|
||||
private String allowIp;
|
||||
private String targetIp;
|
||||
/**
|
||||
* 允许代理的端口
|
||||
*/
|
||||
private String allowPort;
|
||||
private String targetPort;
|
||||
|
||||
/**
|
||||
* 路由类型
|
||||
|
@ -6,11 +6,17 @@ package org.framework.lazy.cloud.network.heartbeat.protocol.route;
|
||||
public interface ProxyRoute {
|
||||
|
||||
|
||||
public String getAllowIp();
|
||||
public String getVirtualIp();
|
||||
|
||||
|
||||
public RouteType getRouteType();
|
||||
|
||||
|
||||
public String getAllowPort();
|
||||
public String getVirtualPort();
|
||||
|
||||
|
||||
public String getTargetIp();
|
||||
|
||||
|
||||
public String getTargetPort();
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ public class RouteContext {
|
||||
|
||||
public static void setRoute(ProxyRoute route) {
|
||||
RouteType routeType = route.getRouteType();
|
||||
String allowIp = route.getAllowIp();
|
||||
String allowPort = route.getAllowPort();
|
||||
String key = allowIp + ":" + allowPort + routeType;
|
||||
String virtualIp = route.getVirtualIp();
|
||||
String virtualPort = route.getVirtualPort();
|
||||
String key = virtualIp + ":" + virtualPort + routeType;
|
||||
if (m.containsKey(key)) {
|
||||
return;
|
||||
}
|
||||
@ -27,7 +27,7 @@ public class RouteContext {
|
||||
public static ProxyRoute getRoute(String ip, String port) {
|
||||
ProxyRoute p = m.values()
|
||||
.stream()
|
||||
.filter(route -> route.getAllowIp().equals(ip) && (route.getAllowPort().equals(port) || route.getAllowPort().equals("ALL")))
|
||||
.filter(route -> route.getVirtualIp().equals(ip) && (route.getVirtualPort().equals(port) || route.getVirtualPort().equals("ALL")))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
return p;
|
||||
|
@ -16,15 +16,26 @@ public class ServerProxyRoute implements ProxyRoute {
|
||||
private String serverIp;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 虚拟IP
|
||||
*/
|
||||
private String virtualIp;
|
||||
/**
|
||||
* 虚拟端口
|
||||
*/
|
||||
private String virtualPort;
|
||||
|
||||
/**
|
||||
*
|
||||
* 路由IP
|
||||
*/
|
||||
private String allowIp;
|
||||
private String targetIp;
|
||||
/**
|
||||
* 允许代理的端口
|
||||
*/
|
||||
private String allowPort;
|
||||
private String targetPort;
|
||||
|
||||
|
||||
/**
|
||||
* 路由类型
|
||||
|
Reference in New Issue
Block a user