v29.4-roots.4 · Commit 3: [PATCH 03/37] policy: restore conservative relay and network controls
test/functional/p2p_eviction.py
Before: test/functional/p2p_eviction.py · After: test/functional/p2p_eviction.py
File metadata
index 0d2bdcc429c07ca550af930aec9d2582cfd20d78..5cc552285c7b2aadfb1817312b59bbd525cbf541 100755
Download original patch · Release notes
Diff rows 1–43 of 43. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
test/functional/p2p_eviction.py
CHANGED
|
@@ -122,6 +122,43 @@ class P2PEvict(BitcoinTestFramework):
|
|
|
122
122
|
self.log.debug("{} protected peers: {}".format(len(protected_peers), protected_peers))
|
|
123
123
|
assert evicted_peers[0] not in protected_peers
|
|
124
124
|
|
|
125
|
+
self.log.info("Test that whitebind inbounds get extra eviction power")
|
|
126
|
+
# Allow 10 inbound connections, set whitebind and forceinbound
|
|
127
|
+
self.restart_node(0, extra_args=['-maxconnections=21', '-whitebind=127.0.0.1:30201', '-whitebind=forceinbound@127.0.0.1:30202'])
|
|
128
|
+
self.log.debug("Fill connections with unprivileged peers")
|
|
129
|
+
for i in range(10):
|
|
130
|
+
node.add_p2p_connection(P2PInterface())
|
|
131
|
+
|
|
132
|
+
# Create a peer that expects to be rejected
|
|
133
|
+
# FIXME: "multiprocess, i686, DEBUG" CI task has a reliable timeout issue for v2transport
|
|
134
|
+
class RejectedPeer(P2PInterface):
|
|
135
|
+
def connection_lost(self, exc):
|
|
136
|
+
return
|
|
137
|
+
|
|
138
|
+
allowed_peers = []
|
|
139
|
+
|
|
140
|
+
self.log.debug("Generic inbound gets rejected when full")
|
|
141
|
+
with node.assert_debug_log(["failed to find an eviction candidate - connection dropped (full)"]):
|
|
142
|
+
node.add_p2p_connection(RejectedPeer(), wait_for_verack=False, supports_v2_p2p=False)
|
|
143
|
+
|
|
144
|
+
self.log.debug("Default whitebind inbound gets rejected, even when full")
|
|
145
|
+
with node.assert_debug_log(["failed to find an eviction candidate - connection dropped (full)"]):
|
|
146
|
+
node.add_p2p_connection(RejectedPeer(), wait_for_verack=False, supports_v2_p2p=False, dstport=30201)
|
|
147
|
+
|
|
148
|
+
self.log.debug("ForceInbound whitebind inbound gets connected, even when full")
|
|
149
|
+
allowed_peers.append(node.add_p2p_connection(P2PInterface(), dstport=30202))
|
|
150
|
+
|
|
151
|
+
peerinfo = node.getpeerinfo()
|
|
152
|
+
assert_equal(len(peerinfo), 10)
|
|
153
|
+
for peer in peerinfo:
|
|
154
|
+
if "30202" in peer["addrbind"]:
|
|
155
|
+
assert peer["forced_inbound"]
|
|
156
|
+
else:
|
|
157
|
+
assert not peer["forced_inbound"]
|
|
158
|
+
|
|
159
|
+
self.log.debug("Generic inbound gets rejected when whitebind peer is filling inbound slot")
|
|
160
|
+
with node.assert_debug_log(["failed to find an eviction candidate - connection dropped (full)"]):
|
|
161
|
+
node.add_p2p_connection(RejectedPeer(), supports_v2_p2p=False, wait_for_verack=False)
|
|
125
162
|
|
|
126
163
|
if __name__ == '__main__':
|
|
127
164
|
P2PEvict(__file__).main()
|