mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-15 12:50:47 +02:00
Fix upload single squeak method and improve loggin (#644)
This commit is contained in:
parent
5ffd1c04eb
commit
c832f2515a
1 changed files with 17 additions and 14 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import logging
|
||||
from contextlib import contextmanager
|
||||
|
||||
from squeak.core import CSqueak
|
||||
|
||||
from squeaknode.core.util import get_hash
|
||||
from squeaknode.network.peer_client import PeerClient
|
||||
from squeaknode.sync.util import parse_buy_offer
|
||||
|
||||
|
|
@ -53,9 +56,6 @@ class PeerSyncController:
|
|||
# if self.peer_connection.stopped():
|
||||
# return
|
||||
self._download_squeak(hash)
|
||||
logger.info("Downloaded squeak {} from peer {}".format(
|
||||
hash.hex(), self.peer
|
||||
))
|
||||
|
||||
# Get local hashes of locked squeaks that don't have an offer from this peer.
|
||||
locked_hashes = self._get_locked_hashes(
|
||||
|
|
@ -68,9 +68,6 @@ class PeerSyncController:
|
|||
# if self.peer_connection.stopped():
|
||||
# return
|
||||
self._download_offer(hash)
|
||||
logger.info("Downloaded offer for squeak {} from peer {}".format(
|
||||
hash.hex(), self.peer
|
||||
))
|
||||
|
||||
def upload(
|
||||
self,
|
||||
|
|
@ -104,10 +101,8 @@ class PeerSyncController:
|
|||
for hash in hashes_to_upload:
|
||||
# if self.peer_connection.stopped():
|
||||
# return
|
||||
self._upload_squeak(hash)
|
||||
logger.info("Uploaded squeak {} to peer {}".format(
|
||||
hash.hex(), self.peer
|
||||
))
|
||||
squeak = self._get_local_squeak(hash)
|
||||
self._upload_squeak(squeak)
|
||||
|
||||
def download_single_squeak(self, squeak_hash: bytes):
|
||||
# Download squeak if not already present.
|
||||
|
|
@ -121,7 +116,7 @@ class PeerSyncController:
|
|||
self._download_offer(squeak_hash)
|
||||
|
||||
def upload_single_squeak(self, squeak_hash: bytes):
|
||||
# Download squeak if not already present.
|
||||
# Upload the squeak if it exists locally.
|
||||
local_squeak = self._get_local_squeak(squeak_hash)
|
||||
if local_squeak and local_squeak.HasDecryptionKey():
|
||||
self._upload_squeak(local_squeak)
|
||||
|
|
@ -161,7 +156,7 @@ class PeerSyncController:
|
|||
def _get_remote_hashes(self, addresses, min_block, max_block):
|
||||
return self.peer_client.lookup_squeaks(addresses, min_block, max_block)
|
||||
|
||||
def _save_squeak(self, squeak):
|
||||
def _save_squeak(self, squeak: CSqueak):
|
||||
self.squeak_controller.save_downloaded_squeak(squeak)
|
||||
|
||||
def _get_saved_offer(self, squeak_hash: bytes):
|
||||
|
|
@ -174,16 +169,24 @@ class PeerSyncController:
|
|||
def _download_squeak(self, squeak_hash: bytes):
|
||||
squeak = self.peer_client.get_squeak(squeak_hash)
|
||||
self._save_squeak(squeak)
|
||||
logger.info("Downloaded squeak {} from peer {}".format(
|
||||
squeak_hash.hex(), self.peer
|
||||
))
|
||||
|
||||
def _download_offer(self, squeak_hash: bytes):
|
||||
self.get_offer(squeak_hash)
|
||||
logger.info("Downloaded offer for squeak {} from peer {}".format(
|
||||
squeak_hash.hex(), self.peer
|
||||
))
|
||||
|
||||
def _get_local_squeak(self, squeak_hash: bytes):
|
||||
return self.squeak_controller.get_squeak(squeak_hash)
|
||||
|
||||
def _upload_squeak(self, squeak_hash: bytes):
|
||||
squeak = self._get_local_squeak(squeak_hash)
|
||||
def _upload_squeak(self, squeak: CSqueak):
|
||||
self.peer_client.post_squeak(squeak)
|
||||
logger.info("Uploaded squeak {} to peer {}".format(
|
||||
get_hash(squeak).hex(), self.peer
|
||||
))
|
||||
|
||||
def _download_offer_msg(self, squeak_hash: bytes):
|
||||
return self.peer_client.buy_squeak(squeak_hash)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue