Skip to content

Commit

Permalink
combine hashes for view id, simplify bft subset.mtls server/client vt…
Browse files Browse the repository at this point in the history
…hread default
  • Loading branch information
Hellblazer committed Jul 5, 2024
1 parent baa9212 commit 24db4b3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public MtlsClient(SocketAddress address, ClientAuth clientAuth, String alias, Cl

Limiter<GrpcClientRequestContext> limiter = new GrpcClientLimiterBuilder().blockOnLimit(false).build();
channel = NettyChannelBuilder.forAddress(address)
// .executor(executor)
.executor(executor)
.withOption(ChannelOption.TCP_NODELAY, true)
.sslContext(supplier.forClient(clientAuth, alias, validator, MtlsServer.TL_SV1_3))
.intercept(new ConcurrencyLimitClientInterceptor(limiter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand Down Expand Up @@ -140,15 +141,15 @@ public static SslContext forServer(ClientAuth clientAuth, String alias, X509Cert
public RouterImpl router(ServerConnectionCache.Builder cacheBuilder, Supplier<Limit> serverLimit,
LimitsRegistry limitsRegistry, List<ServerInterceptor> interceptors,
Predicate<FernetServerInterceptor.HashedToken> validator, ExecutorService executor) {
// if (executor == null) {
// executor = Executors.newVirtualThreadPerTaskExecutor();
// }
if (executor == null) {
executor = Executors.newVirtualThreadPerTaskExecutor();
}
var limitsBuilder = new GrpcServerLimiterBuilder().limit(serverLimit.get());
if (limitsRegistry != null) {
limitsBuilder.metricRegistry(limitsRegistry);
}
NettyServerBuilder serverBuilder = NettyServerBuilder.forAddress(epProvider.getBindAddress())
// .executor(executor)
.executor(executor)
.withOption(ChannelOption.SO_REUSEADDR, true)
.sslContext(supplier.forServer(ClientAuth.REQUIRE,
epProvider.getAlias(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,16 +730,10 @@ public Iterable<T> traverse(int ring, T member) {
*/
@Override
public void uniqueSuccessors(Digest key, Predicate<T> test, Set<T> collector) {
var delegate = ring(0).successor(key, test);
if (delegate == null) {
return;
}
for (Ring<T> ring : rings) {
T successor = ring.successor(hashFor(delegate, ring.index), m -> !collector.contains(m) && test.test(m));
T successor = ring.successor(key, m -> !collector.contains(m) && test.test(m));
if (successor != null) {
collector.add(successor);
} else {
collector.add(delegate);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,11 @@ public Iterable<T> traverse(int ring, T member) {

@Override
public void uniqueSuccessors(Digest key, Predicate<T> test, Set<T> collector) {
var delegate = ring(0).successor(key, test);
if (delegate == null) {
return;
}
for (int ring = 0; ring < rings.length; ring++) {
StaticRing r = ring(ring);
T successor = r.successor(hashFor(delegate, r.index), m -> !collector.contains(m) && test.test(m));
T successor = r.successor(key, m -> !collector.contains(m) && test.test(m));
if (successor != null) {
collector.add(successor);
} else {
collector.add(delegate);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.SequencedSet;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -26,6 +27,30 @@
*/
public class ContextTests {

@Test
public void bftSubset() throws Exception {
var context = new DynamicContextImpl<>(DigestAlgorithm.DEFAULT.getOrigin().prefix(1), 10, 0.2, 2);
List<SigningMember> members = new ArrayList<>();
var entropy = SecureRandom.getInstance("SHA1PRNG");
entropy.setSeed(new byte[] { 6, 6, 6 });
var stereotomy = new StereotomyImpl(new MemKeyStore(), new MemKERL(DigestAlgorithm.DEFAULT), entropy);

for (int i = 0; i < 7; i++) {
SigningMember m = new ControlledIdentifierMember(stereotomy.newIdentifier());
members.add(m);
context.activate(m);
}
var testEntropy = SecureRandom.getInstance("SHA1PRNG");
testEntropy.setSeed(new byte[] { 6, 6, 6 });
var algo = DigestAlgorithm.DEFAULT;
List<SequencedSet<Member>> subsets = new ArrayList<>();
for (int i = 0; i < 10; i++) {
var subset = context.bftSubset(algo.random(testEntropy));
System.out.println(subset.stream().map(Member::getId).toList());
subsets.add(subset);
}
}

@Test
public void consistency() throws Exception {
var context = new DynamicContextImpl<>(DigestAlgorithm.DEFAULT.getOrigin().prefix(1), 10, 0.2, 2);
Expand Down

0 comments on commit 24db4b3

Please sign in to comment.