--http-auth flag to use authentication, refactor settings

settings will prefer, in order:
-defaults
-settings in config file
-settings given as environmental variables
-settings given as command line args
This commit is contained in:
Jack 2016-10-19 00:12:44 -04:00
parent a8a581d35c
commit 06a88599df
34 changed files with 523 additions and 603 deletions

View file

@ -1,6 +1,7 @@
import logging import logging
from conf import Config
__version__ = "0.6.4" __version__ = "0.6.4"
version = tuple(__version__.split('.')) version = tuple(__version__.split('.'))
settings = Config()
logging.getLogger(__name__).addHandler(logging.NullHandler()) logging.getLogger(__name__).addHandler(logging.NullHandler())

View file

@ -5,7 +5,7 @@ import logging
from requests import auth from requests import auth
from requests_futures import sessions from requests_futures import sessions
from lbrynet import conf from lbrynet import settings
from lbrynet.analytics import utils from lbrynet.analytics import utils
@ -66,6 +66,6 @@ class AnalyticsApi(object):
session = sessions.FuturesSession() session = sessions.FuturesSession()
return cls( return cls(
session, session,
conf.ANALYTICS_ENDPOINT, settings.ANALYTICS_ENDPOINT,
utils.deobfuscate(conf.ANALYTICS_TOKEN) utils.deobfuscate(settings.ANALYTICS_TOKEN)
) )

View file

@ -1,10 +1,13 @@
""" import copy
Some network wide and also application specific parameters
"""
import os import os
import sys import sys
import logging
from appdirs import user_data_dir from appdirs import user_data_dir
log = logging.getLogger(__name__)
PRIORITIZE_ENV = True
LINUX = 1 LINUX = 1
DARWIN = 2 DARWIN = 2
WINDOWS = 3 WINDOWS = 3
@ -15,82 +18,154 @@ elif sys.platform.startswith("darwin"):
platform = DARWIN platform = DARWIN
elif sys.platform.startswith("win"): elif sys.platform.startswith("win"):
platform = WINDOWS platform = WINDOWS
else:
platform = LINUX
if platform is LINUX: if platform is LINUX:
DATA_DIR = os.path.join(os.path.expanduser("~"), ".lbrynet") default_download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
default_lbryum_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
default_lbryum_dir = os.path.join(os.path.expanduser("~"), ".lbryum")
elif platform is DARWIN:
default_download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
default_data_dir = user_data_dir("LBRY")
default_lbryum_dir = os.path.join(os.path.expanduser("~"), ".lbryum")
else: else:
DATA_DIR = user_data_dir("LBRY") from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
default_download_directory = get_path(FOLDERID.Downloads, UserHandle.current)
default_data_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbrynet")
default_lbryum_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbryum")
IS_DEVELOPMENT_VERSION = False ADJUSTABLE_SETTINGS = {
'run_on_startup': False,
'download_directory': default_download_directory,
'max_upload': 0.0,
'max_download': 0.0,
'upload_log': True,
'delete_blobs_on_remove': True,
'use_upnp': True,
'start_lbrycrdd': True,
'run_reflector_server': False,
'startup_scripts': [],
'last_version': {},
'peer_port': 3333,
'dht_node_port': 4444,
'reflector_port': 5566,
'download_timeout': 30,
'max_search_results': 25,
'search_timeout': 3.0,
'cache_time': 150,
'host_ui': True,
'check_ui_requirements': True,
'local_ui_path': False,
'API_PORT': 5279,
'search_servers':['lighthouse1.lbry.io:50005'],
'data_rate': .0001, # points/megabyte
'MIN_BLOB_INFO_PAYMENT_RATE': .02, # points/1000 infos
'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),
('lbrynet1.lbry.io', 4444),
('lbrynet2.lbry.io', 4444),
('lbrynet3.lbry.io', 4444)],
'POINTTRADER_SERVER': 'http://127.0.0.1:2424',
'REFLECTOR_SERVERS': [("reflector.lbry.io", 5566)],
'WALLET': "lbryum",
'UI_BRANCH': "master",
'DEFAULT_UI_BRANCH': 'master',
'DATA_DIR': default_data_dir,
'LBRYUM_WALLET_DIR': default_lbryum_dir,
'sd_download_timeout': 3,
'max_key_fee': {'USD': {'amount': 25.0, 'address': ''}},
MAX_HANDSHAKE_SIZE = 2**16 }
MAX_REQUEST_SIZE = 2**16
MAX_BLOB_REQUEST_SIZE = 2**16
MAX_RESPONSE_INFO_SIZE = 2**16
MAX_BLOB_INFOS_TO_REQUEST = 20
BLOBFILES_DIR = ".blobfiles"
BLOB_SIZE = 2**21
MIN_BLOB_DATA_PAYMENT_RATE = .0001 # points/megabyte
MIN_BLOB_INFO_PAYMENT_RATE = .02 # points/1000 infos
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), class ApplicationSettings(object):
('lbrynet1.lbry.io', 4444), USE_AUTH_HTTP = True
('lbrynet2.lbry.io', 4444), MAX_HANDSHAKE_SIZE = 2**16
('lbrynet3.lbry.io', 4444)] MAX_REQUEST_SIZE = 2**16
MAX_BLOB_REQUEST_SIZE = 2**16
MAX_RESPONSE_INFO_SIZE = 2**16
MAX_BLOB_INFOS_TO_REQUEST = 20
BLOBFILES_DIR = "blobfiles"
BLOB_SIZE = 2**21
LOG_FILE_NAME = "lbrynet.log"
LOG_POST_URL = "https://lbry.io/log-upload"
CRYPTSD_FILE_EXTENSION = ".cryptsd"
API_INTERFACE = "localhost"
API_ADDRESS = "lbryapi"
ICON_PATH = "icons" if platform is WINDOWS else "app.icns"
APP_NAME = "LBRY"
PROTOCOL_PREFIX = "lbry"
WALLET_TYPES = ["lbryum", "lbrycrd"]
SOURCE_TYPES = ['lbry_sd_hash', 'url', 'btih']
CURRENCIES = {
'BTC': {'type': 'crypto'},
'LBC': {'type': 'crypto'},
'USD': {'type': 'fiat'},
}
LOGGLY_TOKEN = 'LJEzATH4AzRgAwxjAP00LwZ2YGx3MwVgZTMuBQZ3MQuxLmOv'
ANALYTICS_ENDPOINT = 'https://api.segment.io/v1'
ANALYTICS_TOKEN = 'Ax5LZzR1o3q3Z3WjATASDwR5rKyHH0qOIRIbLmMXn2H='
POINTTRADER_SERVER = 'http://ec2-54-187-192-68.us-west-2.compute.amazonaws.com:2424' @staticmethod
#POINTTRADER_SERVER = 'http://127.0.0.1:2424' def get_dict():
r = {k: v for k, v in ApplicationSettings.__dict__.iteritems() if not k.startswith('__')}
if PRIORITIZE_ENV:
log.info("Checking env settings")
r = add_env_settings(r)
return r
SEARCH_SERVERS = ["http://lighthouse1.lbry.io:50005",
"http://lighthouse2.lbry.io:50005",
"http://lighthouse3.lbry.io:50005"]
REFLECTOR_SERVERS = [("reflector.lbry.io", 5566)] def add_env_settings(settings_dict):
with_env_settings = copy.deepcopy(settings_dict)
for setting, setting_val in settings_dict.iteritems():
env_val = os.environ.get(setting, None)
if env_val != setting_val and env_val is not None:
log.info("Using env value for %s", setting)
with_env_settings.update({setting: env_val})
return with_env_settings
LOG_FILE_NAME = "lbrynet.log"
LOG_POST_URL = "https://lbry.io/log-upload"
CRYPTSD_FILE_EXTENSION = ".cryptsd" DEFAULT_CONFIG = ApplicationSettings.get_dict()
DEFAULT_CONFIG.update(add_env_settings(ADJUSTABLE_SETTINGS))
API_INTERFACE = "localhost"
API_ADDRESS = "lbryapi"
API_PORT = 5279
if os.name == "nt":
ICON_PATH = "icons"
else:
ICON_PATH = "app.icns"
APP_NAME = "LBRY"
ORIGIN = "http://%s:%i" % (API_INTERFACE, API_PORT) class Config(object):
REFERER = "http://%s:%i/" % (API_INTERFACE, API_PORT) __shared_state = copy.deepcopy(DEFAULT_CONFIG)
API_CONNECTION_STRING = "http://%s:%i/%s" % (API_INTERFACE, API_PORT, API_ADDRESS)
UI_ADDRESS = "http://%s:%i" % (API_INTERFACE, API_PORT)
PROTOCOL_PREFIX = "lbry"
DEFAULT_WALLET = "lbryum" def __init__(self):
WALLET_TYPES = ["lbryum", "lbrycrd"] self.__dict__ = self.__shared_state
DEFAULT_TIMEOUT = 30
DEFAULT_MAX_SEARCH_RESULTS = 25
DEFAULT_MAX_KEY_FEE = {'USD': {'amount': 25.0, 'address': ''}}
DEFAULT_SEARCH_TIMEOUT = 3.0
DEFAULT_SD_DOWNLOAD_TIMEOUT = 3
DEFAULT_CACHE_TIME = 150
DEFAULT_UI_BRANCH = "master"
SOURCE_TYPES = ['lbry_sd_hash', 'url', 'btih'] def update(self, settings):
CURRENCIES = { for k, v in settings.iteritems():
'BTC': {'type': 'crypto'}, if k in ADJUSTABLE_SETTINGS:
'LBC': {'type': 'crypto'}, self.__dict__.update({k: v})
'USD': {'type': 'fiat'},
}
LOGGLY_TOKEN = 'LJEzATH4AzRgAwxjAP00LwZ2YGx3MwVgZTMuBQZ3MQuxLmOv' @property
def configurable_settings(self):
return {k: v for k, v in copy.deepcopy(self.__dict__).iteritems() if k in ADJUSTABLE_SETTINGS}
ANALYTICS_ENDPOINT = 'https://api.segment.io/v1' @property
ANALYTICS_TOKEN = 'Ax5LZzR1o3q3Z3WjATASDwR5rKyHH0qOIRIbLmMXn2H=' def ORIGIN(self):
return "http://%s:%i" % (ApplicationSettings.API_INTERFACE, self.API_PORT)
LBRYUM_WALLET_DIR = os.environ.get('LBRYUM_WALLET_DIR') @property
def REFERER(self):
return "http://%s:%i/" % (ApplicationSettings.API_INTERFACE, self.API_PORT)
@property
def API_CONNECTION_STRING(self):
return "http://%s:%i/%s" % (ApplicationSettings.API_INTERFACE, self.API_PORT, ApplicationSettings.API_ADDRESS)
@property
def UI_ADDRESS(self):
return "http://%s:%i" % (ApplicationSettings.API_INTERFACE, self.API_PORT)
@property
def LBRYUM_WALLET_DIR(self):
env_dir = os.environ.get('LBRYUM_WALLET_DIR')
if env_dir:
return env_dir
return self.__dict__.get('LBRYUM_WALLET_DIR')

View file

@ -8,7 +8,7 @@ from twisted.internet import interfaces, defer, threads
from twisted.protocols.basic import FileSender from twisted.protocols.basic import FileSender
from twisted.python.failure import Failure from twisted.python.failure import Failure
from zope.interface import implements from zope.interface import implements
from lbrynet.conf import BLOB_SIZE from lbrynet import settings
from lbrynet.core.Error import DownloadCanceledError, InvalidDataError from lbrynet.core.Error import DownloadCanceledError, InvalidDataError
from lbrynet.core.cryptoutils import get_lbry_hash_obj from lbrynet.core.cryptoutils import get_lbry_hash_obj
@ -87,7 +87,7 @@ class HashBlob(object):
def set_length(self, length): def set_length(self, length):
if self.length is not None and length == self.length: if self.length is not None and length == self.length:
return True return True
if self.length is None and 0 <= length <= BLOB_SIZE: if self.length is None and 0 <= length <= settings.BLOB_SIZE:
self.length = length self.length = length
return True return True
log.warning("Got an invalid length. Previous length: %s, Invalid length: %s", str(self.length), str(length)) log.warning("Got an invalid length. Previous length: %s, Invalid length: %s", str(self.length), str(length))

View file

@ -1,8 +1,9 @@
from lbrynet.core.Strategy import get_default_strategy from lbrynet.core.Strategy import get_default_strategy
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, MIN_BLOB_INFO_PAYMENT_RATE from lbrynet import settings
class BasePaymentRateManager(object): class BasePaymentRateManager(object):
def __init__(self, rate=MIN_BLOB_DATA_PAYMENT_RATE, info_rate=MIN_BLOB_INFO_PAYMENT_RATE): def __init__(self, rate=settings.data_rate, info_rate=settings.MIN_BLOB_INFO_PAYMENT_RATE):
self.min_blob_data_payment_rate = rate self.min_blob_data_payment_rate = rate
self.min_blob_info_payment_rate = info_rate self.min_blob_info_payment_rate = info_rate

View file

@ -2,7 +2,7 @@ from zope.interface import implementer
from decimal import Decimal from decimal import Decimal
from lbrynet.interfaces import IBlobPriceModel from lbrynet.interfaces import IBlobPriceModel
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE from lbrynet import settings
def get_default_price_model(blob_tracker, base_price, **kwargs): def get_default_price_model(blob_tracker, base_price, **kwargs):
@ -21,7 +21,7 @@ class MeanAvailabilityWeightedPrice(object):
""" """
implementer(IBlobPriceModel) implementer(IBlobPriceModel)
def __init__(self, tracker, base_price=MIN_BLOB_DATA_PAYMENT_RATE, alpha=1.0): def __init__(self, tracker, base_price=settings.data_rate, alpha=1.0):
self.blob_tracker = tracker self.blob_tracker = tracker
self.base_price = Decimal(base_price) self.base_price = Decimal(base_price)
self.alpha = Decimal(alpha) self.alpha = Decimal(alpha)

