mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2026-02-04 15:05:54 +08:00
Compare commits
93 Commits
1.2.8-JDK1
...
1.3.0-JDK1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d2152650a | ||
|
|
e82a0c36d3 | ||
|
|
6f8e6cd8a9 | ||
|
|
cf22211114 | ||
|
|
d8a8b630ae | ||
|
|
e0f461460a | ||
|
|
75acddadca | ||
|
|
50e67f54e3 | ||
|
|
3444e90d3d | ||
|
|
b1b329aae1 | ||
|
|
26283de998 | ||
|
|
9c5000f995 | ||
|
|
532d05d4a8 | ||
|
|
402f6f0ac1 | ||
|
|
a5a3d7d6f2 | ||
|
|
e4c33f34c1 | ||
|
|
394dfdf337 | ||
|
|
9b44a199be | ||
|
|
fe8a2c865a | ||
|
|
ba8ca7bcd9 | ||
|
|
9a211ad200 | ||
|
|
40ab82de35 | ||
|
|
8728cd5d54 | ||
|
|
3f7f10bcd5 | ||
|
|
269a0f2ba2 | ||
|
|
8f02c03d42 | ||
|
|
9e1da9649e | ||
|
|
074ab4f217 | ||
|
|
07e8b20449 | ||
|
|
2a98ec0589 | ||
|
|
3321e0dd7b | ||
|
|
cf9438a7da | ||
|
|
4690bc85b3 | ||
|
|
2389a25e11 | ||
|
|
cf10347939 | ||
|
|
98b4701978 | ||
|
|
7da5f58263 | ||
|
|
a019561c06 | ||
|
|
f985cdac8f | ||
|
|
7429cff23a | ||
|
|
9fa3359569 | ||
|
|
fac28c4fc8 | ||
|
|
f9188037a0 | ||
|
|
f19b1cae68 | ||
|
|
0df0a42b2c | ||
|
|
2b3c7cb7c2 | ||
|
|
daeba59a43 | ||
|
|
cb4c9c0b41 | ||
|
|
0ceb88bfe3 | ||
|
|
42bc37c712 | ||
|
|
41a81133f1 | ||
|
|
ddaa5568e0 | ||
|
|
9b64c622cc | ||
|
|
f11200cee9 | ||
|
|
0f04f29cd0 | ||
|
|
3568292ac2 | ||
|
|
1924e87c7d | ||
|
|
30e1141ecf | ||
|
|
79b09ecfea | ||
|
|
5a079fcba8 | ||
|
|
20bb29350c | ||
|
|
ea2fb01b7e | ||
|
|
ba960a70ab | ||
|
|
4de7cdb6be | ||
|
|
1c6f56d31e | ||
|
|
8952d2277f | ||
|
|
dab6e580e4 | ||
|
|
9edb6f3d4d | ||
|
|
3740a4f4ea | ||
|
|
3b57ee1c23 | ||
|
|
b76f7a8f62 | ||
|
|
aa056dbe07 | ||
|
|
810579178f | ||
|
|
240de53888 | ||
|
|
2eb6dc2775 | ||
|
|
c665bf687d | ||
|
|
1e2f58b5a3 | ||
|
|
381f8a6960 | ||
|
|
a04499ab4b | ||
|
|
477d8cfaac | ||
|
|
b2cd1eee0a | ||
|
|
b7d571ccc1 | ||
|
|
55ce3ff359 | ||
|
|
42e8e5afec | ||
|
|
4977348113 | ||
|
|
89f9207367 | ||
|
|
70cf9fe3ac | ||
|
|
ecd5288929 | ||
|
|
571fe7893d | ||
|
|
1e89813793 | ||
|
|
0dd5b986a2 | ||
|
|
67c2537823 | ||
|
|
8dc1272109 |
25
ClientPermeateClient.md
Normal file
25
ClientPermeateClient.md
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
### 背景:国庆期间的问题,如何在老家访问杭州办公室的网络呢
|
||||
#### 实现方案:异地组网
|
||||
#### 实现语言:Java
|
||||
#### 环境:三个网络,一台拥有公网IP的服务器、一台杭州本地机房内服务器、你老家所在网络中的一台电脑(用你自己的就好了)
|
||||
#### 实现原理:
|
||||
|
||||
#### 操作步骤:拥有公网ip的服务器开发6001(web)、7001端口(tcp),然后执行命令启动服务端
|
||||
```shell
|
||||
docker run -d -it -p 6001:6001 -p 7001:7001 -e spring.profiles.active=prod -e MAIN_DB_HOST=localhost:3306 -e MAIN_DB_PASSWORD=root -e MAIN_DB_PASSWORD=root --name wu-lazy-cloud-heartbeat-server-start registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server-start:1.3.0-JDK17-SNAPSHOT
|
||||
```
|
||||
|
||||
#### 操作步骤:杭州本地机房所在网络服务器启动客户端、你老家所在网络中启动客户端,命令如下
|
||||
```shell
|
||||
docker run -d -it --privileged --name hangzhou-client --restart=always -e spring.lazy.netty.client.inet-host=公网IP -e spring.lazy.netty.client.inet-port=7001 -e spring.lazy.netty.client.client-id="hangzhou-jifang" registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.0-JDK17-SNAPSHOT
|
||||
```
|
||||
```shell
|
||||
docker run -d -it --privileged --name my-home-client --restart=always -e spring.lazy.netty.client.inet-host=公网IP -e spring.lazy.netty.client.inet-port=7001 -e spring.lazy.netty.client.client-id="my-home" registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.0-JDK17-SNAPSHOT
|
||||
```
|
||||
#### 操作步骤:配置端口
|
||||

|
||||
#### 操作步骤:打开页面配置菜单看到如下界面(from客户端ID:你老家网络中的电脑,to客户端ID)
|
||||

|
||||
|
||||
#### 连接使用:在你老家使用my-home这个客户端所在机器上的ip+13306 即可访问杭州机房内的数据库的服务3306
|
||||
61
LazyDNS.puml
Normal file
61
LazyDNS.puml
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
|
||||
@startuml
|
||||
|
||||
title 动态DNS
|
||||
|
||||
actor 访客 as User
|
||||
|
||||
package "服务端(公网)" as dns_server_{
|
||||
component [服务端私有网络A]{
|
||||
[mysql:(172.1.1.4:3306)] as dns_server_remote_local_
|
||||
[clickhouse:(172.1.1.5:3306)]
|
||||
}
|
||||
component [服务端私有网络B]{
|
||||
[mysql:(172.1.2.4:3306)]
|
||||
[clickhouse:(172.1.2.5:3306)]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package "客户端(私有网络)" as dns_remote_local_{
|
||||
|
||||
component [客户端私有网络A]{
|
||||
[mysql:(162.1.1.4:3306)] as dns_client_remote_local_
|
||||
[clickhouse:(162.1.1.5:3306)]
|
||||
}
|
||||
component [客户端私有网络B]{
|
||||
[mysql:(162.1.2.4:3306)]
|
||||
[clickhouse:(162.1.2.5:3306)]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
package "客户端(用户本地)" as dns_local_ {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
note "用户本地网络" as local_net_
|
||||
note "服务端网络" as server_net_
|
||||
note "客户端私有网络" as remote_net_
|
||||
|
||||
'(User) .... local_condition_
|
||||
'local_condition_ ... (target)
|
||||
|
||||
[User] ...right...> dns_local_: DNS连接到本地
|
||||
dns_local_ ...right...> local_net_: 访问本地网络(本地DNS)
|
||||
dns_local_ ...up...> dns_server_remote_local_: 远程DNS解析
|
||||
|
||||
dns_server_ ...up...> server_net_: server本地的网络
|
||||
dns_server_ ...down...> dns_remote_local_: 访问的地址在远程的客户端中
|
||||
dns_remote_local_ ...down...> dns_client_remote_local_: 远程客户端所在的私有网络
|
||||
dns_remote_local_ ...down...> remote_net_: 远程客户端中的其他网络
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@enduml
|
||||
|
||||
20
README.md
20
README.md
@@ -208,7 +208,7 @@ public class NettyClientSocket {
|
||||
log.info("连接服务端成功");
|
||||
// 告诉服务端这条连接是client的连接
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.REPORT_CLIENT_CONNECT_SUCCESS);
|
||||
nettyMsg.setType(MessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS);
|
||||
nettyMsg.setClientId(clientId);
|
||||
nettyMsg.setData((clientId).getBytes());
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||
@@ -260,21 +260,21 @@ public class NettyClientSocket {
|
||||
|
||||
| 模块 | 版本 | 描述 |
|
||||
|------------------------------------------------------------------------------------------------------------|----------------------|------------------------------|
|
||||
| [wu-lazy-cloud-heartbeat-common](wu-lazy-cloud-heartbeat-common) | 1.2.8-JDK17-SNAPSHOT | 内网穿透公共模块(声明接口、枚举、常量、适配器、解析器) |
|
||||
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 1.2.8-JDK17-SNAPSHOT | 客户端(支持二次开发) |
|
||||
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 1.2.8-JDK17-SNAPSHOT | 服务端(支持二次开发) |
|
||||
| [wu-lazy-cloud-heartbeat-client-start](wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-server-start) | 1.2.8-JDK17-SNAPSHOT | 客户端样例 |
|
||||
| [wu-lazy-cloud-heartbeat-server-start](wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-client-start) | 1.2.8-JDK17-SNAPSHOT | 服务端样例 |
|
||||
| [wu-lazy-cloud-heartbeat-common](wu-lazy-cloud-heartbeat-common) | 1.3.0-JDK17-SNAPSHOT | 内网穿透公共模块(声明接口、枚举、常量、适配器、解析器) |
|
||||
| [wu-lazy-cloud-heartbeat-client](wu-lazy-cloud-heartbeat-client) | 1.3.0-JDK17-SNAPSHOT | 客户端(支持二次开发) |
|
||||
| [wu-lazy-cloud-heartbeat-server](wu-lazy-cloud-heartbeat-server) | 1.3.0-JDK17-SNAPSHOT | 服务端(支持二次开发) |
|
||||
| [wu-lazy-cloud-heartbeat-client-start](wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-server-start) | 1.3.0-JDK17-SNAPSHOT | 客户端样例 |
|
||||
| [wu-lazy-cloud-heartbeat-server-start](wu-lazy-cloud-heartbeat-start/wu-lazy-cloud-heartbeat-client-start) | 1.3.0-JDK17-SNAPSHOT | 服务端样例 |
|
||||
|
||||
### 使用技术
|
||||
|
||||
| 框架 | 版本 | 描述 |
|
||||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|--------------|
|
||||
| spring-boot | 3.0.7 | springboot框架 |
|
||||
| [wu-framework-web](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-framework-web) | 1.2.8-JDK17-SNAPSHOT | web容器 |
|
||||
| [Lazy -ORM](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-inner-intergration/wu-database-parent) | 1.2.8-JDK17-SNAPSHOT | ORM |
|
||||
| [wu-framework-web](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-framework-web) | 1.3.0-JDK17-SNAPSHOT | web容器 |
|
||||
| [Lazy -ORM](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-inner-intergration/wu-database-parent) | 1.3.0-JDK17-SNAPSHOT | ORM |
|
||||
| mysql-connector-j | 8.0.33 | mysql驱动 |
|
||||
| [wu-authorization-server-platform-starter](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-smart-platform/wu-authorization-server-platform-starter) | 1.2.8-JDK17-SNAPSHOT | 用户授权体系 |
|
||||
| [wu-authorization-server-platform-starter](https://gitee.com/wujiawei1207537021/wu-framework-parent/tree/master/wu-smart-platform/wu-authorization-server-platform-starter) | 1.3.0-JDK17-SNAPSHOT | 用户授权体系 |
|
||||
|
||||
### 使用环境
|
||||
|
||||
@@ -287,7 +287,7 @@ public class NettyClientSocket {
|
||||
|
||||
docker启动
|
||||
|
||||
docker run -d -it -p 18080:18080 --name wu-lazy-cloud-heartbeat-server registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.2.8-JDK17-SNAPSHOT
|
||||
docker run -d -it -p 18080:18080 --name wu-lazy-cloud-heartbeat-server registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-server:1.3.0-JDK17-SNAPSHOT
|
||||
|
||||
http://127.0.0.1:18080/swagger-ui/index.html
|
||||
|
||||
|
||||
489
client-k8s.yaml
Normal file
489
client-k8s.yaml
Normal file
@@ -0,0 +1,489 @@
|
||||
|
||||
---
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
namespace: default
|
||||
labels:
|
||||
k8s.kuboard.cn/layer: monitor
|
||||
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
annotations:
|
||||
k8s.kuboard.cn/displayName: 内网穿透服务端(云下)
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
k8s.kuboard.cn/layer: monitor
|
||||
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
k8s.kuboard.cn/layer: monitor
|
||||
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
annotations:
|
||||
kubectl.kubernetes.io/restartedAt: '2025-01-16T22:39:39+08:00'
|
||||
spec:
|
||||
containers:
|
||||
- name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
image: >-
|
||||
registry.cn-hangzhou.aliyuncs.com/wu-lazy/wu-lazy-cloud-heartbeat-client-start:1.3.0-JDK17-SNAPSHOT
|
||||
env:
|
||||
- name: spring.lazy.netty.client.inet-host
|
||||
value: 124.222.48.62
|
||||
- name: spring.lazy.netty.client.inet-port
|
||||
value: '30560'
|
||||
- name: spring.lazy.netty.client.client-id
|
||||
value: tencent
|
||||
- name: JAVA_OPTS
|
||||
value: '-Xms32m -Xmx64m'
|
||||
- name: logging1.level.root
|
||||
value: DEBUG
|
||||
resources: {}
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
imagePullPolicy: Always
|
||||
securityContext:
|
||||
privileged: true
|
||||
runAsUser: 0
|
||||
restartPolicy: Always
|
||||
terminationGracePeriodSeconds: 30
|
||||
dnsPolicy: ClusterFirst
|
||||
securityContext: {}
|
||||
schedulerName: default-scheduler
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 25%
|
||||
maxSurge: 25%
|
||||
revisionHistoryLimit: 10
|
||||
progressDeadlineSeconds: 600
|
||||
|
||||
---
|
||||
kind: StatefulSet
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: cloud-mysql
|
||||
namespace: default
|
||||
labels:
|
||||
k8s.eip.work/layer: db
|
||||
k8s.eip.work/name: cloud-mysql
|
||||
k8s.kuboard.cn/name: cloud-mysql
|
||||
annotations:
|
||||
analysis.crane.io/replicas-recommendation: |
|
||||
replicas: 1
|
||||
analysis.crane.io/resource-recommendation: |
|
||||
containers:
|
||||
- containerName: mysql
|
||||
target:
|
||||
cpu: 229m
|
||||
memory: 2070Mi
|
||||
k8s.eip.work/displayName: 数据库
|
||||
k8s.eip.work/ingress: 'false'
|
||||
k8s.eip.work/service: NodePort
|
||||
k8s.eip.work/workload: cloud-mysql
|
||||
k8s.kuboard.cn/workload: cloud-mysql
|
||||
spec:
|
||||
replicas: 0
|
||||
selector:
|
||||
matchLabels:
|
||||
k8s.eip.work/layer: db
|
||||
k8s.eip.work/name: cloud-mysql
|
||||
k8s.kuboard.cn/name: cloud-mysql
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
k8s.eip.work/layer: db
|
||||
k8s.eip.work/name: cloud-mysql
|
||||
k8s.kuboard.cn/name: cloud-mysql
|
||||
annotations:
|
||||
kubectl.kubernetes.io/restartedAt: '2023-10-07T09:38:51+08:00'
|
||||
spec:
|
||||
volumes:
|
||||
- name: mysql-cnf-map
|
||||
configMap:
|
||||
name: mysql-cnf
|
||||
items:
|
||||
- key: cnf
|
||||
path: custom.cnf
|
||||
defaultMode: 420
|
||||
- name: tz
|
||||
hostPath:
|
||||
path: /usr/share/zoneinfo/Asia/Shanghai
|
||||
type: File
|
||||
containers:
|
||||
- name: mysql
|
||||
image: 'mysql:8.0.28'
|
||||
env:
|
||||
- name: MYSQL_ROOT_PASSWORD
|
||||
value: wujiawei
|
||||
resources:
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 256Mi
|
||||
requests:
|
||||
cpu: 500m
|
||||
memory: 256Mi
|
||||
volumeMounts:
|
||||
- name: mysql-data
|
||||
mountPath: /var/lib/mysql
|
||||
- name: mysql-cnf-map
|
||||
mountPath: /etc/mysql/conf.d/custom.cnf
|
||||
subPath: custom.cnf
|
||||
- name: tz
|
||||
mountPath: /etc/localtime
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
imagePullPolicy: IfNotPresent
|
||||
restartPolicy: Always
|
||||
terminationGracePeriodSeconds: 30
|
||||
dnsPolicy: ClusterFirst
|
||||
securityContext: {}
|
||||
schedulerName: default-scheduler
|
||||
volumeClaimTemplates:
|
||||
- kind: PersistentVolumeClaim
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: mysql-data
|
||||
creationTimestamp: null
|
||||
annotations:
|
||||
k8s.eip.work/pvcType: Dynamic
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteMany
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
storageClassName: nfs-storage
|
||||
volumeMode: Filesystem
|
||||
status:
|
||||
phase: Pending
|
||||
serviceName: cloud-mysql
|
||||
podManagementPolicy: OrderedReady
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
partition: 0
|
||||
revisionHistoryLimit: 10
|
||||
persistentVolumeClaimRetentionPolicy:
|
||||
whenDeleted: Retain
|
||||
whenScaled: Retain
|
||||
|
||||
---
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: cloud-mysql
|
||||
namespace: default
|
||||
labels:
|
||||
k8s.eip.work/layer: db
|
||||
k8s.eip.work/name: cloud-mysql
|
||||
k8s.kuboard.cn/name: cloud-mysql
|
||||
spec:
|
||||
ports:
|
||||
- name: zmac2s
|
||||
protocol: TCP
|
||||
port: 3306
|
||||
targetPort: 3306
|
||||
nodePort: 30512
|
||||
selector:
|
||||
k8s.eip.work/layer: db
|
||||
k8s.eip.work/name: cloud-mysql
|
||||
type: NodePort
|
||||
sessionAffinity: None
|
||||
externalTrafficPolicy: Cluster
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
ipFamilyPolicy: SingleStack
|
||||
internalTrafficPolicy: Cluster
|
||||
|
||||
---
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
namespace: default
|
||||
labels:
|
||||
k8s.kuboard.cn/layer: monitor
|
||||
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
spec:
|
||||
ports:
|
||||
- name: net
|
||||
protocol: TCP
|
||||
port: 6001
|
||||
targetPort: 6001
|
||||
- name: nas
|
||||
protocol: TCP
|
||||
port: 100
|
||||
targetPort: 100
|
||||
- name: kuboard
|
||||
protocol: TCP
|
||||
port: 101
|
||||
targetPort: 101
|
||||
- name: netty-client
|
||||
protocol: TCP
|
||||
port: 6004
|
||||
targetPort: 6004
|
||||
- name: nas-web-dav
|
||||
protocol: TCP
|
||||
port: 102
|
||||
targetPort: 102
|
||||
- name: rustdesk
|
||||
protocol: TCP
|
||||
port: 103
|
||||
targetPort: 103
|
||||
- name: nastool
|
||||
protocol: TCP
|
||||
port: 104
|
||||
targetPort: 104
|
||||
- name: jellyfin
|
||||
protocol: TCP
|
||||
port: 105
|
||||
targetPort: 105
|
||||
- name: qb
|
||||
protocol: TCP
|
||||
port: 106
|
||||
targetPort: 106
|
||||
- name: jackett
|
||||
protocol: TCP
|
||||
port: 107
|
||||
targetPort: 107
|
||||
- name: rustdesk-tcp
|
||||
protocol: TCP
|
||||
port: 108
|
||||
targetPort: 108
|
||||
- name: rustdesk-ip-tcp
|
||||
protocol: TCP
|
||||
port: 109
|
||||
targetPort: 109
|
||||
- name: rustdesk-ip-udp
|
||||
protocol: UDP
|
||||
port: 109
|
||||
targetPort: 109
|
||||
- name: nas-ssh
|
||||
protocol: TCP
|
||||
port: 110
|
||||
targetPort: 110
|
||||
selector:
|
||||
k8s.kuboard.cn/layer: monitor
|
||||
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
type: ClusterIP
|
||||
sessionAffinity: None
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
ipFamilyPolicy: SingleStack
|
||||
internalTrafficPolicy: Cluster
|
||||
|
||||
---
|
||||
kind: Ingress
|
||||
apiVersion: networking.k8s.io/v1
|
||||
metadata:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
namespace: default
|
||||
labels:
|
||||
k8s.kuboard.cn/layer: monitor
|
||||
k8s.kuboard.cn/name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
rules:
|
||||
- host: net.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 6001
|
||||
- host: nas.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 100
|
||||
- host: kuboard.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 101
|
||||
- host: client.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 6004
|
||||
- host: nas-dav.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 102
|
||||
- host: rustdesk.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 103
|
||||
- host: nastool.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 104
|
||||
- host: jellyfin.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 105
|
||||
- host: qb.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 106
|
||||
- host: jackett.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 107
|
||||
- host: rustdesk-tcp.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 108
|
||||
- host: rustdesk-ip.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 109
|
||||
- host: nas-ssh.wu-framework.cn
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: wu-lazy-cloud-heartbeat-local-client-start
|
||||
port:
|
||||
number: 110
|
||||
|
||||
---
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: mysql-cnf
|
||||
namespace: default
|
||||
data:
|
||||
cnf: >-
|
||||
[mysql]
|
||||
|
||||
no-auto-rehash
|
||||
|
||||
[mysqld]
|
||||
|
||||
skip-host-cache
|
||||
|
||||
skip-name-resolve
|
||||
|
||||
max_connections=100
|
||||
|
||||
lower_case_table_names=0
|
||||
|
||||
table_open_cache=64
|
||||
|
||||
default-time-zone='+08:00'
|
||||
|
||||
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
|
||||
|
||||
log_timestamps='SYSTEM'
|
||||
|
||||
performance_schema_max_table_instances=400 #设置效果不明显
|
||||
|
||||
performance_schema=off #效果明显
|
||||
|
||||
table_definition_cache=400
|
||||
|
||||
slow_query_log=ON
|
||||
|
||||
binlog_expire_logs_seconds = 2
|
||||
|
||||
innodb_flush_log_at_trx_commit=2
|
||||
|
||||
group_concat_max_len=512
|
||||
|
||||
# 全局参数
|
||||
|
||||
innodb_buffer_pool_size = 20M
|
||||
|
||||
innodb_buffer_pool_chunk_size=20M #效果不明显
|
||||
|
||||
key_buffer_size = 1M
|
||||
|
||||
# 排序和连接参数
|
||||
|
||||
sort_buffer_size = 256K
|
||||
|
||||
join_buffer_size = 256K
|
||||
|
||||
# 线程缓存参数
|
||||
|
||||
thread_cache_size = 4
|
||||
|
||||
# 日志参数
|
||||
|
||||
innodb_log_file_size = 5M
|
||||
|
||||
innodb_log_buffer_size = 1M
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 130 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 114 KiB |
123
pom.xml
123
pom.xml
@@ -8,12 +8,12 @@
|
||||
<parent>
|
||||
<artifactId>wu-framework-parent</artifactId>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<version>1.2.8-JDK17-SNAPSHOT</version>
|
||||
<version>1.3.0-JDK17</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>wu-lazy-cloud-network</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.2.8-JDK17-SNAPSHOT</version>
|
||||
<version>1.3.0-JDK17</version>
|
||||
<description>云上云下</description>
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
<module>wu-lazy-cloud-heartbeat-server-cluster</module>
|
||||
<module>wu-lazy-cloud-heartbeat-client</module>
|
||||
<module>wu-lazy-cloud-heartbeat-common</module>
|
||||
<module>wu-lazy-cloud-heartbeat-dns</module>
|
||||
<module>wu-lazy-cloud-heartbeat-protocol-proxy</module>
|
||||
|
||||
<!-- 样例 -->
|
||||
<module>wu-lazy-cloud-heartbeat-start</module>
|
||||
@@ -70,7 +72,7 @@
|
||||
<dependency>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-framework-dependencies</artifactId>
|
||||
<version>1.2.8-JDK17-SNAPSHOT</version>
|
||||
<version>1.3.0-JDK17</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -175,55 +177,96 @@
|
||||
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Spring-Boot-Native-Processed>true</Spring-Boot-Native-Processed>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<image>
|
||||
<builder>paketobuildpacks/builder-jammy-tiny:latest</builder>
|
||||
<env>
|
||||
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
|
||||
</env>
|
||||
</image>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>process-aot</id>
|
||||
<goals>
|
||||
<goal>process-aot</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
|
||||
<requiredVersion>22.3</requiredVersion>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-reachability-metadata</id>
|
||||
<goals>
|
||||
<goal>add-reachability-metadata</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>nativeTest</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>process-test-aot</id>
|
||||
<goals>
|
||||
<goal>process-test-aot</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
<version>0.9.28</version>
|
||||
<!-- 使用graalvm提供的可达性元数据,很多第三方库就直接可以构建成可执行文件了 -->
|
||||
<configuration>
|
||||
<!-- for agent -->
|
||||
<agent>
|
||||
<defaultMode>Standard</defaultMode>
|
||||
<options>
|
||||
<builtinCallerFilter>true</builtinCallerFilter>
|
||||
<builtinHeuristicFilter>true</builtinHeuristicFilter>
|
||||
<enableExperimentalPredefinedClasses>true
|
||||
</enableExperimentalPredefinedClasses>
|
||||
<enableExperimentalUnsafeAllocationTracing>true
|
||||
</enableExperimentalUnsafeAllocationTracing>
|
||||
<trackReflectionMetadata>true</trackReflectionMetadata>
|
||||
</options>
|
||||
<metadataCopy>
|
||||
<merge>true</merge>
|
||||
</metadataCopy>
|
||||
</agent>
|
||||
<!-- for metadata repository -->
|
||||
<metadataRepository>
|
||||
<enabled>true</enabled>
|
||||
</metadataRepository>
|
||||
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
|
||||
<requiredVersion>22.3</requiredVersion>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-reachability-metadata</id>
|
||||
<goals>
|
||||
<goal>add-reachability-metadata</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-native</id>
|
||||
<id>native-test</id>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<phase>test</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>build-native</id>
|
||||
<goals>
|
||||
<goal>compile-no-fork</goal>
|
||||
</goals>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
@@ -24,5 +24,10 @@
|
||||
[change] 新增服务端渗透服务端----本地同局域网内端口映射
|
||||
[change] 新增客户端渗透服务端----本地端口映射到另一个服务端中的局域网端口
|
||||
[change] 新增客户端渗透客户端----本地端口映射到另一个局域网端口
|
||||
|
||||
#### 1.3.0-JDK17-SNAPSHOT
|
||||
[change] 添加appkey&appsecret 验证
|
||||
[change] 支持同一个客户端ID多次注册
|
||||
[change] 修复通道关闭导致调度线程池submit异常问题
|
||||
[change] 添加记录客户端IP
|
||||
[change] 1.2.9为大版本,报文中添加数据无法向下兼容,建议服务端与客户端保持版本一致
|
||||
#### 下一版本计划https
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-lazy-cloud-network</artifactId>
|
||||
<version>1.2.8-JDK17-SNAPSHOT</version>
|
||||
<version>1.3.0-JDK17</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-lazy-cloud-heartbeat-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>top.wu2020</groupId>
|
||||
<artifactId>wu-lazy-cloud-heartbeat-protocol-proxy</artifactId>
|
||||
<version>1.3.0-JDK17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
|
||||
@@ -5,5 +5,5 @@ import org.wu.framework.lazy.orm.core.stereotype.LazyScan;
|
||||
|
||||
@ComponentScan(basePackages = "org.framework.lazy.cloud.network.heartbeat.client")
|
||||
@LazyScan(scanBasePackages = "org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity")
|
||||
public class EnableHeartbeatClientAutoConfiguration {
|
||||
public class EnableClientAutoConfiguration {
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.application;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
|
||||
|
||||
/**
|
||||
* 客户端状态变更事件
|
||||
|
||||
@@ -66,7 +66,17 @@ public class LazyNettyServerPropertiesQueryListCommand {
|
||||
*/
|
||||
@Schema(description ="类型(配置、DB)",name ="type",example = "")
|
||||
private PropertiesType type;
|
||||
/**
|
||||
* 令牌key
|
||||
*/
|
||||
@Schema(description = "令牌key", name = "appKey", example = "")
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
@Schema(description = "令牌密钥", name = "appSecret", example = "")
|
||||
private String appSecret;
|
||||
/**
|
||||
*
|
||||
* 更新时间
|
||||
|
||||
@@ -65,7 +65,17 @@ public class LazyNettyServerPropertiesQueryOneCommand {
|
||||
*/
|
||||
@Schema(description ="类型(配置、DB)",name ="type",example = "")
|
||||
private PropertiesType type;
|
||||
/**
|
||||
* 令牌key
|
||||
*/
|
||||
@Schema(description = "令牌key", name = "appKey", example = "")
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
@Schema(description = "令牌密钥", name = "appSecret", example = "")
|
||||
private String appSecret;
|
||||
/**
|
||||
*
|
||||
* 更新时间
|
||||
|
||||
@@ -66,7 +66,17 @@ public class LazyNettyServerPropertiesRemoveCommand {
|
||||
*/
|
||||
@Schema(description ="类型(配置、DB)",name ="type",example = "")
|
||||
private PropertiesType type;
|
||||
/**
|
||||
* 令牌key
|
||||
*/
|
||||
@Schema(description = "令牌key", name = "appKey", example = "")
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
@Schema(description = "令牌密钥", name = "appSecret", example = "")
|
||||
private String appSecret;
|
||||
/**
|
||||
*
|
||||
* 更新时间
|
||||
|
||||
@@ -65,7 +65,17 @@ public class LazyNettyServerPropertiesStoryCommand {
|
||||
*/
|
||||
@Schema(description ="类型(配置、DB)",name ="type",example = "")
|
||||
private PropertiesType type;
|
||||
/**
|
||||
* 令牌key
|
||||
*/
|
||||
@Schema(description = "令牌key", name = "appKey", example = "")
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
@Schema(description = "令牌密钥", name = "appSecret", example = "")
|
||||
private String appSecret;
|
||||
/**
|
||||
*
|
||||
* 更新时间
|
||||
|
||||
@@ -65,7 +65,17 @@ public class LazyNettyServerPropertiesUpdateCommand {
|
||||
*/
|
||||
@Schema(description ="类型(配置、DB)",name ="type",example = "")
|
||||
private PropertiesType type;
|
||||
/**
|
||||
* 令牌key
|
||||
*/
|
||||
@Schema(description = "令牌key", name = "appKey", example = "")
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
@Schema(description = "令牌密钥", name = "appSecret", example = "")
|
||||
private String appSecret;
|
||||
/**
|
||||
*
|
||||
* 更新时间
|
||||
|
||||
@@ -65,7 +65,17 @@ public class LazyNettyServerPropertiesDTO {
|
||||
*/
|
||||
@Schema(description ="类型(配置、DB)",name ="type",example = "")
|
||||
private PropertiesType type;
|
||||
/**
|
||||
* 令牌key
|
||||
*/
|
||||
@Schema(description = "令牌key", name = "appKey", example = "")
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
@Schema(description = "令牌密钥", name = "appSecret", example = "")
|
||||
private String appSecret;
|
||||
/**
|
||||
*
|
||||
* 更新时间
|
||||
|
||||
@@ -2,18 +2,21 @@ package org.framework.lazy.cloud.network.heartbeat.client.application.impl;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.application.assembler.LazyNettyServerPropertiesDTOAssembler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.application.dto.LazyNettyServerPropertiesDTO;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerPropertiesRepository;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.application.LazyNettyServerPropertiesApplication;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.application.assembler.LazyNettyServerPropertiesDTOAssembler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.application.command.lazy.netty.server.properties.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.application.dto.LazyNettyServerPropertiesDTO;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerPropertiesRepository;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.socket.NettyUdpClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
|
||||
import org.wu.framework.core.NormalUsedString;
|
||||
import org.wu.framework.database.lazy.web.plus.stereotype.LazyApplication;
|
||||
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
|
||||
@@ -186,16 +189,35 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
|
||||
String inetHost = lazyNettyServerProperties.getInetHost();
|
||||
Integer inetPort = lazyNettyServerProperties.getInetPort();
|
||||
String clientId = lazyNettyServerProperties.getClientId();
|
||||
String appKey = lazyNettyServerProperties.getAppKey();
|
||||
String appSecret = lazyNettyServerProperties.getAppSecret();
|
||||
ProtocolType protocolType = lazyNettyServerProperties.getProtocolType();
|
||||
NettyClientSocket nettyClientSocket;
|
||||
if (ProtocolType.TCP.equals(protocolType)) {
|
||||
nettyClientSocket = new
|
||||
NettyTcpClientSocket(inetHost, inetPort, clientId,
|
||||
NormalUsedString.DEFAULT, appKey, appSecret,
|
||||
clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
} else if (ProtocolType.UDP.equals(protocolType)) {
|
||||
nettyClientSocket = new
|
||||
NettyUdpClientSocket(inetHost, inetPort, clientId,
|
||||
NormalUsedString.DEFAULT, appKey, appSecret,
|
||||
clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
} else {
|
||||
nettyClientSocket = null;
|
||||
}
|
||||
|
||||
if (nettyClientSocket == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
NettyClientSocket nettyClientSocket = new
|
||||
NettyClientSocket(inetHost, inetPort, clientId,
|
||||
NormalUsedString.DEFAULT,
|
||||
clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
cacheNettyClientSocketMap.put(lazyNettyServerProperties, nettyClientSocket);
|
||||
|
||||
// 更新状态为运行中
|
||||
lazyNettyServerProperties.setConnectStatus(NettyClientStatus.RUNNING);
|
||||
lazyNettyServerPropertiesRepository.story(lazyNettyServerProperties);
|
||||
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
nettyClientSocket.newConnect2Server();
|
||||
@@ -235,7 +257,7 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
|
||||
@Override
|
||||
public void destroyOneClientSocket(LazyNettyServerProperties needCloseLazyNettyServerProperties) {
|
||||
// 关闭指定socket
|
||||
cacheNettyClientSocketMap.forEach(((nettyServerProperties, nettyClientSocket) -> {
|
||||
cacheNettyClientSocketMap.forEach(((nettyServerProperties, nettyTcpClientSocket) -> {
|
||||
String clientId = nettyServerProperties.getClientId();
|
||||
String inetHost = nettyServerProperties.getInetHost();
|
||||
Integer inetPort = nettyServerProperties.getInetPort();
|
||||
@@ -245,7 +267,7 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
|
||||
if (Objects.equals(clientId, needCloseClientId)
|
||||
&& Objects.equals(inetPort, needCloseInetPort)
|
||||
&& Objects.equals(inetHost, needCloseInetHost)) {
|
||||
nettyClientSocket.shutdown();
|
||||
nettyTcpClientSocket.shutdown();
|
||||
// 关闭客户端:{}与服务端连接:{}:{}
|
||||
log.warn("Close client: {} Connect to server: {}: {}", clientId, inetHost, inetPort);
|
||||
}
|
||||
@@ -258,8 +280,8 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
|
||||
@Override
|
||||
public void destroyClientSocket() {
|
||||
// 关闭socket
|
||||
cacheNettyClientSocketMap.forEach(((nettyServerProperties, nettyClientSocket) -> {
|
||||
nettyClientSocket.shutdown();
|
||||
cacheNettyClientSocketMap.forEach(((nettyServerProperties, nettyTcpClientSocket) -> {
|
||||
nettyTcpClientSocket.shutdown();
|
||||
String clientId = nettyServerProperties.getClientId();
|
||||
String inetHost = nettyServerProperties.getInetHost();
|
||||
Integer inetPort = nettyServerProperties.getInetPort();
|
||||
|
||||
@@ -1,82 +1,386 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.config;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientSocket;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.context.NettyClientSocketApplicationListener;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced.*;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.wu.framework.core.NormalUsedString;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Role;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* description 自动配置
|
||||
*
|
||||
* @author 吴佳伟
|
||||
* @date 2023/09/12 18:22
|
||||
* @see InitConfig
|
||||
*/
|
||||
@Deprecated
|
||||
@Slf4j
|
||||
public class ClientAutoConfiguration implements CommandLineRunner {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
private final ClientChangeEvent clientChangeEvent;
|
||||
|
||||
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList; // 处理服务端发送过来的数据类型
|
||||
@Import({NettyClientSocketApplicationListener.class})
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@ConditionalOnProperty(prefix = NettyClientProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class ClientAutoConfiguration {
|
||||
|
||||
|
||||
public static final ThreadPoolExecutor NETTY_CLIENT_EXECUTOR = new ThreadPoolExecutor(1, 1, 200, TimeUnit.MILLISECONDS,
|
||||
new ArrayBlockingQueue<>(1));
|
||||
@Configuration()
|
||||
static class ClientTcpConfiguration {
|
||||
/**
|
||||
* 服务端 处理客户端心跳
|
||||
*
|
||||
* @return ClientHandleTcpChannelHeartbeatTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleTcpChannelHeartbeatTypeAdvanced clientHandleTcpChannelHeartbeatTypeAdvanced() {
|
||||
return new ClientHandleTcpChannelHeartbeatTypeAdvanced();
|
||||
}
|
||||
|
||||
public ClientAutoConfiguration(NettyClientProperties nettyClientProperties,
|
||||
ClientChangeEvent clientChangeEvent,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
this.clientChangeEvent = clientChangeEvent;
|
||||
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
|
||||
/**
|
||||
* 处理 客户端代理的真实端口自动读写
|
||||
*
|
||||
* @return ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced clientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 接收服务端发送过来的聊天信息
|
||||
*
|
||||
* @return ClientHandleTcpDistributeSingleClientMessageTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeSingleClientMessageTypeAdvanced clientHandleTcpDistributeSingleClientMessageTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeSingleClientMessageTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透服务端数据传输通道连接成功
|
||||
*
|
||||
* @return ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
* @return ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced clientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced clientHandleTcpDistributeClientTransferClientRequestTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced clientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced clientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute clientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle clientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
return new ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle(clientChangeEvent);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpClientChannelActiveAdvanced clientHandleTcpClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleTcpClientChannelActiveAdvanced(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeDisconnectTypeAdvancedHandle clientHandleTcpDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
return new ClientHandleTcpDistributeDisconnectTypeAdvancedHandle(clientChangeEvent);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeStagingClosedTypeAdvanced clientHandleTcpDistributeStagingClosedTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeStagingClosedTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeStagingOpenedTypeAdvanced clientHandleTcpDistributeStagingOpenedTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeStagingOpenedTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透服务端init信息
|
||||
*
|
||||
* @return ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced clientHandleTcpDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced(nettyClientProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @return ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced clientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced clientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced clientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced clientHandleTcpDistributeClientPermeateClientInitTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced clientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced clientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced(
|
||||
NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced clientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced() {
|
||||
return new ClientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced();
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration()
|
||||
static class ClientUdpConfiguration {
|
||||
/**
|
||||
* 服务端 处理客户端心跳
|
||||
*
|
||||
* @return ClientHandleUdpChannelHeartbeatTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleUdpChannelHeartbeatTypeAdvanced clientHandleUdpChannelHeartbeatTypeAdvanced() {
|
||||
return new ClientHandleUdpChannelHeartbeatTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
public NettyClientSocket nettyClientSocket() {
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
return new NettyClientSocket(inetHost, inetPort, clientId, NormalUsedString.DEFAULT, clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
/**
|
||||
* 处理 客户端代理的真实端口自动读写
|
||||
*
|
||||
* @return ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced clientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 接收服务端发送过来的聊天信息
|
||||
*
|
||||
* @return ClientHandleUdpDistributeSingleClientMessageTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeSingleClientMessageTypeAdvanced clientHandleUdpDistributeSingleClientMessageTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeSingleClientMessageTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透服务端数据传输通道连接成功
|
||||
*
|
||||
* @return ClientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
* @return ClientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced clientHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientTransferClientRequestTypeAdvanced clientHandleUdpDistributeClientTransferClientRequestTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientTransferClientRequestTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced clientHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeSingleClientRealCloseVisitorTypeAdvanced clientHandleUdpDistributeSingleClientRealCloseVisitorTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeSingleClientRealCloseVisitorTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute clientHandleUdpChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle clientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
return new ClientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle(clientChangeEvent);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpClientChannelActiveAdvanced clientHandleUdpClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleUdpClientChannelActiveAdvanced(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeDisconnectTypeAdvancedHandle clientHandleUdpDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
return new ClientHandleUdpDistributeDisconnectTypeAdvancedHandle(clientChangeEvent);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeStagingClosedTypeAdvanced clientHandleUdpDistributeStagingClosedTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeStagingClosedTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeStagingOpenedTypeAdvanced clientHandleUdpDistributeStagingOpenedTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeStagingOpenedTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透服务端init信息
|
||||
*
|
||||
* @return ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced clientHandleUdpDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced(nettyClientProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @return ClientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced clientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientPermeateServerTransferTypeAdvanced clientHandleUdpDistributeClientPermeateServerTransferTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientPermeateServerTransferTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientPermeateClientCloseTypeAdvanced clientHandleUdpDistributeClientPermeateClientCloseTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientPermeateClientCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientPermeateClientInitTypeAdvanced clientHandleUdpDistributeClientPermeateClientInitTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientPermeateClientInitTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced clientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced clientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced(
|
||||
NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced clientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced() {
|
||||
return new ClientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
@Configuration
|
||||
static class HttpProxyConfiguration {
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeHttpClientProxyServerTransferTypeAdvanced clientHandleDistributeHttpClientProxyServerTypeAdvanced() {
|
||||
return new ClientHandleDistributeHttpClientProxyServerTransferTypeAdvanced();
|
||||
}
|
||||
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
NettyClientSocket nettyClientSocket = new NettyClientSocket(
|
||||
inetHost, inetPort,
|
||||
clientId, NormalUsedString.DEFAULT,
|
||||
clientChangeEvent, handleChannelTypeAdvancedList);
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
nettyClientSocket.newConnect2Server();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleHttpClientProxyClientTypeAdvanced clientHandleHttpClientClientProxyClientTypeAdvanced() {
|
||||
return new ClientHandleHttpClientProxyClientTypeAdvanced();
|
||||
}
|
||||
|
||||
});
|
||||
log.info("当前服务连接Netty客户端:{},Netty端口:{}", inetHost, inetPort);
|
||||
NETTY_CLIENT_EXECUTOR.execute(thread);
|
||||
@Bean
|
||||
public ClientHandleHttpClientProxyServerTypeAdvanced clientHandleHttpClientClientProxyServerTypeAdvanced() {
|
||||
return new ClientHandleHttpClientProxyServerTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeHttpClientProxyServerServerRouteTypeAdvanced clientHandleDistributeHttpClientProxyServerServerRouteTypeAdvanced() {
|
||||
return new ClientHandleDistributeHttpClientProxyServerServerRouteTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeHttpClientProxyServerClientRouteTypeAdvanced clientHandleDistributeHttpClientProxyServerClientRouteTypeAdvanced() {
|
||||
return new ClientHandleDistributeHttpClientProxyServerClientRouteTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeHttpClientProxyClientConnectionTransferSuccessfulAdvanced clientHandleDistributeHttpClientProxyClientConnectionTransferSuccessfulAdvanced() {
|
||||
return new ClientHandleDistributeHttpClientProxyClientConnectionTransferSuccessfulAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeHttpClientProxyClientTransferRequestAdvanced clientHandleDistributeHttpClientProxyClientTransferRequestAdvanced() {
|
||||
return new ClientHandleDistributeHttpClientProxyClientTransferRequestAdvanced();
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleHttpDistributeClientProxyClientTransferResponseTypeAdvanced clientHandleHttpDistributeClientProxyClientTransferResponseTypeAdvanced(){
|
||||
return new ClientHandleHttpDistributeClientProxyClientTransferResponseTypeAdvanced();
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvanced clientHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvanced(){
|
||||
return new ClientHandleHttpDistributeClientProxyClientTransferCLoseTypeAdvanced();
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleDistributeHttpServerProxyClientConnectionSuccessfulTypeAdvanced clientHandleDistributeHttpServerProxyClientConnectionSuccessfulTypeAdvanced(){
|
||||
return new ClientHandleDistributeHttpServerProxyClientConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleDistributeHttpServerProxyClientTransferRequestAdvanced clientHandleDistributeHttpServerProxyClientTransferRequestAdvanced(){
|
||||
return new ClientHandleDistributeHttpServerProxyClientTransferRequestAdvanced();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.config;
|
||||
|
||||
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Role;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@ConditionalOnProperty(prefix = NettyClientProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class HeartbeatClientConfiguration {
|
||||
|
||||
/**
|
||||
* 服务端 处理客户端心跳
|
||||
*
|
||||
* @return ClientHandleChannelHeartbeatTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleChannelHeartbeatTypeAdvanced clientChannelHeartbeatTypeAdvanced() {
|
||||
return new ClientHandleChannelHeartbeatTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端代理的真实端口自动读写
|
||||
*
|
||||
* @return ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced handleDistributeSingleClientRealAutoReadConnectTypeAdvanced() {
|
||||
return new ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 接收服务端发送过来的聊天信息
|
||||
*
|
||||
* @return ClientHandleDistributeSingleClientMessageTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeSingleClientMessageTypeAdvanced handleDistributeSingleClientMessageTypeAdvanced() {
|
||||
return new ClientHandleDistributeSingleClientMessageTypeAdvanced();
|
||||
}
|
||||
/**
|
||||
* 处理 客户端渗透服务端数据传输通道连接成功
|
||||
*
|
||||
* @return ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
* @return ClientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced clientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced clientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientTransferClientRequestTypeAdvanced clientHandleDistributeClientTransferClientTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientTransferClientRequestTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced clientHandleDistributeClientTransferClientResponseTypeAdvanced() {
|
||||
return new ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced();
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced handleDistributeSingleClientRealCloseVisitorTypeAdvanced() {
|
||||
return new ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute handleChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandleDistributeConnectSuccessNotificationTypeAdvancedHandle handleDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
return new HandleDistributeConnectSuccessNotificationTypeAdvancedHandle(clientChangeEvent);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandleClientChannelActiveAdvanced handleClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
return new HandleClientChannelActiveAdvanced(nettyClientProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandleDistributeDisconnectTypeAdvancedHandle handleDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
return new HandleDistributeDisconnectTypeAdvancedHandle(clientChangeEvent);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandleDistributeStagingClosedTypeAdvanced handleDistributeStagingClosedTypeAdvanced() {
|
||||
return new HandleDistributeStagingClosedTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandleDistributeStagingOpenedTypeAdvanced handleDistributeStagingOpenedTypeAdvanced() {
|
||||
return new HandleDistributeStagingOpenedTypeAdvanced();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理 客户端渗透服务端init信息
|
||||
*
|
||||
* @return ClientHandleDistributeClientPermeateServerInitTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateServerInitTypeAdvanced clientHandleDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
return new ClientHandleDistributeClientPermeateServerInitTypeAdvanced(nettyClientProperties);
|
||||
}
|
||||
/**
|
||||
* 处理 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @return ClientHandleDistributeClientPermeateServerCloseTypeAdvanced
|
||||
*/
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateServerCloseTypeAdvanced clientHandleDistributeClientPermeateServerCloseTypeAdvanced( ) {
|
||||
return new ClientHandleDistributeClientPermeateServerCloseTypeAdvanced();
|
||||
}
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateServerTransferTypeAdvanced clientHandleDistributeClientPermeateServerTransferTypeAdvanced( ) {
|
||||
return new ClientHandleDistributeClientPermeateServerTransferTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateClientCloseTypeAdvanced clientHandleDistributeClientPermeateClientCloseTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientPermeateClientCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateClientInitTypeAdvanced clientHandleDistributeClientPermeateClientInitTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientPermeateClientInitTypeAdvanced();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeClientPermeateClientTransferCloseTypeAdvanced clientHandleDistributeClientPermeateClientTransferCloseTypeAdvanced() {
|
||||
return new ClientHandleDistributeClientPermeateClientTransferCloseTypeAdvanced();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced clientHandleDistributeSingleClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
return new ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced(nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced clientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced() {
|
||||
return new ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity.LazyNettyServerPropertiesDO;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.application.LazyNettyServerPropertiesApplication;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
|
||||
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 初始化配置
|
||||
*/
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class InitConfig implements CommandLineRunner, DisposableBean {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
private final LazyLambdaStream lazyLambdaStream;
|
||||
|
||||
private final LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication;
|
||||
|
||||
public InitConfig(NettyClientProperties nettyClientProperties, LazyLambdaStream lazyLambdaStream, LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
this.lazyLambdaStream = lazyLambdaStream;
|
||||
this.lazyNettyServerPropertiesApplication = lazyNettyServerPropertiesApplication;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
try {
|
||||
// 存储配置到db
|
||||
initDb2Config();
|
||||
// 启动客户端连接
|
||||
lazyNettyServerPropertiesApplication.starterAllClientSocket();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 存储配置到db
|
||||
*/
|
||||
public void initDb2Config() {
|
||||
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
if (Objects.isNull(clientId) ||
|
||||
Objects.isNull(inetHost)) {
|
||||
log.warn("配置信息为空,请通过页面添加配置信息:{}", nettyClientProperties);
|
||||
return;
|
||||
}
|
||||
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = new LazyNettyServerPropertiesDO();
|
||||
lazyNettyServerPropertiesDO.setClientId(clientId);
|
||||
lazyNettyServerPropertiesDO.setInetHost(inetHost);
|
||||
lazyNettyServerPropertiesDO.setInetPort(inetPort);
|
||||
lazyNettyServerPropertiesDO.setType(PropertiesType.CONFIG);
|
||||
lazyNettyServerPropertiesDO.setIsDeleted(false);
|
||||
// 根据服务端端口、port 唯一性验证
|
||||
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
|
||||
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
|
||||
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
|
||||
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)
|
||||
);
|
||||
if (!exists) {
|
||||
lazyLambdaStream.insert(lazyNettyServerPropertiesDO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 程序关闭后执行
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
lazyNettyServerPropertiesApplication.destroyClientSocket();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.config;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -30,7 +30,10 @@ public class NettyClientProperties {
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
|
||||
/**
|
||||
* 协议类型
|
||||
*/
|
||||
private ProtocolType protocolType = ProtocolType.TCP;
|
||||
/**
|
||||
*
|
||||
* 令牌key
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.context;
|
||||
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.application.LazyNettyServerPropertiesApplication;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity.LazyNettyServerPropertiesDO;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
|
||||
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class NettyClientSocketApplicationListener implements ApplicationListener<ApplicationStartedEvent>, DisposableBean {
|
||||
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
private final LazyLambdaStream lazyLambdaStream;
|
||||
|
||||
private final LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication;
|
||||
|
||||
public NettyClientSocketApplicationListener(NettyClientProperties nettyClientProperties, LazyLambdaStream lazyLambdaStream, LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
this.lazyLambdaStream = lazyLambdaStream;
|
||||
this.lazyNettyServerPropertiesApplication = lazyNettyServerPropertiesApplication;
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储配置到db
|
||||
*/
|
||||
public void initDb2Config() {
|
||||
|
||||
try {
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
String appKey = nettyClientProperties.getAppKey();
|
||||
String appSecret = nettyClientProperties.getAppSecret();
|
||||
ProtocolType protocolType = nettyClientProperties.getProtocolType();
|
||||
if (Objects.isNull(clientId) ||
|
||||
Objects.isNull(inetHost)) {
|
||||
log.warn("配置信息为空,请通过页面添加配置信息:{}", nettyClientProperties);
|
||||
return;
|
||||
}
|
||||
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = new LazyNettyServerPropertiesDO();
|
||||
lazyNettyServerPropertiesDO.setClientId(clientId);
|
||||
lazyNettyServerPropertiesDO.setInetHost(inetHost);
|
||||
lazyNettyServerPropertiesDO.setInetPort(inetPort);
|
||||
lazyNettyServerPropertiesDO.setType(PropertiesType.CONFIG);
|
||||
lazyNettyServerPropertiesDO.setIsDeleted(false);
|
||||
lazyNettyServerPropertiesDO.setAppKey(appKey);
|
||||
lazyNettyServerPropertiesDO.setAppSecret(appSecret);
|
||||
lazyNettyServerPropertiesDO.setProtocolType(protocolType);
|
||||
|
||||
|
||||
// 根据服务端端口、port 唯一性验证
|
||||
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
|
||||
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
|
||||
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
|
||||
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)
|
||||
.eq(LazyNettyServerPropertiesDO::getProtocolType, protocolType)
|
||||
);
|
||||
if (!exists) {
|
||||
lazyLambdaStream.insert(lazyNettyServerPropertiesDO);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handle an application event.
|
||||
*
|
||||
* @param event the event to respond to
|
||||
*/
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
try {
|
||||
// 存储配置到db
|
||||
initDb2Config();
|
||||
// 启动客户端连接
|
||||
lazyNettyServerPropertiesApplication.starterAllClientSocket();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PreDestroy
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
lazyNettyServerPropertiesApplication.destroyClientSocket();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
|
||||
|
||||
import java.lang.String;
|
||||
import java.time.LocalDateTime;
|
||||
import java.lang.Integer;
|
||||
/**
|
||||
* describe 服务端配置信息
|
||||
*
|
||||
@@ -66,6 +65,22 @@ public class LazyNettyServerProperties {
|
||||
@Schema(description ="类型(配置、DB)",name ="type",example = "")
|
||||
private PropertiesType type;
|
||||
|
||||
/**
|
||||
* 协议类型
|
||||
*/
|
||||
@Schema(description = "协议类型", name = "protocol_type", example = "")
|
||||
private ProtocolType protocolType;
|
||||
/**
|
||||
* 令牌key
|
||||
*/
|
||||
@Schema(description = "令牌key", name = "appKey", example = "")
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
@Schema(description = "令牌密钥", name = "appSecret", example = "")
|
||||
private String appSecret;
|
||||
/**
|
||||
*
|
||||
* 更新时间
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
|
||||
import org.wu.framework.lazy.orm.core.stereotype.LazyTable;
|
||||
import org.wu.framework.lazy.orm.core.stereotype.LazyTableField;
|
||||
import org.wu.framework.lazy.orm.core.stereotype.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import org.wu.framework.lazy.orm.core.stereotype.LazyTableFieldId;
|
||||
import org.wu.framework.lazy.orm.core.stereotype.LazyTableFieldUnique;
|
||||
|
||||
import java.lang.String;
|
||||
import java.time.LocalDateTime;
|
||||
import java.lang.Integer;
|
||||
/**
|
||||
* describe 服务端配置信息
|
||||
*
|
||||
@@ -26,6 +26,13 @@ import java.lang.Integer;
|
||||
public class LazyNettyServerPropertiesDO {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 主键ID
|
||||
*/
|
||||
@Schema(description ="主键ID",name ="id",example = "")
|
||||
@LazyTableFieldId(name = "id", comment = "主键ID")
|
||||
private Long id;
|
||||
/**
|
||||
*
|
||||
* 客户身份ID
|
||||
@@ -75,6 +82,20 @@ public class LazyNettyServerPropertiesDO {
|
||||
@LazyTableField(name="is_deleted",comment="是否删除")
|
||||
private Boolean isDeleted;
|
||||
|
||||
|
||||
/**
|
||||
* 令牌key
|
||||
*/
|
||||
@Schema(description = "令牌key", name = "appKey", example = "")
|
||||
@LazyTableField(name = "app_key", comment = "令牌key")
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
@Schema(description = "令牌密钥", name = "appSecret", example = "")
|
||||
@LazyTableField(name = "app_secret", comment = "令牌密钥")
|
||||
private String appSecret;
|
||||
/**
|
||||
*
|
||||
* 类型(配置、DB)
|
||||
@@ -83,6 +104,13 @@ public class LazyNettyServerPropertiesDO {
|
||||
@LazyTableField(name="type",comment="类型(配置、DB)",columnType="varchar(255)")
|
||||
private PropertiesType type;
|
||||
|
||||
/**
|
||||
* 协议类型
|
||||
*/
|
||||
@Schema(description ="协议类型",name ="protocol_type",example = "")
|
||||
@LazyTableField(name="protocol_type",comment="协议类型",columnType="varchar(255)")
|
||||
private ProtocolType protocolType;
|
||||
|
||||
/**
|
||||
*
|
||||
* 更新时间
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class InternalNetworkClientPermeateClientVisitor implements InternalNetworkPermeate {
|
||||
public class NettyClientPermeateClientVisitor implements InternalNetworkPermeate {
|
||||
|
||||
/**
|
||||
* 当前客户端ID
|
||||
@@ -1,17 +1,16 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPermeate;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class InternalNetworkPermeateServerVisitor implements InternalNetworkPermeate {
|
||||
public class NettyClientPermeateServerVisitor implements InternalNetworkPermeate {
|
||||
|
||||
/**
|
||||
* 目标地址
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate;
|
||||
|
||||
public interface NettyClientSocket {
|
||||
|
||||
/**
|
||||
* 创建客户端链接服务端
|
||||
* @throws InterruptedException 异常信息
|
||||
*/
|
||||
void newConnect2Server() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* 关闭链接
|
||||
*/
|
||||
void shutdown();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.event;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event;
|
||||
|
||||
/**
|
||||
* 客户端状态变更事件
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.event;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event;
|
||||
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -1,17 +1,17 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.AbstractHandleChannelHeartbeatTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.AbstractTcpHandleChannelHeartbeatTypeAdvanced;
|
||||
|
||||
|
||||
/**
|
||||
* 服务端 处理客户端心跳
|
||||
* TYPE_HEARTBEAT
|
||||
* TCP_TYPE_HEARTBEAT
|
||||
*/
|
||||
public class ClientHandleChannelHeartbeatTypeAdvanced extends AbstractHandleChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpChannelHeartbeatTypeAdvanced extends AbstractTcpHandleChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
@@ -22,7 +22,7 @@ public class ClientHandleChannelHeartbeatTypeAdvanced extends AbstractHandleChan
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg msg) {
|
||||
NettyProxyMsg hb = new NettyProxyMsg();
|
||||
hb.setType(MessageType.TYPE_HEARTBEAT);
|
||||
hb.setType(TcpMessageType.TCP_TYPE_HEARTBEAT);
|
||||
// channel.writeAndFlush(hb);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeServicePermeateClientTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 服务端处理客户端数据传输
|
||||
*
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute extends AbstractHandleTcpDistributeServicePermeateClientTransferTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
|
||||
public ClientHandleTcpChannelTransferTypeAdvancedHandleDistributeTcpDistribute(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
log.debug("接收到服务端需要内网穿透的数据:{}" , nettyProxyMsg);
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
// 真实服务通道
|
||||
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
if (nextChannel == null) {
|
||||
log.error("无法获取访客:{} 真实服务", new String(visitorId));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 把数据转到真实服务
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleClientChannelActiveAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpClientChannelActiveAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
/**
|
||||
* 客户端通道 is active
|
||||
*/
|
||||
public class HandleClientChannelActiveAdvanced extends AbstractHandleClientChannelActiveAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpClientChannelActiveAdvanced extends AbstractHandleTcpClientChannelActiveAdvanced<NettyProxyMsg> {
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
|
||||
public HandleClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
public ClientHandleTcpClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateClientCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateClientCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateClientCloseTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientPermeateClientCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateClientCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateClientVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateClientInitTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端init信息
|
||||
*
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleTcpDistributeClientPermeateClientInitTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] fromClientIdBytes = nettyProxyMsg.getClientId();
|
||||
byte[] visitorPortBytes = nettyProxyMsg.getVisitorPort();
|
||||
byte[] clientTargetIpBytes = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] clientTargetPortBytes = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] toClientIdBytes = nettyProxyMsg.getData();
|
||||
|
||||
String fromClientId = new String(fromClientIdBytes);
|
||||
String toClientId = new String(toClientIdBytes);
|
||||
Integer visitorPort = Integer.parseInt(new String(visitorPortBytes));
|
||||
String clientTargetIp = new String(clientTargetIpBytes);
|
||||
Integer clientTargetPort = Integer.parseInt(new String(clientTargetPortBytes));
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
// ChannelFlowAdapter channelFlowAdapter = SpringContextHolder.getBean(ChannelFlowAdapter.class);
|
||||
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
|
||||
log.info("client permeate client from client_id:【{}】 to_client_id【{}】with visitor_port【{}】, clientTargetIp:【{}】clientTargetPort:【{}】",
|
||||
fromClientId, toClientId, visitorPort, clientTargetIp, clientTargetPort);
|
||||
NettyTcpClientPermeateClientVisitorSocket nettyTcpClientPermeateClientVisitorSocket =
|
||||
NettyTcpClientPermeateClientVisitorSocket.NettyClientPermeateClientVisitorSocketBuilder.builder()
|
||||
.builderClientId(fromClientId)
|
||||
.builderClientTargetIp(clientTargetIp)
|
||||
.builderClientTargetPort(clientTargetPort)
|
||||
.builderVisitorPort(visitorPort)
|
||||
.builderNettyClientProperties(nettyClientProperties)
|
||||
//.builderChannelFlowAdapter(channelFlowAdapter)
|
||||
.builderToClientId(toClientId)
|
||||
.builderHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList)
|
||||
|
||||
.build();
|
||||
try {
|
||||
nettyTcpClientPermeateClientVisitorSocket.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端通信通道关闭
|
||||
*
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateClientTransferCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 关闭客户端真实通道、访客通道
|
||||
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
realChannel.close();// 真实通道关闭
|
||||
channel.close(); // 数据传输通道关闭
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateServerCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateServerCloseTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientPermeateServerCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,34 +1,31 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateServerVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerInitTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.wu.framework.inner.lazy.orm.spring.SpringConnectionHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerInitTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateServerInitTypeAdvanced extends AbstractHandleDistributeClientPermeateServerInitTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerInitTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
|
||||
public ClientHandleDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
public ClientHandleTcpDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
}
|
||||
|
||||
@@ -47,7 +44,7 @@ public class ClientHandleDistributeClientPermeateServerInitTypeAdvanced extends
|
||||
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
NettyClientPermeateServerVisitorSocket nettyClientPermeateServerVisitorSocket = NettyClientPermeateServerVisitorSocket.NettyVisitorSocketBuilder.builder()
|
||||
NettyTcpClientPermeateServerVisitorSocket nettyTcpClientPermeateServerVisitorSocket = NettyTcpClientPermeateServerVisitorSocket.NettyVisitorSocketBuilder.builder()
|
||||
.builderClientId(new String(clientIdBytes))
|
||||
.builderClientTargetIp(new String(clientTargetIp))
|
||||
.builderClientTargetPort(Integer.parseInt(new String(clientTargetPort)))
|
||||
@@ -56,8 +53,9 @@ public class ClientHandleDistributeClientPermeateServerInitTypeAdvanced extends
|
||||
.builderHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList)
|
||||
.build();
|
||||
try {
|
||||
nettyClientPermeateServerVisitorSocket.start();
|
||||
nettyTcpClientPermeateServerVisitorSocket.start();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端通信通道关闭
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleHandleDistributeClientPermeateServerTransferCloseTypeAdvanced extends AbstractHandleDistributeClientPermeateServerTransferCloseTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerTransferCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
@@ -1,23 +1,22 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientPermeateServerTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 服务端处理客户端数据传输
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateServerTransferTypeAdvanced extends AbstractHandleDistributeClientPermeateServerTransferTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientPermeateServerTransferTypeAdvanced extends AbstractHandleTcpDistributeClientPermeateServerTransferTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
*
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleTcpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 创建connect 然后发送创建成功
|
||||
byte[] msgClientId = nettyProxyMsg.getClientId();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
|
||||
String clientId=new String(msgClientId);
|
||||
String clientTargetIp=new String(msgClientTargetIp);
|
||||
Integer clientTargetPort=Integer.parseInt(new String(msgClientTargetPort));
|
||||
String visitorId=new String(msgVisitorId);
|
||||
Integer visitorPort=Integer.parseInt(new String(msgVisitorPort));
|
||||
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
NettyTcpClientPermeateClientRealSocket.buildRealServer(
|
||||
clientId,
|
||||
clientTargetIp,
|
||||
clientTargetPort,
|
||||
visitorPort,
|
||||
visitorId,
|
||||
nettyClientProperties,
|
||||
handleChannelTypeAdvancedList
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
@@ -16,10 +14,10 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
|
||||
* 下发 客户端渗透客户端数据传输通道init 成功
|
||||
*
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced extends AbstractHandleDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced extends AbstractHandleTcpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientRequestTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferClientRequestTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
|
||||
* 下发客户端渗透客户端数据传输
|
||||
*
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientTransferClientRequestTypeAdvanced extends AbstractHandleDistributeClientTransferClientRequestTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientTransferClientRequestTypeAdvanced extends AbstractHandleTcpDistributeClientTransferClientRequestTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ClientHandleDistributeClientTransferClientRequestTypeAdvanced exten
|
||||
// 把数据转到真实服务
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
log.info("client permeate client send request to real socket byte:{} ",new String(nettyProxyMsg.getData()));
|
||||
log.debug("client permeate client send request to real socket byte:{} ",new String(nettyProxyMsg.getData()));
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateServerVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端数据传输通道连接成功
|
||||
* @see NettyClientPermeateServerVisitorTransferSocket
|
||||
* @see NettyClientPermeateServerVisitorHandler
|
||||
* @see NettyTcpClientPermeateServerVisitorTransferSocket
|
||||
* @see NettyTcpClientPermeateServerVisitorHandler
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,12 +13,12 @@ import java.util.List;
|
||||
* 客户端连接成功通知
|
||||
*/
|
||||
@Slf4j
|
||||
public class HandleDistributeConnectSuccessNotificationTypeAdvancedHandle extends AbstractHandleDistributeConnectSuccessNotificationTypeAdvancedHandle<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle extends AbstractHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle<NettyProxyMsg> {
|
||||
|
||||
private final ClientChangeEvent clientChangeEvent;
|
||||
|
||||
|
||||
public HandleDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
public ClientHandleTcpDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
this.clientChangeEvent = clientChangeEvent;
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ public class HandleDistributeConnectSuccessNotificationTypeAdvancedHandle extend
|
||||
|
||||
// 存储其他客户端状态
|
||||
List<String> clientIdList = JSONObject.parseArray(new String(msg.getData()), String.class);
|
||||
for (String tenantId : clientIdList) {
|
||||
clientChangeEvent.clientOnLine(tenantId);
|
||||
for (String clientId : clientIdList) {
|
||||
clientChangeEvent.clientOnLine(clientId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeDisconnectTypeAdvancedHandle;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeDisconnectTypeAdvancedHandle;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,12 +13,12 @@ import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.Abstrac
|
||||
* TYPE_DISCONNECT
|
||||
*/
|
||||
@Slf4j
|
||||
public class HandleDistributeDisconnectTypeAdvancedHandle extends AbstractHandleDistributeDisconnectTypeAdvancedHandle<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeDisconnectTypeAdvancedHandle extends AbstractHandleTcpDistributeDisconnectTypeAdvancedHandle<NettyProxyMsg> {
|
||||
|
||||
|
||||
private final ClientChangeEvent clientChangeEvent;
|
||||
|
||||
public HandleDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
public ClientHandleTcpDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
this.clientChangeEvent = clientChangeEvent;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpServerPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPenetrationRealClient;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端创建真实代理同奥
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced extends AbstractHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;// 服务端地址信息
|
||||
|
||||
|
||||
public ClientHandleTcpDistributeServicePermeateClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param msg 通道数据
|
||||
*/
|
||||
@Override
|
||||
protected void doHandler(Channel channel, NettyProxyMsg msg) {
|
||||
// 创建真实端口监听
|
||||
byte[] clientIdBytes = msg.getClientId();
|
||||
byte[] visitorPort = msg.getVisitorPort();
|
||||
byte[] clientTargetIp = msg.getClientTargetIp();
|
||||
byte[] clientTargetPort = msg.getClientTargetPort();
|
||||
byte[] visitorIdBytes = msg.getVisitorId();
|
||||
InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient =
|
||||
InternalNetworkPenetrationRealClient
|
||||
.builder()
|
||||
.clientId(new String(clientIdBytes))
|
||||
.visitorPort(Integer.valueOf(new String(visitorPort)))
|
||||
.clientTargetIp(new String(clientTargetIp))
|
||||
.clientTargetPort(Integer.valueOf(new String(clientTargetPort)))
|
||||
.visitorId(new String(visitorIdBytes))
|
||||
.build();
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
// 绑定真实服务端口
|
||||
NettyTcpServerPermeateClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
|
||||
* 下发客户端渗透客户端数据传输响应
|
||||
*
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced extends AbstractHandleDistributeServicePermeateClientTransferClientResponseTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced extends AbstractHandleTcpDistributeServicePermeateClientTransferClientResponseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientMessageTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeSingleClientMessageTypeAdvanced;
|
||||
|
||||
/**
|
||||
* 接收服务端发送过来的聊天信息
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeSingleClientMessageTypeAdvanced extends AbstractHandleDistributeSingleClientMessageTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeSingleClientMessageTypeAdvanced extends AbstractHandleTcpDistributeSingleClientMessageTypeAdvanced<NettyProxyMsg> {
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
@@ -1,15 +1,15 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced extends AbstractHandleDistributeSingleClientRealAutoReadConnectTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced extends AbstractHandleTcpDistributeSingleClientRealAutoReadConnectTypeAdvanced<NettyProxyMsg> {
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
@@ -1,14 +1,14 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced;
|
||||
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeSingleClientRealCloseVisitorTypeAdvanced extends AbstractHandleDistributeSingleClientRealCloseVisitorTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced extends AbstractHandleTcpDistributeSingleClientRealCloseVisitorTypeAdvanced<NettyProxyMsg> {
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
@@ -1,15 +1,15 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeStagingClosedTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeStagingClosedTypeAdvanced;
|
||||
|
||||
/**
|
||||
* 服务端下发暂存关闭消息处理
|
||||
*/
|
||||
@Slf4j
|
||||
public class HandleDistributeStagingClosedTypeAdvanced extends AbstractHandleDistributeStagingClosedTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeStagingClosedTypeAdvanced extends AbstractHandleTcpDistributeStagingClosedTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,18 +1,18 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeStagingOpenedTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.tcp.client.AbstractHandleTcpDistributeStagingOpenedTypeAdvanced;
|
||||
|
||||
/**
|
||||
* 服务端下发暂存开启消息处理
|
||||
*/
|
||||
@Slf4j
|
||||
public class HandleDistributeStagingOpenedTypeAdvanced extends AbstractHandleDistributeStagingOpenedTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleTcpDistributeStagingOpenedTypeAdvanced extends AbstractHandleTcpDistributeStagingOpenedTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
public HandleDistributeStagingOpenedTypeAdvanced() {
|
||||
public ClientHandleTcpDistributeStagingOpenedTypeAdvanced() {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.string.StringDecoder;
|
||||
import io.netty.handler.codec.string.StringEncoder;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyClientFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
public class NettyTcpClientFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
|
||||
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
private final NettyClientSocket nettyClientSocket;
|
||||
private final NettyTcpClientSocket nettyTcpClientSocket;
|
||||
|
||||
public NettyClientFilter(ChannelTypeAdapter channelTypeAdapter, NettyClientSocket nettyClientSocket) {
|
||||
public NettyTcpClientFilter(ChannelTypeAdapter channelTypeAdapter, NettyTcpClientSocket nettyTcpClientSocket) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
this.nettyClientSocket = nettyClientSocket;
|
||||
this.nettyTcpClientSocket = nettyTcpClientSocket;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,6 +40,6 @@ public class NettyClientFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
pipeline.addLast("decoder", new StringDecoder());
|
||||
pipeline.addLast("encoder", new StringEncoder());
|
||||
pipeline.addLast("doHandler", new NettyClientHandler(channelTypeAdapter, nettyClientSocket)); //客户端的逻辑
|
||||
pipeline.addLast("doHandler", new NettyTcpClientHandler(channelTypeAdapter, nettyTcpClientSocket)); //客户端的逻辑
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyServerPermeateClientRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateClientRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.TransferEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyServerPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
public class NettyTcpClientPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
@@ -21,7 +21,7 @@ public class NettyServerPermeateClientRealFilter extends DebugChannelInitializer
|
||||
// 解码、编码
|
||||
pipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024*10));
|
||||
pipeline.addLast(new TransferEncoder());
|
||||
pipeline.addLast(new NettyServerPermeateClientRealHandler());
|
||||
pipeline.addLast(new NettyTcpClientPermeateClientRealHandler());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateClientTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
@@ -14,10 +14,10 @@ import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInit
|
||||
/**
|
||||
* netty 客户端渗透通信通道
|
||||
*/
|
||||
public class NettyClientPermeateServerTransferFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
public class NettyTcpClientPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateServerTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
public NettyTcpClientPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@@ -36,9 +36,11 @@ public class NettyClientPermeateServerTransferFilter extends DebugChannelInitial
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyClientPermeateServerTransferHandler(channelTypeAdapter));
|
||||
pipeline.addLast(new NettyTcpClientPermeateClientTransferHandler(channelTypeAdapter));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateClientTransferRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
/**
|
||||
* netty 客户端连接真实服服务端访客拦截器
|
||||
*/
|
||||
public class NettyTcpClientPermeateClientTransferRealFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyTcpClientPermeateClientTransferRealFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
* @throws Exception is thrown if an error occurs. In that case it will be handled by
|
||||
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyTcpClientPermeateClientTransferRealHandler(channelTypeAdapter));
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateServerVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateClientVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyClientPermeateServerVisitorFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
public class NettyTcpClientPermeateClientVisitorFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
|
||||
private final InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor;
|
||||
private final NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor;
|
||||
|
||||
public NettyClientPermeateServerVisitorFilter(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor) {
|
||||
this.internalNetworkPermeateServerVisitor = internalNetworkPermeateServerVisitor;
|
||||
public NettyTcpClientPermeateClientVisitorFilter(NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor) {
|
||||
this.nettyClientPermeateClientVisitor = nettyClientPermeateClientVisitor;
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@ public class NettyClientPermeateServerVisitorFilter extends DebugChannelInitiali
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
pipeline.addLast(new ChannelDuplexHandler());
|
||||
pipeline.addLast(new NettyClientPermeateServerVisitorHandler(internalNetworkPermeateServerVisitor));
|
||||
pipeline.addLast(new NettyTcpClientPermeateClientVisitorHandler(nettyClientPermeateClientVisitor));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateServerTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
/**
|
||||
* netty 客户端渗透通信通道
|
||||
*/
|
||||
public class NettyTcpClientPermeateServerTransferFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyTcpClientPermeateServerTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
*
|
||||
* @param ch the {@link Channel} which was registered.
|
||||
* @throws Exception is thrown if an error occurs. In that case it will be handled by
|
||||
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default connectionClose
|
||||
* the {@link Channel}.
|
||||
*/
|
||||
@Override
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
// // 解码、编码
|
||||
// pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new IdleStateHandler(0, 4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyTcpClientPermeateServerTransferHandler(channelTypeAdapter));
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpClientPermeateServerVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyClientPermeateClientVisitorFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
public class NettyTcpClientPermeateServerVisitorFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
|
||||
private final InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor;
|
||||
private final NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor;
|
||||
|
||||
public NettyClientPermeateClientVisitorFilter(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor) {
|
||||
this.internalNetworkClientPermeateClientVisitor = internalNetworkClientPermeateClientVisitor;
|
||||
public NettyTcpClientPermeateServerVisitorFilter(NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor) {
|
||||
this.nettyClientPermeateServerVisitor = nettyClientPermeateServerVisitor;
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@ public class NettyClientPermeateClientVisitorFilter extends DebugChannelInitiali
|
||||
protected void initChannel0(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
pipeline.addLast(new ChannelDuplexHandler());
|
||||
pipeline.addLast(new NettyClientPermeateClientVisitorHandler(internalNetworkClientPermeateClientVisitor));
|
||||
pipeline.addLast(new NettyTcpClientPermeateServerVisitorHandler(nettyClientPermeateServerVisitor));
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyClientPermeateClientRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpServerPermeateClientRealHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.TransferDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.TransferEncoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInitializer;
|
||||
|
||||
public class NettyClientPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
public class NettyTcpServerPermeateClientRealFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
/**
|
||||
* This method will be called once the {@link Channel} was registered. After the method returns this instance
|
||||
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
|
||||
@@ -21,7 +21,7 @@ public class NettyClientPermeateClientRealFilter extends DebugChannelInitializer
|
||||
// 解码、编码
|
||||
pipeline.addLast(new TransferDecoder(Integer.MAX_VALUE, 1024 * 1024*10));
|
||||
pipeline.addLast(new TransferEncoder());
|
||||
pipeline.addLast(new NettyClientPermeateClientRealHandler());
|
||||
pipeline.addLast(new NettyTcpServerPermeateClientRealHandler());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.filter;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.handler.NettyServerPermeateClientTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler.NettyTcpServerPermeateClientTransferHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.decoder.NettyProxyMsgDecoder;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.encoder.NettyProxyMsgEncoder;
|
||||
@@ -13,10 +13,10 @@ import org.framework.lazy.cloud.network.heartbeat.common.filter.DebugChannelInit
|
||||
/**
|
||||
* netty 客户端连接真实服服务端访客拦截器
|
||||
*/
|
||||
public class NettyServerPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
public class NettyTcpServerPermeateClientTransferFilter extends DebugChannelInitializer<SocketChannel> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyServerPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
public NettyTcpServerPermeateClientTransferFilter(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ public class NettyServerPermeateClientTransferFilter extends DebugChannelInitial
|
||||
// pipeline.addLast(new NettMsgEncoder());
|
||||
pipeline.addLast(new NettyProxyMsgDecoder(Integer.MAX_VALUE, 0, 4, -4, 0));
|
||||
pipeline.addLast(new NettyProxyMsgEncoder());
|
||||
pipeline.addLast(new NettyServerPermeateClientTransferHandler(channelTypeAdapter));
|
||||
pipeline.addLast(new NettyTcpServerPermeateClientTransferHandler(channelTypeAdapter));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -7,8 +7,8 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
|
||||
@@ -23,15 +23,15 @@ import java.util.concurrent.TimeUnit;
|
||||
* @date 2023/09/13 10:29
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
public class NettyTcpClientHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
private final NettyClientSocket nettyClientSocket;
|
||||
private final NettyTcpClientSocket nettyTcpClientSocket;
|
||||
|
||||
|
||||
public NettyClientHandler(ChannelTypeAdapter channelTypeAdapter, NettyClientSocket nettyClientSocket) {
|
||||
public NettyTcpClientHandler(ChannelTypeAdapter channelTypeAdapter, NettyTcpClientSocket nettyTcpClientSocket) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
this.nettyClientSocket = nettyClientSocket;
|
||||
this.nettyTcpClientSocket = nettyTcpClientSocket;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,11 +58,11 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
|
||||
// 建立连接时
|
||||
log.info("When establishing a connection:{}" , new Date());
|
||||
ctx.fireChannelActive();
|
||||
String clientId = nettyClientSocket.getClientId();
|
||||
String clientId = nettyTcpClientSocket.getClientId();
|
||||
// 处理客户端连接成功
|
||||
Channel channel = ctx.channel();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.CLIENT_CHANNEL_ACTIVE);
|
||||
nettyMsg.setType(TcpMessageType.TCP_CLIENT_CHANNEL_ACTIVE);
|
||||
nettyMsg.setClientId(clientId);
|
||||
channelTypeAdapter.handler(channel, nettyMsg);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
|
||||
final EventLoop eventLoop = ctx.channel().eventLoop();
|
||||
eventLoop.schedule(() -> {
|
||||
try {
|
||||
nettyClientSocket.newConnect2Server();
|
||||
nettyTcpClientSocket.newConnect2Server();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -95,18 +95,18 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
|
||||
if (obj instanceof IdleStateEvent event) {
|
||||
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
|
||||
String clientId = nettyClientSocket.getClientId();
|
||||
String clientId = nettyTcpClientSocket.getClientId();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.TYPE_HEARTBEAT);
|
||||
nettyMsg.setType(TcpMessageType.TCP_TYPE_HEARTBEAT);
|
||||
nettyMsg.setData(clientId.getBytes(StandardCharsets.UTF_8));
|
||||
nettyMsg.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
|
||||
ctx.writeAndFlush(nettyMsg);// 发送心跳数据
|
||||
} else if (event.state() == IdleState.WRITER_IDLE) { // 如果检测到写空闲状态,关闭连接
|
||||
// 离线、暂存通知
|
||||
String clientId = nettyClientSocket.getClientId();
|
||||
String clientId = nettyTcpClientSocket.getClientId();
|
||||
Channel channel = ctx.channel();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION);
|
||||
nettyMsg.setType(TcpMessageType.TCP_DISTRIBUTE_CLIENT_DISCONNECTION_NOTIFICATION);
|
||||
nettyMsg.setClientId(clientId.getBytes(StandardCharsets.UTF_8));
|
||||
channelTypeAdapter.handler(channel, nettyMsg);
|
||||
ctx.close();
|
||||
@@ -1,23 +1,20 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyByteBuf;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 来自客户端 真实服务器返回的数据请求
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
|
||||
public class NettyTcpClientPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
|
||||
|
||||
|
||||
@Override
|
||||
@@ -32,7 +29,7 @@ public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHa
|
||||
// 访客通信通道 上报服务端代理完成
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
NettyProxyMsg returnMessage = new NettyProxyMsg();
|
||||
returnMessage.setType(MessageType.REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE);
|
||||
returnMessage.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_RESPONSE);
|
||||
returnMessage.setVisitorId(visitorId);
|
||||
returnMessage.setClientId(clientId);
|
||||
returnMessage.setVisitorPort(visitorPort);
|
||||
@@ -55,7 +52,7 @@ public class NettyClientPermeateClientRealHandler extends SimpleChannelInboundHa
|
||||
if (nextChannel != null) {
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
@@ -1,27 +1,23 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 客户端访客通信通道 处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
public class NettyTcpClientPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
public NettyTcpClientPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@@ -47,7 +43,7 @@ public class NettyClientPermeateClientTransferHandler extends SimpleChannelInbou
|
||||
if (nextChannel != null) {
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
@@ -1,26 +1,23 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
/**
|
||||
* 客户端访客通信通道 处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientTransferRealHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
public class NettyTcpClientPermeateClientTransferRealHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateClientTransferRealHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
public NettyTcpClientPermeateClientTransferRealHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@@ -42,12 +39,13 @@ public class NettyClientPermeateClientTransferRealHandler extends SimpleChannelI
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(ctx.channel());
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(ctx.channel());
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
log.warn("close client permeate client transfer real clientId:{} visitorId:{}", clientId, visitorId);
|
||||
// 关闭访客
|
||||
if (nextChannel != null) {
|
||||
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -8,11 +8,11 @@ import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced.ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateClientVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyCommunicationIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
@@ -21,19 +21,19 @@ import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeK
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
private final InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor;
|
||||
public class NettyTcpClientPermeateClientVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
private final NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor;
|
||||
// private final NettyChannelPool nettyChannelPool = new DefaultNettyChannelPool(10);
|
||||
|
||||
public NettyClientPermeateClientVisitorHandler(InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor) {
|
||||
this.internalNetworkClientPermeateClientVisitor = internalNetworkClientPermeateClientVisitor;
|
||||
public NettyTcpClientPermeateClientVisitorHandler(NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor) {
|
||||
this.nettyClientPermeateClientVisitor = nettyClientPermeateClientVisitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ctx
|
||||
* @throws Exception
|
||||
* @see NettyClientPermeateServerVisitorTransferSocket
|
||||
* @see ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
* @see NettyTcpClientPermeateServerVisitorTransferSocket
|
||||
* @see ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
@@ -53,8 +53,8 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
|
||||
// 判断是否有可用的通道 如果没有创建新的通道
|
||||
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
|
||||
// 创建访客连接客户端通道
|
||||
NettyClientPermeateClientVisitorTransferSocket.buildTransferServer(internalNetworkClientPermeateClientVisitor,visitorChannel);
|
||||
log.info("客户端渗透客户端访客端口连接成功了");
|
||||
NettyTcpClientPermeateClientVisitorTransferSocket.buildTransferServer(nettyClientPermeateClientVisitor,visitorChannel);
|
||||
log.info("客户端渗透客户端访客:【{}】端口连接成功了",visitorId);
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
|
||||
log.debug("【客户端渗透客户端】访客端口成功接收数据:{}", new String(bytes));
|
||||
|
||||
// 使用访客的通信通道
|
||||
Integer visitorPort = internalNetworkClientPermeateClientVisitor.getVisitorPort();
|
||||
String clientId = internalNetworkClientPermeateClientVisitor.getNettyClientProperties().getClientId();
|
||||
Integer visitorPort = nettyClientPermeateClientVisitor.getVisitorPort();
|
||||
String clientId = nettyClientPermeateClientVisitor.getNettyClientProperties().getClientId();
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST);
|
||||
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST);
|
||||
nettyProxyMsg.setVisitorId(visitorId);
|
||||
nettyProxyMsg.setClientId(clientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
@@ -102,13 +102,13 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
|
||||
|
||||
// 通知客户端 关闭访问通道、真实通道
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
myMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE);
|
||||
nextChannel.writeAndFlush(myMsg);
|
||||
}
|
||||
// 关闭 访客通信通道、访客真实通道
|
||||
NettyRealIdContext.clear(visitorId);
|
||||
NettyCommunicationIdContext.clear(visitorId);
|
||||
log.warn("【客户端渗透客户端】访客端口断开连接");
|
||||
log.warn("【客户端渗透客户端】访客:【{}】端口断开连接",visitorId);
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ public class NettyClientPermeateClientVisitorHandler extends SimpleChannelInbou
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
cause.printStackTrace();
|
||||
log.error("exceptionCaught");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
@@ -7,21 +7,19 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 客户端访客通信通道 处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
public class NettyTcpClientPermeateServerTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyClientPermeateServerTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
public NettyTcpClientPermeateServerTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@@ -47,7 +45,7 @@ public class NettyClientPermeateServerTransferHandler extends SimpleChannelInbou
|
||||
if (nextChannel != null) {
|
||||
// 上报关闭服务端客户端真实通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setType(TcpMessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
@@ -79,7 +77,7 @@ public class NettyClientPermeateServerTransferHandler extends SimpleChannelInbou
|
||||
if (obj instanceof IdleStateEvent event) {
|
||||
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.TYPE_HEARTBEAT);
|
||||
nettyMsg.setType(TcpMessageType.TCP_TYPE_HEARTBEAT);
|
||||
ctx.writeAndFlush(nettyMsg);// 发送心跳数据
|
||||
} else if (event.state() == IdleState.WRITER_IDLE) { // 如果检测到写空闲状态,关闭连接
|
||||
// 离线、暂存通知
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -8,29 +8,29 @@ import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.advanced.ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.advanced.ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket.NettyTcpClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
private final InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor;
|
||||
public class NettyTcpClientPermeateServerVisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
private final NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor;
|
||||
// private final NettyChannelPool nettyChannelPool = new DefaultNettyChannelPool(10);
|
||||
|
||||
public NettyClientPermeateServerVisitorHandler(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor) {
|
||||
this.internalNetworkPermeateServerVisitor = internalNetworkPermeateServerVisitor;
|
||||
public NettyTcpClientPermeateServerVisitorHandler(NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor) {
|
||||
this.nettyClientPermeateServerVisitor = nettyClientPermeateServerVisitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ctx
|
||||
* @throws Exception
|
||||
* @see NettyClientPermeateServerVisitorTransferSocket
|
||||
* @see ClientHandleDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
* @see NettyTcpClientPermeateServerVisitorTransferSocket
|
||||
* @see ClientHandleTcpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
@@ -41,14 +41,14 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
|
||||
|
||||
// 生成访客ID
|
||||
String visitorId = UUID.randomUUID().toString();
|
||||
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
|
||||
Integer visitorPort = nettyClientPermeateServerVisitor.getVisitorPort();
|
||||
|
||||
log.info("this channel with visitor port:{} use visitorId:{}", visitorPort, visitorId);
|
||||
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
|
||||
// 判断是否有可用的通道 如果没有创建新的通道
|
||||
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
|
||||
// 创建访客连接服务端通道
|
||||
NettyClientPermeateServerVisitorTransferSocket.buildTransferServer(internalNetworkPermeateServerVisitor,visitorChannel);
|
||||
NettyTcpClientPermeateServerVisitorTransferSocket.buildTransferServer(nettyClientPermeateServerVisitor,visitorChannel);
|
||||
log.debug("客户端渗透服务端访客端口连接成功了,访客ID:{}", visitorId);
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
@@ -67,10 +67,10 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
|
||||
log.debug("【客户端渗透服务端】访客端口成功接收数据:{}", new String(bytes));
|
||||
|
||||
// 使用访客的通信通道
|
||||
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
|
||||
String clientId = internalNetworkPermeateServerVisitor.getNettyClientProperties().getClientId();
|
||||
Integer visitorPort = nettyClientPermeateServerVisitor.getVisitorPort();
|
||||
String clientId = nettyClientPermeateServerVisitor.getNettyClientProperties().getClientId();
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER);
|
||||
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER);
|
||||
nettyProxyMsg.setVisitorId(visitorId);
|
||||
nettyProxyMsg.setClientId(clientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
@@ -95,7 +95,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
|
||||
if (nextChannel != null && nextChannel.isActive()) {
|
||||
// 通知服务端 关闭访问通道、真实通道
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
myMsg.setType(TcpMessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
myMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(myMsg);
|
||||
//通信通道
|
||||
@@ -136,7 +136,7 @@ public class NettyClientPermeateServerVisitorHandler extends SimpleChannelInboun
|
||||
if (nextChannel != null) {
|
||||
// 下发关闭访客
|
||||
NettyProxyMsg closeRealClient = new NettyProxyMsg();
|
||||
closeRealClient.setType(MessageType.REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
closeRealClient.setType(TcpMessageType.TCP_TCP_REPORT_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE);
|
||||
closeRealClient.setClientId(clientId);
|
||||
closeRealClient.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeRealClient);
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
@@ -6,7 +6,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyByteBuf;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
@@ -16,7 +16,7 @@ import org.wu.framework.core.utils.ObjectUtils;
|
||||
* 来自客户端 真实服务器返回的数据请求
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
|
||||
public class NettyTcpServerPermeateClientRealHandler extends SimpleChannelInboundHandler<NettyByteBuf> {
|
||||
|
||||
|
||||
@Override
|
||||
@@ -31,7 +31,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
|
||||
// 访客通信通道 上报服务端代理完成
|
||||
Channel visitor = ChannelAttributeKeyUtils.getNextChannel(ctx.channel());
|
||||
NettyProxyMsg returnMessage = new NettyProxyMsg();
|
||||
returnMessage.setType(MessageType.REPORT_CLIENT_TRANSFER);
|
||||
returnMessage.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER);
|
||||
returnMessage.setVisitorId(visitorId);
|
||||
returnMessage.setClientId(clientId);
|
||||
returnMessage.setVisitorPort(visitorPort);
|
||||
@@ -55,7 +55,7 @@ public class NettyServerPermeateClientRealHandler extends SimpleChannelInboundHa
|
||||
if (visitor != null) {
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
|
||||
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
visitor.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
@@ -8,6 +8,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
import org.wu.framework.core.utils.ObjectUtils;
|
||||
|
||||
@@ -15,10 +16,10 @@ import org.wu.framework.core.utils.ObjectUtils;
|
||||
* 客户端访客通信通道 处理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyServerPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
public class NettyTcpServerPermeateClientTransferHandler extends SimpleChannelInboundHandler<NettyProxyMsg> {
|
||||
private final ChannelTypeAdapter channelTypeAdapter;
|
||||
|
||||
public NettyServerPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
public NettyTcpServerPermeateClientTransferHandler(ChannelTypeAdapter channelTypeAdapter) {
|
||||
this.channelTypeAdapter = channelTypeAdapter;
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ public class NettyServerPermeateClientTransferHandler extends SimpleChannelInbou
|
||||
if (nextChannel != null) {
|
||||
// 上报关闭这个客户端的访客通道
|
||||
NettyProxyMsg closeVisitorMsg = new NettyProxyMsg();
|
||||
closeVisitorMsg.setType(MessageType.REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
|
||||
closeVisitorMsg.setType(TcpMessageType.TCP_REPORT_SERVICE_PERMEATE_CLIENT_CLIENT_CLOSE_VISITOR);
|
||||
closeVisitorMsg.setVisitorId(visitorId);
|
||||
nextChannel.writeAndFlush(closeVisitorMsg);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.handler;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.handler;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
@@ -7,7 +7,7 @@ import io.netty.handler.timeout.IdleStateEvent;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class HeartBeatClientHandler extends ChannelInboundHandlerAdapter {
|
||||
public class TcpHeartBeatClientHandler extends ChannelInboundHandlerAdapter {
|
||||
private final int lossConnectCount = 0;
|
||||
|
||||
@Override
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
@@ -7,11 +7,12 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientTransferRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateClientRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateClientTransferRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,7 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* 客户端连接真实服务
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientRealSocket {
|
||||
public class NettyTcpClientPermeateClientRealSocket {
|
||||
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
|
||||
|
||||
@@ -46,7 +47,7 @@ public class NettyClientPermeateClientRealSocket {
|
||||
// .option(ChannelOption.SO_BACKLOG, 128)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyClientPermeateClientRealFilter())
|
||||
.handler(new NettyTcpClientPermeateClientRealFilter())
|
||||
|
||||
;
|
||||
|
||||
@@ -57,7 +58,7 @@ public class NettyClientPermeateClientRealSocket {
|
||||
Channel realChannel = future.channel();
|
||||
realChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
log.info("访客通过 客户端:【{}】,绑定本地服务,IP:{},端口:{} 新建通道成功", clientId, clientTargetIp, clientTargetPort);
|
||||
log.info("访客通过 客户端:【{}】,visitorId:{},绑定本地服务,IP:{},端口:{} 新建通道成功", clientId,visitorId, clientTargetIp, clientTargetPort);
|
||||
// 客户端真实通道
|
||||
NettyRealIdContext.pushReal(realChannel, visitorId);
|
||||
// 绑定访客ID到当前真实通道属性
|
||||
@@ -113,7 +114,7 @@ public class NettyClientPermeateClientRealSocket {
|
||||
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
.handler(new NettyClientPermeateClientTransferRealFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
|
||||
.handler(new NettyTcpClientPermeateClientTransferRealFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
|
||||
;
|
||||
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
@@ -126,11 +127,9 @@ public class NettyClientPermeateClientRealSocket {
|
||||
|
||||
|
||||
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
|
||||
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {}", inetHost, inetPort);
|
||||
log.info("client creates a new visitor channel to connect to server IP: {}, connecting to server port: {} with visitorId:{} & clientId:{}", inetHost, inetPort,visitorId,clientId);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
|
||||
// 使用的客户端ID:{}
|
||||
log.info("Client ID used: {}", clientId);
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
Channel transferChannel = futureListener.channel();
|
||||
if (futureListener.isSuccess()) {
|
||||
@@ -142,7 +141,7 @@ public class NettyClientPermeateClientRealSocket {
|
||||
nettyProxyMsg.setClientTargetIp(clientTargetIp);
|
||||
nettyProxyMsg.setClientTargetPort(clientTargetPort);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
nettyProxyMsg.setType(MessageType.REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL);
|
||||
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_PERMEATE_CLIENT_TRANSFER_CHANNEL_INIT_SUCCESSFUL);
|
||||
transferChannel.writeAndFlush(nettyProxyMsg);
|
||||
|
||||
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);
|
||||
@@ -152,11 +151,13 @@ public class NettyClientPermeateClientRealSocket {
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
|
||||
|
||||
ChannelAttributeKeyUtils.buildVisitorPort(transferChannel, visitorPort);
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
log.info("无法连接到服务端....");
|
||||
transferChannel.eventLoop().schedule(() -> {
|
||||
eventLoopGroup.schedule(() -> {
|
||||
try {
|
||||
newVisitorConnect2Server(clientId,
|
||||
clientTargetIp,
|
||||
@@ -1,22 +1,24 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateClientVisitorFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateClientVisitorFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelFlowAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 内网穿透 客户端渗透客户端通道
|
||||
*
|
||||
@@ -24,17 +26,15 @@ import java.util.List;
|
||||
* @see NettyClientVisitorContext
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSocket {
|
||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
private final NettyClientPermeateClientVisitorFilter nettyClientPermeateClientVisitorFilter;
|
||||
public class NettyTcpClientPermeateClientVisitorSocket implements PermeateVisitorSocket {
|
||||
private final NettyTcpClientPermeateClientVisitorFilter nettyTcpClientPermeateClientVisitorFilter;
|
||||
@Getter
|
||||
private final String clientId;
|
||||
@Getter
|
||||
private final int visitorPort;
|
||||
|
||||
public NettyClientPermeateClientVisitorSocket(NettyClientPermeateClientVisitorFilter nettyClientPermeateClientVisitorFilter, String clientId, int visitorPort) {
|
||||
this.nettyClientPermeateClientVisitorFilter = nettyClientPermeateClientVisitorFilter;
|
||||
public NettyTcpClientPermeateClientVisitorSocket(NettyTcpClientPermeateClientVisitorFilter nettyTcpClientPermeateClientVisitorFilter, String clientId, int visitorPort) {
|
||||
this.nettyTcpClientPermeateClientVisitorFilter = nettyTcpClientPermeateClientVisitorFilter;
|
||||
this.clientId = clientId;
|
||||
this.visitorPort = visitorPort;
|
||||
}
|
||||
@@ -49,6 +49,9 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor == null) {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
|
||||
EventLoopGroup bossGroup = EventLoopGroupFactory.createBossGroup();
|
||||
EventLoopGroup workerGroup = EventLoopGroupFactory.createWorkerGroup();
|
||||
bootstrap
|
||||
.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
@@ -67,14 +70,16 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
|
||||
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
|
||||
.childHandler(nettyClientPermeateClientVisitorFilter);
|
||||
.childHandler(nettyTcpClientPermeateClientVisitorFilter);
|
||||
|
||||
try {
|
||||
bootstrap.bind(visitorPort).sync().addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
Channel channel = future.channel();
|
||||
ChannelAttributeKeyUtils.buildVisitorPort(channel,visitorPort);
|
||||
// 这里时异步处理
|
||||
log.info("客户端:[{}]访客端口:[{}] 开启", clientId, visitorPort);
|
||||
NettyVisitorPortContext.pushVisitorChannel(visitorPort, future.channel());
|
||||
NettyVisitorPortContext.pushVisitorChannel(visitorPort, channel);
|
||||
|
||||
} else {
|
||||
log.error("客户端:[{}]访客端口:[{}]绑定失败", clientId, visitorPort);
|
||||
@@ -91,12 +96,6 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
|
||||
}
|
||||
@Override
|
||||
public void close() {
|
||||
if (!bossGroup.isShutdown()) {
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
if (!workerGroup.isShutdown()) {
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
Channel visitor = NettyVisitorPortContext.getVisitorChannel(visitorPort);
|
||||
if (visitor != null) {
|
||||
|
||||
@@ -257,7 +256,7 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
|
||||
this.toClientId = toClientId;
|
||||
return this;
|
||||
}
|
||||
public NettyClientPermeateClientVisitorSocket build() {
|
||||
public NettyTcpClientPermeateClientVisitorSocket build() {
|
||||
if (clientTargetIp == null) {
|
||||
throw new IllegalArgumentException("clientTargetIp must not null");
|
||||
}
|
||||
@@ -267,20 +266,20 @@ public class NettyClientPermeateClientVisitorSocket implements PermeateVisitorSo
|
||||
if (visitorPort == null) {
|
||||
throw new IllegalArgumentException("visitorPort must not null");
|
||||
}
|
||||
InternalNetworkClientPermeateClientVisitor internalNetworkClientPermeateClientVisitor = new InternalNetworkClientPermeateClientVisitor();
|
||||
NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor = new NettyClientPermeateClientVisitor();
|
||||
|
||||
internalNetworkClientPermeateClientVisitor.setFromClientId(nettyClientProperties.getClientId());
|
||||
internalNetworkClientPermeateClientVisitor.setToClientId(toClientId);
|
||||
internalNetworkClientPermeateClientVisitor.setTargetIp(clientTargetIp);
|
||||
internalNetworkClientPermeateClientVisitor.setTargetPort(clientTargetPort);
|
||||
internalNetworkClientPermeateClientVisitor.setVisitorPort(visitorPort);
|
||||
internalNetworkClientPermeateClientVisitor.setNettyClientProperties(nettyClientProperties);
|
||||
internalNetworkClientPermeateClientVisitor.setChannelFlowAdapter(channelFlowAdapter);
|
||||
internalNetworkClientPermeateClientVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
|
||||
nettyClientPermeateClientVisitor.setFromClientId(nettyClientProperties.getClientId());
|
||||
nettyClientPermeateClientVisitor.setToClientId(toClientId);
|
||||
nettyClientPermeateClientVisitor.setTargetIp(clientTargetIp);
|
||||
nettyClientPermeateClientVisitor.setTargetPort(clientTargetPort);
|
||||
nettyClientPermeateClientVisitor.setVisitorPort(visitorPort);
|
||||
nettyClientPermeateClientVisitor.setNettyClientProperties(nettyClientProperties);
|
||||
nettyClientPermeateClientVisitor.setChannelFlowAdapter(channelFlowAdapter);
|
||||
nettyClientPermeateClientVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
|
||||
|
||||
|
||||
NettyClientPermeateClientVisitorFilter visitorFilter = new NettyClientPermeateClientVisitorFilter(internalNetworkClientPermeateClientVisitor);
|
||||
return new NettyClientPermeateClientVisitorSocket(visitorFilter, clientId, visitorPort);
|
||||
NettyTcpClientPermeateClientVisitorFilter visitorFilter = new NettyTcpClientPermeateClientVisitorFilter(nettyClientPermeateClientVisitor);
|
||||
return new NettyTcpClientPermeateClientVisitorSocket(visitorFilter, clientId, visitorPort);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateClientVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateClientTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端传输通道
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyTcpClientPermeateClientVisitorTransferSocket {
|
||||
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
|
||||
/**
|
||||
* 连接服务端通信通道
|
||||
*/
|
||||
public static void buildTransferServer(NettyClientPermeateClientVisitor nettyClientPermeateClientVisitor, Channel visitorChannel) {
|
||||
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
// .option(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .option(ChannelOption.SO_BACKLOG, 256)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyTcpClientPermeateClientTransferFilter(new ChannelTypeAdapter(nettyClientPermeateClientVisitor.getHandleChannelTypeAdvancedList())))
|
||||
;
|
||||
NettyClientProperties nettyClientProperties = nettyClientPermeateClientVisitor.getNettyClientProperties();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
|
||||
String targetIp = nettyClientPermeateClientVisitor.getTargetIp();
|
||||
Integer targetPort = nettyClientPermeateClientVisitor.getTargetPort();
|
||||
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
|
||||
Integer visitorPort = nettyClientPermeateClientVisitor.getVisitorPort();
|
||||
String toClientId = nettyClientPermeateClientVisitor.getToClientId();
|
||||
|
||||
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
|
||||
log.info("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {} with clientId:【{}】 toClientId:【{}】 & visitorId:【{}】", inetHost, inetPort, clientId, toClientId, visitorId);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
|
||||
// 使用的客户端ID:{}
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
Channel transferChannel = futureListener.channel();
|
||||
if (futureListener.isSuccess()) {
|
||||
|
||||
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
|
||||
nettyProxyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
// other clientId
|
||||
nettyProxyMsg.setClientId(toClientId);
|
||||
nettyProxyMsg.setVisitorPort(visitorPort);
|
||||
nettyProxyMsg.setClientTargetIp(targetIp);
|
||||
nettyProxyMsg.setClientTargetPort(targetPort);
|
||||
|
||||
nettyProxyMsg.setVisitorId(visitorId);
|
||||
transferChannel.writeAndFlush(nettyProxyMsg);
|
||||
// 绑定客户端真实通信通道
|
||||
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
|
||||
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
|
||||
// 传输通道打开后自动读取
|
||||
ChannelAttributeKeyUtils.buildNextChannel(visitorChannel, transferChannel);
|
||||
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, visitorChannel);
|
||||
|
||||
|
||||
} else {
|
||||
log.info("无法连接到服务端....");
|
||||
eventLoopGroup.schedule(() -> {
|
||||
try {
|
||||
buildTransferServer(nettyClientPermeateClientVisitor, visitorChannel);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateServerVisitorFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateServerVisitorFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyClientVisitorContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.factory.EventLoopGroupFactory;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -23,17 +24,16 @@ import java.util.List;
|
||||
* @see NettyClientVisitorContext
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSocket {
|
||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
private final NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter;
|
||||
public class NettyTcpClientPermeateServerVisitorSocket implements PermeateVisitorSocket {
|
||||
|
||||
private final NettyTcpClientPermeateServerVisitorFilter nettyTcpClientPermeateServerVisitorFilter;
|
||||
@Getter
|
||||
private final String clientId;
|
||||
@Getter
|
||||
private final int visitorPort;
|
||||
|
||||
public NettyClientPermeateServerVisitorSocket(NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter, String clientId, int visitorPort) {
|
||||
this.nettyClientPermeateServerVisitorFilter = nettyClientPermeateServerVisitorFilter;
|
||||
public NettyTcpClientPermeateServerVisitorSocket(NettyTcpClientPermeateServerVisitorFilter nettyTcpClientPermeateServerVisitorFilter, String clientId, int visitorPort) {
|
||||
this.nettyTcpClientPermeateServerVisitorFilter = nettyTcpClientPermeateServerVisitorFilter;
|
||||
this.clientId = clientId;
|
||||
this.visitorPort = visitorPort;
|
||||
}
|
||||
@@ -48,6 +48,8 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
|
||||
PermeateVisitorSocket visitor = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
if (visitor == null) {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
EventLoopGroup bossGroup = EventLoopGroupFactory.createBossGroup();
|
||||
EventLoopGroup workerGroup = EventLoopGroupFactory.createWorkerGroup();
|
||||
bootstrap
|
||||
.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
@@ -66,14 +68,15 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
|
||||
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
|
||||
.childHandler(nettyClientPermeateServerVisitorFilter);
|
||||
.childHandler(nettyTcpClientPermeateServerVisitorFilter);
|
||||
|
||||
try {
|
||||
bootstrap.bind(visitorPort).sync().addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
// 这里时异步处理
|
||||
log.info("客户端:[{}]访客端口:[{}] 开启", clientId, visitorPort);
|
||||
|
||||
Channel channel = future.channel();
|
||||
ChannelAttributeKeyUtils.buildVisitorPort(channel,visitorPort);
|
||||
} else {
|
||||
log.error("客户端:[{}]访客端口:[{}]绑定失败", clientId, visitorPort);
|
||||
}
|
||||
@@ -89,12 +92,6 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
|
||||
}
|
||||
@Override
|
||||
public void close() {
|
||||
if (!bossGroup.isShutdown()) {
|
||||
bossGroup.shutdownGracefully();
|
||||
}
|
||||
if (!workerGroup.isShutdown()) {
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
PermeateVisitorSocket permeateVisitorSocket = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
if (permeateVisitorSocket != null) {
|
||||
log.warn("关闭客户端 :【{}】 访客户端口:【{}】", clientId, visitorPort);
|
||||
@@ -206,7 +203,7 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
|
||||
}
|
||||
|
||||
|
||||
public NettyClientPermeateServerVisitorSocket build() {
|
||||
public NettyTcpClientPermeateServerVisitorSocket build() {
|
||||
if (clientTargetIp == null) {
|
||||
throw new IllegalArgumentException("clientTargetIp must not null");
|
||||
}
|
||||
@@ -216,17 +213,17 @@ public class NettyClientPermeateServerVisitorSocket implements PermeateVisitorSo
|
||||
if (visitorPort == null) {
|
||||
throw new IllegalArgumentException("visitorPort must not null");
|
||||
}
|
||||
InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor = new InternalNetworkPermeateServerVisitor();
|
||||
NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor = new NettyClientPermeateServerVisitor();
|
||||
|
||||
internalNetworkPermeateServerVisitor.setTargetIp(clientTargetIp);
|
||||
internalNetworkPermeateServerVisitor.setTargetPort(clientTargetPort);
|
||||
internalNetworkPermeateServerVisitor.setVisitorPort(visitorPort);
|
||||
internalNetworkPermeateServerVisitor.setNettyClientProperties(nettyClientProperties);
|
||||
internalNetworkPermeateServerVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
|
||||
nettyClientPermeateServerVisitor.setTargetIp(clientTargetIp);
|
||||
nettyClientPermeateServerVisitor.setTargetPort(clientTargetPort);
|
||||
nettyClientPermeateServerVisitor.setVisitorPort(visitorPort);
|
||||
nettyClientPermeateServerVisitor.setNettyClientProperties(nettyClientProperties);
|
||||
nettyClientPermeateServerVisitor.setHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList);
|
||||
|
||||
|
||||
NettyClientPermeateServerVisitorFilter nettyClientPermeateServerVisitorFilter = new NettyClientPermeateServerVisitorFilter(internalNetworkPermeateServerVisitor);
|
||||
return new NettyClientPermeateServerVisitorSocket(nettyClientPermeateServerVisitorFilter, clientId, visitorPort);
|
||||
NettyTcpClientPermeateServerVisitorFilter nettyTcpClientPermeateServerVisitorFilter = new NettyTcpClientPermeateServerVisitorFilter(nettyClientPermeateServerVisitor);
|
||||
return new NettyTcpClientPermeateServerVisitorSocket(nettyTcpClientPermeateServerVisitorFilter, clientId, visitorPort);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
@@ -7,9 +7,9 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.InternalNetworkPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyClientPermeateServerTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientPermeateServerVisitor;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientPermeateServerTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
@@ -20,15 +20,15 @@ import java.util.concurrent.TimeUnit;
|
||||
* 客户端渗透服务端传输通道
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyClientPermeateServerVisitorTransferSocket {
|
||||
public class NettyTcpClientPermeateServerVisitorTransferSocket {
|
||||
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
|
||||
/**
|
||||
* 连接服务端通信通道
|
||||
* <p>
|
||||
* internalNetworkPermeateServerVisitor
|
||||
* nettyClientPermeateServerVisitor
|
||||
*/
|
||||
public static void buildTransferServer(InternalNetworkPermeateServerVisitor internalNetworkPermeateServerVisitor, Channel visitorChannel) {
|
||||
public static void buildTransferServer(NettyClientPermeateServerVisitor nettyClientPermeateServerVisitor, Channel visitorChannel) {
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup)
|
||||
@@ -45,20 +45,20 @@ public class NettyClientPermeateServerVisitorTransferSocket {
|
||||
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
.handler(new NettyClientPermeateServerTransferFilter(new ChannelTypeAdapter(internalNetworkPermeateServerVisitor.getHandleChannelTypeAdvancedList())))
|
||||
.handler(new NettyTcpClientPermeateServerTransferFilter(new ChannelTypeAdapter(nettyClientPermeateServerVisitor.getHandleChannelTypeAdvancedList())))
|
||||
;
|
||||
NettyClientProperties nettyClientProperties = internalNetworkPermeateServerVisitor.getNettyClientProperties();
|
||||
NettyClientProperties nettyClientProperties = nettyClientPermeateServerVisitor.getNettyClientProperties();
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
int inetPort = nettyClientProperties.getInetPort();
|
||||
// local client id
|
||||
|
||||
String clientId = nettyClientProperties.getClientId();
|
||||
|
||||
String targetIp = internalNetworkPermeateServerVisitor.getTargetIp();
|
||||
Integer targetPort = internalNetworkPermeateServerVisitor.getTargetPort();
|
||||
String targetIp = nettyClientPermeateServerVisitor.getTargetIp();
|
||||
Integer targetPort = nettyClientPermeateServerVisitor.getTargetPort();
|
||||
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(visitorChannel);
|
||||
Integer visitorPort = internalNetworkPermeateServerVisitor.getVisitorPort();
|
||||
Integer visitorPort = nettyClientPermeateServerVisitor.getVisitorPort();
|
||||
|
||||
// 客户端新建访客通道 连接服务端IP:{},连接服务端端口:{}
|
||||
log.debug("Client creates a new visitor channel to connect to server IP: {}, connecting to server port: {}", inetHost, inetPort);
|
||||
@@ -71,7 +71,7 @@ public class NettyClientPermeateServerVisitorTransferSocket {
|
||||
if (futureListener.isSuccess()) {
|
||||
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
myMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL);
|
||||
myMsg.setClientId(clientId);
|
||||
myMsg.setVisitorPort(visitorPort);
|
||||
myMsg.setClientTargetIp(targetIp);
|
||||
@@ -87,9 +87,9 @@ public class NettyClientPermeateServerVisitorTransferSocket {
|
||||
|
||||
} else {
|
||||
log.warn("客户端渗透服务端通信通道中断....");
|
||||
transferChannel.eventLoop().schedule(() -> {
|
||||
eventLoopGroup.schedule(() -> {
|
||||
try {
|
||||
buildTransferServer(internalNetworkPermeateServerVisitor, visitorChannel);
|
||||
buildTransferServer(nettyClientPermeateServerVisitor, visitorChannel);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyServerContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 客户端连接服务端
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyTcpClientSocket implements NettyClientSocket {
|
||||
private final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
/**
|
||||
* 服务端host
|
||||
*/
|
||||
private final String inetHost;
|
||||
/**
|
||||
* 服务端端口
|
||||
*/
|
||||
private final int inetPort;
|
||||
/**
|
||||
* 当前客户端id
|
||||
*/
|
||||
@Getter
|
||||
private final String clientId;
|
||||
|
||||
/**
|
||||
* 当前连接的服务端ID
|
||||
*/
|
||||
private final String serverId;
|
||||
private final String appKey;
|
||||
private final String appSecret;
|
||||
/**
|
||||
* 客户端状态变更事件
|
||||
*/
|
||||
@Getter
|
||||
private final ClientChangeEvent clientChangeEvent;
|
||||
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList; // 处理服务端发送过来的数据类型
|
||||
|
||||
public NettyTcpClientSocket(String inetHost,
|
||||
int inetPort,
|
||||
String clientId,
|
||||
String serverId,
|
||||
String appKey,
|
||||
String appSecret,
|
||||
ClientChangeEvent clientChangeEvent,
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
this.inetHost = inetHost;
|
||||
this.inetPort = inetPort;
|
||||
this.clientId = clientId;
|
||||
this.serverId = serverId;
|
||||
this.appKey = appKey;
|
||||
this.appSecret = appSecret;
|
||||
this.clientChangeEvent = clientChangeEvent;
|
||||
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
|
||||
}
|
||||
|
||||
|
||||
protected void newTcpConnect2Server(String inetHost, int inetPort, String clientId, String serverId, ClientChangeEvent clientChangeEvent) throws InterruptedException {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(eventLoopGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
// .childOption(ChannelOption.TCP_NODELAY, false)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000 * 60)//连接超时时间设置为 60 秒
|
||||
// .childOption(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyTcpClientFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList), this))
|
||||
;
|
||||
log.info("use clientId:{} connect to server IP:{},server port :{}", clientId, inetHost, inetPort);
|
||||
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
|
||||
// 客户端连接服务端的channel
|
||||
Channel serviceChannel = future.channel();
|
||||
|
||||
future.addListener((ChannelFutureListener) futureListener -> {
|
||||
if (futureListener.isSuccess()) {
|
||||
|
||||
log.info("clientId:{},connect to server IP:{},server port :{} isSuccess ", clientId, inetHost, inetPort);
|
||||
// 告诉服务端这条连接是client的连接
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS);
|
||||
nettyMsg.setClientId(clientId);
|
||||
String hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
nettyMsg.setOriginalIpString(hostAddress);
|
||||
nettyMsg.setData((clientId).getBytes());
|
||||
nettyMsg.setAppKeyString(appKey);
|
||||
nettyMsg.setAppSecretString(appSecret);
|
||||
ChannelAttributeKeyUtils.buildClientId(serviceChannel, clientId);
|
||||
serviceChannel.writeAndFlush(nettyMsg);
|
||||
|
||||
NettyServerContext.pushServerEndpointChannel(serverId, clientId, serviceChannel);
|
||||
// 在线 客户端注册服务端成功
|
||||
clientChangeEvent.clientOnLine(inetHost, inetPort,serverId, clientId);
|
||||
} else {
|
||||
log.warn("Reconnect every 2 seconds....");
|
||||
// 离线
|
||||
NettyServerContext.removeServerEndpointChannels(serverId, clientId);
|
||||
clientChangeEvent.clientOffLine(inetHost, inetPort,serverId, clientId);
|
||||
eventLoopGroup.schedule(() -> {
|
||||
try {
|
||||
newTcpConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭连接
|
||||
*/
|
||||
|
||||
public void shutdown() {
|
||||
if ((eventLoopGroup != null) && (!eventLoopGroup.isShutdown())) {
|
||||
eventLoopGroup.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建客户端链接服务端
|
||||
*
|
||||
* @throws InterruptedException 异常信息
|
||||
*/
|
||||
@Override
|
||||
public void newConnect2Server() throws InterruptedException {
|
||||
newTcpConnect2Server(inetHost, inetPort, clientId, serverId, clientChangeEvent);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.socket;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.socket;
|
||||
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
@@ -7,11 +7,12 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyServerPermeateClientRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.filter.NettyServerPermeateClientTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpServerPermeateClientRealFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpServerPermeateClientTransferFilter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.*;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,7 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* 客户端连接真实服务
|
||||
*/
|
||||
@Slf4j
|
||||
public class NettyServerPermeateClientRealSocket {
|
||||
public class NettyTcpServerPermeateClientRealSocket {
|
||||
static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
|
||||
/**
|
||||
@@ -62,7 +63,7 @@ public class NettyServerPermeateClientRealSocket {
|
||||
// .option(ChannelOption.SO_BACKLOG, 128)//务端接受连接的队列长度 默认128
|
||||
// .option(ChannelOption.RCVBUF_ALLOCATOR, new NettyRecvByteBufAllocator(1024 * 1024))//用于Channel分配接受Buffer的分配器 默认AdaptiveRecvByteBufAllocator.DEFAULT
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
.handler(new NettyServerPermeateClientRealFilter())
|
||||
.handler(new NettyTcpServerPermeateClientRealFilter())
|
||||
|
||||
;
|
||||
|
||||
@@ -149,7 +150,7 @@ public class NettyServerPermeateClientRealSocket {
|
||||
|
||||
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
|
||||
|
||||
.handler(new NettyServerPermeateClientTransferFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
|
||||
.handler(new NettyTcpServerPermeateClientTransferFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList)))
|
||||
;
|
||||
|
||||
String inetHost = nettyClientProperties.getInetHost();
|
||||
@@ -176,7 +177,7 @@ public class NettyServerPermeateClientRealSocket {
|
||||
if (futureListener.isSuccess()) {
|
||||
|
||||
NettyProxyMsg myMsg = new NettyProxyMsg();
|
||||
myMsg.setType(MessageType.REPORT_SINGLE_CLIENT_REAL_CONNECT);
|
||||
myMsg.setType(TcpMessageType.TCP_REPORT_SINGLE_CLIENT_REAL_CONNECT);
|
||||
myMsg.setClientId(visitorClientId);
|
||||
myMsg.setVisitorPort(visitorPort);
|
||||
myMsg.setClientTargetIp(clientTargetIp);
|
||||
@@ -201,7 +202,7 @@ public class NettyServerPermeateClientRealSocket {
|
||||
} else {
|
||||
log.info("每隔2s重连....");
|
||||
// 离线
|
||||
transferChannel.eventLoop().schedule(() -> {
|
||||
eventLoopGroup.schedule(() -> {
|
||||
try {
|
||||
newVisitorConnect2Server(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList,realChannel);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.constant.UdpMessageType;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.AbstractUdpHandleChannelHeartbeatTypeAdvanced;
|
||||
|
||||
|
||||
/**
|
||||
* 服务端 处理客户端心跳
|
||||
* UDP_TYPE_HEARTBEAT
|
||||
*/
|
||||
public class ClientHandleUdpChannelHeartbeatTypeAdvanced extends AbstractUdpHandleChannelHeartbeatTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param msg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg msg) {
|
||||
NettyProxyMsg hb = new NettyProxyMsg();
|
||||
hb.setType(UdpMessageType.UDP_TYPE_HEARTBEAT);
|
||||
// channel.writeAndFlush(hb);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -6,22 +6,22 @@ import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeServicePermeateClientTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 服务端处理客户端数据传输
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_TRANSFER
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute extends AbstractHandleDistributeServicePermeateClientTransferTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute extends AbstractHandleUdpDistributeServicePermeateClientTransferTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
|
||||
public ClientHandleChannelTransferTypeAdvancedHandleDistributeDistribute(NettyClientProperties nettyClientProperties) {
|
||||
public ClientHandleUdpChannelTransferTypeAdvancedHandleDistribute(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpClientChannelActiveAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
/**
|
||||
* 客户端通道 is active
|
||||
*/
|
||||
public class ClientHandleUdpClientChannelActiveAdvanced extends AbstractHandleUdpClientChannelActiveAdvanced<NettyProxyMsg> {
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
|
||||
public ClientHandleUdpClientChannelActiveAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 缓存当前通道
|
||||
byte[] clientIdByte = nettyProxyMsg.getClientId();
|
||||
String clientId = new String(clientIdByte);
|
||||
ChannelContext.push(channel, clientId);
|
||||
ChannelAttributeKeyUtils.buildClientId(channel, clientId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateClientCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端init close 信息
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientPermeateClientCloseTypeAdvanced extends AbstractHandleUdpDistributeClientPermeateClientCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));
|
||||
PermeateVisitorSocket visitorSocket = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
// 关闭当前客户端渗透服务端访客通道
|
||||
try {
|
||||
visitorSocket.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.socket.NettyUdpClientPermeateClientVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientPermeateClientInitTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateClientInitTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -18,10 +18,10 @@ import java.util.List;
|
||||
/**
|
||||
* 客户端渗透客户端init信息
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_INIT
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientPermeateClientInitTypeAdvanced extends AbstractHandleDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleUdpDistributeClientPermeateClientInitTypeAdvanced extends AbstractHandleUdpDistributeClientPermeateClientInitTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
@@ -49,8 +49,8 @@ public class ClientHandleDistributeClientPermeateClientInitTypeAdvanced extends
|
||||
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
|
||||
log.info("client permeate client from client_id:【{}】 to_client_id【{}】with visitor_port【{}】, clientTargetIp:【{}】clientTargetPort:【{}】",
|
||||
fromClientId, toClientId, visitorPort, clientTargetIp, clientTargetPort);
|
||||
NettyClientPermeateClientVisitorSocket nettyClientPermeateClientVisitorSocket =
|
||||
NettyClientPermeateClientVisitorSocket.NettyClientPermeateClientVisitorSocketBuilder.builder()
|
||||
NettyUdpClientPermeateClientVisitorSocket nettyTcpClientPermeateClientVisitorSocket =
|
||||
NettyUdpClientPermeateClientVisitorSocket.NettyClientPermeateClientVisitorSocketBuilder.builder()
|
||||
.builderClientId(fromClientId)
|
||||
.builderClientTargetIp(clientTargetIp)
|
||||
.builderClientTargetPort(clientTargetPort)
|
||||
@@ -62,7 +62,7 @@ public class ClientHandleDistributeClientPermeateClientInitTypeAdvanced extends
|
||||
|
||||
.build();
|
||||
try {
|
||||
nettyClientPermeateClientVisitorSocket.start();
|
||||
nettyTcpClientPermeateClientVisitorSocket.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端通信通道关闭
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced extends AbstractHandleUdpDistributeClientPermeateClientTransferCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 关闭客户端真实通道、访客通道
|
||||
Channel realChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
realChannel.close();// 真实通道关闭
|
||||
channel.close(); // 数据传输通道关闭
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyVisitorPortContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateServerCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.socket.PermeateVisitorSocket;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端init close 信息
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientPermeateServerCloseTypeAdvanced extends AbstractHandleUdpDistributeClientPermeateServerCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
Integer visitorPort = Integer.parseInt(new String(msgVisitorPort));
|
||||
PermeateVisitorSocket visitorSocket = NettyVisitorPortContext.getVisitorSocket(visitorPort);
|
||||
// 关闭当前客户端渗透服务端访客通道
|
||||
try {
|
||||
visitorSocket.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.socket.NettyUdpClientPermeateServerVisitorSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateServerInitTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.TcpMessageTypeEnums;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端init信息
|
||||
*
|
||||
* @see TcpMessageTypeEnums#TCP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_INIT
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced extends AbstractHandleUdpDistributeClientPermeateServerInitTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;
|
||||
|
||||
public ClientHandleUdpDistributeClientPermeateServerInitTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 初始化 客户端渗透服务端socket
|
||||
byte[] clientIdBytes = nettyProxyMsg.getClientId();
|
||||
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
NettyUdpClientPermeateServerVisitorSocket nettyTcpClientPermeateServerVisitorSocket = NettyUdpClientPermeateServerVisitorSocket.NettyVisitorSocketBuilder.builder()
|
||||
.builderClientId(new String(clientIdBytes))
|
||||
.builderClientTargetIp(new String(clientTargetIp))
|
||||
.builderClientTargetPort(Integer.parseInt(new String(clientTargetPort)))
|
||||
.builderVisitorPort(Integer.parseInt(new String(visitorPort)))
|
||||
.builderNettyClientProperties(nettyClientProperties)
|
||||
.builderHandleChannelTypeAdvancedList(handleChannelTypeAdvancedList)
|
||||
.build();
|
||||
try {
|
||||
nettyTcpClientPermeateServerVisitorSocket.start();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透服务端通信通道关闭
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_SERVER_TRANSFER_CLOSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced extends AbstractHandleUdpDistributeClientPermeateServerTransferCloseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 关闭本地通信通道
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
channel.close();
|
||||
nextChannel.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientPermeateServerTransferTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 服务端处理客户端数据传输
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_TRANSFER
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientPermeateServerTransferTypeAdvanced extends AbstractHandleUdpDistributeClientPermeateServerTransferTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
log.debug("客户端渗透服务端返回数据:{}" , new String(nettyProxyMsg.getData()));
|
||||
byte[] visitorPort = nettyProxyMsg.getVisitorPort();
|
||||
byte[] clientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] clientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
// 真实服务通道
|
||||
// Channel realChannel = NettyRealIdContext.getReal(new String(visitorId));
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
if (nextChannel == null) {
|
||||
log.error("无法获取访客:{} 真实服务", new String(visitorId));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 把数据转到真实服务
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +1,27 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyClientPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.socket.NettyUdpClientPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.MessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透客户端数据传输通道连接成功
|
||||
*
|
||||
*
|
||||
* @see MessageTypeEnums#DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
* @see MessageTypeEnums#UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleUdpDistributeClientTransferClientPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
@@ -47,7 +45,7 @@ public class ClientHandleDistributeClientTransferClientPermeateChannelConnection
|
||||
Integer visitorPort=Integer.parseInt(new String(msgVisitorPort));
|
||||
NettyClientProperties nettyClientProperties = SpringContextHolder.getBean(NettyClientProperties.class);
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
NettyClientPermeateClientRealSocket.buildRealServer(
|
||||
NettyUdpClientPermeateClientRealSocket.buildRealServer(
|
||||
clientId,
|
||||
clientTargetIp,
|
||||
clientTargetPort,
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发 客户端渗透客户端数据传输通道init 成功
|
||||
*
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_TRANSFER_CLIENT_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced extends AbstractHandleUdpDistributeClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 连接成功 开启自动读取写
|
||||
byte[] msgClientId = nettyProxyMsg.getClientId();
|
||||
byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
|
||||
byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
|
||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||
byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
|
||||
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientTransferClientRequestTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输
|
||||
*
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_REQUEST
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientTransferClientRequestTypeAdvanced extends AbstractHandleUdpDistributeClientTransferClientRequestTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
// 把数据转到真实服务
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
log.debug("client permeate client send request to real socket byte:{} ",new String(nettyProxyMsg.getData()));
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.handler.NettyUdpClientPermeateServerVisitorHandler;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.socket.NettyUdpClientPermeateServerVisitorTransferSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端渗透服务端数据传输通道连接成功
|
||||
* @see NettyUdpClientPermeateServerVisitorTransferSocket
|
||||
* @see NettyUdpClientPermeateServerVisitorHandler
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_TRANSFER_SERVER_PERMEATE_CHANNEL_CONNECTION_SUCCESSFUL
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleUdpDistributeClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param transferChannel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 连接成功 开启自动读取写
|
||||
byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
|
||||
String visitorId = new String(msgVisitorId);
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(transferChannel);
|
||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端连接成功通知
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle extends AbstractHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle<NettyProxyMsg> {
|
||||
|
||||
private final ClientChangeEvent clientChangeEvent;
|
||||
|
||||
|
||||
public ClientHandleUdpDistributeConnectSuccessNotificationTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
this.clientChangeEvent = clientChangeEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param msg 通道数据
|
||||
*/
|
||||
@Override
|
||||
protected void doHandler(Channel channel, NettyProxyMsg msg) {
|
||||
// 客户端ID:{},客户端:{}连接成功
|
||||
log.warn("Client ID: {}, Client Data : {} Connection successful", new String(msg.getClientId()), new String(msg.getData()));
|
||||
|
||||
|
||||
// 存储其他客户端状态
|
||||
List<String> clientIdList = JSONObject.parseArray(new String(msg.getData()), String.class);
|
||||
for (String clientId : clientIdList) {
|
||||
clientChangeEvent.clientOnLine(clientId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeDisconnectTypeAdvancedHandle;
|
||||
|
||||
|
||||
/**
|
||||
* 服务端处理客户端断开连接处理
|
||||
* TYPE_DISCONNECT
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeDisconnectTypeAdvancedHandle extends AbstractHandleUdpDistributeDisconnectTypeAdvancedHandle<NettyProxyMsg> {
|
||||
|
||||
|
||||
private final ClientChangeEvent clientChangeEvent;
|
||||
|
||||
public ClientHandleUdpDistributeDisconnectTypeAdvancedHandle(ClientChangeEvent clientChangeEvent) {
|
||||
this.clientChangeEvent = clientChangeEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param msg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg msg) {
|
||||
// 服务下线
|
||||
byte[] data = msg.getData();
|
||||
byte[] clientId = msg.getClientId();
|
||||
String tenantId = new String(clientId);
|
||||
//客户端:{}下线
|
||||
log.warn("Client: {} Offline", tenantId);
|
||||
clientChangeEvent.clientOffLine(tenantId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +1,29 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.advanced;
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.config.NettyClientProperties;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.socket.NettyServerPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.socket.NettyUdpServerPermeateClientRealSocket;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.InternalNetworkPenetrationRealClient;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.client.AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced;
|
||||
import org.wu.framework.spring.utils.SpringContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端创建真实代理同奥
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced extends AbstractHandleDistributeServicePermeateClientRealConnectTypeAdvanced<NettyProxyMsg> {
|
||||
public class ClientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced extends AbstractHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
private final NettyClientProperties nettyClientProperties;// 服务端地址信息
|
||||
private final List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList;
|
||||
|
||||
public ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties, List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList) {
|
||||
|
||||
public ClientHandleUdpDistributeServicePermeateClientRealConnectTypeAdvanced(NettyClientProperties nettyClientProperties) {
|
||||
this.nettyClientProperties = nettyClientProperties;
|
||||
this.handleChannelTypeAdvancedList = handleChannelTypeAdvancedList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,8 +50,9 @@ public class ClientHandleDistributeServicePermeateClientRealConnectTypeAdvanced
|
||||
.visitorId(new String(visitorIdBytes))
|
||||
.build();
|
||||
|
||||
List<HandleChannelTypeAdvanced> handleChannelTypeAdvancedList = new ArrayList<>(SpringContextHolder.getApplicationContext().getBeansOfType(HandleChannelTypeAdvanced.class).values());
|
||||
// 绑定真实服务端口
|
||||
NettyServerPermeateClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
NettyUdpServerPermeateClientRealSocket.buildRealServer(internalNetworkPenetrationRealClient, nettyClientProperties, handleChannelTypeAdvancedList);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.enums.UdpMessageTypeEnums;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 下发客户端渗透客户端数据传输响应
|
||||
*
|
||||
*
|
||||
* @see UdpMessageTypeEnums#UDP_DISTRIBUTE_CLIENT_PERMEATE_CLIENT_TRANSFER_RESPONSE
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced extends AbstractHandleUdpDistributeServicePermeateClientTransferClientResponseTypeAdvanced<NettyProxyMsg> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
public void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
// 把数据转到真实服务
|
||||
ByteBuf buf = channel.config().getAllocator().buffer(nettyProxyMsg.getData().length);
|
||||
buf.writeBytes(nettyProxyMsg.getData());
|
||||
|
||||
nextChannel.writeAndFlush(buf);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeSingleClientMessageTypeAdvanced;
|
||||
|
||||
/**
|
||||
* 接收服务端发送过来的聊天信息
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeSingleClientMessageTypeAdvanced extends AbstractHandleUdpDistributeSingleClientMessageTypeAdvanced<NettyProxyMsg> {
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
byte[] clientId = nettyProxyMsg.getClientId();
|
||||
byte[] data = nettyProxyMsg.getData();
|
||||
log.info("接收客户端:{},发送过来的聊天信息:{}", new String(clientId), new String(data));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.advanced;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.NettyRealIdContext;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.advanced.permeate.udp.client.AbstractHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced;
|
||||
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
|
||||
|
||||
@Slf4j
|
||||
public class ClientHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced extends AbstractHandleUdpDistributeSingleClientRealAutoReadConnectTypeAdvanced<NettyProxyMsg> {
|
||||
/**
|
||||
* 处理当前数据
|
||||
*
|
||||
* @param channel 当前通道
|
||||
* @param nettyProxyMsg 通道数据
|
||||
*/
|
||||
@Override
|
||||
protected void doHandler(Channel channel, NettyProxyMsg nettyProxyMsg) {
|
||||
// 获取访客ID
|
||||
byte[] visitorId = nettyProxyMsg.getVisitorId();
|
||||
// 获取访客对应的真实代理通道
|
||||
Channel realChannel = NettyRealIdContext.getReal(visitorId);
|
||||
Channel nextChannel = ChannelAttributeKeyUtils.getNextChannel(channel);
|
||||
if (nextChannel != null) {
|
||||
nextChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user