Update squeaklib and use new msg type (#1894)

* Use updated squeaklib with offer msg removed

* Bump squeaklib version and use methods to check if message has offer
This commit is contained in:
Jonathan Zernik 2021-12-25 19:47:07 -08:00 committed by GitHub
parent 427e82959a
commit 0ecb73fac3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 30 deletions

View file

@ -3,4 +3,4 @@ grpcio==1.39.0
grpcio-tools==1.39.0
importlib_resources==1.4.0
pytest==6.2.5
squeaklib==0.8.5
squeaklib==0.9.1

View file

@ -14,5 +14,5 @@ python-bitcoinlib==0.11.0
pyzmq==22.3.0
requests==2.26.0
SQLAlchemy==1.4.25
squeaklib==0.8.5
squeaklib==0.9.1
typed-config==0.2.5

View file

@ -145,8 +145,8 @@ class Connection(object):
self.handle_getdata(msg)
elif msg.command == b'notfound':
self.handle_notfound(msg)
elif msg.command == b'offer':
self.handle_offer(msg)
# elif msg.command == b'offer':
# self.handle_offer(msg)
elif msg.command == b'secretkey':
self.handle_secret_key(msg)
elif msg.command == b'subscribe':
@ -202,24 +202,37 @@ class Connection(object):
if saved_squeak_hash is not None:
self.network_handler.request_offers(saved_squeak_hash)
def handle_offer(self, msg):
offer = Offer(
squeak_hash=msg.hashSqk,
nonce=msg.nonce,
payment_request=msg.strPaymentInfo.decode('utf-8'),
host=msg.host.decode('utf-8'),
port=msg.port,
)
self.network_handler.save_received_offer(
offer,
self.peer.remote_address,
)
# def handle_offer(self, msg):
# offer = Offer(
# squeak_hash=msg.hashSqk,
# nonce=msg.nonce,
# payment_request=msg.strPaymentInfo.decode('utf-8'),
# host=msg.host.decode('utf-8'),
# port=msg.port,
# )
# self.network_handler.save_received_offer(
# offer,
# self.peer.remote_address,
# )
def handle_secret_key(self, msg):
self.network_handler.unlock_squeak(
msg.hashSqk,
msg.secretKey,
)
if msg.has_secret_key():
self.network_handler.unlock_squeak(
msg.hashSqk,
msg.secretKey,
)
elif msg.has_offer():
offer = Offer(
squeak_hash=msg.hashSqk,
nonce=msg.offer.nonce,
payment_request=msg.offer.strPaymentInfo.decode('utf-8'),
host=msg.offer.host.decode('utf-8'),
port=msg.offer.port,
)
self.network_handler.save_received_offer(
offer,
self.peer.remote_address,
)
def handle_subscribe(self, msg):
if msg.protover < 60003:

View file

@ -19,9 +19,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from squeak.messages import msg_offer
from squeak.messages import msg_secretkey
from squeak.messages import MsgSerializable
from squeak.net import COffer
from squeaknode.core.offer import Offer
@ -53,11 +53,14 @@ class OfferReply(SecretKeyReply):
self.offer = offer
def get_msg(self) -> MsgSerializable:
return msg_offer(
hashSqk=self.squeak_hash,
offer = COffer(
nonce=self.offer.nonce,
strPaymentInfo=self.offer.payment_request.encode(
'utf-8'),
host=self.offer.host.encode('utf-8'),
port=self.offer.port,
)
return msg_secretkey(
hashSqk=self.squeak_hash,
offer=offer,
)

View file

@ -20,8 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import pytest
from squeak.messages import msg_offer
from squeak.messages import msg_secretkey
from squeak.net import COffer
from squeaknode.node.secret_key_reply import FreeSecretKeyReply
from squeaknode.node.secret_key_reply import OfferReply
@ -55,11 +55,13 @@ def test_free_secret_key_reply_msg(squeak_hash, secret_key, free_secret_key_repl
def test_offer_reply_msg(squeak_hash, offer, offer_reply):
reply_msg = offer_reply.get_msg()
assert reply_msg == msg_offer(
assert reply_msg == msg_secretkey(
hashSqk=squeak_hash,
nonce=offer.nonce,
strPaymentInfo=offer.payment_request.encode(
'utf-8'),
host=offer.host.encode('utf-8'),
port=offer.port,
offer=COffer(
nonce=offer.nonce,
strPaymentInfo=offer.payment_request.encode(
'utf-8'),
host=offer.host.encode('utf-8'),
port=offer.port,
)
)