View file

@ -153,7 +153,12 @@ class Wallet(object):
log.info("Got a new balance: %s", str(balance)) log.info("Got a new balance: %s", str(balance))
self.wallet_balance = balance self.wallet_balance = balance
d.addCallback(set_wallet_balance) def log_error(err):
if isinstance(err, AttributeError):
log.warning("Failed to get an updated balance")
log.warning("Last balance update: %s", str(self.wallet_balance))
d.addCallbacks(set_wallet_balance, log_error)
return d return d
d.addCallback(lambda should_run: do_manage() if should_run else None) d.addCallback(lambda should_run: do_manage() if should_run else None)
@ -1169,7 +1174,8 @@ class LBRYumWallet(Wallet):
self._start_check = None self._start_check = None
if self._catch_up_check is not None: if self._catch_up_check is not None:
self._catch_up_check.stop() if self._catch_up_check.running:
self._catch_up_check.stop()
self._catch_up_check = None self._catch_up_check = None
d = defer.Deferred() d = defer.Deferred()
@ -1241,6 +1247,9 @@ class LBRYumWallet(Wallet):
self._caught_up_counter += 1 self._caught_up_counter += 1
def log_error(err):
log.warning(err.getErrorMessage())
return defer.fail(err)
self._catch_up_check = task.LoopingCall(check_caught_up) self._catch_up_check = task.LoopingCall(check_caught_up)
@ -1248,6 +1257,7 @@ class LBRYumWallet(Wallet):
d.addCallback(self._save_wallet) d.addCallback(self._save_wallet)
d.addCallback(lambda _: self.wallet.start_threads(self.network)) d.addCallback(lambda _: self.wallet.start_threads(self.network))
d.addCallback(lambda _: self._catch_up_check.start(.1)) d.addCallback(lambda _: self._catch_up_check.start(.1))
d.addErrback(log_error)
d.addCallback(lambda _: blockchain_caught_d) d.addCallback(lambda _: blockchain_caught_d)
return d return d

View file

@ -4,7 +4,7 @@ from decimal import Decimal
from twisted.internet import error, defer from twisted.internet import error, defer
from twisted.internet.protocol import Protocol, ClientFactory from twisted.internet.protocol import Protocol, ClientFactory
from twisted.python import failure from twisted.python import failure
from lbrynet.conf import MAX_RESPONSE_INFO_SIZE as MAX_RESPONSE_SIZE from lbrynet import settings
from lbrynet.core.Error import ConnectionClosedBeforeResponseError, NoResponseError from lbrynet.core.Error import ConnectionClosedBeforeResponseError, NoResponseError
from lbrynet.core.Error import DownloadCanceledError, MisbehavingPeerError from lbrynet.core.Error import DownloadCanceledError, MisbehavingPeerError
from lbrynet.core.Error import RequestCanceledError from lbrynet.core.Error import RequestCanceledError
@ -48,7 +48,7 @@ class ClientProtocol(Protocol):
self._blob_download_request.write(data) self._blob_download_request.write(data)
else: else:
self._response_buff += data self._response_buff += data
if len(self._response_buff) > MAX_RESPONSE_SIZE: if len(self._response_buff) > settings.MAX_RESPONSE_INFO_SIZE:
log.warning("Response is too large. Size %s", len(self._response_buff)) log.warning("Response is too large. Size %s", len(self._response_buff))
self.transport.loseConnection() self.transport.loseConnection()
response, extra_data = self._get_valid_response(self._response_buff) response, extra_data = self._get_valid_response(self._response_buff)

View file

@ -1,4 +1,4 @@
from lbrynet.conf import BLOB_SIZE from lbrynet import settings
class ClientRequest(object): class ClientRequest(object):
@ -17,7 +17,7 @@ class ClientBlobRequest(ClientPaidRequest):
def __init__(self, request_dict, response_identifier, write_func, finished_deferred, def __init__(self, request_dict, response_identifier, write_func, finished_deferred,
cancel_func, blob): cancel_func, blob):
if blob.length is None: if blob.length is None:
max_pay_units = BLOB_SIZE max_pay_units = settings.BLOB_SIZE
else: else:
max_pay_units = blob.length max_pay_units = blob.length
ClientPaidRequest.__init__(self, request_dict, response_identifier, max_pay_units) ClientPaidRequest.__init__(self, request_dict, response_identifier, max_pay_units)

View file

@ -2,7 +2,7 @@ import logging
from twisted.internet import defer from twisted.internet import defer
from zope.interface import implements from zope.interface import implements
from lbrynet import interfaces from lbrynet import interfaces
from lbrynet.conf import MAX_CONNECTIONS_PER_STREAM from lbrynet import settings
from lbrynet.core.client.ClientProtocol import ClientProtocolFactory from lbrynet.core.client.ClientProtocol import ClientProtocolFactory
from lbrynet.core.Error import InsufficientFundsError from lbrynet.core.Error import InsufficientFundsError
@ -183,7 +183,7 @@ class ConnectionManager(object):
log.debug("Couldn't find a good peer to connect to") log.debug("Couldn't find a good peer to connect to")
return None return None
if len(self._peer_connections) < MAX_CONNECTIONS_PER_STREAM: if len(self._peer_connections) < settings.max_connections_per_stream:
ordered_request_creators = self._rank_request_creator_connections() ordered_request_creators = self._rank_request_creator_connections()
d = get_new_peers(ordered_request_creators) d = get_new_peers(ordered_request_creators)
d.addCallback(pick_best_peer) d.addCallback(pick_best_peer)

View file

@ -7,7 +7,7 @@ import traceback
from requests_futures.sessions import FuturesSession from requests_futures.sessions import FuturesSession
import lbrynet import lbrynet
from lbrynet import conf from lbrynet import settings
from lbrynet.core import utils from lbrynet.core import utils
session = FuturesSession() session = FuturesSession()
@ -104,7 +104,7 @@ def configure_file_handler(file_name, **kwargs):
def get_loggly_url(token=None, version=None): def get_loggly_url(token=None, version=None):
token = token or utils.deobfuscate(conf.LOGGLY_TOKEN) token = token or utils.deobfuscate(settings.LOGGLY_TOKEN)
version = version or lbrynet.__version__ version = version or lbrynet.__version__
return LOGGLY_URL.format(token=token, tag='lbrynet-' + version) return LOGGLY_URL.format(token=token, tag='lbrynet-' + version)

View file

@ -6,6 +6,8 @@ import json
import yaml import yaml
import datetime import datetime
from lbrynet import settings
from lbrynet.conf import ADJUSTABLE_SETTINGS
from lbrynet.core.cryptoutils import get_lbry_hash_obj from lbrynet.core.cryptoutils import get_lbry_hash_obj
blobhash_length = get_lbry_hash_obj().digest_size * 2 # digest_size is in bytes, and blob hashes are hex encoded blobhash_length = get_lbry_hash_obj().digest_size * 2 # digest_size is in bytes, and blob hashes are hex encoded
@ -63,21 +65,20 @@ settings_encoders = {
def load_settings(path): def load_settings(path):
ext = os.path.splitext(path)[1] ext = os.path.splitext(path)[1]
f = open(path, 'r') with open(path, 'r') as settings_file:
data = f.read() data = settings_file.read()
f.close()
decoder = settings_decoders.get(ext, False) decoder = settings_decoders.get(ext, False)
assert decoder is not False, "Unknown settings format .%s" % ext assert decoder is not False, "Unknown settings format .%s" % ext
return decoder(data) return decoder(data)
def save_settings(path, settings): def save_settings(path):
to_save = {k: v for k, v in settings.__dict__.iteritems() if k in ADJUSTABLE_SETTINGS}
ext = os.path.splitext(path)[1] ext = os.path.splitext(path)[1]
encoder = settings_encoders.get(ext, False) encoder = settings_encoders.get(ext, False)
assert encoder is not False, "Unknown settings format .%s" % ext assert encoder is not False, "Unknown settings format .%s" % ext
f = open(path, 'w') with open(path, 'w') as settings_file:
f.write(encoder(settings)) settings_file.write(encoder(to_save))
f.close()
def today(): def today():

View file

@ -1,7 +1,7 @@
import binascii import binascii
import logging import logging
from Crypto.Cipher import AES from Crypto.Cipher import AES
from lbrynet.conf import BLOB_SIZE from lbrynet import settings
from lbrynet.core.BlobInfo import BlobInfo from lbrynet.core.BlobInfo import BlobInfo
@ -67,7 +67,7 @@ class CryptStreamBlobMaker(object):
self.length = 0 self.length = 0
def write(self, data): def write(self, data):
max_bytes_to_write = BLOB_SIZE - self.length - 1 max_bytes_to_write = settings.BLOB_SIZE - self.length - 1
done = False done = False
if max_bytes_to_write <= len(data): if max_bytes_to_write <= len(data):
num_bytes_to_write = max_bytes_to_write num_bytes_to_write = max_bytes_to_write

View file

@ -7,7 +7,7 @@ import logging
import os import os
from lbrynet.core.StreamDescriptor import PlainStreamDescriptorWriter from lbrynet.core.StreamDescriptor import PlainStreamDescriptorWriter
from lbrynet.cryptstream.CryptStreamCreator import CryptStreamCreator from lbrynet.cryptstream.CryptStreamCreator import CryptStreamCreator
from lbrynet import conf from lbrynet import settings
from lbrynet.lbryfile.StreamDescriptor import get_sd_info from lbrynet.lbryfile.StreamDescriptor import get_sd_info
from lbrynet.core.cryptoutils import get_lbry_hash_obj from lbrynet.core.cryptoutils import get_lbry_hash_obj
from twisted.protocols.basic import FileSender from twisted.protocols.basic import FileSender
@ -130,7 +130,7 @@ def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=Non
def make_stream_desc_file(stream_hash): def make_stream_desc_file(stream_hash):
log.debug("creating the stream descriptor file") log.debug("creating the stream descriptor file")
descriptor_file_path = os.path.join(session.db_dir, file_name + conf.CRYPTSD_FILE_EXTENSION) descriptor_file_path = os.path.join(session.db_dir, file_name + settings.CRYPTSD_FILE_EXTENSION)
descriptor_writer = PlainStreamDescriptorWriter(descriptor_file_path) descriptor_writer = PlainStreamDescriptorWriter(descriptor_file_path)
d = get_sd_info(lbry_file_manager.stream_info_manager, stream_hash, True) d = get_sd_info(lbry_file_manager.stream_info_manager, stream_hash, True)

View file

@ -6,7 +6,7 @@ from lbrynet.core.cryptoutils import get_lbry_hash_obj, get_pub_key, sign_with_p
from Crypto import Random from Crypto import Random
import binascii import binascii
import logging import logging
from lbrynet.conf import CRYPTSD_FILE_EXTENSION from lbrynet import settings
from twisted.internet import interfaces, defer from twisted.internet import interfaces, defer
from twisted.protocols.basic import FileSender from twisted.protocols.basic import FileSender
from zope.interface import implements from zope.interface import implements
@ -23,7 +23,7 @@ class LiveStreamCreator(CryptStreamCreator):
self.stream_info_manager = stream_info_manager self.stream_info_manager = stream_info_manager
self.delete_after_num = delete_after_num self.delete_after_num = delete_after_num
self.secret_pass_phrase = secret_pass_phrase self.secret_pass_phrase = secret_pass_phrase
self.file_extension = CRYPTSD_FILE_EXTENSION self.file_extension = settings.CRYPTSD_FILE_EXTENSION
self.finished_blob_hashes = {} self.finished_blob_hashes = {}
def _save_stream(self): def _save_stream(self):

View file

@ -3,7 +3,7 @@ import logging
from zope.interface import implements from zope.interface import implements
from twisted.internet import defer from twisted.internet import defer
from twisted.python.failure import Failure from twisted.python.failure import Failure
from lbrynet.conf import MAX_BLOB_INFOS_TO_REQUEST from lbrynet import settings
from lbrynet.core.client.ClientRequest import ClientRequest, ClientPaidRequest from lbrynet.core.client.ClientRequest import ClientRequest, ClientPaidRequest
from lbrynet.lbrylive.LiveBlob import LiveBlobInfo from lbrynet.lbrylive.LiveBlob import LiveBlobInfo
from lbrynet.core.cryptoutils import get_lbry_hash_obj, verify_signature from lbrynet.core.cryptoutils import get_lbry_hash_obj, verify_signature
@ -136,7 +136,7 @@ class LiveStreamMetadataHandler(object):
if count is not None: if count is not None:
further_blobs_request['count'] = count further_blobs_request['count'] = count
else: else:
further_blobs_request['count'] = MAX_BLOB_INFOS_TO_REQUEST further_blobs_request['count'] = settings.MAX_BLOB_INFOS_TO_REQUEST
log.debug("Requesting %s blob infos from %s", str(further_blobs_request['count']), str(peer)) log.debug("Requesting %s blob infos from %s", str(further_blobs_request['count']), str(peer))
r_dict = {'further_blobs': further_blobs_request} r_dict = {'further_blobs': further_blobs_request}
response_identifier = 'further_blobs' response_identifier = 'further_blobs'

View file

@ -10,13 +10,13 @@ if sys.platform == "darwin":
from appdirs import user_data_dir from appdirs import user_data_dir
from yapsy.PluginManager import PluginManager from yapsy.PluginManager import PluginManager
from twisted.internet import defer, threads, stdio, task, error from twisted.internet import defer, threads, stdio, task, error
from jsonrpc.proxy import JSONRPCProxy from lbrynet.lbrynet_daemon.auth.client import LBRYAPIClient
from lbrynet.core.Session import Session from lbrynet.core.Session import Session
from lbrynet.lbrynet_console.ConsoleControl import ConsoleControl from lbrynet.lbrynet_console.ConsoleControl import ConsoleControl
from lbrynet.lbrynet_console.Settings import Settings from lbrynet.lbrynet_console.Settings import Settings
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, API_CONNECTION_STRING # , MIN_BLOB_INFO_PAYMENT_RATE from lbrynet import settings
from lbrynet.core.utils import generate_id from lbrynet.core.utils import generate_id
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier
from lbrynet.core.PaymentRateManager import PaymentRateManager from lbrynet.core.PaymentRateManager import PaymentRateManager
@ -209,7 +209,7 @@ class Console():
def _get_session(self): def _get_session(self):
def get_default_data_rate(): def get_default_data_rate():
d = self.settings.get_default_data_payment_rate() d = self.settings.get_default_data_payment_rate()
d.addCallback(lambda rate: {"default_data_payment_rate": rate if rate is not None else MIN_BLOB_DATA_PAYMENT_RATE}) d.addCallback(lambda rate: {"default_data_payment_rate": rate if rate is not None else settings.data_rate})
return d return d
def get_wallet(): def get_wallet():
@ -537,7 +537,7 @@ def launch_lbry_console():
os.mkdir(data_dir) os.mkdir(data_dir)
created_data_dir = True created_data_dir = True
daemon = JSONRPCProxy.from_url(API_CONNECTION_STRING) daemon = LBRYAPIClient.config()
try: try:
daemon.is_running() daemon.is_running()
log.info("Attempt to start lbrynet-console while lbrynet-daemon is running") log.info("Attempt to start lbrynet-console while lbrynet-daemon is running")

View file

@ -23,40 +23,37 @@ from twisted.internet.task import LoopingCall
from txjsonrpc import jsonrpclib from txjsonrpc import jsonrpclib
from jsonschema import ValidationError from jsonschema import ValidationError
from lbrynet import __version__ as lbrynet_version
from lbryum.version import LBRYUM_VERSION as lbryum_version from lbryum.version import LBRYUM_VERSION as lbryum_version
from lbrynet import __version__ as lbrynet_version
from lbrynet import settings as lbrynet_settings
from lbrynet import analytics from lbrynet import analytics
from lbrynet import reflector
from lbrynet.metadata.Metadata import Metadata, verify_name_characters
from lbrynet.metadata.Fee import FeeValidator
from lbrynet.core import log_support
from lbrynet.core import utils
from lbrynet.core.utils import generate_id
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader
from lbrynet.core.Session import Session
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
from lbrynet.core.Error import UnknownNameError, InsufficientFundsError, InvalidNameError from lbrynet.core.Error import UnknownNameError, InsufficientFundsError, InvalidNameError
from lbrynet.core.PTCWallet import PTCWallet
from lbrynet.core.Wallet import LBRYcrdWallet, LBRYumWallet
from lbrynet.lbrynet_console.Settings import Settings
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaverFactory, EncryptedFileOpenerFactory from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaverFactory, EncryptedFileOpenerFactory
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager
from lbrynet.lbryfile.EncryptedFileMetadataManager import TempEncryptedFileMetadataManager
from lbrynet.lbrynet_daemon.UIManager import UIManager from lbrynet.lbrynet_daemon.UIManager import UIManager
from lbrynet.lbrynet_daemon.Downloader import GetStream from lbrynet.lbrynet_daemon.Downloader import GetStream
from lbrynet.lbrynet_daemon.Publisher import Publisher from lbrynet.lbrynet_daemon.Publisher import Publisher
from lbrynet.lbrynet_daemon.ExchangeRateManager import ExchangeRateManager from lbrynet.lbrynet_daemon.ExchangeRateManager import ExchangeRateManager
from lbrynet.lbrynet_daemon.Lighthouse import LighthouseClient from lbrynet.lbrynet_daemon.Lighthouse import LighthouseClient
from lbrynet.lbrynet_daemon.auth.server import AuthJSONRPCServer from lbrynet.lbrynet_daemon.auth.server import AuthJSONRPCServer
from lbrynet.metadata.Metadata import Metadata, verify_name_characters
from lbrynet.core import log_support
from lbrynet.core import utils
from lbrynet.core.utils import generate_id
from lbrynet.lbrynet_console.Settings import Settings
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, DEFAULT_MAX_SEARCH_RESULTS
from lbrynet.conf import KNOWN_DHT_NODES, DEFAULT_MAX_KEY_FEE, DEFAULT_WALLET
from lbrynet.conf import DEFAULT_SEARCH_TIMEOUT, DEFAULT_CACHE_TIME
from lbrynet.conf import LOG_POST_URL, LOG_FILE_NAME, REFLECTOR_SERVERS, SEARCH_SERVERS
from lbrynet.conf import DEFAULT_SD_DOWNLOAD_TIMEOUT, DEFAULT_UI_BRANCH
from lbrynet.conf import DEFAULT_TIMEOUT
from lbrynet import conf
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader
from lbrynet.core.Session import Session
from lbrynet.core.PTCWallet import PTCWallet
from lbrynet.core.Wallet import LBRYcrdWallet, LBRYumWallet
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager, TempEncryptedFileMetadataManager
from lbrynet import reflector
# TODO: this code snippet is everywhere. Make it go away # TODO: this code snippet is everywhere. Make it go away
@ -68,7 +65,7 @@ else:
if not os.path.isdir(log_dir): if not os.path.isdir(log_dir):
os.mkdir(log_dir) os.mkdir(log_dir)
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME) lbrynet_log = os.path.join(log_dir, lbrynet_settings.LOG_FILE_NAME)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -135,225 +132,81 @@ class Daemon(AuthJSONRPCServer):
LBRYnet daemon, a jsonrpc interface to lbry functions LBRYnet daemon, a jsonrpc interface to lbry functions
""" """
def __init__(self, root, wallet_type=None): def __init__(self, root, use_authentication=lbrynet_settings.USE_AUTH_HTTP):
AuthJSONRPCServer.__init__(self) AuthJSONRPCServer.__init__(self, use_authentication)
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
self.allowed_during_startup = ['is_running', 'is_first_run', self.allowed_during_startup = ['is_running', 'is_first_run',
'get_time_behind_blockchain', 'stop', 'get_time_behind_blockchain', 'stop',
'daemon_status', 'get_start_notice', 'daemon_status', 'get_start_notice',
'version', 'get_search_servers'] 'version', 'get_search_servers']
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown) last_version = {'last_version': {'lbrynet': lbrynet_version, 'lbryum': lbryum_version}}
lbrynet_settings.update(last_version)
self.db_dir = lbrynet_settings.DATA_DIR
self.download_directory = lbrynet_settings.download_directory
self.created_data_dir = False
if not os.path.exists(self.db_dir):
os.mkdir(self.db_dir)
self.created_data_dir = True
if lbrynet_settings.BLOBFILES_DIR == "blobfiles":
self.blobfile_dir = os.path.join(self.db_dir, "blobfiles")
else:
log.info("Using non-default blobfiles directory: %s", lbrynet_settings.BLOBFILES_DIR)
self.blobfile_dir = lbrynet_settings.BLOBFILES_DIR
self.run_on_startup = lbrynet_settings.run_on_startup
self.data_rate = lbrynet_settings.data_rate
self.max_key_fee = lbrynet_settings.max_key_fee
self.max_upload = lbrynet_settings.max_upload
self.max_download = lbrynet_settings.max_download
self.upload_log = lbrynet_settings.upload_log
self.search_timeout = lbrynet_settings.search_timeout
self.download_timeout = lbrynet_settings.download_timeout
self.max_search_results = lbrynet_settings.max_search_results
self.run_reflector_server = lbrynet_settings.run_reflector_server
self.wallet_type = lbrynet_settings.WALLET
self.delete_blobs_on_remove = lbrynet_settings.delete_blobs_on_remove
self.peer_port = lbrynet_settings.peer_port
self.reflector_port = lbrynet_settings.reflector_port
self.dht_node_port = lbrynet_settings.dht_node_port
self.use_upnp = lbrynet_settings.use_upnp
self.start_lbrycrdd = lbrynet_settings.start_lbrycrdd
self.cache_time = lbrynet_settings.cache_time
self.startup_scripts = lbrynet_settings.startup_scripts
self.startup_status = STARTUP_STAGES[0] self.startup_status = STARTUP_STAGES[0]
self.startup_message = None self.startup_message = None
self.announced_startup = False self.announced_startup = False
self.connected_to_internet = True self.connected_to_internet = True
self.connection_problem = None self.connection_problem = None
self.query_handlers = {}
self.git_lbrynet_version = None self.git_lbrynet_version = None
self.git_lbryum_version = None self.git_lbryum_version = None
self.ui_version = None self.ui_version = None
self.ip = None self.ip = None
# TODO: this is confusing to set here, and then to be reset below.
self.wallet_type = wallet_type
self.first_run = None self.first_run = None
self.log_file = lbrynet_log self.log_file = lbrynet_log
self.current_db_revision = 1 self.current_db_revision = 1
self.run_server = True
self.session = None self.session = None
self.exchange_rate_manager = ExchangeRateManager()
self.lighthouse_client = LighthouseClient()
self.waiting_on = {}
self.streams = {}
self.pending_claims = {}
self.known_dht_nodes = KNOWN_DHT_NODES
self.first_run_after_update = False self.first_run_after_update = False
self.uploaded_temp_files = [] self.uploaded_temp_files = []
self._session_id = base58.b58encode(generate_id()) self._session_id = base58.b58encode(generate_id())
self.lbryid = None
if os.name == "nt":
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
default_download_directory = get_path(FOLDERID.Downloads, UserHandle.current)
self.db_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbrynet")
try:
os.makedirs(self.db_dir)
except OSError:
if not os.path.isdir(self.db_dir):
raise
elif sys.platform == "darwin":
default_download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
self.db_dir = user_data_dir("LBRY")
else:
default_download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
self.db_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
try:
if not os.path.isdir(default_download_directory):
os.mkdir(default_download_directory)
except:
log.info("Couldn't make download directory, using home")
default_download_directory = os.path.expanduser("~")
old_conf_path = os.path.join(self.db_dir, 'daemon_settings.json')
self.daemon_conf = os.path.join(self.db_dir, 'daemon_settings.yml')
if os.path.isfile(old_conf_path):
log.info("Migrating .json config file to .yml")
tmp_settings = utils.load_settings(old_conf_path)
utils.save_settings(self.daemon_conf, tmp_settings)
try:
os.remove(old_conf_path)
log.info("Cleaned up old config file")
except:
log.warning("Failed to remove old config file")
self.default_settings = {
'run_on_startup': False,
'data_rate': MIN_BLOB_DATA_PAYMENT_RATE,
'max_key_fee': DEFAULT_MAX_KEY_FEE,
'download_directory': default_download_directory,
'max_upload': 0.0,
'max_download': 0.0,
'upload_log': True,
'search_timeout': DEFAULT_SEARCH_TIMEOUT,
'download_timeout': DEFAULT_TIMEOUT,
'max_search_results': DEFAULT_MAX_SEARCH_RESULTS,
'wallet_type': DEFAULT_WALLET,
'delete_blobs_on_remove': True,
'peer_port': 3333,
'dht_node_port': 4444,
'reflector_port': 5566,
'use_upnp': True,
'start_lbrycrdd': True,
'requested_first_run_credits': False,
'run_reflector_server': False,
'cache_time': DEFAULT_CACHE_TIME,
'startup_scripts': [],
'last_version': {'lbrynet': lbrynet_version, 'lbryum': lbryum_version}
}
if os.path.isfile(self.daemon_conf):
loaded_settings = utils.load_settings(self.daemon_conf)
missing_settings = {}
removed_settings = {}
for k in self.default_settings.keys():
if k not in loaded_settings.keys():
missing_settings[k] = self.default_settings[k]
for k in loaded_settings.keys():
if not k in self.default_settings.keys():
log.info("Removing unused setting: " + k + " with value: " + str(loaded_settings[k]))
removed_settings[k] = loaded_settings[k]
del loaded_settings[k]
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:
log.info("Updated and loaded lbrynet-daemon configuration")
else:
log.info("Loaded lbrynet-daemon configuration")
self.session_settings = loaded_settings
else:
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']
self.first_run_after_update = True
log.info("First run after update")
log.info("lbrynet %s --> %s" % (self.session_settings['last_version']['lbrynet'], self.default_settings['last_version']['lbrynet']))
log.info("lbryum %s --> %s" % (self.session_settings['last_version']['lbryum'], self.default_settings['last_version']['lbryum']))
if "0.4.5" == self.default_settings['last_version']['lbrynet']:
log.info("Lowering name cache time")
self.session_settings['cache_time'] = DEFAULT_CACHE_TIME
utils.save_settings(self.daemon_conf, self.session_settings)
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']
self.download_directory = self.session_settings['download_directory']
self.max_upload = self.session_settings['max_upload']
self.max_download = self.session_settings['max_download']
self.upload_log = self.session_settings['upload_log']
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.run_reflector_server = self.session_settings['run_reflector_server']
####
#
# Ignore the saved wallet type. Some users will have their wallet type
# saved as lbrycrd and we want wallets to be lbryum unless explicitly
# set on the command line to be lbrycrd.
#
# 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)
#
# Instead, if wallet is not set on the command line, default to the default wallet
#
if wallet_type:
log.info("Using wallet type %s specified from command line", wallet_type)
self.wallet_type = wallet_type
else:
log.info("Using the default wallet type %s", DEFAULT_WALLET)
self.wallet_type = DEFAULT_WALLET
if self.wallet_type not in conf.WALLET_TYPES:
raise ValueError('Wallet Type {} is not valid'.format(wallet_type))
#
####
self.delete_blobs_on_remove = self.session_settings['delete_blobs_on_remove']
self.peer_port = self.session_settings['peer_port']
self.reflector_port = self.session_settings['reflector_port']
self.dht_node_port = self.session_settings['dht_node_port']
self.use_upnp = self.session_settings['use_upnp']
self.start_lbrycrdd = self.session_settings['start_lbrycrdd']
self.requested_first_run_credits = self.session_settings['requested_first_run_credits']
self.cache_time = self.session_settings['cache_time']
self.startup_scripts = self.session_settings['startup_scripts']
if os.path.isfile(os.path.join(self.db_dir, "stream_info_cache.json")):
f = open(os.path.join(self.db_dir, "stream_info_cache.json"), "r")
self.name_cache = json.loads(f.read())
f.close()
log.info("Loaded claim info cache")
else:
self.name_cache = {}
self.set_wallet_attributes()
if os.name != 'nt':
# TODO: are we still using this?
lbrycrdd_path_conf = os.path.join(os.path.expanduser("~"), ".lbrycrddpath.conf")
if not os.path.isfile(lbrycrdd_path_conf):
f = open(lbrycrdd_path_conf, "w")
f.write(str(self.lbrycrdd_path))
f.close()
self.created_data_dir = False
if not os.path.exists(self.db_dir):
os.mkdir(self.db_dir)
self.created_data_dir = True
self.blobfile_dir = os.path.join(self.db_dir, "blobfiles")
self.wallet_user = None self.wallet_user = None
self.wallet_password = None self.wallet_password = None
self.query_handlers = {}
self.waiting_on = {}
self.streams = {}
self.pending_claims = {}
self.name_cache = {}
self.set_wallet_attributes()
self.internet_connection_checker = LoopingCall(self._check_network_connection) self.internet_connection_checker = LoopingCall(self._check_network_connection)
self.version_checker = LoopingCall(self._check_remote_versions) self.version_checker = LoopingCall(self._check_remote_versions)
self.connection_problem_checker = LoopingCall(self._check_connection_problems) self.connection_problem_checker = LoopingCall(self._check_connection_problems)
self.pending_claim_checker = LoopingCall(self._check_pending_claims) self.pending_claim_checker = LoopingCall(self._check_pending_claims)
self.send_heartbeat = LoopingCall(self._send_heartbeat) self.send_heartbeat = LoopingCall(self._send_heartbeat)
# self.lbrynet_connection_checker = LoopingCall(self._check_lbrynet_connection) self.exchange_rate_manager = ExchangeRateManager()
self.lighthouse_client = LighthouseClient()
self.sd_identifier = StreamDescriptorIdentifier() self.sd_identifier = StreamDescriptorIdentifier()
self.stream_info_manager = TempEncryptedFileMetadataManager() self.stream_info_manager = TempEncryptedFileMetadataManager()
self.settings = Settings(self.db_dir) self.settings = Settings(self.db_dir)
@ -362,16 +215,6 @@ class Daemon(AuthJSONRPCServer):
self.lbry_file_metadata_manager = None self.lbry_file_metadata_manager = None
self.lbry_file_manager = None self.lbry_file_manager = None
if self.wallet_type == "lbrycrd":
if os.path.isfile(self.lbrycrd_conf):
log.info("Using lbrycrd.conf found at " + self.lbrycrd_conf)
else:
log.info("No lbrycrd.conf found at " + self.lbrycrd_conf + ". Generating now...")
password = "".join(random.SystemRandom().choice(string.ascii_letters + string.digits + "_") for i in range(20))
with open(self.lbrycrd_conf, 'w') as f:
f.write("rpcuser=rpcuser\n")
f.write("rpcpassword=" + password)
log.info("Done writing lbrycrd.conf")
@AuthJSONRPCServer.subhandler @AuthJSONRPCServer.subhandler
def _exclude_lbrycrd_only_commands_from_lbryum_session(self, request): def _exclude_lbrycrd_only_commands_from_lbryum_session(self, request):
@ -402,7 +245,7 @@ class Daemon(AuthJSONRPCServer):
self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf") self.lbrycrd_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf") self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
def setup(self, branch=DEFAULT_UI_BRANCH, user_specified=False, branch_specified=False, host_ui=True): def setup(self):
def _log_starting_vals(): def _log_starting_vals():
log.info("Starting balance: " + str(self.session.wallet.wallet_balance)) log.info("Starting balance: " + str(self.session.wallet.wallet_balance))
return defer.succeed(None) return defer.succeed(None)
@ -440,18 +283,16 @@ class Daemon(AuthJSONRPCServer):
self.connection_problem_checker.start(1) self.connection_problem_checker.start(1)
self.exchange_rate_manager.start() self.exchange_rate_manager.start()
if host_ui:
self.lbry_ui_manager.update_checker.start(1800, now=False)
d = defer.Deferred() d = defer.Deferred()
if host_ui:
d.addCallback(lambda _: self.lbry_ui_manager.setup(branch=branch, if lbrynet_settings.host_ui:
user_specified=user_specified, self.lbry_ui_manager.update_checker.start(1800, now=False)
branch_specified=branch_specified)) d.addCallback(lambda _: self.lbry_ui_manager.setup())
d.addCallback(lambda _: self._initial_setup()) d.addCallback(lambda _: self._initial_setup())
d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory)) d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory))
d.addCallback(lambda _: self._check_db_migration()) d.addCallback(lambda _: self._check_db_migration())
d.addCallback(lambda _: self._get_settings()) d.addCallback(lambda _: self._get_settings())
d.addCallback(lambda _: self._load_caches())
d.addCallback(lambda _: self._set_events()) d.addCallback(lambda _: self._set_events())
d.addCallback(lambda _: self._get_session()) d.addCallback(lambda _: self._get_session())
d.addCallback(lambda _: add_lbry_file_to_sd_identifier(self.sd_identifier)) d.addCallback(lambda _: add_lbry_file_to_sd_identifier(self.sd_identifier))
@ -507,6 +348,12 @@ class Daemon(AuthJSONRPCServer):
d = _log_platform() d = _log_platform()
return d return d
def _load_caches(self):
if os.path.isfile(os.path.join(self.db_dir, "stream_info_cache.json")):
with open(os.path.join(self.db_dir, "stream_info_cache.json"), "r") as stream_info_cache:
self.name_cache = json.loads(stream_info_cache.read())
log.info("Loaded claim info cache")
def _set_events(self): def _set_events(self):
context = analytics.make_context(self._get_platform(), self.wallet_type) context = analytics.make_context(self._get_platform(), self.wallet_type)
self._events = analytics.Events(context, base58.b58encode(self.lbryid), self._session_id) self._events = analytics.Events(context, base58.b58encode(self.lbryid), self._session_id)
@ -736,7 +583,7 @@ class Daemon(AuthJSONRPCServer):
'type': "%s-%s" % (lm, log_type) if log_type else lm, 'type': "%s-%s" % (lm, log_type) if log_type else lm,
'log': log_contents 'log': log_contents
} }
requests.post(LOG_POST_URL, params) requests.post(lbrynet_settings.LOG_POST_URL, params)
return defer.succeed(None) return defer.succeed(None)
else: else:
@ -779,87 +626,43 @@ class Daemon(AuthJSONRPCServer):
return d return d
def _update_settings(self, settings): def _update_settings(self, settings):
for k in settings.keys(): setting_types = {
if k == 'run_on_startup': 'run_on_startup': bool,
if type(settings['run_on_startup']) is bool: 'data_rate': float,
self.session_settings['run_on_startup'] = settings['run_on_startup'] 'max_key_fee': float,
else: 'download_directory': str,
return defer.fail() 'max_upload': float,
elif k == 'data_rate': 'max_download': float,
if type(settings['data_rate']) is float: 'upload_log': bool,
self.session_settings['data_rate'] = settings['data_rate'] 'download_timeout': int,
elif type(settings['data_rate']) is int: 'search_timeout': float,
self.session_settings['data_rate'] = float(settings['data_rate']) 'cache_time': int
else: }
return defer.fail()
elif k == 'max_key_fee':
if type(settings['max_key_fee']) is float:
self.session_settings['max_key_fee'] = settings['max_key_fee']
elif type(settings['max_key_fee']) is int:
self.session_settings['max_key_fee'] = float(settings['max_key_fee'])
else:
return defer.fail()
elif k == 'download_directory':
if type(settings['download_directory']) is unicode:
if os.path.isdir(settings['download_directory']):
self.session_settings['download_directory'] = settings['download_directory']
else:
pass
else:
return defer.fail()
elif k == 'max_upload':
if type(settings['max_upload']) is float:
self.session_settings['max_upload'] = settings['max_upload']
elif type(settings['max_upload']) is int:
self.session_settings['max_upload'] = float(settings['max_upload'])
else:
return defer.fail()
elif k == 'max_download':
if type(settings['max_download']) is float:
self.session_settings['max_download'] = settings['max_download']
if type(settings['max_download']) is int:
self.session_settings['max_download'] = float(settings['max_download'])
else:
return defer.fail()
elif k == 'upload_log':
if type(settings['upload_log']) is bool:
self.session_settings['upload_log'] = settings['upload_log']
else:
return defer.fail()
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'] for key, setting_type in setting_types.iteritems():
self.data_rate = self.session_settings['data_rate'] if key in settings:
self.max_key_fee = self.session_settings['max_key_fee'] if isinstance(settings[key], setting_type):
self.download_directory = self.session_settings['download_directory'] lbrynet_settings.update({key: settings[key]})
self.max_upload = self.session_settings['max_upload'] elif key == "max_key_fee" and isinstance(FeeValidator(settings[key]).amount, setting_type):
self.max_download = self.session_settings['max_download'] lbrynet_settings.update({key: settings[key]})
self.upload_log = self.session_settings['upload_log'] else:
self.download_timeout = self.session_settings['download_timeout'] try:
self.search_timeout = self.session_settings['search_timeout'] converted = setting_type(settings[key])
self.cache_time = self.session_settings['cache_time'] lbrynet_settings.update({key: converted})
except Exception as err:
log.warning(err.message)
log.warning("error converting setting '%s' to type %s", key, setting_type)
utils.save_settings(self.daemon_conf, self.session_settings) self.run_on_startup = lbrynet_settings.run_on_startup
self.data_rate = lbrynet_settings.data_rate
self.max_key_fee = lbrynet_settings.max_key_fee
self.download_directory = lbrynet_settings.download_directory
self.max_upload = lbrynet_settings.max_upload
self.max_download = lbrynet_settings.max_download
self.upload_log = lbrynet_settings.upload_log
self.download_timeout = lbrynet_settings.download_timeout
self.search_timeout = lbrynet_settings.search_timeout
self.cache_time = lbrynet_settings.cache_time
return defer.succeed(True) return defer.succeed(True)
@ -946,7 +749,7 @@ class Daemon(AuthJSONRPCServer):
def get_default_data_rate(): def get_default_data_rate():
d = self.settings.get_default_data_payment_rate() d = self.settings.get_default_data_payment_rate()
d.addCallback(lambda rate: {"default_data_payment_rate": rate if rate is not None else d.addCallback(lambda rate: {"default_data_payment_rate": rate if rate is not None else
MIN_BLOB_DATA_PAYMENT_RATE}) lbrynet_settings.data_rate})
return d return d
def get_wallet(): def get_wallet():
@ -960,8 +763,8 @@ class Daemon(AuthJSONRPCServer):
elif self.wallet_type == "lbryum": elif self.wallet_type == "lbryum":
log.info("Using lbryum wallet") log.info("Using lbryum wallet")
config = {'auto-connect': True} config = {'auto-connect': True}
if conf.LBRYUM_WALLET_DIR: if lbrynet_settings.LBRYUM_WALLET_DIR:
config['lbryum_path'] = conf.LBRYUM_WALLET_DIR config['lbryum_path'] = lbrynet_settings.LBRYUM_WALLET_DIR
d = defer.succeed(LBRYumWallet(self.db_dir, config)) d = defer.succeed(LBRYumWallet(self.db_dir, config))
elif self.wallet_type == "ptc": elif self.wallet_type == "ptc":
log.info("Using PTC wallet") log.info("Using PTC wallet")
@ -984,7 +787,7 @@ class Daemon(AuthJSONRPCServer):
def create_session(results): def create_session(results):
self.session = Session(results['default_data_payment_rate'], db_dir=self.db_dir, lbryid=self.lbryid, self.session = Session(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, blob_dir=self.blobfile_dir, dht_node_port=self.dht_node_port,
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port, known_dht_nodes=lbrynet_settings.known_dht_nodes, peer_port=self.peer_port,
use_upnp=self.use_upnp, wallet=results['wallet']) use_upnp=self.use_upnp, wallet=results['wallet'])
self.startup_status = STARTUP_STAGES[2] self.startup_status = STARTUP_STAGES[2]
@ -1006,7 +809,7 @@ class Daemon(AuthJSONRPCServer):
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, file_opener_factory) self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, file_opener_factory)
return defer.succeed(None) return defer.succeed(None)
def _download_sd_blob(self, sd_hash, timeout=DEFAULT_SD_DOWNLOAD_TIMEOUT): def _download_sd_blob(self, sd_hash, timeout=lbrynet_settings.sd_download_timeout):
def cb(result): def cb(result):
if not r.called: if not r.called:
r.callback(result) r.callback(result)
@ -1024,7 +827,7 @@ class Daemon(AuthJSONRPCServer):
return r return r
def _download_name(self, name, timeout=DEFAULT_TIMEOUT, download_directory=None, def _download_name(self, name, timeout=lbrynet_settings.download_timeout, download_directory=None,
file_name=None, stream_info=None, wait_for_write=True): file_name=None, stream_info=None, wait_for_write=True):
""" """
Add a lbry file to the file manager, start the download, and return the new lbry file. Add a lbry file to the file manager, start the download, and return the new lbry file.
@ -1275,7 +1078,7 @@ class Daemon(AuthJSONRPCServer):
log.info("Reflecting stream: %s" % stream_hash) log.info("Reflecting stream: %s" % stream_hash)
reflector_server = random.choice(REFLECTOR_SERVERS) reflector_server = random.choice(lbrynet_settings.REFLECTOR_SERVERS)
reflector_address, reflector_port = reflector_server[0], reflector_server[1] reflector_address, reflector_port = reflector_server[0], reflector_server[1]
log.info("Start reflector client") log.info("Start reflector client")
factory = reflector.ClientFactory( factory = reflector.ClientFactory(
@ -1294,7 +1097,7 @@ class Daemon(AuthJSONRPCServer):
log.info("Reflecting %i blobs" % len(blob_hashes)) log.info("Reflecting %i blobs" % len(blob_hashes))
reflector_server = random.choice(REFLECTOR_SERVERS) reflector_server = random.choice(lbrynet_settings.REFLECTOR_SERVERS)
reflector_address, reflector_port = reflector_server[0], reflector_server[1] reflector_address, reflector_port = reflector_server[0], reflector_server[1]
log.info("Start reflector client") log.info("Start reflector client")
factory = reflector.BlobClientFactory( factory = reflector.BlobClientFactory(
@ -1317,9 +1120,9 @@ class Daemon(AuthJSONRPCServer):
log.info("Removing one time startup scripts") log.info("Removing one time startup scripts")
remaining_scripts = [s for s in self.startup_scripts if 'run_once' not in s.keys()] remaining_scripts = [s for s in self.startup_scripts if 'run_once' not in s.keys()]
startup_scripts = self.startup_scripts startup_scripts = self.startup_scripts
self.startup_scripts = self.session_settings['startup_scripts'] = remaining_scripts self.startup_scripts = lbrynet_settings['startup_scripts'] = remaining_scripts
utils.save_settings(self.daemon_conf, self.session_settings) utils.save_settings(self.daemon_conf, lbrynet_settings)
for script in startup_scripts: for script in startup_scripts:
if script['script_name'] == 'migrateto025': if script['script_name'] == 'migrateto025':
@ -1469,7 +1272,6 @@ class Daemon(AuthJSONRPCServer):
log.info("Get version info: " + json.dumps(msg)) log.info("Get version info: " + json.dumps(msg))
return self._render_response(msg, OK_CODE) return self._render_response(msg, OK_CODE)
@AuthJSONRPCServer.auth_required
def jsonrpc_get_settings(self): def jsonrpc_get_settings(self):
""" """
Get lbrynet daemon settings Get lbrynet daemon settings
@ -1496,9 +1298,9 @@ class Daemon(AuthJSONRPCServer):
""" """
log.info("Get daemon settings") log.info("Get daemon settings")
return self._render_response(self.session_settings, OK_CODE) return self._render_response(lbrynet_settings.configurable_settings, OK_CODE)
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_set_settings(self, p): def jsonrpc_set_settings(self, p):
""" """
Set lbrynet daemon settings Set lbrynet daemon settings
@ -1517,12 +1319,12 @@ class Daemon(AuthJSONRPCServer):
""" """
def _log_settings_change(): def _log_settings_change():
log.info("Set daemon settings to " + json.dumps(self.session_settings)) log.info("Set daemon settings to " + json.dumps(lbrynet_settings.configurable_settings))
d = self._update_settings(p) d = self._update_settings(p)
d.addErrback(lambda err: log.info(err.getTraceback())) d.addErrback(lambda err: log.info(err.getTraceback()))
d.addCallback(lambda _: _log_settings_change()) d.addCallback(lambda _: _log_settings_change())
d.addCallback(lambda _: self._render_response(self.session_settings, OK_CODE)) d.addCallback(lambda _: self._render_response(lbrynet_settings.configurable_settings, OK_CODE))
return d return d
@ -1550,7 +1352,6 @@ class Daemon(AuthJSONRPCServer):
else: else:
return self._render_response(self.jsonrpc_help.__doc__, OK_CODE) return self._render_response(self.jsonrpc_help.__doc__, OK_CODE)
@AuthJSONRPCServer.auth_required
def jsonrpc_get_balance(self): def jsonrpc_get_balance(self):
""" """
Get balance Get balance
@ -1583,7 +1384,6 @@ class Daemon(AuthJSONRPCServer):
return self._render_response("Shutting down", OK_CODE) return self._render_response("Shutting down", OK_CODE)
@AuthJSONRPCServer.auth_required
def jsonrpc_get_lbry_files(self): def jsonrpc_get_lbry_files(self):
""" """
Get LBRY files Get LBRY files
@ -1610,7 +1410,6 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_get_lbry_file(self, p): def jsonrpc_get_lbry_file(self, p):
""" """
Get lbry file Get lbry file
@ -1661,6 +1460,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallbacks(lambda info: self._render_response(info, OK_CODE), lambda _: server.failure) d.addCallbacks(lambda info: self._render_response(info, OK_CODE), lambda _: server.failure)
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_get_my_claim(self, p): def jsonrpc_get_my_claim(self, p):
""" """
Return existing claim for a given name Return existing claim for a given name
@ -1700,7 +1500,6 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required
def _process_get_parameters(self, p): def _process_get_parameters(self, p):
"""Extract info from input parameters and fill in default values for `get` call.""" """Extract info from input parameters and fill in default values for `get` call."""
# TODO: this process can be abstracted s.t. each method # TODO: this process can be abstracted s.t. each method
@ -1722,7 +1521,7 @@ class Daemon(AuthJSONRPCServer):
name=name name=name
) )
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_get(self, p): def jsonrpc_get(self, p):
"""Download stream from a LBRY uri. """Download stream from a LBRY uri.
@ -1753,7 +1552,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda message: self._render_response(message, OK_CODE)) d.addCallback(lambda message: self._render_response(message, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_stop_lbry_file(self, p): def jsonrpc_stop_lbry_file(self, p):
""" """
Stop lbry file Stop lbry file
@ -1779,7 +1578,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_start_lbry_file(self, p): def jsonrpc_start_lbry_file(self, p):
""" """
Stop lbry file Stop lbry file
@ -1820,7 +1619,6 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_search_nametrie(self, p): def jsonrpc_search_nametrie(self, p):
""" """
Search the nametrie for claims Search the nametrie for claims
@ -1857,7 +1655,7 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_delete_lbry_file(self, p): def jsonrpc_delete_lbry_file(self, p):
""" """
Delete a lbry file Delete a lbry file
@ -1887,7 +1685,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_publish(self, p): def jsonrpc_publish(self, p):
""" """
Make a new name claim and publish associated data to lbrynet Make a new name claim and publish associated data to lbrynet
@ -1964,7 +1762,7 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_abandon_claim(self, p): def jsonrpc_abandon_claim(self, p):
""" """
Abandon a name and reclaim credits from the claim Abandon a name and reclaim credits from the claim
@ -1991,7 +1789,7 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_abandon_name(self, p): def jsonrpc_abandon_name(self, p):
""" """
DEPRECIATED, use abandon_claim DEPRECIATED, use abandon_claim
@ -2004,7 +1802,7 @@ class Daemon(AuthJSONRPCServer):
return self.jsonrpc_abandon_claim(p) return self.jsonrpc_abandon_claim(p)
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_support_claim(self, p): def jsonrpc_support_claim(self, p):
""" """
Support a name claim Support a name claim
@ -2024,7 +1822,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_get_name_claims(self): def jsonrpc_get_name_claims(self):
""" """
Get my name claims Get my name claims
@ -2063,7 +1861,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_get_transaction_history(self): def jsonrpc_get_transaction_history(self):
""" """
Get transaction history Get transaction history
@ -2094,7 +1892,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_address_is_mine(self, p): def jsonrpc_address_is_mine(self, p):
""" """
Checks if an address is associated with the current wallet. Checks if an address is associated with the current wallet.
@ -2112,7 +1910,7 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_get_public_key_from_wallet(self, p): def jsonrpc_get_public_key_from_wallet(self, p):
""" """
Get public key from wallet address Get public key from wallet address
@ -2150,7 +1948,7 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_get_new_address(self): def jsonrpc_get_new_address(self):
""" """
Generate a new wallet address Generate a new wallet address
@ -2170,7 +1968,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda address: self._render_response(address, OK_CODE)) d.addCallback(lambda address: self._render_response(address, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_send_amount_to_address(self, p): def jsonrpc_send_amount_to_address(self, p):
""" """
Send credits to an address Send credits to an address
@ -2250,7 +2048,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_download_descriptor(self, p): def jsonrpc_download_descriptor(self, p):
""" """
Download and return a sd blob Download and return a sd blob
@ -2261,7 +2059,7 @@ class Daemon(AuthJSONRPCServer):
sd blob, dict sd blob, dict
""" """
sd_hash = p['sd_hash'] sd_hash = p['sd_hash']
timeout = p.get('timeout', DEFAULT_SD_DOWNLOAD_TIMEOUT) timeout = p.get('timeout', lbrynet_settings.sd_download_timeout)
d = self._download_sd_blob(sd_hash, timeout) d = self._download_sd_blob(sd_hash, timeout)
d.addCallbacks(lambda r: self._render_response(r, OK_CODE), lambda _: self._render_response(False, OK_CODE)) d.addCallbacks(lambda r: self._render_response(r, OK_CODE), lambda _: self._render_response(False, OK_CODE))
@ -2282,7 +2080,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_set_miner(self, p): def jsonrpc_set_miner(self, p):
""" """
Start of stop the miner, function only available when lbrycrd is set as the wallet Start of stop the miner, function only available when lbrycrd is set as the wallet
@ -2302,7 +2100,6 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_get_miner_status(self): def jsonrpc_get_miner_status(self):
""" """
Get status of miner Get status of miner
@ -2372,7 +2169,7 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda _: self._render_response(True, OK_CODE)) d.addCallback(lambda _: self._render_response(True, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_configure_ui(self, p): def jsonrpc_configure_ui(self, p):
""" """
Configure the UI being hosted Configure the UI being hosted
@ -2397,7 +2194,7 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_reveal(self, p): def jsonrpc_reveal(self, p):
""" """
Reveal a file or directory in file browser Reveal a file or directory in file browser
@ -2417,7 +2214,6 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda _: self._render_response(True, OK_CODE)) d.addCallback(lambda _: self._render_response(True, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_get_peers_for_hash(self, p): def jsonrpc_get_peers_for_hash(self, p):
""" """
Get peers for blob hash Get peers for blob hash
@ -2435,7 +2231,6 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_announce_all_blobs_to_dht(self): def jsonrpc_announce_all_blobs_to_dht(self):
""" """
Announce all blobs to the dht Announce all blobs to the dht
@ -2450,7 +2245,6 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda _: self._render_response("Announced", OK_CODE)) d.addCallback(lambda _: self._render_response("Announced", OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_reflect(self, p): def jsonrpc_reflect(self, p):
""" """
Reflect a stream Reflect a stream
@ -2467,7 +2261,6 @@ class Daemon(AuthJSONRPCServer):
d.addCallbacks(lambda _: self._render_response(True, OK_CODE), lambda err: self._render_response(err.getTraceback(), OK_CODE)) d.addCallbacks(lambda _: self._render_response(True, OK_CODE), lambda err: self._render_response(err.getTraceback(), OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_get_blob_hashes(self): def jsonrpc_get_blob_hashes(self):
""" """
Returns all blob hashes Returns all blob hashes
@ -2482,7 +2275,6 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r, OK_CODE)) d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_reflect_all_blobs(self): def jsonrpc_reflect_all_blobs(self):
""" """
Reflects all saved blobs Reflects all saved blobs
@ -2507,7 +2299,7 @@ class Daemon(AuthJSONRPCServer):
List of address:port List of address:port
""" """
d = self._render_response(SEARCH_SERVERS, OK_CODE) d = self._render_response(lbrynet_settings.search_servers, OK_CODE)
return d return d
def jsonrpc_get_mean_availability(self): def jsonrpc_get_mean_availability(self):
@ -2557,6 +2349,12 @@ class Daemon(AuthJSONRPCServer):
return d return d
@AuthJSONRPCServer.auth_required
def jsonrpc_test_api_authentication(self):
if self._use_authentication:
return self._render_response(True, OK_CODE)
return self._render_response("Not using authentication", OK_CODE)
def get_lbrynet_version_from_github(): def get_lbrynet_version_from_github():
"""Return the latest released version from github.""" """Return the latest released version from github."""
@ -2613,7 +2411,7 @@ def get_darwin_lbrycrdd_path():
class _DownloadNameHelper(object): class _DownloadNameHelper(object):
def __init__(self, daemon, name, timeout=DEFAULT_TIMEOUT, download_directory=None, def __init__(self, daemon, name, timeout=lbrynet_settings.download_timeout, download_directory=None,
file_name=None, wait_for_write=True): file_name=None, wait_for_write=True):
self.daemon = daemon self.daemon = daemon
self.name = name self.name = name

View file

@ -11,19 +11,19 @@ from twisted.cred import portal
from jsonrpc.proxy import JSONRPCProxy from jsonrpc.proxy import JSONRPCProxy
from lbrynet.core import log_support from lbrynet.core import log_support, utils
from lbrynet.lbrynet_daemon.auth.auth import PasswordChecker, HttpPasswordRealm from lbrynet.lbrynet_daemon.auth.auth import PasswordChecker, HttpPasswordRealm
from lbrynet.lbrynet_daemon.auth.util import initialize_api_key_file from lbrynet.lbrynet_daemon.auth.util import initialize_api_key_file
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_PORT from lbrynet import settings
from lbrynet.conf import UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
from lbrynet.conf import DATA_DIR as log_dir log_dir = settings.DATA_DIR
if not os.path.isdir(log_dir): if not os.path.isdir(log_dir):
os.mkdir(log_dir) os.mkdir(log_dir)
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME) lbrynet_log = os.path.join(log_dir, settings.LOG_FILE_NAME)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -52,7 +52,7 @@ def stop():
log.info("Attempt to shut down lbrynet-daemon from command line when daemon isn't running") log.info("Attempt to shut down lbrynet-daemon from command line when daemon isn't running")
d = defer.Deferred(None) d = defer.Deferred(None)
d.addCallback(lambda _: JSONRPCProxy.from_url(API_CONNECTION_STRING).stop()) d.addCallback(lambda _: JSONRPCProxy.from_url(settings.API_CONNECTION_STRING).stop())
d.addCallbacks(lambda _: _disp_shutdown(), lambda _: _disp_not_running()) d.addCallbacks(lambda _: _disp_shutdown(), lambda _: _disp_not_running())
d.callback(None) d.callback(None)
@ -62,18 +62,37 @@ def start():
parser.add_argument("--wallet", parser.add_argument("--wallet",
help="lbrycrd or lbryum, default lbryum", help="lbrycrd or lbryum, default lbryum",
type=str, type=str,
default='') default='lbryum')
parser.add_argument("--ui", parser.add_argument("--ui",
help="path to custom UI folder", help="path to custom UI folder",
default=None) default=None)
parser.add_argument("--branch", parser.add_argument("--branch",
help="Branch of lbry-web-ui repo to use, defaults on master") help="Branch of lbry-web-ui repo to use, defaults on master",
parser.add_argument('--no-launch', dest='launchui', action="store_false") default=settings.UI_BRANCH)
parser.add_argument('--log-to-console', dest='logtoconsole', action="store_true")
parser.add_argument('--quiet', dest='quiet', action="store_true") parser.add_argument("--http-auth",
parser.add_argument('--verbose', action='store_true', dest="useauth",
action="store_true")
parser.add_argument('--no-launch',
dest='launchui',
action="store_false")
parser.add_argument('--log-to-console',
dest='logtoconsole',
action="store_true")
parser.add_argument('--quiet',
dest='quiet',
action="store_true")
parser.add_argument('--verbose',
action='store_true',
help='enable more debug output for the console') help='enable more debug output for the console')
parser.set_defaults(branch=False, launchui=True, logtoconsole=False, quiet=False)
parser.set_defaults(branch=False, launchui=True, logtoconsole=False, quiet=False, useauth=False)
args = parser.parse_args() args = parser.parse_args()
log_support.configure_file_handler(lbrynet_log) log_support.configure_file_handler(lbrynet_log)
@ -84,13 +103,26 @@ def start():
if not args.verbose: if not args.verbose:
log_support.disable_noisy_loggers() log_support.disable_noisy_loggers()
to_pass = {}
settings_path = os.path.join(settings.DATA_DIR, "daemon_settings.yml")
if os.path.isfile(settings_path):
to_pass.update(utils.load_settings(settings_path))
log.info("Loaded settings file")
if args.ui:
to_pass.update({'local_ui_path': args.ui})
if args.branch:
to_pass.update({'UI_BRANCH': args.branch})
to_pass.update({'USE_AUTH_HTTP': args.useauth})
to_pass.update({'WALLET': args.wallet})
settings.update(to_pass)
try: try:
JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running() JSONRPCProxy.from_url(settings.API_CONNECTION_STRING).is_running()
log.info("lbrynet-daemon is already running") log.info("lbrynet-daemon is already running")
if not args.logtoconsole: if not args.logtoconsole:
print "lbrynet-daemon is already running" print "lbrynet-daemon is already running"
if args.launchui: if args.launchui:
webbrowser.open(UI_ADDRESS) webbrowser.open(settings.UI_ADDRESS)
return return
except: except:
pass pass
@ -100,30 +132,33 @@ def start():
if not args.logtoconsole and not args.quiet: if not args.logtoconsole and not args.quiet:
print "Starting lbrynet-daemon from command line" print "Starting lbrynet-daemon from command line"
print "To view activity, view the log file here: " + lbrynet_log 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 "Web UI is available at http://%s:%i" % (settings.API_INTERFACE, settings.API_PORT)
print "JSONRPC API is available at " + API_CONNECTION_STRING print "JSONRPC API is available at " + settings.API_CONNECTION_STRING
print "To quit press ctrl-c or call 'stop' via the API" print "To quit press ctrl-c or call 'stop' via the API"
if test_internet_connection(): if test_internet_connection():
lbry = DaemonServer() lbry = DaemonServer()
d = lbry.start(branch=args.branch if args.branch else DEFAULT_UI_BRANCH, d = lbry.start(args.useauth)
user_specified=args.ui,
wallet=args.wallet,
branch_specified=True if args.branch else False)
if args.launchui: if args.launchui:
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS)) d.addCallback(lambda _: webbrowser.open(settings.UI_ADDRESS))
pw_path = os.path.join(log_dir, ".api_keys") if args.useauth:
initialize_api_key_file(pw_path) log.info("Using authenticated API")
checker = PasswordChecker.load_file(pw_path) pw_path = os.path.join(settings.DATA_DIR, ".api_keys")
realm = HttpPasswordRealm(lbry.root) initialize_api_key_file(pw_path)
portal_to_realm = portal.Portal(realm, [checker, ]) checker = PasswordChecker.load_file(pw_path)
factory = guard.BasicCredentialFactory('Login to lbrynet api') realm = HttpPasswordRealm(lbry.root)
protected_resource = guard.HTTPAuthSessionWrapper(portal_to_realm, [factory, ]) portal_to_realm = portal.Portal(realm, [checker, ])
lbrynet_server = server.Site(protected_resource) factory = guard.BasicCredentialFactory('Login to lbrynet api')
_lbrynet_server = guard.HTTPAuthSessionWrapper(portal_to_realm, [factory, ])
else:
log.info("Using non-authenticated API")
_lbrynet_server = server.Site(lbry.root)
lbrynet_server = server.Site(_lbrynet_server)
lbrynet_server.requestFactory = DaemonRequest lbrynet_server.requestFactory = DaemonRequest
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) reactor.listenTCP(settings.API_PORT, lbrynet_server, interface=settings.API_INTERFACE)
reactor.run() reactor.run()
if not args.logtoconsole and not args.quiet: if not args.logtoconsole and not args.quiet:

View file

@ -6,7 +6,7 @@ from appdirs import user_data_dir
from twisted.internet import defer from twisted.internet import defer
from lbrynet.lbrynet_daemon.Daemon import Daemon from lbrynet.lbrynet_daemon.Daemon import Daemon
from lbrynet.lbrynet_daemon.Resources import LBRYindex, HostedEncryptedFile, EncryptedFileUpload from lbrynet.lbrynet_daemon.Resources import LBRYindex, HostedEncryptedFile, EncryptedFileUpload
from lbrynet.conf import API_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME from lbrynet import settings
# TODO: omg, this code is essentially duplicated in Daemon # TODO: omg, this code is essentially duplicated in Daemon
@ -17,20 +17,20 @@ else:
if not os.path.isdir(data_dir): if not os.path.isdir(data_dir):
os.mkdir(data_dir) os.mkdir(data_dir)
lbrynet_log = os.path.join(data_dir, LOG_FILE_NAME) lbrynet_log = os.path.join(data_dir, settings.LOG_FILE_NAME)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class DaemonServer(object): class DaemonServer(object):
def _setup_server(self, wallet): def _setup_server(self, use_authentication):
self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active")) self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active"))
self._api = Daemon(self.root, wallet_type=wallet) self._api = Daemon(self.root, use_authentication=use_authentication)
self.root.putChild("view", HostedEncryptedFile(self._api)) self.root.putChild("view", HostedEncryptedFile(self._api))
self.root.putChild("upload", EncryptedFileUpload(self._api)) self.root.putChild("upload", EncryptedFileUpload(self._api))
self.root.putChild(API_ADDRESS, self._api) self.root.putChild(settings.API_ADDRESS, self._api)
return defer.succeed(True) return defer.succeed(True)
def start(self, branch=DEFAULT_UI_BRANCH, user_specified=False, branch_specified=False, wallet=None): def start(self, use_authentication):
d = self._setup_server(wallet) d = self._setup_server(use_authentication)
d.addCallback(lambda _: self._api.setup(branch, user_specified, branch_specified)) d.addCallback(lambda _: self._api.setup())
return d return d

View file

@ -12,7 +12,7 @@ from lbrynet.core.Error import InsufficientFundsError, KeyFeeAboveMaxAllowed
from lbrynet.core.StreamDescriptor import download_sd_blob from lbrynet.core.StreamDescriptor import download_sd_blob
from lbrynet.metadata.Fee import FeeValidator from lbrynet.metadata.Fee import FeeValidator
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory
from lbrynet.conf import DEFAULT_TIMEOUT, LOG_FILE_NAME from lbrynet import settings
INITIALIZING_CODE = 'initializing' INITIALIZING_CODE = 'initializing'
DOWNLOAD_METADATA_CODE = 'downloading_metadata' DOWNLOAD_METADATA_CODE = 'downloading_metadata'
@ -35,13 +35,13 @@ else:
if not os.path.isdir(log_dir): if not os.path.isdir(log_dir):
os.mkdir(log_dir) os.mkdir(log_dir)
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME) lbrynet_log = os.path.join(log_dir, settings.LOG_FILE_NAME)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class GetStream(object): class GetStream(object):
def __init__(self, sd_identifier, session, wallet, lbry_file_manager, exchange_rate_manager, def __init__(self, sd_identifier, session, wallet, lbry_file_manager, exchange_rate_manager,
max_key_fee, data_rate=0.5, timeout=DEFAULT_TIMEOUT, download_directory=None, file_name=None): max_key_fee, data_rate=0.5, timeout=settings.download_timeout, download_directory=None, file_name=None):
self.wallet = wallet self.wallet = wallet
self.resolved_name = None self.resolved_name = None
self.description = None self.description = None

