Skip to content

Commit

Permalink
Merge pull request #29 from lbryio/development
Browse files Browse the repository at this point in the history
0.2.3
  • Loading branch information
Jack Robison committed May 6, 2016
2 parents 9a65598 + 7425098 commit 7d5c618
Show file tree
Hide file tree
Showing 14 changed files with 1,320 additions and 760 deletions.
2 changes: 1 addition & 1 deletion lbrynet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
logging.getLogger(__name__).addHandler(logging.NullHandler())


version = (0, 2, 2)
version = (0, 2, 3)
__version__ = ".".join([str(x) for x in version])
12 changes: 6 additions & 6 deletions lbrynet/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
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
DEFAULT_MAX_SEARCH_RESULTS = 25
DEFAULT_MAX_KEY_FEE = 100.0

KNOWN_DHT_NODES = [('104.236.42.182', 4000)]

Expand All @@ -33,11 +31,13 @@
API_PORT = 5279
ICON_PATH = "app.icns"
APP_NAME = "LBRY"
DEFAULT_WALLET = "lbryum"

API_CONNECTION_STRING = "http://%s:%i/%s" % (API_INTERFACE, API_PORT, API_ADDRESS)
UI_ADDRESS = "http://" + API_INTERFACE + ":" + str(API_PORT)

PROTOCOL_PREFIX = "lbry"

DEFAULT_TIMEOUT = 30
DEFAULT_WALLET = "lbryum"
DEFAULT_TIMEOUT = 30
DEFAULT_MAX_SEARCH_RESULTS = 25
DEFAULT_MAX_KEY_FEE = 100.0
DEFAULT_SEARCH_TIMEOUT = 3.0
DEFAULT_CACHE_TIME = 3600
35 changes: 34 additions & 1 deletion lbrynet/core/LBRYcrdWallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ def check_caught_up():
self.max_behind = self.blocks_behind_alert
self.catchup_progress = int(100 * (self.blocks_behind_alert / (5 + self.max_behind)))
if self._caught_up_counter == 0:
alert.info('Catching up to the blockchain...showing blocks left...')
alert.info('Catching up with the blockchain...showing blocks left...')
if self._caught_up_counter % 30 == 0:
alert.info('%d...', (remote_height - local_height))

Expand Down Expand Up @@ -1136,6 +1136,39 @@ def get_nametrie(self):
func = getattr(self.cmd_runner, cmd.name)
return threads.deferToThread(func)

def get_history(self):
cmd = known_commands['history']
func = getattr(self.cmd_runner, cmd.name)
return threads.deferToThread(func)

def get_tx_json(self, txid):
def _decode(raw_tx):
tx = Transaction(raw_tx).deserialize()
decoded_tx = {}
for txkey in tx.keys():
if isinstance(tx[txkey], list):
decoded_tx[txkey] = []
for i in tx[txkey]:
tmp = {}
for k in i.keys():
if isinstance(i[k], Decimal):
tmp[k] = float(i[k] / 1e8)
else:
tmp[k] = i[k]
decoded_tx[txkey].append(tmp)
else:
decoded_tx[txkey] = tx[txkey]
return decoded_tx

d = self._get_raw_tx(txid)
d.addCallback(_decode)
return d

def get_pub_keys(self, wallet):
cmd = known_commands['getpubkeys']
func = getattr(self.cmd_runner, cmd.name)
return threads.deferToThread(func, wallet)

def _save_wallet(self, val):
d = threads.deferToThread(self.wallet.storage.write)
d.addCallback(lambda _: val)
Expand Down
14 changes: 12 additions & 2 deletions lbrynet/lbryfile/client/LBRYFileDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,20 @@ def open_file():
file_name = "_"
if os.path.exists(os.path.join(self.download_directory, file_name)):
ext_num = 1

def _get_file_name(ext):
if len(file_name.split(".")):
fn = ''.join(file_name.split(".")[:-1])
file_ext = ''.join(file_name.split(".")[-1])
return fn + "-" + str(ext) + "." + file_ext
else:
return file_name + "_" + str(ext)

while os.path.exists(os.path.join(self.download_directory,
file_name + "_" + str(ext_num))):
_get_file_name(ext_num))):
ext_num += 1
file_name = file_name + "_" + str(ext_num)

file_name = _get_file_name(ext_num)
try:
self.file_handle = open(os.path.join(self.download_directory, file_name), 'wb')
self.file_written_to = os.path.join(self.download_directory, file_name)
Expand Down
3 changes: 2 additions & 1 deletion lbrynet/lbryfilemanager/LBRYFileCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def stop_file(creator):

