Skip to content

Commit

Permalink
test: BIP324: add check for missing garbage terminator detection
Browse files Browse the repository at this point in the history
  • Loading branch information
theStack committed Oct 10, 2023
1 parent 04265ba commit 68c51db
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/functional/p2p_v2_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ def run_test(self):
with self.nodes[0].assert_debug_log("V2 transport error: V1 peer with wrong MessageStart"):
s.sendall(wrong_network_magic_prefix + b"somepayload")

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


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

0 comments on commit 68c51db

Please sign in to comment.