View file

@ -1,14 +1,14 @@
import logging import logging
import random import random
from txjsonrpc.web.jsonrpc import Proxy from txjsonrpc.web.jsonrpc import Proxy
from lbrynet.conf import SEARCH_SERVERS from lbrynet import settings
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class LighthouseClient(object): class LighthouseClient(object):
def __init__(self, servers=None): def __init__(self, servers=None):
self.servers = servers or SEARCH_SERVERS self.servers = servers or settings.search_servers
def _get_random_server(self): def _get_random_server(self):
return Proxy(random.choice(self.servers)) return Proxy(random.choice(self.servers))

View file

@ -12,7 +12,7 @@ from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
from lbrynet.metadata.Metadata import Metadata from lbrynet.metadata.Metadata import Metadata
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet import reflector from lbrynet import reflector
from lbrynet.conf import LOG_FILE_NAME, REFLECTOR_SERVERS from lbrynet import settings
from twisted.internet import threads, defer, reactor from twisted.internet import threads, defer, reactor
if sys.platform != "darwin": if sys.platform != "darwin":
@ -23,7 +23,7 @@ else:
if not os.path.isdir(log_dir): if not os.path.isdir(log_dir):
os.mkdir(log_dir) os.mkdir(log_dir)
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME) lbrynet_log = os.path.join(log_dir, settings.LOG_FILE_NAME)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -41,7 +41,7 @@ class Publisher(object):
self.lbry_file = None self.lbry_file = None
self.txid = None self.txid = None
self.stream_hash = None self.stream_hash = None
reflector_server = random.choice(REFLECTOR_SERVERS) reflector_server = random.choice(settings.REFLECTOR_SERVERS)
self.reflector_server, self.reflector_port = reflector_server[0], reflector_server[1] self.reflector_server, self.reflector_port = reflector_server[0], reflector_server[1]
self.metadata = {} self.metadata = {}
@ -74,7 +74,7 @@ class Publisher(object):
return d return d
def start_reflector(self): def start_reflector(self):
reflector_server = random.choice(REFLECTOR_SERVERS) reflector_server = random.choice(settings.REFLECTOR_SERVERS)
reflector_address, reflector_port = reflector_server[0], reflector_server[1] reflector_address, reflector_port = reflector_server[0], reflector_server[1]
log.info("Reflecting new publication") log.info("Reflecting new publication")
factory = reflector.ClientFactory( factory = reflector.ClientFactory(

View file

@ -10,7 +10,7 @@ from appdirs import user_data_dir
from twisted.web import server, static, resource from twisted.web import server, static, resource
from twisted.internet import defer, error from twisted.internet import defer, error
from lbrynet.conf import UI_ADDRESS from lbrynet import settings
from lbrynet.lbrynet_daemon.FileStreamer import EncryptedFileStreamer from lbrynet.lbrynet_daemon.FileStreamer import EncryptedFileStreamer
# TODO: omg, this code is essentially duplicated in Daemon # TODO: omg, this code is essentially duplicated in Daemon
@ -80,10 +80,10 @@ class HostedEncryptedFile(resource.Resource):
d = self._api._download_name(request.args['name'][0]) d = self._api._download_name(request.args['name'][0])
d.addCallback(lambda stream: self._make_stream_producer(request, stream)) d.addCallback(lambda stream: self._make_stream_producer(request, stream))
elif request.args['name'][0] in self._api.waiting_on.keys(): elif request.args['name'][0] in self._api.waiting_on.keys():
request.redirect(UI_ADDRESS + "/?watch=" + request.args['name'][0]) request.redirect(settings.UI_ADDRESS + "/?watch=" + request.args['name'][0])
request.finish() request.finish()
else: else:
request.redirect(UI_ADDRESS) request.redirect(settings.UI_ADDRESS)
request.finish() request.finish()
return server.NOT_DONE_YET return server.NOT_DONE_YET

View file

@ -8,7 +8,7 @@ from urllib2 import urlopen
from StringIO import StringIO from StringIO import StringIO
from twisted.internet import defer from twisted.internet import defer
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
from lbrynet.conf import DEFAULT_UI_BRANCH, LOG_FILE_NAME from lbrynet import settings
from lbrynet.lbrynet_daemon.Resources import NoCacheStaticFile from lbrynet.lbrynet_daemon.Resources import NoCacheStaticFile
from lbrynet import __version__ as lbrynet_version from lbrynet import __version__ as lbrynet_version
from lbryum.version import LBRYUM_VERSION as lbryum_version from lbryum.version import LBRYUM_VERSION as lbryum_version
@ -23,7 +23,7 @@ else:
if not os.path.isdir(log_dir): if not os.path.isdir(log_dir):
os.mkdir(log_dir) os.mkdir(log_dir)
lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME) lbrynet_log = os.path.join(log_dir, settings.LOG_FILE_NAME)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -74,29 +74,29 @@ class UIManager(object):
self.loaded_branch = None self.loaded_branch = None
self.loaded_requirements = None self.loaded_requirements = None
def setup(self, branch=DEFAULT_UI_BRANCH, user_specified=None, branch_specified=False, check_requirements=None): def setup(self, branch=None, check_requirements=None, user_specified=None):
if check_requirements is not None: local_ui_path = settings.local_ui_path or user_specified
self.check_requirements = check_requirements self.branch = settings.UI_BRANCH or branch
if self.branch is not None: self.check_requirements = settings.check_ui_requirements or check_requirements
self.branch = branch
if user_specified: if local_ui_path:
if os.path.isdir(user_specified): if os.path.isdir(local_ui_path):
log.info("Checking user specified UI directory: " + str(user_specified)) log.info("Checking user specified UI directory: " + str(local_ui_path))
self.branch = "user-specified" self.branch = "user-specified"
self.loaded_git_version = "user-specified" self.loaded_git_version = "user-specified"
d = self.migrate_ui(source=user_specified) d = self.migrate_ui(source=local_ui_path)
d.addCallback(lambda _: self._load_ui()) d.addCallback(lambda _: self._load_ui())
return d return d
else: else:
log.info("User specified UI directory doesn't exist, using " + self.branch) log.info("User specified UI directory doesn't exist, using " + self.branch)
elif self.loaded_branch == "user-specified" and not branch_specified: elif self.loaded_branch == "user-specified":
log.info("Loading user provided UI") log.info("Loading user provided UI")
d = self._load_ui() d = self._load_ui()
return d return d
else: else:
log.info("Checking for updates for UI branch: " + branch) log.info("Checking for updates for UI branch: " + self.branch)
self._git_url = "https://s3.amazonaws.com/lbry-ui/{}/data.json".format(branch) self._git_url = "https://s3.amazonaws.com/lbry-ui/{}/data.json".format(self.branch)
self._dist_url = "https://s3.amazonaws.com/lbry-ui/{}/dist.zip".format(branch) self._dist_url = "https://s3.amazonaws.com/lbry-ui/{}/dist.zip".format(self.branch)
d = self._up_to_date() d = self._up_to_date()
d.addCallback(lambda r: self._download_ui() if not r else self._load_ui()) d.addCallback(lambda r: self._download_ui() if not r else self._load_ui())

View file

@ -6,8 +6,7 @@ import base64
import json import json
from lbrynet.lbrynet_daemon.auth.util import load_api_keys, APIKey, API_KEY_NAME, get_auth_message from lbrynet.lbrynet_daemon.auth.util import load_api_keys, APIKey, API_KEY_NAME, get_auth_message
from lbrynet.conf import API_INTERFACE, API_ADDRESS, API_PORT from lbrynet import settings
from lbrynet.conf import DATA_DIR
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
USER_AGENT = "AuthServiceProxy/0.1" USER_AGENT = "AuthServiceProxy/0.1"
@ -77,7 +76,6 @@ class LBRYAPIClient(object):
cookies = http_response.cookies cookies = http_response.cookies
headers = http_response.headers headers = http_response.headers
next_secret = headers.get(LBRY_SECRET, False) next_secret = headers.get(LBRY_SECRET, False)
if next_secret: if next_secret:
self.__api_key.secret = next_secret self.__api_key.secret = next_secret
self.__cookies = cookies self.__cookies = cookies
@ -103,14 +101,18 @@ class LBRYAPIClient(object):
service=None, cookies=None, auth=None, url=None, login_url=None): service=None, cookies=None, auth=None, url=None, login_url=None):
api_key_name = API_KEY_NAME if not key_name else key_name api_key_name = API_KEY_NAME if not key_name else key_name
pw_path = os.path.join(DATA_DIR, ".api_keys") if not pw_path else pw_path pw_path = os.path.join(settings.DATA_DIR, ".api_keys") if not pw_path else pw_path
if not key: if not key:
keys = load_api_keys(pw_path) keys = load_api_keys(pw_path)
api_key = keys.get(api_key_name, False) api_key = keys.get(api_key_name, False)
else: else:
api_key = APIKey(name=api_key_name, secret=key) api_key = APIKey(name=api_key_name, secret=key)
if login_url is None: if login_url is None:
service_url = "http://%s:%s@%s:%i/%s" % (api_key_name, api_key.secret, API_INTERFACE, API_PORT, API_ADDRESS) service_url = "http://%s:%s@%s:%i/%s" % (api_key_name,
api_key.secret,
settings.API_INTERFACE,
settings.API_PORT,
settings.API_ADDRESS)
else: else:
service_url = login_url service_url = login_url
id_count = count id_count = count
@ -143,7 +145,6 @@ class LBRYAPIClient(object):
cookies = http_response.cookies cookies = http_response.cookies
uid = cookies.get(TWISTED_SESSION) uid = cookies.get(TWISTED_SESSION)
api_key = APIKey.new(seed=uid) api_key = APIKey.new(seed=uid)
else: else:
# This is a client that already has a session, use it # This is a client that already has a session, use it
auth_header = auth auth_header = auth

