Merge branch 'development' into lbryum

This commit is contained in:
Jack 2016-02-24 16:19:19 -05:00
commit 96bc02c8cb
3 changed files with 41 additions and 78 deletions

View file

@ -835,6 +835,7 @@ class LBRYumWallet(LBRYWallet):
self.wallet = None
self.cmd_runner = None
self.first_run = False
self.printed_retrieving_headers = False
def _start(self):
@ -843,15 +844,20 @@ class LBRYumWallet(LBRYWallet):
def setup_network():
self.config = SimpleConfig()
self.network = Network(self.config)
alert.info("Starting the wallet...")
return defer.succeed(self.network.start())
d = setup_network()
def check_started():
if self.network.is_connecting():
if not self.printed_retrieving_headers and self.network.blockchain.retrieving_headers:
alert.info("Running the wallet for the first time...this may take a moment.")
self.printed_retrieving_headers = True
return False
start_check.stop()
if self.network.is_connected():
alert.info("Wallet started.")
network_start_d.callback(True)
else:
network_start_d.errback(ValueError("Failed to connect to network."))
@ -917,7 +923,9 @@ class LBRYumWallet(LBRYWallet):
return d
def get_block(self, blockhash):
return defer.fail(NotImplementedError())
cmd = known_commands['getblock']
func = getattr(self.cmd_runner, cmd.name)
return threads.deferToThread(func, blockhash)
def get_most_recent_blocktime(self):
header = self.network.get_header(self.network.get_local_height())
@ -970,6 +978,11 @@ class LBRYumWallet(LBRYWallet):
def _get_balance_for_address(self, address):
return defer.succeed(Decimal(self.wallet.get_addr_received(address))/COIN)
def get_nametrie(self):
cmd = known_commands['getnametrie']
func = getattr(self.cmd_runner, cmd.name)
return threads.deferToThread(func)
def _save_wallet(self, val):
d = threads.deferToThread(self.wallet.storage.write)
d.addCallback(lambda _: val)

View file

@ -96,8 +96,9 @@ class CryptStreamDownloader(object):
self.starting = True
self.completed = False
self.finished_deferred = defer.Deferred()
fd = self.finished_deferred
d = self._start()
d.addCallback(lambda _: self.finished_deferred)
d.addCallback(lambda _: fd)
return d
def stop(self, err=None):

View file

