From e30ea50ef47f1198a6c5217a432a513d74242917 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 15 Feb 2018 16:49:00 -0500 Subject: [PATCH] more --- lbrynet/core/HashAnnouncer.py | 18 ----------------- lbrynet/core/PeerFinder.py | 19 ------------------ lbrynet/core/Session.py | 8 +++----- lbrynet/core/SinglePeerDownloader.py | 5 +++-- lbrynet/dht/hashannouncer.py | 22 ++++++++++++++++++++- lbrynet/dht/peerfinder.py | 18 ++++++++++++++++- lbrynet/tests/unit/core/test_BlobManager.py | 2 +- scripts/download_blob_from_peer.py | 2 +- scripts/encrypt_blob.py | 3 +-- scripts/reseed_file.py | 4 ++-- 10 files changed, 49 insertions(+), 52 deletions(-) delete mode 100644 lbrynet/core/HashAnnouncer.py delete mode 100644 lbrynet/core/PeerFinder.py diff --git a/lbrynet/core/HashAnnouncer.py b/lbrynet/core/HashAnnouncer.py deleted file mode 100644 index 5453eed15..000000000 --- a/lbrynet/core/HashAnnouncer.py +++ /dev/null @@ -1,18 +0,0 @@ -class DummyHashAnnouncer(object): - def __init__(self, *args): - pass - - def run_manage_loop(self): - pass - - def stop(self): - pass - - def add_supplier(self, *args): - pass - - def hash_queue_size(self): - return 0 - - def immediate_announce(self, *args): - pass diff --git a/lbrynet/core/PeerFinder.py b/lbrynet/core/PeerFinder.py deleted file mode 100644 index 3f2339de2..000000000 --- a/lbrynet/core/PeerFinder.py +++ /dev/null @@ -1,19 +0,0 @@ -from twisted.internet import defer - - -class DummyPeerFinder(object): - """This class finds peers which have announced to the DHT that they have certain blobs""" - def __init__(self): - pass - - def run_manage_loop(self): - pass - - def stop(self): - pass - - def find_peers_for_blob(self, blob_hash): - return defer.succeed([]) - - def get_most_popular_hashes(self, num_to_return): - return [] diff --git a/lbrynet/core/Session.py b/lbrynet/core/Session.py index cb82161bc..288a7d7d8 100644 --- a/lbrynet/core/Session.py +++ b/lbrynet/core/Session.py @@ -2,11 +2,9 @@ import logging import miniupnpc from twisted.internet import threads, defer from lbrynet.core.BlobManager import DiskBlobManager -from lbrynet.dht import node, peerfinder, peermanager +from lbrynet.dht import node, peerfinder, peermanager, hashannouncer from lbrynet.database.storage import SQLiteStorage from lbrynet.core.RateLimiter import RateLimiter -from lbrynet.core.HashAnnouncer import DummyHashAnnouncer -from lbrynet.dht.hashannouncer import DHTHashAnnouncer from lbrynet.core.utils import generate_id from lbrynet.core.PaymentRateManager import BasePaymentRateManager, NegotiatedPaymentRateManager from lbrynet.core.BlobAvailability import BlobAvailabilityTracker @@ -162,7 +160,7 @@ class Session(object): else: if self.hash_announcer is None and self.peer_port is not None: log.warning("The server has no way to advertise its available blobs.") - self.hash_announcer = DummyHashAnnouncer() + self.hash_announcer = hashannouncer.DummyHashAnnouncer() d.addCallback(lambda _: self._setup_other_components()) return d @@ -296,7 +294,7 @@ class Session(object): ) self.peer_finder = peerfinder.DHTPeerFinder(self.dht_node, self.peer_manager) if self.hash_announcer is None: - self.hash_announcer = DHTHashAnnouncer(self.dht_node, self.peer_port) + self.hash_announcer = hashannouncer.DHTHashAnnouncer(self.dht_node, self.peer_port) self.dht_node.startNetwork() diff --git a/lbrynet/core/SinglePeerDownloader.py b/lbrynet/core/SinglePeerDownloader.py index 85ade1bb6..9073e980b 100644 --- a/lbrynet/core/SinglePeerDownloader.py +++ b/lbrynet/core/SinglePeerDownloader.py @@ -6,13 +6,14 @@ from twisted.internet import defer, threads, reactor from lbrynet.blob import BlobFile from lbrynet.core.BlobManager import DiskBlobManager -from lbrynet.core.HashAnnouncer import DummyHashAnnouncer from lbrynet.core.RateLimiter import DummyRateLimiter from lbrynet.core.PaymentRateManager import OnlyFreePaymentsManager -from lbrynet.core.PeerFinder import DummyPeerFinder from lbrynet.core.client.BlobRequester import BlobRequester from lbrynet.core.client.StandaloneBlobDownloader import StandaloneBlobDownloader from lbrynet.core.client.ConnectionManager import ConnectionManager +from lbrynet.dht.hashannouncer import DummyHashAnnouncer +from lbrynet.dht.peerfinder import DummyPeerFinder + log = logging.getLogger(__name__) diff --git a/lbrynet/dht/hashannouncer.py b/lbrynet/dht/hashannouncer.py index d029f1f15..baf7a0667 100644 --- a/lbrynet/dht/hashannouncer.py +++ b/lbrynet/dht/hashannouncer.py @@ -10,7 +10,27 @@ from lbrynet.core import utils log = logging.getLogger(__name__) -class DHTHashAnnouncer(object): +class DummyHashAnnouncer(object): + def __init__(self): + pass + + def run_manage_loop(self): + pass + + def stop(self): + pass + + def add_supplier(self, supplier): + pass + + def hash_queue_size(self): + return 0 + + def immediate_announce(self, blob_hashes): + pass + + +class DHTHashAnnouncer(DummyHashAnnouncer): ANNOUNCE_CHECK_INTERVAL = 60 CONCURRENT_ANNOUNCERS = 5 diff --git a/lbrynet/dht/peerfinder.py b/lbrynet/dht/peerfinder.py index b4f94097d..9e4dd167d 100644 --- a/lbrynet/dht/peerfinder.py +++ b/lbrynet/dht/peerfinder.py @@ -10,7 +10,23 @@ from lbrynet.core.utils import short_hash log = logging.getLogger(__name__) -class DHTPeerFinder(object): +class DummyPeerFinder(object): + """This class finds peers which have announced to the DHT that they have certain blobs""" + + def run_manage_loop(self): + pass + + def stop(self): + pass + + def find_peers_for_blob(self, blob_hash): + return defer.succeed([]) + + def get_most_popular_hashes(self, num_to_return): + return [] + + +class DHTPeerFinder(DummyPeerFinder): """This class finds peers which have announced to the DHT that they have certain blobs""" implements(IPeerFinder) diff --git a/lbrynet/tests/unit/core/test_BlobManager.py b/lbrynet/tests/unit/core/test_BlobManager.py index 3f513f623..5bc118f92 100644 --- a/lbrynet/tests/unit/core/test_BlobManager.py +++ b/lbrynet/tests/unit/core/test_BlobManager.py @@ -8,7 +8,7 @@ from twisted.internet import defer, threads from lbrynet.tests.util import random_lbry_hash from lbrynet.core.BlobManager import DiskBlobManager -from lbrynet.core.HashAnnouncer import DummyHashAnnouncer +from lbrynet.dht.hashannouncer import DummyHashAnnouncer from lbrynet.database.storage import SQLiteStorage from lbrynet.core.Peer import Peer from lbrynet import conf diff --git a/scripts/download_blob_from_peer.py b/scripts/download_blob_from_peer.py index c5263d29d..dc688956d 100644 --- a/scripts/download_blob_from_peer.py +++ b/scripts/download_blob_from_peer.py @@ -14,7 +14,7 @@ from lbrynet.core import log_support, Wallet, Peer from lbrynet.core.SinglePeerDownloader import SinglePeerDownloader from lbrynet.core.StreamDescriptor import BlobStreamDescriptorReader from lbrynet.core.BlobManager import DiskBlobManager -from lbrynet.core.HashAnnouncer import DummyHashAnnouncer +from lbrynet.dht.hashannouncer import DummyHashAnnouncer log = logging.getLogger() diff --git a/scripts/encrypt_blob.py b/scripts/encrypt_blob.py index 3d3552f48..2b83dce3e 100644 --- a/scripts/encrypt_blob.py +++ b/scripts/encrypt_blob.py @@ -5,12 +5,11 @@ import sys from twisted.internet import defer from twisted.internet import reactor -from twisted.protocols import basic from twisted.web.client import FileBodyProducer from lbrynet import conf from lbrynet.core import log_support -from lbrynet.core.HashAnnouncer import DummyHashAnnouncer +from lbrynet.dht.hashannouncer import DummyHashAnnouncer from lbrynet.core.BlobManager import DiskBlobManager from lbrynet.cryptstream.CryptStreamCreator import CryptStreamCreator diff --git a/scripts/reseed_file.py b/scripts/reseed_file.py index 108ff2f00..0068ce5c8 100644 --- a/scripts/reseed_file.py +++ b/scripts/reseed_file.py @@ -17,7 +17,7 @@ from twisted.protocols import basic from lbrynet import conf from lbrynet.core import BlobManager -from lbrynet.core import HashAnnouncer +from lbrynet.dht import hashannouncer from lbrynet.core import log_support from lbrynet.cryptstream import CryptStreamCreator @@ -52,7 +52,7 @@ def reseed_file(input_file, sd_blob): sd_blob = SdBlob.new_instance(sd_blob) db_dir = conf.settings['data_dir'] blobfile_dir = os.path.join(db_dir, "blobfiles") - announcer = HashAnnouncer.DummyHashAnnouncer() + announcer = hashannouncer.DummyHashAnnouncer() blob_manager = BlobManager.DiskBlobManager(announcer, blobfile_dir, db_dir) yield blob_manager.setup() creator = CryptStreamCreator.CryptStreamCreator(