forked from LBRYCommunity/lbry-sdk
version function, ui version tracking, blocks behind blockchain during startup, cleaner set_vars
-adds version() function, which can be called after the daemon is running and returns lbrynet, lbryum, and lbry ui version information. -daemon_status now returns how far behind its behind the blockchain when in the loading_wallet phase of startup -cleans up set_vars by moving to init
This commit is contained in:
parent
aa8c362cb8
commit
31fa974379
3 changed files with 130 additions and 106 deletions
|
@ -902,6 +902,7 @@ class LBRYumWallet(LBRYWallet):
|
|||
self._start_check = None
|
||||
self._catch_up_check = None
|
||||
self._caught_up_counter = 0
|
||||
self.blocks_behind_alert = 0
|
||||
|
||||
def _start(self):
|
||||
|
||||
|
@ -996,6 +997,7 @@ class LBRYumWallet(LBRYWallet):
|
|||
if self._caught_up_counter == 0:
|
||||
alert.info('Catching up to the blockchain...showing blocks left...')
|
||||
if self._caught_up_counter % 30 == 0:
|
||||
self.blocks_behind_alert = remote_height - local_height
|
||||
alert.info('%d...', (remote_height - local_height))
|
||||
self._caught_up_counter += 1
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ from decimal import Decimal
|
|||
from appdirs import user_data_dir
|
||||
from urllib2 import urlopen
|
||||
|
||||
from lbrynet import __version__
|
||||
from lbrynet import __version__ as lbrynet_version
|
||||
from lbryum.version import ELECTRUM_VERSION as lbryum_version
|
||||
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
||||
from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory
|
||||
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||
|
@ -65,7 +66,6 @@ STARTUP_STAGES = [
|
|||
('initializing', 'Initializing...'),
|
||||
('loading_db', 'Loading databases...'),
|
||||
('loading_wallet', 'Catching up with blockchain... %s'),
|
||||
('loading_session', 'Starting session'),
|
||||
('loading_file_manager', 'Setting up file manager'),
|
||||
('loading_server', 'Starting lbrynet'),
|
||||
('started', 'Started lbrynet')
|
||||
|
@ -88,8 +88,92 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
"""
|
||||
LBRYnet daemon, a jsonrpc interface to lbry functions
|
||||
"""
|
||||
|
||||
isLeaf = True
|
||||
|
||||
def __init__(self, wallet_type, check_for_updates, ui_version_info):
|
||||
jsonrpc.JSONRPC.__init__(self)
|
||||
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
|
||||
|
||||
self.log_file = LOG_FILENAME
|
||||
self.fetcher = None
|
||||
self.current_db_revision = 1
|
||||
self.run_server = True
|
||||
self.session = None
|
||||
self.known_dht_nodes = KNOWN_DHT_NODES
|
||||
if sys.platform != "darwin":
|
||||
self.db_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
self.db_dir = user_data_dir("LBRY")
|
||||
self.blobfile_dir = os.path.join(self.db_dir, "blobfiles")
|
||||
self.peer_port = 3333
|
||||
self.dht_node_port = 4444
|
||||
self.first_run = None
|
||||
if os.name == "nt":
|
||||
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
||||
self.download_directory = get_path(FOLDERID.Downloads, UserHandle.current)
|
||||
self.wallet_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbrycrd")
|
||||
elif sys.platform == "darwin":
|
||||
self.download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
|
||||
if wallet_type == "lbrycrd":
|
||||
self.wallet_dir = user_data_dir("lbrycrd")
|
||||
else:
|
||||
self.wallet_dir = user_data_dir("LBRY")
|
||||
else:
|
||||
self.download_directory = os.getcwd()
|
||||
if wallet_type == "lbrycrd":
|
||||
self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
|
||||
else:
|
||||
self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbryum")
|
||||
self.daemon_conf = os.path.join(self.db_dir, 'daemon_settings.json')
|
||||
self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
|
||||
self.wallet_user = None
|
||||
self.wallet_password = None
|
||||
self.sd_identifier = StreamDescriptorIdentifier()
|
||||
self.stream_info_manager = TempLBRYFileMetadataManager()
|
||||
self.wallet_rpc_port = 8332
|
||||
self.downloads = []
|
||||
self.stream_frames = []
|
||||
self.default_blob_data_payment_rate = MIN_BLOB_DATA_PAYMENT_RATE
|
||||
self.use_upnp = True
|
||||
self.start_lbrycrdd = True
|
||||
if os.name == "nt":
|
||||
self.lbrycrdd_path = "lbrycrdd.exe"
|
||||
else:
|
||||
self.lbrycrdd_path = "./lbrycrdd"
|
||||
self.delete_blobs_on_remove = True
|
||||
self.blob_request_payment_rate_manager = None
|
||||
self.lbry_file_metadata_manager = None
|
||||
self.lbry_file_manager = None
|
||||
self.settings = LBRYSettings(self.db_dir)
|
||||
self.wallet_type = wallet_type
|
||||
self.check_for_updates = check_for_updates
|
||||
self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
|
||||
self.autofetcher_conf = os.path.join(self.wallet_dir, "autofetcher.conf")
|
||||
self.created_data_dir = False
|
||||
if not os.path.exists(self.db_dir):
|
||||
os.mkdir(self.db_dir)
|
||||
self.created_data_dir = True
|
||||
self.session_settings = None
|
||||
self.data_rate = MIN_BLOB_DATA_PAYMENT_RATE
|
||||
self.max_key_fee = DEFAULT_MAX_KEY_FEE
|
||||
self.max_search_results = DEFAULT_MAX_SEARCH_RESULTS
|
||||
self.startup_status = STARTUP_STAGES[0]
|
||||
self.startup_message = None
|
||||
self.announced_startup = False
|
||||
self.search_timeout = 3.0
|
||||
self.query_handlers = {}
|
||||
self.default_settings = {
|
||||
'run_on_startup': False,
|
||||
'data_rate': MIN_BLOB_DATA_PAYMENT_RATE,
|
||||
'max_key_fee': 10.0,
|
||||
'default_download_directory': self.download_directory,
|
||||
'max_upload': 0.0,
|
||||
'max_download': 0.0,
|
||||
'upload_log': True
|
||||
}
|
||||
self.ui_version = ui_version_info.replace('\n', '')
|
||||
|
||||
def render(self, request):
|
||||
request.content.seek(0, 0)
|
||||
# Unmarshal the JSON-RPC data.
|
||||
|
@ -97,6 +181,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
parsed = jsonrpclib.loads(content)
|
||||
functionPath = parsed.get("method")
|
||||
args = parsed.get('params')
|
||||
|
||||
#TODO convert args to correct types if possible
|
||||
|
||||
id = parsed.get('id')
|
||||
version = parsed.get('jsonrpc')
|
||||
if version:
|
||||
|
@ -155,91 +242,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
log.error(failure)
|
||||
return jsonrpclib.Fault(self.FAILURE, "error")
|
||||
|
||||
def setup(self, wallet_type, check_for_updates):
|
||||
def _set_vars(wallet_type, check_for_updates):
|
||||
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
|
||||
|
||||
self.log_file = LOG_FILENAME
|
||||
self.fetcher = None
|
||||
self.current_db_revision = 1
|
||||
self.run_server = True
|
||||
self.session = None
|
||||
self.known_dht_nodes = KNOWN_DHT_NODES
|
||||
if sys.platform != "darwin":
|
||||
self.db_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||
else:
|
||||
self.db_dir = user_data_dir("LBRY")
|
||||
# self.db_dir = os.path.join(os.path.expanduser("~"), "Library/Application Support/lbrynet")
|
||||
self.blobfile_dir = os.path.join(self.db_dir, "blobfiles")
|
||||
self.peer_port = 3333
|
||||
self.dht_node_port = 4444
|
||||
self.first_run = None
|
||||
if os.name == "nt":
|
||||
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
||||
self.download_directory = get_path(FOLDERID.Downloads, UserHandle.current)
|
||||
self.wallet_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbrycrd")
|
||||
elif sys.platform == "darwin":
|
||||
self.download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
|
||||
if wallet_type == "lbrycrd":
|
||||
self.wallet_dir = user_data_dir("lbrycrd")
|
||||
else:
|
||||
self.wallet_dir = user_data_dir("LBRY")
|
||||
else:
|
||||
self.download_directory = os.getcwd()
|
||||
if wallet_type == "lbrycrd":
|
||||
self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
|
||||
else:
|
||||
self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbryum")
|
||||
self.daemon_conf = os.path.join(self.db_dir, 'daemon_settings.json')
|
||||
self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
|
||||
self.wallet_user = None
|
||||
self.wallet_password = None
|
||||
self.sd_identifier = StreamDescriptorIdentifier()
|
||||
self.stream_info_manager = TempLBRYFileMetadataManager()
|
||||
self.wallet_rpc_port = 8332
|
||||
self.downloads = []
|
||||
self.stream_frames = []
|
||||
self.default_blob_data_payment_rate = MIN_BLOB_DATA_PAYMENT_RATE
|
||||
self.use_upnp = True
|
||||
self.start_lbrycrdd = True
|
||||
if os.name == "nt":
|
||||
self.lbrycrdd_path = "lbrycrdd.exe"
|
||||
else:
|
||||
self.lbrycrdd_path = "./lbrycrdd"
|
||||
self.delete_blobs_on_remove = True
|
||||
self.blob_request_payment_rate_manager = None
|
||||
self.lbry_file_metadata_manager = None
|
||||
self.lbry_file_manager = None
|
||||
self.settings = LBRYSettings(self.db_dir)
|
||||
self.wallet_type = wallet_type
|
||||
self.check_for_updates = check_for_updates
|
||||
self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
|
||||
self.autofetcher_conf = os.path.join(self.wallet_dir, "autofetcher.conf")
|
||||
self.created_data_dir = False
|
||||
if not os.path.exists(self.db_dir):
|
||||
os.mkdir(self.db_dir)
|
||||
self.created_data_dir = True
|
||||
self.session_settings = None
|
||||
self.data_rate = MIN_BLOB_DATA_PAYMENT_RATE
|
||||
self.max_key_fee = DEFAULT_MAX_KEY_FEE
|
||||
self.max_search_results = DEFAULT_MAX_SEARCH_RESULTS
|
||||
self.startup_status = STARTUP_STAGES[0]
|
||||
self.startup_message = None
|
||||
self.announced_startup = False
|
||||
self.search_timeout = 3.0
|
||||
self.query_handlers = {}
|
||||
self.default_settings = {
|
||||
'run_on_startup': False,
|
||||
'data_rate': MIN_BLOB_DATA_PAYMENT_RATE,
|
||||
'max_key_fee': 10.0,
|
||||
'default_download_directory': self.download_directory,
|
||||
'max_upload': 0.0,
|
||||
'max_download': 0.0,
|
||||
'upload_log': True
|
||||
}
|
||||
|
||||
return defer.succeed(None)
|
||||
|
||||
def setup(self):
|
||||
def _log_starting_vals():
|
||||
def _get_lbry_files_json():
|
||||
r = []
|
||||
|
@ -266,14 +269,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
|
||||
def _announce_startup():
|
||||
self.announced_startup = True
|
||||
self.startup_status = STARTUP_STAGES[6]
|
||||
self.startup_status = STARTUP_STAGES[5]
|
||||
log.info("[" + str(datetime.now()) + "] Started lbrynet-daemon")
|
||||
return defer.succeed(None)
|
||||
|
||||
log.info("[" + str(datetime.now()) + "] Starting lbrynet-daemon")
|
||||
|
||||
d = defer.Deferred()
|
||||
d.addCallback(lambda _:_set_vars(wallet_type, check_for_updates))
|
||||
d.addCallback(lambda _: self._initial_setup())
|
||||
d.addCallback(self._set_daemon_settings)
|
||||
d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory))
|
||||
|
@ -299,7 +301,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
msg = {
|
||||
"processor": platform.processor(),
|
||||
"python version: ": platform.python_version(),
|
||||
"lbrynet version: ": __version__,
|
||||
"lbrynet version: ": lbrynet_version,
|
||||
"lbryum version: ": lbryum_version,
|
||||
"ui_version": self.ui_version,
|
||||
# 'ip': json.load(urlopen('http://jsonip.com'))['ip'],
|
||||
}
|
||||
if sys.platform == "darwin":
|
||||
|
@ -358,7 +362,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
return self._start_server()
|
||||
return defer.succeed(True)
|
||||
|
||||
self.startup_status = STARTUP_STAGES[5]
|
||||
self.startup_status = STARTUP_STAGES[4]
|
||||
|
||||
dl = self.settings.get_server_running_status()
|
||||
dl.addCallback(restore_running_status)
|
||||
|
@ -542,7 +546,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
return d
|
||||
|
||||
def _setup_lbry_file_manager(self):
|
||||
self.startup_status = STARTUP_STAGES[4]
|
||||
self.startup_status = STARTUP_STAGES[3]
|
||||
self.lbry_file_metadata_manager = DBLBRYFileMetadataManager(self.db_dir)
|
||||
d = self.lbry_file_metadata_manager.setup()
|
||||
|
||||
|
@ -597,12 +601,11 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
return r
|
||||
|
||||
def create_session(results):
|
||||
self.startup_status = STARTUP_STAGES[2]
|
||||
self.session = LBRYSession(results['default_data_payment_rate'], db_dir=self.db_dir, lbryid=self.lbryid,
|
||||
blob_dir=self.blobfile_dir, dht_node_port=self.dht_node_port,
|
||||
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port,
|
||||
use_upnp=self.use_upnp, wallet=results['wallet'])
|
||||
self.startup_status = STARTUP_STAGES[3]
|
||||
self.startup_status = STARTUP_STAGES[2]
|
||||
|
||||
dl = defer.DeferredList([d1, d2], fireOnOneErrback=True)
|
||||
dl.addCallback(combine_results)
|
||||
|
@ -868,6 +871,11 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
"""
|
||||
|
||||
r = {'status_code': self.startup_status[0], 'status_message': self.startup_status[1]}
|
||||
try:
|
||||
if self.startup_status[0] == 'loading_wallet':
|
||||
r['status_message'] = r['status_message'] % (str(self.session.wallet.blocks_behind_alert) + " blocks behind")
|
||||
except:
|
||||
pass
|
||||
log.info("[" + str(datetime.now()) + "] daemon status: " + str(r))
|
||||
return self._render_response(r, OK_CODE)
|
||||
|
||||
|
@ -901,6 +909,18 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
else:
|
||||
self._render_response(self.startup_message, OK_CODE)
|
||||
|
||||
def jsonrpc_version(self):
|
||||
"""
|
||||
Get lbry version information
|
||||
"""
|
||||
|
||||
msg = {
|
||||
"lbrynet version: ": lbrynet_version,
|
||||
"lbryum version: ": lbryum_version,
|
||||
"ui_version": self.ui_version,
|
||||
}
|
||||
return self._render_response(msg, OK_CODE)
|
||||
|
||||
def jsonrpc_get_settings(self):
|
||||
"""
|
||||
Get LBRY payment settings
|
||||
|
|
|
@ -88,21 +88,23 @@ def start():
|
|||
if ui_dir:
|
||||
if os.path.isdir(ui_dir):
|
||||
log.info("Using user specified UI directory: " + str(ui_dir))
|
||||
return defer.succeed(ui_dir)
|
||||
ui_version_info = "user-specified"
|
||||
return defer.succeed([ui_dir, ui_version_info])
|
||||
else:
|
||||
log.info("User specified UI directory doesn't exist: " + str(ui_dir))
|
||||
|
||||
def download_ui(dest_dir):
|
||||
def download_ui(dest_dir, ui_version):
|
||||
url = urlopen(DIST_URL)
|
||||
z = ZipFile(StringIO(url.read()))
|
||||
names = [i for i in z.namelist() if '.DS_Store' not in i and '__MACOSX' not in i]
|
||||
z.extractall(dest_dir, members=names)
|
||||
return defer.succeed(dest_dir)
|
||||
return defer.succeed([dest_dir, ui_version])
|
||||
|
||||
data_dir = user_data_dir("LBRY")
|
||||
version_dir = os.path.join(data_dir, "ui_version_history")
|
||||
|
||||
git_version = subprocess.check_output(GIT_CMD_STRING, shell=True)
|
||||
ui_version_info = git_version
|
||||
|
||||
if not os.path.isdir(data_dir):
|
||||
os.mkdir(data_dir)
|
||||
|
@ -128,28 +130,28 @@ def start():
|
|||
log.info(version_message)
|
||||
|
||||
if os.path.isdir(os.path.join(data_dir, "lbry-web-ui")):
|
||||
return defer.succeed(os.path.join(data_dir, "lbry-web-ui"))
|
||||
return defer.succeed([os.path.join(data_dir, "lbry-web-ui"), ui_version_info])
|
||||
else:
|
||||
return download_ui((os.path.join(data_dir, "lbry-web-ui")))
|
||||
return download_ui(os.path.join(data_dir, "lbry-web-ui"), ui_version_info)
|
||||
|
||||
def setupserver(ui_dir):
|
||||
def setupserver(ui_dir, ui_version):
|
||||
root = LBRYindex(ui_dir)
|
||||
root.putChild("css", static.File(os.path.join(ui_dir, "css")))
|
||||
root.putChild("font", static.File(os.path.join(ui_dir, "font")))
|
||||
root.putChild("img", static.File(os.path.join(ui_dir, "img")))
|
||||
root.putChild("js", static.File(os.path.join(ui_dir, "js")))
|
||||
root.putChild("view", LBRYFileRender())
|
||||
return defer.succeed(root)
|
||||
return defer.succeed([root, ui_version])
|
||||
|
||||
def setupapi(root, wallet):
|
||||
daemon = LBRYDaemon()
|
||||
def setupapi(root, wallet, ui_version):
|
||||
daemon = LBRYDaemon(wallet, "False", ui_version)
|
||||
root.putChild(API_ADDRESS, daemon)
|
||||
reactor.listenTCP(API_PORT, server.Site(root), interface=API_INTERFACE)
|
||||
return daemon.setup(wallet, "False")
|
||||
return daemon.setup()
|
||||
|
||||
d = getui(args.ui)
|
||||
d.addCallback(setupserver)
|
||||
d.addCallback(lambda r: setupapi(r, args.wallet))
|
||||
d.addCallback(lambda r: setupserver(r[0], r[1]))
|
||||
d.addCallback(lambda r: setupapi(r[0], args.wallet, r[1]))
|
||||
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
||||
|
||||
reactor.run()
|
Loading…
Reference in a new issue