use of co.rsk.net.NodeID in project rskj by rsksmart.
the class WriterMessageRecorderTest method recordRskMessageWithSender.
@Test
public void recordRskMessageWithSender() throws IOException {
Message message = createRskMessage();
StringWriter writer = new StringWriter();
BufferedWriter bwriter = new BufferedWriter(writer);
Random random = new Random();
byte[] nodeId = new byte[10];
random.nextBytes(nodeId);
NodeID sender = new NodeID(nodeId);
WriterMessageRecorder recorder = new WriterMessageRecorder(bwriter, null);
recorder.recordMessage(sender, message);
bwriter.close();
String result = writer.toString();
String encoded = Hex.toHexString(message.getEncoded());
Assert.assertTrue(result.contains("," + encoded + "," + Hex.toHexString(nodeId)));
Assert.assertTrue(result.contains(",0,RSK_MESSAGE,GET_BLOCK_MESSAGE,"));
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class DecidingSyncStateTest method doesntStartSyncingIfAllPeersHaveLowerDifficulty.
@Test
public void doesntStartSyncingIfAllPeersHaveLowerDifficulty() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
SimpleSyncInformation syncInformation = new SimpleSyncInformation().withWorsePeers();
PeersInformation knownPeers = new PeersInformation(syncInformation, RskMockFactory.getChannelManager(), syncConfiguration);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, syncInformation, knownPeers);
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
knownPeers.registerPeer(new NodeID(HashUtil.randomPeerId()));
syncState.newPeerStatus();
syncState.tick(Duration.ofMinutes(2));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class DecidingSyncStateTest method startsSyncingWith5NonRepeatedPeers.
@Test
public void startsSyncingWith5NonRepeatedPeers() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
SimpleSyncInformation syncInformation = new SimpleSyncInformation();
ChannelManager channelManager = RskMockFactory.getChannelManager();
PeersInformation knownPeers = new PeersInformation(syncInformation, channelManager, syncConfiguration);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, syncInformation, knownPeers);
Collection<Channel> peers = new ArrayList<>();
NodeID peerToRepeat = new NodeID(HashUtil.randomPeerId());
Channel channel = mock(Channel.class);
when(channel.getNodeId()).thenReturn(peerToRepeat);
peers.add(channel);
for (int i = 0; i < 10; i++) {
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
knownPeers.registerPeer(peerToRepeat).setStatus(StatusUtils.getFakeStatus());
syncState.newPeerStatus();
}
for (int i = 0; i < 4; i++) {
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
NodeID nodeID = new NodeID(HashUtil.randomPeerId());
knownPeers.registerPeer(nodeID).setStatus(StatusUtils.getFakeStatus());
channel = mock(Channel.class);
when(channel.getNodeId()).thenReturn(nodeID);
peers.add(channel);
when(channelManager.getActivePeers()).thenReturn(peers);
syncState.newPeerStatus();
}
Assert.assertTrue(syncEventsHandler.startSyncingWasCalled());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class DecidingSyncStateTest method doesntStartSyncingWith1PeerBeforeTimeout.
@Test
public void doesntStartSyncingWith1PeerBeforeTimeout() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
SimpleSyncInformation syncInformation = new SimpleSyncInformation();
PeersInformation knownPeers = new PeersInformation(syncInformation, RskMockFactory.getChannelManager(), syncConfiguration);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, syncInformation, knownPeers);
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
knownPeers.registerPeer(new NodeID(HashUtil.randomPeerId()));
syncState.newPeerStatus();
syncState.tick(syncConfiguration.getTimeoutWaitingPeers().minusSeconds(1L));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class DecidingSyncStateTest method doesntStartSyncingIfAllPeersHaveBadReputation.
@Test
public void doesntStartSyncingIfAllPeersHaveBadReputation() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
SimpleSyncInformation syncInformation = new SimpleSyncInformation().withBadReputation();
PeersInformation knownPeers = new PeersInformation(syncInformation, RskMockFactory.getChannelManager(), syncConfiguration);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, syncInformation, knownPeers);
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
knownPeers.registerPeer(new NodeID(HashUtil.randomPeerId()));
syncState.newPeerStatus();
syncState.tick(Duration.ofMinutes(2));
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
Aggregations