Search in sources :

Example 6 with NetworkConfig

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));
}
Also used : NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig)

Example 7 with NetworkConfig

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());
}
Also used : LeshanBootstrapServerBuilder(org.eclipse.leshan.server.californium.LeshanBootstrapServerBuilder) ObjectModel(org.eclipse.leshan.core.model.ObjectModel) LeshanBootstrapServer(org.eclipse.leshan.server.californium.impl.LeshanBootstrapServer) LeshanBootstrapServer(org.eclipse.leshan.server.californium.impl.LeshanBootstrapServer) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServerServlet(org.eclipse.leshan.server.bootstrap.demo.servlet.ServerServlet) NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig) LwM2mModel(org.eclipse.leshan.core.model.LwM2mModel) BootstrapServlet(org.eclipse.leshan.server.bootstrap.demo.servlet.BootstrapServlet) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) File(java.io.File)

Example 8 with NetworkConfig

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;
}
Also used : NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig)

Example 9 with 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;
}
Also used : NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig)

Example 10 with 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();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) CoapServer(org.eclipse.californium.core.CoapServer) Server(org.eclipse.leshan.client.object.Server) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) InetSocketAddress(java.net.InetSocketAddress) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder) NetworkConfig(org.eclipse.californium.core.network.config.NetworkConfig) CoapServer(org.eclipse.californium.core.CoapServer) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint)

Aggregations

NetworkConfig (org.eclipse.californium.core.network.config.NetworkConfig)14 CoapEndpoint (org.eclipse.californium.core.network.CoapEndpoint)4 File (java.io.File)3 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 CoapServer (org.eclipse.californium.core.CoapServer)3 DTLSConnector (org.eclipse.californium.scandium.DTLSConnector)3 DtlsConnectorConfig (org.eclipse.californium.scandium.config.DtlsConnectorConfig)3 LeshanClientBuilder (org.eclipse.leshan.client.californium.LeshanClientBuilder)3 Server (org.eclipse.leshan.client.object.Server)3 LwM2mObjectEnabler (org.eclipse.leshan.client.resource.LwM2mObjectEnabler)3 ObjectsInitializer (org.eclipse.leshan.client.resource.ObjectsInitializer)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 PrivateKey (java.security.PrivateKey)2 Certificate (java.security.cert.Certificate)2 Endpoint (org.eclipse.californium.core.network.Endpoint)2 MemoryBasedConnectionLimitStrategy (org.eclipse.hono.adapter.limiting.MemoryBasedConnectionLimitStrategy)2 Server (org.eclipse.jetty.server.Server)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2