use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.
the class SimpleAsyncNode method createNode.
public static SimpleAsyncNode createNode(Blockchain blockchain, SyncConfiguration syncConfiguration) {
final BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
DummyBlockValidationRule blockValidationRule = new DummyBlockValidationRule();
PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
SimpleChannelManager channelManager = new SimpleChannelManager();
SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, peerScoringManager, channelManager, syncConfiguration, blockValidationRule, new DifficultyCalculator(config));
NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, null, peerScoringManager, blockValidationRule);
return new SimpleAsyncNode(handler, syncProcessor, channelManager);
}
use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.
the class Web3ImplScoringTest method getPeerList.
@Test
public void getPeerList() throws UnknownHostException {
NodeID node = generateNodeID();
InetAddress address = generateNonLocalIPAddressV4();
PeerScoringManager peerScoringManager = createPeerScoringManager();
peerScoringManager.recordEvent(node, address, EventType.VALID_BLOCK);
peerScoringManager.recordEvent(node, address, EventType.VALID_TRANSACTION);
peerScoringManager.recordEvent(node, address, EventType.VALID_BLOCK);
Web3Impl web3 = createWeb3(peerScoringManager);
PeerScoringInformation[] result = web3.sco_peerList();
Assert.assertNotNull(result);
Assert.assertEquals(2, result.length);
PeerScoringInformation info = result[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.assertTrue(info.getScore() > 0);
info = result[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.assertTrue(info.getScore() > 0);
}
use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.
the class Web3ImplScoringTest method addBannedAddressWithInvalidMask.
@Test
public void addBannedAddressWithInvalidMask() throws UnknownHostException {
PeerScoringManager peerScoringManager = createPeerScoringManager();
Web3Impl web3 = createWeb3(peerScoringManager);
try {
web3.sco_banAddress("192.168.56.1/a");
Assert.fail();
} catch (JsonRpcInvalidParamException ex) {
Assert.assertEquals("invalid banned address 192.168.56.1/a", ex.getMessage());
}
}
use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.
the class Web3ImplScoringTest method banningLocalIPv4AddressThrowsException.
@Test(expected = JsonRpcInvalidParamException.class)
public void banningLocalIPv4AddressThrowsException() throws UnknownHostException {
PeerScoringManager peerScoringManager = createPeerScoringManager();
Web3Impl web3 = createWeb3(peerScoringManager);
// generate a random local IPv4 address
InetAddress address = generateLocalIPAddressV4();
Assert.assertTrue(peerScoringManager.hasGoodReputation(address));
web3.sco_banAddress(address.getHostAddress());
}
use of co.rsk.scoring.PeerScoringManager in project rskj by rsksmart.
the class Web3ImplScoringTest method getAddressListWithTwoElements.
@Test
public void getAddressListWithTwoElements() {
PeerScoringManager peerScoringManager = createPeerScoringManager();
Web3Impl web3 = createWeb3(peerScoringManager);
web3.sco_banAddress("192.168.56.1");
web3.sco_banAddress("192.168.56.2");
String[] result = web3.sco_bannedAddresses();
Assert.assertNotNull(result);
Assert.assertEquals(2, result.length);
Assert.assertTrue("192.168.56.1".equals(result[0]) || "192.168.56.1".equals(result[1]));
Assert.assertTrue("192.168.56.2".equals(result[0]) || "192.168.56.2".equals(result[1]));
}
Aggregations