From 801479c2488af3f4b60de91fd179dc02d2c79d4a Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Tue, 12 Sep 2023 20:33:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20RegisterSubscribe=20?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../register/request/RegisterRequest.java | 5 -- .../message/subscribe/RegisterSubscribe.java | 39 ++++++++++ .../sip/message/subscribe/SipSubscribe.java | 34 +++++++++ .../core/sip/request/SipRequestBuilder.java | 46 ++---------- .../src/main/resources/application-local.yml | 71 +++++++++++++++++++ .../src/main/resources/application.yml | 2 + .../src/main/resources/logback.xml | 54 ++++++++++++++ 7 files changed, 207 insertions(+), 44 deletions(-) delete mode 100644 gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/register/request/RegisterRequest.java create mode 100644 gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/subscribe/RegisterSubscribe.java create mode 100644 gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/subscribe/SipSubscribe.java create mode 100644 gb28181-mocking-starter/src/main/resources/application-local.yml create mode 100644 gb28181-mocking-starter/src/main/resources/logback.xml diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/register/request/RegisterRequest.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/register/request/RegisterRequest.java deleted file mode 100644 index f90d297..0000000 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/register/request/RegisterRequest.java +++ /dev/null @@ -1,5 +0,0 @@ -package cn.skcks.docking.gb28181.mocking.core.sip.message.register.request; - - -public class RegisterRequest { -} diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/subscribe/RegisterSubscribe.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/subscribe/RegisterSubscribe.java new file mode 100644 index 0000000..4f950b5 --- /dev/null +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/subscribe/RegisterSubscribe.java @@ -0,0 +1,39 @@ +package cn.skcks.docking.gb28181.mocking.core.sip.message.subscribe; + +import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe; +import gov.nist.javax.sip.message.SIPResponse; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; +import java.util.concurrent.Flow; +import java.util.concurrent.SubmissionPublisher; + +@RequiredArgsConstructor +public class RegisterSubscribe implements GenericSubscribe { + private final Executor executor; + + private static final Map> publishers = new ConcurrentHashMap<>(); + + public void close() { + Helper.close(publishers); + } + + public void addPublisher(String key) { + Helper.addPublisher(executor, publishers, key); + } + + public SubmissionPublisher getPublisher(String key) { + return Helper.getPublisher(publishers, key); + } + + public void addSubscribe(String key, Flow.Subscriber subscribe) { + Helper.addSubscribe(publishers, key, subscribe); + } + + @Override + public void delPublisher(String key) { + Helper.delPublisher(publishers, key); + } +} diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/subscribe/SipSubscribe.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/subscribe/SipSubscribe.java new file mode 100644 index 0000000..b0f66da --- /dev/null +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/subscribe/SipSubscribe.java @@ -0,0 +1,34 @@ +package cn.skcks.docking.gb28181.mocking.core.sip.message.subscribe; + +import cn.skcks.docking.gb28181.core.sip.executor.DefaultSipExecutor; +import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe; +import gov.nist.javax.sip.message.SIPResponse; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.concurrent.Executor; + +@Slf4j +@Data +@RequiredArgsConstructor +@Service +public class SipSubscribe { + @Qualifier(DefaultSipExecutor.EXECUTOR_BEAN_NAME) + private final Executor executor; + private GenericSubscribe registerSubscribe; + + @PostConstruct + private void init() { + registerSubscribe = new RegisterSubscribe(executor); + } + + @PreDestroy + private void destroy() { + registerSubscribe.close(); + } +} diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/request/SipRequestBuilder.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/request/SipRequestBuilder.java index c634ff1..02e1ce9 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/request/SipRequestBuilder.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/request/SipRequestBuilder.java @@ -41,38 +41,6 @@ public class SipRequestBuilder implements ApplicationContextAware { return SipFactory.getInstance(); } - @SneakyThrows - private static SipURI getSipURI(String id, String address){ - return MessageHelper.createSipURI(id, address); - } - - @SneakyThrows - private static Address getAddress(SipURI uri){ - return MessageHelper.createAddress(uri); - } - - @SneakyThrows - private static FromHeader getFromHeader(Address fromAddress, String fromTag){ - return MessageHelper.createFromHeader(fromAddress, fromTag); - } - - @SneakyThrows - private static ToHeader getToHeader(Address toAddress, String toTag){ - return MessageHelper.createToHeader(toAddress, toTag); - } - - @SneakyThrows - private static MaxForwardsHeader getMaxForwardsHeader(int maxForwards){ - return getSipFactory().createHeaderFactory().createMaxForwardsHeader(maxForwards); - } - - @SneakyThrows - private static List getDeviceViaHeaders(DockingDevice device, String viaTag){ - ViaHeader viaHeader = getSipFactory().createHeaderFactory().createViaHeader(device.getLocalIp(), serverConfig.getPort(), device.getTransport(), viaTag); - viaHeader.setRPort(); - return Collections.singletonList(viaHeader); - } - @SneakyThrows private static List getViaHeaders(String ip,int port, String transport, String viaTag){ ViaHeader viaHeader = getSipFactory().createHeaderFactory().createViaHeader(ip, port, transport, viaTag); @@ -88,21 +56,21 @@ public class SipRequestBuilder implements ApplicationContextAware { @SneakyThrows public static Request createRegisterRequest(MockingDevice device, String ip, int port, long cSeq, String fromTag, String viaTag, CallIdHeader callIdHeader) { String target = StringUtils.joinWith(":", serverConfig.getIp(), serverConfig.getPort()); - SipURI requestURI = getSipURI(serverConfig.getId(), target); + SipURI requestURI = MessageHelper.createSipURI(serverConfig.getId(), target); // via List viaHeaders = getViaHeaders(serverConfig.getIp(), serverConfig.getPort(), sipConfig.getTransport(), viaTag); // from String from = StringUtils.joinWith(":", ip, port); - SipURI fromSipURI = getSipURI(device.getGbDeviceId(), from); - Address fromAddress = getAddress(fromSipURI); - FromHeader fromHeader = getFromHeader(fromAddress, fromTag); + SipURI fromSipURI = MessageHelper.createSipURI(device.getGbDeviceId(), from); + Address fromAddress = MessageHelper.createAddress(fromSipURI); + FromHeader fromHeader = MessageHelper.createFromHeader(fromAddress, fromTag); // to - ToHeader toHeader = getToHeader(fromAddress, null); + ToHeader toHeader = MessageHelper.createToHeader(fromAddress, null); // forwards - MaxForwardsHeader maxForwardsHeader = getMaxForwardsHeader(70); + MaxForwardsHeader maxForwardsHeader = MessageHelper.createMaxForwardsHeader(70); // ceq CSeqHeader cSeqHeader = getCSeqHeader(cSeq, Request.REGISTER); @@ -129,7 +97,7 @@ public class SipRequestBuilder implements ApplicationContextAware { String qop = www.getQop(); String target = StringUtils.joinWith(":", serverConfig.getIp(), serverConfig.getPort()); - SipURI requestURI = getSipURI(serverConfig.getId(), target); + SipURI requestURI = MessageHelper.createSipURI(serverConfig.getId(), target); String cNonce = null; String nc = "00000001"; if (qop != null) { diff --git a/gb28181-mocking-starter/src/main/resources/application-local.yml b/gb28181-mocking-starter/src/main/resources/application-local.yml new file mode 100644 index 0000000..2ff9f22 --- /dev/null +++ b/gb28181-mocking-starter/src/main/resources/application-local.yml @@ -0,0 +1,71 @@ +server: + port: 18182 + +project: + version: @project.version@ + +spring: + data: + redis: + # [必须修改] Redis服务器IP, REDIS安装在本机的,使用127.0.0.1 + # host: 192.168.1.241 + host: 10.10.10.200 + # [必须修改] 端口号 + port: 6379 + # [可选] 数据库 DB + database: 15 + # [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接 + password: 12341234 + # [可选] 超时时间 + timeout: 10000 + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 12341234 + url: jdbc:mysql://10.10.10.200:3306/gb28181_docking_platform?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + config: + activate: + on-profile: local + +gb28181: + # 作为28181服务器的配置 + sip: + # [必须修改] 本机的IP,对应你的网卡,监听什么ip就是使用什么网卡, + # 如果不明白,就使用0.0.0.0,大部分情况都是可以的 + # 请不要使用127.0.0.1,任何包括localhost在内的域名都是不可以的。 + ip: +# - 10.27.0.1 +# - 192.168.0.195 +# - 192.168.10.195 + - 10.10.10.20 +# - 10.27.0.6 + # [可选] 28181服务监听的端口 + port: 15060 + # 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007) + # 后两位为行业编码,定义参照附录D.3 + # 3701020049标识山东济南历下区 信息行业接入 + # [可选] + domain: 4405010000 + # [可选] + id: 44050100002000000002 + # [可选] 默认设备认证密码,后续扩展使用设备单独密码, 移除密码将不进行校验 + password: 123456 + expire: 3600 + transport: "UDP" + server: + ip: 10.10.10.20 +# ip: 192.168.10.32 +# ip: 192.168.3.12 + port: 5060 + password: 123456 + domain: 4405010000 + id: 44050100002000000001 + +media: + ip: 10.10.10.200 + url: 'http://10.10.10.200:5080' + # url: 'http://10.10.10.200:12580/anything/' + id: amrWMKmbKqoBjRQ9 +# secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc + secret: 4155cca6-2f9f-11ee-85e6-8de4ce2e7333 diff --git a/gb28181-mocking-starter/src/main/resources/application.yml b/gb28181-mocking-starter/src/main/resources/application.yml index 78c17bc..4d40faf 100644 --- a/gb28181-mocking-starter/src/main/resources/application.yml +++ b/gb28181-mocking-starter/src/main/resources/application.yml @@ -24,6 +24,8 @@ spring: username: root password: 123456a url: jdbc:mysql://192.168.1.241:3306/gb28181_docking_platform?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + profiles: + active: local gb28181: # 作为28181服务器的配置 diff --git a/gb28181-mocking-starter/src/main/resources/logback.xml b/gb28181-mocking-starter/src/main/resources/logback.xml new file mode 100644 index 0000000..dca0ed8 --- /dev/null +++ b/gb28181-mocking-starter/src/main/resources/logback.xml @@ -0,0 +1,54 @@ + + + + + logback + + + + + + + + + + + + + %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %yellow(at %class.%method) (%file:%line\) - %cyan(%msg%n) + + UTF-8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +