Search in sources :

Example 26 with PeerScoringManager

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

the class Web3ImplScoringTest method addAndRemoveBannedAddressUsingIPV4AndMask.

@Test
public void addAndRemoveBannedAddressUsingIPV4AndMask() throws UnknownHostException {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    // generate a random non-local IPv4 address
    InetAddress address = generateNonLocalIPAddressV4();
    Assert.assertTrue(peerScoringManager.hasGoodReputation(address));
    web3.sco_banAddress(address.getHostAddress() + "/8");
    Assert.assertFalse(peerScoringManager.hasGoodReputation(address));
    web3.sco_unbanAddress(address.getHostAddress() + "/8");
    Assert.assertTrue(peerScoringManager.hasGoodReputation(address));
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 27 with PeerScoringManager

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

the class Web3ImplScoringTest method removeBannedAddressWithInvalidMask.

@Test
public void removeBannedAddressWithInvalidMask() throws UnknownHostException {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    try {
        web3.sco_unbanAddress("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 28 with PeerScoringManager

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

the class Web3ImplScoringTest method addAndRemoveBannedAddressUsingIPV6.

@Test
public void addAndRemoveBannedAddressUsingIPV6() throws UnknownHostException {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    InetAddress address = generateIPAddressV6();
    Assert.assertTrue(peerScoringManager.hasGoodReputation(address));
    web3.sco_banAddress(address.getHostAddress());
    Assert.assertFalse(peerScoringManager.hasGoodReputation(address));
    web3.sco_unbanAddress(address.getHostAddress());
    Assert.assertTrue(peerScoringManager.hasGoodReputation(address));
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 29 with PeerScoringManager

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

the class Web3ImplScoringTest method getAddressListWithOneElement.

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

Example 30 with PeerScoringManager

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

the class Web3ImplScoringTest method addAndRemoveBannedAddressUsingIPV4.

@Test
public void addAndRemoveBannedAddressUsingIPV4() throws UnknownHostException {
    PeerScoringManager peerScoringManager = createPeerScoringManager();
    Web3Impl web3 = createWeb3(peerScoringManager);
    // generate a random non-local IPv4 address
    InetAddress address = generateNonLocalIPAddressV4();
    Assert.assertTrue(peerScoringManager.hasGoodReputation(address));
    web3.sco_banAddress(address.getHostAddress());
    Assert.assertFalse(peerScoringManager.hasGoodReputation(address));
    web3.sco_unbanAddress(address.getHostAddress());
    Assert.assertTrue(peerScoringManager.hasGoodReputation(address));
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) InetAddress(java.net.InetAddress) 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