use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerScoringManagerTest method notGoodReputationByNodeIDExpires.
@Test
public void notGoodReputationByNodeIDExpires() throws UnknownHostException, InterruptedException {
NodeID id = generateNodeID();
PeerScoringManager manager = createPeerScoringManager();
manager.recordEvent(id, null, EventType.INVALID_BLOCK);
Assert.assertEquals(1, manager.getPeerScoring(id).getEventCounter(EventType.INVALID_BLOCK));
Assert.assertFalse(manager.hasGoodReputation(id));
Assert.assertNotEquals(0, manager.getPeerScoring(id).getTimeLostGoodReputation());
Assert.assertFalse(manager.hasGoodReputation(id));
Assert.assertNotEquals(0, manager.getPeerScoring(id).getTimeLostGoodReputation());
Assert.assertEquals(1, manager.getPeerScoring(id).getEventCounter(EventType.INVALID_BLOCK));
TimeUnit.MILLISECONDS.sleep(100);
Assert.assertTrue(manager.hasGoodReputation(id));
Assert.assertEquals(0, manager.getPeerScoring(id).getTimeLostGoodReputation());
Assert.assertEquals(0, manager.getPeerScoring(id).getEventCounter(EventType.INVALID_BLOCK));
Assert.assertTrue(manager.getPeerScoring(id).isEmpty());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerScoringManagerTest method getEmptyNodeStatusFromUnknownNodeId.
@Test
public void getEmptyNodeStatusFromUnknownNodeId() {
NodeID id = generateNodeID();
PeerScoringManager manager = createPeerScoringManager();
PeerScoring result = manager.getPeerScoring(id);
Assert.assertNotNull(result);
Assert.assertTrue(result.isEmpty());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerScoringManagerTest method getPeersInformationFromManagerWithThreeEvents.
@Test
public void getPeersInformationFromManagerWithThreeEvents() throws UnknownHostException {
PeerScoringManager manager = createPeerScoringManager();
NodeID node = generateNodeID();
InetAddress address = generateIPAddressV4();
manager.recordEvent(node, address, EventType.VALID_BLOCK);
manager.recordEvent(node, address, EventType.VALID_TRANSACTION);
manager.recordEvent(node, address, EventType.VALID_BLOCK);
List<PeerScoringInformation> result = manager.getPeersInformation();
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
Assert.assertEquals(2, result.size());
PeerScoringInformation info = result.get(0);
Assert.assertEquals(Hex.toHexString(node.getID()).substring(0, 8), info.getId());
Assert.assertEquals(2, info.getValidBlocks());
Assert.assertEquals(0, info.getInvalidBlocks());
Assert.assertEquals(1, info.getValidTransactions());
Assert.assertEquals(0, info.getInvalidTransactions());
Assert.assertEquals(0, info.getPunishments());
Assert.assertEquals(0, info.getSuccessfulHandshakes());
Assert.assertTrue(info.getScore() > 0);
info = result.get(1);
Assert.assertEquals(address.getHostAddress(), info.getId());
Assert.assertEquals(2, info.getValidBlocks());
Assert.assertEquals(0, info.getInvalidBlocks());
Assert.assertEquals(1, info.getValidTransactions());
Assert.assertEquals(0, info.getInvalidTransactions());
Assert.assertEquals(0, info.getPunishments());
Assert.assertEquals(0, info.getSuccessfulHandshakes());
Assert.assertTrue(info.getScore() > 0);
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class WriterMessageRecorderTest method filterMessage.
@Test
public void filterMessage() throws IOException {
Message message = createRskMessage();
StringWriter writer = new StringWriter();
BufferedWriter bwriter = new BufferedWriter(writer);
List<String> commands = new ArrayList<>();
commands.add("TRANSACTIONS");
MessageFilter filter = new MessageFilter(commands);
Random random = new Random();
byte[] nodeId = new byte[10];
random.nextBytes(nodeId);
NodeID sender = new NodeID(nodeId);
WriterMessageRecorder recorder = new WriterMessageRecorder(bwriter, filter);
recorder.recordMessage(sender, message);
bwriter.close();
String result = writer.toString();
Assert.assertEquals(0, result.length());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class DecidingSyncStateTest method startsSyncingWith1PeerAfter2Minutes.
@Test
public void startsSyncingWith1PeerAfter2Minutes() {
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);
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
Channel channel = mock(Channel.class);
NodeID nodeID = new NodeID(HashUtil.randomPeerId());
when(channel.getNodeId()).thenReturn(nodeID);
Collection<Channel> peers = Collections.singletonList(channel);
when(channelManager.getActivePeers()).thenReturn(peers);
knownPeers.registerPeer(nodeID);
syncState.newPeerStatus();
syncState.tick(Duration.ofMinutes(2));
Assert.assertTrue(syncEventsHandler.startSyncingWasCalled());
}
Aggregations