|
|
@ -50,26 +50,26 @@ BOOST_AUTO_TEST_CASE(DoS_banning) |
|
|
|
CAddress addr1(ip(0xa0b0c001), NODE_NONE); |
|
|
|
CAddress addr1(ip(0xa0b0c001), NODE_NONE); |
|
|
|
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 0, 0, CAddress(), "", true); |
|
|
|
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 0, 0, CAddress(), "", true); |
|
|
|
dummyNode1.SetSendVersion(PROTOCOL_VERSION); |
|
|
|
dummyNode1.SetSendVersion(PROTOCOL_VERSION); |
|
|
|
GetNodeSignals().InitializeNode(&dummyNode1, connman); |
|
|
|
peerLogic->InitializeNode(&dummyNode1, connman); |
|
|
|
dummyNode1.nVersion = 1; |
|
|
|
dummyNode1.nVersion = 1; |
|
|
|
dummyNode1.fSuccessfullyConnected = true; |
|
|
|
dummyNode1.fSuccessfullyConnected = true; |
|
|
|
Misbehaving(dummyNode1.GetId(), 100); // Should get banned
|
|
|
|
Misbehaving(dummyNode1.GetId(), 100); // Should get banned
|
|
|
|
SendMessages(&dummyNode1, connman, interruptDummy); |
|
|
|
peerLogic->SendMessages(&dummyNode1, connman, interruptDummy); |
|
|
|
BOOST_CHECK(connman->IsBanned(addr1)); |
|
|
|
BOOST_CHECK(connman->IsBanned(addr1)); |
|
|
|
BOOST_CHECK(!connman->IsBanned(ip(0xa0b0c001|0x0000ff00))); // Different IP, not banned
|
|
|
|
BOOST_CHECK(!connman->IsBanned(ip(0xa0b0c001|0x0000ff00))); // Different IP, not banned
|
|
|
|
|
|
|
|
|
|
|
|
CAddress addr2(ip(0xa0b0c002), NODE_NONE); |
|
|
|
CAddress addr2(ip(0xa0b0c002), NODE_NONE); |
|
|
|
CNode dummyNode2(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr2, 1, 1, CAddress(), "", true); |
|
|
|
CNode dummyNode2(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr2, 1, 1, CAddress(), "", true); |
|
|
|
dummyNode2.SetSendVersion(PROTOCOL_VERSION); |
|
|
|
dummyNode2.SetSendVersion(PROTOCOL_VERSION); |
|
|
|
GetNodeSignals().InitializeNode(&dummyNode2, connman); |
|
|
|
peerLogic->InitializeNode(&dummyNode2, connman); |
|
|
|
dummyNode2.nVersion = 1; |
|
|
|
dummyNode2.nVersion = 1; |
|
|
|
dummyNode2.fSuccessfullyConnected = true; |
|
|
|
dummyNode2.fSuccessfullyConnected = true; |
|
|
|
Misbehaving(dummyNode2.GetId(), 50); |
|
|
|
Misbehaving(dummyNode2.GetId(), 50); |
|
|
|
SendMessages(&dummyNode2, connman, interruptDummy); |
|
|
|
peerLogic->SendMessages(&dummyNode2, connman, interruptDummy); |
|
|
|
BOOST_CHECK(!connman->IsBanned(addr2)); // 2 not banned yet...
|
|
|
|
BOOST_CHECK(!connman->IsBanned(addr2)); // 2 not banned yet...
|
|
|
|
BOOST_CHECK(connman->IsBanned(addr1)); // ... but 1 still should be
|
|
|
|
BOOST_CHECK(connman->IsBanned(addr1)); // ... but 1 still should be
|
|
|
|
Misbehaving(dummyNode2.GetId(), 50); |
|
|
|
Misbehaving(dummyNode2.GetId(), 50); |
|
|
|
SendMessages(&dummyNode2, connman, interruptDummy); |
|
|
|
peerLogic->SendMessages(&dummyNode2, connman, interruptDummy); |
|
|
|
BOOST_CHECK(connman->IsBanned(addr2)); |
|
|
|
BOOST_CHECK(connman->IsBanned(addr2)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -82,17 +82,17 @@ BOOST_AUTO_TEST_CASE(DoS_banscore) |
|
|
|
CAddress addr1(ip(0xa0b0c001), NODE_NONE); |
|
|
|
CAddress addr1(ip(0xa0b0c001), NODE_NONE); |
|
|
|
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 3, 1, CAddress(), "", true); |
|
|
|
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 3, 1, CAddress(), "", true); |
|
|
|
dummyNode1.SetSendVersion(PROTOCOL_VERSION); |
|
|
|
dummyNode1.SetSendVersion(PROTOCOL_VERSION); |
|
|
|
GetNodeSignals().InitializeNode(&dummyNode1, connman); |
|
|
|
peerLogic->InitializeNode(&dummyNode1, connman); |
|
|
|
dummyNode1.nVersion = 1; |
|
|
|
dummyNode1.nVersion = 1; |
|
|
|
dummyNode1.fSuccessfullyConnected = true; |
|
|
|
dummyNode1.fSuccessfullyConnected = true; |
|
|
|
Misbehaving(dummyNode1.GetId(), 100); |
|
|
|
Misbehaving(dummyNode1.GetId(), 100); |
|
|
|
SendMessages(&dummyNode1, connman, interruptDummy); |
|
|
|
peerLogic->SendMessages(&dummyNode1, connman, interruptDummy); |
|
|
|
BOOST_CHECK(!connman->IsBanned(addr1)); |
|
|
|
BOOST_CHECK(!connman->IsBanned(addr1)); |
|
|
|
Misbehaving(dummyNode1.GetId(), 10); |
|
|
|
Misbehaving(dummyNode1.GetId(), 10); |
|
|
|
SendMessages(&dummyNode1, connman, interruptDummy); |
|
|
|
peerLogic->SendMessages(&dummyNode1, connman, interruptDummy); |
|
|
|
BOOST_CHECK(!connman->IsBanned(addr1)); |
|
|
|
BOOST_CHECK(!connman->IsBanned(addr1)); |
|
|
|
Misbehaving(dummyNode1.GetId(), 1); |
|
|
|
Misbehaving(dummyNode1.GetId(), 1); |
|
|
|
SendMessages(&dummyNode1, connman, interruptDummy); |
|
|
|
peerLogic->SendMessages(&dummyNode1, connman, interruptDummy); |
|
|
|
BOOST_CHECK(connman->IsBanned(addr1)); |
|
|
|
BOOST_CHECK(connman->IsBanned(addr1)); |
|
|
|
gArgs.ForceSetArg("-banscore", std::to_string(DEFAULT_BANSCORE_THRESHOLD)); |
|
|
|
gArgs.ForceSetArg("-banscore", std::to_string(DEFAULT_BANSCORE_THRESHOLD)); |
|
|
|
} |
|
|
|
} |
|
|
@ -108,12 +108,12 @@ BOOST_AUTO_TEST_CASE(DoS_bantime) |
|
|
|
CAddress addr(ip(0xa0b0c001), NODE_NONE); |
|
|
|
CAddress addr(ip(0xa0b0c001), NODE_NONE); |
|
|
|
CNode dummyNode(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr, 4, 4, CAddress(), "", true); |
|
|
|
CNode dummyNode(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr, 4, 4, CAddress(), "", true); |
|
|
|
dummyNode.SetSendVersion(PROTOCOL_VERSION); |
|
|
|
dummyNode.SetSendVersion(PROTOCOL_VERSION); |
|
|
|
GetNodeSignals().InitializeNode(&dummyNode, connman); |
|
|
|
peerLogic->InitializeNode(&dummyNode, connman); |
|
|
|
dummyNode.nVersion = 1; |
|
|
|
dummyNode.nVersion = 1; |
|
|
|
dummyNode.fSuccessfullyConnected = true; |
|
|
|
dummyNode.fSuccessfullyConnected = true; |
|
|
|
|
|
|
|
|
|
|
|
Misbehaving(dummyNode.GetId(), 100); |
|
|
|
Misbehaving(dummyNode.GetId(), 100); |
|
|
|
SendMessages(&dummyNode, connman, interruptDummy); |
|
|
|
peerLogic->SendMessages(&dummyNode, connman, interruptDummy); |
|
|
|
BOOST_CHECK(connman->IsBanned(addr)); |
|
|
|
BOOST_CHECK(connman->IsBanned(addr)); |
|
|
|
|
|
|
|
|
|
|
|
SetMockTime(nStartTime+60*60); |
|
|
|
SetMockTime(nStartTime+60*60); |
|
|
|