diff --git a/ethereal/src/test/java/com/salesforce/apollo/ethereal/RbcAdderTest.java b/ethereal/src/test/java/com/salesforce/apollo/ethereal/RbcAdderTest.java index 8cb415325..e3bb8c996 100644 --- a/ethereal/src/test/java/com/salesforce/apollo/ethereal/RbcAdderTest.java +++ b/ethereal/src/test/java/com/salesforce/apollo/ethereal/RbcAdderTest.java @@ -45,7 +45,9 @@ public void before() throws Exception { d = DagReader.readDag(fis, new DagFactory.TestDagFactory()); } units = DagTest.collectUnits(d); - var context = DynamicContext.newBuilder().setCardinality(10).build(); + var b = DynamicContext.newBuilder(); + b.setCardinality(10); + var context = b.build(); var entropy = SecureRandom.getInstance("SHA1PRNG"); entropy.setSeed(new byte[] { 6, 6, 6 }); var stereotomy = new StereotomyImpl(new MemKeyStore(), new MemKERL(DigestAlgorithm.DEFAULT), entropy); diff --git a/gorgoneion-client/src/test/java/com/salesforce/apollo/gorgoneion/client/GorgoneionClientTest.java b/gorgoneion-client/src/test/java/com/salesforce/apollo/gorgoneion/client/GorgoneionClientTest.java index 78d4b420d..c414fa443 100644 --- a/gorgoneion-client/src/test/java/com/salesforce/apollo/gorgoneion/client/GorgoneionClientTest.java +++ b/gorgoneion-client/src/test/java/com/salesforce/apollo/gorgoneion/client/GorgoneionClientTest.java @@ -59,7 +59,9 @@ public void clientSmoke() throws Exception { var stereotomy = new StereotomyImpl(new MemKeyStore(), kerl, entropy); final var prefix = UUID.randomUUID().toString(); var member = new ControlledIdentifierMember(stereotomy.newIdentifier()); - var context = DynamicContext.newBuilder().setCardinality(1).build(); + var b = DynamicContext.newBuilder(); + b.setCardinality(1); + var context = b.build(); context.activate(member); // Gorgoneion service comms @@ -139,7 +141,9 @@ public Void answer(InvocationOnMock invocation) { } }).when(observer).publish(Mockito.any(), Mockito.anyList()); - var context = DynamicContext.newBuilder().setCardinality(members.size()).build(); + var b = DynamicContext.newBuilder(); + b.setCardinality(members.size()); + var context = b.build(); for (ControlledIdentifierMember member : members) { context.activate(member); } diff --git a/gorgoneion/src/test/java/com/salesforce/apollo/gorgoneion/GorgoneionTest.java b/gorgoneion/src/test/java/com/salesforce/apollo/gorgoneion/GorgoneionTest.java index 06267ec73..57386081a 100644 --- a/gorgoneion/src/test/java/com/salesforce/apollo/gorgoneion/GorgoneionTest.java +++ b/gorgoneion/src/test/java/com/salesforce/apollo/gorgoneion/GorgoneionTest.java @@ -47,7 +47,9 @@ public void smokin() throws Exception { var stereotomy = new StereotomyImpl(new MemKeyStore(), kerl, entropy); final var prefix = UUID.randomUUID().toString(); var member = new ControlledIdentifierMember(stereotomy.newIdentifier()); - var context = DynamicContext.newBuilder().setCardinality(1).build(); + var b = DynamicContext.newBuilder(); + b.setCardinality(10); + var context = b.build(); context.activate(member); // Gorgoneion service comms diff --git a/leyden/src/test/java/com/salesforce/apollo/leyden/LeydenJarTest.java b/leyden/src/test/java/com/salesforce/apollo/leyden/LeydenJarTest.java index d397793d8..1e5ffce2e 100644 --- a/leyden/src/test/java/com/salesforce/apollo/leyden/LeydenJarTest.java +++ b/leyden/src/test/java/com/salesforce/apollo/leyden/LeydenJarTest.java @@ -80,7 +80,9 @@ public boolean validateUnbind(byte[] key) { .mapToObj(i -> stereotomy.newIdentifier()) .collect(Collectors.toMap(controlled -> new ControlledIdentifierMember(controlled), controlled -> controlled)); - context = DynamicContext.newBuilder().setpByz(PBYZ).setCardinality(cardinality).build(); + var b = DynamicContext.newBuilder(); + b.setpByz(PBYZ).setCardinality(cardinality); + context = b.build(); identities.keySet().forEach(m -> context.activate(m)); identities.keySet().forEach(member -> instantiate(member, context)); diff --git a/memberships/src/main/java/com/salesforce/apollo/context/Context.java b/memberships/src/main/java/com/salesforce/apollo/context/Context.java index aed5ef7ec..2e4917cdf 100644 --- a/memberships/src/main/java/com/salesforce/apollo/context/Context.java +++ b/memberships/src/main/java/com/salesforce/apollo/context/Context.java @@ -7,6 +7,7 @@ package com.salesforce.apollo.context; import com.salesforce.apollo.cryptography.Digest; +import com.salesforce.apollo.cryptography.DigestAlgorithm; import com.salesforce.apollo.membership.Member; import com.salesforce.apollo.membership.Util; import org.apache.commons.math3.random.BitsStreamGenerator; @@ -497,4 +498,62 @@ default int majority() { Iterable traverse(int ring, T member); boolean validRing(int ring); + + /** + * @author hal.hildebrand + **/ + abstract class Builder { + protected int bias = 2; + protected int cardinality; + protected double epsilon = DEFAULT_EPSILON; + protected Digest id = DigestAlgorithm.DEFAULT.getOrigin(); + protected double pByz = 0.1; // 10% chance any node is out to get ya + + public abstract > C build(); + + public int getBias() { + return bias; + } + + public Builder setBias(int bias) { + this.bias = bias; + return this; + } + + public int getCardinality() { + return cardinality; + } + + public Builder setCardinality(int cardinality) { + this.cardinality = cardinality; + return this; + } + + public double getEpsilon() { + return epsilon; + } + + public Builder setEpsilon(double epsilon) { + this.epsilon = epsilon; + return this; + } + + public Digest getId() { + return id; + } + + public Builder setId(Digest id) { + this.id = id; + return this; + } + + public double getpByz() { + return pByz; + } + + public Builder setpByz(double pByz) { + this.pByz = pByz; + return this; + } + } } diff --git a/memberships/src/main/java/com/salesforce/apollo/context/DynamicContext.java b/memberships/src/main/java/com/salesforce/apollo/context/DynamicContext.java index a47199afe..3abcf8048 100644 --- a/memberships/src/main/java/com/salesforce/apollo/context/DynamicContext.java +++ b/memberships/src/main/java/com/salesforce/apollo/context/DynamicContext.java @@ -7,7 +7,6 @@ package com.salesforce.apollo.context; import com.salesforce.apollo.cryptography.Digest; -import com.salesforce.apollo.cryptography.DigestAlgorithm; import com.salesforce.apollo.membership.Member; import java.util.Collection; @@ -28,13 +27,7 @@ public interface DynamicContext extends Context { static Builder newBuilder() { - return new Builder<>() { - - @Override - public DynamicContext build() { - return new DynamicContextImpl(id, Math.max(bias + 1, cardinality), pByz, bias, epsilon); - } - }; + return new Builder<>(); } /** @@ -200,59 +193,11 @@ default void offline(T member) { } } - abstract class Builder { - protected int bias = 2; - protected int cardinality; - protected double epsilon = Context.DEFAULT_EPSILON; - protected Digest id = DigestAlgorithm.DEFAULT.getOrigin(); - protected double pByz = 0.1; // 10% chance any node is out to get ya - - public abstract DynamicContext build(); - - public int getBias() { - return bias; - } - - public Builder setBias(int bias) { - this.bias = bias; - return this; - } + class Builder extends Context.Builder { - public int getCardinality() { - return cardinality; - } - - public Builder setCardinality(int cardinality) { - this.cardinality = cardinality; - return this; - } - - public double getEpsilon() { - return epsilon; - } - - public Builder setEpsilon(double epsilon) { - this.epsilon = epsilon; - return this; - } - - public Digest getId() { - return id; - } - - public Builder setId(Digest id) { - this.id = id; - return this; - } - - public double getpByz() { - return pByz; - } - - public Builder setpByz(double pByz) { - this.pByz = pByz; - return this; + @Override + public DynamicContext build() { + return new DynamicContextImpl(id, Math.max(bias + 1, cardinality), pByz, bias, epsilon); } } - } diff --git a/memberships/src/test/java/com/salesforce/apollo/messaging/rbc/RbcTest.java b/memberships/src/test/java/com/salesforce/apollo/messaging/rbc/RbcTest.java index 6186aeb2e..1623aa18c 100644 --- a/memberships/src/test/java/com/salesforce/apollo/messaging/rbc/RbcTest.java +++ b/memberships/src/test/java/com/salesforce/apollo/messaging/rbc/RbcTest.java @@ -87,7 +87,9 @@ public void broadcast() throws Exception { .map(e -> (SigningMember) e) .toList(); - var context = DynamicContext.newBuilder().setCardinality(members.size()).build(); + var b = DynamicContext.newBuilder(); + b.setCardinality(members.size()); + var context = b.build(); var metrics = new RbcMetricsImpl(context.getId(), "test", registry); members.forEach(m -> context.activate(m)); 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 706fa8828..1d04e23b3 100644 --- a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java +++ b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java @@ -55,11 +55,9 @@ public ProcessDomain(Digest group, ControlledIdentifierMember member, ProcessDom com.salesforce.apollo.fireflies.Parameters.Builder ff, StereotomyMetrics stereotomyMetrics) { super(member, builder, pdParams.dbURL, pdParams.checkpointBaseDir, runtime); parameters = pdParams; - var base = DynamicContext.newBuilder() - .setBias(parameters.dhtBias) - .setpByz(parameters.dhtPbyz) - .setId(group) - .build(); + var b = DynamicContext.newBuilder(); + b.setBias(parameters.dhtBias).setpByz(parameters.dhtPbyz).setId(group); + var base = b.build(); JdbcConnectionPool connectionPool = JdbcConnectionPool.create(parameters.dhtDbUrl, "", ""); connectionPool.setMaxConnections(parameters.jdbcMaxConnections()); dht = new KerlDHT(parameters.dhtOpsFrequency, params.context(), member, connectionPool, diff --git a/thoth/src/test/java/com/salesforce/apollo/thoth/MaatTest.java b/thoth/src/test/java/com/salesforce/apollo/thoth/MaatTest.java index d91b206fa..0a7b6c8e6 100644 --- a/thoth/src/test/java/com/salesforce/apollo/thoth/MaatTest.java +++ b/thoth/src/test/java/com/salesforce/apollo/thoth/MaatTest.java @@ -36,7 +36,9 @@ public void smokin() throws Exception { entropy.setSeed(new byte[] { 6, 6, 6 }); final var kerl_ = new MemKERL(DigestAlgorithm.DEFAULT); var stereotomy = new StereotomyImpl(new MemKeyStore(), kerl_, entropy); - var context = DynamicContext.newBuilder().setCardinality(4).build(); + var b = DynamicContext.newBuilder(); + b.setCardinality(4); + var context = b.build(); for (int i = 0; i < 4; i++) { context.activate(new ControlledIdentifierMember(stereotomy.newIdentifier())); }