Search in sources :

Example 21 with NodeID

use of co.rsk.net.NodeID in project rskj by rsksmart.

the class PeerScoringManagerTest method getPeersInformationFromManagerWithOneEvent.

@Test
public void getPeersInformationFromManagerWithOneEvent() throws UnknownHostException {
    PeerScoringManager manager = createPeerScoringManager();
    NodeID node = generateNodeID();
    InetAddress address = generateIPAddressV4();
    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(1, info.getValidBlocks());
    Assert.assertEquals(0, info.getInvalidBlocks());
    Assert.assertEquals(0, 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(1, info.getValidBlocks());
    Assert.assertEquals(0, info.getInvalidBlocks());
    Assert.assertEquals(0, info.getValidTransactions());
    Assert.assertEquals(0, info.getInvalidTransactions());
    Assert.assertEquals(0, info.getPunishments());
    Assert.assertEquals(0, info.getSuccessfulHandshakes());
    Assert.assertTrue(info.getScore() > 0);
}
Also used : NodeID(co.rsk.net.NodeID) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 22 with NodeID

use of co.rsk.net.NodeID in project rskj by rsksmart.

the class PeerScoringManagerTest method recordEventUsingNodeID.

@Test
public void recordEventUsingNodeID() {
    NodeID id = generateNodeID();
    PeerScoringManager manager = createPeerScoringManager();
    manager.recordEvent(id, null, EventType.INVALID_BLOCK);
    PeerScoring result = manager.getPeerScoring(id);
    Assert.assertNotNull(result);
    Assert.assertFalse(result.isEmpty());
    Assert.assertEquals(1, result.getEventCounter(EventType.INVALID_BLOCK));
    Assert.assertEquals(1, result.getTotalEventCounter());
}
Also used : NodeID(co.rsk.net.NodeID) Test(org.junit.Test)

Example 23 with NodeID

use of co.rsk.net.NodeID in project rskj by rsksmart.

the class PeerScoringManagerTest method managesOnlyThreeNodes.

@Test
public void managesOnlyThreeNodes() {
    PeerScoringManager manager = createPeerScoringManager(3);
    NodeID node1 = generateNodeID();
    NodeID node2 = generateNodeID();
    NodeID node3 = generateNodeID();
    manager.recordEvent(node1, null, EventType.INVALID_BLOCK);
    Assert.assertFalse(manager.getPeerScoring(node1).hasGoodReputation());
    manager.recordEvent(node2, null, EventType.INVALID_BLOCK);
    manager.recordEvent(node3, null, EventType.INVALID_BLOCK);
    NodeID node4 = generateNodeID();
    manager.recordEvent(node4, null, EventType.INVALID_BLOCK);
    Assert.assertTrue(manager.getPeerScoring(node1).hasGoodReputation());
    Assert.assertFalse(manager.getPeerScoring(node2).hasGoodReputation());
    Assert.assertFalse(manager.getPeerScoring(node3).hasGoodReputation());
    Assert.assertFalse(manager.getPeerScoring(node4).hasGoodReputation());
}
Also used : NodeID(co.rsk.net.NodeID) Test(org.junit.Test)

Example 24 with NodeID

use of co.rsk.net.NodeID in project rskj by rsksmart.

the class PeerScoringManagerTest method recordEventUsingNodeIDAndAddress.

@Test
public void recordEventUsingNodeIDAndAddress() throws UnknownHostException {
    NodeID id = generateNodeID();
    InetAddress address = generateIPAddressV4();
    PeerScoringManager manager = createPeerScoringManager();
    manager.recordEvent(id, address, EventType.INVALID_BLOCK);
    PeerScoring result = manager.getPeerScoring(id);
    Assert.assertNotNull(result);
    Assert.assertFalse(result.isEmpty());
    Assert.assertEquals(1, result.getEventCounter(EventType.INVALID_BLOCK));
    Assert.assertEquals(1, result.getTotalEventCounter());
    result = manager.getPeerScoring(address);
    Assert.assertNotNull(result);
    Assert.assertFalse(result.isEmpty());
    Assert.assertEquals(1, result.getEventCounter(EventType.INVALID_BLOCK));
    Assert.assertEquals(1, result.getTotalEventCounter());
}
Also used : NodeID(co.rsk.net.NodeID) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 25 with NodeID

use of co.rsk.net.NodeID in project rskj by rsksmart.

the class PeerScoringManagerTest method newNodeHasGoodReputation.

@Test
public void newNodeHasGoodReputation() {
    NodeID id = generateNodeID();
    PeerScoringManager manager = createPeerScoringManager();
    Assert.assertTrue(manager.hasGoodReputation(id));
}
Also used : NodeID(co.rsk.net.NodeID) Test(org.junit.Test)

Aggregations

NodeID (co.rsk.net.NodeID)27 Test (org.junit.Test)19 InetAddress (java.net.InetAddress)8 Block (org.ethereum.core.Block)4 RskSystemProperties (co.rsk.config.RskSystemProperties)3 Metrics (co.rsk.net.Metrics)3 Status (co.rsk.net.Status)3 RskMessage (co.rsk.net.eth.RskMessage)3 co.rsk.net.messages (co.rsk.net.messages)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 java.util (java.util)3 ArrayList (java.util.ArrayList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 Executors (java.util.concurrent.Executors)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 CollectionUtils (org.apache.commons.collections4.CollectionUtils)3