def make_stream_desc_file(stream_hash):
log.debug("creating the stream descriptor file")
descriptor_writer = PlainStreamDescriptorWriter(file_name + conf.CRYPTSD_FILE_EXTENSION)
descriptor_file_path = os.path.join(session.db_dir, file_name + conf.CRYPTSD_FILE_EXTENSION)
descriptor_writer = PlainStreamDescriptorWriter(descriptor_file_path)

d = get_sd_info(lbry_file_manager.stream_info_manager, stream_hash, True)

Expand Down
25 changes: 22 additions & 3 deletions lbrynet/lbryfilemanager/LBRYFileDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ def __init__(self, rowid, stream_hash, peer_finder, rate_limiter, blob_manager,
LBRYFileSaver.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
stream_info_manager, payment_rate_manager, wallet, download_directory,
upload_allowed, file_name)
self.sd_hash = None
self.rowid = rowid
self.lbry_file_manager = lbry_file_manager
self.saving_status = False

def restore(self):
d = self.lbry_file_manager.get_lbry_file_status(self)
d = self.stream_info_manager._get_sd_blob_hashes_for_stream(self.stream_hash)

def _save_sd_hash(sd_hash):
if len(sd_hash):
self.sd_hash = sd_hash[0]
return defer.succeed(None)

d.addCallback(_save_sd_hash)

d.addCallback(lambda _: self.lbry_file_manager.get_lbry_file_status(self))

def restore_status(status):
if status == ManagedLBRYFileDownloader.STATUS_RUNNING:
Expand Down Expand Up @@ -87,6 +97,14 @@ def _start(self):

d = LBRYFileSaver._start(self)

d.addCallback(lambda _: self.stream_info_manager._get_sd_blob_hashes_for_stream(self.stream_hash))

def _save_sd_hash(sd_hash):
self.sd_hash = sd_hash[0]
return defer.succeed(None)

d.addCallback(_save_sd_hash)

d.addCallback(lambda _: self._save_status())

return d
Expand Down Expand Up @@ -119,7 +137,7 @@ def __init__(self, lbry_file_manager):
def can_download(self, sd_validator):
return True

def make_downloader(self, metadata, options, payment_rate_manager, download_directory=None):
def make_downloader(self, metadata, options, payment_rate_manager, download_directory=None, file_name=None):
data_rate = options[0]
upload_allowed = options[1]

Expand All @@ -138,7 +156,8 @@ def save_source_if_blob(stream_hash):
payment_rate_manager,
data_rate,
upload_allowed,
download_directory=download_directory))
download_directory=download_directory,
file_name=file_name))
return d

@staticmethod
Expand Down
42 changes: 7 additions & 35 deletions lbrynet/lbryfilemanager/LBRYFileManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

import logging
import os
import sys
from datetime import datetime

