diff --git a/domain-epoll/pom.xml b/domain-epoll/pom.xml index 23587b129..5abb014d0 100644 --- a/domain-epoll/pom.xml +++ b/domain-epoll/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 com.salesforce.apollo @@ -6,15 +7,18 @@ 0.0.1-SNAPSHOT domain-epoll - Domain EPoll + Domain Sockets EPoll Linux Unix Domain Socket Support - + + + com.salesforce.apollo + domain-sockets + io.netty netty-transport-native-epoll ${netty.version} - ${os.detected.classifier} - \ No newline at end of file + diff --git a/domain-epoll/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java b/domain-epoll/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketsLinux.java similarity index 55% rename from domain-epoll/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java rename to domain-epoll/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketsLinux.java index 680b1252c..605abf917 100644 --- a/domain-epoll/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java +++ b/domain-epoll/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketsLinux.java @@ -6,9 +6,6 @@ */ package com.salesforce.apollo.comm.grpc; -import java.io.IOException; -import java.util.concurrent.Executor; - import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopTaskQueueFactory; @@ -21,57 +18,56 @@ import io.netty.util.concurrent.EventExecutorChooserFactory; import io.netty.util.concurrent.RejectedExecutionHandler; +import java.io.IOException; +import java.util.concurrent.Executor; + /** * @author hal.hildebrand - * */ -public class DomainSockets { +public class DomainSocketsLinux implements DomainSockets { - public static Class getChannelType() { + public Class getChannelType() { return EpollDomainSocketChannel.class; } - public static EventLoopGroup getEventLoopGroup() { + public EventLoopGroup getEventLoopGroup() { return new EpollEventLoopGroup(); } - public static EventLoopGroup getEventLoopGroup(int threads) { + public EventLoopGroup getEventLoopGroup(int threads) { return new EpollEventLoopGroup(threads); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor) { + public EventLoopGroup getEventLoopGroup(int threads, Executor executor) { return new EpollEventLoopGroup(threads, executor); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor, - EventExecutorChooserFactory chooserFactory, - SelectStrategyFactory selectStrategyFactory) { + public EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory) { return new EpollEventLoopGroup(threads, executor, chooserFactory, selectStrategyFactory); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor, - EventExecutorChooserFactory chooserFactory, - SelectStrategyFactory selectStrategyFactory, - RejectedExecutionHandler rejectedExecutionHandler) { + public EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory, + RejectedExecutionHandler rejectedExecutionHandler) { return new EpollEventLoopGroup(threads, executor, chooserFactory, selectStrategyFactory, rejectedExecutionHandler); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor, - EventExecutorChooserFactory chooserFactory, - SelectStrategyFactory selectStrategyFactory, - RejectedExecutionHandler rejectedExecutionHandler, - EventLoopTaskQueueFactory queueFactory) { + public EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory, + RejectedExecutionHandler rejectedExecutionHandler, + EventLoopTaskQueueFactory queueFactory) { return new EpollEventLoopGroup(threads, executor, chooserFactory, selectStrategyFactory, rejectedExecutionHandler, queueFactory); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor, - SelectStrategyFactory selectStrategyFactory) { + public EventLoopGroup getEventLoopGroup(int threads, Executor executor, + SelectStrategyFactory selectStrategyFactory) { return new EpollEventLoopGroup(threads, executor, selectStrategyFactory); } - public static PeerCredentials getPeerCredentials(Channel channel) { + public PeerCredentials getPeerCredentials(Channel channel) { if (channel instanceof EpollDomainSocketChannel ep) { try { return ep.peerCredentials(); @@ -83,7 +79,7 @@ public static PeerCredentials getPeerCredentials(Channel channel) { } } - public static Class getServerDomainSocketChannelClass() { + public Class getServerDomainSocketChannelClass() { return EpollServerDomainSocketChannel.class; } } diff --git a/domain-kqueue/pom.xml b/domain-kqueue/pom.xml index 4fa4b5580..a0766a0c2 100644 --- a/domain-kqueue/pom.xml +++ b/domain-kqueue/pom.xml @@ -1,20 +1,24 @@ - + 4.0.0 com.salesforce.apollo apollo.app 0.0.1-SNAPSHOT - Domain KQueue + Domain Sockets KQueue Mac/OSx Unix Domain Socket Support domain-kqueue + + com.salesforce.apollo + domain-sockets + io.netty netty-transport-native-kqueue ${netty.version} - ${os.detected.classifier} - \ No newline at end of file + diff --git a/domain-kqueue/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java b/domain-kqueue/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketsOSX.java similarity index 56% rename from domain-kqueue/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java rename to domain-kqueue/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketsOSX.java index a56be6842..a5ce92bae 100644 --- a/domain-kqueue/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java +++ b/domain-kqueue/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketsOSX.java @@ -6,9 +6,6 @@ */ package com.salesforce.apollo.comm.grpc; -import java.io.IOException; -import java.util.concurrent.Executor; - import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopTaskQueueFactory; @@ -21,65 +18,73 @@ import io.netty.util.concurrent.EventExecutorChooserFactory; import io.netty.util.concurrent.RejectedExecutionHandler; +import java.io.IOException; +import java.util.concurrent.Executor; + /** * @author hal.hildebrand - * */ -public class DomainSockets { +public class DomainSocketsOSX implements DomainSockets { static { try { final var sock = new KQueueServerDomainSocketChannel(); sock.close(); } catch (Throwable t) { -// t.printStackTrace(); + // t.printStackTrace(); } } - public static Class getChannelType() { + @Override + public Class getChannelType() { return KQueueDomainSocketChannel.class; } - public static EventLoopGroup getEventLoopGroup() { + @Override + public EventLoopGroup getEventLoopGroup() { return new KQueueEventLoopGroup(); } - public static EventLoopGroup getEventLoopGroup(int threads) { + @Override + public EventLoopGroup getEventLoopGroup(int threads) { return new KQueueEventLoopGroup(threads); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor) { + @Override + public EventLoopGroup getEventLoopGroup(int threads, Executor executor) { return new KQueueEventLoopGroup(threads, executor); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor, - EventExecutorChooserFactory chooserFactory, - SelectStrategyFactory selectStrategyFactory) { + @Override + public EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory) { return new KQueueEventLoopGroup(threads, executor, chooserFactory, selectStrategyFactory); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor, - EventExecutorChooserFactory chooserFactory, - SelectStrategyFactory selectStrategyFactory, - RejectedExecutionHandler rejectedExecutionHandler) { + @Override + public EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory, + RejectedExecutionHandler rejectedExecutionHandler) { return new KQueueEventLoopGroup(threads, executor, chooserFactory, selectStrategyFactory, rejectedExecutionHandler); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor, - EventExecutorChooserFactory chooserFactory, - SelectStrategyFactory selectStrategyFactory, - RejectedExecutionHandler rejectedExecutionHandler, - EventLoopTaskQueueFactory queueFactory) { + @Override + public EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory, + RejectedExecutionHandler rejectedExecutionHandler, + EventLoopTaskQueueFactory queueFactory) { return new KQueueEventLoopGroup(threads, executor, chooserFactory, selectStrategyFactory, rejectedExecutionHandler, queueFactory); } - public static EventLoopGroup getEventLoopGroup(int threads, Executor executor, - SelectStrategyFactory selectStrategyFactory) { + @Override + public EventLoopGroup getEventLoopGroup(int threads, Executor executor, + SelectStrategyFactory selectStrategyFactory) { return new KQueueEventLoopGroup(threads, executor, selectStrategyFactory); } - public static PeerCredentials getPeerCredentials(Channel channel) { + @Override + public PeerCredentials getPeerCredentials(Channel channel) { if (channel instanceof KQueueDomainSocketChannel ep) { try { return ep.peerCredentials(); @@ -91,7 +96,8 @@ public static PeerCredentials getPeerCredentials(Channel channel) { } } - public static Class getServerDomainSocketChannelClass() { + @Override + public Class getServerDomainSocketChannelClass() { return KQueueServerDomainSocketChannel.class; } } diff --git a/domain-sockets/pom.xml b/domain-sockets/pom.xml new file mode 100644 index 000000000..4b9005037 --- /dev/null +++ b/domain-sockets/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + com.salesforce.apollo + apollo.app + 0.0.1-SNAPSHOT + + domain-sockets + Domain Sockets + Domain Socket Access Interface + + + + io.grpc + grpc-netty + + + diff --git a/domain-sockets/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java b/domain-sockets/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java new file mode 100644 index 000000000..1b4d4da4f --- /dev/null +++ b/domain-sockets/src/main/java/com/salesforce/apollo/comm/grpc/DomainSockets.java @@ -0,0 +1,40 @@ +package com.salesforce.apollo.comm.grpc; + +import io.netty.channel.Channel; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.EventLoopTaskQueueFactory; +import io.netty.channel.SelectStrategyFactory; +import io.netty.channel.unix.PeerCredentials; +import io.netty.channel.unix.ServerDomainSocketChannel; +import io.netty.util.concurrent.EventExecutorChooserFactory; +import io.netty.util.concurrent.RejectedExecutionHandler; + +import java.util.concurrent.Executor; + +public interface DomainSockets { + Class getChannelType(); + + EventLoopGroup getEventLoopGroup(); + + EventLoopGroup getEventLoopGroup(int threads); + + EventLoopGroup getEventLoopGroup(int threads, Executor executor); + + EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory); + + EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory, + RejectedExecutionHandler rejectedExecutionHandler); + + EventLoopGroup getEventLoopGroup(int threads, Executor executor, EventExecutorChooserFactory chooserFactory, + SelectStrategyFactory selectStrategyFactory, + RejectedExecutionHandler rejectedExecutionHandler, + EventLoopTaskQueueFactory queueFactory); + + EventLoopGroup getEventLoopGroup(int threads, Executor executor, SelectStrategyFactory selectStrategyFactory); + + PeerCredentials getPeerCredentials(Channel channel); + + Class getServerDomainSocketChannelClass(); +} diff --git a/isolate-ftesting/pom.xml b/isolate-ftesting/pom.xml index efca341d9..32a1ea5fe 100644 --- a/isolate-ftesting/pom.xml +++ b/isolate-ftesting/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 com.salesforce.apollo @@ -28,10 +29,61 @@ maven-surefire-plugin - + 1 - \ No newline at end of file + + + + mac-domain + + + mac + + + + + io.netty + netty-transport-native-unix-common + ${netty.version} + ${os.detected.classifier} + test + + + io.netty + netty-transport-native-kqueue + ${netty.version} + ${os.detected.classifier} + optional + + + + + linux-domain + + + linux + + + + + io.netty + netty-transport-native-unix-common + ${netty.version} + ${os.detected.classifier} + test + + + io.netty + netty-transport-native-epoll + ${netty.version} + ${os.detected.classifier} + optional + + + + + diff --git a/isolate-ftesting/src/test/java/com/salesforce/apollo/domain/DemesneIsolateTest.java b/isolate-ftesting/src/test/java/com/salesforce/apollo/domain/DemesneIsolateTest.java index 9a71f65dd..0975b1f09 100644 --- a/isolate-ftesting/src/test/java/com/salesforce/apollo/domain/DemesneIsolateTest.java +++ b/isolate-ftesting/src/test/java/com/salesforce/apollo/domain/DemesneIsolateTest.java @@ -6,15 +6,15 @@ */ package com.salesforce.apollo.domain; +import com.salesfoce.apollo.cryptography.proto.Digeste; import com.salesfoce.apollo.demesne.proto.DemesneParameters; import com.salesfoce.apollo.demesne.proto.SubContext; -import com.salesfoce.apollo.cryptography.proto.Digeste; import com.salesforce.apollo.archipelago.Router; import com.salesforce.apollo.archipelago.RouterImpl; import com.salesforce.apollo.archipelago.ServerConnectionCache; import com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor; -import com.salesforce.apollo.crypto.Digest; -import com.salesforce.apollo.crypto.DigestAlgorithm; +import com.salesforce.apollo.cryptography.Digest; +import com.salesforce.apollo.cryptography.DigestAlgorithm; import com.salesforce.apollo.membership.Member; import com.salesforce.apollo.membership.stereotomy.ControlledIdentifierMember; import com.salesforce.apollo.model.demesnes.JniBridge; @@ -49,8 +49,7 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; -import static com.salesforce.apollo.comm.grpc.DomainSockets.getEventLoopGroup; -import static com.salesforce.apollo.comm.grpc.DomainSockets.getServerDomainSocketChannelClass; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -58,10 +57,10 @@ * @author hal.hildebrand */ public class DemesneIsolateTest { - private static final Class channelType = getServerDomainSocketChannelClass(); - private static final Class serverChannelType = getServerDomainSocketChannelClass(); + private static final Class channelType = IMPL.getServerDomainSocketChannelClass(); + private static final Class serverChannelType = IMPL.getServerDomainSocketChannelClass(); - private EventLoopGroup eventLoopGroup = getEventLoopGroup(); + private EventLoopGroup eventLoopGroup = IMPL.getEventLoopGroup(); @Test public void smokin() throws Exception { @@ -76,7 +75,7 @@ public void smokin() throws Exception { var parentAddress = UUID.randomUUID().toString(); final var portalEndpoint = new DomainSocketAddress(commDirectory.resolve(portalAddress).toFile()); var serverBuilder = NettyServerBuilder.forAddress(portalEndpoint) - .protocolNegotiator(new DomainSocketNegotiator()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) .channelType(serverChannelType) .workerEventLoopGroup(eventLoopGroup) .bossEventLoopGroup(eventLoopGroup) @@ -106,12 +105,12 @@ public void register(SubContext context) { var kerlServer = new DemesneKERLServer(new ProtoKERLAdapter(kerl), null); var outerService = new OuterContextServer(service, null); var outerContextService = NettyServerBuilder.forAddress(parentEndpoint) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) .addService(kerlServer) .addService(outerService) - .workerEventLoopGroup(getEventLoopGroup()) - .bossEventLoopGroup(getEventLoopGroup()) + .workerEventLoopGroup(IMPL.getEventLoopGroup()) + .bossEventLoopGroup(IMPL.getEventLoopGroup()) .intercept(new DomainSocketServerInterceptor()) .build(); outerContextService.start(); diff --git a/isolates/pom.xml b/isolates/pom.xml index 3f07370c6..8819bfcb7 100644 --- a/isolates/pom.xml +++ b/isolates/pom.xml @@ -1,6 +1,6 @@ - + 4.0.0 com.salesforce.apollo @@ -79,7 +79,7 @@ [3.8.1,) - + [20,) @@ -122,76 +122,106 @@ ${imageName} - ${project.build.outputDirectory}/natives/osx_arm64 + ${project.build.outputDirectory}/natives/osx_arm64 + true -Djava.awt.headless=true - -Djava.util.logging.manager=io.yupiik.logging.jul.YupiikLogManager + -Djava.util.logging.manager=io.yupiik.logging.jul.YupiikLogManager + --enable-preview --enable-http --no-fallback --add-modules java.sql.rowset --initialize-at-build-time=org.jooq - --initialize-at-build-time=javax.sql.rowset.RowSetProvider + --initialize-at-build-time=javax.sql.rowset.RowSetProvider + - --initialize-at-build-time=org.slf4j.LoggerFactory + --initialize-at-build-time=org.slf4j.LoggerFactory + - --initialize-at-build-time=org.bouncycastle + --initialize-at-build-time=org.bouncycastle + - --initialize-at-build-time=org.slf4j.jul.JDK14LoggerAdapter + --initialize-at-build-time=org.slf4j.jul.JDK14LoggerAdapter + - --initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder + --initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder + - --initialize-at-run-time=io.netty.handler.ssl.BouncyCastleAlpnSslUtils + --initialize-at-run-time=io.netty.handler.ssl.BouncyCastleAlpnSslUtils + - --initialize-at-run-time=org.jooq.impl.Convert$_JSON + --initialize-at-run-time=org.jooq.impl.Convert$_JSON + - --initialize-at-run-time=org.jooq.tools.Convert + --initialize-at-run-time=org.jooq.tools.Convert + - --initialize-at-run-time=org.jooq.impl.Convert$_XML + --initialize-at-run-time=org.jooq.impl.Convert$_XML + - --initialize-at-run-time=org.jooq.impl.DefaultRenderContext + --initialize-at-run-time=org.jooq.impl.DefaultRenderContext + - --initialize-at-run-time=io.netty.util.AbstractReferenceCounted + --initialize-at-run-time=io.netty.util.AbstractReferenceCounted + - --initialize-at-run-time=io.netty.channel.epoll + --initialize-at-run-time=io.netty.channel.epoll + - --initialize-at-run-time=io.netty.channel.kqueue + --initialize-at-run-time=io.netty.channel.kqueue + - --initialize-at-run-time=io.netty.channel.unix.Errors + --initialize-at-run-time=io.netty.channel.unix.Errors + - --initialize-at-run-time=io.netty.channel.unix.IovArray + --initialize-at-run-time=io.netty.channel.unix.IovArray + - --initialize-at-run-time=io.netty.channel.unix.Limits + --initialize-at-run-time=io.netty.channel.unix.Limits + - --initialize-at-run-time=io.netty.channel.unix.Socket + --initialize-at-run-time=io.netty.channel.unix.Socket + - --initialize-at-run-time=com.salesforce.apollo.domain.Demesne + --initialize-at-run-time=com.salesforce.apollo.domain.Demesne + - --initialize-at-run-time=org.h2.store.fs.FilePath + --initialize-at-run-time=org.h2.store.fs.FilePath + - --trace-object-instantiation=com.fasterxml.jackson.databind.ObjectMapper + --trace-object-instantiation=com.fasterxml.jackson.databind.ObjectMapper + - --trace-object-instantiation=org.slf4j.jul.JDK14LoggerAdapter + --trace-object-instantiation=org.slf4j.jul.JDK14LoggerAdapter + - --trace-class-initialization=jakarta.xml.bind.ContextFinder + --trace-class-initialization=jakarta.xml.bind.ContextFinder + - --trace-class-initialization=org.slf4j.MDC + --trace-class-initialization=org.slf4j.MDC + - --trace-class-initialization=io.netty.channel.DefaultFileRegion + --trace-class-initialization=io.netty.channel.DefaultFileRegion + - --trace-class-initialization=io.netty.channel.kqueue.KQueue + --trace-class-initialization=io.netty.channel.kqueue.KQueue + - --trace-class-initialization=io.netty.util.AbstractReferenceCounted + --trace-class-initialization=io.netty.util.AbstractReferenceCounted + - --trace-class-initialization=io.netty.channel.epoll.Native + --trace-class-initialization=io.netty.channel.epoll.Native + - -H:+AllowDeprecatedBuilderClassesOnImageClasspath + -H:+AllowDeprecatedBuilderClassesOnImageClasspath + -H:+BuildReport -H:+UnlockExperimentalVMOptions - + --enable-sbom -march=native @@ -201,7 +231,8 @@ - ${project.build.directory}/${project.artifactId}-${project.version}-graalvm-jar-with-dependencies.jar + ${project.build.directory}/${project.artifactId}-${project.version}-graalvm-jar-with-dependencies.jar + @@ -218,7 +249,7 @@ - isolates + isolates org.graalvm.sdk @@ -227,5 +258,49 @@ + + mac-domain + + + mac + + + + + io.netty + netty-transport-native-unix-common + ${netty.version} + ${os.detected.classifier} + + + io.netty + netty-transport-native-kqueue + ${netty.version} + ${os.detected.classifier} + + + + + linux-domain + + + linux + + + + + io.netty + netty-transport-native-unix-common + ${netty.version} + ${os.detected.classifier} + + + io.netty + netty-transport-native-epoll + ${netty.version} + ${os.detected.classifier} + + + - \ No newline at end of file + diff --git a/isolates/src/main/java/com/salesforce/apollo/demesnes/isolate/DemesneIsolate.java b/isolates/src/main/java/com/salesforce/apollo/demesnes/isolate/DemesneIsolate.java index 91045a0be..374234d87 100644 --- a/isolates/src/main/java/com/salesforce/apollo/demesnes/isolate/DemesneIsolate.java +++ b/isolates/src/main/java/com/salesforce/apollo/demesnes/isolate/DemesneIsolate.java @@ -6,7 +6,24 @@ */ package com.salesforce.apollo.demesnes.isolate; -import static com.salesforce.apollo.comm.grpc.DomainSockets.getEventLoopGroup; +import com.google.protobuf.InvalidProtocolBufferException; +import com.salesfoce.apollo.cryptography.proto.Digeste; +import com.salesfoce.apollo.demesne.proto.DemesneParameters; +import com.salesfoce.apollo.demesne.proto.ViewChange; +import com.salesfoce.apollo.stereotomy.event.proto.*; +import com.salesforce.apollo.cryptography.Digest; +import com.salesforce.apollo.model.demesnes.Demesne; +import com.salesforce.apollo.model.demesnes.DemesneImpl; +import com.salesforce.apollo.stereotomy.EventCoordinates; +import com.salesforce.apollo.stereotomy.identifier.SelfAddressingIdentifier; +import com.salesforce.apollo.stereotomy.identifier.spec.IdentifierSpecification; +import com.salesforce.apollo.stereotomy.identifier.spec.RotationSpecification; +import org.graalvm.nativeimage.IsolateThread; +import org.graalvm.nativeimage.c.function.CEntryPoint; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CTypeConversion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; @@ -19,41 +36,16 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.logging.LogManager; -import org.graalvm.nativeimage.IsolateThread; -import org.graalvm.nativeimage.c.function.CEntryPoint; -import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.c.type.CTypeConversion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.protobuf.InvalidProtocolBufferException; -import com.salesfoce.apollo.demesne.proto.DemesneParameters; -import com.salesfoce.apollo.demesne.proto.ViewChange; -import com.salesfoce.apollo.stereotomy.event.proto.EventCoords; -import com.salesfoce.apollo.stereotomy.event.proto.Ident; -import com.salesfoce.apollo.stereotomy.event.proto.IdentifierSpec; -import com.salesfoce.apollo.stereotomy.event.proto.InceptionEvent; -import com.salesfoce.apollo.stereotomy.event.proto.RotationEvent; -import com.salesfoce.apollo.stereotomy.event.proto.RotationSpec; -import com.salesfoce.apollo.cryptography.proto.Digeste; -import com.salesforce.apollo.cryptography.Digest; -import com.salesforce.apollo.model.demesnes.Demesne; -import com.salesforce.apollo.model.demesnes.DemesneImpl; -import com.salesforce.apollo.stereotomy.EventCoordinates; -import com.salesforce.apollo.stereotomy.identifier.SelfAddressingIdentifier; -import com.salesforce.apollo.stereotomy.identifier.spec.IdentifierSpecification; -import com.salesforce.apollo.stereotomy.identifier.spec.RotationSpecification; - /** * GraalVM Isolate for the Apollo SubDomain stack * * @author hal.hildebrand - * */ public class DemesneIsolate { - private static final AtomicReference demesne = new AtomicReference<>(); - private static final Lock lock = new ReentrantLock(); - private static final Logger log = LoggerFactory.getLogger(DemesneIsolate.class); + private static final AtomicReference demesne = new AtomicReference<>(); + private static final Lock lock = new ReentrantLock(); + private static final Logger log = LoggerFactory.getLogger(DemesneIsolate.class); + static { System.setProperty(".level", "FINEST"); } @@ -62,8 +54,8 @@ public class DemesneIsolate { public static native IsolateThread createIsolate(); @CEntryPoint(name = "Java_com_salesforce_apollo_model_demesnes_JniBridge_active") - private static boolean active(JNIEnvironment jniEnv, JClass clazz, - @CEntryPoint.IsolateThreadContext long isolateId) throws GeneralSecurityException { + private static boolean active(JNIEnvironment jniEnv, JClass clazz, @CEntryPoint.IsolateThreadContext long isolateId) + throws GeneralSecurityException { final Demesne d = demesne.get(); return d == null ? false : d.active(); } @@ -73,10 +65,8 @@ private static void commit(JNIEnvironment jniEnv, JClass clazz, @CEntryPoint.Iso JByteArray eventCoordinates, int eventCoordinatesLen) { final Demesne d = demesne.get(); if (d != null) { - var coordBuff = CTypeConversion.asByteBuffer(jniEnv.getFunctions() - .getGetByteArrayElements() - .call(jniEnv, eventCoordinates, false), - eventCoordinatesLen); + var coordBuff = CTypeConversion.asByteBuffer( + jniEnv.getFunctions().getGetByteArrayElements().call(jniEnv, eventCoordinates, false), eventCoordinatesLen); EventCoords coords; try { coords = EventCoords.parseFrom(coordBuff); @@ -136,14 +126,10 @@ private static JByteArray inception(JNIEnvironment jniEnv, JClass clazz, int identLen, JByteArray spec, int specLen) { final Demesne d = demesne.get(); if (d != null) { - var identBuff = CTypeConversion.asByteBuffer(jniEnv.getFunctions() - .getGetByteArrayElements() - .call(jniEnv, ident, false), - identLen); - var specBuff = CTypeConversion.asByteBuffer(jniEnv.getFunctions() - .getGetByteArrayElements() - .call(jniEnv, spec, false), - specLen); + var identBuff = CTypeConversion.asByteBuffer( + jniEnv.getFunctions().getGetByteArrayElements().call(jniEnv, ident, false), identLen); + var specBuff = CTypeConversion.asByteBuffer( + jniEnv.getFunctions().getGetByteArrayElements().call(jniEnv, spec, false), specLen); Ident identifier; try { identifier = Ident.parseFrom(identBuff); @@ -170,15 +156,15 @@ private static JByteArray inception(JNIEnvironment jniEnv, JClass clazz, return jniEnv.getFunctions().getNewByteArray().call(jniEnv, 0); } - private static void launch(JNIEnvironment jniEnv, ByteBuffer data, JClass clazz) throws GeneralSecurityException, - IOException { + private static void launch(JNIEnvironment jniEnv, ByteBuffer data, JClass clazz) + throws GeneralSecurityException, IOException { final var parameters = DemesneParameters.parseFrom(data); configureLogging(parameters); launch(jniEnv, parameters, clazz); } - private static void launch(JNIEnvironment jniEnv, DemesneParameters parameters, - JClass clazz) throws GeneralSecurityException, IOException { + private static void launch(JNIEnvironment jniEnv, DemesneParameters parameters, JClass clazz) + throws GeneralSecurityException, IOException { try { lock.lock(); if (demesne.get() != null) { @@ -193,10 +179,8 @@ private static void launch(JNIEnvironment jniEnv, DemesneParameters parameters, @CEntryPoint(name = "Java_com_salesforce_apollo_model_demesnes_JniBridge_launch") private static boolean launch(JNIEnvironment jniEnv, JClass clazz, @CEntryPoint.IsolateThreadContext long isolateId, JByteArray parameters, int parametersLen) { - var parametersBuff = CTypeConversion.asByteBuffer(jniEnv.getFunctions() - .getGetByteArrayElements() - .call(jniEnv, parameters, false), - parametersLen); + var parametersBuff = CTypeConversion.asByteBuffer( + jniEnv.getFunctions().getGetByteArrayElements().call(jniEnv, parameters, false), parametersLen); log.trace("Launch Demesne Isolate: {}", isolateId); try { launch(jniEnv, parametersBuff, clazz); @@ -212,10 +196,8 @@ private static CCharPointer rotate(JNIEnvironment jniEnv, JClass clazz, @CEntryPoint.IsolateThreadContext long isolateId, JByteArray spec, int specLen) { final Demesne d = demesne.get(); if (d != null) { - var specBuff = CTypeConversion.asByteBuffer(jniEnv.getFunctions() - .getGetByteArrayElements() - .call(jniEnv, spec, false), - specLen); + var specBuff = CTypeConversion.asByteBuffer( + jniEnv.getFunctions().getGetByteArrayElements().call(jniEnv, spec, false), specLen); RotationSpecification.Builder specification; try { specification = RotationSpecification.Builder.from(RotationSpec.parseFrom(specBuff)); @@ -228,8 +210,8 @@ private static CCharPointer rotate(JNIEnvironment jniEnv, JClass clazz, } @CEntryPoint(name = "Java_com_salesforce_apollo_model_demesnes_JniBridge_start") - private static void start(JNIEnvironment jniEnv, JClass clazz, - @CEntryPoint.IsolateThreadContext long isolateId) throws GeneralSecurityException { + private static void start(JNIEnvironment jniEnv, JClass clazz, @CEntryPoint.IsolateThreadContext long isolateId) + throws GeneralSecurityException { final Demesne d = demesne.get(); if (d != null) { d.start(); @@ -237,8 +219,8 @@ private static void start(JNIEnvironment jniEnv, JClass clazz, } @CEntryPoint(name = "Java_com_salesforce_apollo_model_demesnes_JniBridge_stop") - private static void stop(JNIEnvironment jniEnv, JClass clazz, - @CEntryPoint.IsolateThreadContext long isolateId) throws GeneralSecurityException { + private static void stop(JNIEnvironment jniEnv, JClass clazz, @CEntryPoint.IsolateThreadContext long isolateId) + throws GeneralSecurityException { final Demesne d = demesne.get(); if (d != null) { d.stop(); diff --git a/isolates/src/test/java/com/salesforce/apollo/demesnes/DemesneSmoke.java b/isolates/src/test/java/com/salesforce/apollo/demesnes/DemesneSmoke.java index 5a78ca659..23960d702 100644 --- a/isolates/src/test/java/com/salesforce/apollo/demesnes/DemesneSmoke.java +++ b/isolates/src/test/java/com/salesforce/apollo/demesnes/DemesneSmoke.java @@ -8,13 +8,13 @@ import com.google.protobuf.Any; import com.google.protobuf.ByteString; +import com.salesfoce.apollo.cryptography.proto.Digeste; import com.salesfoce.apollo.demesne.proto.DemesneParameters; import com.salesfoce.apollo.demesne.proto.SubContext; import com.salesfoce.apollo.test.proto.ByteMessage; import com.salesfoce.apollo.test.proto.TestItGrpc; import com.salesfoce.apollo.test.proto.TestItGrpc.TestItBlockingStub; import com.salesfoce.apollo.test.proto.TestItGrpc.TestItImplBase; -import com.salesfoce.apollo.cryptography.proto.Digeste; import com.salesforce.apollo.archipelago.*; import com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor; import com.salesforce.apollo.cryptography.Digest; @@ -59,7 +59,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import static com.salesforce.apollo.comm.grpc.DomainSockets.*; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; import static com.salesforce.apollo.cryptography.QualifiedBase64.qb64; /** @@ -67,8 +67,8 @@ */ public class DemesneSmoke { - private final static Class clientChannelType = getChannelType(); - private static final Class serverChannelType = getServerDomainSocketChannelClass(); + private final static Class clientChannelType = IMPL.getChannelType(); + private static final Class serverChannelType = IMPL.getServerDomainSocketChannelClass(); private final static Executor executor = Executors.newVirtualThreadPerTaskExecutor(); private EventLoopGroup eventLoopGroup; @@ -108,7 +108,7 @@ public void after() throws Exception { } public void before() { - eventLoopGroup = getEventLoopGroup(); + eventLoopGroup = IMPL.getEventLoopGroup(); } public void smokin() throws Exception { @@ -123,7 +123,7 @@ public void smokin() throws Exception { final var portalEndpoint = new DomainSocketAddress(commDirectory.resolve(portalAddress).toFile()); final var router = new RouterImpl(serverMember, NettyServerBuilder.forAddress(portalEndpoint) .protocolNegotiator( - new DomainSocketNegotiator()) + new DomainSocketNegotiator(IMPL)) .channelType(serverChannelType) .workerEventLoopGroup(eventLoopGroup) .bossEventLoopGroup(eventLoopGroup) @@ -153,12 +153,12 @@ public void register(SubContext context) { final var kerlServer = new DemesneKERLServer(new ProtoKERLAdapter(kerl), null); final var outerService = new OuterContextServer(service, null); final var outerContextService = NettyServerBuilder.forAddress(parentEndpoint) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) .addService(kerlServer) .addService(outerService) - .workerEventLoopGroup(getEventLoopGroup()) - .bossEventLoopGroup(getEventLoopGroup()) + .workerEventLoopGroup(IMPL.getEventLoopGroup()) + .bossEventLoopGroup(IMPL.getEventLoopGroup()) .intercept(new DomainSocketServerInterceptor()) .build(); outerContextService.start(); diff --git a/memberships/pom.xml b/memberships/pom.xml index c417f866b..154f335a6 100644 --- a/memberships/pom.xml +++ b/memberships/pom.xml @@ -39,6 +39,17 @@ org.scijava native-lib-loader + + com.salesforce.apollo + domain-epoll + provided + + + com.salesforce.apollo + domain-kqueue + provided + + org.junit.jupiter diff --git a/memberships/src/main/java/com/salesforce/apollo/archipelago/Enclave.java b/memberships/src/main/java/com/salesforce/apollo/archipelago/Enclave.java index 071304fe4..b71c9fc07 100644 --- a/memberships/src/main/java/com/salesforce/apollo/archipelago/Enclave.java +++ b/memberships/src/main/java/com/salesforce/apollo/archipelago/Enclave.java @@ -29,7 +29,7 @@ import java.util.function.Consumer; import java.util.function.Supplier; -import static com.salesforce.apollo.comm.grpc.DomainSockets.*; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; import static com.salesforce.apollo.cryptography.QualifiedBase64.digest; import static com.salesforce.apollo.cryptography.QualifiedBase64.qb64; @@ -40,13 +40,13 @@ */ public class Enclave implements RouterSupplier { private final static Executor executor = Executors.newVirtualThreadPerTaskExecutor(); - private final static Class channelType = getChannelType(); + private final static Class channelType = IMPL.getChannelType(); private static final Logger log = LoggerFactory.getLogger(Enclave.class); private final DomainSocketAddress bridge; private final Consumer contextRegistration; private final DomainSocketAddress endpoint; - private final EventLoopGroup eventLoopGroup = getEventLoopGroup(); + private final EventLoopGroup eventLoopGroup = IMPL.getEventLoopGroup(); private final Member from; private final String fromString; @@ -79,10 +79,10 @@ public RouterImpl router(ServerConnectionCache.Builder cacheBuilder, Supplier
  • serverBuilder = NettyServerBuilder.forAddress(endpoint) .executor(executor) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) - .workerEventLoopGroup(getEventLoopGroup()) - .bossEventLoopGroup(getEventLoopGroup()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) + .workerEventLoopGroup(IMPL.getEventLoopGroup()) + .bossEventLoopGroup(IMPL.getEventLoopGroup()) .intercept(new DomainSocketServerInterceptor()) .intercept(ConcurrencyLimitServerInterceptor.newBuilder( limitsBuilder.build()) diff --git a/memberships/src/main/java/com/salesforce/apollo/archipelago/Portal.java b/memberships/src/main/java/com/salesforce/apollo/archipelago/Portal.java index 95ddbfa2b..64a5f51af 100644 --- a/memberships/src/main/java/com/salesforce/apollo/archipelago/Portal.java +++ b/memberships/src/main/java/com/salesforce/apollo/archipelago/Portal.java @@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Function; -import static com.salesforce.apollo.comm.grpc.DomainSockets.*; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; /** * Local "service mesh" for in process Isolate Enclaves. The Portal provides the externally visible GRPC endpoint that @@ -36,10 +36,10 @@ */ public class Portal { private static final Executor executor = Executors.newVirtualThreadPerTaskExecutor(); - private final static Class channelType = getChannelType(); + private final static Class channelType = IMPL.getChannelType(); private final String agent; - private final EventLoopGroup eventLoopGroup = getEventLoopGroup(); + private final EventLoopGroup eventLoopGroup = IMPL.getEventLoopGroup(); private final Demultiplexer inbound; private final Duration keepAlive; private final Demultiplexer outbound; @@ -49,10 +49,10 @@ public Portal(Digest agent, ServerBuilder inbound, Function handler(router.apply(d))); this.outbound = new Demultiplexer(NettyServerBuilder.forAddress(bridge) .executor(executor) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) - .workerEventLoopGroup(getEventLoopGroup()) - .bossEventLoopGroup(getEventLoopGroup()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) + .workerEventLoopGroup(IMPL.getEventLoopGroup()) + .bossEventLoopGroup(IMPL.getEventLoopGroup()) .intercept(new DomainSocketServerInterceptor()), Router.METADATA_TARGET_KEY, outbound); this.keepAlive = keepAlive; diff --git a/memberships/src/test/java/com/salesforce/apollo/archipeligo/DemultiplexerTest.java b/memberships/src/test/java/com/salesforce/apollo/archipeligo/DemultiplexerTest.java index 613da0741..155f23b96 100644 --- a/memberships/src/test/java/com/salesforce/apollo/archipeligo/DemultiplexerTest.java +++ b/memberships/src/test/java/com/salesforce/apollo/archipeligo/DemultiplexerTest.java @@ -46,8 +46,8 @@ import java.util.function.Function; import static com.salesforce.apollo.archipelago.RouterImpl.clientInterceptor; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.PEER_CREDENTIALS_CONTEXT_KEY; -import static com.salesforce.apollo.comm.grpc.DomainSockets.*; import static com.salesforce.apollo.cryptography.QualifiedBase64.qb64; import static org.junit.jupiter.api.Assertions.*; @@ -56,9 +56,9 @@ */ public class DemultiplexerTest { - private static final Class channelType = getChannelType(); + private static final Class channelType = IMPL.getChannelType(); private static final Executor executor = Executors.newVirtualThreadPerTaskExecutor(); - private final EventLoopGroup eventLoopGroup = getEventLoopGroup(); + private final EventLoopGroup eventLoopGroup = IMPL.getEventLoopGroup(); private final List opened = new ArrayList<>(); private Server serverA; private Server serverB; @@ -130,10 +130,10 @@ private DomainSocketAddress serverA() throws IOException { final var address = new DomainSocketAddress(socketPathA.toFile()); serverA = NettyServerBuilder.forAddress(address) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) - .workerEventLoopGroup(getEventLoopGroup()) - .bossEventLoopGroup(getEventLoopGroup()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) + .workerEventLoopGroup(IMPL.getEventLoopGroup()) + .bossEventLoopGroup(IMPL.getEventLoopGroup()) .addService(new ServerA()) .intercept(new DomainSocketServerInterceptor()) .build(); @@ -148,10 +148,10 @@ private DomainSocketAddress serverB() throws IOException { final var address = new DomainSocketAddress(socketPathA.toFile()); serverB = NettyServerBuilder.forAddress(address) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) - .workerEventLoopGroup(getEventLoopGroup()) - .bossEventLoopGroup(getEventLoopGroup()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) + .workerEventLoopGroup(IMPL.getEventLoopGroup()) + .bossEventLoopGroup(IMPL.getEventLoopGroup()) .addService(new ServerB()) .intercept(new DomainSocketServerInterceptor()) .build(); diff --git a/memberships/src/test/java/com/salesforce/apollo/archipeligo/EnclaveTest.java b/memberships/src/test/java/com/salesforce/apollo/archipeligo/EnclaveTest.java index cfca0d65b..c2b935cf5 100644 --- a/memberships/src/test/java/com/salesforce/apollo/archipeligo/EnclaveTest.java +++ b/memberships/src/test/java/com/salesforce/apollo/archipeligo/EnclaveTest.java @@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Function; -import static com.salesforce.apollo.comm.grpc.DomainSockets.*; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; import static com.salesforce.apollo.cryptography.QualifiedBase64.qb64; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -50,7 +50,7 @@ * @author hal.hildebrand */ public class EnclaveTest { - private final static Class channelType = getChannelType(); + private final static Class channelType = IMPL.getChannelType(); private static final Executor executor = Executors.newVirtualThreadPerTaskExecutor(); private final TestItService local = new TestItService() { @@ -81,7 +81,7 @@ public void after() throws Exception { @BeforeEach public void before() { - eventLoopGroup = getEventLoopGroup(); + eventLoopGroup = IMPL.getEventLoopGroup(); } @Test @@ -99,10 +99,10 @@ public void smokin() throws Exception { Path.of("target").resolve(UUID.randomUUID().toString()).toFile()); final var agent = DigestAlgorithm.DEFAULT.getLast(); final var portal = new Portal<>(agent, NettyServerBuilder.forAddress(portalEndpoint) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) - .workerEventLoopGroup(getEventLoopGroup()) - .bossEventLoopGroup(getEventLoopGroup()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) + .workerEventLoopGroup(IMPL.getEventLoopGroup()) + .bossEventLoopGroup(IMPL.getEventLoopGroup()) .intercept(new DomainSocketServerInterceptor()), s -> handler(portalEndpoint), bridge, Duration.ofMillis(1), router); diff --git a/model/pom.xml b/model/pom.xml index c576868d6..8ca8bbc73 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -1,4 +1,4 @@ - 4.0.0 @@ -26,6 +26,16 @@ com.salesforce.apollo thoth + + com.salesforce.apollo + domain-kqueue + provided + + + com.salesforce.apollo + domain-epoll + provided + org.scijava native-lib-loader diff --git a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java index f67b50be2..a25cf98eb 100644 --- a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java +++ b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java @@ -60,7 +60,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import static com.salesforce.apollo.comm.grpc.DomainSockets.*; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; import static com.salesforce.apollo.cryptography.QualifiedBase64.qb64; /** @@ -75,23 +75,23 @@ */ public class ProcessDomain extends Domain { - private final static Class channelType = getChannelType(); + private final static Class channelType = IMPL.getChannelType(); private final static Logger log = LoggerFactory.getLogger(ProcessDomain.class); private final DomainSocketAddress bridge; - private final EventLoopGroup clientEventLoopGroup = getEventLoopGroup(); + private final EventLoopGroup clientEventLoopGroup = IMPL.getEventLoopGroup(); private final Path communicationsDirectory; - private final EventLoopGroup contextEventLoopGroup = getEventLoopGroup(); + private final EventLoopGroup contextEventLoopGroup = IMPL.getEventLoopGroup(); private final KerlDHT dht; - private final View foundation; - private final Map hostedDomains = new ConcurrentHashMap<>(); - private final UUID listener; + private final View foundation; + private final Map hostedDomains = new ConcurrentHashMap<>(); + private final UUID listener; private final DomainSocketAddress outerContextEndpoint; private final Server outerContextService; private final Portal portal; private final DomainSocketAddress portalEndpoint; - private final EventLoopGroup portalEventLoopGroup = getEventLoopGroup(); + private final EventLoopGroup portalEventLoopGroup = IMPL.getEventLoopGroup(); private final Map routes = new HashMap<>(); private final IdentifierSpecification.Builder subDomainSpecification; @@ -118,8 +118,8 @@ public ProcessDomain(Digest group, ControlledIdentifierMember member, Builder bu portalEndpoint = new DomainSocketAddress( communicationsDirectory.resolve(UUID.randomUUID().toString()).toFile()); portal = new Portal<>(member.getId(), NettyServerBuilder.forAddress(portalEndpoint) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) .workerEventLoopGroup(portalEventLoopGroup) .bossEventLoopGroup(portalEventLoopGroup) .intercept(new DomainSocketServerInterceptor()), @@ -127,8 +127,8 @@ public ProcessDomain(Digest group, ControlledIdentifierMember member, Builder bu outerContextEndpoint = new DomainSocketAddress( communicationsDirectory.resolve(UUID.randomUUID().toString()).toFile()); outerContextService = NettyServerBuilder.forAddress(outerContextEndpoint) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) .addService(new DemesneKERLServer(dht, null)) .addService(outerContextService()) .workerEventLoopGroup(contextEventLoopGroup) diff --git a/model/src/main/java/com/salesforce/apollo/model/demesnes/DemesneImpl.java b/model/src/main/java/com/salesforce/apollo/model/demesnes/DemesneImpl.java index 327cf8f97..1a1973176 100644 --- a/model/src/main/java/com/salesforce/apollo/model/demesnes/DemesneImpl.java +++ b/model/src/main/java/com/salesforce/apollo/model/demesnes/DemesneImpl.java @@ -63,8 +63,7 @@ import java.util.function.Supplier; import static com.salesforce.apollo.archipelago.RouterImpl.clientInterceptor; -import static com.salesforce.apollo.comm.grpc.DomainSockets.getChannelType; -import static com.salesforce.apollo.comm.grpc.DomainSockets.getEventLoopGroup; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; /** * Isolate for the Apollo SubDomain stack @@ -72,9 +71,9 @@ * @author hal.hildebrand */ public class DemesneImpl implements Demesne { - private static final Class channelType = getChannelType(); + private static final Class channelType = IMPL.getChannelType(); private static final Duration DEFAULT_GOSSIP_INTERVAL = Duration.ofMillis(5); - private static final EventLoopGroup eventLoopGroup = getEventLoopGroup(); + private static final EventLoopGroup eventLoopGroup = IMPL.getEventLoopGroup(); private static final Logger log = LoggerFactory.getLogger(DemesneImpl.class); private final static Executor executor = Executors.newVirtualThreadPerTaskExecutor(); private final KERL kerl; diff --git a/model/src/test/java/com/salesforce/apollo/model/demesnes/DemesneTest.java b/model/src/test/java/com/salesforce/apollo/model/demesnes/DemesneTest.java index b5a79dc3f..5483dd02e 100644 --- a/model/src/test/java/com/salesforce/apollo/model/demesnes/DemesneTest.java +++ b/model/src/test/java/com/salesforce/apollo/model/demesnes/DemesneTest.java @@ -66,7 +66,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import static com.salesforce.apollo.comm.grpc.DomainSockets.*; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; import static com.salesforce.apollo.cryptography.QualifiedBase64.qb64; import static org.junit.jupiter.api.Assertions.*; @@ -74,8 +74,8 @@ * @author hal.hildebrand */ public class DemesneTest { - private final static Class clientChannelType = getChannelType(); - private static final Class serverChannelType = getServerDomainSocketChannelClass(); + private final static Class clientChannelType = IMPL.getChannelType(); + private static final Class serverChannelType = IMPL.getServerDomainSocketChannelClass(); private final static Executor executor = Executors.newVirtualThreadPerTaskExecutor(); private final TestItService local = new TestItService() { @@ -123,7 +123,7 @@ public void after() throws Exception { @BeforeEach public void before() { - eventLoopGroup = getEventLoopGroup(); + eventLoopGroup = IMPL.getEventLoopGroup(); } @Test @@ -140,13 +140,13 @@ public void portal() throws Exception { final var routes = new HashMap(); final var portal = new Portal<>(serverMember1.getId(), NettyServerBuilder.forAddress(portalEndpoint) .protocolNegotiator( - new DomainSocketNegotiator()) + new DomainSocketNegotiator(IMPL)) .channelType( - getServerDomainSocketChannelClass()) + IMPL.getServerDomainSocketChannelClass()) .workerEventLoopGroup( - getEventLoopGroup()) + IMPL.getEventLoopGroup()) .bossEventLoopGroup( - getEventLoopGroup()) + IMPL.getEventLoopGroup()) .intercept( new DomainSocketServerInterceptor()), s -> handler(portalEndpoint), bridge, Duration.ofMillis(1), s -> routes.get(s)); @@ -200,7 +200,7 @@ public void smokin() throws Exception { final var portalEndpoint = new DomainSocketAddress(commDirectory.resolve(portalAddress).toFile()); final var router = new RouterImpl(serverMember, NettyServerBuilder.forAddress(portalEndpoint) .protocolNegotiator( - new DomainSocketNegotiator()) + new DomainSocketNegotiator(IMPL)) .channelType(serverChannelType) .workerEventLoopGroup(eventLoopGroup) .bossEventLoopGroup(eventLoopGroup) @@ -230,12 +230,12 @@ public void register(SubContext context) { final var kerlServer = new DemesneKERLServer(new ProtoKERLAdapter(kerl), null); final var outerService = new OuterContextServer(service, null); final var outerContextService = NettyServerBuilder.forAddress(parentEndpoint) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) .addService(kerlServer) .addService(outerService) - .workerEventLoopGroup(getEventLoopGroup()) - .bossEventLoopGroup(getEventLoopGroup()) + .workerEventLoopGroup(IMPL.getEventLoopGroup()) + .bossEventLoopGroup(IMPL.getEventLoopGroup()) .intercept(new DomainSocketServerInterceptor()) .build(); outerContextService.start(); diff --git a/pom.xml b/pom.xml index 2aa3896d3..7f3a1b3a7 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,9 @@ gorgoneion gorgoneion-client cryptography + domain-epoll + domain-kqueue + domain-sockets @@ -121,6 +124,11 @@ thoth ${project.version} + + com.salesforce.apollo + domain-sockets + ${project.version} + com.salesforce.apollo domain-epoll @@ -494,10 +502,29 @@ + + io.netty + netty-common + ${netty.version} + io.netty netty-transport-native-unix-common ${netty.version} + ${os.detected.classifier} + + + io.netty + netty-transport-native-kqueue + ${netty.version} + ${os.detected.classifier} + + + io.netty + netty-transport-native-epoll + ${netty.version} + ${os.detected.classifier} + provided org.graalvm.sdk @@ -596,49 +623,6 @@ - - - pre - - false - - - h2-deterministic - - - - isolates - - false - - - isolates - isolate-ftesting - - - - mac-domain - - - mac - - - - domain-kqueue - - - - linux-domain - - - linux - - - - domain-epoll - - - @@ -881,4 +865,25 @@ + + + pre + + false + + + h2-deterministic + + + + isolates + + false + + + isolates + isolate-ftesting + + + diff --git a/protocols/pom.xml b/protocols/pom.xml index 815c0403d..9a0f09ee4 100644 --- a/protocols/pom.xml +++ b/protocols/pom.xml @@ -11,6 +11,16 @@ Apollo base GRPC communications and rate limiting + + com.salesforce.apollo + domain-kqueue + provided + + + com.salesforce.apollo + domain-epoll + provided + org.checkerframework checker-qual @@ -27,10 +37,6 @@ io.grpc grpc-netty - - io.netty - netty-transport-native-unix-common - io.perfmark perfmark-api @@ -101,7 +107,7 @@ - mac + mac-domain mac @@ -109,13 +115,23 @@ - com.salesforce.apollo - domain-kqueue + io.netty + netty-transport-native-unix-common + ${netty.version} + ${os.detected.classifier} + test + + + io.netty + netty-transport-native-kqueue + ${netty.version} + ${os.detected.classifier} + optional - linux + linux-domain linux @@ -123,9 +139,18 @@ - com.salesforce.apollo - domain-epoll - ${project.version} + io.netty + netty-transport-native-unix-common + ${netty.version} + ${os.detected.classifier} + test + + + io.netty + netty-transport-native-epoll + ${netty.version} + ${os.detected.classifier} + optional diff --git a/protocols/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketServerInterceptor.java b/protocols/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketServerInterceptor.java index 3ca7dc53f..3497232da 100644 --- a/protocols/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketServerInterceptor.java +++ b/protocols/src/main/java/com/salesforce/apollo/comm/grpc/DomainSocketServerInterceptor.java @@ -6,24 +6,41 @@ */ package com.salesforce.apollo.comm.grpc; -import static io.grpc.netty.DomainSocketNegotiatorHandler.TRANSPORT_ATTR_PEER_CREDENTIALS; - -import io.grpc.Context; -import io.grpc.Contexts; -import io.grpc.Metadata; -import io.grpc.ServerCall; -import io.grpc.ServerCallHandler; -import io.grpc.ServerInterceptor; -import io.grpc.Status; +import io.grpc.*; import io.netty.channel.unix.PeerCredentials; +import static io.grpc.netty.DomainSocketNegotiatorHandler.TRANSPORT_ATTR_PEER_CREDENTIALS; + /** * @author hal.hildebrand - * */ public class DomainSocketServerInterceptor implements ServerInterceptor { - public static final Context.Key PEER_CREDENTIALS_CONTEXT_KEY = Context.key("com.salesforce.apollo.PEER_CREDENTIALS"); + public static final Context.Key PEER_CREDENTIALS_CONTEXT_KEY = Context.key( + "com.salesforce.apollo.PEER_CREDENTIALS"); + private static final String OS = System.getProperty("os.name") + .toLowerCase(); + public static final DomainSockets IMPL = configure(); + + public static boolean isMac() { + return OS.indexOf("mac") >= 0; + } + + static DomainSockets configure() { + if (isMac()) { + return configureMac(); + } else { + return configureLunux(); + } + } + + static DomainSockets configureLunux() { + return new DomainSocketsLinux(); + } + + static DomainSockets configureMac() { + return new DomainSocketsOSX(); + } @Override public ServerCall.Listener interceptCall(ServerCall call, @@ -32,8 +49,7 @@ public ServerCall.Listener interceptCall(ServerCall() { }; } diff --git a/protocols/src/main/java/io/grpc/netty/DomainSocketNegotiatorHandler.java b/protocols/src/main/java/io/grpc/netty/DomainSocketNegotiatorHandler.java index 3ad61bd34..6844a0817 100644 --- a/protocols/src/main/java/io/grpc/netty/DomainSocketNegotiatorHandler.java +++ b/protocols/src/main/java/io/grpc/netty/DomainSocketNegotiatorHandler.java @@ -7,7 +7,6 @@ package io.grpc.netty; import com.salesforce.apollo.comm.grpc.DomainSockets; - import io.grpc.Attributes; import io.grpc.ChannelLogger; import io.grpc.Grpc; @@ -24,35 +23,18 @@ /** * @author hal.hildebrand - * */ public class DomainSocketNegotiatorHandler extends ProtocolNegotiationHandler { - public static final class DomainSocketNegotiator implements ProtocolNegotiator { - - @Override - public void close() { - } - - @Override - public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) { - ChannelHandler grpcNegotiationHandler = new GrpcNegotiationHandler(grpcHandler); - return new DomainSocketNegotiatorHandler(grpcNegotiationHandler, grpcHandler.getNegotiationLogger()); - } - - @Override - public AsciiString scheme() { - return AsciiString.of("domain"); - } - } - @TransportAttr - public static final Attributes.Key TRANSPORT_ATTR_PEER_CREDENTIALS = Attributes.Key.create("com.salesforce.apollo.TRANSPORT_ATTR_PEER_CREDENTIAL"); - + public static final Attributes.Key TRANSPORT_ATTR_PEER_CREDENTIALS = Attributes.Key.create( + "com.salesforce.apollo.TRANSPORT_ATTR_PEER_CREDENTIAL"); + private final DomainSockets domainSockets; boolean protocolNegotiationEventReceived; - DomainSocketNegotiatorHandler(ChannelHandler next, ChannelLogger negotiationLogger) { + DomainSocketNegotiatorHandler(ChannelHandler next, ChannelLogger negotiationLogger, DomainSockets domainSockets) { super(next, negotiationLogger); + this.domainSockets = domainSockets; } @Override @@ -76,7 +58,7 @@ protected void protocolNegotiationEventTriggered(ChannelHandlerContext ctx) { private void replaceOnActive(ChannelHandlerContext ctx) { ProtocolNegotiationEvent existingPne = getProtocolNegotiationEvent(); - PeerCredentials credentials = DomainSockets.getPeerCredentials(ctx.channel()); + PeerCredentials credentials = domainSockets.getPeerCredentials(ctx.channel()); Attributes attrs = existingPne.getAttributes() .toBuilder() .set(GrpcAttributes.ATTR_SECURITY_LEVEL, SecurityLevel.PRIVACY_AND_INTEGRITY) @@ -86,4 +68,29 @@ private void replaceOnActive(ChannelHandlerContext ctx) { .build(); replaceProtocolNegotiationEvent(existingPne.withAttributes(attrs)); } + + public static final class DomainSocketNegotiator implements ProtocolNegotiator { + + private final DomainSockets domainSockets; + + public DomainSocketNegotiator(DomainSockets domainSockets) { + this.domainSockets = domainSockets; + } + + @Override + public void close() { + } + + @Override + public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) { + ChannelHandler grpcNegotiationHandler = new GrpcNegotiationHandler(grpcHandler); + return new DomainSocketNegotiatorHandler(grpcNegotiationHandler, grpcHandler.getNegotiationLogger(), + domainSockets); + } + + @Override + public AsciiString scheme() { + return AsciiString.of("domain"); + } + } } diff --git a/protocols/src/test/java/com/salesforce/apollo/comm/grpc/DomainSocketTest.java b/protocols/src/test/java/com/salesforce/apollo/comm/grpc/DomainSocketTest.java index f12e55d49..831ed3f4b 100644 --- a/protocols/src/test/java/com/salesforce/apollo/comm/grpc/DomainSocketTest.java +++ b/protocols/src/test/java/com/salesforce/apollo/comm/grpc/DomainSocketTest.java @@ -6,26 +6,11 @@ */ package com.salesforce.apollo.comm.grpc; -import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.PEER_CREDENTIALS_CONTEXT_KEY; -import static com.salesforce.apollo.comm.grpc.DomainSockets.getChannelType; -import static com.salesforce.apollo.comm.grpc.DomainSockets.getEventLoopGroup; -import static com.salesforce.apollo.comm.grpc.DomainSockets.getServerDomainSocketChannelClass; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.concurrent.TimeUnit; - -import org.junit.jupiter.api.Test; - import com.google.common.primitives.Ints; import com.google.protobuf.Any; import com.salesfoce.apollo.test.proto.PeerCreds; import com.salesfoce.apollo.test.proto.TestItGrpc; import com.salesfoce.apollo.test.proto.TestItGrpc.TestItImplBase; - import io.grpc.ManagedChannel; import io.grpc.Status; import io.grpc.StatusRuntimeException; @@ -35,33 +20,22 @@ import io.grpc.stub.StreamObserver; import io.netty.channel.Channel; import io.netty.channel.unix.DomainSocketAddress; +import org.junit.jupiter.api.Test; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.TimeUnit; + +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.IMPL; +import static com.salesforce.apollo.comm.grpc.DomainSocketServerInterceptor.PEER_CREDENTIALS_CONTEXT_KEY; +import static org.junit.jupiter.api.Assertions.*; /** * @author hal.hildebrand - * */ public class DomainSocketTest { - public static class TestServer extends TestItImplBase { - - @Override - public void ping(Any request, StreamObserver responseObserver) { - final var credentials = PEER_CREDENTIALS_CONTEXT_KEY.get(); - if (credentials == null) { - responseObserver.onError(new StatusRuntimeException(Status.INVALID_ARGUMENT.withDescription("No credentials available"))); - return; - } - responseObserver.onNext(Any.pack(PeerCreds.newBuilder() - .setPid(credentials.pid()) - .setUid(credentials.uid()) - .addAllGids(Ints.asList(credentials.gids())) - .build())); - responseObserver.onCompleted(); - } - - } - - private static final Class channelType = getChannelType(); + private static final Class channelType = IMPL.getChannelType(); @Test public void smokin() throws Exception { @@ -69,10 +43,10 @@ public void smokin() throws Exception { Files.deleteIfExists(socketPath); assertFalse(Files.exists(socketPath)); - final var eventLoopGroup = getEventLoopGroup(); + final var eventLoopGroup = IMPL.getEventLoopGroup(); var server = NettyServerBuilder.forAddress(new DomainSocketAddress(socketPath.toFile())) - .protocolNegotiator(new DomainSocketNegotiator()) - .channelType(getServerDomainSocketChannelClass()) + .protocolNegotiator(new DomainSocketNegotiator(IMPL)) + .channelType(IMPL.getServerDomainSocketChannelClass()) .workerEventLoopGroup(eventLoopGroup) .bossEventLoopGroup(eventLoopGroup) .addService(new TestServer()) @@ -101,4 +75,24 @@ public void smokin() throws Exception { } } + public static class TestServer extends TestItImplBase { + + @Override + public void ping(Any request, StreamObserver responseObserver) { + final var credentials = PEER_CREDENTIALS_CONTEXT_KEY.get(); + if (credentials == null) { + responseObserver.onError( + new StatusRuntimeException(Status.INVALID_ARGUMENT.withDescription("No credentials available"))); + return; + } + responseObserver.onNext(Any.pack(PeerCreds.newBuilder() + .setPid(credentials.pid()) + .setUid(credentials.uid()) + .addAllGids(Ints.asList(credentials.gids())) + .build())); + responseObserver.onCompleted(); + } + + } + }