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

[PAN-2473] bond with bootnodes #1160

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ public void start() {
throw new IllegalStateException("The peer table had already been started");
}

bootstrapNodes.stream().filter(p -> isPeerPermitted(localPeer, p)).forEach(peerTable::tryAdd);
final List<DiscoveryPeer> initialDiscoveryPeers =
bootstrapNodes.stream()
.filter(p -> isPeerPermitted(localPeer, p))
.collect(Collectors.toList());
initialDiscoveryPeers.stream().forEach(peerTable::tryAdd);

recursivePeerRefreshState =
new RecursivePeerRefreshState(
Expand All @@ -215,16 +219,20 @@ public void start() {
PEER_REFRESH_ROUND_TIMEOUT_IN_SECONDS,
100);

final List<DiscoveryPeer> initialDiscoveryPeers =
bootstrapNodes.stream()
.filter(p -> isPeerPermitted(localPeer, p))
.collect(Collectors.toList());

if (nodePermissioningController.isPresent()) {

// if smart contract permissioning is enabled, bond with bootnodes
if (nodePermissioningController.get().getSyncStatusNodePermissioningProvider().isPresent()) {
for (DiscoveryPeer p : initialDiscoveryPeers) {
bond(p);
}
}

nodePermissioningController
.get()
.startPeerDiscoveryCallback(
() -> recursivePeerRefreshState.start(initialDiscoveryPeers, localPeer.getId()));

} else {
recursivePeerRefreshState.start(initialDiscoveryPeers, localPeer.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

Expand All @@ -27,6 +28,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import org.mockito.ArgumentCaptor;

public class NodePermissioningControllerTestHelper {

private final EnodeURL localNode;
Expand Down Expand Up @@ -88,6 +91,15 @@ public NodePermissioningController build() {
});
}

ArgumentCaptor<Runnable> callback = ArgumentCaptor.forClass(Runnable.class);
doAnswer(
(i) -> {
callback.getValue().run();
return null;
})
.when(nodePermissioningController)
.startPeerDiscoveryCallback(callback.capture());

return nodePermissioningController;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.List;
import java.util.Optional;

import com.google.common.annotations.VisibleForTesting;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -66,8 +65,7 @@ public void startPeerDiscoveryCallback(final Runnable peerDiscoveryCallback) {
}
}

@VisibleForTesting
Optional<SyncStatusNodePermissioningProvider> getSyncStatusNodePermissioningProvider() {
public Optional<SyncStatusNodePermissioningProvider> getSyncStatusNodePermissioningProvider() {
return syncStatusNodePermissioningProvider;
}

Expand Down