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);
}
Aggregations