View file

@ -7,7 +7,7 @@ from twisted.internet import defer
from txjsonrpc import jsonrpclib from txjsonrpc import jsonrpclib
from lbrynet.core.Error import InvalidAuthenticationToken, InvalidHeaderError, SubhandlerError from lbrynet.core.Error import InvalidAuthenticationToken, InvalidHeaderError, SubhandlerError
from lbrynet.conf import API_INTERFACE, REFERER, ORIGIN from lbrynet import settings
from lbrynet.lbrynet_daemon.auth.util import APIKey, get_auth_message from lbrynet.lbrynet_daemon.auth.util import APIKey, get_auth_message
from lbrynet.lbrynet_daemon.auth.client import LBRY_SECRET from lbrynet.lbrynet_daemon.auth.client import LBRY_SECRET
@ -81,8 +81,9 @@ class AuthJSONRPCServer(AuthorizedBase):
NOT_FOUND = 8001 NOT_FOUND = 8001
FAILURE = 8002 FAILURE = 8002
def __init__(self): def __init__(self, use_authentication=True):
AuthorizedBase.__init__(self) AuthorizedBase.__init__(self)
self._use_authentication = use_authentication
self.allowed_during_startup = [] self.allowed_during_startup = []
self.sessions = {} self.sessions = {}
@ -95,18 +96,19 @@ class AuthJSONRPCServer(AuthorizedBase):
session = request.getSession() session = request.getSession()
session_id = session.uid session_id = session.uid
# if this is a new session, send a new secret and set the expiration, otherwise, session.touch() if self._use_authentication:
if self._initialize_session(session_id): # if this is a new session, send a new secret and set the expiration, otherwise, session.touch()
def expire_session(): if self._initialize_session(session_id):
self._unregister_user_session(session_id) def expire_session():
session.startCheckingExpiration() self._unregister_user_session(session_id)
session.notifyOnExpire(expire_session) session.startCheckingExpiration()
message = "OK" session.notifyOnExpire(expire_session)
request.setResponseCode(self.OK) message = "OK"
self._set_headers(request, message, True) request.setResponseCode(self.OK)
self._render_message(request, message) self._set_headers(request, message, True)
return server.NOT_DONE_YET self._render_message(request, message)
session.touch() return server.NOT_DONE_YET
session.touch()
request.content.seek(0, 0) request.content.seek(0, 0)
content = request.content.read() content = request.content.read()
@ -127,16 +129,17 @@ class AuthJSONRPCServer(AuthorizedBase):
return server.failure return server.failure
reply_with_next_secret = False reply_with_next_secret = False
if function_name in self.authorized_functions: if self._use_authentication:
try: if function_name in self.authorized_functions:
self._verify_token(session_id, parsed, token) try:
except InvalidAuthenticationToken: self._verify_token(session_id, parsed, token)
log.warning("API validation failed") except InvalidAuthenticationToken:
request.setResponseCode(self.UNAUTHORIZED) log.warning("API validation failed")
request.finish() request.setResponseCode(self.UNAUTHORIZED)
return server.NOT_DONE_YET request.finish()
self._update_session_secret(session_id) return server.NOT_DONE_YET
reply_with_next_secret = True self._update_session_secret(session_id)
reply_with_next_secret = True
try: try:
function = self._get_jsonrpc_method(function_name) function = self._get_jsonrpc_method(function_name)
@ -161,9 +164,9 @@ class AuthJSONRPCServer(AuthorizedBase):
@param session_id: @param session_id:
@return: secret @return: secret
""" """
token = APIKey.new() log.info("Register api session")
token = APIKey.new(seed=session_id)
self.sessions.update({session_id: token}) self.sessions.update({session_id: token})
return token
def _unregister_user_session(self, session_id): def _unregister_user_session(self, session_id):
log.info("Unregister API session") log.info("Unregister API session")
@ -173,7 +176,7 @@ class AuthJSONRPCServer(AuthorizedBase):
log.debug(err.getTraceback()) log.debug(err.getTraceback())
def _set_headers(self, request, data, update_secret=False): def _set_headers(self, request, data, update_secret=False):
request.setHeader("Access-Control-Allow-Origin", API_INTERFACE) request.setHeader("Access-Control-Allow-Origin", settings.API_INTERFACE)
request.setHeader("Content-Type", "text/json") request.setHeader("Content-Type", "text/json")
request.setHeader("Content-Length", str(len(data))) request.setHeader("Content-Length", str(len(data)))
if update_secret: if update_secret:
@ -187,10 +190,10 @@ class AuthJSONRPCServer(AuthorizedBase):
def _check_headers(self, request): def _check_headers(self, request):
origin = request.getHeader("Origin") origin = request.getHeader("Origin")
referer = request.getHeader("Referer") referer = request.getHeader("Referer")
if origin not in [None, ORIGIN]: if origin not in [None, settings.ORIGIN]:
log.warning("Attempted api call from %s", origin) log.warning("Attempted api call from %s", origin)
return False return False
if referer is not None and not referer.startswith(REFERER): if referer is not None and not referer.startswith(settings.REFERER):
log.warning("Attempted api call from %s", referer) log.warning("Attempted api call from %s", referer)
return False return False
return True return True
@ -211,8 +214,7 @@ class AuthJSONRPCServer(AuthorizedBase):
def _initialize_session(self, session_id): def _initialize_session(self, session_id):
if not self.sessions.get(session_id, False): if not self.sessions.get(session_id, False):
log.info("Initializing new api session") self._register_user_session(session_id)
self.sessions.update({session_id: APIKey.new(seed=session_id, name=session_id)})
return True return True
return False return False
@ -242,7 +244,6 @@ class AuthJSONRPCServer(AuthorizedBase):
log.error(err.message) log.error(err.message)
raise SubhandlerError raise SubhandlerError
def _callback_render(self, result, request, id, version, auth_required=False): def _callback_render(self, result, request, id, version, auth_required=False):
result_for_return = result if not isinstance(result, dict) else result['result'] result_for_return = result if not isinstance(result, dict) else result['result']
@ -271,5 +272,3 @@ class AuthJSONRPCServer(AuthorizedBase):
def _render_response(self, result, code): def _render_response(self, result, code):
return defer.succeed({'result': result, 'code': code}) return defer.succeed({'result': result, 'code': code})

