use of org.eclipse.californium.scandium.DtlsClusterHealthLogger in project californium by eclipse.
the class ExtendedTestServer method addClusterEndpoint.
private void addClusterEndpoint(ScheduledExecutorService secondaryExecutor, InetSocketAddress dtlsInterface, int nodeId, DtlsClusterConnectorConfig clusterConfiguration, ClusterNodesProvider nodesProvider, ClusterNodesDiscover nodesDiscoverer, BaseConfig cliConfig) {
if (nodesDiscoverer == null ^ nodesProvider != null) {
throw new IllegalArgumentException("either nodes-provider or -dicoverer is required!");
}
InterfaceType interfaceType = dtlsInterface.getAddress().isLoopbackAddress() ? InterfaceType.LOCAL : InterfaceType.EXTERNAL;
Configuration configuration = getConfig(Protocol.DTLS, interfaceType);
String tag = "dtls:node-" + nodeId + ":" + StringUtil.toString(dtlsInterface);
int handshakeResultDelayMillis = configuration.getTimeAsInt(DTLS_HANDSHAKE_RESULT_DELAY, TimeUnit.MILLISECONDS);
long healthStatusIntervalMillis = configuration.get(SystemConfig.HEALTH_STATUS_INTERVAL, TimeUnit.MILLISECONDS);
Integer cidLength = configuration.get(DtlsConfig.DTLS_CONNECTION_ID_LENGTH);
if (cidLength == null || cidLength < 6) {
throw new IllegalArgumentException("cid length must be at least 6 for cluster!");
}
initCredentials();
DtlsConnectorConfig.Builder dtlsConfigBuilder = DtlsConnectorConfig.builder(configuration);
if (cliConfig.clientAuth != null) {
dtlsConfigBuilder.set(DtlsConfig.DTLS_CLIENT_AUTHENTICATION_MODE, cliConfig.clientAuth);
}
// set node-id in dtls-config-builder's Configuration clone
dtlsConfigBuilder.set(DtlsConfig.DTLS_CONNECTION_ID_NODE_ID, nodeId);
AsyncAdvancedPskStore asyncPskStore = new AsyncAdvancedPskStore(new PlugPskStore());
asyncPskStore.setDelay(handshakeResultDelayMillis);
dtlsConfigBuilder.setAdvancedPskStore(asyncPskStore);
dtlsConfigBuilder.setAddress(dtlsInterface);
X509KeyManager keyManager = SslContextUtil.getX509KeyManager(serverCredentials);
AsyncKeyManagerCertificateProvider certificateProvider = new AsyncKeyManagerCertificateProvider(keyManager, CertificateType.RAW_PUBLIC_KEY, CertificateType.X_509);
certificateProvider.setDelay(handshakeResultDelayMillis);
dtlsConfigBuilder.setCertificateIdentityProvider(certificateProvider);
AsyncNewAdvancedCertificateVerifier.Builder verifierBuilder = AsyncNewAdvancedCertificateVerifier.builder();
if (cliConfig.trustall) {
verifierBuilder.setTrustAllCertificates();
} else {
verifierBuilder.setTrustedCertificates(trustedCertificates);
}
verifierBuilder.setTrustAllRPKs();
AsyncNewAdvancedCertificateVerifier verifier = verifierBuilder.build();
verifier.setDelay(handshakeResultDelayMillis);
dtlsConfigBuilder.setAdvancedCertificateVerifier(verifier);
dtlsConfigBuilder.setConnectionListener(new MdcConnectionListener());
dtlsConfigBuilder.setLoggingTag(tag);
if (healthStatusIntervalMillis > 0) {
DtlsClusterHealthLogger health = new DtlsClusterHealthLogger(tag);
dtlsConfigBuilder.setHealthHandler(health);
add(health);
// reset to prevent active logger
dtlsConfigBuilder.set(SystemConfig.HEALTH_STATUS_INTERVAL, 0, TimeUnit.MILLISECONDS);
}
DtlsConnectorConfig dtlsConnectorConfig = dtlsConfigBuilder.build();
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
EndpointObserver endpointObserver = null;
if (nodesDiscoverer != null) {
DtlsManagedClusterConnector connector = new DtlsManagedClusterConnector(dtlsConnectorConfig, clusterConfiguration);
final DtlsClusterManager manager = new DtlsClusterManager(connector, dtlsConnectorConfig.getConfiguration(), nodesDiscoverer, secondaryExecutor);
builder.setConnector(connector);
endpointObserver = new EndpointObserver() {
@Override
public void stopped(Endpoint endpoint) {
manager.stop();
}
@Override
public void started(Endpoint endpoint) {
manager.start();
}
@Override
public void destroyed(Endpoint endpoint) {
manager.stop();
}
};
components.add(manager);
} else if (nodesProvider != null) {
builder.setConnector(new DtlsClusterConnector(dtlsConnectorConfig, clusterConfiguration, nodesProvider));
}
// use dtls-config-builder's Configuration clone with the set node-id
builder.setConfiguration(dtlsConnectorConfig.getConfiguration());
CoapEndpoint endpoint = builder.build();
if (healthStatusIntervalMillis > 0) {
HealthStatisticLogger healthLogger = new HealthStatisticLogger(CoAP.COAP_SECURE_URI_SCHEME + "-" + nodeId, true);
if (healthLogger.isEnabled()) {
endpoint.addPostProcessInterceptor(healthLogger);
add(healthLogger);
}
}
if (endpointObserver != null) {
endpoint.addObserver(endpointObserver);
}
addEndpoint(endpoint);
print(endpoint, interfaceType);
}
use of org.eclipse.californium.scandium.DtlsClusterHealthLogger 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