Search in sources :

Example 6 with PeerScoringManager

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);
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DifficultyCalculator(co.rsk.core.DifficultyCalculator) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule)

Example 7 with PeerScoringManager

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);
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) PeerScoringInformation(co.rsk.scoring.PeerScoringInformation) NodeID(co.rsk.net.NodeID) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 8 with PeerScoringManager

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());
    }
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException) Test(org.junit.Test)

Example 9 with PeerScoringManager

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());
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 10 with PeerScoringManager

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]));
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) 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