View file

@ -1,4 +1,4 @@
from lbrynet.conf import POINTTRADER_SERVER from lbrynet import settings
from twisted.web.client import Agent, FileBodyProducer, Headers, ResponseDone from twisted.web.client import Agent, FileBodyProducer, Headers, ResponseDone
from twisted.internet import threads, defer, protocol from twisted.internet import threads, defer, protocol
@ -46,7 +46,7 @@ def get_body_from_request(path, data):
jsondata = FileBodyProducer(StringIO(json.dumps(data))) jsondata = FileBodyProducer(StringIO(json.dumps(data)))
agent = Agent(reactor) agent = Agent(reactor)
d = agent.request('POST', POINTTRADER_SERVER + path, Headers({'Content-Type': ['application/json']}), jsondata) d = agent.request('POST', settings.POINTTRADER_SERVER + path, Headers({'Content-Type': ['application/json']}), jsondata)
d.addCallback(get_body) d.addCallback(get_body)
return d return d

View file

@ -27,9 +27,9 @@ if not os.path.isfile(lbrycrdd_path_conf):
f.write(lbrycrdd_path) f.write(lbrycrdd_path)
f.close() f.close()
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer, DaemonRequest from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
from lbrynet.conf import UI_ADDRESS from lbrynet import settings
if platform.mac_ver()[0] >= "10.10": if platform.mac_ver()[0] >= "10.10":
from LBRYNotify import LBRYNotify from LBRYNotify import LBRYNotify
@ -53,7 +53,7 @@ class LBRYDaemonApp(AppKit.NSApplication):
self.connection = False self.connection = False
statusbar = AppKit.NSStatusBar.systemStatusBar() statusbar = AppKit.NSStatusBar.systemStatusBar()
self.statusitem = statusbar.statusItemWithLength_(AppKit.NSVariableStatusItemLength) self.statusitem = statusbar.statusItemWithLength_(AppKit.NSVariableStatusItemLength)
self.icon = AppKit.NSImage.alloc().initByReferencingFile_(ICON_PATH) self.icon = AppKit.NSImage.alloc().initByReferencingFile_(settings.ICON_PATH)
self.icon.setScalesWhenResized_(True) self.icon.setScalesWhenResized_(True)
self.icon.setSize_((20, 20)) self.icon.setSize_((20, 20))
self.statusitem.setImage_(self.icon) self.statusitem.setImage_(self.icon)
@ -63,7 +63,7 @@ class LBRYDaemonApp(AppKit.NSApplication):
self.quit = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Quit", "replyToApplicationShouldTerminate:", "") self.quit = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Quit", "replyToApplicationShouldTerminate:", "")
self.menubarMenu.addItem_(self.quit) self.menubarMenu.addItem_(self.quit)
self.statusitem.setMenu_(self.menubarMenu) self.statusitem.setMenu_(self.menubarMenu)
self.statusitem.setToolTip_(APP_NAME) self.statusitem.setToolTip_(settings.APP_NAME)
if test_internet_connection(): if test_internet_connection():
@ -77,13 +77,13 @@ class LBRYDaemonApp(AppKit.NSApplication):
lbry = DaemonServer() lbry = DaemonServer()
d = lbry.start() d = lbry.start()
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS)) d.addCallback(lambda _: webbrowser.open(settings.UI_ADDRESS))
lbrynet_server = server.Site(lbry.root) lbrynet_server = server.Site(lbry.root)
lbrynet_server.requestFactory = DaemonRequest lbrynet_server.requestFactory = DaemonRequest
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) reactor.listenTCP(settings.API_PORT, lbrynet_server, interface=settings.API_INTERFACE)
def openui_(self, sender): def openui_(self, sender):
webbrowser.open(UI_ADDRESS) webbrowser.open(settings.UI_ADDRESS)
def replyToApplicationShouldTerminate_(self, shouldTerminate): def replyToApplicationShouldTerminate_(self, shouldTerminate):
if platform.mac_ver()[0] >= "10.10": if platform.mac_ver()[0] >= "10.10":

