[*] 日常优化
This commit is contained in:
@@ -2,31 +2,31 @@
|
|||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.acgist</groupId>
|
<groupId>com.acgist</groupId>
|
||||||
<artifactId>taoyao</artifactId>
|
<artifactId>taoyao</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>taoyao-boot</artifactId>
|
<artifactId>taoyao-boot</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>taoyao-boot</name>
|
<name>taoyao-boot</name>
|
||||||
<description>基础模块</description>
|
<description>基础模块</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -15,6 +15,8 @@ import java.lang.annotation.Target;
|
|||||||
* -[消息类型]) 全员广播:对所有的终端广播信令(排除自己)
|
* -[消息类型]) 全员广播:对所有的终端广播信令(排除自己)
|
||||||
* +[消息类型]) 全员广播:对所有的终端广播信令(包含自己)
|
* +[消息类型]) 全员广播:对所有的终端广播信令(包含自己)
|
||||||
*
|
*
|
||||||
|
* 消息类型可以省略表示和前面一致
|
||||||
|
*
|
||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@@ -26,15 +28,15 @@ public @interface Description {
|
|||||||
/**
|
/**
|
||||||
* @return 消息主体
|
* @return 消息主体
|
||||||
*/
|
*/
|
||||||
String[] body() default { "{}" };
|
String[] body() default "{}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 数据流向
|
* @return 数据流向
|
||||||
*/
|
*/
|
||||||
String[] flow() default { "终端->信令服务->终端" };
|
String[] flow() default "终端->信令服务->终端";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 描述信息
|
* @return 详细描述
|
||||||
*/
|
*/
|
||||||
String memo() default "";
|
String memo() default "";
|
||||||
|
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ import org.springframework.stereotype.Component;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
public @interface Protocol {
|
public @interface Protocol {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String TO = "to";
|
String TO = "to";
|
||||||
/**
|
/**
|
||||||
* IP
|
* IP地址
|
||||||
*/
|
*/
|
||||||
String IP = "ip";
|
String IP = "ip";
|
||||||
/**
|
/**
|
||||||
@@ -58,21 +58,13 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String CHARGING = "charging";
|
String CHARGING = "charging";
|
||||||
/**
|
/**
|
||||||
* 终端是否正在录像
|
* 终端是否正在录像(录像端)
|
||||||
*/
|
*/
|
||||||
String CLIENT_RECORDING = "clientRecording";
|
String CLIENT_RECORDING = "clientRecording";
|
||||||
/**
|
/**
|
||||||
* 服务端是否正在录像
|
* 终端是否正在录像(服务端)
|
||||||
*/
|
*/
|
||||||
String SERVER_RECORDING = "serverRecording";
|
String SERVER_RECORDING = "serverRecording";
|
||||||
/**
|
|
||||||
* 地址
|
|
||||||
*/
|
|
||||||
String URLS = "urls";
|
|
||||||
/**
|
|
||||||
* 凭证
|
|
||||||
*/
|
|
||||||
String CREDENTIAL = "credential";
|
|
||||||
/**
|
/**
|
||||||
* 最小
|
* 最小
|
||||||
*/
|
*/
|
||||||
@@ -118,7 +110,7 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String PORT = "port";
|
String PORT = "port";
|
||||||
/**
|
/**
|
||||||
* 地址
|
* 主机
|
||||||
*/
|
*/
|
||||||
String HOST = "host";
|
String HOST = "host";
|
||||||
/**
|
/**
|
||||||
@@ -153,10 +145,6 @@ public interface Constant {
|
|||||||
* WebRTC
|
* WebRTC
|
||||||
*/
|
*/
|
||||||
String WEBRTC = "webrtc";
|
String WEBRTC = "webrtc";
|
||||||
/**
|
|
||||||
* 音量
|
|
||||||
*/
|
|
||||||
String VOLUMES = "volumes";
|
|
||||||
/**
|
/**
|
||||||
* 日期时间
|
* 日期时间
|
||||||
*/
|
*/
|
||||||
@@ -181,6 +169,10 @@ public interface Constant {
|
|||||||
* 来源终端ID
|
* 来源终端ID
|
||||||
*/
|
*/
|
||||||
String SOURCE_ID = "sourceId";
|
String SOURCE_ID = "sourceId";
|
||||||
|
/**
|
||||||
|
* 目标终端ID
|
||||||
|
*/
|
||||||
|
String TARGET_ID = "targetId";
|
||||||
/**
|
/**
|
||||||
* 会话ID
|
* 会话ID
|
||||||
*/
|
*/
|
||||||
@@ -209,6 +201,14 @@ public interface Constant {
|
|||||||
* 媒体服务ID
|
* 媒体服务ID
|
||||||
*/
|
*/
|
||||||
String MEDIA_CLIENT_ID = "mediaClientId";
|
String MEDIA_CLIENT_ID = "mediaClientId";
|
||||||
|
/**
|
||||||
|
* 地址列表
|
||||||
|
*/
|
||||||
|
String URLS = "urls";
|
||||||
|
/**
|
||||||
|
* 凭证信息
|
||||||
|
*/
|
||||||
|
String CREDENTIAL = "credential";
|
||||||
/**
|
/**
|
||||||
* ICE服务
|
* ICE服务
|
||||||
*/
|
*/
|
||||||
@@ -316,12 +316,20 @@ public interface Constant {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 生产者ID生成器
|
* 生产者ID生成器
|
||||||
|
* type 媒体类型
|
||||||
|
* producerId 生产者终端ID
|
||||||
*/
|
*/
|
||||||
public static final BiFunction<String, String, String> STREAM_ID_PRODUCER = (type, producerId) -> type + "::" + producerId;
|
public static final BiFunction<String, String, String> STREAM_ID_PRODUCER
|
||||||
|
=
|
||||||
|
(type, producerId) -> type + "::" + producerId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费者ID生成器
|
* 消费者ID生成器
|
||||||
|
* producerStreamId 生产者媒体ID
|
||||||
|
* consumerId 消费者终端ID
|
||||||
*/
|
*/
|
||||||
public static final BiFunction<String, String, String> STREAM_ID_CONSUMER = (producerStreamId, consumerId) -> producerStreamId + "->" + consumerId;
|
public static final BiFunction<String, String, String> STREAM_ID_CONSUMER
|
||||||
|
=
|
||||||
|
(producerStreamId, consumerId) -> producerStreamId + "->" + consumerId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import lombok.Setter;
|
|||||||
@Schema(title = "ID配置", description = "ID配置")
|
@Schema(title = "ID配置", description = "ID配置")
|
||||||
@ConfigurationProperties(prefix = "taoyao.id")
|
@ConfigurationProperties(prefix = "taoyao.id")
|
||||||
public class IdProperties {
|
public class IdProperties {
|
||||||
|
|
||||||
@Schema(title = "最大序号", description = "最大序号")
|
@Schema(title = "最大序号", description = "最大序号")
|
||||||
private Integer maxIndex;
|
private Integer maxIndex;
|
||||||
@Schema(title = "机器序号", description = "机器序号")
|
@Schema(title = "机器序号", description = "机器序号")
|
||||||
private Integer serverIndex;
|
private Integer serverIndex;
|
||||||
@Schema(title = "最小终端序号", description = "最小终端序号")
|
@Schema(title = "最小终端序号", description = "最小终端序号")
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ import lombok.Setter;
|
|||||||
@Schema(title = "音频配置", description = "音频配置")
|
@Schema(title = "音频配置", description = "音频配置")
|
||||||
public class MediaAudioProperties {
|
public class MediaAudioProperties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 音频格式
|
* 音频格式
|
||||||
*
|
*
|
||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
public enum Format {
|
public enum Format {
|
||||||
|
|
||||||
// G722
|
// G722
|
||||||
G722,
|
G722,
|
||||||
// G711A
|
// G711A
|
||||||
PCMA,
|
PCMA,
|
||||||
@@ -32,15 +32,15 @@ public class MediaAudioProperties {
|
|||||||
// OPUS
|
// OPUS
|
||||||
OPUS;
|
OPUS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Schema(title = "格式", description = "格式", example = "G722|PCMA|PCMU|OPUS")
|
@Schema(title = "格式", description = "格式", example = "G722|PCMA|PCMU|OPUS")
|
||||||
private Format format;
|
private Format format;
|
||||||
@Schema(title = "比特率", description = "比特率", example = "96|128|256")
|
@Schema(title = "比特率", description = "比特率", example = "96|128|256")
|
||||||
private Integer bitrate;
|
private Integer bitrate;
|
||||||
@Schema(title = "采样位数(位深)", description = "采样位数(位深)", example = "8|16|32")
|
@Schema(title = "采样位数(位深)", description = "采样位数(位深)", example = "8|16|32")
|
||||||
private Integer sampleSize;
|
private Integer sampleSize;
|
||||||
@Schema(title = "采样率", description = "采样率", example = "8000|16000|32000|48000")
|
@Schema(title = "采样率", description = "采样率", example = "8000|16000|32000|48000")
|
||||||
private Integer sampleRate;
|
private Integer sampleRate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ public class MediaProperties {
|
|||||||
private Integer minAudioBitrate;
|
private Integer minAudioBitrate;
|
||||||
@Schema(title = "最大音频码率", description = "最大音频码率")
|
@Schema(title = "最大音频码率", description = "最大音频码率")
|
||||||
private Integer maxAudioBitrate;
|
private Integer maxAudioBitrate;
|
||||||
@Schema(title = "音频默认配置", description = "音频默认配置")
|
@Schema(title = "音频默认配置", description = "音频默认配置")
|
||||||
private MediaAudioProperties audio;
|
private MediaAudioProperties audio;
|
||||||
@Schema(title = "视频默认配置", description = "视频默认配置")
|
@Schema(title = "视频默认配置", description = "视频默认配置")
|
||||||
private MediaVideoProperties video;
|
private MediaVideoProperties video;
|
||||||
@Schema(title = "音频配置", description = "音频配置")
|
@Schema(title = "音频配置", description = "音频配置")
|
||||||
private Map<String, MediaAudioProperties> audios;
|
private Map<String, MediaAudioProperties> audios;
|
||||||
@Schema(title = "视频配置", description = "视频配置")
|
@Schema(title = "视频配置", description = "视频配置")
|
||||||
private Map<String, MediaVideoProperties> videos;
|
private Map<String, MediaVideoProperties> videos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,28 +21,32 @@ import lombok.Setter;
|
|||||||
@Schema(title = "视频配置", description = "视频配置")
|
@Schema(title = "视频配置", description = "视频配置")
|
||||||
public class MediaVideoProperties {
|
public class MediaVideoProperties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 视频格式
|
* 视频格式
|
||||||
*
|
*
|
||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
public enum Format {
|
public enum Format {
|
||||||
|
|
||||||
VP8,
|
// VP8
|
||||||
VP9,
|
VP8,
|
||||||
H264,
|
// VP9
|
||||||
H265;
|
VP9,
|
||||||
|
// H264
|
||||||
}
|
H264,
|
||||||
|
// H265
|
||||||
@Schema(title = "格式", description = "格式", example = "VP8|VP9|H264|H265")
|
H265;
|
||||||
private Format format;
|
|
||||||
@Schema(title = "码率", description = "码率影响画质", example = "600|1200|1500|1800")
|
}
|
||||||
private Integer bitrate;
|
|
||||||
@Schema(title = "帧率", description = "帧率影响流畅", example = "15|18|20|24|30|45")
|
@Schema(title = "格式", description = "格式", example = "VP8|VP9|H264|H265")
|
||||||
private Integer frameRate;
|
private Format format;
|
||||||
@Schema(title = "分辨率", description = "分辨率影响画面大小", example = "4096*2160|2560*1440|1920*1080|1280*720|720*480")
|
@Schema(title = "码率", description = "码率影响画质", example = "600|1200|1500|1800")
|
||||||
private String resolution;
|
private Integer bitrate;
|
||||||
|
@Schema(title = "帧率", description = "帧率影响流畅", example = "15|18|20|24|30|45")
|
||||||
|
private Integer frameRate;
|
||||||
|
@Schema(title = "分辨率", description = "分辨率影响画面大小", example = "4096*2160|2560*1440|1920*1080|1280*720|720*480")
|
||||||
|
private String resolution;
|
||||||
@Schema(title = "宽度", description = "宽度", example = "4096|2560|1920|1280|720")
|
@Schema(title = "宽度", description = "宽度", example = "4096|2560|1920|1280|720")
|
||||||
private Integer width;
|
private Integer width;
|
||||||
@Schema(title = "高度", description = "高度", example = "2160|1440|1080|720|480")
|
@Schema(title = "高度", description = "高度", example = "2160|1440|1080|720|480")
|
||||||
@@ -50,7 +54,7 @@ public class MediaVideoProperties {
|
|||||||
|
|
||||||
public Integer getWidth() {
|
public Integer getWidth() {
|
||||||
if (this.width == null) {
|
if (this.width == null) {
|
||||||
final int index = this.resolution.indexOf('*');
|
final int index = this.resolution.indexOf('*');
|
||||||
return this.width = Integer.valueOf(this.resolution.substring(0, index).strip());
|
return this.width = Integer.valueOf(this.resolution.substring(0, index).strip());
|
||||||
}
|
}
|
||||||
return this.width;
|
return this.width;
|
||||||
@@ -58,7 +62,7 @@ public class MediaVideoProperties {
|
|||||||
|
|
||||||
public Integer getHeight() {
|
public Integer getHeight() {
|
||||||
if (this.height == null) {
|
if (this.height == null) {
|
||||||
final int index = this.resolution.indexOf('*');
|
final int index = this.resolution.indexOf('*');
|
||||||
return this.height = Integer.valueOf(this.resolution.substring(index + 1).strip());
|
return this.height = Integer.valueOf(this.resolution.substring(index + 1).strip());
|
||||||
}
|
}
|
||||||
return this.height;
|
return this.height;
|
||||||
|
|||||||
@@ -9,21 +9,22 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地址重写
|
* 地址重写配置
|
||||||
|
* 用于多网卡多子网复杂网络环境自动适配IP地址
|
||||||
*
|
*
|
||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Schema(title = "地址重写", description = "地址重写")
|
@Schema(title = "地址重写", description = "地址重写")
|
||||||
@ConfigurationProperties(prefix = "taoyao.ip-rewrite")
|
@ConfigurationProperties(prefix = "taoyao.rewrite")
|
||||||
public class IpRewriteProperties {
|
public class RewriteProperties {
|
||||||
|
|
||||||
@Schema(title = "是否启用", description = "是否启用")
|
@Schema(title = "是否启用", description = "是否启用")
|
||||||
private Boolean enabled;
|
private Boolean enabled;
|
||||||
@Schema(title = "子网掩码", description = "子网掩码:主机号的长度")
|
@Schema(title = "子网掩码", description = "子网掩码:主机号的长度")
|
||||||
private Integer prefix;
|
private Integer prefix;
|
||||||
@Schema(title = "重写规则", description = "重写规则")
|
@Schema(title = "重写规则", description = "重写规则")
|
||||||
private List<IpRewriteRuleProperties> rule;
|
private List<RewriteRuleProperties> rule;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,14 +6,18 @@ import lombok.Setter;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 重写规则
|
* 重写规则
|
||||||
* 没有配置内网地址等于网络号加上原始主机号
|
* 配置内网地址直接返回内网地址
|
||||||
|
* 没有配置内网地址内网地址等于网络号加上原始主机号
|
||||||
|
*
|
||||||
|
* 内网设备IP返回内网地址
|
||||||
|
* 外网设备IP返回外网地址
|
||||||
*
|
*
|
||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Schema(title = "重写规则", description = "重写规则")
|
@Schema(title = "重写规则", description = "重写规则")
|
||||||
public class IpRewriteRuleProperties {
|
public class RewriteRuleProperties {
|
||||||
|
|
||||||
@Schema(title = "网络号", description = "网络号:匹配终端IP")
|
@Schema(title = "网络号", description = "网络号:匹配终端IP")
|
||||||
private String network;
|
private String network;
|
||||||
@@ -21,5 +25,5 @@ public class IpRewriteRuleProperties {
|
|||||||
private String innerHost;
|
private String innerHost;
|
||||||
@Schema(title = "外网地址", description = "外网地址")
|
@Schema(title = "外网地址", description = "外网地址")
|
||||||
private String outerHost;
|
private String outerHost;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ import org.springframework.web.servlet.NoHandlerFoundException;
|
|||||||
|
|
||||||
import com.acgist.taoyao.boot.config.FfmpegProperties;
|
import com.acgist.taoyao.boot.config.FfmpegProperties;
|
||||||
import com.acgist.taoyao.boot.config.IdProperties;
|
import com.acgist.taoyao.boot.config.IdProperties;
|
||||||
import com.acgist.taoyao.boot.config.IpRewriteProperties;
|
import com.acgist.taoyao.boot.config.RewriteProperties;
|
||||||
import com.acgist.taoyao.boot.config.MediaProperties;
|
import com.acgist.taoyao.boot.config.MediaProperties;
|
||||||
import com.acgist.taoyao.boot.config.ScriptProperties;
|
import com.acgist.taoyao.boot.config.ScriptProperties;
|
||||||
import com.acgist.taoyao.boot.config.SecurityProperties;
|
import com.acgist.taoyao.boot.config.SecurityProperties;
|
||||||
@@ -92,8 +92,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
SocketProperties.class,
|
SocketProperties.class,
|
||||||
TaoyaoProperties.class,
|
TaoyaoProperties.class,
|
||||||
WebrtcProperties.class,
|
WebrtcProperties.class,
|
||||||
|
RewriteProperties.class,
|
||||||
SecurityProperties.class,
|
SecurityProperties.class,
|
||||||
IpRewriteProperties.class
|
|
||||||
})
|
})
|
||||||
public class BootAutoConfiguration {
|
public class BootAutoConfiguration {
|
||||||
|
|
||||||
@@ -150,12 +150,12 @@ public class BootAutoConfiguration {
|
|||||||
public CommandLineRunner successCommandLineRunner(
|
public CommandLineRunner successCommandLineRunner(
|
||||||
TaskExecutor taskExecutor,
|
TaskExecutor taskExecutor,
|
||||||
TaoyaoProperties taoyaoProperties,
|
TaoyaoProperties taoyaoProperties,
|
||||||
IpRewriteProperties ipRewriteProperties
|
RewriteProperties rewriteProperties
|
||||||
) {
|
) {
|
||||||
return new OrderedCommandLineRunner() {
|
return new OrderedCommandLineRunner() {
|
||||||
@Override
|
@Override
|
||||||
public void run(String ... args) throws Exception {
|
public void run(String ... args) throws Exception {
|
||||||
NetUtils.init(ipRewriteProperties);
|
NetUtils.init(rewriteProperties);
|
||||||
HTTPUtils.init(taoyaoProperties.getTimeout(), taskExecutor);
|
HTTPUtils.init(taoyaoProperties.getTimeout(), taskExecutor);
|
||||||
BootAutoConfiguration.this.registerException();
|
BootAutoConfiguration.this.registerException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import java.util.BitSet;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import com.acgist.taoyao.boot.config.IpRewriteProperties;
|
import com.acgist.taoyao.boot.config.RewriteProperties;
|
||||||
import com.acgist.taoyao.boot.config.IpRewriteRuleProperties;
|
import com.acgist.taoyao.boot.config.RewriteRuleProperties;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -36,14 +36,14 @@ public final class NetUtils {
|
|||||||
/**
|
/**
|
||||||
* 地址重写
|
* 地址重写
|
||||||
*/
|
*/
|
||||||
private static IpRewriteProperties ipRewriteProperties;
|
private static RewriteProperties rewriteProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载配置
|
* 加载配置
|
||||||
*/
|
*/
|
||||||
public static final void init(IpRewriteProperties ipRewriteProperties) {
|
public static final void init(RewriteProperties rewriteProperties) {
|
||||||
try {
|
try {
|
||||||
NetUtils.ipRewriteProperties = ipRewriteProperties;
|
NetUtils.rewriteProperties = rewriteProperties;
|
||||||
final InetAddress localHost = InetAddress.getLocalHost();
|
final InetAddress localHost = InetAddress.getLocalHost();
|
||||||
final InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
|
final InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
|
||||||
NetUtils.localIp = localHost.getHostAddress();
|
NetUtils.localIp = localHost.getHostAddress();
|
||||||
@@ -89,8 +89,8 @@ public final class NetUtils {
|
|||||||
final int length = (sourceBytes.length & clientBytes.length) * Byte.SIZE;
|
final int length = (sourceBytes.length & clientBytes.length) * Byte.SIZE;
|
||||||
final BitSet sourceBit = BitSet.valueOf(sourceBytes);
|
final BitSet sourceBit = BitSet.valueOf(sourceBytes);
|
||||||
final BitSet clientBit = BitSet.valueOf(clientBytes);
|
final BitSet clientBit = BitSet.valueOf(clientBytes);
|
||||||
sourceBit.set(NetUtils.ipRewriteProperties.getPrefix(), length, true);
|
sourceBit.set(NetUtils.rewriteProperties.getPrefix(), length, true);
|
||||||
clientBit.set(NetUtils.ipRewriteProperties.getPrefix(), length, true);
|
clientBit.set(NetUtils.rewriteProperties.getPrefix(), length, true);
|
||||||
final BigInteger source = new BigInteger(sourceBit.toByteArray());
|
final BigInteger source = new BigInteger(sourceBit.toByteArray());
|
||||||
final BigInteger client = new BigInteger(clientBit.toByteArray());
|
final BigInteger client = new BigInteger(clientBit.toByteArray());
|
||||||
return source.equals(client);
|
return source.equals(client);
|
||||||
@@ -110,10 +110,10 @@ public final class NetUtils {
|
|||||||
* @return 替换IP
|
* @return 替换IP
|
||||||
*/
|
*/
|
||||||
public static final String rewriteIp(final String sourceIp, final String clientIp) {
|
public static final String rewriteIp(final String sourceIp, final String clientIp) {
|
||||||
if(Boolean.FALSE.equals(NetUtils.ipRewriteProperties.getEnabled())) {
|
if(Boolean.FALSE.equals(NetUtils.rewriteProperties.getEnabled())) {
|
||||||
return sourceIp;
|
return sourceIp;
|
||||||
}
|
}
|
||||||
final IpRewriteRuleProperties rule = NetUtils.ipRewriteProperties.getRule().stream()
|
final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream()
|
||||||
.filter(v -> NetUtils.subnetIp(v.getNetwork(), clientIp))
|
.filter(v -> NetUtils.subnetIp(v.getNetwork(), clientIp))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
@@ -138,7 +138,7 @@ public final class NetUtils {
|
|||||||
final BitSet sourceBit = BitSet.valueOf(sourceBytes);
|
final BitSet sourceBit = BitSet.valueOf(sourceBytes);
|
||||||
final BitSet clientBit = BitSet.valueOf(clientBytes);
|
final BitSet clientBit = BitSet.valueOf(clientBytes);
|
||||||
// 替换网络号保留主机号
|
// 替换网络号保留主机号
|
||||||
for (int index = 0; index < NetUtils.ipRewriteProperties.getPrefix(); index++) {
|
for (int index = 0; index < NetUtils.rewriteProperties.getPrefix(); index++) {
|
||||||
sourceBit.set(index, clientBit.get(index));
|
sourceBit.set(index, clientBit.get(index));
|
||||||
}
|
}
|
||||||
final byte[] bytes = sourceBit.toByteArray();
|
final byte[] bytes = sourceBit.toByteArray();
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import com.acgist.taoyao.boot.config.IpRewriteProperties;
|
import com.acgist.taoyao.boot.config.RewriteProperties;
|
||||||
import com.acgist.taoyao.boot.config.IpRewriteRuleProperties;
|
import com.acgist.taoyao.boot.config.RewriteRuleProperties;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -18,15 +18,15 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
public class NetUtilsTest {
|
public class NetUtilsTest {
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
final IpRewriteRuleProperties ipRewriteRuleProperties1 = new IpRewriteRuleProperties();
|
final RewriteRuleProperties rewriteRuleProperties1 = new RewriteRuleProperties();
|
||||||
ipRewriteRuleProperties1.setNetwork("192.168.1.0");
|
rewriteRuleProperties1.setNetwork("192.168.1.0");
|
||||||
final IpRewriteRuleProperties ipRewriteRuleProperties10 = new IpRewriteRuleProperties();
|
final RewriteRuleProperties rewriteRuleProperties10 = new RewriteRuleProperties();
|
||||||
ipRewriteRuleProperties10.setNetwork("192.168.10.0");
|
rewriteRuleProperties10.setNetwork("192.168.10.0");
|
||||||
final IpRewriteProperties ipRewriteProperties = new IpRewriteProperties();
|
final RewriteProperties rewriteProperties = new RewriteProperties();
|
||||||
ipRewriteProperties.setEnabled(true);
|
rewriteProperties.setEnabled(true);
|
||||||
ipRewriteProperties.setPrefix(24);
|
rewriteProperties.setPrefix(24);
|
||||||
ipRewriteProperties.setRule(List.of(ipRewriteRuleProperties1, ipRewriteRuleProperties10));
|
rewriteProperties.setRule(List.of(rewriteRuleProperties1, rewriteRuleProperties10));
|
||||||
NetUtils.init(ipRewriteProperties);
|
NetUtils.init(rewriteProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.acgist.taoyao.boot.config.FfmpegProperties;
|
import com.acgist.taoyao.boot.config.FfmpegProperties;
|
||||||
|
import com.acgist.taoyao.boot.config.RewriteProperties;
|
||||||
import com.acgist.taoyao.boot.config.MediaProperties;
|
import com.acgist.taoyao.boot.config.MediaProperties;
|
||||||
import com.acgist.taoyao.boot.config.SocketProperties;
|
import com.acgist.taoyao.boot.config.SocketProperties;
|
||||||
import com.acgist.taoyao.boot.config.WebrtcProperties;
|
import com.acgist.taoyao.boot.config.WebrtcProperties;
|
||||||
@@ -32,6 +33,7 @@ public class ConfigController {
|
|||||||
private final FfmpegProperties ffmpegProperties;
|
private final FfmpegProperties ffmpegProperties;
|
||||||
private final SocketProperties socketProperties;
|
private final SocketProperties socketProperties;
|
||||||
private final WebrtcProperties webrtcProperties;
|
private final WebrtcProperties webrtcProperties;
|
||||||
|
private final RewriteProperties rewriteProperties;
|
||||||
|
|
||||||
@Operation(summary = "媒体配置", description = "媒体配置")
|
@Operation(summary = "媒体配置", description = "媒体配置")
|
||||||
@GetMapping("/media")
|
@GetMapping("/media")
|
||||||
@@ -61,4 +63,11 @@ public class ConfigController {
|
|||||||
return Message.success(this.webrtcProperties);
|
return Message.success(this.webrtcProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "地址重写配置", description = "地址重写配置")
|
||||||
|
@GetMapping("/rewrite")
|
||||||
|
@ApiResponse(content = @Content(schema = @Schema(implementation = WebrtcProperties.class)))
|
||||||
|
public Message rewrite() {
|
||||||
|
return Message.success(this.rewriteProperties);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,6 +236,18 @@ taoyao:
|
|||||||
# port: 3478
|
# port: 3478
|
||||||
# username: taoyao
|
# username: taoyao
|
||||||
# password: taoyao
|
# password: taoyao
|
||||||
|
# 地址重写
|
||||||
|
rewrite:
|
||||||
|
enabled: true
|
||||||
|
prefix: 24
|
||||||
|
# 重写规则
|
||||||
|
rule:
|
||||||
|
# - network: 192.168.1.0
|
||||||
|
# inner-host:
|
||||||
|
# outer-host:
|
||||||
|
# - network: 192.168.8.0
|
||||||
|
# inner-host:
|
||||||
|
# outer-host:
|
||||||
# 安全配置
|
# 安全配置
|
||||||
security:
|
security:
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -253,15 +265,3 @@ taoyao:
|
|||||||
room: 0 0/5 * * * ?
|
room: 0 0/5 * * * ?
|
||||||
# 清理无效终端连接
|
# 清理无效终端连接
|
||||||
client: 0 * * * * ?
|
client: 0 * * * * ?
|
||||||
# 地址重写
|
|
||||||
ip-rewrite:
|
|
||||||
enabled: true
|
|
||||||
prefix: 24
|
|
||||||
# 重写规则
|
|
||||||
rule:
|
|
||||||
# - network: 192.168.1.0
|
|
||||||
# inner-host:
|
|
||||||
# outer-host:
|
|
||||||
# - network: 192.168.8.0
|
|
||||||
# inner-host:
|
|
||||||
# outer-host:
|
|
||||||
|
|||||||
Reference in New Issue
Block a user