diff --git a/requirements-itest.txt b/requirements-itest.txt index 814f47b7..9021f3a6 100644 --- a/requirements-itest.txt +++ b/requirements-itest.txt @@ -4,4 +4,4 @@ grpcio grpcio-tools importlib_resources==1.4.0 pytest -squeakpy==0.7.1 +squeakpy==0.7.3 diff --git a/requirements.txt b/requirements.txt index a5337e10..1a3a9c2f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,5 +15,5 @@ psycopg2 pyzmq requests SQLAlchemy -squeakpy==0.7.1 +squeakpy==0.7.3 typed-config diff --git a/setup.py b/setup.py index 2cc21d21..e3b84eeb 100644 --- a/setup.py +++ b/setup.py @@ -103,7 +103,7 @@ setup( include_package_data=True, zip_safe=False, install_requires=[ - 'squeakpy>=0.7.1', + 'squeakpy>=0.7.3', 'importlib_resources', 'argparse', 'googleapis-common-protos', diff --git a/squeaknode/network/peer_message_handler.py b/squeaknode/network/peer_message_handler.py index 61bb2040..8fad3159 100644 --- a/squeaknode/network/peer_message_handler.py +++ b/squeaknode/network/peer_message_handler.py @@ -27,7 +27,9 @@ from squeak.messages import msg_inv from squeak.messages import msg_notfound from squeak.messages import msg_offer from squeak.messages import msg_pong +from squeak.messages import MSG_SECRET_KEY from squeak.messages import msg_secretkey +from squeak.messages import MSG_SQUEAK from squeak.messages import msg_squeak from squeak.net import CInv @@ -200,51 +202,34 @@ class PeerMessageHandler: self.peer.send_msg(inv_msg) def _get_inv_reply(self, inv): - if inv.type == 1: - squeak = self.squeak_controller.get_squeak(inv.hash) - if squeak is not None: - return msg_squeak(squeak=squeak) - if inv.type == 2: - offer_or_secret_key = self.squeak_controller.get_offer_or_secret_key( - inv.hash, - self.peer.remote_address, - ) - if offer_or_secret_key is None: - return None - elif type(offer_or_secret_key) is bytes: - return msg_secretkey( - hashSqk=inv.hash, - secretKey=offer_or_secret_key, - ) - elif type(offer_or_secret_key) is Offer: - return msg_offer( - hashSqk=inv.hash, - nonce=offer_or_secret_key.nonce, - strPaymentInfo=offer_or_secret_key.payment_request.encode( - 'utf-8'), - host=offer_or_secret_key.host.encode('utf-8'), - port=offer_or_secret_key.port, - ) + if inv.type == MSG_SQUEAK: + return self._get_inv_reply_for_squeak(inv) + if inv.type == MSG_SECRET_KEY: + return self._get_inv_reply_for_secret_key(inv) - # price = self.squeak_controller.get_price_for_squeak(inv.hash) - # if price == 0: - # secret_key = self.squeak_controller.get_squeak_secret_key( - # inv.hash) - # if secret_key is not None: - # return msg_secretkey( - # hashSqk=inv.hash, - # secretKey=secret_key, - # ) - # else: - # offer = self.squeak_controller.get_buy_offer( - # squeak_hash=inv.hash, - # peer_address=self.peer.remote_address, - # ) - # if offer is not None: - # return msg_offer( - # hashSqk=inv.hash, - # nonce=offer.nonce, - # strPaymentInfo=offer.payment_request.encode('utf-8'), - # host=offer.host.encode('utf-8'), - # port=offer.port, - # ) + def _get_inv_reply_for_squeak(self, inv): + squeak = self.squeak_controller.get_squeak(inv.hash) + if squeak is not None: + return msg_squeak(squeak=squeak) + + def _get_inv_reply_for_secret_key(self, inv): + resp = self.squeak_controller.get_offer_or_secret_key( + inv.hash, + self.peer.remote_address, + ) + if resp is None: + return None + elif type(resp) is bytes: + return msg_secretkey( + hashSqk=inv.hash, + secretKey=resp, + ) + elif type(resp) is Offer: + return msg_offer( + hashSqk=inv.hash, + nonce=resp.nonce, + strPaymentInfo=resp.payment_request.encode( + 'utf-8'), + host=resp.host.encode('utf-8'), + port=resp.port, + )