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]);
}
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;
}
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));
}
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));
}
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));
}
Aggregations