Search in sources :

Example 1 with NodeConnectionIdGenerator

use of org.eclipse.californium.scandium.dtls.NodeConnectionIdGenerator in project californium by eclipse.

the class NatTestHelper method createSecureServer.

void createSecureServer(ConnectionIdGenerator... cidGenerators) throws IOException {
    MyClusterNodesProvider provider = new MyClusterNodesProvider();
    int count = 1;
    for (ConnectionIdGenerator generator : cidGenerators) {
        String tag = "server" + count;
        DtlsClusterHealthLogger health = new DtlsClusterHealthLogger(tag);
        this.serverStatistics.add(health);
        TestUtilPskStore pskStore = new TestUtilPskStore();
        pskStore.set(IDENITITY, KEY.getBytes());
        pskStore.setCatchAll(true);
        DtlsConnectorConfig dtlsConfig = DtlsConnectorConfig.builder(config).set(DtlsConfig.DTLS_ROLE, DtlsRole.SERVER_ONLY).set(DtlsConfig.DTLS_MAX_CONNECTIONS, 10000).set(DtlsConfig.DTLS_STALE_CONNECTION_THRESHOLD, 20, TimeUnit.SECONDS).set(DtlsConfig.DTLS_RECEIVER_THREAD_COUNT, 2).set(DtlsConfig.DTLS_CONNECTOR_THREAD_COUNT, 4).set(DtlsConfig.DTLS_VERIFY_PEERS_ON_RESUMPTION_THRESHOLD, 100).setAddress(TestTools.LOCALHOST_EPHEMERAL).setLoggingTag(tag).setHealthHandler(health).setConnectionIdGenerator(generator).setAdvancedPskStore(pskStore).build();
        DebugConnectionStore serverConnectionStore = ConnectorHelper.createDebugConnectionStore(dtlsConfig);
        this.serverConnections.add(serverConnectionStore);
        CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
        if (generator instanceof NodeConnectionIdGenerator) {
            DtlsClusterConnectorConfig.Builder clusterConfigBuilder = DtlsClusterConnectorConfig.builder();
            clusterConfigBuilder.setAddress(TestTools.LOCALHOST_EPHEMERAL);
            DtlsManagedClusterConnector serverConnector = new MyDtlsClusterConnector(dtlsConfig, clusterConfigBuilder.build(), serverConnectionStore);
            serverConnector.setClusterNodesProvider(provider);
            provider.add(serverConnector);
            serverConnector.setAlertHandler(new MyAlertHandler(dtlsConfig.getLoggingTag()));
            builder.setConnector(serverConnector);
        } else {
            DTLSConnector serverConnector = new MyDtlsConnector(dtlsConfig, serverConnectionStore);
            serverConnector.setAlertHandler(new MyAlertHandler(dtlsConfig.getLoggingTag()));
            builder.setConnector(serverConnector);
        }
        builder.setConfiguration(config);
        CoapEndpoint serverEndpoint = builder.build();
        HealthStatisticLogger healthLogger = new HealthStatisticLogger(tag, true);
        serverCoapStatistics.add(healthLogger);
        serverEndpoint.addPostProcessInterceptor(healthLogger);
        serverEndpoints.add(serverEndpoint);
        CoapServer server = new CoapServer();
        server.addEndpoint(serverEndpoint);
        resource = new MyResource(TARGET);
        server.add(resource);
        server.start();
        servers.add(server);
        ++count;
    }
    createLoadBalancer();
    System.out.println("coap-server " + uri);
}
Also used : DtlsManagedClusterConnector(org.eclipse.californium.scandium.DtlsManagedClusterConnector) CoapServer(org.eclipse.californium.core.CoapServer) DtlsClusterHealthLogger(org.eclipse.californium.scandium.DtlsClusterHealthLogger) HealthStatisticLogger(org.eclipse.californium.core.network.interceptors.HealthStatisticLogger) Endpoint(org.eclipse.californium.core.network.Endpoint) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) DtlsConnectorConfig(org.eclipse.californium.scandium.config.DtlsConnectorConfig) DTLSConnector(org.eclipse.californium.scandium.DTLSConnector) NodeConnectionIdGenerator(org.eclipse.californium.scandium.dtls.NodeConnectionIdGenerator) SingleNodeConnectionIdGenerator(org.eclipse.californium.scandium.dtls.SingleNodeConnectionIdGenerator) NodeConnectionIdGenerator(org.eclipse.californium.scandium.dtls.NodeConnectionIdGenerator) ConnectionIdGenerator(org.eclipse.californium.scandium.dtls.ConnectionIdGenerator) SingleNodeConnectionIdGenerator(org.eclipse.californium.scandium.dtls.SingleNodeConnectionIdGenerator) DebugConnectionStore(org.eclipse.californium.scandium.dtls.DebugConnectionStore) CoapEndpoint(org.eclipse.californium.core.network.CoapEndpoint) DtlsClusterConnectorConfig(org.eclipse.californium.scandium.config.DtlsClusterConnectorConfig)

Aggregations

CoapServer (org.eclipse.californium.core.CoapServer)1 CoapEndpoint (org.eclipse.californium.core.network.CoapEndpoint)1 Endpoint (org.eclipse.californium.core.network.Endpoint)1 HealthStatisticLogger (org.eclipse.californium.core.network.interceptors.HealthStatisticLogger)1 DTLSConnector (org.eclipse.californium.scandium.DTLSConnector)1 DtlsClusterHealthLogger (org.eclipse.californium.scandium.DtlsClusterHealthLogger)1 DtlsManagedClusterConnector (org.eclipse.californium.scandium.DtlsManagedClusterConnector)1 DtlsClusterConnectorConfig (org.eclipse.californium.scandium.config.DtlsClusterConnectorConfig)1 DtlsConnectorConfig (org.eclipse.californium.scandium.config.DtlsConnectorConfig)1 ConnectionIdGenerator (org.eclipse.californium.scandium.dtls.ConnectionIdGenerator)1 DebugConnectionStore (org.eclipse.californium.scandium.dtls.DebugConnectionStore)1 NodeConnectionIdGenerator (org.eclipse.californium.scandium.dtls.NodeConnectionIdGenerator)1 SingleNodeConnectionIdGenerator (org.eclipse.californium.scandium.dtls.SingleNodeConnectionIdGenerator)1