Search in sources :

Example 16 with PeerScoringManager

use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.

the class Web3ImplScoringTest method getAddressListWithOneElementUsingMask.

@Test
public void getAddressListWithOneElementUsingMask() {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    web3.sco_banAddress("192.168.56.1/16");
    String[] result = web3.sco_bannedAddresses();
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.length);
    Assert.assertEquals("192.168.56.1/16", result[0]);
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) Test(org.junit.Test)

Example 17 with PeerScoringManager

use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.

the class RskMockFactory method getPeerScoringManager.

public static PeerScoringManager getPeerScoringManager() {
    PeerScoringManager peerScoringManager = mock(PeerScoringManager.class);
    when(peerScoringManager.hasGoodReputation(isA(NodeID.class))).thenReturn(true);
    when(peerScoringManager.getPeerScoring(isA(NodeID.class))).thenReturn(new PeerScoring());
    return peerScoringManager;
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) NodeID(co.rsk.net.NodeID)

Example 18 with PeerScoringManager

use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.

the class RskFactory method getPeerScoringManager.

@Bean
public PeerScoringManager getPeerScoringManager(SystemProperties config) {
    int nnodes = config.scoringNumberOfNodes();
    long nodePunishmentDuration = config.scoringNodesPunishmentDuration();
    int nodePunishmentIncrement = config.scoringNodesPunishmentIncrement();
    long nodePunhishmentMaximumDuration = config.scoringNodesPunishmentMaximumDuration();
    long addressPunishmentDuration = config.scoringAddressesPunishmentDuration();
    int addressPunishmentIncrement = config.scoringAddressesPunishmentIncrement();
    long addressPunishmentMaximunDuration = config.scoringAddressesPunishmentMaximumDuration();
    return new PeerScoringManager(nnodes, new PunishmentParameters(nodePunishmentDuration, nodePunishmentIncrement, nodePunhishmentMaximumDuration), new PunishmentParameters(addressPunishmentDuration, addressPunishmentIncrement, addressPunishmentMaximunDuration));
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) PunishmentParameters(co.rsk.scoring.PunishmentParameters) Bean(org.springframework.context.annotation.Bean)

Example 19 with PeerScoringManager

use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.

the class NodeMessageHandlerTest method postBlockMessageTwice.

@Test
public void postBlockMessageTwice() throws InterruptedException, UnknownHostException {
    MessageChannel sender = new SimpleMessageChannel();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, scoring, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    Block block = BlockChainBuilder.ofSize(1, true).getBestBlock();
    Message message = new BlockMessage(block);
    processor.postMessage(sender, message);
    processor.postMessage(sender, message);
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.REPEATED_MESSAGE));
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 20 with PeerScoringManager

use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.

the class NodeMessageHandlerTest method processMissingPoWBlockMessageUsingProcessor.

@Test
public void processMissingPoWBlockMessageUsingProcessor() throws UnknownHostException {
    SimpleMessageChannel sender = new SimpleMessageChannel();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, scoring, new DummyBlockValidationRule());
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block = blockGenerator.getGenesisBlock();
    for (int i = 0; i < 50; i++) {
        block = blockGenerator.createChildBlock(block);
    }
    Message message = new BlockMessage(block);
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(1, sbp.getBlocks().size());
    Assert.assertFalse(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_BLOCK));
    Assert.assertEquals(0, pscoring.getEventCounter(EventType.INVALID_BLOCK));
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

PeerScoringManager (co.rsk.scoring.PeerScoringManager)31 Test (org.junit.Test)26 InetAddress (java.net.InetAddress)11 PeerScoring (co.rsk.scoring.PeerScoring)10 SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)9 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)9 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)7 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)4 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)4 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)3 TxHandler (co.rsk.net.handler.TxHandler)3 SimpleTransactionPool (co.rsk.net.simples.SimpleTransactionPool)3 NodeID (co.rsk.net.NodeID)2 PeerScoringInformation (co.rsk.scoring.PeerScoringInformation)2 JsonRpcInvalidParamException (org.ethereum.rpc.exception.JsonRpcInvalidParamException)2 DifficultyCalculator (co.rsk.core.DifficultyCalculator)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 TxHandlerImpl (co.rsk.net.handler.TxHandlerImpl)1 PunishmentParameters (co.rsk.scoring.PunishmentParameters)1 World (co.rsk.test.World)1