from twisted.internet.task import LoopingCall
from twisted.enterprise import adbapi
from twisted.internet import defer, task, reactor
from twisted.python.failure import Failure
Expand All @@ -28,50 +25,24 @@ class LBRYFileManager(object):
Keeps track of currently opened LBRY Files, their options, and their LBRY File specific metadata.
"""

def __init__(self, session, stream_info_manager, sd_identifier, delete_data=False, download_directory=None):
def __init__(self, session, stream_info_manager, sd_identifier, download_directory=None):
self.session = session
self.stream_info_manager = stream_info_manager
self.sd_identifier = sd_identifier
self.lbry_files = []
self.sql_db = None
# self.delete_data = delete_data
# self.check_exists_loop = LoopingCall(self.check_files_exist)
if download_directory:
self.download_directory = download_directory
else:
self.download_directory = os.getcwd()
log.debug("Download directory for LBRYFileManager: %s", str(self.download_directory))

def setup(self):
# self.check_exists_loop.start(10)

d = self._open_db()
d.addCallback(lambda _: self._add_to_sd_identifier())
d.addCallback(lambda _: self._start_lbry_files())
return d

# def check_files_exist(self):
# def _disp(deleted_files):
# if deleted_files[0][0]:
# for file in bad_files:
# log.info("[" + str(datetime.now()) + "] Detected " + file.file_name + " was deleted, removing from file manager")
#
# def _delete_stream_data(lbry_file):
# s_h = lbry_file.stream_hash
# d = self.get_count_for_stream_hash(s_h)
# # TODO: could possibly be a timing issue here
# d.addCallback(lambda c: self.stream_info_manager.delete_stream(s_h) if c == 0 else True)
# return d
#
# bad_files = [lbry_file for lbry_file in self.lbry_files
# if lbry_file.completed == True and
# os.path.isfile(os.path.join(self.download_directory, lbry_file.file_name)) == False]
# d = defer.DeferredList([self.delete_lbry_file(lbry_file) for lbry_file in bad_files], consumeErrors=True)
# d.addCallback(lambda files: _disp(files) if len(files) else defer.succeed(None))
#
# if self.delete_data:
# d2 = defer.DeferredList([_delete_stream_data(lbry_file) for lbry_file in bad_files], consumeErrors=True)

def get_lbry_file_status(self, lbry_file):
return self._get_lbry_file_status(lbry_file.rowid)

Expand Down Expand Up @@ -123,7 +94,7 @@ def start_lbry_files(lbry_files_and_options):
return d

def start_lbry_file(self, rowid, stream_hash, payment_rate_manager, blob_data_rate=None, upload_allowed=True,
download_directory=None):
download_directory=None, file_name=None):
if not download_directory:
download_directory = self.download_directory
payment_rate_manager.min_blob_data_payment_rate = blob_data_rate
Expand All @@ -134,16 +105,18 @@ def start_lbry_file(self, rowid, stream_hash, payment_rate_manager, blob_data_ra
self.stream_info_manager, self,
payment_rate_manager, self.session.wallet,
download_directory,
upload_allowed)
upload_allowed,
file_name=file_name)
self.lbry_files.append(lbry_file_downloader)
d = lbry_file_downloader.set_stream_info()
d.addCallback(lambda _: lbry_file_downloader)
return d

def add_lbry_file(self, stream_hash, payment_rate_manager, blob_data_rate=None, upload_allowed=True, download_directory=None):
def add_lbry_file(self, stream_hash, payment_rate_manager, blob_data_rate=None, upload_allowed=True,
download_directory=None, file_name=None):
d = self._save_lbry_file(stream_hash, blob_data_rate)
d.addCallback(lambda rowid: self.start_lbry_file(rowid, stream_hash, payment_rate_manager,
blob_data_rate, upload_allowed, download_directory))
blob_data_rate, upload_allowed, download_directory, file_name))
return d

def delete_lbry_file(self, lbry_file):
Expand Down Expand Up @@ -183,7 +156,6 @@ def toggle_lbry_file_running(self, lbry_file):
return defer.fail(Failure(ValueError("Could not find that LBRY file")))

def stop(self):
# self.check_exists_loop.stop()

ds = []

Expand Down
62 changes: 14 additions & 48 deletions lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,73 +11,39 @@
UI_ADDRESS = "http://localhost:5279"


class Timeout(Exception):
def __init__(self, value):
self.parameter = value

def __str__(self):
return repr(self.parameter)


class LBRYURIHandler(object):
def __init__(self):
self.started_daemon = False
self.start_timeout = 0
self.daemon = JSONRPCProxy.from_url(API_CONNECTION_STRING)

def check_status(self):
status = None
try:
status = self.daemon.is_running()
if self.start_timeout < 30 and not status:
sleep(1)
self.start_timeout += 1
self.check_status()
elif status:
return True
else:
raise Timeout("LBRY daemon is running, but connection timed out")
except:
if self.start_timeout < 30:
sleep(1)
self.start_timeout += 1
self.check_status()
else:
raise Timeout("Timed out trying to start LBRY daemon")

def handle_osx(self, lbry_name):
lbry_process = [d for d in subprocess.Popen(['ps','aux'], stdout=subprocess.PIPE).stdout.readlines()
if 'LBRY.app' in d and 'LBRYURIHandler' not in d]
try:
status = self.daemon.is_running()
except:
status = None

if lbry_process or status:
self.check_status()
started = False
else:
os.system("open /Applications/LBRY.app")
self.check_status()
started = True
sleep(3)

if lbry_name == "lbry" or lbry_name == "" and not started:
if lbry_name == "lbry" or lbry_name == "":
webbrowser.open(UI_ADDRESS)
else:
webbrowser.open(UI_ADDRESS + "/view?name=" + lbry_name)
webbrowser.open(UI_ADDRESS + "/?watch=" + lbry_name)

def handle_linux(self, lbry_name):
try:
is_running = self.daemon.is_running()
if not is_running:
sys.exit(0)
status = self.daemon.is_running()
except:
sys.exit(0)

if lbry_name == "lbry":
cmd = r'DIR = "$( cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"' \
r'if [-z "$(pgrep lbrynet-daemon)"]; then' \
r'echo "running lbrynet-daemon..."' \
r'$DIR / lbrynet - daemon &' \
r'sleep 3 # let the daemon load before connecting' \
r'fi'
subprocess.Popen(cmd, shell=True)

if lbry_name == "lbry" or lbry_name == "":
webbrowser.open(UI_ADDRESS)
else:
webbrowser.open(UI_ADDRESS + "/view?name=" + lbry_name)
webbrowser.open(UI_ADDRESS + "/?watch=" + lbry_name)


def main(args):
Expand Down
Loading

0 comments on commit 7d5c618

Please sign in to comment.