Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
PAN-2860 - Ignore discport during static node permissioning check (#1631
Browse files Browse the repository at this point in the history
)

- Update SyncStatusNodePermissioningProvider to use URI (without discovery port) instead of EnodeURI to allow optimised permission checking of static nodes
- Add EnodeURL.toURIWithoutDiscoveryPort
  • Loading branch information
usmansaleem authored Jul 3, 2019
1 parent 97234e7 commit d5798f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ public URI toURI() {
}
}

public URI toURIWithoutDiscoveryPort() {
final String uri =
String.format(
"enode://%s@%s:%d",
nodeId.toUnprefixedString(), InetAddresses.toUriString(ip), getListeningPortOrZero());

return URI.create(uri);
}

/**
* Returns the discovery port only if it differs from the listening port
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.metrics.PantheonMetricCategory;

import java.net.URI;
import java.util.Collection;
import java.util.HashSet;
import java.util.OptionalLong;
import java.util.Set;
import java.util.stream.Collectors;

public class SyncStatusNodePermissioningProvider implements NodePermissioningProvider {

private final Synchronizer synchronizer;
private final Collection<EnodeURL> fixedNodes = new HashSet<>();
private final Set<URI> fixedNodes;
private final Counter checkCounter;
private final Counter checkCounterPermitted;
private final Counter checkCounterUnpermitted;
Expand All @@ -44,7 +46,8 @@ public SyncStatusNodePermissioningProvider(
this.synchronizer = synchronizer;
long id = this.synchronizer.observeSyncStatus(this::handleSyncStatusUpdate);
this.syncStatusObserverId = OptionalLong.of(id);
this.fixedNodes.addAll(fixedNodes);
this.fixedNodes =
fixedNodes.stream().map(EnodeURL::toURIWithoutDiscoveryPort).collect(Collectors.toSet());

metricsSystem.createIntegerGauge(
PantheonMetricCategory.PERMISSIONING,
Expand Down Expand Up @@ -103,7 +106,7 @@ public boolean isPermitted(final EnodeURL sourceEnode, final EnodeURL destinatio
return true;
} else {
checkCounter.inc();
if (fixedNodes.stream().anyMatch(p -> EnodeURL.sameListeningEndpoint(p, destinationEnode))) {
if (fixedNodes.contains(destinationEnode.toURIWithoutDiscoveryPort())) {
checkCounterPermitted.inc();
return true;
} else {
Expand Down

0 comments on commit d5798f7

Please sign in to comment.