Commit 9bd4bf0eaaf344c92535d6d8867c06d385f5af03
Committed by
GitHub
Merge pull request #4771 from thingsboard/Coap_oneEndPoint
Coap: noSec one Endpoint
Showing
2 changed files
with
10 additions
and
18 deletions
... | ... | @@ -87,12 +87,6 @@ public class DefaultCoapServerService implements CoapServerService { |
87 | 87 | } |
88 | 88 | |
89 | 89 | private CoapServer createCoapServer() throws UnknownHostException { |
90 | - server = new CoapServer(); | |
91 | - | |
92 | - CoapEndpoint.Builder noSecCoapEndpointBuilder = new CoapEndpoint.Builder(); | |
93 | - InetAddress addr = InetAddress.getByName(coapServerContext.getHost()); | |
94 | - InetSocketAddress sockAddr = new InetSocketAddress(addr, coapServerContext.getPort()); | |
95 | - noSecCoapEndpointBuilder.setInetSocketAddress(sockAddr); | |
96 | 90 | NetworkConfig networkConfig = new NetworkConfig(); |
97 | 91 | networkConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_STRICT_BLOCK2_OPTION, true); |
98 | 92 | networkConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true); |
... | ... | @@ -102,14 +96,23 @@ public class DefaultCoapServerService implements CoapServerService { |
102 | 96 | networkConfig.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 1024); |
103 | 97 | networkConfig.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024); |
104 | 98 | networkConfig.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 4); |
99 | + networkConfig.setInt(NetworkConfig.Keys.COAP_PORT, coapServerContext.getPort()); | |
100 | + server = new CoapServer(networkConfig); | |
101 | + | |
102 | + CoapEndpoint.Builder noSecCoapEndpointBuilder = new CoapEndpoint.Builder(); | |
103 | + InetAddress addr = InetAddress.getByName(coapServerContext.getHost()); | |
104 | + InetSocketAddress sockAddr = new InetSocketAddress(addr, coapServerContext.getPort()); | |
105 | + noSecCoapEndpointBuilder.setInetSocketAddress(sockAddr); | |
106 | + | |
105 | 107 | noSecCoapEndpointBuilder.setNetworkConfig(networkConfig); |
106 | 108 | CoapEndpoint noSecCoapEndpoint = noSecCoapEndpointBuilder.build(); |
107 | 109 | server.addEndpoint(noSecCoapEndpoint); |
108 | - | |
109 | 110 | if (isDtlsEnabled()) { |
110 | 111 | CoapEndpoint.Builder dtlsCoapEndpointBuilder = new CoapEndpoint.Builder(); |
111 | 112 | TbCoapDtlsSettings dtlsSettings = coapServerContext.getDtlsSettings(); |
112 | 113 | DtlsConnectorConfig dtlsConnectorConfig = dtlsSettings.dtlsConnectorConfig(); |
114 | + networkConfig.setInt(NetworkConfig.Keys.COAP_SECURE_PORT, dtlsConnectorConfig.getAddress().getPort()); | |
115 | + dtlsCoapEndpointBuilder.setNetworkConfig(networkConfig); | |
113 | 116 | DTLSConnector connector = new DTLSConnector(dtlsConnectorConfig); |
114 | 117 | dtlsCoapEndpointBuilder.setConnector(connector); |
115 | 118 | CoapEndpoint dtlsCoapEndpoint = dtlsCoapEndpointBuilder.build(); | ... | ... |
... | ... | @@ -18,7 +18,6 @@ package org.thingsboard.server.transport.coap; |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | 19 | import org.eclipse.californium.core.CoapResource; |
20 | 20 | import org.eclipse.californium.core.CoapServer; |
21 | -import org.eclipse.californium.core.network.config.NetworkConfig; | |
22 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
23 | 22 | import org.springframework.stereotype.Service; |
24 | 23 | import org.thingsboard.server.coapserver.CoapServerService; |
... | ... | @@ -31,8 +30,6 @@ import javax.annotation.PostConstruct; |
31 | 30 | import javax.annotation.PreDestroy; |
32 | 31 | import java.net.UnknownHostException; |
33 | 32 | |
34 | -import static org.eclipse.californium.core.network.config.NetworkConfigDefaults.DEFAULT_BLOCKWISE_STATUS_LIFETIME; | |
35 | - | |
36 | 33 | @Service("CoapTransportService") |
37 | 34 | @TbCoapServerComponent |
38 | 35 | @Slf4j |
... | ... | @@ -55,14 +52,6 @@ public class CoapTransportService implements TbTransportService { |
55 | 52 | public void init() throws UnknownHostException { |
56 | 53 | log.info("Starting CoAP transport..."); |
57 | 54 | coapServer = coapServerService.getCoapServer(); |
58 | - coapServer.getConfig().setBoolean(NetworkConfig.Keys.BLOCKWISE_STRICT_BLOCK2_OPTION, true); | |
59 | - coapServer.getConfig().setBoolean(NetworkConfig.Keys.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true); | |
60 | - coapServer.getConfig().setLong(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, DEFAULT_BLOCKWISE_STATUS_LIFETIME); | |
61 | - coapServer.getConfig().setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE, 256 * 1024 * 1024); | |
62 | - coapServer.getConfig().setString(NetworkConfig.Keys.RESPONSE_MATCHING, "RELAXED"); | |
63 | - coapServer.getConfig().setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 1024); | |
64 | - coapServer.getConfig().setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024); | |
65 | - coapServer.getConfig().setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 10); | |
66 | 55 | CoapResource api = new CoapResource(API); |
67 | 56 | api.add(new CoapTransportResource(coapTransportContext, coapServerService, V1)); |
68 | 57 | ... | ... |