mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 17:54:19 +02:00
Merge #20852: net: allow CSubNet of non-IP networks
39b43298d9test: add test for banning of non-IP addresses (Vasil Dimov)94d335da7fnet: allow CSubNet of non-IP networks (Vasil Dimov) Pull request description: Allow creation of valid `CSubNet` objects of non-IP networks and only match the single address they were created from (like /32 for IPv4 or /128 for IPv6). This fixes a deficiency in `CConnman::DisconnectNode(const CNetAddr& addr)` and in `BanMan` which assume that creating a subnet from any address using the `CSubNet(CNetAddr)` constructor would later match that address only. Before this change a non-IP subnet would be invalid and would not match any address. ACKs for top commit: jonatack: Code review re-ACK39b43298d9per `git diff 5e95ce6 39b4329`; only change since last review is improvements to the functional test; verified the test fails on master @616eace0where expected (`assert(self.is_banned(node, tor_addr))` fails and unban unfails) laanwj: code review ACK39b43298d9Tree-SHA512: 3239b26d0f2fa2d1388b4fdbc1d05ce4ac1980be699c6ec46049409baefcb2006b1e72b889871e2210e897f6725c48e873f68457eea7e6e4958ab4f959d20297
This commit is contained in:
@@ -15,6 +15,9 @@ class SetBanTests(BitcoinTestFramework):
|
||||
self.setup_clean_chain = True
|
||||
self.extra_args = [[],[]]
|
||||
|
||||
def is_banned(self, node, addr):
|
||||
return any(e['address'] == addr for e in node.listbanned())
|
||||
|
||||
def run_test(self):
|
||||
# Node 0 connects to Node 1, check that the noban permission is not granted
|
||||
self.connect_nodes(0, 1)
|
||||
@@ -42,5 +45,18 @@ class SetBanTests(BitcoinTestFramework):
|
||||
peerinfo = self.nodes[1].getpeerinfo()[0]
|
||||
assert(not 'noban' in peerinfo['permissions'])
|
||||
|
||||
self.log.info("Test that a non-IP address can be banned/unbanned")
|
||||
node = self.nodes[1]
|
||||
tor_addr = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"
|
||||
ip_addr = "1.2.3.4"
|
||||
assert(not self.is_banned(node, tor_addr))
|
||||
assert(not self.is_banned(node, ip_addr))
|
||||
node.setban(tor_addr, "add")
|
||||
assert(self.is_banned(node, tor_addr))
|
||||
assert(not self.is_banned(node, ip_addr))
|
||||
node.setban(tor_addr, "remove")
|
||||
assert(not self.is_banned(self.nodes[1], tor_addr))
|
||||
assert(not self.is_banned(node, ip_addr))
|
||||
|
||||
if __name__ == '__main__':
|
||||
SetBanTests().main()
|
||||
|
||||
Reference in New Issue
Block a user