View file

@ -5,7 +5,7 @@ import sys
from time import sleep from time import sleep
from lbrynet.lbrynet_daemon.auth.client import LBRYAPIClient from lbrynet.lbrynet_daemon.auth.client import LBRYAPIClient
from lbrynet.conf import UI_ADDRESS from lbrynet import settings
class LBRYURIHandler(object): class LBRYURIHandler(object):
@ -69,9 +69,9 @@ class LBRYURIHandler(object):
@staticmethod @staticmethod
def open_address(lbry_name): def open_address(lbry_name):
if lbry_name == "lbry" or lbry_name == "" or lbry_name is None: if lbry_name == "lbry" or lbry_name == "" or lbry_name is None:
webbrowser.open(UI_ADDRESS) webbrowser.open(settings.UI_ADDRESS)
else: else:
webbrowser.open(UI_ADDRESS + "/?show=" + lbry_name) webbrowser.open(settings.UI_ADDRESS + "/?show=" + lbry_name)
def main(args): def main(args):

View file

@ -18,9 +18,9 @@ try:
except ImportError: except ImportError:
import win32gui import win32gui
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer, DaemonRequest from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
from lbrynet.conf import UI_ADDRESS, API_CONNECTION_STRING, LOG_FILE_NAME from lbrynet import settings
from packaging.uri_handler.LBRYURIHandler import LBRYURIHandler from packaging.uri_handler.LBRYURIHandler import LBRYURIHandler
@ -29,7 +29,7 @@ data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
if not os.path.isdir(data_dir): if not os.path.isdir(data_dir):
os.mkdir(data_dir) os.mkdir(data_dir)
lbrynet_log = os.path.join(data_dir, LOG_FILE_NAME) lbrynet_log = os.path.join(data_dir, settings.LOG_FILE_NAME)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
if getattr(sys, 'frozen', False) and os.name == "nt": if getattr(sys, 'frozen', False) and os.name == "nt":
@ -257,7 +257,7 @@ def main(lbry_name=None):
return SysTrayIcon(icon, hover_text, menu_options, on_quit=stop) return SysTrayIcon(icon, hover_text, menu_options, on_quit=stop)
def openui_(sender): def openui_(sender):
webbrowser.open(UI_ADDRESS) webbrowser.open(settings.UI_ADDRESS)
def replyToApplicationShouldTerminate_(): def replyToApplicationShouldTerminate_():
try: try:
@ -269,11 +269,11 @@ def main(lbry_name=None):
replyToApplicationShouldTerminate_() replyToApplicationShouldTerminate_()
if getattr(sys, 'frozen', False) and os.name == "nt": if getattr(sys, 'frozen', False) and os.name == "nt":
icon = os.path.join(os.path.dirname(sys.executable), ICON_PATH, 'lbry16.ico') icon = os.path.join(os.path.dirname(sys.executable), settings.ICON_PATH, 'lbry16.ico')
else: else:
icon = os.path.join(ICON_PATH, 'lbry16.ico') icon = os.path.join(settings.ICON_PATH, 'lbry16.ico')
hover_text = APP_NAME hover_text = settings.APP_NAME
menu_options = (('Open', icon, openui_),) menu_options = (('Open', icon, openui_),)
if not test_internet_connection(): if not test_internet_connection():
@ -290,14 +290,14 @@ def main(lbry_name=None):
lbrynet_server = server.Site(lbry.root) lbrynet_server = server.Site(lbry.root)
lbrynet_server.requestFactory = DaemonRequest lbrynet_server.requestFactory = DaemonRequest
try: try:
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE) reactor.listenTCP(settings.API_PORT, lbrynet_server, interface=settings.API_INTERFACE)
except error.CannotListenError: except error.CannotListenError:
log.info('Daemon already running, exiting app') log.info('Daemon already running, exiting app')
sys.exit(1) sys.exit(1)
reactor.run() reactor.run()
if __name__ == '__main__': if __name__ == '__main__':
lbry_daemon = JSONRPCProxy.from_url(API_CONNECTION_STRING) lbry_daemon = JSONRPCProxy.from_url(settings.API_CONNECTION_STRING)
try: try:
daemon_running = lbry_daemon.is_running() daemon_running = lbry_daemon.is_running()

