mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-15 12:50:47 +02:00
Include network in peer rpc methods (#749)
This commit is contained in:
parent
128a8ac900
commit
c4ae0835f4
6 changed files with 38 additions and 15 deletions
|
|
@ -117,6 +117,7 @@ def test_lookup_squeaks(server_stub, admin_stub, signing_profile_id, saved_squea
|
|||
addresses = [squeak_profile_address]
|
||||
lookup_response = server_stub.LookupSqueaksToDownload(
|
||||
squeak_server_pb2.LookupSqueaksToDownloadRequest(
|
||||
network="simnet",
|
||||
addresses=addresses,
|
||||
min_block=0,
|
||||
max_block=99999999,
|
||||
|
|
@ -134,6 +135,7 @@ def test_lookup_squeaks_empty_result_addresses(server_stub, admin_stub):
|
|||
addresses = [address]
|
||||
lookup_response = server_stub.LookupSqueaksToDownload(
|
||||
squeak_server_pb2.LookupSqueaksToDownloadRequest(
|
||||
network="simnet",
|
||||
addresses=addresses,
|
||||
min_block=0,
|
||||
max_block=99999999,
|
||||
|
|
@ -157,6 +159,7 @@ def test_lookup_squeaks_empty_result_block_ranges(
|
|||
addresses = [squeak_profile_address]
|
||||
lookup_response = server_stub.LookupSqueaksToDownload(
|
||||
squeak_server_pb2.LookupSqueaksToDownloadRequest(
|
||||
network="simnet",
|
||||
addresses=addresses,
|
||||
min_block=99999999,
|
||||
max_block=99999999,
|
||||
|
|
@ -178,6 +181,7 @@ def test_lookup_squeaks_to_upload(server_stub, admin_stub, signing_profile_id, s
|
|||
addresses = [squeak_profile_address]
|
||||
lookup_response = server_stub.LookupSqueaksToUpload(
|
||||
squeak_server_pb2.LookupSqueaksToUploadRequest(
|
||||
network="simnet",
|
||||
addresses=addresses,
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -43,17 +43,21 @@ message DownloadSqueakRequest {
|
|||
}
|
||||
|
||||
message LookupSqueaksToDownloadRequest {
|
||||
/// The bitcoin network
|
||||
string network = 1;
|
||||
/// List of the author addresses
|
||||
repeated string addresses = 1;
|
||||
repeated string addresses = 2;
|
||||
/// Minimum block to look for
|
||||
int32 min_block = 2;
|
||||
int32 min_block = 3;
|
||||
/// Maximum block to look for
|
||||
int32 max_block = 3;
|
||||
int32 max_block = 4;
|
||||
}
|
||||
|
||||
message LookupSqueaksToUploadRequest {
|
||||
/// The bitcoin network
|
||||
string network = 1;
|
||||
/// List of the author addresses
|
||||
repeated string addresses = 1;
|
||||
repeated string addresses = 2;
|
||||
}
|
||||
|
||||
message DownloadOfferRequest {
|
||||
|
|
|
|||
|
|
@ -145,11 +145,7 @@ class SqueakAdminServerHandler(object):
|
|||
squeak_profile = self.squeak_controller.get_squeak_profile(profile_id)
|
||||
if squeak_profile is None:
|
||||
return None
|
||||
logger.info("Got squeak profile with image: {}".format(
|
||||
squeak_profile.profile_image))
|
||||
squeak_profile_msg = squeak_profile_to_message(squeak_profile)
|
||||
logger.info("Got squeak profile msg with image: {}".format(
|
||||
squeak_profile_msg.profile_image))
|
||||
return squeak_admin_pb2.GetSqueakProfileReply(
|
||||
squeak_profile=squeak_profile_msg,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -27,19 +27,25 @@ class PeerClient:
|
|||
yield self
|
||||
self.stub = None
|
||||
|
||||
def lookup_squeaks_to_download(self, addresses: List[str], min_block: int, max_block: int):
|
||||
def lookup_squeaks_to_download(self, network: str, addresses: List[str], min_block: int, max_block: int):
|
||||
request = squeak_server_pb2.LookupSqueaksToDownloadRequest(
|
||||
network=network,
|
||||
addresses=addresses,
|
||||
min_block=min_block,
|
||||
max_block=max_block,
|
||||
)
|
||||
logger.info("Making lookup request: {}".format(
|
||||
request
|
||||
))
|
||||
lookup_response = self.stub.LookupSqueaksToDownload(
|
||||
squeak_server_pb2.LookupSqueaksToDownloadRequest(
|
||||
addresses=addresses,
|
||||
min_block=min_block,
|
||||
max_block=max_block,
|
||||
)
|
||||
request
|
||||
)
|
||||
return lookup_response
|
||||
|
||||
def lookup_squeaks_to_upload(self, addresses: List[str]):
|
||||
def lookup_squeaks_to_upload(self, network: str, addresses: List[str]):
|
||||
lookup_response = self.stub.LookupSqueaksToUpload(
|
||||
squeak_server_pb2.LookupSqueaksToUploadRequest(
|
||||
network=network,
|
||||
addresses=addresses,
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -51,9 +51,12 @@ class SqueakServerHandler(object):
|
|||
)
|
||||
|
||||
def handle_lookup_squeaks_to_download(self, request):
|
||||
network = request.network
|
||||
addresses = request.addresses
|
||||
min_block = request.min_block
|
||||
max_block = request.max_block
|
||||
if network != self.squeak_controller.get_network():
|
||||
raise Exception("Wrong network.")
|
||||
logger.info(
|
||||
"Handle lookup squeaks to download with addresses: {}, min_block: {}, max_block: {}".format(
|
||||
str(addresses), min_block, max_block
|
||||
|
|
@ -68,12 +71,16 @@ class SqueakServerHandler(object):
|
|||
)
|
||||
|
||||
def handle_lookup_squeaks_to_upload(self, request):
|
||||
network = request.network
|
||||
addresses = request.addresses
|
||||
if network != self.squeak_controller.get_network():
|
||||
raise Exception("Wrong network.")
|
||||
logger.info(
|
||||
"Handle lookup squeaks to upload with addresses: {}".format(
|
||||
str(addresses)
|
||||
)
|
||||
)
|
||||
network = self.squeak_controller.get_network()
|
||||
allowed_addresses = self.squeak_controller.lookup_allowed_addresses(
|
||||
addresses)
|
||||
latest_block_height = self.squeak_controller.get_best_block_height()
|
||||
|
|
|
|||
|
|
@ -35,10 +35,13 @@ class PeerConnection:
|
|||
min_block,
|
||||
max_block,
|
||||
):
|
||||
# Get the network
|
||||
network = self.squeak_controller.get_network()
|
||||
# Get list of followed addresses
|
||||
followed_addresses = self.squeak_controller.get_followed_addresses()
|
||||
# Get remote hashes
|
||||
lookup_result = self.peer_client.lookup_squeaks_to_download(
|
||||
network,
|
||||
followed_addresses,
|
||||
min_block,
|
||||
max_block,
|
||||
|
|
@ -76,10 +79,13 @@ class PeerConnection:
|
|||
self._download_offer(hash)
|
||||
|
||||
def upload(self):
|
||||
# Get the network
|
||||
network = self.squeak_controller.get_network()
|
||||
# Get list of sharing addresses.
|
||||
sharing_addresses = self.squeak_controller.get_sharing_addresses()
|
||||
# Get remote hashes
|
||||
lookup_result = self.peer_client.lookup_squeaks_to_upload(
|
||||
network,
|
||||
sharing_addresses,
|
||||
)
|
||||
remote_hashes = lookup_result.hashes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue