use of org.eclipse.californium.core.network.config.NetworkConfig in project hono by eclipse.
the class ConfigBasedCoapEndpointFactory method getSecureNetworkConfig.
/**
* Gets the CoAP network configuration for the secure endpoint.
* <ol>
* <li>Creates a default CoAP network configuration based on {@link CoapAdapterProperties}.</li>
* <li>Merge in network configuration loaded from {@link CoapAdapterProperties#getNetworkConfig()}.</li>
* <li>Merge in network configuration loaded from {@link CoapAdapterProperties#getSecureNetworkConfig()}.</li>
* </ol>
*
* @return The network configuration for the secure endpoint.
*/
protected Future<NetworkConfig> getSecureNetworkConfig() {
final NetworkConfig networkConfig = newDefaultNetworkConfig();
networkConfig.setInt(Keys.BLOCKWISE_STATUS_LIFETIME, config.getBlockwiseStatusLifetime());
networkConfig.setInt(Keys.NETWORK_STAGE_SENDER_THREAD_COUNT, config.getDtlsThreads());
return loadNetworkConfig(config.getNetworkConfig(), networkConfig).compose(c -> loadNetworkConfig(config.getSecureNetworkConfig(), c));
}
use of org.eclipse.californium.core.network.config.NetworkConfig in project leshan by eclipse.
the class LeshanBootstrapServerDemo method createAndStartServer.
public static void createAndStartServer(int webPort, String localAddress, int localPort, String secureLocalAddress, int secureLocalPort, String modelsFolderPath, String configFilename) throws Exception {
// Create Models
List<ObjectModel> models = ObjectLoader.loadDefault();
if (modelsFolderPath != null) {
models.addAll(ObjectLoader.loadObjectsFromDir(new File(modelsFolderPath)));
}
// Prepare and start bootstrap server
LeshanBootstrapServerBuilder builder = new LeshanBootstrapServerBuilder();
BootstrapStoreImpl bsStore = new BootstrapStoreImpl(configFilename);
builder.setConfigStore(bsStore);
builder.setSecurityStore(new BootstrapSecurityStoreImpl(bsStore));
builder.setLocalAddress(localAddress, localPort);
builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
builder.setModel(new LwM2mModel(models));
// Create CoAP Config
NetworkConfig coapConfig;
File configFile = new File(NetworkConfig.DEFAULT_FILE_NAME);
if (configFile.isFile()) {
coapConfig = new NetworkConfig();
coapConfig.load(configFile);
} else {
coapConfig = LeshanServerBuilder.createDefaultNetworkConfig();
coapConfig.store(configFile);
}
builder.setCoapConfig(coapConfig);
LeshanBootstrapServer bsServer = builder.build();
bsServer.start();
// Now prepare and start jetty
Server server = new Server(webPort);
WebAppContext root = new WebAppContext();
root.setContextPath("/");
root.setResourceBase(LeshanBootstrapServerDemo.class.getClassLoader().getResource("webapp").toExternalForm());
root.setParentLoaderPriority(true);
ServletHolder bsServletHolder = new ServletHolder(new BootstrapServlet(bsStore));
root.addServlet(bsServletHolder, "/api/bootstrap/*");
ServletHolder serverServletHolder = new ServletHolder(new ServerServlet(bsServer));
root.addServlet(serverServletHolder, "/api/server/*");
server.setHandler(root);
server.start();
LOG.info("Web server started at {}.", server.getURI());
}
use of org.eclipse.californium.core.network.config.NetworkConfig in project leshan by eclipse.
the class LeshanClientBuilder method createDefaultNetworkConfig.
public static NetworkConfig createDefaultNetworkConfig() {
NetworkConfig networkConfig = new NetworkConfig();
networkConfig.set(Keys.MID_TRACKER, "NULL");
networkConfig.set(Keys.MAX_ACTIVE_PEERS, 10);
networkConfig.set(Keys.PROTOCOL_STAGE_THREAD_COUNT, 1);
return networkConfig;
}
use of org.eclipse.californium.core.network.config.NetworkConfig in project leshan by eclipse.
the class LeshanServerBuilder method createDefaultNetworkConfig.
/**
* The default Californium/CoAP {@link NetworkConfig} used by the builder.
*/
public static NetworkConfig createDefaultNetworkConfig() {
NetworkConfig networkConfig = new NetworkConfig();
networkConfig.set(Keys.MID_TRACKER, "NULL");
return networkConfig;
}
use of org.eclipse.californium.core.network.config.NetworkConfig in project leshan by eclipse.
the class SecureIntegrationTestHelper method createX509CertClient.
// TODO implement X509 support for client
public void createX509CertClient(PrivateKey privatekey, Certificate[] trustedCertificates) {
ObjectsInitializer initializer = new ObjectsInitializer();
// TODO security instance with certificate info
initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec("coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(), 12345));
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
List<LwM2mObjectEnabler> objects = initializer.createMandatory();
objects.add(initializer.create(2));
InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
// TODO we should read the config from the security object
config.setIdentity(privatekey, clientX509CertChain, false);
config.setTrustStore(trustedCertificates);
CoapServer coapServer = new CoapServer();
CoapEndpoint.CoapEndpointBuilder coapBuilder = new CoapEndpoint.CoapEndpointBuilder();
coapBuilder.setConnector(new DTLSConnector(config.build()));
coapBuilder.setNetworkConfig(new NetworkConfig());
coapServer.addEndpoint(coapBuilder.build());
LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
builder.setObjects(objects);
client = builder.build();
}
Aggregations