You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemds.apache.org by ba...@apache.org on 2020/11/27 13:45:32 UTC
[systemds] branch master updated: [MINOR] Singleton Federated SSL
context
This is an automated email from the ASF dual-hosted git repository.
baunsgaard pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/master by this push:
new c50165d [MINOR] Singleton Federated SSL context
c50165d is described below
commit c50165ddd47f50bc1c71c752f67c2a6fbaaa5aaa
Author: baunsgaard <ba...@tugraz.at>
AuthorDate: Fri Nov 27 14:44:19 2020 +0100
[MINOR] Singleton Federated SSL context
---
.../controlprogram/federated/FederatedData.java | 42 ++++++++++++++--------
1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/src/main/java/org/apache/sysds/runtime/controlprogram/federated/FederatedData.java b/src/main/java/org/apache/sysds/runtime/controlprogram/federated/FederatedData.java
index 67f16e2..1713ff1 100644
--- a/src/main/java/org/apache/sysds/runtime/controlprogram/federated/FederatedData.java
+++ b/src/main/java/org/apache/sysds/runtime/controlprogram/federated/FederatedData.java
@@ -58,16 +58,8 @@ public class FederatedData {
private static final Log LOG = LogFactory.getLog(FederatedData.class.getName());
private static final Set<InetSocketAddress> _allFedSites = new HashSet<>();
- private static SslContext sslCtx;
-
- static {
- try {
- sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
- }
- catch(SSLException e) {
- LOG.error("Static SSL setup failed for client side");
- }
- }
+ /** A Singleton constructed SSL context, that only is assigned if ssl is enabled. */
+ private static SslContextMan instance = null;
private final Types.DataType _dataType;
private final InetSocketAddress _address;
@@ -178,8 +170,8 @@ public class FederatedData {
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline cp = ch.pipeline();
if(ConfigurationManager.getDMLConfig().getBooleanValue(DMLConfig.USE_SSL_FEDERATED_COMMUNICATION)) {
- cp.addLast(
- sslCtx.newHandler(ch.alloc(), address.getAddress().getHostAddress(), address.getPort()));
+ cp.addLast(SslConstructor().context
+ .newHandler(ch.alloc(), address.getAddress().getHostAddress(), address.getPort()));
}
cp.addLast("ObjectDecoder",
@@ -190,10 +182,10 @@ public class FederatedData {
}
});
-
+
ChannelFuture f = b.connect(address).sync();
Promise<FederatedResponse> promise = f.channel().eventLoop().newPromise();
-
+
handler.setPromise(promise);
f.channel().writeAndFlush(request);
return promise;
@@ -254,6 +246,28 @@ public class FederatedData {
}
}
+ private static class SslContextMan {
+ protected final SslContext context;
+
+ private SslContextMan() {
+ try {
+ context = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
+ }
+ catch(SSLException e) {
+ throw new DMLRuntimeException("Static SSL setup failed for client side", e);
+ }
+ }
+ }
+
+ private static SslContextMan SslConstructor() {
+ if(instance == null) {
+ return new SslContextMan();
+ }
+ else {
+ return instance;
+ }
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();