Use new peer protocol with multiple addresses in getsqueaks msg (#969)

This commit is contained in:
Jonathan Zernik 2021-08-18 00:26:32 -07:00 committed by GitHub
parent 1363d8c0fc
commit 1243f9da30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 28 deletions

View file

@ -13,5 +13,5 @@ protobuf
psycopg2
requests
SQLAlchemy
squeakpy==0.6.3
squeakpy==0.6.4
typed-config

View file

@ -372,7 +372,7 @@ class SqueakDb:
def lookup_squeaks(
self,
address: str,
addresses: List[str],
min_block: int,
max_block: int,
reply_to_hash: bytes,
@ -380,12 +380,12 @@ class SqueakDb:
) -> List[bytes]:
""" Lookup squeaks. """
logger.info("""Running lookup query with
address: {},
addresses: {},
min_block: {}
max_block: {}
reply_to_hash: {!r}
include_locked: {}""".format(
address,
addresses,
min_block,
max_block,
reply_to_hash,
@ -393,8 +393,8 @@ class SqueakDb:
))
s = select([self.squeaks.c.hash])
if address:
s = s.where(self.squeaks.c.author_address == address)
if addresses:
s = s.where(self.squeaks.c.author_address.in_(addresses))
if min_block:
s = s.where(self.squeaks.c.n_block_height >= min_block)
if max_block:

View file

@ -149,7 +149,7 @@ class PeerMessageHandler:
max_block = interest.nMaxBlockHeight if interest.nMaxBlockHeight != -1 else None
reply_to_hash = interest.hashReplySqk if interest.hashReplySqk != EMPTY_HASH else None
squeak_hashes = self.squeak_controller.lookup_squeaks_for_interest(
address=str(interest.address),
address=[str(address) for address in interest.addresses],
min_block=min_block,
max_block=max_block,
reply_to_hash=reply_to_hash,

View file

@ -545,11 +545,11 @@ class SqueakController:
followed_addresses))
interests = [
CInterested(
address=CSqueakAddress(address),
addresses=[CSqueakAddress(address)
for address in followed_addresses],
nMinBlockHeight=block_range.min_block,
nMaxBlockHeight=block_range.max_block,
)
for address in followed_addresses
]
locator = CSqueakLocator(
vInterested=interests,
@ -602,25 +602,25 @@ class SqueakController:
)
self.broadcast_msg(getsqueaks_msg)
def filter_shared_squeak_locator(self, interests: List[CInterested]):
ret = []
block_range = self.get_block_range()
followed_addresses = self.get_followed_addresses()
for interest in interests:
if str(interest.address) in followed_addresses:
min_block = max(interest.nMinBlockHeight,
block_range.min_block)
max_block = min(interest.nMaxBlockHeight,
block_range.max_block)
if min_block <= max_block:
ret.append(
CInterested(
address=interest.address,
nMinBlockHeight=min_block,
nMaxBlockHeight=max_block,
)
)
return ret
# def filter_shared_squeak_locator(self, interests: List[CInterested]):
# ret = []
# block_range = self.get_block_range()
# followed_addresses = self.get_followed_addresses()
# for interest in interests:
# if str(interest.address) in followed_addresses:
# min_block = max(interest.nMinBlockHeight,
# block_range.min_block)
# max_block = min(interest.nMaxBlockHeight,
# block_range.max_block)
# if min_block <= max_block:
# ret.append(
# CInterested(
# address=interest.address,
# nMinBlockHeight=min_block,
# nMaxBlockHeight=max_block,
# )
# )
# return ret
def broadcast_msg(self, msg: MsgSerializable) -> None:
self.network_manager.broadcast_msg(msg)