diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 72a804faa3..99e3571503 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -937,7 +937,7 @@ transport: client_side_rpc: # Processing timeout interval of the RPC command on the CLIENT SIDE. Time in milliseconds timeout: "${CLIENT_SIDE_RPC_TIMEOUT:60000}" - # Enable/disable http/mqtt/coap transport protocols (has higher priority than certain protocol's 'enabled' property) + # Enable/disable http/mqtt/coap/lwm2m transport protocols (has higher priority than certain protocol's 'enabled' property) api_enabled: "${TB_TRANSPORT_API_ENABLED:true}" log: # Enable/Disable log of transport messages to telemetry. For example, logging of LwM2M registration update @@ -1024,10 +1024,6 @@ transport: coap: # Enable/disable CoAP transport protocol. enabled: "${COAP_ENABLED:true}" - # CoAP bind-address - bind_address: "${COAP_BIND_ADDRESS:0.0.0.0}" - # CoAP bind port - bind_port: "${COAP_BIND_PORT:5683}" # CoaP processing timeout in milliseconds timeout: "${COAP_TIMEOUT:10000}" # CoaP piggyback response timeout in milliseconds @@ -1036,56 +1032,6 @@ transport: psm_activity_timer: "${COAP_PSM_ACTIVITY_TIMER:10000}" # Default PSM Activity Timer if not specified in device profile paging_transmission_window: "${COAP_PAGING_TRANSMISSION_WINDOW:10000}" - dtls: - # Enable/disable DTLS 1.2 support - enabled: "${COAP_DTLS_ENABLED:false}" - # RFC7925_RETRANSMISSION_TIMEOUT_IN_MILLISECONDS = 9000 - retransmission_timeout: "${COAP_DTLS_RETRANSMISSION_TIMEOUT_MS:9000}" - # CoAP DTLS bind-address - bind_address: "${COAP_DTLS_BIND_ADDRESS:0.0.0.0}" - # CoAP DTLS bind port - bind_port: "${COAP_DTLS_BIND_PORT:5684}" - # Server DTLS credentials - # CoAP DTLS connection ID length. RFC 9146, Connection Identifier for DTLS 1.2 - # Default: off - # Control usage of DTLS connection ID length (CID). - # - 'off' to deactivate it. - # - 'on' to activate Connection ID support (same as CID 0 or more 0). - # - A positive value defines generated CID size in bytes. - # - A value of 0 means we accept using CID but will not generate one for foreign peer (enables support but not for incoming traffic). - # - A value between 0 and <= 4: SingleNodeConnectionIdGenerator is used - # - A value that are > 4: MultiNodeConnectionIdGenerator is used - connection_id_length: "${COAP_DTLS_CONNECTION_ID_LENGTH:}" - credentials: - # Server credentials type (PEM - pem certificate file; KEYSTORE - java keystore) - type: "${COAP_DTLS_CREDENTIALS_TYPE:PEM}" - # PEM server credentials - pem: - # Path to the server certificate file (holds server certificate or certificate chain, may include server private key) - cert_file: "${COAP_DTLS_PEM_CERT:coapserver.pem}" - # Path to the server certificate private key file. Optional by default. Required if the private key is not present in the server certificate file; - key_file: "${COAP_DTLS_PEM_KEY:coapserver_key.pem}" - # Server certificate private key password (optional) - key_password: "${COAP_DTLS_PEM_KEY_PASSWORD:server_key_password}" - # Keystore server credentials - keystore: - # Type of the key store (JKS or PKCS12) - type: "${COAP_DTLS_KEY_STORE_TYPE:JKS}" - # Path to the key store that holds the SSL certificate - store_file: "${COAP_DTLS_KEY_STORE:coapserver.jks}" - # Password used to access the key store - store_password: "${COAP_DTLS_KEY_STORE_PASSWORD:server_ks_password}" - # Key alias - key_alias: "${COAP_DTLS_KEY_ALIAS:serveralias}" - # Password used to access the key - key_password: "${COAP_DTLS_KEY_PASSWORD:server_key_password}" - x509: - # Skip certificate validity check for client certificates. - skip_validity_check_for_client_cert: "${TB_COAP_X509_DTLS_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}" - # Inactivity timeout of DTLS session. Used to clean cache - dtls_session_inactivity_timeout: "${TB_COAP_X509_DTLS_SESSION_INACTIVITY_TIMEOUT:86400000}" - # Interval of periodic eviction of the timed-out DTLS sessions - dtls_session_report_timeout: "${TB_COAP_X509_DTLS_SESSION_REPORT_TIMEOUT:1800000}" # Local LwM2M transport parameters lwm2m: # Enable/disable LwM2M transport protocol. @@ -1250,6 +1196,65 @@ transport: # Interval of transport statistics logging print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}" +# CoAP server parameters +coap: + # Enable/disable coap server. + enabled: "${COAP_SERVER_ENABLED:true}" + # CoAP bind address + bind_address: "${COAP_BIND_ADDRESS:0.0.0.0}" + # CoAP bind port + bind_port: "${COAP_BIND_PORT:5683}" + dtls: + # Enable/disable DTLS 1.2 support + enabled: "${COAP_DTLS_ENABLED:false}" + # RFC7925_RETRANSMISSION_TIMEOUT_IN_MILLISECONDS = 9000 + retransmission_timeout: "${COAP_DTLS_RETRANSMISSION_TIMEOUT_MS:9000}" + # CoAP DTLS bind address + bind_address: "${COAP_DTLS_BIND_ADDRESS:0.0.0.0}" + # CoAP DTLS bind port + bind_port: "${COAP_DTLS_BIND_PORT:5684}" + # CoAP DTLS connection ID length. RFC 9146, Connection Identifier for DTLS 1.2 + # Default: off + # Control usage of DTLS connection ID length (CID). + # - 'off' to deactivate it. + # - 'on' to activate Connection ID support (same as CID 0 or more 0). + # - A positive value defines generated CID size in bytes. + # - A value of 0 means we accept using CID but will not generate one for foreign peer (enables support but not for incoming traffic). + # - A value between 0 and <= 4: SingleNodeConnectionIdGenerator is used + # - A value that are > 4: MultiNodeConnectionIdGenerator is used + connection_id_length: "${COAP_DTLS_CONNECTION_ID_LENGTH:}" + # Server DTLS credentials + credentials: + # Server credentials type (PEM - pem certificate file; KEYSTORE - java keystore) + type: "${COAP_DTLS_CREDENTIALS_TYPE:PEM}" + # PEM server credentials + pem: + # Path to the server certificate file (holds server certificate or certificate chain, may include server private key) + cert_file: "${COAP_DTLS_PEM_CERT:coapserver.pem}" + # Path to the server certificate private key file. Optional by default. Required if the private key is not present in the server certificate file; + key_file: "${COAP_DTLS_PEM_KEY:coapserver_key.pem}" + # Server certificate private key password (optional) + key_password: "${COAP_DTLS_PEM_KEY_PASSWORD:server_key_password}" + # Keystore server credentials + keystore: + # Type of the key store (JKS or PKCS12) + type: "${COAP_DTLS_KEY_STORE_TYPE:JKS}" + # Path to the key store that holds the SSL certificate + store_file: "${COAP_DTLS_KEY_STORE:coapserver.jks}" + # Password used to access the key store + store_password: "${COAP_DTLS_KEY_STORE_PASSWORD:server_ks_password}" + # Key alias + key_alias: "${COAP_DTLS_KEY_ALIAS:serveralias}" + # Password used to access the key + key_password: "${COAP_DTLS_KEY_PASSWORD:server_key_password}" + x509: + # Skip certificate validity check for client certificates. + skip_validity_check_for_client_cert: "${TB_COAP_X509_DTLS_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}" + # Inactivity timeout of DTLS session. Used to cleanup cache + dtls_session_inactivity_timeout: "${TB_COAP_X509_DTLS_SESSION_INACTIVITY_TIMEOUT:86400000}" + # Interval of periodic eviction of the timed-out DTLS sessions + dtls_session_report_timeout: "${TB_COAP_X509_DTLS_SESSION_REPORT_TIMEOUT:1800000}" + # Device connectivity parameters device: connectivity: diff --git a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/CoapServerContext.java b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/CoapServerContext.java index 06a4d5d690..46caba5f29 100644 --- a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/CoapServerContext.java +++ b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/CoapServerContext.java @@ -27,29 +27,13 @@ import org.springframework.stereotype.Component; public class CoapServerContext { @Getter - @Value("${transport.coap.bind_address}") + @Value("${coap.bind_address}") private String host; @Getter - @Value("${transport.coap.bind_port}") + @Value("${coap.bind_port}") private Integer port; - @Getter - @Value("${transport.coap.timeout}") - private Long timeout; - - @Getter - @Value("${transport.coap.piggyback_timeout}") - private Long piggybackTimeout; - - @Getter - @Value("${transport.coap.psm_activity_timer:10000}") - private long psmActivityTimer; - - @Getter - @Value("${transport.coap.paging_transmission_window:10000}") - private long pagingTransmissionWindow; - @Getter @Autowired(required = false) private TbCoapDtlsSettings dtlsSettings; diff --git a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/CoapServerService.java b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/CoapServerService.java index c5c30d4bc0..0b1ba35709 100644 --- a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/CoapServerService.java +++ b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/CoapServerService.java @@ -26,9 +26,4 @@ public interface CoapServerService { CoapServer getCoapServer() throws UnknownHostException; ConcurrentMap getDtlsSessionsMap(); - - long getTimeout(); - - long getPiggybackTimeout(); - } diff --git a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/DefaultCoapServerService.java b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/DefaultCoapServerService.java index 0eca05aab2..508103a1db 100644 --- a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/DefaultCoapServerService.java +++ b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/DefaultCoapServerService.java @@ -83,16 +83,6 @@ public class DefaultCoapServerService implements CoapServerService { return tbDtlsCertificateVerifier != null ? tbDtlsCertificateVerifier.getTbCoapDtlsSessionsMap() : null; } - @Override - public long getTimeout() { - return coapServerContext.getTimeout(); - } - - @Override - public long getPiggybackTimeout() { - return coapServerContext.getPiggybackTimeout(); - } - private CoapServer createCoapServer() throws UnknownHostException { Configuration networkConfig = new Configuration(); networkConfig.set(CoapConfig.BLOCKWISE_STRICT_BLOCK2_OPTION, true); diff --git a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapDtlsSettings.java b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapDtlsSettings.java index c2cf1a4603..f83a20b139 100644 --- a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapDtlsSettings.java +++ b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapDtlsSettings.java @@ -50,24 +50,24 @@ import static org.eclipse.californium.scandium.config.DtlsConfig.DtlsRole.SERVER @Getter @Slf4j -@ConditionalOnProperty(prefix = "transport.coap.dtls", value = "enabled", havingValue = "true", matchIfMissing = false) +@ConditionalOnProperty(prefix = "coap.dtls", value = "enabled", havingValue = "true") @Component public class TbCoapDtlsSettings { - @Value("${transport.coap.dtls.bind_address}") + @Value("${coap.dtls.bind_address}") private String host; - @Value("${transport.coap.dtls.bind_port}") + @Value("${coap.dtls.bind_port}") private Integer port; - @Value("${transport.coap.dtls.retransmission_timeout:9000}") + @Value("${coap.dtls.retransmission_timeout:9000}") private int dtlsRetransmissionTimeout; - @Value("${transport.coap.dtls.connection_id_length:}") + @Value("${coap.dtls.connection_id_length:}") private Integer cIdLength; @Bean - @ConfigurationProperties(prefix = "transport.coap.dtls.credentials") + @ConfigurationProperties(prefix = "coap.dtls.credentials") public SslCredentialsConfig coapDtlsCredentials() { return new SslCredentialsConfig("COAP DTLS Credentials", false); } @@ -76,19 +76,19 @@ public class TbCoapDtlsSettings { @Qualifier("coapDtlsCredentials") private SslCredentialsConfig coapDtlsCredentialsConfig; - @Value("${transport.coap.dtls.x509.skip_validity_check_for_client_cert:false}") + @Value("${coap.dtls.x509.skip_validity_check_for_client_cert:false}") private boolean skipValidityCheckForClientCert; - @Value("${transport.coap.dtls.x509.dtls_session_inactivity_timeout:86400000}") + @Value("${coap.dtls.x509.dtls_session_inactivity_timeout:86400000}") private long dtlsSessionInactivityTimeout; - @Value("${transport.coap.dtls.x509.dtls_session_report_timeout:1800000}") + @Value("${coap.dtls.x509.dtls_session_report_timeout:1800000}") private long dtlsSessionReportTimeout; - @Autowired + @Autowired(required = false) private TransportService transportService; - @Autowired + @Autowired(required = false) private TbServiceInfoProvider serviceInfoProvider; public DtlsConnectorConfig dtlsConnectorConfig(Configuration configuration) throws UnknownHostException { @@ -100,8 +100,8 @@ public class TbCoapDtlsSettings { configBuilder.set(DTLS_CLIENT_AUTHENTICATION_MODE, WANTED); configBuilder.set(DTLS_RETRANSMISSION_TIMEOUT, dtlsRetransmissionTimeout, MILLISECONDS); configBuilder.set(DTLS_ROLE, SERVER_ONLY); - configBuilder.set(DTLS_CONNECTION_ID_LENGTH, cIdLength); if (cIdLength != null) { + configBuilder.set(DTLS_CONNECTION_ID_LENGTH, cIdLength); if (cIdLength > 4) { configBuilder.set(DTLS_CONNECTION_ID_NODE_ID, 0); } else { diff --git a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapServerComponent.java b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapServerComponent.java index c468c71095..2d94de2682 100644 --- a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapServerComponent.java +++ b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapServerComponent.java @@ -21,6 +21,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) -@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')") +@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${coap.enabled}'=='true')") public @interface TbCoapServerComponent { } diff --git a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapTransportComponent.java b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapTransportComponent.java new file mode 100644 index 0000000000..33f4b36b70 --- /dev/null +++ b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapTransportComponent.java @@ -0,0 +1,27 @@ +/** + * Copyright © 2016-2024 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.thingsboard.server.coapserver; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || " + + "('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${coap.enabled}'=='true' && '${transport.coap.enabled}'=='true')") +public @interface TbCoapTransportComponent { +} diff --git a/common/coap-server/src/test/java/org/thingsboard/server/coapserver/TbCoapDtlsSettingsTest.java b/common/coap-server/src/test/java/org/thingsboard/server/coapserver/TbCoapDtlsSettingsTest.java index 72f5b964ae..870c4210e5 100644 --- a/common/coap-server/src/test/java/org/thingsboard/server/coapserver/TbCoapDtlsSettingsTest.java +++ b/common/coap-server/src/test/java/org/thingsboard/server/coapserver/TbCoapDtlsSettingsTest.java @@ -28,14 +28,14 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(classes = TbCoapDtlsSettings.class) @TestPropertySource(properties = { - "transport.coap.dtls.enabled=true", - "transport.coap.dtls.bind_address=192.168.1.1", - "transport.coap.dtls.bind_port=1234", - "transport.coap.dtls.retransmission_timeout=100", - "transport.coap.dtls.connection_id_length=500", - "transport.coap.dtls.x509.skip_validity_check_for_client_cert=true", - "transport.coap.dtls.x509.dtls_session_inactivity_timeout=1000", - "transport.coap.dtls.x509.dtls_session_report_timeout=3000", + "coap.dtls.enabled=true", + "coap.dtls.bind_address=192.168.1.1", + "coap.dtls.bind_port=1234", + "coap.dtls.retransmission_timeout=100", + "coap.dtls.connection_id_length=500", + "coap.dtls.x509.skip_validity_check_for_client_cert=true", + "coap.dtls.x509.dtls_session_inactivity_timeout=1000", + "coap.dtls.x509.dtls_session_report_timeout=3000", }) class TbCoapDtlsSettingsTest { diff --git a/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportContext.java b/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportContext.java index 1b9f111ac1..2190380065 100644 --- a/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportContext.java +++ b/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportContext.java @@ -19,8 +19,8 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; +import org.thingsboard.server.coapserver.TbCoapTransportComponent; import org.thingsboard.server.common.transport.TransportContext; import org.thingsboard.server.gen.transport.TransportProtos; import org.thingsboard.server.transport.coap.adaptors.JsonCoapAdaptor; @@ -36,7 +36,7 @@ import java.util.concurrent.ConcurrentMap; * Created by ashvayka on 18.10.18. */ @Slf4j -@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')") +@TbCoapTransportComponent @Component @Getter public class CoapTransportContext extends TransportContext { @@ -44,6 +44,22 @@ public class CoapTransportContext extends TransportContext { @Value("${transport.sessions.report_timeout}") private long sessionReportTimeout; + @Getter + @Value("${transport.coap.timeout}") + private Long timeout; + + @Getter + @Value("${transport.coap.piggyback_timeout}") + private Long piggybackTimeout; + + @Getter + @Value("${transport.coap.psm_activity_timer:10000}") + private long psmActivityTimer; + + @Getter + @Value("${transport.coap.paging_transmission_window:10000}") + private long pagingTransmissionWindow; + @Autowired private JsonCoapAdaptor jsonCoapAdaptor; diff --git a/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java b/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java index ebc52fc034..67ae1b9ae7 100644 --- a/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java +++ b/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java @@ -75,8 +75,8 @@ public class CoapTransportResource extends AbstractCoapTransportResource { this.setObservable(true); // enable observing this.addObserver(new CoapResourceObserver()); this.dtlsSessionsMap = coapServerService.getDtlsSessionsMap(); - this.timeout = coapServerService.getTimeout(); - this.piggybackTimeout = coapServerService.getPiggybackTimeout(); + this.timeout = ctx.getTimeout(); + this.piggybackTimeout = ctx.getPiggybackTimeout(); this.clients = ctx.getClientContext(); long sessionReportTimeout = ctx.getSessionReportTimeout(); ctx.getScheduler().scheduleAtFixedRate(clients::reportActivity, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS); diff --git a/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportService.java b/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportService.java index ada19e2ccb..07e7c1b4b4 100644 --- a/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportService.java +++ b/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportService.java @@ -15,24 +15,24 @@ */ package org.thingsboard.server.transport.coap; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import lombok.extern.slf4j.Slf4j; import org.eclipse.californium.core.CoapResource; import org.eclipse.californium.core.CoapServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.thingsboard.server.coapserver.CoapServerService; -import org.thingsboard.server.coapserver.TbCoapServerComponent; +import org.thingsboard.server.coapserver.TbCoapTransportComponent; import org.thingsboard.server.common.data.DataConstants; import org.thingsboard.server.common.data.TbTransportService; import org.thingsboard.server.common.data.ota.OtaPackageType; import org.thingsboard.server.transport.coap.efento.CoapEfentoTransportResource; -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; import java.net.UnknownHostException; @Service("CoapTransportService") -@TbCoapServerComponent +@TbCoapTransportComponent @Slf4j public class CoapTransportService implements TbTransportService { diff --git a/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/client/DefaultCoapClientContext.java b/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/client/DefaultCoapClientContext.java index 8dafc18a88..6f117dbf29 100644 --- a/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/client/DefaultCoapClientContext.java +++ b/common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/client/DefaultCoapClientContext.java @@ -21,11 +21,11 @@ import org.eclipse.californium.core.coap.CoAP; import org.eclipse.californium.core.coap.Response; import org.eclipse.californium.core.observe.ObserveRelation; import org.eclipse.californium.core.server.resources.CoapExchange; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.context.annotation.Lazy; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; import org.thingsboard.server.coapserver.CoapServerContext; +import org.thingsboard.server.coapserver.TbCoapTransportComponent; import org.thingsboard.server.common.adaptor.AdaptorException; import org.thingsboard.server.common.data.DataConstants; import org.thingsboard.server.common.data.Device; @@ -81,7 +81,7 @@ import static org.eclipse.californium.core.coap.Message.NONE; @Slf4j @Service -@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')") +@TbCoapTransportComponent public class DefaultCoapClientContext implements CoapClientContext { private final CoapServerContext config; @@ -266,7 +266,7 @@ public class DefaultCoapClientContext implements CoapClientContext { } if (psmActivityTimer == null || psmActivityTimer == 0L) { - psmActivityTimer = config.getPsmActivityTimer(); + psmActivityTimer = transportContext.getPsmActivityTimer(); } timeout = psmActivityTimer; @@ -277,7 +277,7 @@ public class DefaultCoapClientContext implements CoapClientContext { } if (pagingTransmissionWindow == null || pagingTransmissionWindow == 0L) { - pagingTransmissionWindow = config.getPagingTransmissionWindow(); + pagingTransmissionWindow = transportContext.getPagingTransmissionWindow(); } timeout = pagingTransmissionWindow; } @@ -757,7 +757,7 @@ public class DefaultCoapClientContext implements CoapClientContext { } if (psmActivityTimer == null || psmActivityTimer == 0L) { - psmActivityTimer = config.getPsmActivityTimer(); + psmActivityTimer = transportContext.getPsmActivityTimer(); } return timeSinceLastUplink <= psmActivityTimer; } else { @@ -767,7 +767,7 @@ public class DefaultCoapClientContext implements CoapClientContext { } if (pagingTransmissionWindow == null || pagingTransmissionWindow == 0L) { - pagingTransmissionWindow = config.getPagingTransmissionWindow(); + pagingTransmissionWindow = transportContext.getPagingTransmissionWindow(); } boolean allowed = timeSinceLastUplink <= pagingTransmissionWindow; if (!allowed) { diff --git a/transport/coap/src/main/resources/tb-coap-transport.yml b/transport/coap/src/main/resources/tb-coap-transport.yml index fbd64b8d59..f2ea0c1685 100644 --- a/transport/coap/src/main/resources/tb-coap-transport.yml +++ b/transport/coap/src/main/resources/tb-coap-transport.yml @@ -130,13 +130,11 @@ redis: # Determines the behavior when a thread requests a connection from the pool but there are no available connections and the pool cannot create more due to the maxTotal configuration blockWhenExhausted: "${REDIS_POOL_CONFIG_BLOCK_WHEN_EXHAUSTED:true}" -# COAP server parameters transport: + # Local CoAP transport parameters coap: - # CoAP bind-address - bind_address: "${COAP_BIND_ADDRESS:0.0.0.0}" - # CoAP bind port - bind_port: "${COAP_BIND_PORT:5683}" + # Enable/disable coap transport protocol. + enabled: "${COAP_ENABLED:true}" # CoaP processing timeout in milliseconds timeout: "${COAP_TIMEOUT:10000}" # CoaP piggyback response timeout in milliseconds @@ -145,57 +143,6 @@ transport: psm_activity_timer: "${COAP_PSM_ACTIVITY_TIMER:10000}" # Default PSM Activity Timer if not specified in device profile paging_transmission_window: "${COAP_PAGING_TRANSMISSION_WINDOW:10000}" - dtls: - # Enable/disable DTLS 1.2 support - enabled: "${COAP_DTLS_ENABLED:false}" - # RFC7925_RETRANSMISSION_TIMEOUT_IN_MILLISECONDS = 9000 - retransmission_timeout: "${COAP_DTLS_RETRANSMISSION_TIMEOUT_MS:9000}" - # CoAP DTLS bind address - bind_address: "${COAP_DTLS_BIND_ADDRESS:0.0.0.0}" - # CoAP DTLS bind port - bind_port: "${COAP_DTLS_BIND_PORT:5684}" - # Server DTLS credentials - # Server DTLS credentials - # CoAP DTLS connection ID length. RFC 9146, Connection Identifier for DTLS 1.2 - # Default: off - # Control usage of DTLS connection ID length (CID). - # - 'off' to deactivate it. - # - 'on' to activate Connection ID support (same as CID 0 or more 0). - # - A positive value defines generated CID size in bytes. - # - A value of 0 means we accept using CID but will not generate one for foreign peer (enables support but not for incoming traffic). - # - A value between 0 and <= 4: SingleNodeConnectionIdGenerator is used - # - A value that are > 4: MultiNodeConnectionIdGenerator is used - connection_id_length: "${COAP_DTLS_CONNECTION_ID_LENGTH:}" - credentials: - # Server credentials type (PEM - pem certificate file; KEYSTORE - java keystore) - type: "${COAP_DTLS_CREDENTIALS_TYPE:PEM}" - # PEM server credentials - pem: - # Path to the server certificate file (holds server certificate or certificate chain, may include server private key) - cert_file: "${COAP_DTLS_PEM_CERT:coapserver.pem}" - # Path to the server certificate private key file. Optional by default. Required if the private key is not present in server certificate file; - key_file: "${COAP_DTLS_PEM_KEY:coapserver_key.pem}" - # Server certificate private key password (optional) - key_password: "${COAP_DTLS_PEM_KEY_PASSWORD:server_key_password}" - # Keystore server credentials - keystore: - # Type of the key store (JKS or PKCS12) - type: "${COAP_DTLS_KEY_STORE_TYPE:JKS}" - # Path to the key store that holds the SSL certificate - store_file: "${COAP_DTLS_KEY_STORE:coapserver.jks}" - # Password used to access the key store - store_password: "${COAP_DTLS_KEY_STORE_PASSWORD:server_ks_password}" - # Key alias - key_alias: "${COAP_DTLS_KEY_ALIAS:serveralias}" - # Password used to access the key - key_password: "${COAP_DTLS_KEY_PASSWORD:server_key_password}" - x509: - # Skip certificate validity check for client certificates. - skip_validity_check_for_client_cert: "${TB_COAP_X509_DTLS_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}" - # Inactivity timeout of DTLS session. Used to clean cache - dtls_session_inactivity_timeout: "${TB_COAP_X509_DTLS_SESSION_INACTIVITY_TIMEOUT:86400000}" - # Interval of periodic eviction of the timed-out DTLS sessions - dtls_session_report_timeout: "${TB_COAP_X509_DTLS_SESSION_REPORT_TIMEOUT:1800000}" sessions: # Session inactivity timeout is a global configuration parameter that defines how long the device transport session will be opened after the last message arrives from the device. # The parameter value is in milliseconds. @@ -224,6 +171,65 @@ transport: # Interval of transport statistics logging print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}" +# CoAP server parameters +coap: + # Enable/disable coap transport protocol. + enabled: "${COAP_SERVER_ENABLED:true}" + # CoAP bind-address + bind_address: "${COAP_BIND_ADDRESS:0.0.0.0}" + # CoAP bind port + bind_port: "${COAP_BIND_PORT:5683}" + dtls: + # Enable/disable DTLS 1.2 support + enabled: "${COAP_DTLS_ENABLED:false}" + # RFC7925_RETRANSMISSION_TIMEOUT_IN_MILLISECONDS = 9000 + retransmission_timeout: "${COAP_DTLS_RETRANSMISSION_TIMEOUT_MS:9000}" + # CoAP DTLS bind address + bind_address: "${COAP_DTLS_BIND_ADDRESS:0.0.0.0}" + # CoAP DTLS bind port + bind_port: "${COAP_DTLS_BIND_PORT:5684}" + # CoAP DTLS connection ID length. RFC 9146, Connection Identifier for DTLS 1.2 + # Default: off + # Control usage of DTLS connection ID length (CID). + # - 'off' to deactivate it. + # - 'on' to activate Connection ID support (same as CID 0 or more 0). + # - A positive value defines generated CID size in bytes. + # - A value of 0 means we accept using CID but will not generate one for foreign peer (enables support but not for incoming traffic). + # - A value between 0 and <= 4: SingleNodeConnectionIdGenerator is used + # - A value that are > 4: MultiNodeConnectionIdGenerator is used + connection_id_length: "${COAP_DTLS_CONNECTION_ID_LENGTH:}" + # Server DTLS credentials + credentials: + # Server credentials type (PEM - pem certificate file; KEYSTORE - java keystore) + type: "${COAP_DTLS_CREDENTIALS_TYPE:PEM}" + # PEM server credentials + pem: + # Path to the server certificate file (holds server certificate or certificate chain, may include server private key) + cert_file: "${COAP_DTLS_PEM_CERT:coapserver.pem}" + # Path to the server certificate private key file. Optional by default. Required if the private key is not present in the server certificate file; + key_file: "${COAP_DTLS_PEM_KEY:coapserver_key.pem}" + # Server certificate private key password (optional) + key_password: "${COAP_DTLS_PEM_KEY_PASSWORD:server_key_password}" + # Keystore server credentials + keystore: + # Type of the key store (JKS or PKCS12) + type: "${COAP_DTLS_KEY_STORE_TYPE:JKS}" + # Path to the key store that holds the SSL certificate + store_file: "${COAP_DTLS_KEY_STORE:coapserver.jks}" + # Password used to access the key store + store_password: "${COAP_DTLS_KEY_STORE_PASSWORD:server_ks_password}" + # Key alias + key_alias: "${COAP_DTLS_KEY_ALIAS:serveralias}" + # Password used to access the key + key_password: "${COAP_DTLS_KEY_PASSWORD:server_key_password}" + x509: + # Skip certificate validity check for client certificates. + skip_validity_check_for_client_cert: "${TB_COAP_X509_DTLS_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}" + # Inactivity timeout of DTLS session. Used to cleanup cache + dtls_session_inactivity_timeout: "${TB_COAP_X509_DTLS_SESSION_INACTIVITY_TIMEOUT:86400000}" + # Interval of periodic eviction of the timed-out DTLS sessions + dtls_session_report_timeout: "${TB_COAP_X509_DTLS_SESSION_REPORT_TIMEOUT:1800000}" + # Queue configuration parameters queue: type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ) diff --git a/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml b/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml index 6f6d173aa6..bf6a159106 100644 --- a/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml +++ b/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml @@ -152,8 +152,6 @@ transport: client_side_rpc: # Processing timeout interval of the RPC command on the CLIENT SIDE. Time in milliseconds timeout: "${CLIENT_SIDE_RPC_TIMEOUT:60000}" - # Enable/disable http/mqtt/coap transport protocols (has higher priority than certain protocol's 'enabled' property) - api_enabled: "${TB_TRANSPORT_API_ENABLED:true}" log: # Enable/Disable log of transport messages to telemetry. For example, logging of LwM2M registration update enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"