Skip to content

Commit 3bb51c2

Browse files
committed
test: BIP324: add check for missing garbage terminator detection
1 parent 04265ba commit 3bb51c2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/functional/p2p_v2_transport.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ def run_test(self):
148148
with self.nodes[0].assert_debug_log("V2 transport error: V1 peer with wrong MessageStart"):
149149
s.sendall(wrong_network_magic_prefix + b"somepayload")
150150

151+
# Check detection of missing garbage terminator (hits after fixed amount of data if terminator never matches garbage)
152+
MAX_KEY_GARB_AND_GARBTERM_LEN = 64 + 4095 + 16
153+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
154+
num_peers = len(self.nodes[0].getpeerinfo())
155+
s.connect(("127.0.0.1", p2p_port(0)))
156+
self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == num_peers + 1)
157+
s.sendall(b'\x00' * (MAX_KEY_GARB_AND_GARBTERM_LEN - 1))
158+
self.wait_until(lambda: self.nodes[0].getpeerinfo()[-1]["bytesrecv"] == MAX_KEY_GARB_AND_GARBTERM_LEN - 1)
159+
with self.nodes[0].assert_debug_log("V2 transport error: missing garbage terminator"):
160+
s.sendall(b'\x00') # send out last byte
161+
# should disconnect immediately
162+
self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == num_peers)
163+
151164

152165
if __name__ == '__main__':
153166
V2TransportTest().main()

0 commit comments

Comments
 (0)