View file

@ -10,8 +10,7 @@ import unittest
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from Crypto import Random from Crypto import Random
from Crypto.Hash import MD5 from Crypto.Hash import MD5
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE from lbrynet import settings
from lbrynet.conf import MIN_BLOB_INFO_PAYMENT_RATE
from lbrynet.lbrylive.LiveStreamCreator import FileLiveStreamCreator from lbrynet.lbrylive.LiveStreamCreator import FileLiveStreamCreator
from lbrynet.lbrylive.LiveStreamMetadataManager import DBLiveStreamMetadataManager from lbrynet.lbrylive.LiveStreamMetadataManager import DBLiveStreamMetadataManager
from lbrynet.lbrylive.LiveStreamMetadataManager import TempLiveStreamMetadataManager from lbrynet.lbrylive.LiveStreamMetadataManager import TempLiveStreamMetadataManager
@ -236,7 +235,7 @@ def start_lbry_uploader(sd_hash_queue, kill_event, dead_event, file_size, ul_rat
db_dir = "server" db_dir = "server"
os.mkdir(db_dir) os.mkdir(db_dir)
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553, peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker,
dht_node_class=Node) dht_node_class=Node)
@ -351,7 +350,7 @@ def start_lbry_reuploader(sd_hash, kill_event, dead_event, ready_event, n, ul_ra
os.mkdir(db_dir) os.mkdir(db_dir)
os.mkdir(blob_dir) os.mkdir(blob_dir)
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd" + str(n), session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd" + str(n),
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=peer_port, blob_dir=None, peer_port=peer_port,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker) use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker)
@ -462,7 +461,7 @@ def start_live_server(sd_hash_queue, kill_event, dead_event):
db_dir = "server" db_dir = "server"
os.mkdir(db_dir) os.mkdir(db_dir)
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553, peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker) blob_tracker_class=DummyBlobAvailabilityTracker)
@ -596,7 +595,7 @@ def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow):
os.mkdir(db_dir) os.mkdir(db_dir)
os.mkdir(blob_dir) os.mkdir(blob_dir)
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="efgh", session = Session(settings.data_rate, db_dir=db_dir, lbryid="efgh",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=peer_port, blob_dir=blob_dir, peer_port=peer_port,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker) use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker)
@ -768,7 +767,7 @@ class TestTransfer(TestCase):
os.mkdir(db_dir) os.mkdir(db_dir)
os.mkdir(blob_dir) os.mkdir(blob_dir)
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker,
@ -854,7 +853,7 @@ class TestTransfer(TestCase):
db_dir = "client" db_dir = "client"
os.mkdir(db_dir) os.mkdir(db_dir)
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=None, peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=None,
peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet,
blob_tracker_class=DummyBlobAvailabilityTracker, dht_node_class=Node) blob_tracker_class=DummyBlobAvailabilityTracker, dht_node_class=Node)
@ -955,7 +954,7 @@ class TestTransfer(TestCase):
os.mkdir(db_dir) os.mkdir(db_dir)
os.mkdir(blob_dir) os.mkdir(blob_dir)
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker) use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker)
@ -1035,7 +1034,7 @@ class TestTransfer(TestCase):
os.mkdir(db_dir) os.mkdir(db_dir)
os.mkdir(blob_dir) os.mkdir(blob_dir)
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, use_upnp=False, blob_dir=blob_dir, peer_port=5553, use_upnp=False,
rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker) rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker)
@ -1150,7 +1149,7 @@ class TestTransfer(TestCase):
os.mkdir(db_dir) os.mkdir(db_dir)
os.mkdir(blob_dir) os.mkdir(blob_dir)
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=5553, blob_dir=None, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker) use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker)
@ -1269,7 +1268,7 @@ class TestStreamify(TestCase):
os.mkdir(db_dir) os.mkdir(db_dir)
os.mkdir(blob_dir) os.mkdir(blob_dir)
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker) use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker)
@ -1322,7 +1321,7 @@ class TestStreamify(TestCase):
os.mkdir(db_dir) os.mkdir(db_dir)
os.mkdir(blob_dir) os.mkdir(blob_dir)
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", self.session = Session(settings.data_rate, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker) use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker_class=DummyBlobAvailabilityTracker)

View file

@ -4,7 +4,7 @@ import shutil
from twisted.internet import defer, threads, error from twisted.internet import defer, threads, error
from twisted.trial import unittest from twisted.trial import unittest
from lbrynet import conf from lbrynet import settings
from lbrynet import lbryfile from lbrynet import lbryfile
from lbrynet import reflector from lbrynet import reflector
from lbrynet.core import BlobManager from lbrynet.core import BlobManager
@ -83,7 +83,7 @@ class TestReflector(unittest.TestCase):
os.mkdir(db_dir) os.mkdir(db_dir)
self.session = Session.Session( self.session = Session.Session(
conf.MIN_BLOB_DATA_PAYMENT_RATE, settings.data_rate,
db_dir=db_dir, db_dir=db_dir,
lbryid="abcd", lbryid="abcd",
peer_finder=peer_finder, peer_finder=peer_finder,

View file

@ -2,7 +2,7 @@ import io
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from decimal import Decimal from decimal import Decimal
from twisted.internet import defer, threads, task, error from twisted.internet import defer
from lbrynet.core import PTCWallet from lbrynet.core import PTCWallet
from lbrynet.core.BlobAvailability import BlobAvailabilityTracker from lbrynet.core.BlobAvailability import BlobAvailabilityTracker