fix whitespace and long-lines

This commit is contained in:
Job Evers-Meltzer 2016-11-03 14:22:16 -05:00
parent 693fef1964
commit 10cb20d08f
3 changed files with 93 additions and 58 deletions

View file

@ -18,60 +18,87 @@ log = logging.getLogger(__name__)
class Session(object): class Session(object):
"""This class manages all important services common to any application that uses the network: """This class manages all important services common to any application that uses the network.
the hash announcer, which informs other peers that this peer is associated with some hash. Usually,
this means this peer has a blob identified by the hash in question, but it can be used for other the hash announcer, which informs other peers that this peer is
purposes. associated with some hash. Usually, this means this peer has a
the peer finder, which finds peers that are associated with some hash. blob identified by the hash in question, but it can be used for
the blob manager, which keeps track of which blobs have been downloaded and provides access to them, other purposes.
the rate limiter, which attempts to ensure download and upload rates stay below a set maximum,
and upnp, which opens holes in compatible firewalls so that remote peers can connect to this peer.""" the peer finder, which finds peers that are associated with some
def __init__(self, blob_data_payment_rate, db_dir=None, lbryid=None, peer_manager=None, dht_node_port=None, hash.
known_dht_nodes=None, peer_finder=None, hash_announcer=None, blob_dir=None, blob_manager=None,
peer_port=None, use_upnp=True, rate_limiter=None, wallet=None, dht_node_class=node.Node, the blob manager, which keeps track of which blobs have been
blob_tracker_class=None, payment_rate_manager_class=None, is_generous=True): downloaded and provides access to them,
the rate limiter, which attempts to ensure download and upload
rates stay below a set maximum
upnp, which opens holes in compatible firewalls so that remote
peers can connect to this peer.
""" """
@param blob_data_payment_rate: The default payment rate for blob data def __init__(self, blob_data_payment_rate, db_dir=None,
lbryid=None, peer_manager=None, dht_node_port=None,
known_dht_nodes=None, peer_finder=None,
hash_announcer=None, blob_dir=None,
blob_manager=None, peer_port=None, use_upnp=True,
rate_limiter=None, wallet=None,
dht_node_class=node.Node, blob_tracker_class=None,
payment_rate_manager_class=None, is_generous=True):
"""@param blob_data_payment_rate: The default payment rate for blob data
@param db_dir: The directory in which levelDB files should be stored @param db_dir: The directory in which levelDB files should be stored
@param lbryid: The unique ID of this node @param lbryid: The unique ID of this node
@param peer_manager: An object which keeps track of all known peers. If None, a PeerManager will be created @param peer_manager: An object which keeps track of all known
peers. If None, a PeerManager will be created
@param dht_node_port: The port on which the dht node should listen for incoming connections @param dht_node_port: The port on which the dht node should
listen for incoming connections
@param known_dht_nodes: A list of nodes which the dht node should use to bootstrap into the dht @param known_dht_nodes: A list of nodes which the dht node
should use to bootstrap into the dht
@param peer_finder: An object which is used to look up peers that are associated with some hash. If None, @param peer_finder: An object which is used to look up peers
a DHTPeerFinder will be used, which looks for peers in the distributed hash table. that are associated with some hash. If None, a
DHTPeerFinder will be used, which looks for peers in the
distributed hash table.
@param hash_announcer: An object which announces to other peers that this peer is associated with some hash. @param hash_announcer: An object which announces to other
If None, and peer_port is not None, a DHTHashAnnouncer will be used. If None and peers that this peer is associated with some hash. If
peer_port is None, a DummyHashAnnouncer will be used, which will not actually announce None, and peer_port is not None, a DHTHashAnnouncer will
anything. be used. If None and peer_port is None, a
DummyHashAnnouncer will be used, which will not actually
announce anything.
@param blob_dir: The directory in which blobs will be stored. If None and blob_manager is None, blobs will @param blob_dir: The directory in which blobs will be
be stored in memory only. stored. If None and blob_manager is None, blobs will be
stored in memory only.
@param blob_manager: An object which keeps track of downloaded blobs and provides access to them. If None, @param blob_manager: An object which keeps track of downloaded
and blob_dir is not None, a DiskBlobManager will be used, with the given blob_dir. blobs and provides access to them. If None, and blob_dir
If None and blob_dir is None, a TempBlobManager will be used, which stores blobs in is not None, a DiskBlobManager will be used, with the
memory only. given blob_dir. If None and blob_dir is None, a
TempBlobManager will be used, which stores blobs in memory
only.
@param peer_port: The port on which other peers should connect to this peer @param peer_port: The port on which other peers should connect
to this peer
@param use_upnp: Whether or not to try to open a hole in the firewall so that outside peers can connect to @param use_upnp: Whether or not to try to open a hole in the
this peer's peer_port and dht_node_port firewall so that outside peers can connect to this peer's
peer_port and dht_node_port
@param rate_limiter: An object which keeps track of the amount of data transferred to and from this peer, @param rate_limiter: An object which keeps track of the amount
and can limit that rate if desired of data transferred to and from this peer, and can limit
that rate if desired
@param wallet: An object which will be used to keep track of expected payments and which will pay peers. @param wallet: An object which will be used to keep track of
If None, a wallet which uses the Point Trader system will be used, which is meant for testing expected payments and which will pay peers. If None, a
only wallet which uses the Point Trader system will be used,
which is meant for testing only
@return:
""" """
self.db_dir = db_dir self.db_dir = db_dir
@ -178,7 +205,9 @@ class Session(object):
self.external_ip = external_ip self.external_ip = external_ip
if self.peer_port is not None: if self.peer_port is not None:
if u.getspecificportmapping(self.peer_port, 'TCP') is None: if u.getspecificportmapping(self.peer_port, 'TCP') is None:
u.addportmapping(self.peer_port, 'TCP', u.lanaddr, self.peer_port, 'LBRY peer port', '') u.addportmapping(
self.peer_port, 'TCP', u.lanaddr, self.peer_port,
'LBRY peer port', '')
self.upnp_redirects.append((self.peer_port, 'TCP')) self.upnp_redirects.append((self.peer_port, 'TCP'))
log.info("Set UPnP redirect for TCP port %d", self.peer_port) log.info("Set UPnP redirect for TCP port %d", self.peer_port)
else: else:
@ -187,16 +216,23 @@ class Session(object):
self.upnp_redirects.append((self.peer_port, 'TCP')) self.upnp_redirects.append((self.peer_port, 'TCP'))
if self.dht_node_port is not None: if self.dht_node_port is not None:
if u.getspecificportmapping(self.dht_node_port, 'UDP') is None: if u.getspecificportmapping(self.dht_node_port, 'UDP') is None:
u.addportmapping(self.dht_node_port, 'UDP', u.lanaddr, self.dht_node_port, 'LBRY DHT port', '') u.addportmapping(
self.dht_node_port, 'UDP', u.lanaddr, self.dht_node_port,
'LBRY DHT port', '')
self.upnp_redirects.append((self.dht_node_port, 'UDP')) self.upnp_redirects.append((self.dht_node_port, 'UDP'))
log.info("Set UPnP redirect for UPD port %d", self.dht_node_port) log.info("Set UPnP redirect for UPD port %d", self.dht_node_port)
else: else:
# TODO: check that the existing redirect was put up by an old lbrynet session before grabbing it # TODO: check that the existing redirect was
# if such a disconnected redirect exists, then upnp won't work unless the redirect is appended # put up by an old lbrynet session before
# or is torn down and set back up. a bad shutdown of lbrynet could leave such a redirect up # grabbing it if such a disconnected redirect
# and cause problems on the next start. # exists, then upnp won't work unless the
# this could be problematic if a previous lbrynet session didn't make the redirect, and it was # redirect is appended or is torn down and set
# made by another application # back up. a bad shutdown of lbrynet could
# leave such a redirect up and cause problems
# on the next start. this could be
# problematic if a previous lbrynet session
# didn't make the redirect, and it was made by
# another application
log.warning("UPnP redirect already set for UDP port %d", self.dht_node_port) log.warning("UPnP redirect already set for UDP port %d", self.dht_node_port)
self.upnp_redirects.append((self.dht_node_port, 'UDP')) self.upnp_redirects.append((self.dht_node_port, 'UDP'))
return True return True
@ -271,7 +307,8 @@ class Session(object):
self.peer_finder, self.peer_finder,
self.dht_node) self.dht_node)
if self.payment_rate_manager is None: if self.payment_rate_manager is None:
self.payment_rate_manager = self.payment_rate_manager_class(self.base_payment_rate_manager, self.payment_rate_manager = self.payment_rate_manager_class(
self.base_payment_rate_manager,
self.blob_tracker, self.blob_tracker,
self.is_generous) self.is_generous)
@ -294,7 +331,9 @@ class Session(object):
u.selectigd() u.selectigd()
for port, protocol in self.upnp_redirects: for port, protocol in self.upnp_redirects:
if u.getspecificportmapping(port, protocol) is None: if u.getspecificportmapping(port, protocol) is None:
log.warning("UPnP redirect for %s %d was removed by something else.", protocol, port) log.warning(
"UPnP redirect for %s %d was removed by something else.",
protocol, port)
else: else:
u.deleteportmapping(port, protocol) u.deleteportmapping(port, protocol)
log.info("Removed UPnP redirect for %s %d.", protocol, port) log.info("Removed UPnP redirect for %s %d.", protocol, port)
@ -307,5 +346,3 @@ class Session(object):
def _subfailure(self, err): def _subfailure(self, err):
log.error(err.getTraceback()) log.error(err.getTraceback())
return err.value return err.value

View file

@ -769,14 +769,11 @@ class Daemon(AuthJSONRPCServer):
d = self.lbry_file_metadata_manager.setup() d = self.lbry_file_metadata_manager.setup()
def set_lbry_file_manager(): def set_lbry_file_manager():
self.lbry_file_manager = EncryptedFileManager(self.session, self.lbry_file_manager = EncryptedFileManager(
self.lbry_file_metadata_manager, self.session, self.lbry_file_metadata_manager,
self.sd_identifier, self.sd_identifier, download_directory=self.download_directory)
download_directory=self.download_directory)
return self.lbry_file_manager.setup() return self.lbry_file_manager.setup()
d.addCallback(lambda _: set_lbry_file_manager()) d.addCallback(lambda _: set_lbry_file_manager())
return d return d
def _get_analytics(self): def _get_analytics(self):

View file

@ -29,6 +29,7 @@ from lbrynet.core import utils
if platform.mac_ver()[0] >= "10.10": if platform.mac_ver()[0] >= "10.10":
from LBRYNotify import LBRYNotify from LBRYNotify import LBRYNotify
log = logging.getLogger(__name__) log = logging.getLogger(__name__)