Skip to content

Commit

Permalink
Use the new clone API on DtlsconfigBuilder from californium
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Sep 20, 2018
1 parent 921e31c commit 116d6f0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.californium.elements.auth.RawPublicKeyIdentity;
import org.eclipse.californium.scandium.DTLSConnector;
import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
import org.eclipse.californium.scandium.config.DtlsConnectorConfig.Builder;
import org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore;
import org.eclipse.californium.scandium.dtls.rpkstore.TrustedRpkStore;
Expand Down Expand Up @@ -73,7 +72,7 @@ public synchronized Identity createEndpoint(ServerInfo serverInfo) {
// Create new endpoint
Identity server;
if (serverInfo.isSecure()) {
Builder newBuilder = cloneDtlsConfigBuilder(dtlsConfigbuilder);
Builder newBuilder = new Builder(dtlsConfigbuilder.getIncompleteConfig());

// Support PSK
if (serverInfo.secureMode == SecurityMode.PSK) {
Expand Down Expand Up @@ -140,43 +139,6 @@ public boolean isTrusted(RawPublicKeyIdentity id) {
return server;
}

public static Builder cloneDtlsConfigBuilder(Builder builder) {
return cloneDtlsConfigBuilder(builder.getIncompleteConfig());
}

public static Builder cloneDtlsConfigBuilder(DtlsConnectorConfig config) {
Builder newBuilder = new Builder();

newBuilder.setAddress(config.getAddress());
newBuilder.setMaxConnections(config.getMaxConnections());
newBuilder.setStaleConnectionThreshold(config.getStaleConnectionThreshold());
newBuilder.setConnectionThreadCount(config.getConnectionThreadCount());

if (config.getPskStore() != null)
newBuilder.setPskStore(config.getPskStore());
if (config.isAddressReuseEnabled() != null)
newBuilder.setEnableAddressReuse(config.isAddressReuseEnabled());
if (config.isClientAuthenticationRequired() != null)
newBuilder.setClientAuthenticationRequired(config.isClientAuthenticationRequired());
if (config.isEarlyStopRetransmission() != null)
newBuilder.setEarlyStopRetransmission(config.isEarlyStopRetransmission());
if (config.getMaxFragmentLengthCode() != null)
newBuilder.setMaxFragmentLengthCode(config.getMaxFragmentLengthCode());
if (config.getMaxRetransmissions() != null)
newBuilder.setMaxRetransmissions(config.getMaxRetransmissions());
if (config.getOutboundMessageBufferSize() != null)
newBuilder.setOutboundMessageBufferSize(config.getOutboundMessageBufferSize());
if (config.getRetransmissionTimeout() != null)
newBuilder.setRetransmissionTimeout(config.getRetransmissionTimeout());
if (config.getTrustStore() != null)
newBuilder.setTrustStore(config.getTrustStore());

// TODO we should probably clean cipherSuite depending on which kind of endpoint(psk,rpk,x509) we will create
// in case users choose specific cipher

return newBuilder;
}

@Override
public synchronized Collection<Server> createEndpoints(Collection<? extends ServerInfo> serverInfo) {
if (serverInfo == null || serverInfo.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.eclipse.californium.scandium.config.DtlsConnectorConfig.Builder;
import org.eclipse.leshan.LwM2mId;
import org.eclipse.leshan.client.californium.LeshanClientBuilder;
import org.eclipse.leshan.client.californium.impl.CaliforniumEndpointsManager;
import org.eclipse.leshan.client.object.Device;
import org.eclipse.leshan.client.object.Security;
import org.eclipse.leshan.client.object.Server;
Expand Down Expand Up @@ -200,7 +199,7 @@ public CoapEndpoint createUnsecuredEndpoint(InetSocketAddress address, NetworkCo
public CoapEndpoint createSecuredEndpoint(DtlsConnectorConfig dtlsConfig, NetworkConfig coapConfig,
ObservationStore store) {
CoapEndpoint.CoapEndpointBuilder builder = new CoapEndpoint.CoapEndpointBuilder();
Builder dtlsConfigBuilder = CaliforniumEndpointsManager.cloneDtlsConfigBuilder(dtlsConfig);
Builder dtlsConfigBuilder = new Builder(dtlsConfig);
if (dtlsConfig.getPskStore() != null) {
String identity = dtlsConfig.getPskStore().getIdentity(null);
byte[] key = dtlsConfig.getPskStore().getKey(null);
Expand Down

0 comments on commit 116d6f0

Please sign in to comment.