@ -7,8 +7,6 @@ import locale
import sys
from yapsy.PluginManager import PluginManager
from twisted.internet import defer, threads, stdio, task, error
from twisted.python.failure import Failure
# from lbrynet.core.client.AutoDownloader import AutoFetcher
from lbrynet.lbrynet_console.ConsoleControl import ConsoleControl
from lbrynet.lbrynet_console.LBRYSettings import LBRYSettings
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
@ -24,10 +22,8 @@ from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifi
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileOpenerFactory
from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
#from lbrynet.lbrylive.PaymentRateManager import LiveStreamPaymentRateManager
from lbrynet.lbrynet_console.ControlHandlers import ApplicationStatusFactory, GetWalletBalancesFactory, ShutDownFactory
#from lbrynet.lbrynet_console.ControlHandlers import AutoFetcherStartFactory, AutoFetcherStopFactory
from lbrynet.lbrynet_console.ControlHandlers import ImmediateAnnounceAllBlobsFactory #, AutoFetcherStatusFactory
from lbrynet.lbrynet_console.ControlHandlers import ImmediateAnnounceAllBlobsFactory
from lbrynet.lbrynet_console.ControlHandlers import LBRYFileStatusFactory, DeleteLBRYFileChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import ToggleLBRYFileRunningChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import ModifyApplicationDefaultsFactory
@ -50,9 +46,9 @@ alert = logging.getLogger("lbryalert." + __name__)
class LBRYConsole():
"""A class which can upload and download file streams to and from the network"""
def __init__(self, peer_port, dht_node_port, known_dht_nodes, wallet_type,
def __init__(self, peer_port, dht_node_port, known_dht_nodes, fake_wallet,
lbrycrd_conf, lbrycrd_dir, use_upnp, data_dir, created_data_dir,
lbrycrdd_path, start_lbrycrdd):
lbrycrdd_path):
"""
@param peer_port: the network port on which to listen for peers
@ -63,7 +59,7 @@ class LBRYConsole():
self.peer_port = peer_port
self.dht_node_port = dht_node_port
self.known_dht_nodes = known_dht_nodes
self.wallet_type = wallet_type
self.fake_wallet = fake_wallet
self.lbrycrd_conf = lbrycrd_conf
self.lbrycrd_dir = lbrycrd_dir
if not self.lbrycrd_dir:
@ -73,10 +69,7 @@ class LBRYConsole():
self.lbrycrd_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
if not self.lbrycrd_conf:
self.lbrycrd_conf = os.path.join(self.lbrycrd_dir, "lbrycrd.conf")
# self.autofetcher_conf = os.path.join(self.lbrycrd_dir, "autofetcher.conf")
self.lbrycrdd_path = lbrycrdd_path
self.default_lbrycrdd_path = "./lbrycrdd"
self.start_lbrycrdd = start_lbrycrdd
self.use_upnp = use_upnp
self.lbry_server_port = None
self.session = None
@ -100,7 +93,6 @@ class LBRYConsole():
self.sd_identifier = StreamDescriptorIdentifier()
self.plugin_objects = []
self.db_migration_revisions = None
# self.autofetcher = None
def start(self):
"""Initialize the session and restore everything to its saved state"""
@ -112,7 +104,6 @@ class LBRYConsole():
d.addCallback(lambda _: add_lbry_file_to_sd_identifier(self.sd_identifier))
d.addCallback(lambda _: self._setup_lbry_file_manager())
d.addCallback(lambda _: self._setup_lbry_file_opener())
#d.addCallback(lambda _: self._get_autofetcher())
d.addCallback(lambda _: self._setup_control_handlers())
d.addCallback(lambda _: self._setup_query_handlers())
d.addCallback(lambda _: self._load_plugins())
@ -121,10 +112,6 @@ class LBRYConsole():
d.addErrback(self._show_start_error)
return d
# def _get_autofetcher(self):
# self.autofetcher = AutoFetcher(self.session, self.lbry_file_manager, self.lbry_file_metadata_manager,
# self.session.wallet, self.sd_identifier, self.autofetcher_conf)
def _show_start_error(self, error):
print error.getTraceback()
log.error("An error occurred during start up: %s", error.getTraceback())
@ -201,30 +188,6 @@ class LBRYConsole():
d = self.settings.start()
d.addCallback(lambda _: self.settings.get_lbryid())
d.addCallback(self.set_lbryid)
d.addCallback(lambda _: self.get_lbrycrdd_path())
return d
def get_lbrycrdd_path(self):
if not self.start_lbrycrdd:
return defer.succeed(None)
def get_lbrycrdd_path_conf_file():
lbrycrdd_path_conf_path = os.path.join(os.path.expanduser("~"), ".lbrycrddpath.conf")
if not os.path.exists(lbrycrdd_path_conf_path):
return ""
lbrycrdd_path_conf = open(lbrycrdd_path_conf_path)
lines = lbrycrdd_path_conf.readlines()
return lines
d = threads.deferToThread(get_lbrycrdd_path_conf_file)
def load_lbrycrdd_path(conf):
for line in conf:
if len(line.strip()) and line.strip()[0] != "#":
self.lbrycrdd_path = line.strip()
d.addCallback(load_lbrycrdd_path)
return d
def set_lbryid(self, lbryid):
@ -245,21 +208,14 @@ class LBRYConsole():
return d
def get_wallet():
if self.wallet_type == "lbrycrd":
lbrycrdd_path = None
if self.start_lbrycrdd is True:
lbrycrdd_path = self.lbrycrdd_path
if not lbrycrdd_path:
lbrycrdd_path = self.default_lbrycrdd_path
if self.fake_wallet:
d = defer.succeed(PTCWallet(self.db_dir))
elif self.lbrycrdd_path is not None:
d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.lbrycrd_dir,
wallet_conf=self.lbrycrd_conf,
lbrycrdd_path=lbrycrdd_path))
elif self.wallet_type == 'ptc':
d = defer.succeed(PTCWallet(self.db_dir))
elif self.wallet_type == 'lbryum':
d = defer.succeed(LBRYumWallet(self.db_dir))
lbrycrdd_path=self.lbrycrdd_path))
else:
d = defer.fail(Failure(ValueError("Invalid wallet type")))
d = defer.succeed(LBRYumWallet(self.db_dir))
d.addCallback(lambda wallet: {"wallet": wallet})
return d
@ -377,14 +333,11 @@ class LBRYConsole():
ModifyLBRYFileOptionsChooserFactory(self.lbry_file_manager),
AddStreamFromHashFactory(self.sd_identifier, self.session, self.session.wallet),
StatusFactory(self, self.session.rate_limiter, self.lbry_file_manager,
self.session.blob_manager, self.session.wallet if self.wallet_type in ['lbrycrd', 'lbryum'] else None),
# AutoFetcherStartFactory(self.autofetcher),
# AutoFetcherStopFactory(self.autofetcher),
# AutoFetcherStatusFactory(self.autofetcher),
self.session.blob_manager, self.session.wallet if not self.fake_wallet else None),
ImmediateAnnounceAllBlobsFactory(self.session.blob_manager)
]
self.add_control_handlers(handlers)
if self.wallet_type in ['lbrycrd', 'lbryum']:
if not self.fake_wallet:
lbrycrd_handlers = [
AddStreamFromLBRYcrdNameFactory(self.sd_identifier, self.session,
self.session.wallet),
@ -524,15 +477,9 @@ def launch_lbry_console():
parser.add_argument("--dht_node_port",
help="The port on which the console will listen for DHT connections.",
type=int, default=4444)
parser.add_argument("--wallet_type",
help="Either 'lbrycrd' or 'ptc' or 'lbryum'.",
type=str, default="lbrycrd")
parser.add_argument("--lbrycrd_wallet_dir",
help="The directory in which lbrycrd data will stored. Used if lbrycrdd is "
"launched by this application.")
parser.add_argument("--lbrycrd_wallet_conf",
help="The configuration file for the LBRYcrd wallet. Default: ~/.lbrycrd/lbrycrd.conf",
type=str)
parser.add_argument("--fake_wallet",
help="Testing purposes only. Use a non-blockchain wallet.",
action="store_true")
parser.add_argument("--no_dht_bootstrap",
help="Don't try to connect to the DHT",
action="store_true")
@ -552,12 +499,15 @@ def launch_lbry_console():
"Default: ~/.lbrynet on linux, ~/Library/Application Support/lbrynet on OS X"),
type=str)
parser.add_argument("--lbrycrdd_path",
help="The path to lbrycrdd, which will be launched if it isn't running, unless "
"launching lbrycrdd is disabled by --disable_launch_lbrycrdd. By default, "
"the file ~/.lbrycrddpath.conf will be checked, and if no path is found "
"there, it will be ./lbrycrdd")
parser.add_argument("--disable_launch_lbrycrdd",
help="Don't launch lbrycrdd even if it's not running.")
help="The path to lbrycrdd, which will be launched if it isn't running. If"
"this option is chosen, lbrycrdd will be used as the interface to the"
"blockchain. By default, a lightweight interface is used.")
parser.add_argument("--lbrycrd_wallet_dir",
help="The directory in which lbrycrd data will stored. Used if lbrycrdd is "
"launched by this application.")
parser.add_argument("--lbrycrd_wallet_conf",
help="The configuration file for the LBRYcrd wallet. Default: ~/.lbrycrd/lbrycrd.conf",
type=str)
args = parser.parse_args()
@ -599,11 +549,10 @@ def launch_lbry_console():
file_handler.addFilter(logging.Filter("lbrynet"))
logger.addHandler(file_handler)
console = LBRYConsole(peer_port, dht_node_port, bootstrap_nodes, wallet_type=args.wallet_type,
console = LBRYConsole(peer_port, dht_node_port, bootstrap_nodes, fake_wallet=args.fake_wallet,
lbrycrd_conf=args.lbrycrd_wallet_conf, lbrycrd_dir=args.lbrycrd_wallet_dir,
use_upnp=not args.disable_upnp, data_dir=data_dir,
created_data_dir=created_data_dir, lbrycrdd_path=args.lbrycrdd_path,
start_lbrycrdd=not args.disable_launch_lbrycrdd)
created_data_dir=created_data_dir, lbrycrdd_path=args.lbrycrdd_path)
d = task.deferLater(reactor, 0, console.start)