forked from LBRYCommunity/lbry-sdk
commit
4255a9916d
14 changed files with 146 additions and 280 deletions
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -1,3 +1,3 @@
|
|||
[submodule "packaging/osx/lbry-osx-app"]
|
||||
path = packaging/osx/lbry-osx-app
|
||||
url = https://github.com/jobevers/lbry-osx-app.git
|
||||
url = https://github.com/lbryio/lbry-osx-app.git
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import logging
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
|
||||
log.setLevel(logging.ERROR)
|
||||
|
||||
version = (0, 2, 5)
|
||||
__version__ = ".".join([str(x) for x in version])
|
||||
|
|
|
@ -3,9 +3,6 @@ Some network wide and also application specific parameters
|
|||
"""
|
||||
|
||||
|
||||
import os
|
||||
|
||||
|
||||
MAX_HANDSHAKE_SIZE = 2**16
|
||||
MAX_REQUEST_SIZE = 2**16
|
||||
MAX_BLOB_REQUEST_SIZE = 2**16
|
||||
|
@ -19,11 +16,17 @@ MIN_VALUABLE_BLOB_INFO_PAYMENT_RATE = .05 # points/1000 infos
|
|||
MIN_VALUABLE_BLOB_HASH_PAYMENT_RATE = .05 # points/1000 infos
|
||||
MAX_CONNECTIONS_PER_STREAM = 5
|
||||
|
||||
KNOWN_DHT_NODES = [('104.236.42.182', 4000)]
|
||||
KNOWN_DHT_NODES = [('104.236.42.182', 4000),
|
||||
('lbryum1.lbry.io', 4444),
|
||||
('lbryum2.lbry.io', 4444),
|
||||
('lbryum3.lbry.io', 4444)]
|
||||
|
||||
POINTTRADER_SERVER = 'http://ec2-54-187-192-68.us-west-2.compute.amazonaws.com:2424'
|
||||
#POINTTRADER_SERVER = 'http://127.0.0.1:2424'
|
||||
|
||||
LOG_FILE_NAME = "lbrynet.log"
|
||||
LOG_POST_URL = "https://lbry.io/log-upload"
|
||||
|
||||
CRYPTSD_FILE_EXTENSION = ".cryptsd"
|
||||
|
||||
API_INTERFACE = "localhost"
|
||||
|
|
|
@ -28,7 +28,7 @@ class LBRYSession(object):
|
|||
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):
|
||||
rate_limiter=None, wallet=None, dht_node_class=node.Node):
|
||||
"""
|
||||
@param blob_data_payment_rate: The default payment rate for blob data
|
||||
|
||||
|
@ -99,7 +99,7 @@ class LBRYSession(object):
|
|||
self.upnp_redirects = []
|
||||
|
||||
self.wallet = wallet
|
||||
|
||||
self.dht_node_class = dht_node_class
|
||||
self.dht_node = None
|
||||
|
||||
self.base_payment_rate_manager = BasePaymentRateManager(blob_data_payment_rate)
|
||||
|
@ -220,8 +220,11 @@ class LBRYSession(object):
|
|||
d.addCallback(match_port, port)
|
||||
ds.append(d)
|
||||
|
||||
self.dht_node = node.Node(udpPort=self.dht_node_port, lbryid=self.lbryid,
|
||||
externalIP=self.external_ip)
|
||||
self.dht_node = self.dht_node_class(
|
||||
udpPort=self.dht_node_port,
|
||||
lbryid=self.lbryid,
|
||||
externalIP=self.external_ip
|
||||
)
|
||||
self.peer_finder = DHTPeerFinder(self.dht_node, self.peer_manager)
|
||||
if self.hash_announcer is None:
|
||||
self.hash_announcer = DHTHashAnnouncer(self.dht_node, self.peer_port)
|
||||
|
@ -269,4 +272,4 @@ class LBRYSession(object):
|
|||
|
||||
d = threads.deferToThread(threaded_unset_upnp)
|
||||
d.addErrback(lambda err: str(err))
|
||||
return d
|
||||
return d
|
||||
|
|
|
@ -18,7 +18,8 @@ from twisted.internet import defer, task
|
|||
|
||||
class LBRYStdinUploader():
|
||||
"""This class reads from standard in, creates a stream, and makes it available on the network."""
|
||||
def __init__(self, peer_port, dht_node_port, known_dht_nodes):
|
||||
def __init__(self, peer_port, dht_node_port, known_dht_nodes,
|
||||
stream_info_manager_class=DBLiveStreamMetadataManager, blob_manager_class=TempBlobManager):
|
||||
"""
|
||||
@param peer_port: the network port on which to listen for peers
|
||||
|
||||
|
@ -28,8 +29,8 @@ class LBRYStdinUploader():
|
|||
"""
|
||||
self.peer_port = peer_port
|
||||
self.lbry_server_port = None
|
||||
self.session = LBRYSession(blob_manager_class=TempBlobManager,
|
||||
stream_info_manager_class=DBLiveStreamMetadataManager,
|
||||
self.session = LBRYSession(blob_manager_class=blob_manager_class,
|
||||
stream_info_manager_class=stream_info_manager_class,
|
||||
dht_node_class=Node, dht_node_port=dht_node_port,
|
||||
known_dht_nodes=known_dht_nodes, peer_port=self.peer_port,
|
||||
use_upnp=False)
|
||||
|
|
|
@ -18,15 +18,17 @@ from twisted.internet import task
|
|||
|
||||
class LBRYStdoutDownloader():
|
||||
"""This class downloads a live stream from the network and outputs it to standard out."""
|
||||
def __init__(self, dht_node_port, known_dht_nodes):
|
||||
def __init__(self, dht_node_port, known_dht_nodes,
|
||||
stream_info_manager_class=DBLiveStreamMetadataManager, blob_manager_class=TempBlobManager):
|
||||
"""
|
||||
@param dht_node_port: the network port on which to listen for DHT node requests
|
||||
|
||||
@param known_dht_nodes: a list of (ip_address, dht_port) which will be used to join the DHT network
|
||||
|
||||
"""
|
||||
self.session = LBRYSession(blob_manager_class=TempBlobManager,
|
||||
stream_info_manager_class=DBLiveStreamMetadataManager,
|
||||
|
||||
self.session = LBRYSession(blob_manager_class=blob_manager_class,
|
||||
stream_info_manager_class=stream_info_manager_class,
|
||||
dht_node_class=Node, dht_node_port=dht_node_port, known_dht_nodes=known_dht_nodes,
|
||||
use_upnp=False)
|
||||
self.payment_rate_manager = BaseLiveStreamPaymentRateManager()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import locale
|
||||
import mimetypes
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -38,7 +39,7 @@ from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher
|
|||
from lbrynet.core.utils import generate_id
|
||||
from lbrynet.lbrynet_console.LBRYSettings import LBRYSettings
|
||||
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, DEFAULT_MAX_SEARCH_RESULTS, KNOWN_DHT_NODES, DEFAULT_MAX_KEY_FEE, \
|
||||
DEFAULT_WALLET, DEFAULT_SEARCH_TIMEOUT, DEFAULT_CACHE_TIME, DEFAULT_UI_BRANCH
|
||||
DEFAULT_WALLET, DEFAULT_SEARCH_TIMEOUT, DEFAULT_CACHE_TIME, DEFAULT_UI_BRANCH, LOG_POST_URL, LOG_FILE_NAME
|
||||
from lbrynet.conf import DEFAULT_TIMEOUT, WALLET_TYPES
|
||||
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob
|
||||
from lbrynet.core.Session import LBRYSession
|
||||
|
@ -46,6 +47,9 @@ from lbrynet.core.PTCWallet import PTCWallet
|
|||
from lbrynet.core.LBRYcrdWallet import LBRYcrdWallet, LBRYumWallet
|
||||
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
|
||||
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
|
||||
from lbryum import LOG_PATH as lbryum_log
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
if sys.platform != "darwin":
|
||||
|
@ -56,20 +60,26 @@ else:
|
|||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
|
||||
|
||||
if os.path.isfile(LOG_FILENAME):
|
||||
f = open(LOG_FILENAME, 'r')
|
||||
PREVIOUS_LOG = len(f.read())
|
||||
f.close()
|
||||
else:
|
||||
PREVIOUS_LOG = 0
|
||||
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
|
||||
handler = logging.handlers.RotatingFileHandler(lbrynet_log, maxBytes=2097152, backupCount=5)
|
||||
log.addHandler(handler)
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
if os.path.isfile(lbryum_log):
|
||||
f = open(lbryum_log, 'r')
|
||||
PREVIOUS_LBRYUM_LOG = len(f.read())
|
||||
f.close()
|
||||
else:
|
||||
PREVIOUS_LBRYUM_LOG = 0
|
||||
if os.path.isfile(lbrynet_log):
|
||||
f = open(lbrynet_log, 'r')
|
||||
PREVIOUS_LBRYNET_LOG = len(f.read())
|
||||
f.close()
|
||||
else:
|
||||
PREVIOUS_LBRYNET_LOG = 0
|
||||
|
||||
INITIALIZING_CODE = 'initializing'
|
||||
LOADING_DB_CODE = 'loading_db'
|
||||
LOADING_WALLET_CODE = 'loading_wallet'
|
||||
|
@ -131,7 +141,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
|
||||
isLeaf = True
|
||||
|
||||
def __init__(self, root, wallet_type=DEFAULT_WALLET):
|
||||
def __init__(self, root, wallet_type=None):
|
||||
jsonrpc.JSONRPC.__init__(self)
|
||||
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
|
||||
|
||||
|
@ -147,7 +157,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
self.ip = None
|
||||
self.wallet_type = wallet_type
|
||||
self.first_run = None
|
||||
self.log_file = LOG_FILENAME
|
||||
self.log_file = lbrynet_log
|
||||
self.current_db_revision = 1
|
||||
self.run_server = True
|
||||
self.session = None
|
||||
|
@ -209,37 +219,34 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
for k in missing_settings.keys():
|
||||
log.info("Adding missing setting: " + k + " with default value: " + str(missing_settings[k]))
|
||||
loaded_settings[k] = missing_settings[k]
|
||||
if loaded_settings['wallet_type'] != self.wallet_type and self.wallet_type:
|
||||
loaded_settings['wallet_type'] = self.wallet_type
|
||||
|
||||
if missing_settings or removed_settings:
|
||||
f = open(self.daemon_conf, "w")
|
||||
f.write(json.dumps(loaded_settings))
|
||||
f.close()
|
||||
log.info("Updated and loaded lbrynet-daemon configuration")
|
||||
else:
|
||||
log.info("Loaded lbrynet-daemon configuration")
|
||||
settings_dict = loaded_settings
|
||||
self.session_settings = loaded_settings
|
||||
else:
|
||||
log.info(
|
||||
"Writing default settings : " + json.dumps(self.default_settings) + " --> " + str(self.daemon_conf))
|
||||
f = open(self.daemon_conf, "w")
|
||||
f.write(json.dumps(self.default_settings))
|
||||
f.close()
|
||||
settings_dict = self.default_settings
|
||||
|
||||
self.session_settings = settings_dict
|
||||
missing_settings = self.default_settings
|
||||
log.info("Writing default settings : " + json.dumps(self.default_settings) + " --> " + str(self.daemon_conf))
|
||||
self.session_settings = self.default_settings
|
||||
|
||||
if 'last_version' in missing_settings.keys():
|
||||
self.session_settings['last_version'] = None
|
||||
|
||||
if self.session_settings['last_version'] != self.default_settings['last_version']:
|
||||
self.session_settings['last_version'] = self.default_settings['last_version']
|
||||
f = open(self.daemon_conf, "w")
|
||||
f.write(json.dumps(self.session_settings))
|
||||
f.close()
|
||||
|
||||
self.first_run_after_update = True
|
||||
log.info("First run after update")
|
||||
if lbrynet_version == '0.2.5':
|
||||
self.session_settings['startup_scripts'].append({'script_name': 'migrateto025', 'run_once': True})
|
||||
|
||||
f = open(self.daemon_conf, "w")
|
||||
f.write(json.dumps(self.session_settings))
|
||||
f.close()
|
||||
|
||||
self.run_on_startup = self.session_settings['run_on_startup']
|
||||
self.data_rate = self.session_settings['data_rate']
|
||||
self.max_key_fee = self.session_settings['max_key_fee']
|
||||
|
@ -250,7 +257,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
self.search_timeout = self.session_settings['search_timeout']
|
||||
self.download_timeout = self.session_settings['download_timeout']
|
||||
self.max_search_results = self.session_settings['max_search_results']
|
||||
self.wallet_type = self.session_settings['wallet_type'] if self.session_settings['wallet_type'] in WALLET_TYPES else wallet_type
|
||||
if self.session_settings['wallet_type'] in WALLET_TYPES and not wallet_type:
|
||||
self.wallet_type = self.session_settings['wallet_type']
|
||||
log.info("Using wallet type %s from config" % self.wallet_type)
|
||||
else:
|
||||
self.wallet_type = wallet_type
|
||||
self.session_settings['wallet_type'] = wallet_type
|
||||
log.info("Using wallet type %s specified from command line" % self.wallet_type)
|
||||
self.delete_blobs_on_remove = self.session_settings['delete_blobs_on_remove']
|
||||
self.peer_port = self.session_settings['peer_port']
|
||||
self.dht_node_port = self.session_settings['dht_node_port']
|
||||
|
@ -410,8 +423,10 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
|
||||
if self.first_run:
|
||||
d = self._upload_log(log_type="first_run")
|
||||
else:
|
||||
elif self.upload_log:
|
||||
d = self._upload_log(exclude_previous=True, log_type="start")
|
||||
else:
|
||||
d = defer.succeed(None)
|
||||
|
||||
if float(self.session.wallet.wallet_balance) == 0.0:
|
||||
d.addCallback(lambda _: self._check_first_run())
|
||||
|
@ -619,25 +634,26 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
|
||||
def _upload_log(self, log_type=None, exclude_previous=False, force=False):
|
||||
if self.upload_log or force:
|
||||
LOG_URL = "https://lbry.io/log-upload"
|
||||
if exclude_previous:
|
||||
f = open(self.log_file, "r")
|
||||
f.seek(PREVIOUS_LOG)
|
||||
log_contents = f.read()
|
||||
f.close()
|
||||
else:
|
||||
f = open(self.log_file, "r")
|
||||
log_contents = f.read()
|
||||
f.close()
|
||||
params = {
|
||||
'date': datetime.utcnow().strftime('%Y%m%d-%H%M%S'),
|
||||
'hash': base58.b58encode(self.lbryid)[:20],
|
||||
'sys': platform.system(),
|
||||
'type': log_type,
|
||||
'log': log_contents
|
||||
}
|
||||
for lm, lp in [('lbrynet', lbrynet_log), ('lbryum', lbryum_log)]:
|
||||
if os.path.isfile(lp):
|
||||
if exclude_previous:
|
||||
f = open(lp, "r")
|
||||
f.seek(PREVIOUS_LBRYNET_LOG if lm == 'lbrynet' else PREVIOUS_LBRYUM_LOG)
|
||||
log_contents = f.read()
|
||||
f.close()
|
||||
else:
|
||||
f = open(lp, "r")
|
||||
log_contents = f.read()
|
||||
f.close()
|
||||
params = {
|
||||
'date': datetime.utcnow().strftime('%Y%m%d-%H%M%S'),
|
||||
'hash': base58.b58encode(self.lbryid)[:20],
|
||||
'sys': platform.system(),
|
||||
'type': "%s-%s" % (lm, log_type) if log_type else lm,
|
||||
'log': log_contents
|
||||
}
|
||||
requests.post(LOG_POST_URL, params)
|
||||
|
||||
requests.post(LOG_URL, params)
|
||||
return defer.succeed(None)
|
||||
else:
|
||||
return defer.succeed(None)
|
||||
|
@ -713,16 +729,22 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
elif k == 'download_timeout':
|
||||
if type(settings['download_timeout']) is int:
|
||||
self.session_settings['download_timeout'] = settings['download_timeout']
|
||||
elif type(settings['download_timeout']) is float:
|
||||
self.session_settings['download_timeout'] = int(settings['download_timeout'])
|
||||
else:
|
||||
return defer.fail()
|
||||
elif k == 'search_timeout':
|
||||
if type(settings['search_timeout']) is float:
|
||||
self.session_settings['search_timeout'] = settings['search_timeout']
|
||||
elif type(settings['search_timeout']) is int:
|
||||
self.session_settings['search_timeout'] = float(settings['search_timeout'])
|
||||
else:
|
||||
return defer.fail()
|
||||
elif k == 'cache_time':
|
||||
if type(settings['cache_time']) is int:
|
||||
self.session_settings['cache_time'] = settings['cache_time']
|
||||
elif type(settings['cache_time']) is float:
|
||||
self.session_settings['cache_time'] = int(settings['cache_time'])
|
||||
else:
|
||||
return defer.fail()
|
||||
self.run_on_startup = self.session_settings['run_on_startup']
|
||||
|
@ -1221,6 +1243,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
d.addCallback(lambda message: {'completed': f.completed, 'file_name': f.file_name,
|
||||
'download_directory': f.download_directory,
|
||||
'download_path': os.path.join(f.download_directory, f.file_name),
|
||||
'mime_type': mimetypes.guess_type(os.path.join(f.download_directory, f.file_name))[0],
|
||||
'key': key,
|
||||
'points_paid': f.points_paid, 'stopped': f.stopped,
|
||||
'stream_hash': f.stream_hash,
|
||||
|
@ -1235,6 +1258,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
d = defer.succeed({'completed': f.completed, 'file_name': f.file_name, 'key': key,
|
||||
'download_directory': f.download_directory,
|
||||
'download_path': os.path.join(f.download_directory, f.file_name),
|
||||
'mime_type': mimetypes.guess_type(os.path.join(f.download_directory, f.file_name))[0],
|
||||
'points_paid': f.points_paid, 'stopped': f.stopped, 'stream_hash': f.stream_hash,
|
||||
'stream_name': f.stream_name, 'suggested_file_name': f.suggested_file_name,
|
||||
'upload_allowed': f.upload_allowed, 'sd_hash': f.sd_hash, 'total_bytes': size,
|
||||
|
@ -1287,16 +1311,15 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
def _run_scripts(self):
|
||||
if len([k for k in self.startup_scripts if 'run_once' in k.keys()]):
|
||||
log.info("Removing one time startup scripts")
|
||||
f = open(self.daemon_conf, "r")
|
||||
initialsettings = json.loads(f.read())
|
||||
f.close()
|
||||
t = [s for s in self.startup_scripts if 'run_once' not in s.keys()]
|
||||
initialsettings['startup_scripts'] = t
|
||||
remaining_scripts = [s for s in self.startup_scripts if 'run_once' not in s.keys()]
|
||||
startup_scripts = self.startup_scripts
|
||||
self.startup_scripts = self.session_settings['startup_scripts'] = remaining_scripts
|
||||
|
||||
f = open(self.daemon_conf, "w")
|
||||
f.write(json.dumps(initialsettings))
|
||||
f.write(json.dumps(self.session_settings))
|
||||
f.close()
|
||||
|
||||
for script in self.startup_scripts:
|
||||
for script in startup_scripts:
|
||||
if script['script_name'] == 'migrateto025':
|
||||
log.info("Running migrator to 0.2.5")
|
||||
from lbrynet.lbrynet_daemon.daemon_scripts.migrateto025 import run as run_migrate
|
||||
|
@ -1482,6 +1505,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
log.info("[" + str(datetime.now()) + "] Set daemon settings to " + json.dumps(self.session_settings))
|
||||
|
||||
d = self._update_settings(p)
|
||||
d.addErrback(lambda err: log.info(err.getTraceback()))
|
||||
d.addCallback(lambda _: _log_settings_change())
|
||||
d.addCallback(lambda _: self._render_response(self.session_settings, OK_CODE))
|
||||
|
||||
|
@ -2145,17 +2169,18 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
#
|
||||
# return d
|
||||
|
||||
def jsonrpc_log(self, message):
|
||||
def jsonrpc_log(self, p):
|
||||
"""
|
||||
Log message
|
||||
|
||||
Args:
|
||||
message: message to be logged
|
||||
'message': message to be logged
|
||||
Returns:
|
||||
True
|
||||
"""
|
||||
|
||||
log.info(message)
|
||||
message = p['message']
|
||||
log.info("API client log request: %s" % message)
|
||||
return self._render_response(True, OK_CODE)
|
||||
|
||||
def jsonrpc_upload_log(self, p=None):
|
||||
|
@ -2172,6 +2197,8 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
if p:
|
||||
if 'name_prefix' in p.keys():
|
||||
log_type = p['name_prefix'] + '_api'
|
||||
elif 'log_type' in p.keys():
|
||||
log_type = p['log_type'] + '_api'
|
||||
else:
|
||||
log_type = None
|
||||
|
||||
|
|
|
@ -6,16 +6,15 @@ import webbrowser
|
|||
import sys
|
||||
import socket
|
||||
import platform
|
||||
|
||||
from appdirs import user_data_dir
|
||||
|
||||
from twisted.web import server
|
||||
from twisted.internet import reactor, defer
|
||||
from jsonrpc.proxy import JSONRPCProxy
|
||||
|
||||
from lbrynet.lbrynet_daemon.LBRYDaemonServer import LBRYDaemonServer
|
||||
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_ADDRESS, API_PORT, \
|
||||
DEFAULT_WALLET, UI_ADDRESS, DEFAULT_UI_BRANCH
|
||||
|
||||
DEFAULT_WALLET, UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
||||
|
||||
if sys.platform != "darwin":
|
||||
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
|
@ -25,13 +24,12 @@ else:
|
|||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
|
||||
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
|
||||
handler = logging.handlers.RotatingFileHandler(lbrynet_log, maxBytes=2097152, backupCount=5)
|
||||
log.addHandler(handler)
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
|
||||
REMOTE_SERVER = "www.google.com"
|
||||
|
||||
|
||||
|
@ -64,7 +62,7 @@ def start():
|
|||
parser.add_argument("--wallet",
|
||||
help="lbrycrd or lbryum, default lbryum",
|
||||
type=str,
|
||||
default=DEFAULT_WALLET)
|
||||
default='')
|
||||
parser.add_argument("--ui",
|
||||
help="path to custom UI folder",
|
||||
default=None)
|
||||
|
@ -96,7 +94,7 @@ def start():
|
|||
|
||||
if not args.logtoconsole and not args.quiet:
|
||||
print "Starting lbrynet-daemon from command line"
|
||||
print "To view activity, view the log file here: " + LOG_FILENAME
|
||||
print "To view activity, view the log file here: " + lbrynet_log
|
||||
print "Web UI is available at http://%s:%i" % (API_INTERFACE, API_PORT)
|
||||
print "JSONRPC API is available at " + API_CONNECTION_STRING
|
||||
print "To quit press ctrl-c or call 'stop' via the API"
|
||||
|
|
|
@ -5,38 +5,28 @@ import json
|
|||
import sys
|
||||
import mimetypes
|
||||
|
||||
from StringIO import StringIO
|
||||
from zipfile import ZipFile
|
||||
from urllib import urlopen
|
||||
from datetime import datetime
|
||||
from appdirs import user_data_dir
|
||||
from twisted.web import server, static, resource
|
||||
from twisted.internet import defer, interfaces, error, reactor, task, threads
|
||||
from twisted.python.failure import Failure
|
||||
from txjsonrpc.web import jsonrpc
|
||||
|
||||
from zope.interface import implements
|
||||
|
||||
from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon
|
||||
from lbrynet.conf import API_CONNECTION_STRING, API_ADDRESS, DEFAULT_WALLET, UI_ADDRESS, DEFAULT_UI_BRANCH
|
||||
from lbrynet.conf import API_CONNECTION_STRING, API_ADDRESS, DEFAULT_WALLET, UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
||||
|
||||
|
||||
if sys.platform != "darwin":
|
||||
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
data_dir = user_data_dir("LBRY")
|
||||
|
||||
if not os.path.isdir(data_dir):
|
||||
os.mkdir(data_dir)
|
||||
version_dir = os.path.join(data_dir, "ui_version_history")
|
||||
if not os.path.isdir(version_dir):
|
||||
os.mkdir(version_dir)
|
||||
|
||||
version_log = logging.getLogger("lbry_version")
|
||||
version_log.addHandler(logging.FileHandler(os.path.join(version_dir, "lbry_version.log")))
|
||||
version_log.setLevel(logging.INFO)
|
||||
lbrynet_log = os.path.join(data_dir, LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
log.addHandler(logging.FileHandler(os.path.join(data_dir, 'lbrynet-daemon.log')))
|
||||
handler = logging.handlers.RotatingFileHandler(lbrynet_log, maxBytes=2097152, backupCount=5)
|
||||
log.addHandler(handler)
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
|
||||
|
@ -198,7 +188,7 @@ class LBRYDaemonServer(object):
|
|||
self.root.putChild(API_ADDRESS, self._api)
|
||||
return defer.succeed(True)
|
||||
|
||||
def start(self, branch=DEFAULT_UI_BRANCH, user_specified=False, branch_specified=False, wallet=DEFAULT_WALLET):
|
||||
d = self._setup_server(self._setup_server(wallet))
|
||||
def start(self, branch=DEFAULT_UI_BRANCH, user_specified=False, branch_specified=False, wallet=None):
|
||||
d = self._setup_server(wallet)
|
||||
d.addCallback(lambda _: self._api.setup(branch, user_specified, branch_specified))
|
||||
return d
|
||||
|
|
|
@ -12,7 +12,7 @@ from lbrynet.core.Error import InvalidStreamInfoError, InsufficientFundsError
|
|||
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
||||
from lbrynet.core.StreamDescriptor import download_sd_blob
|
||||
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloaderFactory
|
||||
from lbrynet.conf import DEFAULT_TIMEOUT
|
||||
from lbrynet.conf import DEFAULT_TIMEOUT, LOG_FILE_NAME
|
||||
|
||||
INITIALIZING_CODE = 'initializing'
|
||||
DOWNLOAD_METADATA_CODE = 'downloading_metadata'
|
||||
|
@ -35,13 +35,12 @@ else:
|
|||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
|
||||
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
|
||||
handler = logging.handlers.RotatingFileHandler(lbrynet_log, maxBytes=2097152, backupCount=5)
|
||||
log.addHandler(handler)
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
|
||||
class GetStream(object):
|
||||
def __init__(self, sd_identifier, session, wallet, lbry_file_manager, max_key_fee, pay_key=True, data_rate=0.5,
|
||||
timeout=DEFAULT_TIMEOUT, download_directory=None, file_name=None):
|
||||
|
|
|
@ -10,6 +10,7 @@ from lbrynet.lbryfilemanager.LBRYFileCreator import create_lbry_file
|
|||
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
|
||||
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
||||
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloader
|
||||
from lbrynet.conf import LOG_FILE_NAME
|
||||
from twisted.internet import threads, defer
|
||||
|
||||
if sys.platform != "darwin":
|
||||
|
@ -20,9 +21,9 @@ else:
|
|||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
|
||||
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
|
||||
handler = logging.handlers.RotatingFileHandler(lbrynet_log, maxBytes=2097152, backupCount=5)
|
||||
log.addHandler(handler)
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
|
|
|
@ -8,31 +8,34 @@ from urllib2 import urlopen
|
|||
from StringIO import StringIO
|
||||
from twisted.web import static
|
||||
from twisted.internet import defer
|
||||
from lbrynet.conf import DEFAULT_UI_BRANCH
|
||||
from lbrynet.conf import DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
||||
from lbrynet import __version__ as lbrynet_version
|
||||
from lbryum.version import ELECTRUM_VERSION as lbryum_version
|
||||
from zipfile import ZipFile
|
||||
from appdirs import user_data_dir
|
||||
|
||||
if sys.platform != "darwin":
|
||||
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
data_dir = user_data_dir("LBRY")
|
||||
log_dir = user_data_dir("LBRY")
|
||||
|
||||
if not os.path.isdir(data_dir):
|
||||
os.mkdir(data_dir)
|
||||
version_dir = os.path.join(data_dir, "ui_version_history")
|
||||
if not os.path.isdir(version_dir):
|
||||
os.mkdir(version_dir)
|
||||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME)
|
||||
log = logging.getLogger(__name__)
|
||||
log.addHandler(logging.FileHandler(os.path.join(data_dir, 'lbrynet-daemon.log')))
|
||||
handler = logging.handlers.RotatingFileHandler(lbrynet_log, maxBytes=2097152, backupCount=5)
|
||||
log.addHandler(handler)
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
|
||||
class LBRYUIManager(object):
|
||||
def __init__(self, root):
|
||||
self.data_dir = user_data_dir("LBRY")
|
||||
if sys.platform != "darwin":
|
||||
self.data_dir = os.path.join(os.path.expanduser("~"), '.lbrynet')
|
||||
else:
|
||||
self.data_dir = user_data_dir("LBRY")
|
||||
|
||||
self.ui_root = os.path.join(self.data_dir, "lbry-ui")
|
||||
self.active_dir = os.path.join(self.ui_root, "active")
|
||||
self.update_dir = os.path.join(self.ui_root, "update")
|
||||
|
@ -41,10 +44,10 @@ class LBRYUIManager(object):
|
|||
os.mkdir(self.data_dir)
|
||||
if not os.path.isdir(self.ui_root):
|
||||
os.mkdir(self.ui_root)
|
||||
if not os.path.isdir(self.ui_root):
|
||||
os.mkdir(self.ui_root)
|
||||
if not os.path.isdir(self.ui_root):
|
||||
os.mkdir(self.ui_root)
|
||||
if not os.path.isdir(self.active_dir):
|
||||
os.mkdir(self.active_dir)
|
||||
if not os.path.isdir(self.update_dir):
|
||||
os.mkdir(self.update_dir)
|
||||
|
||||
self.config = os.path.join(self.ui_root, "active.json")
|
||||
self.update_requires = os.path.join(self.update_dir, "requirements.txt")
|
||||
|
|
|
@ -20,7 +20,6 @@ class migrator(object):
|
|||
return lbry_file.restore()
|
||||
|
||||
r = defer.DeferredList([_restart_lbry_file(lbry_file) for lbry_file in self._api.lbry_file_manager.lbry_files if not lbry_file.txid], consumeErrors=True)
|
||||
r.callback(None)
|
||||
return r
|
||||
|
||||
d = self._api.session.wallet.get_nametrie()
|
||||
|
|
|
@ -1,160 +0,0 @@
|
|||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from appdirs import user_data_dir
|
||||
from datetime import datetime
|
||||
from twisted.internet import defer
|
||||
from twisted.internet.task import LoopingCall
|
||||
|
||||
from lbrynet.core.Error import InvalidStreamInfoError, InsufficientFundsError
|
||||
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
||||
from lbrynet.core.StreamDescriptor import download_sd_blob
|
||||
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloaderFactory
|
||||
from lbrynet.conf import DEFAULT_TIMEOUT
|
||||
|
||||
INITIALIZING_CODE = 'initializing'
|
||||
DOWNLOAD_METADATA_CODE = 'downloading_metadata'
|
||||
DOWNLOAD_TIMEOUT_CODE = 'timeout'
|
||||
DOWNLOAD_RUNNING_CODE = 'running'
|
||||
DOWNLOAD_STOPPED_CODE = 'stopped'
|
||||
STREAM_STAGES = [
|
||||
(INITIALIZING_CODE, 'Initializing...'),
|
||||
(DOWNLOAD_METADATA_CODE, 'Downloading metadata'),
|
||||
(DOWNLOAD_RUNNING_CODE, 'Started stream'),
|
||||
(DOWNLOAD_STOPPED_CODE, 'Paused stream'),
|
||||
(DOWNLOAD_TIMEOUT_CODE, 'Stream timed out')
|
||||
]
|
||||
|
||||
if sys.platform != "darwin":
|
||||
log_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
log_dir = user_data_dir("LBRY")
|
||||
|
||||
if not os.path.isdir(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
|
||||
LOG_FILENAME = os.path.join(log_dir, 'lbrynet-daemon.log')
|
||||
log = logging.getLogger(__name__)
|
||||
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2097152, backupCount=5)
|
||||
log.addHandler(handler)
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
|
||||
class GetStream(object):
|
||||
def __init__(self, sd_identifier, session, wallet, lbry_file_manager, max_key_fee, pay_key=True, data_rate=0.5,
|
||||
timeout=DEFAULT_TIMEOUT, download_directory=None, file_name=None):
|
||||
self.wallet = wallet
|
||||
self.resolved_name = None
|
||||
self.description = None
|
||||
self.key_fee = None
|
||||
self.key_fee_address = None
|
||||
self.data_rate = data_rate
|
||||
self.pay_key = pay_key
|
||||
self.name = None
|
||||
self.file_name = file_name
|
||||
self.session = session
|
||||
self.payment_rate_manager = PaymentRateManager(self.session.base_payment_rate_manager)
|
||||
self.lbry_file_manager = lbry_file_manager
|
||||
self.sd_identifier = sd_identifier
|
||||
self.stream_hash = None
|
||||
self.max_key_fee = max_key_fee
|
||||
self.stream_info = None
|
||||
self.stream_info_manager = None
|
||||
self.d = defer.Deferred(None)
|
||||
self.timeout = timeout
|
||||
self.timeout_counter = 0
|
||||
self.download_directory = download_directory
|
||||
self.download_path = None
|
||||
self.downloader = None
|
||||
self.finished = defer.Deferred()
|
||||
self.checker = LoopingCall(self.check_status)
|
||||
self.code = STREAM_STAGES[0]
|
||||
|
||||
def check_status(self):
|
||||
self.timeout_counter += 1
|
||||
|
||||
if self.download_path:
|
||||
self.checker.stop()
|
||||
self.finished.callback((self.stream_hash, self.download_path))
|
||||
|
||||
elif self.timeout_counter >= self.timeout:
|
||||
log.info("Timeout downloading lbry://" + self.resolved_name + ", " + str(self.stream_info))
|
||||
self.checker.stop()
|
||||
self.d.cancel()
|
||||
self.code = STREAM_STAGES[4]
|
||||
self.finished.callback(False)
|
||||
|
||||
def start(self, stream_info, name):
|
||||
self.resolved_name = name
|
||||
self.stream_info = stream_info
|
||||
if 'stream_hash' in self.stream_info.keys():
|
||||
self.stream_hash = self.stream_info['stream_hash']
|
||||
elif 'sources' in self.stream_info.keys():
|
||||
self.stream_hash = self.stream_info['sources']['lbry_sd_hash']
|
||||
else:
|
||||
raise InvalidStreamInfoError(self.stream_info)
|
||||
if 'description' in self.stream_info.keys():
|
||||
self.description = self.stream_info['description']
|
||||
if 'key_fee' in self.stream_info.keys():
|
||||
self.key_fee = float(self.stream_info['key_fee'])
|
||||
if 'key_fee_address' in self.stream_info.keys():
|
||||
self.key_fee_address = self.stream_info['key_fee_address']
|
||||
else:
|
||||
self.key_fee_address = None
|
||||
else:
|
||||
self.key_fee = None
|
||||
self.key_fee_address = None
|
||||
if self.key_fee > self.max_key_fee:
|
||||
if self.pay_key:
|
||||
log.info("Key fee (" + str(self.key_fee) + ") above limit of " + str(
|
||||
self.max_key_fee) + ", didn't download lbry://" + str(self.resolved_name))
|
||||
return defer.fail(None)
|
||||
else:
|
||||
pass
|
||||
|
||||
def _cause_timeout():
|
||||
self.timeout_counter = self.timeout * 2
|
||||
|
||||
def _set_status(x, status):
|
||||
self.code = next(s for s in STREAM_STAGES if s[0] == status)
|
||||
return x
|
||||
|
||||
self.checker.start(1)
|
||||
|
||||
self.d.addCallback(lambda _: _set_status(None, DOWNLOAD_METADATA_CODE))
|
||||
self.d.addCallback(lambda _: download_sd_blob(self.session, self.stream_hash, self.payment_rate_manager))
|
||||
self.d.addCallback(self.sd_identifier.get_metadata_for_sd_blob)
|
||||
self.d.addCallback(lambda r: _set_status(r, DOWNLOAD_RUNNING_CODE))
|
||||
self.d.addCallback(lambda metadata: (
|
||||
next(factory for factory in metadata.factories if isinstance(factory, ManagedLBRYFileDownloaderFactory)),
|
||||
metadata))
|
||||
self.d.addCallback(lambda (factory, metadata): factory.make_downloader(metadata,
|
||||
[self.data_rate, True],
|
||||
self.payment_rate_manager,
|
||||
download_directory=self.download_directory,
|
||||
file_name=self.file_name))
|
||||
self.d.addCallbacks(self._start_download, lambda _: _cause_timeout())
|
||||
self.d.callback(None)
|
||||
|
||||
return self.finished
|
||||
|
||||
def _start_download(self, downloader):
|
||||
def _pay_key_fee():
|
||||
if self.key_fee is not None and self.key_fee_address is not None:
|
||||
reserved_points = self.wallet.reserve_points(self.key_fee_address, self.key_fee)
|
||||
if reserved_points is None:
|
||||
return defer.fail(InsufficientFundsError())
|
||||
log.info("Key fee: " + str(self.key_fee) + " | " + str(self.key_fee_address))
|
||||
return self.wallet.send_points_to_address(reserved_points, self.key_fee)
|
||||
return defer.succeed(None)
|
||||
|
||||
if self.pay_key:
|
||||
d = _pay_key_fee()
|
||||
else:
|
||||
d = defer.Deferred()
|
||||
self.downloader = downloader
|
||||
self.download_path = os.path.join(downloader.download_directory, downloader.file_name)
|
||||
d.addCallback(lambda _: log.info("[" + str(datetime.now()) + "] Downloading " + str(self.stream_hash) + " --> " + str(self.download_path)))
|
||||
d.addCallback(lambda _: self.downloader.start())
|
Loading…
Reference in a new issue