|
5 | 5 | """Test node responses to invalid network messages."""
|
6 | 6 | import asyncio
|
7 | 7 | import struct
|
8 |
| -import sys |
9 | 8 |
|
10 | 9 | from test_framework.messages import (
|
11 | 10 | CBlockHeader,
|
@@ -50,11 +49,6 @@ def run_test(self):
|
50 | 49 | . Test msg header
|
51 | 50 | 0. Send a bunch of large (4MB) messages of an unrecognized type. Check to see
|
52 | 51 | that it isn't an effective DoS against the node.
|
53 |
| -
|
54 |
| - 1. Send an oversized (4MB+) message and check that we're disconnected. |
55 |
| -
|
56 |
| - 2. Send a few messages with an incorrect data size in the header, ensure the |
57 |
| - messages are ignored. |
58 | 52 | """
|
59 | 53 | self.test_magic_bytes()
|
60 | 54 | self.test_checksum()
|
@@ -95,66 +89,6 @@ def run_test(self):
|
95 | 89 | node.p2p.sync_with_ping(timeout=400)
|
96 | 90 | assert node.p2p.is_connected
|
97 | 91 |
|
98 |
| - # |
99 |
| - # 1. |
100 |
| - # |
101 |
| - # Send an oversized message, ensure we're disconnected. |
102 |
| - # |
103 |
| - # Under macOS this test is skipped due to an unexpected error code |
104 |
| - # returned from the closing socket which python/asyncio does not |
105 |
| - # yet know how to handle. |
106 |
| - # |
107 |
| - if sys.platform != 'darwin': |
108 |
| - msg_over_size = msg_unrecognized(str_data="b" * (valid_data_limit + 1)) |
109 |
| - assert len(msg_over_size.serialize()) == (msg_limit + 1) |
110 |
| - |
111 |
| - # An unknown message type (or *any* message type) over |
112 |
| - # MAX_PROTOCOL_MESSAGE_LENGTH should result in a disconnect. |
113 |
| - node.p2p.send_message(msg_over_size) |
114 |
| - node.p2p.wait_for_disconnect(timeout=4) |
115 |
| - |
116 |
| - node.disconnect_p2ps() |
117 |
| - conn = node.add_p2p_connection(P2PDataStore()) |
118 |
| - conn.wait_for_verack() |
119 |
| - else: |
120 |
| - self.log.info("Skipping test p2p_invalid_messages/1 (oversized message) under macOS") |
121 |
| - |
122 |
| - # |
123 |
| - # 2. |
124 |
| - # |
125 |
| - # Send messages with an incorrect data size in the header. |
126 |
| - # |
127 |
| - actual_size = 100 |
128 |
| - msg = msg_unrecognized(str_data="b" * actual_size) |
129 |
| - |
130 |
| - # TODO: handle larger-than cases. I haven't been able to pin down what behavior to expect. |
131 |
| - for wrong_size in (2, 77, 78, 79): |
132 |
| - self.log.info("Sending a message with incorrect size of {}".format(wrong_size)) |
133 |
| - |
134 |
| - # Unmodified message should submit okay. |
135 |
| - node.p2p.send_and_ping(msg) |
136 |
| - |
137 |
| - # A message lying about its data size results in a disconnect when the incorrect |
138 |
| - # data size is less than the actual size. |
139 |
| - # |
140 |
| - # TODO: why does behavior change at 78 bytes? |
141 |
| - # |
142 |
| - node.p2p.send_raw_message(self._tweak_msg_data_size(msg, wrong_size)) |
143 |
| - |
144 |
| - # For some reason unknown to me, we sometimes have to push additional data to the |
145 |
| - # peer in order for it to realize a disconnect. |
146 |
| - try: |
147 |
| - node.p2p.send_message(msg_ping(nonce=123123)) |
148 |
| - except IOError: |
149 |
| - pass |
150 |
| - |
151 |
| - node.p2p.wait_for_disconnect(timeout=10) |
152 |
| - node.disconnect_p2ps() |
153 |
| - node.add_p2p_connection(P2PDataStore()) |
154 |
| - |
155 |
| - # Node is still up. |
156 |
| - conn = node.add_p2p_connection(P2PDataStore()) |
157 |
| - |
158 | 92 | def test_magic_bytes(self):
|
159 | 93 | conn = self.nodes[0].add_p2p_connection(P2PDataStore())
|
160 | 94 |
|
@@ -225,26 +159,6 @@ def test_large_inv(self):
|
225 | 159 | conn.send_and_ping(msg)
|
226 | 160 | self.nodes[0].disconnect_p2ps()
|
227 | 161 |
|
228 |
| - def _tweak_msg_data_size(self, message, wrong_size): |
229 |
| - """ |
230 |
| - Return a raw message based on another message but with an incorrect data size in |
231 |
| - the message header. |
232 |
| - """ |
233 |
| - raw_msg = self.node.p2p.build_message(message) |
234 |
| - |
235 |
| - bad_size_bytes = struct.pack("<I", wrong_size) |
236 |
| - num_header_bytes_before_size = 4 + 12 |
237 |
| - |
238 |
| - # Replace the correct data size in the message with an incorrect one. |
239 |
| - raw_msg_with_wrong_size = ( |
240 |
| - raw_msg[:num_header_bytes_before_size] + |
241 |
| - bad_size_bytes + |
242 |
| - raw_msg[(num_header_bytes_before_size + len(bad_size_bytes)):] |
243 |
| - ) |
244 |
| - assert len(raw_msg) == len(raw_msg_with_wrong_size) |
245 |
| - |
246 |
| - return raw_msg_with_wrong_size |
247 |
| - |
248 | 162 |
|
249 | 163 | if __name__ == '__main__':
|
250 | 164 | InvalidMessagesTest().main()
|
0 commit comments