Skip to content

Commit

Permalink
adapt builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Mar 4, 2024
1 parent dc8e552 commit a540445
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -497,4 +498,62 @@ default int majority() {
Iterable<T> traverse(int ring, T member);

boolean validRing(int ring);

/**
* @author hal.hildebrand
**/
abstract class Builder<Z extends Member> {
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 extends Context<Z>> C build();

public int getBias() {
return bias;
}

public Builder<Z> setBias(int bias) {
this.bias = bias;
return this;
}

public int getCardinality() {
return cardinality;
}

public Builder<Z> setCardinality(int cardinality) {
this.cardinality = cardinality;
return this;
}

public double getEpsilon() {
return epsilon;
}

public Builder<Z> setEpsilon(double epsilon) {
this.epsilon = epsilon;
return this;
}

public Digest getId() {
return id;
}

public Builder<Z> setId(Digest id) {
this.id = id;
return this;
}

public double getpByz() {
return pByz;
}

public Builder<Z> setpByz(double pByz) {
this.pByz = pByz;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,13 +27,7 @@
public interface DynamicContext<T extends Member> extends Context<T> {

static <Z extends Member> Builder<Z> newBuilder() {
return new Builder<>() {

@Override
public DynamicContext<Z> build() {
return new DynamicContextImpl<Z>(id, Math.max(bias + 1, cardinality), pByz, bias, epsilon);
}
};
return new Builder<>();
}

/**
Expand Down Expand Up @@ -200,59 +193,11 @@ default void offline(T member) {
}
}

abstract class Builder<Z extends Member> {
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<Z> build();

public int getBias() {
return bias;
}

public Builder<Z> setBias(int bias) {
this.bias = bias;
return this;
}
class Builder<Z extends Member> extends Context.Builder<Z> {

public int getCardinality() {
return cardinality;
}

public Builder<Z> setCardinality(int cardinality) {
this.cardinality = cardinality;
return this;
}

public double getEpsilon() {
return epsilon;
}

public Builder<Z> setEpsilon(double epsilon) {
this.epsilon = epsilon;
return this;
}

public Digest getId() {
return id;
}

public Builder<Z> setId(Digest id) {
this.id = id;
return this;
}

public double getpByz() {
return pByz;
}

public Builder<Z> setpByz(double pByz) {
this.pByz = pByz;
return this;
@Override
public DynamicContext<Z> build() {
return new DynamicContextImpl<Z>(id, Math.max(bias + 1, cardinality), pByz, bias, epsilon);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Participant>newBuilder()
.setBias(parameters.dhtBias)
.setpByz(parameters.dhtPbyz)
.setId(group)
.build();
var b = DynamicContext.<Participant>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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down

0 comments on commit a540445

Please sign in to comment.