mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-13 12:33:25 +02:00
Implement download squeaks rpc (#1168)
* Implement download squeaks rpc * Handle replyto hash in download squeaks method
This commit is contained in:
parent
21b82bc9a8
commit
408ec42340
5 changed files with 92 additions and 40 deletions
|
|
@ -38,6 +38,7 @@ from tests.util import delete_profile
|
|||
from tests.util import delete_squeak
|
||||
from tests.util import download_offers
|
||||
from tests.util import download_squeak
|
||||
from tests.util import download_squeaks
|
||||
from tests.util import download_squeaks_for_address
|
||||
from tests.util import get_connected_peer
|
||||
from tests.util import get_connected_peers
|
||||
|
|
@ -881,43 +882,39 @@ def test_connect_peer(admin_stub, other_admin_stub):
|
|||
print(item)
|
||||
assert len(item) == 0
|
||||
|
||||
# TODO: Re-enable after DownloadSqueaks RPC method supports params.
|
||||
# def test_get_squeak_by_lookup(
|
||||
# admin_stub,
|
||||
# other_admin_stub,
|
||||
# connected_tcp_peer_id,
|
||||
# lightning_client,
|
||||
# signing_profile_id,
|
||||
# saved_squeak_hash,
|
||||
# ):
|
||||
# # Get the squeak profile
|
||||
# squeak_profile = get_squeak_profile(admin_stub, signing_profile_id)
|
||||
# squeak_profile_address = squeak_profile.address
|
||||
# squeak_profile_name = squeak_profile.profile_name
|
||||
|
||||
# # Add the contact profile to the other server and set the profile to be following
|
||||
# contact_profile_id = create_contact_profile(
|
||||
# other_admin_stub, squeak_profile_name, squeak_profile_address)
|
||||
# other_admin_stub.SetSqueakProfileFollowing(
|
||||
# squeak_admin_pb2.SetSqueakProfileFollowingRequest(
|
||||
# profile_id=contact_profile_id,
|
||||
# following=True,
|
||||
# )
|
||||
# )
|
||||
def test_get_squeak_by_lookup(
|
||||
admin_stub,
|
||||
other_admin_stub,
|
||||
connected_tcp_peer_id,
|
||||
lightning_client,
|
||||
signing_profile_id,
|
||||
saved_squeak_hash,
|
||||
):
|
||||
# Get the squeak profile
|
||||
squeak_profile = get_squeak_profile(admin_stub, signing_profile_id)
|
||||
squeak_profile_address = squeak_profile.address
|
||||
squeak_profile.profile_name
|
||||
|
||||
# # Get the squeak display item
|
||||
# squeak_display_entry = get_squeak_display(
|
||||
# other_admin_stub, saved_squeak_hash)
|
||||
# assert squeak_display_entry is None
|
||||
# Get the squeak display item
|
||||
squeak_display_entry = get_squeak_display(
|
||||
other_admin_stub, saved_squeak_hash)
|
||||
assert squeak_display_entry is None
|
||||
|
||||
# # Sync squeaks
|
||||
# download_squeaks(other_admin_stub)
|
||||
# time.sleep(5)
|
||||
# Sync squeaks
|
||||
download_squeaks(
|
||||
other_admin_stub,
|
||||
[squeak_profile_address],
|
||||
-1,
|
||||
-1,
|
||||
None,
|
||||
)
|
||||
time.sleep(5)
|
||||
|
||||
# # Get the squeak display item
|
||||
# squeak_display_entry = get_squeak_display(
|
||||
# other_admin_stub, saved_squeak_hash)
|
||||
# assert squeak_display_entry.squeak_hash == saved_squeak_hash
|
||||
# Get the squeak display item
|
||||
squeak_display_entry = get_squeak_display(
|
||||
other_admin_stub, saved_squeak_hash)
|
||||
assert squeak_display_entry.squeak_hash == saved_squeak_hash
|
||||
|
||||
|
||||
def test_subscribe_squeaks(
|
||||
|
|
|
|||
|
|
@ -242,9 +242,14 @@ def download_squeak(node_stub, squeak_hash):
|
|||
)
|
||||
|
||||
|
||||
def download_squeaks(node_stub):
|
||||
def download_squeaks(node_stub, addresses, min_block, max_block, reply_to):
|
||||
node_stub.DownloadSqueaks(
|
||||
squeak_admin_pb2.DownloadSqueaksRequest(),
|
||||
squeak_admin_pb2.DownloadSqueaksRequest(
|
||||
addreses=addresses,
|
||||
min_block_height=min_block,
|
||||
max_block_height=max_block,
|
||||
replyto_squeak_hash=reply_to,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -736,6 +736,17 @@ message OfferDisplayEntry {
|
|||
}
|
||||
|
||||
message DownloadSqueaksRequest {
|
||||
/// The interested addresses
|
||||
repeated string addreses = 1;
|
||||
|
||||
/// Minimum block height
|
||||
int32 min_block_height = 2;
|
||||
|
||||
/// Maximum block height
|
||||
int32 max_block_height = 3;
|
||||
|
||||
/// The hash replied to
|
||||
string replyto_squeak_hash = 4;
|
||||
}
|
||||
|
||||
message DownloadSqueaksReply {
|
||||
|
|
|
|||
|
|
@ -531,8 +531,27 @@ class SqueakAdminServerHandler(object):
|
|||
)
|
||||
|
||||
def handle_download_squeaks(self, request):
|
||||
logger.info("Handle download squeaks")
|
||||
self.squeak_controller.download_squeaks()
|
||||
addresses = request.addreses
|
||||
min_block = request.min_block_height
|
||||
max_block = request.max_block_height
|
||||
replyto_hash = request.replyto_squeak_hash
|
||||
logger.info("""Handle download squeaks for
|
||||
addreses: {}
|
||||
min_block: {}
|
||||
max_block: {}
|
||||
replyto_hash: {}
|
||||
""".format(
|
||||
addresses,
|
||||
min_block,
|
||||
max_block,
|
||||
replyto_hash,
|
||||
))
|
||||
self.squeak_controller.download_squeaks(
|
||||
addresses,
|
||||
min_block,
|
||||
max_block,
|
||||
replyto_hash,
|
||||
)
|
||||
return squeak_admin_pb2.DownloadSqueaksReply()
|
||||
|
||||
def handle_download_squeak(self, request):
|
||||
|
|
|
|||
|
|
@ -580,9 +580,29 @@ class SqueakController:
|
|||
vInterested=interests,
|
||||
)
|
||||
|
||||
def download_squeaks(self):
|
||||
# TODO: Don't use get interested locator, instead use params from request.
|
||||
locator = self.get_interested_locator()
|
||||
def download_squeaks(
|
||||
self,
|
||||
addresses: List[str],
|
||||
min_block: int,
|
||||
max_block: int,
|
||||
replyto_hash: Optional[bytes],
|
||||
):
|
||||
interest = CInterested(
|
||||
addresses=[CSqueakAddress(address)
|
||||
for address in addresses],
|
||||
nMinBlockHeight=min_block,
|
||||
nMaxBlockHeight=max_block,
|
||||
replyto_squeak_hash=replyto_hash,
|
||||
) if replyto_hash else CInterested(
|
||||
addresses=[CSqueakAddress(address)
|
||||
for address in addresses],
|
||||
nMinBlockHeight=min_block,
|
||||
nMaxBlockHeight=max_block,
|
||||
)
|
||||
self.temporary_interest_manager.add_range_interest(10, interest)
|
||||
locator = CSqueakLocator(
|
||||
vInterested=[interest],
|
||||
)
|
||||
getsqueaks_msg = msg_getsqueaks(
|
||||
locator=locator,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue