@@ -46,47 +46,12 @@ def set_test_params(self):
46
46
self .setup_clean_chain = True
47
47
48
48
def run_test (self ):
49
- """
50
- . Test msg header
51
- 0. Send a bunch of large (4MB) messages of an unrecognized type. Check to see
52
- that it isn't an effective DoS against the node.
53
- """
54
49
self .test_magic_bytes ()
55
50
self .test_checksum ()
56
51
self .test_size ()
57
52
self .test_msgtype ()
58
53
self .test_large_inv ()
59
-
60
- node = self .nodes [0 ]
61
- self .node = node
62
- node .add_p2p_connection (P2PDataStore ())
63
- conn2 = node .add_p2p_connection (P2PDataStore ())
64
-
65
-
66
- #
67
- # 0.
68
- #
69
- # Send as large a message as is valid, ensure we aren't disconnected but
70
- # also can't exhaust resources.
71
- #
72
- msg_at_size = msg_unrecognized (str_data = "b" * VALID_DATA_LIMIT )
73
- assert len (msg_at_size .serialize ()) == MSG_LIMIT
74
-
75
- self .log .info ("Sending a bunch of large, junk messages to test memory exhaustion. May take a bit..." )
76
-
77
- # Run a bunch of times to test for memory exhaustion.
78
- for _ in range (80 ):
79
- node .p2p .send_message (msg_at_size )
80
-
81
- # Check that, even though the node is being hammered by nonsense from one
82
- # connection, it can still service other peers in a timely way.
83
- for _ in range (20 ):
84
- conn2 .sync_with_ping (timeout = 2 )
85
-
86
- # Peer 1, despite serving up a bunch of nonsense, should still be connected.
87
- self .log .info ("Waiting for node to drop junk messages." )
88
- node .p2p .sync_with_ping (timeout = 400 )
89
- assert node .p2p .is_connected
54
+ self .test_resource_exhaustion ()
90
55
91
56
def test_magic_bytes (self ):
92
57
conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
@@ -154,6 +119,29 @@ def test_large_inv(self):
154
119
conn .send_and_ping (msg )
155
120
self .nodes [0 ].disconnect_p2ps ()
156
121
122
+ def test_resource_exhaustion (self ):
123
+ conn = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
124
+ conn2 = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
125
+ msg_at_size = msg_unrecognized (str_data = "b" * VALID_DATA_LIMIT )
126
+ assert len (msg_at_size .serialize ()) == MSG_LIMIT
127
+
128
+ self .log .info ("Sending a bunch of large, junk messages to test memory exhaustion. May take a bit..." )
129
+
130
+ # Run a bunch of times to test for memory exhaustion.
131
+ for _ in range (80 ):
132
+ conn .send_message (msg_at_size )
133
+
134
+ # Check that, even though the node is being hammered by nonsense from one
135
+ # connection, it can still service other peers in a timely way.
136
+ for _ in range (20 ):
137
+ conn2 .sync_with_ping (timeout = 2 )
138
+
139
+ # Peer 1, despite being served up a bunch of nonsense, should still be connected.
140
+ self .log .info ("Waiting for node to drop junk messages." )
141
+ conn .sync_with_ping (timeout = 400 )
142
+ assert conn .is_connected
143
+ self .nodes [0 ].disconnect_p2ps ()
144
+
157
145
158
146
if __name__ == '__main__' :
159
147
InvalidMessagesTest ().main ()
0 commit comments