From 29ebdc44c9dacbf09ebbc0b9d3a5128d470809dd Mon Sep 17 00:00:00 2001 From: TheKysek Date: Sun, 16 Oct 2016 13:14:32 +0200 Subject: [PATCH] Unify types of exceptions raised during message parsing --- src/message.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/message.py b/src/message.py index 2030b4e..a4ddbd5 100644 --- a/src/message.py +++ b/src/message.py @@ -127,8 +127,8 @@ class Version(object): payload = payload[user_agent_length:] - # Assume it is stream 1 - assert payload == b'\x01\x01' + if payload != b'\x01\x01': + raise ValueError('message not for stream 1') return cls(host, port, protocol_version, services, nonce, user_agent) @@ -158,7 +158,8 @@ class Inv(object): vectors.add(payload[:32]) payload = payload[32:] - assert vector_count == len(vectors) + if vector_count != len(vectors): + raise ValueError('malformed Inv message, wrong vector_count') return cls(vectors) @@ -188,6 +189,9 @@ class GetData(object): vectors.add(payload[:32]) payload = payload[32:] + if vector_count != len(vectors): + raise ValueError('malformed GetData message, wrong vector_count') + return cls(vectors)