Skip to content

Commit

Permalink
Use delegated Verifiers and EventValidation in the View
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Jan 1, 2024
1 parent 8e96d59 commit 6dc1ad6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,107 +165,4 @@ public boolean verify(SigningThreshold threshold, JohnHancock signature, InputSt

record Filtered(boolean verified, int validating, JohnHancock filtered) {
}

class DelegatedVerifier implements Verifier {
private volatile Verifier delegate;

public DelegatedVerifier(Verifier delegate) {
this.delegate = delegate;
}

@Override
public Filtered filtered(SigningThreshold threshold, JohnHancock signature, byte[]... message) {
return getDelegate().filtered(threshold, signature, message);
}

@Override
public Filtered filtered(SigningThreshold threshold, JohnHancock signature, ByteBuffer... message) {
return getDelegate().filtered(threshold, signature, message);
}

@Override
public Filtered filtered(SigningThreshold threshold, JohnHancock signature, ByteString... message) {
return getDelegate().filtered(threshold, signature, message);
}

@Override
public Filtered filtered(SigningThreshold threshold, JohnHancock signature, InputStream message) {
return getDelegate().filtered(threshold, signature, message);
}

@Override
public Filtered filtered(SigningThreshold threshold, JohnHancock signature, List<ByteBuffer> forSigning) {
return getDelegate().filtered(threshold, signature, forSigning);
}

@Override
public Filtered filtered(SigningThreshold threshold, JohnHancock signature, String message) {
return getDelegate().filtered(threshold, signature, message);
}

@Override
public boolean verify(JohnHancock signature, byte[]... message) {
return getDelegate().verify(signature, message);
}

@Override
public boolean verify(JohnHancock signature, ByteBuffer... message) {
return getDelegate().verify(signature, message);
}

@Override
public boolean verify(JohnHancock signature, ByteString... message) {
return getDelegate().verify(signature, message);
}

@Override
public boolean verify(JohnHancock signature, InputStream message) {
return getDelegate().verify(signature, message);
}

@Override
public boolean verify(JohnHancock signature, List<ByteBuffer> forSigning) {
return getDelegate().verify(signature, forSigning);
}

@Override
public boolean verify(JohnHancock signature, String message) {
return getDelegate().verify(signature, message);
}

@Override
public boolean verify(SigningThreshold threshold, JohnHancock signature, byte[]... message) {
return getDelegate().verify(threshold, signature, message);
}

@Override
public boolean verify(SigningThreshold threshold, JohnHancock signature, ByteBuffer... message) {
return getDelegate().verify(threshold, signature, message);
}

@Override
public boolean verify(SigningThreshold threshold, JohnHancock signature, ByteString... message) {
return getDelegate().verify(threshold, signature, message);
}

@Override
public boolean verify(SigningThreshold threshold, JohnHancock signature, InputStream message) {
return getDelegate().verify(threshold, signature, message);
}

@Override
public boolean verify(SigningThreshold threshold, JohnHancock signature, List<ByteBuffer> forSigning) {
return getDelegate().verify(threshold, signature, forSigning);
}

@Override
public boolean verify(SigningThreshold threshold, JohnHancock signature, String message) {
return getDelegate().verify(threshold, signature, message);
}

private Verifier getDelegate() {
final var current = delegate;
return current;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public class View {
private final ReadWriteLock viewChange = new ReentrantReadWriteLock(
true);
private final ViewManagement viewManagement;
private final EventValidation validation;
private final Verifiers verifiers;
private final EventValidation.DelegatedEventValidation validation;
private final Verifiers.DelegatedVerifiers verifiers;
private volatile ScheduledFuture<?> futureGossip;

public View(Context<Participant> context, ControlledIdentifierMember member, InetSocketAddress endpoint,
Expand Down Expand Up @@ -138,8 +138,8 @@ public View(Context<Participant> context, ControlledIdentifierMember member, Ine
r -> new EntranceServer(gateway.getClientIdentityProvider(), r, metrics),
EntranceClient.getCreate(metrics), Entrance.getLocalLoopback(node, service));
gossiper = new RingCommunications<>(context, node, comm);
this.validation = validation;
this.verifiers = verifiers;
this.validation = new EventValidation.DelegatedEventValidation(validation);
this.verifiers = new Verifiers.DelegatedVerifiers(verifiers);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public KeyState keyState(Identifier id, ULong sequenceNumber) {
return delegate().keyState(id, sequenceNumber);
}

public void setDelegate(EventValidation delegate) {
this.delegate = delegate;
}

@Override
public boolean validate(EventCoordinates coordinates) {
return delegate().validate(coordinates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,33 @@ static Verifiers fromKeyState_(List<KeyState_> states) {

Optional<Verifier> verifierFor(Identifier identifier);

class DelegatedVerifiers implements Verifiers {
private volatile Verifiers delegate;

public DelegatedVerifiers(Verifiers delegate) {
this.delegate = delegate;
}

public void setDelegate(Verifiers delegate) {
this.delegate = delegate;
}

@Override
public Optional<Verifier> verifierFor(Identifier identifier) {
return delegate().verifierFor(identifier);
}

@Override
public Optional<Verifier> verifierFor(EventCoordinates coordinates) {
return delegate().verifierFor(coordinates);
}

private Verifiers delegate() {
final var current = delegate;
return current;
}
}

class FixedVerifiers implements Verifiers {
private final Map<EventCoordinates, Verifier> verifiersByCoordinates;
private final Map<Identifier, Verifier> verifiersByIdentifer;
Expand Down

0 comments on commit 6dc1ad6

Please sign in to comment.