Merge branch 'master' into auth-jsonrpc

# Conflicts:
#	lbrynet/lbrynet_daemon/Daemon.py
#	lbrynet/lbrynet_daemon/DaemonControl.py
This commit is contained in:
Jack 2016-10-07 17:11:43 -04:00
commit 5a0b5dc680
63 changed files with 1188 additions and 989 deletions

View file

@ -12,116 +12,17 @@ notifications:
incoming_webhook:
secure: LuxwG5OZnnA//gmSXzCKu8/FRqYjCgGfVFqajSsGHeQ1HQNp7rYNhQpsO8/3PK63xKJj3wzt86DJekf9q9Q5OcHa9AHXUQbEveX0psd7elw=
branches:
only:
- master
- appveyor
- windows-setup
clone_folder: c:\projects\lbry
init:
- ps: >-
$env:Path += ";C:\MinGW\bin\"
$env:Path += ";C:\Program Files (x86)\Windows Kits\10\bin\x86\"
gcc --version
mingw32-make --version
mkdir C:\temp
Invoke-WebRequest "https://pypi.python.org/packages/55/90/e987e28ed29b571f315afea7d317b6bf4a551e37386b344190cffec60e72/miniupnpc-1.9.tar.gz" -OutFile "C:\temp\miniupnpc-1.9.tar.gz"
cd C:\temp
7z e miniupnpc-1.9.tar.gz
7z x miniupnpc-1.9.tar
cd C:\temp\miniupnpc-1.9
mingw32-make.exe -f Makefile.mingw
C:\Python27\python.exe C:\temp\miniupnpc-1.9\setupmingw32.py build --compiler=mingw32
C:\Python27\python.exe C:\temp\miniupnpc-1.9\setupmingw32.py install
Invoke-WebRequest "https://github.com/lbryio/lbry/raw/master/packaging/windows/libs/gmpy-1.17-cp27-none-win32.whl" -OutFile "C:\temp\gmpy-1.17-cp27-none-win32.whl"
C:\Python27\Scripts\pip.exe install "C:\temp\gmpy-1.17-cp27-none-win32.whl"
C:\Python27\Scripts\pip.exe install pypiwin32==219
C:\Python27\Scripts\pip.exe install six==1.9.0
C:\Python27\Scripts\pip.exe install requests==2.9.1
C:\Python27\Scripts\pip.exe install zope.interface==4.1.3
C:\Python27\Scripts\pip.exe install cx-freeze==4.3.3
C:\Python27\Scripts\pip.exe install cython==0.24.1
C:\Python27\Scripts\pip.exe install Twisted==16.0.0
C:\Python27\Scripts\pip.exe install Yapsy==1.11.223
C:\Python27\Scripts\pip.exe install appdirs==1.4.0
C:\Python27\Scripts\pip.exe install argparse==1.2.1
C:\Python27\Scripts\pip.exe install colorama==0.3.7
C:\Python27\Scripts\pip.exe install dnspython==1.12.0
C:\Python27\Scripts\pip.exe install ecdsa==0.13
C:\Python27\Scripts\pip.exe install jsonrpc==1.2
C:\Python27\Scripts\pip.exe install jsonrpclib==0.1.7
C:\Python27\Scripts\pip.exe install loggly-python-handler==1.0.0
C:\Python27\Scripts\pip.exe install pbkdf2==1.3
C:\Python27\Scripts\pip.exe install protobuf==3.0.0
C:\Python27\Scripts\pip.exe install pycrypto==2.6.1
C:\Python27\Scripts\pip.exe install python-bitcoinrpc==0.1
C:\Python27\Scripts\pip.exe install qrcode==5.2.2
C:\Python27\Scripts\pip.exe install requests_futures==0.9.7
C:\Python27\Scripts\pip.exe install seccure==0.3.1.3
C:\Python27\Scripts\pip.exe install simplejson==3.8.2
C:\Python27\Scripts\pip.exe install slowaes==0.1a1
C:\Python27\Scripts\pip.exe install txJSON-RPC==0.3.1
C:\Python27\Scripts\pip.exe install unqlite==0.5.3
C:\Python27\Scripts\pip.exe install wsgiref==0.1.2
C:\Python27\Scripts\pip.exe install base58==0.2.2
C:\Python27\Scripts\pip.exe install googlefinance==0.7
C:\Python27\Scripts\pip.exe install pyyaml==3.12
C:\Python27\Scripts\pip.exe install git+https://github.com/lbryio/lbryum.git
cd C:\projects\lbry
install:
- cmd: dir C:\projects\lbry\packaging\windows\
- ps: .\packaging\windows\init.ps1
- nuget install secure-file -ExcludeVersion
- secure-file\tools\secure-file -decrypt packaging\windows\certs\lbry2.pfx.enc -secret %pfx_key%
- cmd: C:\Python27\python.exe setup.py install
- ps: .\packaging\windows\install.ps1
build_script:
@ -130,12 +31,8 @@ build_script:
test_script:
- ps: >-
C:\Python27\Scripts\pip.exe install mock
- ps: .\packaging\windows\test.ps1
C:\Python27\Scripts\pip.exe install pylint
C:\Python27\python.exe C:\Python27\Scripts\trial.py C:\projects\lbry\tests
artifacts:
- path: dist/*.msi
@ -144,3 +41,16 @@ artifacts:
name: lbry-portable
- path: packaging/windows/lbry-win32-app/LBRY-URI.reg
name: LBRY-URI
deploy:
release: $(APPVEYOR_REPO_TAG_NAME)
description: 'Release'
provider: GitHub
auth_token:
secure: 28gMVxQkXr2iXP4F+5kVwefUtKCfS1ePZ97PVfaSR8UDupjAvKhSJx862TnEjukb
artifact: /.*\.msi/
draft: false
prerelease: true
on:
appveyor_repo_tag: true # deploy on tag push only

View file

@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.9
current_version = 0.6.3
commit = True
tag = True

View file

@ -4,7 +4,7 @@
Installing LBRY is simple. You can get a dmg installer for OS X or a .deb for linux [here](https://github.com/lbryio/lbry/releases/latest).
##### OS X
Just drag and drop LBRY.app into your applications folder (replacing any older versions). When it's running you'll have a LBRY icon in your status bar and the browser will open to the UI.
Drag and drop LBRY.app into your applications folder (replacing any older versions). When it's running you'll have a LBRY icon in your status bar and the browser will open to the UI.
##### Linux
Double click the .deb file and follow the prompts. The app can be started by searching "LBRY", and it can be turned off by clicking the red 'x' in the browser interface.
@ -12,26 +12,52 @@ Double click the .deb file and follow the prompts. The app can be started by sea
On both systems you can also open the UI while the app is running by going to lbry://lbry in Firefox or Safari, or localhost:5279 in Chrome.
#### Installing LBRY command line
#### Installing LBRY from source
--------------------------
##### OS X
You can install LBRY command line by running `curl -sL https://raw.githubusercontent.com/lbryio/lbry/master/packaging/osx/install_lbry_source.sh | sudo bash` in a terminal. This script will install lbrynet and its dependencies. You can start LBRY by running `lbrynet-daemon` from a terminal.
Installing LBRY from source is not the recommended way to install
LBRY. Only do so if you're interested in doing development work.
##### Linux
On Ubuntu or Mint you can install the prerequisites and lbrynet by running
##### OS X Prerequisites
In order to install LBRY from source you'll need to first install [xcode command line tools](https://developer.xamarin.com/guides/testcloud/calabash/configuring/osx/install-xcode-command-line-tools/) and [homebrew](http://brew.sh/). The dependencies can then be installed by running
```
brew install mpfr libmpc
sudo easy_install pip
sudo pip install virtualenv
```
##### Linux Prerequisites
On Ubuntu or Mint you can install the prerequisites by running
```
sudo apt-get install libgmp3-dev build-essential python2.7 python2.7-dev \
python-pip git python-virtualenv
```
##### OSX and Linux Installation
It is strongly recommended to create a new virtualenv for LBRY
```
sudo apt-get install
virtualenv lbry-venv
source lbry-venv/bin/activate
```
and install the package in the new virtualenv:
```
sudo apt-get install libgmp3-dev build-essential python2.7 python2.7-dev python-pip git
git clone https://github.com/lbryio/lbry.git
cd lbry
sudo python setup.py install
python setup.py install
```
To start LBRY, run `lbrynet-daemon` in a terminal.
#### On windows:
##### On windows
Install [mingw32](http://www.mingw.org/) base and c++ compiler.

View file

@ -1,6 +1,6 @@
import logging
__version__ = "0.4.9"
__version__ = "0.6.3"
version = tuple(__version__.split('.'))
logging.getLogger(__name__).addHandler(logging.NullHandler())

View file

@ -1,6 +1,21 @@
import logging
from lbrynet.analytics import utils
log = logging.getLogger(__name__)
def get_sd_hash(stream_info):
if not stream_info:
return None
try:
return stream_info['sources']['lbry_sd_hash']
except (KeyError, TypeError, ValueError):
log.debug('Failed to get sd_hash from %s', stream_info, exc_info=True)
return None
class Events(object):
def __init__(self, context, lbry_id, session_id):
self.context = context
@ -19,6 +34,20 @@ class Events(object):
'timestamp': utils.now()
}
def download_started(self, name, stream_info=None):
return {
'userId': 'lbry',
'event': 'Download Started',
'properties': {
'lbry_id': self.lbry_id,
'session_id': self.session_id,
'name': name,
'stream_info': get_sd_hash(stream_info)
},
'context': self.context,
'timestamp': utils.now()
}
def make_context(platform, wallet, is_dev=False):
# TODO: distinguish between developer and release instances

View file

@ -7,12 +7,12 @@ from Crypto.Hash import SHA512
from Crypto.PublicKey import RSA
from lbrynet.core.client.ClientRequest import ClientRequest
from lbrynet.core.Error import RequestCanceledError
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, ILBRYWallet
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet
from lbrynet.pointtraderclient import pointtraderclient
from twisted.internet import defer, threads
from zope.interface import implements
from twisted.python.failure import Failure
from lbrynet.core.LBRYWallet import ReservedPoints
from lbrynet.core.Wallet import ReservedPoints
log = logging.getLogger(__name__)
@ -21,7 +21,7 @@ log = logging.getLogger(__name__)
class PTCWallet(object):
"""This class sends payments to peers and also ensures that expected payments are received.
This class is only intended to be used for testing."""
implements(ILBRYWallet)
implements(IWallet)
def __init__(self, db_dir):
self.db_dir = db_dir

View file

@ -33,4 +33,8 @@ class Peer(object):
self.stats[stat_type] += count
def __str__(self):
return self.host + ":" + str(self.port)
return '{}:{}'.format(self.host, self.port)
def __repr__(self):
return 'Peer({!r}, {!r})'.format(self.host, self.port)

View file

@ -16,7 +16,7 @@ from twisted.internet import threads, defer
log = logging.getLogger(__name__)
class LBRYSession(object):
class Session(object):
"""This class manages all important services common to any application that uses the network:
the hash announcer, which informs other peers that this peer is associated with some hash. Usually,
this means this peer has a blob identified by the hash in question, but it can be used for other

View file

@ -17,15 +17,15 @@ from decimal import Decimal
from lbryum import SimpleConfig, Network
from lbryum.lbrycrd import COIN
from lbryum.wallet import WalletStorage, Wallet
import lbryum.wallet
from lbryum.commands import known_commands, Commands
from lbryum.transaction import Transaction
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, ILBRYWallet
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet
from lbrynet.core.client.ClientRequest import ClientRequest
from lbrynet.core.Error import UnknownNameError, InvalidStreamInfoError, RequestCanceledError
from lbrynet.core.Error import InsufficientFundsError
from lbrynet.metadata.LBRYMetadata import Metadata
from lbrynet.metadata.Metadata import Metadata
log = logging.getLogger(__name__)
alert = logging.getLogger("lbryalert." + __name__)
@ -47,9 +47,9 @@ def _catch_connection_error(f):
return w
class LBRYWallet(object):
"""This class implements the LBRYWallet interface for the LBRYcrd payment system"""
implements(ILBRYWallet)
class Wallet(object):
"""This class implements the Wallet interface for the LBRYcrd payment system"""
implements(IWallet)
_FIRST_RUN_UNKNOWN = 0
_FIRST_RUN_YES = 1
@ -368,6 +368,31 @@ class LBRYWallet(object):
d.addCallback(_get_id_for_return)
return d
def get_my_claim(self, name):
def _convert_units(claim):
amount = Decimal(claim['nEffectiveAmount'] / COIN)
claim['nEffectiveAmount'] = amount
return claim
def _get_claim_for_return(claim):
if not claim:
return False
d = self.get_claim(name, claim['claim_id'])
d.addCallback(_convert_units)
d.addCallback(lambda clm: self._format_claim_for_return(name, clm, claim['txid']))
return d
def _get_my_unspent_claim(claims):
for claim in claims:
if claim['name'] == name and not claim['is spent']:
return claim
return False
d = self.get_name_claims()
d.addCallback(_get_my_unspent_claim)
d.addCallback(_get_claim_for_return)
return d
def get_claim_info(self, name, txid=None):
if not txid:
d = self._get_value_for_name(name)
@ -377,9 +402,20 @@ class LBRYWallet(object):
d.addErrback(lambda _: False)
return d
def _format_claim_for_return(self, name, claim, txid, metadata=None, meta_version=None):
result = {}
result['claim_id'] = claim['claimId']
result['amount'] = claim['nEffectiveAmount']
result['height'] = claim['nHeight']
result['name'] = name
result['txid'] = txid
result['value'] = metadata if metadata else json.loads(claim['value'])
result['supports'] = [{'txid': support['txid'], 'n': support['n']} for support in claim['supports']]
result['meta_version'] = meta_version if meta_version else result['value'].get('ver', '0.0.1')
return result
def _get_claim_info(self, name, txid):
def _build_response(claim):
result = {}
try:
metadata = Metadata(json.loads(claim['value']))
meta_ver = metadata.version
@ -390,27 +426,12 @@ class LBRYWallet(object):
meta_ver = "Non-compliant"
d = defer.succeed(None)
claim_id = claim['claimId']
result['claim_id'] = claim_id
result['amount'] = claim['nEffectiveAmount']
result['height'] = claim['nHeight']
result['name'] = name
result['txid'] = txid
result['value'] = metadata
result['supports'] = [{'txid': support['txid'], 'n': support['n']} for support in claim['supports']]
result['meta_version'] = meta_ver
d.addCallback(lambda _: self._format_claim_for_return(name, claim, txid,
metadata=metadata, meta_version=meta_ver))
log.info("get claim info lbry://%s metadata: %s, claimid: %s", name, meta_ver, claim['claimId'])
log.info("get claim info lbry://%s metadata: %s, claimid: %s", name, meta_ver, claim_id)
d.addCallback(lambda _: self.get_name_claims())
d.addCallback(lambda r: [c['txid'] for c in r])
d.addCallback(lambda my_claims: _add_is_mine(result, my_claims))
return d
def _add_is_mine(response, my_txs):
response['is_mine'] = response['txid'] in my_txs
return response
d = self.get_claimid(name, txid)
d.addCallback(lambda claim_id: self.get_claim(name, claim_id))
d.addCallback(_build_response)
@ -741,9 +762,9 @@ class LBRYWallet(object):
pass
class LBRYcrdWallet(LBRYWallet):
class LBRYcrdWallet(Wallet):
def __init__(self, db_dir, wallet_dir=None, wallet_conf=None, lbrycrdd_path=None):
LBRYWallet.__init__(self, db_dir)
Wallet.__init__(self, db_dir)
self.started_lbrycrdd = False
self.wallet_dir = wallet_dir
self.wallet_conf = wallet_conf
@ -1087,10 +1108,10 @@ class LBRYcrdWallet(LBRYWallet):
self.lbrycrdd.wait()
class LBRYumWallet(LBRYWallet):
class LBRYumWallet(Wallet):
def __init__(self, db_dir):
LBRYWallet.__init__(self, db_dir)
Wallet.__init__(self, db_dir)
self.config = None
self.network = None
self.wallet = None
@ -1168,8 +1189,8 @@ class LBRYumWallet(LBRYWallet):
def get_wallet():
path = self.config.get_wallet_path()
storage = WalletStorage(path)
wallet = Wallet(storage)
storage = lbryum.wallet.WalletStorage(path)
wallet = lbryum.wallet.Wallet(storage)
if not storage.file_exists:
self.first_run = True
seed = wallet.make_seed()

View file

@ -13,6 +13,21 @@ from lbrynet.interfaces import IRequestCreator
log = logging.getLogger(__name__)
def get_points(num_bytes, rate):
return 1.0 * num_bytes * rate / 2**20
def cache(fn):
"""Caches the function call for each instance"""
attr = '__{}_value'.format(fn.__name__)
def helper(self):
if not hasattr(self, attr):
value = fn(self)
setattr(self, attr, value)
return getattr(self, attr)
return helper
class BlobRequester(object):
implements(IRequestCreator)
@ -30,56 +45,11 @@ class BlobRequester(object):
self._incompatible_peers = []
######## IRequestCreator #########
def send_next_request(self, peer, protocol):
sent_request = False
if self._blobs_to_download() and self._should_send_request_to(peer):
a_r = self._get_availability_request(peer)
d_r = self._get_download_request(peer)
p_r = None
if a_r is not None or d_r is not None:
p_r = self._get_price_request(peer, protocol)
if a_r is not None:
d1 = protocol.add_request(a_r)
d1.addCallback(self._handle_availability, peer, a_r)
d1.addErrback(self._request_failed, "availability request", peer)
sent_request = True
if d_r is not None:
reserved_points = self._reserve_points(peer, protocol, d_r.max_pay_units)
if reserved_points is not None:
# Note: The following three callbacks will be called when the blob has been
# fully downloaded or canceled
d_r.finished_deferred.addCallbacks(self._download_succeeded, self._download_failed,
callbackArgs=(peer, d_r.blob),
errbackArgs=(peer,))
d_r.finished_deferred.addBoth(self._pay_or_cancel_payment, protocol, reserved_points, d_r.blob)
d_r.finished_deferred.addErrback(self._handle_download_error, peer, d_r.blob)
d2 = protocol.add_blob_request(d_r)
# Note: The following two callbacks will be called as soon as the peer sends its
# response, which will be before the blob has finished downloading, but may be
# after the blob has been canceled. For example,
# 1) client sends request to Peer A
# 2) the blob is finished downloading from peer B, and therefore this one is canceled
# 3) client receives response from Peer A
# Therefore, these callbacks shouldn't rely on there being a blob about to be
# downloaded.
d2.addCallback(self._handle_incoming_blob, peer, d_r)
d2.addErrback(self._request_failed, "download request", peer)
sent_request = True
else:
d_r.cancel(InsufficientFundsError())
d_r.finished_deferred.addErrback(lambda _: True)
return defer.fail(InsufficientFundsError())
if sent_request is True:
if p_r is not None:
d3 = protocol.add_request(p_r)
d3.addCallback(self._handle_price_response, peer, p_r, protocol)
d3.addErrback(self._request_failed, "price request", peer)
return defer.succeed(sent_request)
"""Makes an availability request, download request and price request"""
if not self.should_send_next_request(peer):
return defer.succeed(False)
return self._send_next_request(peer, protocol)
def get_new_peers(self):
d = self._get_hash_for_peer_search()
@ -87,36 +57,34 @@ class BlobRequester(object):
return d
######### internal calls #########
def should_send_next_request(self, peer):
return (
self._blobs_to_download() and
self._should_send_request_to(peer)
)
def _download_succeeded(self, arg, peer, blob):
log.info("Blob %s has been successfully downloaded from %s", str(blob), str(peer))
self._update_local_score(peer, 5.0)
peer.update_stats('blobs_downloaded', 1)
peer.update_score(5.0)
self.blob_manager.blob_completed(blob)
return arg
def _send_next_request(self, peer, protocol):
log.debug('Sending a blob request for %s and %s', peer, protocol)
availability = AvailabilityRequest(self, peer, protocol)
download = DownloadRequest(self, peer, protocol, self.wallet, self.payment_rate_manager)
price = PriceRequest(self, peer, protocol)
def _download_failed(self, reason, peer):
if not reason.check(DownloadCanceledError, PriceDisagreementError):
self._update_local_score(peer, -10.0)
return reason
sent_request = False
if availability.can_make_request():
availability.make_request_and_handle_response()
sent_request = True
def _pay_or_cancel_payment(self, arg, protocol, reserved_points, blob):
if blob.length != 0 and (not isinstance(arg, Failure) or arg.check(DownloadCanceledError)):
self._pay_peer(protocol, blob.length, reserved_points)
else:
self._cancel_points(reserved_points)
return arg
def _handle_download_error(self, err, peer, blob_to_download):
if not err.check(DownloadCanceledError, PriceDisagreementError, RequestCanceledError):
log.warning("An error occurred while downloading %s from %s. Error: %s",
blob_to_download.blob_hash, str(peer), err.getTraceback())
if err.check(PriceDisagreementError):
# Don't kill the whole connection just because a price couldn't be agreed upon.
# Other information might be desired by other request creators at a better rate.
return True
return err
if download.can_make_request():
try:
download.make_request_and_handle_response()
sent_request = True
except InsufficientFundsError as err:
return defer.fail(err)
if sent_request and price.can_make_request():
# TODO: document why a PriceRequest is only made if an
# Availability or Download request was made
price.make_request_and_handle_response()
return defer.succeed(sent_request)
def _get_hash_for_peer_search(self):
r = None
@ -178,96 +146,71 @@ class BlobRequester(object):
return sorted(needed_blobs, key=lambda b: b.is_downloading())
def _blobs_without_sources(self):
return [b for b in self.download_manager.needed_blobs() if not self._hash_available(b.blob_hash)]
def _get_availability_request(self, peer):
all_needed = [b.blob_hash for b in self._blobs_to_download() if not b.blob_hash in self._available_blobs[peer]]
# sort them so that the peer will be asked first for blobs it hasn't said it doesn't have
to_request = sorted(all_needed, key=lambda b: b in self._unavailable_blobs[peer])[:20]
if to_request:
r_dict = {'requested_blobs': to_request}
response_identifier = 'available_blobs'
request = ClientRequest(r_dict, response_identifier)
return request
return None
def _get_download_request(self, peer):
request = None
to_download = [b for b in self._blobs_to_download() if self._hash_available_on(b.blob_hash, peer)]
while to_download and request is None:
blob_to_download = to_download[0]
to_download = to_download[1:]
if not blob_to_download.is_validated():
d, write_func, cancel_func = blob_to_download.open_for_writing(peer)
def counting_write_func(data):
peer.update_stats('blob_bytes_downloaded', len(data))
return write_func(data)
if d is not None:
request_dict = {'requested_blob': blob_to_download.blob_hash}
response_identifier = 'incoming_blob'
request = ClientBlobRequest(request_dict, response_identifier, counting_write_func, d,
cancel_func, blob_to_download)
log.info("Requesting blob %s from %s", str(blob_to_download), str(peer))
return request
return [
b for b in self.download_manager.needed_blobs()
if not self._hash_available(b.blob_hash)
]
def _price_settled(self, protocol):
if protocol in self._protocol_prices:
return True
return False
def _get_price_request(self, peer, protocol):
request = None
if not protocol in self._protocol_prices:
self._protocol_prices[protocol] = self.payment_rate_manager.get_rate_blob_data(peer)
request_dict = {'blob_data_payment_rate': self._protocol_prices[protocol]}
request = ClientRequest(request_dict, 'blob_data_payment_rate')
return request
def _update_local_score(self, peer, amount):
self._peers[peer] += amount
def _reserve_points(self, peer, protocol, max_bytes):
assert protocol in self._protocol_prices
points_to_reserve = 1.0 * max_bytes * self._protocol_prices[protocol] / 2**20
return self.wallet.reserve_points(peer, points_to_reserve)
def _pay_peer(self, protocol, num_bytes, reserved_points):
assert num_bytes != 0
assert protocol in self._protocol_prices
point_amount = 1.0 * num_bytes * self._protocol_prices[protocol] / 2**20
self.wallet.send_points(reserved_points, point_amount)
self.payment_rate_manager.record_points_paid(point_amount)
class RequestHelper(object):
def __init__(self, requestor, peer, protocol):
self.requestor = requestor
self.peer = peer
self.protocol = protocol
def _cancel_points(self, reserved_points):
self.wallet.cancel_point_reservation(reserved_points)
@property
def protocol_prices(self):
return self.requestor._protocol_prices
def _handle_availability(self, response_dict, peer, request):
if not request.response_identifier in response_dict:
raise InvalidResponseError("response identifier not in response")
log.debug("Received a response to the availability request")
blob_hashes = response_dict[request.response_identifier]
for blob_hash in blob_hashes:
if blob_hash in request.request_dict['requested_blobs']:
log.debug("The server has indicated it has the following blob available: %s", blob_hash)
self._available_blobs[peer].append(blob_hash)
if blob_hash in self._unavailable_blobs[peer]:
self._unavailable_blobs[peer].remove(blob_hash)
request.request_dict['requested_blobs'].remove(blob_hash)
for blob_hash in request.request_dict['requested_blobs']:
self._unavailable_blobs[peer].append(blob_hash)
return True
@property
def available_blobs(self):
return self.requestor._available_blobs[self.peer]
def _handle_incoming_blob(self, response_dict, peer, request):
@property
def unavailable_blobs(self):
return self.requestor._unavailable_blobs[self.peer]
def update_local_score(self, score):
self.requestor._update_local_score(self.peer, score)
def _request_failed(self, reason, request_type):
if reason.check(RequestCanceledError):
return
if reason.check(NoResponseError):
self.requestor._incompatible_peers.append(self.peer)
log.warning("A request of type '%s' failed. Reason: %s, Error type: %s",
request_type, reason.getErrorMessage(), reason.type)
self.update_local_score(-10.0)
if isinstance(reason, InvalidResponseError) or isinstance(reason, NoResponseError):
self.peer.update_score(-10.0)
else:
self.peer.update_score(-2.0)
if reason.check(ConnectionClosedBeforeResponseError):
return
return reason
def get_and_save_rate_for_protocol(self):
rate = self.protocol_prices.get(self.protocol)
if rate is None:
rate = self.requestor.payment_rate_manager.get_rate_blob_data(self.peer)
self.protocol_prices[self.protocol] = rate
return rate
def _handle_incoming_blob(response_dict, peer, request):
if not request.response_identifier in response_dict:
return InvalidResponseError("response identifier not in response")
if not type(response_dict[request.response_identifier]) == dict:
return InvalidResponseError("response not a dict. got %s" %
(type(response_dict[request.response_identifier]),))
type(response_dict[request.response_identifier]))
response = response_dict[request.response_identifier]
if 'error' in response:
# This means we're not getting our blob for some reason
@ -282,38 +225,295 @@ class BlobRequester(object):
if not 'blob_hash' in response:
return InvalidResponseError("Missing the required field 'blob_hash'")
if not response['blob_hash'] == request.request_dict['requested_blob']:
return InvalidResponseError("Incoming blob does not match expected. Incoming: %s. Expected: %s" %
(response['blob_hash'], request.request_dict['requested_blob']))
return InvalidResponseError(
"Incoming blob does not match expected. Incoming: %s. Expected: %s" %
(response['blob_hash'], request.request_dict['requested_blob'])
)
if not 'length' in response:
return InvalidResponseError("Missing the required field 'length'")
if not request.blob.set_length(response['length']):
return InvalidResponseError("Could not set the length of the blob")
return True
def _handle_price_response(self, response_dict, peer, request, protocol):
if not request.response_identifier in response_dict:
def _handle_download_error(err, peer, blob_to_download):
if not err.check(DownloadCanceledError, PriceDisagreementError, RequestCanceledError):
log.warning("An error occurred while downloading %s from %s. Error: %s",
blob_to_download.blob_hash, str(peer), err.getTraceback())
if err.check(PriceDisagreementError):
# Don't kill the whole connection just because a price couldn't be agreed upon.
# Other information might be desired by other request creators at a better rate.
return True
return err
class AvailabilityRequest(RequestHelper):
"""Ask a peer what blobs it has available.
Results are saved in `_available_blobs` and `_unavailable_blobs`
on the parent BlobRequester.
"""
def can_make_request(self):
return self.get_top_needed_blobs()
def make_request_and_handle_response(self):
request = self._get_request()
self._handle_request(request)
def _get_request(self):
to_request = self.get_top_needed_blobs()
if not to_request:
raise Exception('Unable to make a request without available blobs')
return self._make_request(to_request)
@cache
def get_top_needed_blobs(self, limit=20):
all_needed = [
b.blob_hash for b in self.requestor._blobs_to_download()
if not self.is_available(b)
]
# sort them so that the peer will be asked first for blobs it
# hasn't said it doesn't have
sorted_needed = sorted(
all_needed,
key=lambda b: b in self.unavailable_blobs
)
return sorted_needed[:limit]
def is_available(self, blob):
return blob.blob_hash in self.available_blobs
def _make_request(self, to_request):
log.debug('Requesting blobs: %s', to_request)
r_dict = {'requested_blobs': to_request}
response_identifier = 'available_blobs'
request = ClientRequest(r_dict, response_identifier)
return request
def _handle_request(self, a_r):
log.debug('making an availability request')
d1 = self.protocol.add_request(a_r)
d1.addCallback(self._handle_availability, a_r)
d1.addErrback(self._request_failed, "availability request")
def _handle_availability(self, response_dict, request):
assert request.response_identifier == 'available_blobs'
if 'available_blobs' not in response_dict:
raise InvalidResponseError("response identifier not in response")
log.debug("Received a response to the availability request")
# save available blobs
blob_hashes = response_dict['available_blobs']
for blob_hash in blob_hashes:
if blob_hash in request.request_dict['requested_blobs']:
self.process_available_blob_hash(blob_hash, request)
# everything left in the request is missing
for blob_hash in request.request_dict['requested_blobs']:
self.unavailable_blobs.append(blob_hash)
return True
def process_available_blob_hash(self, blob_hash, request):
log.debug("The server has indicated it has the following blob available: %s", blob_hash)
self.available_blobs.append(blob_hash)
self.remove_from_unavailable_blobs(blob_hash)
request.request_dict['requested_blobs'].remove(blob_hash)
def remove_from_unavailable_blobs(self, blob_hash):
if blob_hash in self.unavailable_blobs:
self.unavailable_blobs.remove(blob_hash)
class DownloadRequest(RequestHelper):
"""Choose a blob and download it from a peer and also pay the peer for the data."""
def __init__(self, requestor, peer, protocol, wallet, payment_rate_manager):
RequestHelper.__init__(self, requestor, peer, protocol)
self.wallet = wallet
self.payment_rate_manager = payment_rate_manager
def can_make_request(self):
return self.get_blob_details()
def make_request_and_handle_response(self):
request = self._get_request()
self._handle_download_request(request)
def _get_request(self):
blob_details = self.get_blob_details()
if not blob_details:
raise Exception('No blobs available to download')
return self._make_request(blob_details)
@cache
def get_blob_details(self):
"""Open a blob for writing and return the details.
If no blob can be opened, returns None.
"""
to_download = self.get_available_blobs()
return self.find_blob(to_download)
def get_available_blobs(self):
available_blobs = [
b for b in self.requestor._blobs_to_download()
if self.requestor._hash_available_on(b.blob_hash, self.peer)
]
log.debug('available blobs: %s', available_blobs)
return available_blobs
def find_blob(self, to_download):
"""Return the first blob in `to_download` that is successfully opened for write."""
for blob in to_download:
if blob.is_validated():
log.debug('Skipping blob %s as its already validated', blob)
continue
d, write_func, cancel_func = blob.open_for_writing(self.peer)
if d is not None:
return BlobDownloadDetails(blob, d, write_func, cancel_func, self.peer)
log.debug('Skipping blob %s as there was an issue opening it for writing', blob)
return None
def _make_request(self, blob_details):
blob = blob_details.blob
request = ClientBlobRequest(
{'requested_blob': blob.blob_hash},
'incoming_blob',
blob_details.counting_write_func,
blob_details.deferred,
blob_details.cancel_func,
blob
)
log.info("Requesting blob %s from %s", blob.blob_hash, self.peer)
return request
def _handle_download_request(self, client_blob_request):
reserved_points = self.reserve_funds_or_cancel(client_blob_request)
self.add_callbacks_to_download_request(client_blob_request, reserved_points)
self.create_add_blob_request(client_blob_request)
def reserve_funds_or_cancel(self, client_blob_request):
reserved_points = self._reserve_points(client_blob_request.max_pay_units)
if reserved_points is not None:
return reserved_points
client_blob_request.cancel(InsufficientFundsError())
client_blob_request.finished_deferred.addErrback(lambda _: True)
raise InsufficientFundsError()
def add_callbacks_to_download_request(self, client_blob_request, reserved_points):
# Note: The following three callbacks will be called when the blob has been
# fully downloaded or canceled
client_blob_request.finished_deferred.addCallbacks(
self._download_succeeded,
self._download_failed,
callbackArgs=(client_blob_request.blob,),
)
client_blob_request.finished_deferred.addBoth(
self._pay_or_cancel_payment, reserved_points, client_blob_request.blob)
client_blob_request.finished_deferred.addErrback(
_handle_download_error, self.peer, client_blob_request.blob)
def _pay_or_cancel_payment(self, arg, reserved_points, blob):
if self._can_pay_peer(blob, arg):
self._pay_peer(blob.length, reserved_points)
else:
self._cancel_points(reserved_points)
return arg
def _can_pay_peer(self, blob, arg):
return (
blob.length != 0 and
(not isinstance(arg, Failure) or arg.check(DownloadCanceledError))
)
def _pay_peer(self, num_bytes, reserved_points):
assert num_bytes != 0
rate = self.get_and_save_rate_for_protocol()
point_amount = get_points(num_bytes, rate)
self.wallet.send_points(reserved_points, point_amount)
self.payment_rate_manager.record_points_paid(point_amount)
def _cancel_points(self, reserved_points):
self.wallet.cancel_point_reservation(reserved_points)
def create_add_blob_request(self, client_blob_request):
d = self.protocol.add_blob_request(client_blob_request)
# Note: The following two callbacks will be called as soon as the peer sends its
# response, which will be before the blob has finished downloading, but may be
# after the blob has been canceled. For example,
# 1) client sends request to Peer A
# 2) the blob is finished downloading from peer B, and therefore this one is canceled
# 3) client receives response from Peer A
# Therefore, these callbacks shouldn't rely on there being a blob about to be
# downloaded.
d.addCallback(_handle_incoming_blob, self.peer, client_blob_request)
d.addErrback(self._request_failed, "download request")
def _reserve_points(self, num_bytes):
# jobevers: there was an assertion here, but I don't think it
# was a valid assertion to make. It is possible for a rate to
# not yet been set for this protocol or for it to have been
# removed so instead I switched it to check if a rate has been set
# and calculate it if it has not
rate = self.get_and_save_rate_for_protocol()
points_to_reserve = get_points(num_bytes, rate)
return self.wallet.reserve_points(self.peer, points_to_reserve)
def _download_succeeded(self, arg, blob):
log.info("Blob %s has been successfully downloaded from %s", blob, self.peer)
self.update_local_score(5.0)
self.peer.update_stats('blobs_downloaded', 1)
self.peer.update_score(5.0)
self.requestor.blob_manager.blob_completed(blob)
return arg
def _download_failed(self, reason):
if not reason.check(DownloadCanceledError, PriceDisagreementError):
self.update_local_score(-10.0)
return reason
class BlobDownloadDetails(object):
"""Contains the information needed to make a ClientBlobRequest from an open blob"""
def __init__(self, blob, deferred, write_func, cancel_func, peer):
self.blob = blob
self.deferred = deferred
self.write_func = write_func
self.cancel_func = cancel_func
self.peer = peer
def counting_write_func(self, data):
self.peer.update_stats('blob_bytes_downloaded', len(data))
return self.write_func(data)
class PriceRequest(RequestHelper):
"""Ask a peer if a certain price is acceptable"""
def can_make_request(self):
return self.get_and_save_rate_for_protocol() is not None
def make_request_and_handle_response(self):
request = self._get_price_request()
self._handle_price_request(request)
def _get_price_request(self):
rate = self.get_and_save_rate_for_protocol()
if rate is None:
raise Exception('Cannot make a price request without a payment rate')
request_dict = {'blob_data_payment_rate': rate}
return ClientRequest(request_dict, 'blob_data_payment_rate')
def _handle_price_request(self, price_request):
d = self.protocol.add_request(price_request)
d.addCallback(self._handle_price_response, price_request)
d.addErrback(self._request_failed, "price request")
def _handle_price_response(self, response_dict, request):
assert request.response_identifier == 'blob_data_payment_rate'
if 'blob_data_payment_rate' not in response_dict:
return InvalidResponseError("response identifier not in response")
assert protocol in self._protocol_prices
response = response_dict[request.response_identifier]
assert self.protocol in self.protocol_prices
response = response_dict['blob_data_payment_rate']
if response == "RATE_ACCEPTED":
return True
else:
del self._protocol_prices[protocol]
self._price_disagreements.append(peer)
del self.protocol_prices[self.protocol]
self.requestor._price_disagreements.append(self.peer)
return True
def _request_failed(self, reason, request_type, peer):
if reason.check(RequestCanceledError):
return
if reason.check(NoResponseError):
self._incompatible_peers.append(peer)
log.warning("Blob requester: a request of type '%s' failed. Reason: %s, Error type: %s",
str(request_type), reason.getErrorMessage(), reason.type)
self._update_local_score(peer, -10.0)
if isinstance(reason, InvalidResponseError) or isinstance(reason, NoResponseError):
peer.update_score(-10.0)
else:
peer.update_score(-2.0)
if reason.check(ConnectionClosedBeforeResponseError):
return
return reason

View file

@ -49,8 +49,8 @@ class ConnectionManager(object):
for peer in self._peer_connections.keys():
def close_connection(p):
log.info("Abruptly closing a connection to %s due to downloading being paused",
str(p))
log.info(
"Abruptly closing a connection to %s due to downloading being paused", p)
if self._peer_connections[p].factory.p is not None:
d = self._peer_connections[p].factory.p.cancel_requests()
@ -73,7 +73,7 @@ class ConnectionManager(object):
def get_next_request(self, peer, protocol):
log.debug("Trying to get the next request for peer %s", str(peer))
log.debug("Trying to get the next request for peer %s", peer)
if not peer in self._peer_connections or self.stopped is True:
log.debug("The peer has already been told to shut down.")
@ -148,7 +148,7 @@ class ConnectionManager(object):
from twisted.internet import reactor
if peer is not None and self.stopped is False:
log.debug("Trying to connect to %s", str(peer))
log.debug("Trying to connect to %s", peer)
factory = ClientProtocolFactory(peer, self.rate_limiter, self)
self._peer_connections[peer] = PeerConnectionHandler(self._primary_request_creators[:],
factory)
@ -162,7 +162,7 @@ class ConnectionManager(object):
def get_new_peers(request_creators):
log.debug("Trying to get a new peer to connect to")
if len(request_creators) > 0:
log.debug("Got a creator to check: %s", str(request_creators[0]))
log.debug("Got a creator to check: %s", request_creators[0])
d = request_creators[0].get_new_peers()
d.addCallback(lambda h: h if h is not None else get_new_peers(request_creators[1:]))
return d
@ -173,12 +173,12 @@ class ConnectionManager(object):
# TODO: Eventually rank them based on past performance/reputation. For now
# TODO: just pick the first to which we don't have an open connection
log.debug("Got a list of peers to choose from: %s", str(peers))
log.debug("Got a list of peers to choose from: %s", peers)
if peers is None:
return None
for peer in peers:
if not peer in self._peer_connections:
log.debug("Got a good peer. Returning peer %s", str(peer))
log.debug("Got a good peer. Returning peer %s", peer)
return peer
log.debug("Couldn't find a good peer to connect to")
return None

View file

@ -93,7 +93,6 @@ class DummyBlobHandler(object):
class StandaloneBlobDownloader(object):
def __init__(self, blob_hash, blob_manager, peer_finder, rate_limiter, payment_rate_manager, wallet):
self.blob_hash = blob_hash
self.blob_manager = blob_manager

View file

@ -73,16 +73,15 @@ def _log_decorator(fn):
def disable_third_party_loggers():
logging.getLogger('requests').setLevel(logging.WARNING)
logging.getLogger('BitcoinRPC').setLevel(logging.INFO)
def disable_noisy_loggers():
logging.getLogger('BitcoinRPC').setLevel(logging.INFO)
logging.getLogger('lbrynet.analytics.api').setLevel(logging.INFO)
logging.getLogger('lbrynet.core.client').setLevel(logging.INFO)
logging.getLogger('lbrynet.core.server').setLevel(logging.INFO)
logging.getLogger('lbrynet.dht').setLevel(logging.INFO)
logging.getLogger('lbrynet.lbrynet_daemon').setLevel(logging.INFO)
logging.getLogger('lbrynet.core.LBRYWallet').setLevel(logging.INFO)
logging.getLogger('lbrynet.core.Wallet').setLevel(logging.INFO)
logging.getLogger('lbrynet.lbryfile').setLevel(logging.INFO)
logging.getLogger('lbrynet.lbryfilemanager').setLevel(logging.INFO)

View file

@ -32,12 +32,14 @@ class BlobRequestHandlerFactory(object):
class BlobRequestHandler(object):
implements(IQueryHandler, IBlobSender)
PAYMENT_RATE_QUERY = 'blob_data_payment_rate'
BLOB_QUERY = 'requested_blob'
def __init__(self, blob_manager, wallet, payment_rate_manager):
self.blob_manager = blob_manager
self.payment_rate_manager = payment_rate_manager
self.wallet = wallet
self.query_identifiers = ['blob_data_payment_rate', 'requested_blob']
self.query_identifiers = [self.PAYMENT_RATE_QUERY, self.BLOB_QUERY]
self.peer = None
self.blob_data_payment_rate = None
self.read_handle = None
@ -54,43 +56,51 @@ class BlobRequestHandler(object):
def handle_queries(self, queries):
response = {}
if self.query_identifiers[0] in queries:
if not self.handle_blob_data_payment_rate(queries[self.query_identifiers[0]]):
if self.PAYMENT_RATE_QUERY in queries:
self._handle_payment_rate_query(response, queries[self.PAYMENT_RATE_QUERY])
if self.BLOB_QUERY in queries:
return self._handle_blob_query(response, queries[self.BLOB_QUERY])
else:
return defer.succeed(response)
def _handle_payment_rate_query(self, response, query):
if not self.handle_blob_data_payment_rate(query):
response['blob_data_payment_rate'] = "RATE_TOO_LOW"
else:
response['blob_data_payment_rate'] = 'RATE_ACCEPTED'
if self.query_identifiers[1] in queries:
def _handle_blob_query(self, response, query):
log.debug("Received the client's request to send a blob")
response_fields = {}
response['incoming_blob'] = response_fields
response['incoming_blob'] = {}
if self.blob_data_payment_rate is None:
response_fields['error'] = "RATE_UNSET"
response['incoming_blob']['error'] = "RATE_UNSET"
return defer.succeed(response)
else:
return self._send_blob(response, query)
d = self.blob_manager.get_blob(queries[self.query_identifiers[1]], True)
def _send_blob(self, response, query):
d = self.blob_manager.get_blob(query, True)
d.addCallback(self.open_blob_for_reading, response)
return d
def open_blob_for_reading(blob):
if blob.is_validated():
def open_blob_for_reading(self, blob, response):
def failure(msg):
log.warning("We can not send %s: %s", blob, msg)
response['incoming_blob']['error'] = "BLOB_UNAVAILABLE"
return response
if not blob.is_validated():
return failure("blob can't be validated")
read_handle = blob.open_for_reading()
if read_handle is not None:
if read_handle is None:
return failure("blob can't be opened")
self.currently_uploading = blob
self.read_handle = read_handle
log.info("Sending %s to client", str(blob))
response_fields['blob_hash'] = blob.blob_hash
response_fields['length'] = blob.length
log.info("Sending %s to client", blob)
response['incoming_blob']['blob_hash'] = blob.blob_hash
response['incoming_blob']['length'] = blob.length
return response
log.warning("We can not send %s", str(blob))
response_fields['error'] = "BLOB_UNAVAILABLE"
return response
d.addCallback(open_blob_for_reading)
return d
else:
return defer.succeed(response)
######### IBlobSender #########

View file

@ -50,7 +50,7 @@ class CryptStreamDownloader(object):
@param payment_rate_manager: A PaymentRateManager object
@param wallet: An object which implements the ILBRYWallet interface
@param wallet: An object which implements the IWallet interface
@return:
"""

View file

@ -233,14 +233,14 @@
# " foreign key(stream_hash) references lbry_files(stream_hash)" +
# ")")
# new_db.commit()
# LBRYFILE_STATUS = "t"
# LBRYFILE_OPTIONS = "o"
# FILE_STATUS = "t"
# FILE_OPTIONS = "o"
# c = new_db.cursor()
# for k, v in old_db.RangeIter():
# key_type, stream_hash = json.loads(k)
# if key_type == LBRYFILE_STATUS:
# if key_type == FILE_STATUS:
# try:
# rate = json.loads(old_db.Get(json.dumps((LBRYFILE_OPTIONS, stream_hash))))[0]
# rate = json.loads(old_db.Get(json.dumps((FILE_OPTIONS, stream_hash))))[0]
# except KeyError:
# rate = None
# c.execute("insert into lbry_file_options values (?, ?, ?)",

View file

@ -548,13 +548,13 @@ class IStreamDescriptorValidator(Interface):
"""
class ILBRYWallet(Interface):
class IWallet(Interface):
"""
Send and receive payments.
To send a payment, a payment reservation must be obtained first. This guarantees that a payment
isn't promised if it can't be paid. When the service in question is rendered, the payment
reservation must be given to the ILBRYWallet along with the final price. The reservation can also
reservation must be given to the IWallet along with the final price. The reservation can also
be canceled.
"""
def stop(self):

View file

@ -11,7 +11,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked
log = logging.getLogger(__name__)
class DBLBRYFileMetadataManager(object):
class DBEncryptedFileMetadataManager(object):
"""Store and provide access to LBRY file metadata using sqlite"""
def __init__(self, db_dir):
@ -243,7 +243,7 @@ class DBLBRYFileMetadataManager(object):
return d
class TempLBRYFileMetadataManager(object):
class TempEncryptedFileMetadataManager(object):
def __init__(self):
self.streams = {}
self.stream_blobs = {}

View file

@ -11,7 +11,7 @@ import os
log = logging.getLogger(__name__)
LBRYFileStreamType = "lbryfile"
EncryptedFileStreamType = "lbryfile"
def save_sd_info(stream_info_manager, sd_info, ignore_duplicate=False):
@ -50,7 +50,7 @@ def get_sd_info(stream_info_manager, stream_hash, include_blobs):
def format_info(stream_info):
fields = {}
fields['stream_type'] = LBRYFileStreamType
fields['stream_type'] = EncryptedFileStreamType
fields['stream_name'] = stream_info[1]
fields['key'] = stream_info[0]
fields['suggested_file_name'] = stream_info[2]
@ -121,7 +121,7 @@ def create_plain_sd(stream_info_manager, stream_hash, file_name, overwrite_exist
return d
class LBRYFileStreamDescriptorValidator(object):
class EncryptedFileStreamDescriptorValidator(object):
def __init__(self, raw_info):
self.raw_info = raw_info

View file

@ -8,7 +8,7 @@ from lbrynet.cryptstream.client.CryptStreamDownloader import CryptStreamDownload
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
from lbrynet.core.StreamDescriptor import StreamMetadata
from lbrynet.interfaces import IStreamDownloaderFactory
from lbrynet.lbryfile.client.LBRYFileMetadataHandler import LBRYFileMetadataHandler
from lbrynet.lbryfile.client.EncryptedFileMetadataHandler import EncryptedFileMetadataHandler
import os
from twisted.internet import defer, threads, reactor
from twisted.python.procutils import which
@ -19,7 +19,7 @@ import traceback
log = logging.getLogger(__name__)
class LBRYFileDownloader(CryptStreamDownloader):
class EncryptedFileDownloader(CryptStreamDownloader):
"""Classes which inherit from this class download LBRY files"""
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
@ -120,10 +120,10 @@ class LBRYFileDownloader(CryptStreamDownloader):
return 0
def _get_metadata_handler(self, download_manager):
return LBRYFileMetadataHandler(self.stream_hash, self.stream_info_manager, download_manager)
return EncryptedFileMetadataHandler(self.stream_hash, self.stream_info_manager, download_manager)
class LBRYFileDownloaderFactory(object):
class EncryptedFileDownloaderFactory(object):
implements(IStreamDownloaderFactory)
def __init__(self, peer_finder, rate_limiter, blob_manager, stream_info_manager,
@ -165,10 +165,10 @@ class LBRYFileDownloaderFactory(object):
pass
class LBRYFileSaver(LBRYFileDownloader):
class EncryptedFileSaver(EncryptedFileDownloader):
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
payment_rate_manager, wallet, download_directory, upload_allowed, file_name=None):
LBRYFileDownloader.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
EncryptedFileDownloader.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
stream_info_manager, payment_rate_manager, wallet, upload_allowed)
self.download_directory = download_directory
self.file_name = file_name
@ -182,7 +182,7 @@ class LBRYFileSaver(LBRYFileDownloader):
return str(self.file_name)
def set_stream_info(self):
d = LBRYFileDownloader.set_stream_info(self)
d = EncryptedFileDownloader.set_stream_info(self)
def set_file_name():
if self.file_name is None:
@ -195,7 +195,7 @@ class LBRYFileSaver(LBRYFileDownloader):
return d
def stop(self, err=None):
d = LBRYFileDownloader.stop(self, err=err)
d = EncryptedFileDownloader.stop(self, err=err)
d.addCallback(lambda _: self._delete_from_info_manager())
return d
@ -257,15 +257,15 @@ class LBRYFileSaver(LBRYFileDownloader):
return self.stream_info_manager.delete_stream(self.stream_hash)
class LBRYFileSaverFactory(LBRYFileDownloaderFactory):
class EncryptedFileSaverFactory(EncryptedFileDownloaderFactory):
def __init__(self, peer_finder, rate_limiter, blob_manager, stream_info_manager,
wallet, download_directory):
LBRYFileDownloaderFactory.__init__(self, peer_finder, rate_limiter, blob_manager,
EncryptedFileDownloaderFactory.__init__(self, peer_finder, rate_limiter, blob_manager,
stream_info_manager, wallet)
self.download_directory = download_directory
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info, upload_allowed):
return LBRYFileSaver(stream_hash, self.peer_finder, self.rate_limiter, self.blob_manager,
return EncryptedFileSaver(stream_hash, self.peer_finder, self.rate_limiter, self.blob_manager,
self.stream_info_manager, payment_rate_manager, self.wallet,
self.download_directory, upload_allowed)
@ -274,16 +274,16 @@ class LBRYFileSaverFactory(LBRYFileDownloaderFactory):
return "Save"
class LBRYFileOpener(LBRYFileDownloader):
class EncryptedFileOpener(EncryptedFileDownloader):
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
payment_rate_manager, wallet, upload_allowed):
LBRYFileDownloader.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
EncryptedFileDownloader.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
stream_info_manager, payment_rate_manager, wallet, upload_allowed)
self.process = None
self.process_log = None
def stop(self, err=None):
d = LBRYFileDownloader.stop(self, err=err)
d = EncryptedFileDownloader.stop(self, err=err)
d.addCallback(lambda _: self._delete_from_info_manager())
return d
@ -333,7 +333,7 @@ class LBRYFileOpener(LBRYFileDownloader):
return self.stream_info_manager.delete_stream(self.stream_hash)
class LBRYFileOpenerFactory(LBRYFileDownloaderFactory):
class EncryptedFileOpenerFactory(EncryptedFileDownloaderFactory):
def can_download(self, sd_validator):
if which('vlc'):
return True
@ -346,7 +346,7 @@ class LBRYFileOpenerFactory(LBRYFileDownloaderFactory):
return False
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info, upload_allowed):
return LBRYFileOpener(stream_hash, self.peer_finder, self.rate_limiter, self.blob_manager,
return EncryptedFileOpener(stream_hash, self.peer_finder, self.rate_limiter, self.blob_manager,
self.stream_info_manager, payment_rate_manager, self.wallet, upload_allowed)
@staticmethod

View file

@ -7,7 +7,7 @@ from lbrynet.interfaces import IMetadataHandler
log = logging.getLogger(__name__)
class LBRYFileMetadataHandler(object):
class EncryptedFileMetadataHandler(object):
implements(IMetadataHandler)
def __init__(self, stream_hash, stream_info_manager, download_manager):

View file

@ -1,12 +1,12 @@
from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType, LBRYFileStreamDescriptorValidator
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType, EncryptedFileStreamDescriptorValidator
from lbrynet.core.DownloadOption import DownloadOption, DownloadOptionChoice
def add_lbry_file_to_sd_identifier(sd_identifier):
sd_identifier.add_stream_type(LBRYFileStreamType, LBRYFileStreamDescriptorValidator, LBRYFileOptions())
sd_identifier.add_stream_type(EncryptedFileStreamType, EncryptedFileStreamDescriptorValidator, EncryptedFileOptions())
class LBRYFileOptions(object):
class EncryptedFileOptions(object):
def __init__(self):
pass

View file

@ -16,9 +16,9 @@ from twisted.protocols.basic import FileSender
log = logging.getLogger(__name__)
class LBRYFileStreamCreator(CryptStreamCreator):
class EncryptedFileStreamCreator(CryptStreamCreator):
"""
A CryptStreamCreator which adds itself and its additional metadata to an LBRYFileManager
A CryptStreamCreator which adds itself and its additional metadata to an EncryptedFileManager
"""
def __init__(self, blob_manager, lbry_file_manager, name=None,
key=None, iv_generator=None, suggested_file_name=None):
@ -93,11 +93,11 @@ def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=Non
into chunks and encrypted, and then a stream descriptor file with the stream parameters
and other metadata is written to disk.
@param session: An LBRYSession object.
@type session: LBRYSession
@param session: An Session object.
@type session: Session
@param lbry_file_manager: The LBRYFileManager object this LBRY File will be added to.
@type lbry_file_manager: LBRYFileManager
@param lbry_file_manager: The EncryptedFileManager object this LBRY File will be added to.
@type lbry_file_manager: EncryptedFileManager
@param file_name: The path to the plain file.
@type file_name: string
@ -141,7 +141,7 @@ def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=Non
base_file_name = os.path.basename(file_name)
lbry_file_creator = LBRYFileStreamCreator(session.blob_manager, lbry_file_manager, base_file_name,
lbry_file_creator = EncryptedFileStreamCreator(session.blob_manager, lbry_file_manager, base_file_name,
key, iv_generator, suggested_file_name)
def start_stream():

View file

@ -5,8 +5,8 @@ Download LBRY Files from LBRYnet and save them to disk.
from zope.interface import implements
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
from lbrynet.core.StreamDescriptor import StreamMetadata
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaver, LBRYFileDownloader
from lbrynet.lbryfilemanager.LBRYFileStatusReport import LBRYFileStatusReport
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaver, EncryptedFileDownloader
from lbrynet.lbryfilemanager.EncryptedFileStatusReport import EncryptedFileStatusReport
from lbrynet.interfaces import IStreamDownloaderFactory
from lbrynet.lbryfile.StreamDescriptor import save_sd_info
from twisted.internet import defer
@ -15,7 +15,7 @@ import logging
log = logging.getLogger(__name__)
class ManagedLBRYFileDownloader(LBRYFileSaver):
class ManagedEncryptedFileDownloader(EncryptedFileSaver):
STATUS_RUNNING = "running"
STATUS_STOPPED = "stopped"
@ -24,7 +24,7 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
def __init__(self, rowid, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
lbry_file_manager, payment_rate_manager, wallet, download_directory, upload_allowed,
file_name=None):
LBRYFileSaver.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
EncryptedFileSaver.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
stream_info_manager, payment_rate_manager, wallet, download_directory,
upload_allowed, file_name)
self.sd_hash = None
@ -68,11 +68,11 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
d.addCallback(lambda _: self.lbry_file_manager.get_lbry_file_status(self))
def restore_status(status):
if status == ManagedLBRYFileDownloader.STATUS_RUNNING:
if status == ManagedEncryptedFileDownloader.STATUS_RUNNING:
return self.start()
elif status == ManagedLBRYFileDownloader.STATUS_STOPPED:
elif status == ManagedEncryptedFileDownloader.STATUS_STOPPED:
return defer.succeed(False)
elif status == ManagedLBRYFileDownloader.STATUS_FINISHED:
elif status == ManagedEncryptedFileDownloader.STATUS_FINISHED:
self.completed = True
return defer.succeed(True)
@ -84,7 +84,7 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
def set_saving_status_done():
self.saving_status = False
d = LBRYFileDownloader.stop(self, err=err) # LBRYFileSaver deletes metadata when it's stopped. We don't want that here.
d = EncryptedFileDownloader.stop(self, err=err) # EncryptedFileSaver deletes metadata when it's stopped. We don't want that here.
if change_status is True:
self.saving_status = True
d.addCallback(lambda _: self._save_status())
@ -111,7 +111,7 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
s = "stopped"
else:
s = "running"
status = LBRYFileStatusReport(self.file_name, num_completed, num_known, s)
status = EncryptedFileStatusReport(self.file_name, num_completed, num_known, s)
return status
d = self.stream_info_manager.get_blobs_for_stream(self.stream_hash)
@ -121,7 +121,7 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
def _start(self):
d = LBRYFileSaver._start(self)
d = EncryptedFileSaver._start(self)
d.addCallback(lambda _: self.stream_info_manager._get_sd_blob_hashes_for_stream(self.stream_hash))
@ -153,18 +153,18 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
def _save_status(self):
if self.completed is True:
s = ManagedLBRYFileDownloader.STATUS_FINISHED
s = ManagedEncryptedFileDownloader.STATUS_FINISHED
elif self.stopped is True:
s = ManagedLBRYFileDownloader.STATUS_STOPPED
s = ManagedEncryptedFileDownloader.STATUS_STOPPED
else:
s = ManagedLBRYFileDownloader.STATUS_RUNNING
s = ManagedEncryptedFileDownloader.STATUS_RUNNING
return self.lbry_file_manager.change_lbry_file_status(self, s)
def _get_progress_manager(self, download_manager):
return FullStreamProgressManager(self._finished_downloading, self.blob_manager, download_manager)
class ManagedLBRYFileDownloaderFactory(object):
class ManagedEncryptedFileDownloaderFactory(object):
implements(IStreamDownloaderFactory)
def __init__(self, lbry_file_manager):

View file

@ -9,9 +9,9 @@ from twisted.enterprise import adbapi
from twisted.internet import defer, task, reactor
from twisted.python.failure import Failure
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloader
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloaderFactory
from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
from lbrynet.core.PaymentRateManager import PaymentRateManager
from lbrynet.cryptstream.client.CryptStreamDownloader import AlreadyStoppedError, CurrentlyStoppingError
from lbrynet.core.sqlite_helpers import rerun_if_locked
@ -20,7 +20,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked
log = logging.getLogger(__name__)
class LBRYFileManager(object):
class EncryptedFileManager(object):
"""
Keeps track of currently opened LBRY Files, their options, and their LBRY File specific metadata.
"""
@ -35,7 +35,7 @@ class LBRYFileManager(object):
self.download_directory = download_directory
else:
self.download_directory = os.getcwd()
log.debug("Download directory for LBRYFileManager: %s", str(self.download_directory))
log.debug("Download directory for EncryptedFileManager: %s", str(self.download_directory))
def setup(self):
d = self._open_db()
@ -68,8 +68,8 @@ class LBRYFileManager(object):
return dl
def _add_to_sd_identifier(self):
downloader_factory = ManagedLBRYFileDownloaderFactory(self)
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, downloader_factory)
downloader_factory = ManagedEncryptedFileDownloaderFactory(self)
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, downloader_factory)
def _start_lbry_files(self):
@ -101,7 +101,7 @@ class LBRYFileManager(object):
if not download_directory:
download_directory = self.download_directory
payment_rate_manager.min_blob_data_payment_rate = blob_data_rate
lbry_file_downloader = ManagedLBRYFileDownloader(rowid, stream_hash,
lbry_file_downloader = ManagedEncryptedFileDownloader(rowid, stream_hash,
self.session.peer_finder,
self.session.rate_limiter,
self.session.blob_manager,
@ -207,7 +207,7 @@ class LBRYFileManager(object):
def _save_lbry_file(self, stream_hash, data_payment_rate):
def do_save(db_transaction):
db_transaction.execute("insert into lbry_file_options values (?, ?, ?)",
(data_payment_rate, ManagedLBRYFileDownloader.STATUS_STOPPED,
(data_payment_rate, ManagedEncryptedFileDownloader.STATUS_STOPPED,
stream_hash))
return db_transaction.lastrowid
return self.sql_db.runInteraction(do_save)
@ -236,7 +236,7 @@ class LBRYFileManager(object):
def _get_lbry_file_status(self, rowid):
d = self.sql_db.runQuery("select status from lbry_file_options where rowid = ?",
(rowid,))
d.addCallback(lambda r: r[0][0] if len(r) else ManagedLBRYFileDownloader.STATUS_STOPPED)
d.addCallback(lambda r: r[0][0] if len(r) else ManagedEncryptedFileDownloader.STATUS_STOPPED)
return d
@rerun_if_locked

View file

@ -1,4 +1,4 @@
class LBRYFileStatusReport(object):
class EncryptedFileStatusReport(object):
def __init__(self, name, num_completed, num_known, running_status):
self.name = name
self.num_completed = num_completed

View file

@ -5,7 +5,7 @@ import logging
import sys
from lbrynet.lbrylive.LiveStreamCreator import StdOutLiveStreamCreator
from lbrynet.core.BlobManager import TempBlobManager
from lbrynet.core.Session import LBRYSession
from lbrynet.core.Session import Session
from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
@ -16,7 +16,7 @@ from lbrynet.dht.node import Node
from twisted.internet import defer, task
class LBRYStdinUploader():
class StdinUploader():
"""This class reads from standard in, creates a stream, and makes it available on the network."""
def __init__(self, peer_port, dht_node_port, known_dht_nodes,
stream_info_manager_class=DBLiveStreamMetadataManager, blob_manager_class=TempBlobManager):
@ -29,7 +29,7 @@ class LBRYStdinUploader():
"""
self.peer_port = peer_port
self.lbry_server_port = None
self.session = LBRYSession(blob_manager_class=blob_manager_class,
self.session = Session(blob_manager_class=blob_manager_class,
stream_info_manager_class=stream_info_manager_class,
dht_node_class=Node, dht_node_port=dht_node_port,
known_dht_nodes=known_dht_nodes, peer_port=self.peer_port,
@ -99,9 +99,9 @@ def launch_stdin_uploader():
logging.basicConfig(level=logging.WARNING, filename="ul.log")
if len(sys.argv) == 4:
uploader = LBRYStdinUploader(int(sys.argv[2]), int(sys.argv[3]), [])
uploader = StdinUploader(int(sys.argv[2]), int(sys.argv[3]), [])
elif len(sys.argv) == 6:
uploader = LBRYStdinUploader(int(sys.argv[2]), int(sys.argv[3]), [(sys.argv[4], int(sys.argv[5]))])
uploader = StdinUploader(int(sys.argv[2]), int(sys.argv[3]), [(sys.argv[4], int(sys.argv[5]))])
else:
print "Usage: lbrynet-stdin-uploader <stream_name> <peer_port> <dht_node_port>" \
" [<dht_bootstrap_host> <dht_bootstrap port>]"

View file

@ -4,9 +4,9 @@
import logging
import sys
from lbrynet.lbrylive.client.LiveStreamDownloader import LBRYLiveStreamDownloader
from lbrynet.lbrylive.client.LiveStreamDownloader import LiveStreamDownloader
from lbrynet.core.BlobManager import TempBlobManager
from lbrynet.core.Session import LBRYSession
from lbrynet.core.Session import Session
from lbrynet.core.client.StandaloneBlobDownloader import StandaloneBlobDownloader
from lbrynet.core.StreamDescriptor import BlobStreamDescriptorReader
from lbrynet.lbrylive.PaymentRateManager import BaseLiveStreamPaymentRateManager
@ -16,7 +16,7 @@ from lbrynet.dht.node import Node
from twisted.internet import task
class LBRYStdoutDownloader():
class StdoutDownloader():
"""This class downloads a live stream from the network and outputs it to standard out."""
def __init__(self, dht_node_port, known_dht_nodes,
stream_info_manager_class=DBLiveStreamMetadataManager, blob_manager_class=TempBlobManager):
@ -27,7 +27,7 @@ class LBRYStdoutDownloader():
"""
self.session = LBRYSession(blob_manager_class=blob_manager_class,
self.session = Session(blob_manager_class=blob_manager_class,
stream_info_manager_class=stream_info_manager_class,
dht_node_class=Node, dht_node_port=dht_node_port, known_dht_nodes=known_dht_nodes,
use_upnp=False)
@ -55,7 +55,7 @@ class LBRYStdoutDownloader():
d.addCallbacks(self.read_sd_file)
def start_stream(stream_hash):
consumer = LBRYLiveStreamDownloader(stream_hash, self.session.peer_finder,
consumer = LiveStreamDownloader(stream_hash, self.session.peer_finder,
self.session.rate_limiter, self.session.blob_manager,
self.stream_info_manager, self.payment_rate_manager,
self.session.wallet)
@ -76,9 +76,9 @@ def launch_stdout_downloader():
logging.basicConfig(level=logging.WARNING, filename="dl.log")
if len(sys.argv) == 3:
downloader = LBRYStdoutDownloader(int(sys.argv[2]), [])
downloader = StdoutDownloader(int(sys.argv[2]), [])
elif len(sys.argv) == 5:
downloader = LBRYStdoutDownloader(int(sys.argv[2]), [(sys.argv[3], int(sys.argv[4]))])
downloader = StdoutDownloader(int(sys.argv[2]), [(sys.argv[3], int(sys.argv[4]))])
else:
print "Usage: lbrynet-stdout-downloader <sd_hash> <peer_port> <dht_node_port>" \
" [<dht_bootstrap_host> <dht_bootstrap port>]"

View file

@ -84,7 +84,7 @@ def get_sd_info(stream_info_manager, stream_hash, include_blobs):
return d
class LBRYLiveStreamDescriptorValidator(object):
class LiveStreamDescriptorValidator(object):
implements(IStreamDescriptorValidator)
def __init__(self, raw_info):

View file

@ -12,7 +12,7 @@ from lbrynet.interfaces import IStreamDownloaderFactory
from lbrynet.lbrylive.StreamDescriptor import LiveStreamType
class LiveStreamDownloader(CryptStreamDownloader):
class _LiveStreamDownloader(CryptStreamDownloader):
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
payment_rate_manager, wallet, upload_allowed):
@ -39,10 +39,10 @@ class LiveStreamDownloader(CryptStreamDownloader):
return defer.succeed(True)
class LBRYLiveStreamDownloader(LiveStreamDownloader):
class LiveStreamDownloader(_LiveStreamDownloader):
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
payment_rate_manager, wallet, upload_allowed):
LiveStreamDownloader.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
_LiveStreamDownloader.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
stream_info_manager, payment_rate_manager, wallet, upload_allowed)
#self.writer = process.ProcessWriter(reactor, self, 'write', 1)
@ -65,17 +65,17 @@ class LBRYLiveStreamDownloader(LiveStreamDownloader):
return write_func
class FullLiveStreamDownloader(LiveStreamDownloader):
class FullLiveStreamDownloader(_LiveStreamDownloader):
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
payment_rate_manager, wallet, upload_allowed):
LiveStreamDownloader.__init__(self, stream_hash, peer_finder, rate_limiter,
_LiveStreamDownloader.__init__(self, stream_hash, peer_finder, rate_limiter,
blob_manager, stream_info_manager, payment_rate_manager,
wallet, upload_allowed)
self.file_handle = None
self.file_name = None
def set_stream_info(self):
d = LiveStreamDownloader.set_stream_info(self)
d = _LiveStreamDownloader.set_stream_info(self)
def set_file_name_if_unset():
if not self.file_name:
@ -88,7 +88,7 @@ class FullLiveStreamDownloader(LiveStreamDownloader):
def stop(self, err=None):
d = self._close_file()
d.addBoth(lambda _: LiveStreamDownloader.stop(self, err))
d.addBoth(lambda _: _LiveStreamDownloader.stop(self, err))
return d
def _start(self):
@ -96,7 +96,7 @@ class FullLiveStreamDownloader(LiveStreamDownloader):
d = self._open_file()
else:
d = defer.succeed(True)
d.addCallback(lambda _: LiveStreamDownloader._start(self))
d.addCallback(lambda _: _LiveStreamDownloader._start(self))
return d
def _open_file(self):

View file

@ -1,9 +1,9 @@
from lbrynet.lbrylive.StreamDescriptor import LiveStreamType, LBRYLiveStreamDescriptorValidator
from lbrynet.lbrylive.StreamDescriptor import LiveStreamType, LiveStreamDescriptorValidator
from lbrynet.core.DownloadOption import DownloadOption, DownloadOptionChoice
def add_live_stream_to_sd_identifier(sd_identifier, base_live_stream_payment_rate_manager):
sd_identifier.add_stream_type(LiveStreamType, LBRYLiveStreamDescriptorValidator,
sd_identifier.add_stream_type(LiveStreamType, LiveStreamDescriptorValidator,
LiveStreamOptions(base_live_stream_payment_rate_manager))

View file

@ -12,10 +12,10 @@ from yapsy.PluginManager import PluginManager
from twisted.internet import defer, threads, stdio, task, error
from jsonrpc.proxy import JSONRPCProxy
from lbrynet.core.Session import LBRYSession
from lbrynet.core.Session import Session
from lbrynet.lbrynet_console.ConsoleControl import ConsoleControl
from lbrynet.lbrynet_console.LBRYSettings import LBRYSettings
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
from lbrynet.lbrynet_console.Settings import Settings
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.core.utils import generate_id
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier
@ -24,33 +24,33 @@ from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerF
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
from lbrynet.core.PTCWallet import PTCWallet
from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileOpenerFactory
from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileOpenerFactory
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager, TempEncryptedFileMetadataManager
from lbrynet.lbrynet_console.ControlHandlers import ApplicationStatusFactory, GetWalletBalancesFactory, ShutDownFactory
from lbrynet.lbrynet_console.ControlHandlers import ImmediateAnnounceAllBlobsFactory
from lbrynet.lbrynet_console.ControlHandlers import LBRYFileStatusFactory, DeleteLBRYFileChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import ToggleLBRYFileRunningChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import EncryptedFileStatusFactory, DeleteEncryptedFileChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import ToggleEncryptedFileRunningChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import ModifyApplicationDefaultsFactory
from lbrynet.lbrynet_console.ControlHandlers import CreateLBRYFileFactory, PublishStreamDescriptorChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import CreateEncryptedFileFactory, PublishStreamDescriptorChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import ShowPublishedSDHashesChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import CreatePlainStreamDescriptorChooserFactory
from lbrynet.lbrynet_console.ControlHandlers import ShowLBRYFileStreamHashChooserFactory, AddStreamFromHashFactory
from lbrynet.lbrynet_console.ControlHandlers import ShowEncryptedFileStreamHashChooserFactory, AddStreamFromHashFactory
from lbrynet.lbrynet_console.ControlHandlers import AddStreamFromSDFactory, AddStreamFromLBRYcrdNameFactory
from lbrynet.lbrynet_console.ControlHandlers import ClaimNameFactory, GetNewWalletAddressFactory
from lbrynet.lbrynet_console.ControlHandlers import ShowServerStatusFactory, ModifyServerSettingsFactory
from lbrynet.lbrynet_console.ControlHandlers import ModifyLBRYFileOptionsChooserFactory, StatusFactory
from lbrynet.lbrynet_console.ControlHandlers import ModifyEncryptedFileOptionsChooserFactory, StatusFactory
from lbrynet.lbrynet_console.ControlHandlers import PeerStatsAndSettingsChooserFactory, PublishFactory
from lbrynet.lbrynet_console.ControlHandlers import BlockchainStatusFactory
from lbrynet.core.LBRYWallet import LBRYcrdWallet, LBRYumWallet
from lbrynet.core.Wallet import LBRYcrdWallet, LBRYumWallet
log = logging.getLogger(__name__)
alert = logging.getLogger("lbryalert." + __name__)
class LBRYConsole():
class Console():
"""A class which can upload and download file streams to and from the network"""
def __init__(self, peer_port, dht_node_port, known_dht_nodes, fake_wallet,
lbrycrd_conf, lbrycrd_dir, use_upnp, data_dir, created_data_dir,
@ -93,7 +93,7 @@ class LBRYConsole():
self.command_handlers = []
self.query_handlers = {}
self.settings = LBRYSettings(self.db_dir)
self.settings = Settings(self.db_dir)
self.blob_request_payment_rate_manager = None
self.lbryid = None
self.sd_identifier = StreamDescriptorIdentifier()
@ -239,7 +239,7 @@ class LBRYConsole():
alert.info("Databases loaded.")
self.session = LBRYSession(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,
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port,
use_upnp=self.use_upnp, wallet=results['wallet'])
@ -297,11 +297,11 @@ class LBRYConsole():
"catch up with our blockchain.\n", points_string)
def _setup_lbry_file_manager(self):
self.lbry_file_metadata_manager = DBLBRYFileMetadataManager(self.db_dir)
self.lbry_file_metadata_manager = DBEncryptedFileMetadataManager(self.db_dir)
d = self.lbry_file_metadata_manager.setup()
def set_lbry_file_manager():
self.lbry_file_manager = LBRYFileManager(self.session, self.lbry_file_metadata_manager, self.sd_identifier)
self.lbry_file_manager = EncryptedFileManager(self.session, self.lbry_file_metadata_manager, self.sd_identifier)
return self.lbry_file_manager.setup()
d.addCallback(lambda _: set_lbry_file_manager())
@ -309,11 +309,11 @@ class LBRYConsole():
return d
def _setup_lbry_file_opener(self):
stream_info_manager = TempLBRYFileMetadataManager()
downloader_factory = LBRYFileOpenerFactory(self.session.peer_finder, self.session.rate_limiter,
stream_info_manager = TempEncryptedFileMetadataManager()
downloader_factory = EncryptedFileOpenerFactory(self.session.peer_finder, self.session.rate_limiter,
self.session.blob_manager, stream_info_manager,
self.session.wallet)
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, downloader_factory)
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, downloader_factory)
return defer.succeed(True)
def _setup_control_handlers(self):
@ -323,20 +323,20 @@ class LBRYConsole():
ModifyApplicationDefaultsFactory(self),
ShutDownFactory(self),
PeerStatsAndSettingsChooserFactory(self.session.peer_manager),
LBRYFileStatusFactory(self.lbry_file_manager),
EncryptedFileStatusFactory(self.lbry_file_manager),
AddStreamFromSDFactory(self.sd_identifier, self.session.base_payment_rate_manager,
self.session.wallet),
DeleteLBRYFileChooserFactory(self.lbry_file_metadata_manager, self.session.blob_manager,
DeleteEncryptedFileChooserFactory(self.lbry_file_metadata_manager, self.session.blob_manager,
self.lbry_file_manager),
ToggleLBRYFileRunningChooserFactory(self.lbry_file_manager),
CreateLBRYFileFactory(self.session, self.lbry_file_manager),
ToggleEncryptedFileRunningChooserFactory(self.lbry_file_manager),
CreateEncryptedFileFactory(self.session, self.lbry_file_manager),
PublishStreamDescriptorChooserFactory(self.lbry_file_metadata_manager,
self.session.blob_manager),
ShowPublishedSDHashesChooserFactory(self.lbry_file_metadata_manager,
self.lbry_file_manager),
CreatePlainStreamDescriptorChooserFactory(self.lbry_file_manager),
ShowLBRYFileStreamHashChooserFactory(self.lbry_file_manager),
ModifyLBRYFileOptionsChooserFactory(self.lbry_file_manager),
ShowEncryptedFileStreamHashChooserFactory(self.lbry_file_manager),
ModifyEncryptedFileOptionsChooserFactory(self.lbry_file_manager),
AddStreamFromHashFactory(self.sd_identifier, self.session, self.session.wallet),
StatusFactory(self, self.session.rate_limiter, self.lbry_file_manager,
self.session.blob_manager, self.session.wallet if not self.fake_wallet else None),
@ -565,7 +565,7 @@ def launch_lbry_console():
logger.addHandler(file_handler)
console = LBRYConsole(peer_port, dht_node_port, bootstrap_nodes, fake_wallet=args.fake_wallet,
console = Console(peer_port, dht_node_port, bootstrap_nodes, fake_wallet=args.fake_wallet,
lbrycrd_conf=args.lbrycrd_wallet_conf, lbrycrd_dir=args.lbrycrd_wallet_dir,
use_upnp=not args.disable_upnp, data_dir=data_dir,
created_data_dir=created_data_dir, lbrycrdd_path=args.lbrycrdd_path)

View file

@ -2,8 +2,8 @@ import logging
from zope.interface import implements
from lbrynet.core.PaymentRateManager import PaymentRateManager
from lbrynet.lbryfilemanager.LBRYFileCreator import create_lbry_file
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloader
from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob, create_plain_sd
from lbrynet.lbrynet_console.interfaces import ICommandHandler, ICommandHandlerFactory
from lbrynet.core.StreamDescriptor import download_sd_blob
@ -418,7 +418,7 @@ class ShutDownFactory(CommandHandlerFactory):
full_help = "Shut down"
class LBRYFileStatus(CommandHandler):
class EncryptedFileStatus(CommandHandler):
#prompt_description = "Print status information for all LBRY Files"
def __init__(self, console, lbry_file_manager):
@ -446,8 +446,8 @@ class LBRYFileStatus(CommandHandler):
self.console.sendLine(''.join(status_strings))
class LBRYFileStatusFactory(CommandHandlerFactory):
control_handler_class = LBRYFileStatus
class EncryptedFileStatusFactory(CommandHandlerFactory):
control_handler_class = EncryptedFileStatus
command = "lbryfile-status"
short_help = "Print status information for LBRY files"
full_help = "Print the status information for all streams that are being saved to disk." \
@ -988,7 +988,7 @@ class AddStreamFromLBRYcrdNameFactory(CommandHandlerFactory):
"Usage: get <name>"
class LBRYFileChooser(RecursiveCommandHandler):
class EncryptedFileChooser(RecursiveCommandHandler):
def __init__(self, console, lbry_file_manager, factory_class, *args, **kwargs):
"""
@ -1014,23 +1014,23 @@ class LBRYFileChooser(RecursiveCommandHandler):
return control_handler_factories
class LBRYFileChooserFactory(CommandHandlerFactory):
class EncryptedFileChooserFactory(CommandHandlerFactory):
def get_prompt_description(self):
lbry_file = self.args[0]
return lbry_file.file_name
class DeleteLBRYFileChooser(LBRYFileChooser):
class DeleteEncryptedFileChooser(EncryptedFileChooser):
#prompt_description = "Delete LBRY File"
def __init__(self, console, stream_info_manager, blob_manager, lbry_file_manager):
LBRYFileChooser.__init__(self, console, lbry_file_manager, DeleteLBRYFileFactory,
EncryptedFileChooser.__init__(self, console, lbry_file_manager, DeleteEncryptedFileFactory,
stream_info_manager, blob_manager, lbry_file_manager,
exit_after_one_done=True)
class DeleteLBRYFileChooserFactory(CommandHandlerFactory):
control_handler_class = DeleteLBRYFileChooser
class DeleteEncryptedFileChooserFactory(CommandHandlerFactory):
control_handler_class = DeleteEncryptedFileChooser
command = "delete-lbryfile"
short_help = "Delete an LBRY file"
full_help = "Delete an LBRY file which has been downloaded or created by this application.\n" \
@ -1040,7 +1040,7 @@ class DeleteLBRYFileChooserFactory(CommandHandlerFactory):
"not be able to upload those chunks of data to other peers on LBRYnet."
class DeleteLBRYFile(CommandHandler):
class DeleteEncryptedFile(CommandHandler):
#prompt_description = "Delete LBRY File"
delete_data_prompt = "Also delete data? (y/n): "
confirm_prompt = "Are you sure? (y/n): "
@ -1106,27 +1106,27 @@ class DeleteLBRYFile(CommandHandler):
return d
class DeleteLBRYFileFactory(LBRYFileChooserFactory):
control_handler_class = DeleteLBRYFile
class DeleteEncryptedFileFactory(EncryptedFileChooserFactory):
control_handler_class = DeleteEncryptedFile
class ToggleLBRYFileRunningChooser(LBRYFileChooser):
class ToggleEncryptedFileRunningChooser(EncryptedFileChooser):
#prompt_description = "Toggle whether an LBRY File is running"
def __init__(self, console, lbry_file_manager):
LBRYFileChooser.__init__(self, console, lbry_file_manager, ToggleLBRYFileRunningFactory,
EncryptedFileChooser.__init__(self, console, lbry_file_manager, ToggleEncryptedFileRunningFactory,
lbry_file_manager, exit_after_one_done=True)
class ToggleLBRYFileRunningChooserFactory(CommandHandlerFactory):
control_handler_class = ToggleLBRYFileRunningChooser
class ToggleEncryptedFileRunningChooserFactory(CommandHandlerFactory):
control_handler_class = ToggleEncryptedFileRunningChooser
command = "toggle-running"
short_help = "Toggle whether an LBRY file is running"
full_help = "Toggle whether an LBRY file, which is being saved by this application," \
"is currently being downloaded."
class ToggleLBRYFileRunning(CommandHandler):
class ToggleEncryptedFileRunning(CommandHandler):
#prompt_description = "Toggle whether an LBRY File is running"
def __init__(self, console, lbry_file, lbry_file_manager):
@ -1151,11 +1151,11 @@ class ToggleLBRYFileRunning(CommandHandler):
return "An unexpected error occurred. See %s for details." % log_file
class ToggleLBRYFileRunningFactory(LBRYFileChooserFactory):
control_handler_class = ToggleLBRYFileRunning
class ToggleEncryptedFileRunningFactory(EncryptedFileChooserFactory):
control_handler_class = ToggleEncryptedFileRunning
class CreateLBRYFile(CommandHandler):
class CreateEncryptedFile(CommandHandler):
#prompt_description = "Create an LBRY File from file"
line_prompt = "File name: "
@ -1179,13 +1179,13 @@ class CreateLBRYFile(CommandHandler):
def set_status(self, lbry_file_downloader):
d = self.lbry_file_manager.change_lbry_file_status(lbry_file_downloader,
ManagedLBRYFileDownloader.STATUS_FINISHED)
ManagedEncryptedFileDownloader.STATUS_FINISHED)
d.addCallback(lambda _: lbry_file_downloader.restore())
return d
class CreateLBRYFileFactory(CommandHandlerFactory):
control_handler_class = CreateLBRYFile
class CreateEncryptedFileFactory(CommandHandlerFactory):
control_handler_class = CreateEncryptedFile
command = "create-lbryfile"
short_help = "LBRYize a file"
full_help = "Encrypt a file, split it into chunks, and make those chunks available on LBRYnet. Also " \
@ -1196,11 +1196,11 @@ class CreateLBRYFileFactory(CommandHandlerFactory):
"downloaded via the hash of the stream descriptor."
class PublishStreamDescriptorChooser(LBRYFileChooser):
class PublishStreamDescriptorChooser(EncryptedFileChooser):
#prompt_description = "Publish a stream descriptor file to the DHT for an LBRY File"
def __init__(self, console, stream_info_manager, blob_manager, lbry_file_manager):
LBRYFileChooser.__init__(self, console, lbry_file_manager, PublishStreamDescriptorFactory,
EncryptedFileChooser.__init__(self, console, lbry_file_manager, PublishStreamDescriptorFactory,
stream_info_manager, blob_manager, lbry_file_manager,
exit_after_one_done=True)
@ -1243,15 +1243,15 @@ class PublishStreamDescriptor(CommandHandler):
# return d
class PublishStreamDescriptorFactory(LBRYFileChooserFactory):
class PublishStreamDescriptorFactory(EncryptedFileChooserFactory):
control_handler_class = PublishStreamDescriptor
class ShowPublishedSDHashesChooser(LBRYFileChooser):
class ShowPublishedSDHashesChooser(EncryptedFileChooser):
#prompt_description = "Show published stream descriptors for an LBRY File"
def __init__(self, console, stream_info_manager, lbry_file_manager):
LBRYFileChooser.__init__(self, console, lbry_file_manager, ShowPublishedSDHashesFactory,
EncryptedFileChooser.__init__(self, console, lbry_file_manager, ShowPublishedSDHashesFactory,
stream_info_manager, lbry_file_manager)
@ -1288,15 +1288,15 @@ class ShowPublishedSDHashes(CommandHandler):
return d
class ShowPublishedSDHashesFactory(LBRYFileChooserFactory):
class ShowPublishedSDHashesFactory(EncryptedFileChooserFactory):
control_handler_class = ShowPublishedSDHashes
class CreatePlainStreamDescriptorChooser(LBRYFileChooser):
class CreatePlainStreamDescriptorChooser(EncryptedFileChooser):
#prompt_description = "Create a plain stream descriptor file for an LBRY File"
def __init__(self, console, lbry_file_manager):
LBRYFileChooser.__init__(self, console, lbry_file_manager,
EncryptedFileChooser.__init__(self, console, lbry_file_manager,
CreatePlainStreamDescriptorFactory, lbry_file_manager,
exit_after_one_done=True)
@ -1352,26 +1352,26 @@ class CreatePlainStreamDescriptor(CommandHandler):
return defer.succeed(file_name)
class CreatePlainStreamDescriptorFactory(LBRYFileChooserFactory):
class CreatePlainStreamDescriptorFactory(EncryptedFileChooserFactory):
control_handler_class = CreatePlainStreamDescriptor
class ShowLBRYFileStreamHashChooser(LBRYFileChooser):
class ShowEncryptedFileStreamHashChooser(EncryptedFileChooser):
#prompt_description = "Show an LBRY File's stream hash (not usually what you want)"
def __init__(self, console, lbry_file_manager):
LBRYFileChooser.__init__(self, console, lbry_file_manager, ShowLBRYFileStreamHashFactory)
EncryptedFileChooser.__init__(self, console, lbry_file_manager, ShowEncryptedFileStreamHashFactory)
class ShowLBRYFileStreamHashChooserFactory(CommandHandlerFactory):
control_handler_class = ShowLBRYFileStreamHashChooser
class ShowEncryptedFileStreamHashChooserFactory(CommandHandlerFactory):
control_handler_class = ShowEncryptedFileStreamHashChooser
command = "lbryfile-streamhash"
short_help = "Show an LBRY file's stream hash"
full_help = "Show the stream hash of an LBRY file, which is how the LBRY file is referenced internally" \
" by this application and therefore not usually what you want to see."
class ShowLBRYFileStreamHash(CommandHandler):
class ShowEncryptedFileStreamHash(CommandHandler):
#prompt_description = "Show an LBRY File's stream hash (not usually what you want)"
def __init__(self, console, lbry_file):
@ -1383,11 +1383,11 @@ class ShowLBRYFileStreamHash(CommandHandler):
self.finished_deferred.callback(None)
class ShowLBRYFileStreamHashFactory(LBRYFileChooserFactory):
control_handler_class = ShowLBRYFileStreamHash
class ShowEncryptedFileStreamHashFactory(EncryptedFileChooserFactory):
control_handler_class = ShowEncryptedFileStreamHash
class ModifyLBRYFileDataPaymentRate(ModifyPaymentRate):
class ModifyEncryptedFileDataPaymentRate(ModifyPaymentRate):
prompt_description = "Modify LBRY File data payment rate"
def __init__(self, console, lbry_file, lbry_file_manager):
@ -1415,19 +1415,19 @@ class ModifyLBRYFileDataPaymentRate(ModifyPaymentRate):
return status
class ModifyLBRYFileDataPaymentRateFactory(CommandHandlerFactory):
control_handler_class = ModifyLBRYFileDataPaymentRate
class ModifyEncryptedFileDataPaymentRateFactory(CommandHandlerFactory):
control_handler_class = ModifyEncryptedFileDataPaymentRate
class ModifyLBRYFileOptionsChooser(LBRYFileChooser):
class ModifyEncryptedFileOptionsChooser(EncryptedFileChooser):
#prompt_description = "Modify an LBRY File's options"
def __init__(self, console, lbry_file_manager):
LBRYFileChooser.__init__(self, console, lbry_file_manager, ModifyLBRYFileOptionsFactory, lbry_file_manager)
EncryptedFileChooser.__init__(self, console, lbry_file_manager, ModifyEncryptedFileOptionsFactory, lbry_file_manager)
class ModifyLBRYFileOptionsChooserFactory(CommandHandlerFactory):
control_handler_class = ModifyLBRYFileOptionsChooser
class ModifyEncryptedFileOptionsChooserFactory(CommandHandlerFactory):
control_handler_class = ModifyEncryptedFileOptionsChooser
command = "modify-lbryfile-options"
short_help = "Modify an LBRY file's options"
full_help = "Modify an LBRY file's options. Options include, and are limited to, " \
@ -1435,7 +1435,7 @@ class ModifyLBRYFileOptionsChooserFactory(CommandHandlerFactory):
"this LBRY file."
class ModifyLBRYFileOptions(RecursiveCommandHandler):
class ModifyEncryptedFileOptions(RecursiveCommandHandler):
#prompt_description = "Modify an LBRY File's options"
def __init__(self, console, lbry_file, lbry_file_manager):
@ -1445,12 +1445,12 @@ class ModifyLBRYFileOptions(RecursiveCommandHandler):
def _get_control_handler_factories(self):
factories = []
factories.append(ModifyLBRYFileDataPaymentRateFactory(self.lbry_file, self.lbry_file_manager))
factories.append(ModifyEncryptedFileDataPaymentRateFactory(self.lbry_file, self.lbry_file_manager))
return factories
class ModifyLBRYFileOptionsFactory(LBRYFileChooserFactory):
control_handler_class = ModifyLBRYFileOptions
class ModifyEncryptedFileOptionsFactory(EncryptedFileChooserFactory):
control_handler_class = ModifyEncryptedFileOptions
class ClaimName(CommandHandler):
@ -1821,7 +1821,7 @@ class Publish(CommandHandler):
def set_status(self, lbry_file_downloader):
self.lbry_file = lbry_file_downloader
d = self.lbry_file_manager.change_lbry_file_status(self.lbry_file,
ManagedLBRYFileDownloader.STATUS_FINISHED)
ManagedEncryptedFileDownloader.STATUS_FINISHED)
d.addCallback(lambda _: lbry_file_downloader.restore())
return d
@ -2354,7 +2354,7 @@ class PeerStatsAndSettingsChooserFactory(CommandHandlerFactory):
"which peers to connect to."
class LBRYFileStatusModifier(CommandHandler):
class EncryptedFileStatusModifier(CommandHandler):
def __init__(self, console, lbry_file, stream_info_manager, blob_manager, lbry_file_manager):
CommandHandler.__init__(self, console)
self.lbry_file = lbry_file
@ -2371,11 +2371,11 @@ class LBRYFileStatusModifier(CommandHandler):
if self.current_handler is None:
if line:
if line.lower() == 'd':
self.current_handler = DeleteLBRYFile(self.console, self.lbry_file,
self.current_handler = DeleteEncryptedFile(self.console, self.lbry_file,
self.stream_info_manager, self.blob_manager,
self.lbry_file_manager)
elif line.lower() == 't':
self.current_handler = ToggleLBRYFileRunning(self.console, self.lbry_file,
self.current_handler = ToggleEncryptedFileRunning(self.console, self.lbry_file,
self.lbry_file_manager)
else:
self.console.sendLine("Invalid selection\n")
@ -2444,7 +2444,7 @@ class Status(CommandHandler):
self.console.sendLine("Invalid choice.\n")
self.finished_deferred.callback(None)
return
self.current_handler = LBRYFileStatusModifier(self.console, self.lbry_files[index],
self.current_handler = EncryptedFileStatusModifier(self.console, self.lbry_files[index],
self.lbry_file_manager.stream_info_manager,
self.blob_manager, self.lbry_file_manager)
try:

View file

@ -1,7 +1,7 @@
from yapsy.IPlugin import IPlugin
class LBRYPlugin(IPlugin):
class Plugin(IPlugin):
def __init__(self):
IPlugin.__init__(self)

View file

@ -18,7 +18,7 @@ def run_in_thread(fn):
return wrapped
class LBRYSettings(object):
class Settings(object):
NAME = "settings.db"
def __init__(self, db_dir):
self.db_dir = db_dir

View file

@ -1,4 +1,4 @@
from lbrynet.lbrynet_console import LBRYPlugin
from lbrynet.lbrynet_console import Plugin
from twisted.internet import defer
from lbrynet.conf import MIN_VALUABLE_BLOB_HASH_PAYMENT_RATE, MIN_VALUABLE_BLOB_INFO_PAYMENT_RATE
from BlindRepeater import BlindRepeater
@ -13,10 +13,10 @@ from ValuableBlobQueryHandler import ValuableBlobHashQueryHandlerFactory
from PaymentRateManager import BlindRepeaterPaymentRateManager
class BlindRepeaterPlugin(LBRYPlugin.LBRYPlugin):
class BlindRepeaterPlugin(Plugin.Plugin):
def __init__(self):
LBRYPlugin.LBRYPlugin.__init__(self)
Plugin.Plugin.__init__(self)
self.enabled = False
self.blind_info_manager = None
self.valuable_blob_length_query_handler = None

View file

@ -22,7 +22,6 @@ from twisted.internet import defer, threads, error, reactor, task
from twisted.internet.task import LoopingCall
from txjsonrpc import jsonrpclib
from txjsonrpc.web import jsonrpc
from txjsonrpc.web.jsonrpc import Handler
from lbrynet import __version__ as lbrynet_version
from lbryum.version import LBRYUM_VERSION as lbryum_version
@ -32,33 +31,33 @@ from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerF
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
from lbrynet.core.Error import UnknownNameError, InsufficientFundsError, InvalidNameError
from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaverFactory, LBRYFileOpenerFactory
from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbrynet_daemon.LBRYUIManager import LBRYUIManager
from lbrynet.lbrynet_daemon.LBRYDownloader import GetStream
from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher
from lbrynet.lbrynet_daemon.LBRYExchangeRateManager import ExchangeRateManager
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaverFactory, EncryptedFileOpenerFactory
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbrynet_daemon.UIManager import UIManager
from lbrynet.lbrynet_daemon.Downloader import GetStream
from lbrynet.lbrynet_daemon.Publisher import Publisher
from lbrynet.lbrynet_daemon.ExchangeRateManager import ExchangeRateManager
from lbrynet.lbrynet_daemon.Lighthouse import LighthouseClient
from lbrynet.lbrynet_daemon.auth.server import AuthJSONRPCServer
from lbrynet.lbrynet_daemon.auth.util import get_auth_message
from lbrynet.metadata.LBRYMetadata import Metadata, verify_name_characters
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.LBRYSettings import LBRYSettings
from lbrynet.lbrynet_console.Settings import Settings
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, DEFAULT_MAX_SEARCH_RESULTS, \
KNOWN_DHT_NODES, DEFAULT_MAX_KEY_FEE, DEFAULT_WALLET, \
DEFAULT_SEARCH_TIMEOUT, DEFAULT_CACHE_TIME, DEFAULT_UI_BRANCH, \
LOG_POST_URL, LOG_FILE_NAME, REFLECTOR_SERVERS, SEARCH_SERVERS
LOG_POST_URL, LOG_FILE_NAME, REFLECTOR_SERVERS
from lbrynet.conf import DEFAULT_SD_DOWNLOAD_TIMEOUT
from lbrynet.conf import DEFAULT_TIMEOUT
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader
from lbrynet.core.Session import LBRYSession
from lbrynet.core.Session import Session
from lbrynet.core.PTCWallet import PTCWallet
from lbrynet.core.LBRYWallet import LBRYcrdWallet, LBRYumWallet
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
from lbrynet.core.Wallet import LBRYcrdWallet, LBRYumWallet
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager, TempEncryptedFileMetadataManager
from lbrynet import reflector
@ -77,9 +76,9 @@ log = logging.getLogger(__name__)
if os.path.isfile(lbrynet_log):
with open(lbrynet_log, 'r') as f:
PREVIOUS_LBRYNET_LOG = len(f.read())
PREVIOUS_NET_LOG = len(f.read())
else:
PREVIOUS_LBRYNET_LOG = 0
PREVIOUS_NET_LOG = 0
INITIALIZING_CODE = 'initializing'
LOADING_DB_CODE = 'loading_db'
@ -133,7 +132,7 @@ class Parameters(object):
self.__dict__.update(kwargs)
class LBRYDaemon(AuthJSONRPCServer):
class Daemon(AuthJSONRPCServer):
"""
LBRYnet daemon, a jsonrpc interface to lbry functions
"""
@ -376,9 +375,9 @@ class LBRYDaemon(AuthJSONRPCServer):
# self.lbrynet_connection_checker = LoopingCall(self._check_lbrynet_connection)
self.sd_identifier = StreamDescriptorIdentifier()
self.stream_info_manager = TempLBRYFileMetadataManager()
self.settings = LBRYSettings(self.db_dir)
self.lbry_ui_manager = LBRYUIManager(root)
self.stream_info_manager = TempEncryptedFileMetadataManager()
self.settings = Settings(self.db_dir)
self.lbry_ui_manager = UIManager(root)
self.blob_request_payment_rate_manager = None
self.lbry_file_metadata_manager = None
self.lbry_file_manager = None
@ -476,10 +475,13 @@ class LBRYDaemon(AuthJSONRPCServer):
self.send_heartbeat.start(60)
def _send_heartbeat(self):
log.debug('Sending heartbeat')
heartbeat = self._events.heartbeat()
self.analytics_api.track(heartbeat)
def _send_download_started(self, name, stream_info=None):
event = self._events.download_started(name, stream_info)
self.analytics_api.track(event)
def _get_platform(self):
r = {
"processor": platform.processor(),
@ -603,7 +605,7 @@ class LBRYDaemon(AuthJSONRPCServer):
self._add_to_pending_claims(name, txid)
def _process_lbry_file(name, lbry_file):
# lbry_file is an instance of ManagedLBRYFileDownloader or None
# lbry_file is an instance of ManagedEncryptedFileDownloader or None
# TODO: check for sd_hash in addition to txid
ready_to_start = (
lbry_file and
@ -727,11 +729,11 @@ class LBRYDaemon(AuthJSONRPCServer):
def _upload_log(self, log_type=None, exclude_previous=False, force=False):
if self.upload_log or force:
for lm, lp in [('lbrynet', lbrynet_log)]: #, ('lbryum', lbryum_log)]:
for lm, lp in [('lbrynet', lbrynet_log)]:
if os.path.isfile(lp):
if exclude_previous:
f = open(lp, "r")
f.seek(PREVIOUS_LBRYNET_LOG) # if lm == 'lbrynet' else PREVIOUS_LBRYUM_LOG)
f.seek(PREVIOUS_NET_LOG)
log_contents = f.read()
f.close()
else:
@ -937,11 +939,11 @@ class LBRYDaemon(AuthJSONRPCServer):
def _setup_lbry_file_manager(self):
self.startup_status = STARTUP_STAGES[3]
self.lbry_file_metadata_manager = DBLBRYFileMetadataManager(self.db_dir)
self.lbry_file_metadata_manager = DBEncryptedFileMetadataManager(self.db_dir)
d = self.lbry_file_metadata_manager.setup()
def set_lbry_file_manager():
self.lbry_file_manager = LBRYFileManager(self.session,
self.lbry_file_manager = EncryptedFileManager(self.session,
self.lbry_file_metadata_manager,
self.sd_identifier,
download_directory=self.download_directory)
@ -988,7 +990,7 @@ class LBRYDaemon(AuthJSONRPCServer):
return r
def create_session(results):
self.session = LBRYSession(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,
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port,
use_upnp=self.use_upnp, wallet=results['wallet'])
@ -1002,22 +1004,22 @@ class LBRYDaemon(AuthJSONRPCServer):
return dl
def _setup_stream_identifier(self):
file_saver_factory = LBRYFileSaverFactory(self.session.peer_finder, self.session.rate_limiter,
file_saver_factory = EncryptedFileSaverFactory(self.session.peer_finder, self.session.rate_limiter,
self.session.blob_manager, self.stream_info_manager,
self.session.wallet, self.download_directory)
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, file_saver_factory)
file_opener_factory = LBRYFileOpenerFactory(self.session.peer_finder, self.session.rate_limiter,
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, file_saver_factory)
file_opener_factory = EncryptedFileOpenerFactory(self.session.peer_finder, self.session.rate_limiter,
self.session.blob_manager, self.stream_info_manager,
self.session.wallet)
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, file_opener_factory)
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, file_opener_factory)
return defer.succeed(None)
def _setup_lbry_file_opener(self):
downloader_factory = LBRYFileOpenerFactory(self.session.peer_finder, self.session.rate_limiter,
downloader_factory = EncryptedFileOpenerFactory(self.session.peer_finder, self.session.rate_limiter,
self.session.blob_manager, self.stream_info_manager,
self.session.wallet)
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, downloader_factory)
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, downloader_factory)
return defer.succeed(True)
def _download_sd_blob(self, sd_hash, timeout=DEFAULT_SD_DOWNLOAD_TIMEOUT):
@ -1044,6 +1046,7 @@ class LBRYDaemon(AuthJSONRPCServer):
Add a lbry file to the file manager, start the download, and return the new lbry file.
If it already exists in the file manager, return the existing lbry file
"""
self._send_download_started(name)
helper = _DownloadNameHelper(
self, name, timeout, download_directory, file_name, wait_for_write)
@ -1090,7 +1093,7 @@ class LBRYDaemon(AuthJSONRPCServer):
force_refresh: if True, always go out to the blockchain to resolve.
"""
if name.startswith('lbry://'):
raise ValueError('name %s should not start with lbry://')
raise ValueError('name {} should not start with lbry://'.format(name))
helper = _ResolveNameHelper(self, name, force_refresh)
return helper.get_deferred()
@ -1664,6 +1667,21 @@ class LBRYDaemon(AuthJSONRPCServer):
d.addCallbacks(lambda info: self._render_response(info, OK_CODE), lambda _: server.failure)
return d
def jsonrpc_get_my_claim(self, p):
"""
Return existing claim for a given name
Args:
'name': name to look up
Returns:
claim info, False if no such claim exists
"""
name = p['name']
d = self.session.wallet.get_my_claim(name)
d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d
def jsonrpc_get_claim_info(self, p):
"""
Resolve claim info from a LBRY uri
@ -2562,16 +2580,14 @@ class _DownloadNameHelper(object):
def _setup_stream(self, stream_info):
stream_hash = get_sd_hash(stream_info)
d = self.daemon._get_lbry_file_by_sd_hash(stream_hash)
d.addCallback(self._add_results_callback(stream_info))
d.addCallback(self._prepend_stream_info, stream_info)
return d
def _add_results_callback(self, stream_info):
def add_results(l):
if l:
if os.path.isfile(os.path.join(self.download_directory, l.file_name)):
return defer.succeed((stream_info, l))
def _prepend_stream_info(self, lbry_file, stream_info):
if lbry_file:
if os.path.isfile(os.path.join(self.download_directory, lbry_file.file_name)):
return defer.succeed((stream_info, lbry_file))
return defer.succeed((stream_info, None))
return add_results
def wait_or_get_stream(self, args):
stream_info, lbry_file = args

View file

@ -1,11 +1,9 @@
import argparse
import logging
import logging.handlers
import os
import webbrowser
import sys
import socket
from appdirs import user_data_dir
from twisted.web import server, guard
from twisted.internet import defer, reactor
@ -14,9 +12,9 @@ from twisted.cred import portal
from jsonrpc.proxy import JSONRPCProxy
from lbrynet.core import log_support
from lbrynet.lbrynet_daemon.LBRYDaemonServer import LBRYDaemonServer, LBRYDaemonRequest
from lbrynet.lbrynet_daemon.auth.auth import PasswordChecker, HttpPasswordRealm
from lbrynet.lbrynet_daemon.auth.util import initialize_api_key_file
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer, DaemonRequest
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_PORT, \
UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
from lbrynet.conf import DATA_DIR as log_dir
@ -72,6 +70,8 @@ def start():
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')
parser.set_defaults(branch=False, launchui=True, logtoconsole=False, quiet=False)
args = parser.parse_args()
@ -80,6 +80,7 @@ def start():
if args.logtoconsole:
log_support.configure_console(level='DEBUG')
log_support.disable_third_party_loggers()
if not args.verbose:
log_support.disable_noisy_loggers()
try:
@ -103,7 +104,7 @@ def start():
print "To quit press ctrl-c or call 'stop' via the API"
if test_internet_connection():
lbry = LBRYDaemonServer()
lbry = DaemonServer()
d = lbry.start(branch=args.branch if args.branch else DEFAULT_UI_BRANCH,
user_specified=args.ui,
@ -120,8 +121,7 @@ def start():
factory = guard.BasicCredentialFactory('Login to lbrynet api')
protected_resource = guard.HTTPAuthSessionWrapper(portal_to_realm, [factory, ])
lbrynet_server = server.Site(protected_resource)
lbrynet_server.requestFactory = LBRYDaemonRequest
lbrynet_server.requestFactory = DaemonRequest
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
reactor.run()

View file

@ -11,15 +11,16 @@ import cgi
from appdirs import user_data_dir
from twisted.web import server, static, resource
from twisted.internet import defer, interfaces, error, reactor, threads
from twisted.internet import abstract, defer, interfaces, error, reactor, task
from zope.interface import implements
from zope.interface import implementer
from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon
from lbrynet.lbrynet_daemon.Daemon import Daemon
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet.conf import API_ADDRESS, UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
# TODO: omg, this code is essentially duplicated in LBRYDaemon
# TODO: omg, this code is essentially duplicated in Daemon
if sys.platform != "darwin":
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
else:
@ -31,7 +32,7 @@ lbrynet_log = os.path.join(data_dir, LOG_FILE_NAME)
log = logging.getLogger(__name__)
class LBRYDaemonRequest(server.Request):
class DaemonRequest(server.Request):
"""
For LBRY specific request functionality. Currently just provides
handling for large multipart POST requests, taken from here:
@ -231,123 +232,112 @@ class LBRYindex(resource.Resource):
return static.File(os.path.join(self.ui_dir, "index.html")).render_GET(request)
class LBRYFileStreamer(object):
@implementer(interfaces.IPushProducer)
class EncryptedFileStreamer(object):
"""
Writes downloaded LBRY file to request as the download comes in, pausing and resuming as requested
used for Chrome
Writes LBRY stream to request; will pause to wait for new data if the file
is downloading.
No support for range requests (some browser players can't handle it when
the full video data isn't available on request).
"""
implements(interfaces.IPushProducer)
bufferSize = abstract.FileDescriptor.bufferSize
# How long to wait between sending blocks (needed because some
# video players freeze up if you try to send data too fast)
stream_interval = 0.005
# How long to wait before checking if new data has been appended to the file
new_data_check_interval = 0.25
def __init__(self, request, path, stream, file_manager):
def _set_content_length_header(length):
self._request.setHeader('content-length', length)
return defer.succeed(None)
def __init__(self, request, path, start, stop, size):
self._request = request
self._fileObject = file(path)
self._content_type = mimetypes.guess_type(path)[0]
self._stop_pos = size - 1 if stop == '' else int(stop) #chrome and firefox send range requests for "0-"
self._cursor = self._start_pos = int(start)
self._file_size = size
self._depth = 0
self._file = open(path, 'rb')
self._stream = stream
self._file_manager = file_manager
self._headers_sent = False
self._paused = self._sent_bytes = self._stopped = False
self._delay = 0.25
self._deferred = defer.succeed(None)
self._running = True
self._request.setResponseCode(206)
self._request.setHeader('accept-ranges', 'bytes')
self._request.setHeader('content-type', self._content_type)
self._request.setResponseCode(200)
self._request.setHeader('accept-ranges', 'none')
self._request.setHeader('content-type', mimetypes.guess_type(path)[0])
self._request.setHeader("Content-Security-Policy", "sandbox")
self.resumeProducing()
self._deferred = stream.get_total_bytes()
self._deferred.addCallback(_set_content_length_header)
self._deferred.addCallback(lambda _: self.resumeProducing())
def _check_for_new_data(self):
def _recurse_or_stop(stream_status):
if not self._running:
return
if stream_status != ManagedEncryptedFileDownloader.STATUS_FINISHED:
self._deferred.addCallback(lambda _: task.deferLater(reactor, self.new_data_check_interval, self._check_for_new_data))
else:
self.stopProducing()
if not self._running:
return
# Clear the file's EOF indicator by seeking to current position
self._file.seek(self._file.tell())
data = self._file.read(self.bufferSize)
if data:
self._request.write(data)
if self._running: # .write() can trigger a pause
self._deferred.addCallback(lambda _: task.deferLater(reactor, self.stream_interval, self._check_for_new_data))
else:
self._deferred.addCallback(lambda _: self._file_manager.get_lbry_file_status(self._stream))
self._deferred.addCallback(_recurse_or_stop)
def pauseProducing(self):
self._paused = True
log.info("Pausing producer")
return defer.succeed(None)
self._running = False
def resumeProducing(self):
def _check_for_new_data():
self._depth += 1
self._fileObject.seek(self._start_pos, os.SEEK_END)
readable_bytes = self._fileObject.tell()
self._fileObject.seek(self._cursor)
self._sent_bytes = False
if (readable_bytes > self._cursor) and not (self._stopped or self._paused):
read_length = min(readable_bytes, self._stop_pos) - self._cursor + 1
self._request.setHeader('content-range', 'bytes %s-%s/%s' % (self._cursor, self._cursor + read_length - 1, self._file_size))
self._request.setHeader('content-length', str(read_length))
start_cur = self._cursor
for i in range(read_length):
if self._paused or self._stopped:
break
else:
data = self._fileObject.read(1)
self._request.write(data)
self._cursor += 1
log.info("Wrote range %s-%s/%s, length: %s, readable: %s, depth: %s" %
(start_cur, self._cursor, self._file_size, self._cursor - start_cur, readable_bytes, self._depth))
self._sent_bytes = True
if self._cursor == self._stop_pos + 1:
self.stopProducing()
return defer.succeed(None)
elif self._paused or self._stopped:
return defer.succeed(None)
else:
self._deferred.addCallback(lambda _: threads.deferToThread(reactor.callLater, self._delay, _check_for_new_data))
return defer.succeed(None)
log.info("Resuming producer")
self._paused = False
self._deferred.addCallback(lambda _: _check_for_new_data())
self._running = True
self._check_for_new_data()
def stopProducing(self):
log.info("Stopping producer")
self._stopped = True
# self._fileObject.close()
self._running = False
self._file.close()
self._deferred.addErrback(lambda err: err.trap(defer.CancelledError))
self._deferred.addErrback(lambda err: err.trap(error.ConnectionDone))
self._deferred.cancel()
# self._request.finish()
self._request.unregisterProducer()
return defer.succeed(None)
self._request.finish()
class HostedLBRYFile(resource.Resource):
class HostedEncryptedFile(resource.Resource):
def __init__(self, api):
self._api = api
self._producer = None
resource.Resource.__init__(self)
# todo: fix LBRYFileStreamer and use it instead of static.File
# def makeProducer(self, request, stream):
# def _save_producer(producer):
# self._producer = producer
# return defer.succeed(None)
#
# range_header = request.getAllHeaders()['range'].replace('bytes=', '').split('-')
# start, stop = int(range_header[0]), range_header[1]
# log.info("GET range %s-%s" % (start, stop))
# path = os.path.join(self._api.download_directory, stream.file_name)
#
# d = stream.get_total_bytes()
# d.addCallback(lambda size: _save_producer(LBRYFileStreamer(request, path, start, stop, size)))
# d.addCallback(lambda _: request.registerProducer(self._producer, streaming=True))
# # request.notifyFinish().addCallback(lambda _: self._producer.stopProducing())
# request.notifyFinish().addErrback(self._responseFailed, d)
# return d
def _make_stream_producer(self, request, stream):
path = os.path.join(self._api.download_directory, stream.file_name)
producer = EncryptedFileStreamer(request, path, stream, self._api.lbry_file_manager)
request.registerProducer(producer, streaming=True)
d = request.notifyFinish()
d.addErrback(self._responseFailed, d)
return d
def render_GET(self, request):
request.setHeader("Content-Security-Policy", "sandbox")
if 'name' in request.args.keys():
if request.args['name'][0] != 'lbry' and request.args['name'][0] not in self._api.waiting_on.keys():
d = self._api._download_name(request.args['name'][0])
# d.addCallback(lambda stream: self.makeProducer(request, stream))
d.addCallback(lambda stream: static.File(os.path.join(self._api.download_directory,
stream.file_name)).render_GET(request))
d.addCallback(lambda stream: self._make_stream_producer(request, stream))
elif request.args['name'][0] in self._api.waiting_on.keys():
request.redirect(UI_ADDRESS + "/?watch=" + request.args['name'][0])
request.finish()
@ -356,13 +346,13 @@ class HostedLBRYFile(resource.Resource):
request.finish()
return server.NOT_DONE_YET
# def _responseFailed(self, err, call):
# call.addErrback(lambda err: err.trap(error.ConnectionDone))
# call.addErrback(lambda err: err.trap(defer.CancelledError))
# call.addErrback(lambda err: log.info("Error: " + str(err)))
# call.cancel()
def _responseFailed(self, err, call):
call.addErrback(lambda err: err.trap(error.ConnectionDone))
call.addErrback(lambda err: err.trap(defer.CancelledError))
call.addErrback(lambda err: log.info("Error: " + str(err)))
call.cancel()
class LBRYFileUpload(resource.Resource):
class EncryptedFileUpload(resource.Resource):
"""
Accepts a file sent via the file upload widget in the web UI, saves
it into a temporary dir, and responds with a JSON string containing
@ -401,12 +391,12 @@ class LBRYFileUpload(resource.Resource):
return json.dumps(newpath)
class LBRYDaemonServer(object):
class DaemonServer(object):
def _setup_server(self, wallet):
self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active"))
self._api = LBRYDaemon(self.root, wallet_type=wallet)
self.root.putChild("view", HostedLBRYFile(self._api))
self.root.putChild("upload", LBRYFileUpload(self._api))
self._api = Daemon(self.root, wallet_type=wallet)
self.root.putChild("view", HostedEncryptedFile(self._api))
self.root.putChild("upload", EncryptedFileUpload(self._api))
self.root.putChild(API_ADDRESS, self._api)
return defer.succeed(True)

View file

@ -11,8 +11,8 @@ from twisted.internet.task import LoopingCall
from lbrynet.core.Error import InsufficientFundsError, KeyFeeAboveMaxAllowed
from lbrynet.core.PaymentRateManager import PaymentRateManager
from lbrynet.core.StreamDescriptor import download_sd_blob
from lbrynet.metadata.LBRYFee import LBRYFeeValidator
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloaderFactory
from lbrynet.metadata.Fee import FeeValidator
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory
from lbrynet.conf import DEFAULT_TIMEOUT, LOG_FILE_NAME
INITIALIZING_CODE = 'initializing'
@ -86,7 +86,7 @@ class GetStream(object):
def _convert_max_fee(self):
if isinstance(self.max_key_fee, dict):
max_fee = LBRYFeeValidator(self.max_key_fee)
max_fee = FeeValidator(self.max_key_fee)
if max_fee.currency_symbol == "LBC":
return max_fee.amount
return self.exchange_rate_manager.to_lbc(self.fee).amount
@ -105,7 +105,7 @@ class GetStream(object):
def get_downloader_factory(metadata):
for factory in metadata.factories:
if isinstance(factory, ManagedLBRYFileDownloaderFactory):
if isinstance(factory, ManagedEncryptedFileDownloaderFactory):
return factory, metadata
raise Exception('No suitable factory was found in {}'.format(metadata.factories))
@ -123,7 +123,7 @@ class GetStream(object):
self.stream_hash = self.stream_info['sources']['lbry_sd_hash']
if 'fee' in self.stream_info:
self.fee = LBRYFeeValidator(self.stream_info['fee'])
self.fee = FeeValidator(self.stream_info['fee'])
max_key_fee = self._convert_max_fee()
if self.exchange_rate_manager.to_lbc(self.fee).amount > max_key_fee:
log.info("Key fee %f above limit of %f didn't download lbry://%s" % (self.fee.amount,

View file

@ -6,7 +6,7 @@ import googlefinance
from twisted.internet import defer, reactor
from twisted.internet.task import LoopingCall
from lbrynet.metadata.LBRYFee import LBRYFeeValidator
from lbrynet.metadata.Fee import FeeValidator
log = logging.getLogger(__name__)
@ -151,12 +151,12 @@ class ExchangeRateManager(object):
def to_lbc(self, fee):
if fee is None:
return None
if not isinstance(fee, LBRYFeeValidator):
fee_in = LBRYFeeValidator(fee)
if not isinstance(fee, FeeValidator):
fee_in = FeeValidator(fee)
else:
fee_in = fee
return LBRYFeeValidator({fee_in.currency_symbol:
return FeeValidator({fee_in.currency_symbol:
{
'amount': self.convert_currency(fee_in.currency_symbol, "LBC", fee_in.amount),
'address': fee_in.address
@ -206,12 +206,12 @@ class DummyExchangeRateManager(object):
def to_lbc(self, fee):
if fee is None:
return None
if not isinstance(fee, LBRYFeeValidator):
fee_in = LBRYFeeValidator(fee)
if not isinstance(fee, FeeValidator):
fee_in = FeeValidator(fee)
else:
fee_in = fee
return LBRYFeeValidator({fee_in.currency_symbol:
return FeeValidator({fee_in.currency_symbol:
{
'amount': self.convert_currency(fee_in.currency_symbol, "LBC", fee_in.amount),
'address': fee_in.address

View file

@ -7,11 +7,11 @@ import random
from appdirs import user_data_dir
from lbrynet.core.Error import InsufficientFundsError
from lbrynet.lbryfilemanager.LBRYFileCreator import create_lbry_file
from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
from lbrynet.core.PaymentRateManager import PaymentRateManager
from lbrynet.metadata.LBRYMetadata import Metadata
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloader
from lbrynet.metadata.Metadata import Metadata
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
from lbrynet import reflector
from lbrynet.conf import LOG_FILE_NAME, REFLECTOR_SERVERS
from twisted.internet import threads, defer, reactor
@ -124,7 +124,7 @@ class Publisher(object):
def set_status(self):
log.debug('Setting status')
d = self.lbry_file_manager.change_lbry_file_status(self.lbry_file, ManagedLBRYFileDownloader.STATUS_FINISHED)
d = self.lbry_file_manager.change_lbry_file_status(self.lbry_file, ManagedEncryptedFileDownloader.STATUS_FINISHED)
d.addCallback(lambda _: self.lbry_file.restore())
return d

View file

@ -27,7 +27,7 @@ lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME)
log = logging.getLogger(__name__)
class LBRYUIManager(object):
class UIManager(object):
def __init__(self, root):
if sys.platform != "darwin":
self.data_dir = os.path.join(os.path.expanduser("~"), '.lbrynet')

View file

@ -80,7 +80,7 @@ class USDFeeValidator(Validator):
Validator.__init__(self, fee)
class LBRYFeeValidator(Validator):
class FeeValidator(Validator):
CV001 = "0.0.1"
CURRENT_CURRENCY_VERSION = CV001

View file

@ -1,7 +1,7 @@
import logging
from lbrynet.metadata.Validator import Validator, skip_validate
from lbrynet.metadata.LBRYFee import LBRYFeeValidator, verify_supported_currency
from lbrynet.metadata.Fee import FeeValidator, verify_supported_currency
from lbrynet.conf import SOURCE_TYPES
log = logging.getLogger(__name__)
@ -83,4 +83,4 @@ class Metadata(Validator):
def _load_fee(self):
if 'fee' in self:
self.update({'fee': LBRYFeeValidator(self['fee'])})
self.update({'fee': FeeValidator(self['fee'])})

View file

@ -1,3 +1,3 @@
from lbrynet.reflector.server.server import ReflectorServerFactory as ServerFactory
from lbrynet.reflector.client.client import LBRYFileReflectorClientFactory as ClientFactory
from lbrynet.reflector.client.client import LBRYBlobReflectorClientFactory as BlobClientFactory
from lbrynet.reflector.client.client import EncryptedFileReflectorClientFactory as ClientFactory
from lbrynet.reflector.client.client import BlobReflectorClientFactory as BlobClientFactory

View file

@ -61,7 +61,7 @@ class IncompleteResponseError(Exception):
pass
class LBRYFileReflectorClient(Protocol):
class EncryptedFileReflectorClient(Protocol):
# Protocol stuff
@ -238,8 +238,8 @@ class LBRYFileReflectorClient(Protocol):
self.transport.loseConnection()
class LBRYFileReflectorClientFactory(ClientFactory):
protocol = LBRYFileReflectorClient
class EncryptedFileReflectorClientFactory(ClientFactory):
protocol = EncryptedFileReflectorClient
def __init__(self, blob_manager, stream_info_manager, stream_hash):
self.blob_manager = blob_manager
@ -269,7 +269,7 @@ class LBRYFileReflectorClientFactory(ClientFactory):
log.debug("connection failed: %s", reason)
class LBRYBlobReflectorClient(Protocol):
class BlobReflectorClient(Protocol):
# Protocol stuff
def connectionMade(self):
@ -424,8 +424,8 @@ class LBRYBlobReflectorClient(Protocol):
self.transport.loseConnection()
class LBRYBlobReflectorClientFactory(ClientFactory):
protocol = LBRYBlobReflectorClient
class BlobReflectorClientFactory(ClientFactory):
protocol = BlobReflectorClient
def __init__(self, blob_manager, blobs):
self.blob_manager = blob_manager

View file

@ -27,7 +27,7 @@ if not os.path.isfile(lbrycrdd_path_conf):
f.write(lbrycrdd_path)
f.close()
from lbrynet.lbrynet_daemon.LBRYDaemonServer import LBRYDaemonServer, LBRYDaemonRequest
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer, DaemonRequest
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME
from lbrynet.conf import UI_ADDRESS
@ -75,11 +75,11 @@ class LBRYDaemonApp(AppKit.NSApplication):
sys.exit(0)
lbry = LBRYDaemonServer()
lbry = DaemonServer()
d = lbry.start()
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
lbrynet_server = server.Site(lbry.root)
lbrynet_server.requestFactory = LBRYDaemonRequest
lbrynet_server.requestFactory = DaemonRequest
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
def openui_(self, sender):

View file

@ -1,5 +1,5 @@
[Desktop Entry]
Version=0.4.9
Version=0.6.3
Name=LBRY
Comment=The world's first user-owned content marketplace
Icon=lbry

View file

@ -152,6 +152,15 @@ function addfile() {
echo "$(md5sum "data/$TARGET" | cut -d' ' -f1) $TARGET" >> control/md5sums
}
function addlink() {
SRC="$1"
TARGET="$2"
TMP="$PACKAGING_DIR/lbry-temp-symlink"
ln -s "$SRC" "$TMP"
addfile "$TMP" "$TARGET"
rm "$TMP"
}
# add icons
addfile "$PACKAGING_DIR/icons/lbry32.png" usr/share/icons/hicolor/32x32/apps/lbry.png
addfile "$PACKAGING_DIR/icons/lbry48.png" usr/share/icons/hicolor/48x48/apps/lbry.png
@ -164,9 +173,10 @@ addfile "$PACKAGING_DIR/lbry.desktop" usr/share/applications/lbry.desktop
BINPATH=usr/share/python/lbrynet/bin
addfile "$PACKAGING_DIR/lbry" "$BINPATH/lbry"
# symlink script into /usr/bin
ln -s "/$BINPATH/lbry" "$PACKAGING_DIR/lbry-temp-symlink"
addfile "$PACKAGING_DIR/lbry-temp-symlink" usr/bin/lbry
# symlink scripts into /usr/bin
for script in "lbry" "lbrynet-daemon" "lbrynet-cli" "stop-lbrynet-daemon"; do
addlink "/$BINPATH/$script" "usr/bin/$script"
done
# add lbrycrdd and lbrycrd-cli
mkdir -p "$PACKAGING_DIR/bins"

View file

@ -0,0 +1,95 @@
$env:Path += ";C:\MinGW\bin\"
$env:Path += ";C:\Program Files (x86)\Windows Kits\10\bin\x86\"
gcc --version
mingw32-make --version
mkdir C:\temp
Invoke-WebRequest "https://pypi.python.org/packages/55/90/e987e28ed29b571f315afea7d317b6bf4a551e37386b344190cffec60e72/miniupnpc-1.9.tar.gz" -OutFile "C:\temp\miniupnpc-1.9.tar.gz"
cd C:\temp
7z e miniupnpc-1.9.tar.gz
7z x miniupnpc-1.9.tar
cd C:\temp\miniupnpc-1.9
mingw32-make.exe -f Makefile.mingw
C:\Python27\python.exe C:\temp\miniupnpc-1.9\setupmingw32.py build --compiler=mingw32
C:\Python27\python.exe C:\temp\miniupnpc-1.9\setupmingw32.py install
Invoke-WebRequest "https://github.com/lbryio/lbry/raw/master/packaging/windows/libs/gmpy-1.17-cp27-none-win32.whl" -OutFile "C:\temp\gmpy-1.17-cp27-none-win32.whl"
C:\Python27\Scripts\pip.exe install "C:\temp\gmpy-1.17-cp27-none-win32.whl"
C:\Python27\Scripts\pip.exe install pypiwin32==219
C:\Python27\Scripts\pip.exe install six==1.9.0
C:\Python27\Scripts\pip.exe install requests==2.9.1
C:\Python27\Scripts\pip.exe install zope.interface==4.1.3
C:\Python27\Scripts\pip.exe install cx-freeze==4.3.3
C:\Python27\Scripts\pip.exe install cython==0.24.1
C:\Python27\Scripts\pip.exe install Twisted==16.0.0
C:\Python27\Scripts\pip.exe install Yapsy==1.11.223
C:\Python27\Scripts\pip.exe install appdirs==1.4.0
C:\Python27\Scripts\pip.exe install argparse==1.2.1
C:\Python27\Scripts\pip.exe install colorama==0.3.7
C:\Python27\Scripts\pip.exe install dnspython==1.12.0
C:\Python27\Scripts\pip.exe install ecdsa==0.13
C:\Python27\Scripts\pip.exe install jsonrpc==1.2
C:\Python27\Scripts\pip.exe install jsonrpclib==0.1.7
C:\Python27\Scripts\pip.exe install loggly-python-handler==1.0.0
C:\Python27\Scripts\pip.exe install pbkdf2==1.3
C:\Python27\Scripts\pip.exe install protobuf==3.0.0
C:\Python27\Scripts\pip.exe install pycrypto==2.6.1
C:\Python27\Scripts\pip.exe install python-bitcoinrpc==0.1
C:\Python27\Scripts\pip.exe install pyyaml==3.12
C:\Python27\Scripts\pip.exe install qrcode==5.2.2
C:\Python27\Scripts\pip.exe install requests_futures==0.9.7
C:\Python27\Scripts\pip.exe install seccure==0.3.1.3
C:\Python27\Scripts\pip.exe install simplejson==3.8.2
C:\Python27\Scripts\pip.exe install slowaes==0.1a1
C:\Python27\Scripts\pip.exe install txJSON-RPC==0.3.1
C:\Python27\Scripts\pip.exe install unqlite==0.5.3
C:\Python27\Scripts\pip.exe install wsgiref==0.1.2
C:\Python27\Scripts\pip.exe install base58==0.2.2
C:\Python27\Scripts\pip.exe install googlefinance==0.7
C:\Python27\Scripts\pip.exe install git+https://github.com/lbryio/lbryum.git
cd C:\projects\lbry

View file

@ -0,0 +1,15 @@
C:\Python27\python.exe setup.py install
# If this is a build because of a tag, make sure that
# its either a testing tag or a tag that matches the version
# specified in the source code.
If ($(APPVEYOR_REPO_TAG) -Match "true") {
If ($(APPVEYOR_REPO_TAG_NAME) -Like "test*") {
exit 0
}
# non-testing tags should be in the form v1.2.3
If ("v$(C:\Python27\python.exe setup.py -V)" -Match $(APPVEYOR_REPO_TAG_NAME)) {
exit 0
}
exit 1
}

View file

@ -18,7 +18,7 @@ try:
except ImportError:
import win32gui
from lbrynet.lbrynet_daemon.LBRYDaemonServer import LBRYDaemonServer, LBRYDaemonRequest
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer, DaemonRequest
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME
from lbrynet.conf import UI_ADDRESS, API_CONNECTION_STRING, LOG_FILE_NAME
from packaging.uri_handler.LBRYURIHandler import LBRYURIHandler
@ -284,11 +284,11 @@ def main(lbry_name=None):
systray_thread.daemon = True
systray_thread.start()
lbry = LBRYDaemonServer()
lbry = DaemonServer()
d = lbry.start()
d.addCallback(lambda _: LBRYURIHandler.open_address(lbry_name))
lbrynet_server = server.Site(lbry.root)
lbrynet_server.requestFactory = LBRYDaemonRequest
lbrynet_server.requestFactory = DaemonRequest
try:
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
except error.CannotListenError:

View file

@ -0,0 +1,4 @@
C:\Python27\Scripts\pip.exe install mock
C:\Python27\Scripts\pip.exe install pylint
C:\Python27\python.exe C:\Python27\Scripts\trial.py C:\projects\lbry\tests\unit

View file

@ -57,9 +57,9 @@ console_scripts = [
# 'lbrynet-rpc-node-cli = lbrynet.node_rpc_cli:main',
# 'lbrynet-lookup-hosts-for-hash = lbrynet.dht_scripts:get_hosts_for_hash_in_dht',
# 'lbrynet-announce_hash_to_dht = lbrynet.dht_scripts:announce_hash_to_dht',
'lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:start',
'stop-lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:stop',
'lbrynet-cli = lbrynet.lbrynet_daemon.LBRYDaemonCLI:main'
'lbrynet-daemon = lbrynet.lbrynet_daemon.DaemonControl:start',
'stop-lbrynet-daemon = lbrynet.lbrynet_daemon.DaemonControl:stop',
'lbrynet-cli = lbrynet.lbrynet_daemon.DaemonCLI:main'
]
if platform == LINUX:
@ -303,7 +303,7 @@ elif platform == WINDOWS:
)
daemon_exe = Executable(
script=os.path.join(daemon_dir, 'LBRYDaemonControl.py'),
script=os.path.join(daemon_dir, 'DaemonControl.py'),
icon=win_icon,
# shortcutName="lbrynet-daemon",
# shortcutDir='DesktopFolder',
@ -311,7 +311,7 @@ elif platform == WINDOWS:
)
cli_exe = Executable(
script=os.path.join(daemon_dir, 'LBRYDaemonCLI.py'),
script=os.path.join(daemon_dir, 'DaemonCLI.py'),
icon=win_icon,
# shortcutName="lbrynet-cli",
# shortcutDir='DesktopFolder',

View file

@ -1,9 +1,12 @@
import shutil
from multiprocessing import Process, Event, Queue
import logging
import platform
import sys
import random
import io
import unittest
from Crypto.PublicKey import RSA
from Crypto import Random
from Crypto.Hash import MD5
@ -14,17 +17,17 @@ from lbrynet.lbrylive.PaymentRateManager import BaseLiveStreamPaymentRateManager
from lbrynet.lbrylive.PaymentRateManager import LiveStreamPaymentRateManager
from lbrynet.lbrylive.LiveStreamMetadataManager import DBLiveStreamMetadataManager
from lbrynet.lbrylive.LiveStreamMetadataManager import TempLiveStreamMetadataManager
from lbrynet.lbryfile.LBRYFileMetadataManager import TempLBRYFileMetadataManager, DBLBRYFileMetadataManager
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
from lbrynet.lbryfile.EncryptedFileMetadataManager import TempEncryptedFileMetadataManager, DBEncryptedFileMetadataManager
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
from lbrynet.core.PaymentRateManager import PaymentRateManager
from lbrynet.core.PTCWallet import PointTraderKeyQueryHandlerFactory, PointTraderKeyExchanger
from lbrynet.core.Session import LBRYSession
from lbrynet.core.Session import Session
from lbrynet.core.client.StandaloneBlobDownloader import StandaloneBlobDownloader
from lbrynet.core.StreamDescriptor import BlobStreamDescriptorWriter
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier
from lbrynet.core.StreamDescriptor import download_sd_blob
from lbrynet.lbryfilemanager.LBRYFileCreator import create_lbry_file
from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbryfile.StreamDescriptor import get_sd_info
from twisted.internet import defer, threads, task, error
from twisted.trial.unittest import TestCase
@ -39,7 +42,7 @@ from lbrynet.lbrylive.server.LiveBlobInfoQueryHandler import CryptBlobInfoQueryH
from lbrynet.lbrylive.client.LiveStreamOptions import add_live_stream_to_sd_identifier
from lbrynet.lbrylive.client.LiveStreamDownloader import add_full_live_stream_downloader_to_sd_identifier
from lbrynet.core.BlobManager import TempBlobManager
from lbrynet.reflector.client.client import LBRYFileReflectorClientFactory
from lbrynet.reflector.client.client import EncryptedFileReflectorClientFactory
from lbrynet.reflector.server.server import ReflectorServerFactory
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
@ -48,6 +51,15 @@ log_format = "%(funcName)s(): %(message)s"
logging.basicConfig(level=logging.WARNING, format=log_format)
def require_system(system):
def wrapper(fn):
return fn
if platform.system() == system:
return wrapper
else:
return unittest.skip("Skipping. Test can only be run on " + system)
class FakeNode(object):
def __init__(self, *args, **kwargs):
pass
@ -230,13 +242,13 @@ def start_lbry_uploader(sd_hash_queue, kill_event, dead_event, file_size, ul_rat
db_dir = "server"
os.mkdir(db_dir)
session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
stream_info_manager = TempLBRYFileMetadataManager()
stream_info_manager = TempEncryptedFileMetadataManager()
lbry_file_manager = LBRYFileManager(session, stream_info_manager, sd_identifier)
lbry_file_manager = EncryptedFileManager(session, stream_info_manager, sd_identifier)
if ul_rate_limit is not None:
session.rate_limiter.set_ul_limit(ul_rate_limit)
@ -347,14 +359,14 @@ def start_lbry_reuploader(sd_hash, kill_event, dead_event, ready_event, n, ul_ra
os.mkdir(db_dir)
os.mkdir(blob_dir)
session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd" + str(n),
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd" + str(n),
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=peer_port,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
stream_info_manager = TempLBRYFileMetadataManager()
stream_info_manager = TempEncryptedFileMetadataManager()
lbry_file_manager = LBRYFileManager(session, stream_info_manager, sd_identifier)
lbry_file_manager = EncryptedFileManager(session, stream_info_manager, sd_identifier)
if ul_rate_limit is not None:
session.rate_limiter.set_ul_limit(ul_rate_limit)
@ -461,7 +473,7 @@ def start_live_server(sd_hash_queue, kill_event, dead_event):
db_dir = "server"
os.mkdir(db_dir)
session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
@ -606,7 +618,7 @@ def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow):
os.mkdir(db_dir)
os.mkdir(blob_dir)
session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="efgh",
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="efgh",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=peer_port,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
@ -756,8 +768,8 @@ class TestTransfer(TestCase):
return d
@unittest.skip("Sadly skipping failing test instead of fixing it")
def test_lbry_transfer(self):
sd_hash_queue = Queue()
kill_event = Event()
dead_event = Event()
@ -779,14 +791,14 @@ class TestTransfer(TestCase):
os.mkdir(db_dir)
os.mkdir(blob_dir)
self.session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
self.stream_info_manager = TempLBRYFileMetadataManager()
self.stream_info_manager = TempEncryptedFileMetadataManager()
self.lbry_file_manager = LBRYFileManager(self.session, self.stream_info_manager, sd_identifier)
self.lbry_file_manager = EncryptedFileManager(self.session, self.stream_info_manager, sd_identifier)
def make_downloader(metadata, prm):
info_validator = metadata.validator
@ -843,6 +855,7 @@ class TestTransfer(TestCase):
return d
@require_system('Linux')
def test_live_transfer(self):
sd_hash_queue = Queue()
@ -863,7 +876,7 @@ class TestTransfer(TestCase):
db_dir = "client"
os.mkdir(db_dir)
self.session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=None,
peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
@ -938,6 +951,7 @@ class TestTransfer(TestCase):
d.addBoth(stop)
return d
@require_system('Linux')
def test_last_blob_retrieval(self):
kill_event = Event()
@ -967,7 +981,7 @@ class TestTransfer(TestCase):
os.mkdir(db_dir)
os.mkdir(blob_dir)
self.session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
@ -1022,8 +1036,8 @@ class TestTransfer(TestCase):
return d
@unittest.skip("Sadly skipping failing test instead of fixing it")
def test_double_download(self):
sd_hash_queue = Queue()
kill_event = Event()
dead_event = Event()
@ -1047,14 +1061,14 @@ class TestTransfer(TestCase):
os.mkdir(db_dir)
os.mkdir(blob_dir)
self.session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, use_upnp=False,
rate_limiter=rate_limiter, wallet=wallet)
self.stream_info_manager = DBLBRYFileMetadataManager(self.session.db_dir)
self.stream_info_manager = DBEncryptedFileMetadataManager(self.session.db_dir)
self.lbry_file_manager = LBRYFileManager(self.session, self.stream_info_manager, sd_identifier)
self.lbry_file_manager = EncryptedFileManager(self.session, self.stream_info_manager, sd_identifier)
def make_downloader(metadata, prm):
info_validator = metadata.validator
@ -1137,8 +1151,8 @@ class TestTransfer(TestCase):
d.addBoth(stop)
return d
@unittest.skip("Sadly skipping failing test instead of fixing it")
def test_multiple_uploaders(self):
sd_hash_queue = Queue()
num_uploaders = 3
kill_event = Event()
@ -1163,14 +1177,14 @@ class TestTransfer(TestCase):
os.mkdir(db_dir)
os.mkdir(blob_dir)
self.session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
self.stream_info_manager = TempLBRYFileMetadataManager()
self.stream_info_manager = TempEncryptedFileMetadataManager()
self.lbry_file_manager = LBRYFileManager(self.session, self.stream_info_manager, sd_identifier)
self.lbry_file_manager = EncryptedFileManager(self.session, self.stream_info_manager, sd_identifier)
def start_additional_uploaders(sd_hash):
for i in range(1, num_uploaders):
@ -1281,14 +1295,14 @@ class TestStreamify(TestCase):
os.mkdir(db_dir)
os.mkdir(blob_dir)
self.session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
self.stream_info_manager = TempLBRYFileMetadataManager()
self.stream_info_manager = TempEncryptedFileMetadataManager()
self.lbry_file_manager = LBRYFileManager(self.session, self.stream_info_manager, sd_identifier)
self.lbry_file_manager = EncryptedFileManager(self.session, self.stream_info_manager, sd_identifier)
d = self.session.setup()
d.addCallback(lambda _: self.stream_info_manager.setup())
@ -1333,14 +1347,14 @@ class TestStreamify(TestCase):
os.mkdir(db_dir)
os.mkdir(blob_dir)
self.session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
self.stream_info_manager = DBLBRYFileMetadataManager(self.session.db_dir)
self.stream_info_manager = DBEncryptedFileMetadataManager(self.session.db_dir)
self.lbry_file_manager = LBRYFileManager(self.session, self.stream_info_manager, sd_identifier)
self.lbry_file_manager = EncryptedFileManager(self.session, self.stream_info_manager, sd_identifier)
def start_lbry_file(lbry_file):
logging.debug("Calling lbry_file.start()")
@ -1374,146 +1388,3 @@ class TestStreamify(TestCase):
d.addCallback(lambda _: create_stream())
d.addCallback(combine_stream)
return d
class TestReflector(TestCase):
def setUp(self):
self.session = None
self.stream_info_manager = None
self.lbry_file_manager = None
self.server_blob_manager = None
self.reflector_port = None
self.addCleanup(self.take_down_env)
def take_down_env(self):
d = defer.succeed(True)
if self.lbry_file_manager is not None:
d.addCallback(lambda _: self.lbry_file_manager.stop())
if self.session is not None:
d.addCallback(lambda _: self.session.shut_down())
if self.stream_info_manager is not None:
d.addCallback(lambda _: self.stream_info_manager.stop())
if self.server_blob_manager is not None:
d.addCallback(lambda _: self.server_blob_manager.stop())
if self.reflector_port is not None:
d.addCallback(lambda _: self.reflector_port.stopListening())
def delete_test_env():
shutil.rmtree('client')
d.addCallback(lambda _: threads.deferToThread(delete_test_env))
return d
def test_reflector(self):
wallet = FakeWallet()
peer_manager = PeerManager()
peer_finder = FakePeerFinder(5553, peer_manager, 2)
hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter()
sd_identifier = StreamDescriptorIdentifier()
self.expected_blobs = [
('dc4708f76a5e7af0f1cae0ee96b824e2ed9250c9346c093b'
'441f0a20d3607c17948b6fcfb4bc62020fe5286693d08586', 2097152),
('f4067522c1b49432a2a679512e3917144317caa1abba0c04'
'1e0cd2cf9f635d4cf127ce1824fa04189b63916174951f70', 2097152),
('305486c434260484fcb2968ce0e963b72f81ba56c11b08b1'
'af0789b55b44d78422600f9a38e3cf4f2e9569897e5646a9', 1015056),
]
db_dir = "client"
os.mkdir(db_dir)
self.session = LBRYSession(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=5553,
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
self.stream_info_manager = TempLBRYFileMetadataManager()
self.lbry_file_manager = LBRYFileManager(self.session, self.stream_info_manager, sd_identifier)
self.server_blob_manager = TempBlobManager(hash_announcer)
d = self.session.setup()
d.addCallback(lambda _: self.stream_info_manager.setup())
d.addCallback(lambda _: add_lbry_file_to_sd_identifier(sd_identifier))
d.addCallback(lambda _: self.lbry_file_manager.setup())
d.addCallback(lambda _: self.server_blob_manager.setup())
def verify_equal(sd_info):
self.assertEqual(sd_info, test_create_stream_sd_file)
def save_sd_blob_hash(sd_hash):
self.expected_blobs.append((sd_hash, 923))
def verify_stream_descriptor_file(stream_hash):
d = get_sd_info(self.lbry_file_manager.stream_info_manager, stream_hash, True)
d.addCallback(verify_equal)
d.addCallback(lambda _: publish_sd_blob(self.lbry_file_manager.stream_info_manager, self.session.blob_manager, stream_hash))
d.addCallback(save_sd_blob_hash)
d.addCallback(lambda _: stream_hash)
return d
def iv_generator():
iv = 0
while 1:
iv += 1
yield "%016d" % iv
def create_stream():
test_file = GenFile(5209343, b''.join([chr(i + 3) for i in xrange(0, 64, 6)]))
d = create_lbry_file(self.session, self.lbry_file_manager, "test_file", test_file,
key="0123456701234567", iv_generator=iv_generator())
return d
def start_server():
server_factory = ReflectorServerFactory(peer_manager, self.server_blob_manager)
from twisted.internet import reactor
port = 8943
while self.reflector_port is None:
try:
self.reflector_port = reactor.listenTCP(port, server_factory)
except error.CannotListenError:
port += 1
return defer.succeed(port)
def send_to_server(port, stream_hash):
factory = LBRYFileReflectorClientFactory(
self.session.blob_manager,
self.stream_info_manager,
stream_hash
)
from twisted.internet import reactor
reactor.connectTCP('localhost', port, factory)
return factory.finished_deferred
def verify_blob_completed(blob, blob_size):
self.assertTrue(blob.is_validated())
self.assertEqual(blob_size, blob.length)
def verify_have_blob(blob_hash, blob_size):
d = self.server_blob_manager.get_blob(blob_hash, True)
d.addCallback(lambda blob: verify_blob_completed(blob, blob_size))
return d
def verify_data_on_reflector():
check_blob_ds = []
for blob_hash, blob_size in self.expected_blobs:
check_blob_ds.append(verify_have_blob(blob_hash, blob_size))
return defer.DeferredList(check_blob_ds)
def upload_to_reflector(stream_hash):
d = start_server()
d.addCallback(lambda port: send_to_server(port, stream_hash))
d.addCallback(lambda _: verify_data_on_reflector())
return d
d.addCallback(lambda _: create_stream())
d.addCallback(verify_stream_descriptor_file)
d.addCallback(upload_to_reflector)
return d

View file

@ -12,10 +12,10 @@ from lbrynet.core import PeerManager
from lbrynet.core import RateLimiter
from lbrynet.core import Session
from lbrynet.core import StreamDescriptor
from lbrynet.lbryfile import LBRYFileMetadataManager
from lbrynet.lbryfile.client import LBRYFileOptions
from lbrynet.lbryfilemanager import LBRYFileCreator
from lbrynet.lbryfilemanager import LBRYFileManager
from lbrynet.lbryfile import EncryptedFileMetadataManager
from lbrynet.lbryfile.client import EncryptedFileOptions
from lbrynet.lbryfilemanager import EncryptedFileCreator
from lbrynet.lbryfilemanager import EncryptedFileManager
from tests import mocks
@ -81,7 +81,7 @@ class TestReflector(unittest.TestCase):
db_dir = "client"
os.mkdir(db_dir)
self.session = Session.LBRYSession(
self.session = Session.Session(
conf.MIN_BLOB_DATA_PAYMENT_RATE,
db_dir=db_dir,
lbryid="abcd",
@ -94,16 +94,16 @@ class TestReflector(unittest.TestCase):
wallet=wallet
)
self.stream_info_manager = LBRYFileMetadataManager.TempLBRYFileMetadataManager()
self.stream_info_manager = EncryptedFileMetadataManager.TempEncryptedFileMetadataManager()
self.lbry_file_manager = LBRYFileManager.LBRYFileManager(
self.lbry_file_manager = EncryptedFileManager.EncryptedFileManager(
self.session, self.stream_info_manager, sd_identifier)
self.server_blob_manager = BlobManager.TempBlobManager(hash_announcer)
d = self.session.setup()
d.addCallback(lambda _: self.stream_info_manager.setup())
d.addCallback(lambda _: LBRYFileOptions.add_lbry_file_to_sd_identifier(sd_identifier))
d.addCallback(lambda _: EncryptedFileOptions.add_lbry_file_to_sd_identifier(sd_identifier))
d.addCallback(lambda _: self.lbry_file_manager.setup())
d.addCallback(lambda _: self.server_blob_manager.setup())
@ -128,7 +128,7 @@ class TestReflector(unittest.TestCase):
def create_stream():
test_file = mocks.GenFile(5209343, b''.join([chr(i + 3) for i in xrange(0, 64, 6)]))
d = LBRYFileCreator.create_lbry_file(
d = EncryptedFileCreator.create_lbry_file(
self.session,
self.lbry_file_manager,
"test_file",

View file

@ -1,11 +1,11 @@
import mock
from lbrynet.metadata import LBRYMetadata
from lbrynet.lbrynet_daemon import LBRYExchangeRateManager
from lbrynet.metadata import Metadata
from lbrynet.lbrynet_daemon import ExchangeRateManager
from twisted.trial import unittest
class LBRYFeeFormatTest(unittest.TestCase):
class FeeFormatTest(unittest.TestCase):
def test_fee_created_with_correct_inputs(self):
fee_dict = {
'USD': {
@ -13,11 +13,11 @@ class LBRYFeeFormatTest(unittest.TestCase):
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
}
}
fee = LBRYMetadata.LBRYFeeValidator(fee_dict)
fee = Metadata.FeeValidator(fee_dict)
self.assertEqual(10.0, fee['USD']['amount'])
class LBRYFeeTest(unittest.TestCase):
class FeeTest(unittest.TestCase):
def setUp(self):
patcher = mock.patch('time.time')
self.time = patcher.start()
@ -32,5 +32,5 @@ class LBRYFeeTest(unittest.TestCase):
}
}
rates = {'BTCLBC': {'spot': 3.0, 'ts': 2}, 'USDBTC': {'spot': 2.0, 'ts': 3}}
manager = LBRYExchangeRateManager.DummyExchangeRateManager(rates)
manager = ExchangeRateManager.DummyExchangeRateManager(rates)
self.assertEqual(60.0, manager.to_lbc(fee_dict).amount)

View file

@ -1,4 +1,4 @@
from lbrynet.metadata import LBRYMetadata
from lbrynet.metadata import Metadata
from twisted.trial import unittest
@ -6,7 +6,7 @@ class MetadataTest(unittest.TestCase):
def test_assertion_if_no_metadata(self):
metadata = {}
with self.assertRaises(AssertionError):
LBRYMetadata.Metadata(metadata)
Metadata.Metadata(metadata)
def test_assertion_if_source_is_missing(self):
metadata = {
@ -19,7 +19,7 @@ class MetadataTest(unittest.TestCase):
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
}
with self.assertRaises(AssertionError):
LBRYMetadata.Metadata(metadata)
Metadata.Metadata(metadata)
def test_metadata_works_without_fee(self):
metadata = {
@ -33,7 +33,7 @@ class MetadataTest(unittest.TestCase):
'content-type': 'audio/mpeg',
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
}
m = LBRYMetadata.Metadata(metadata)
m = Metadata.Metadata(metadata)
self.assertFalse('fee' in m)
def test_assertion_if_invalid_source(self):
@ -49,7 +49,7 @@ class MetadataTest(unittest.TestCase):
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
}
with self.assertRaises(AssertionError):
LBRYMetadata.Metadata(metadata)
Metadata.Metadata(metadata)
def test_assertion_if_missing_v001_field(self):
metadata = {
@ -64,7 +64,7 @@ class MetadataTest(unittest.TestCase):
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg'
}
with self.assertRaises(AssertionError):
LBRYMetadata.Metadata(metadata)
Metadata.Metadata(metadata)
def test_version_is_001_if_all_fields_are_present(self):
metadata = {
@ -78,7 +78,7 @@ class MetadataTest(unittest.TestCase):
'content-type': 'audio/mpeg',
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
}
m = LBRYMetadata.Metadata(metadata, process_now=False)
m = Metadata.Metadata(metadata, process_now=False)
self.assertEquals('0.0.1', m.version)
def test_assertion_if_there_is_an_extra_field(self):
@ -95,7 +95,7 @@ class MetadataTest(unittest.TestCase):
'MYSTERYFIELD': '?'
}
with self.assertRaises(AssertionError):
LBRYMetadata.Metadata(metadata, process_now=False)
Metadata.Metadata(metadata, process_now=False)
def test_version_is_002_if_all_fields_are_present(self):
metadata = {
@ -112,7 +112,7 @@ class MetadataTest(unittest.TestCase):
'content-type': 'video/mp4',
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
}
m = LBRYMetadata.Metadata(metadata, process_now=False)
m = Metadata.Metadata(metadata, process_now=False)
self.assertEquals('0.0.2', m.version)
def test_version_is_003_if_all_fields_are_present(self):
@ -130,7 +130,7 @@ class MetadataTest(unittest.TestCase):
'content_type': 'video/mp4',
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
}
m = LBRYMetadata.Metadata(metadata, process_now=False)
m = Metadata.Metadata(metadata, process_now=False)
self.assertEquals('0.0.3', m.version)
def test_version_claimed_is_001_but_version_is_002(self):
@ -149,7 +149,7 @@ class MetadataTest(unittest.TestCase):
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
}
with self.assertRaises(AssertionError):
LBRYMetadata.Metadata(metadata, process_now=False)
Metadata.Metadata(metadata, process_now=False)
def test_version_claimed_is_002_but_version_is_003(self):
metadata = {
@ -167,7 +167,7 @@ class MetadataTest(unittest.TestCase):
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
}
with self.assertRaises(AssertionError):
LBRYMetadata.Metadata(metadata, process_now=False)
Metadata.Metadata(metadata, process_now=False)
def test_version_001_ports_to_003(self):
metadata = {
@ -181,7 +181,7 @@ class MetadataTest(unittest.TestCase):
'content-type': 'audio/mpeg',
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
}
m = LBRYMetadata.Metadata(metadata, process_now=True)
m = Metadata.Metadata(metadata, process_now=True)
self.assertEquals('0.0.3', m.version)
def test_version_002_ports_to_003(self):
@ -199,5 +199,5 @@ class MetadataTest(unittest.TestCase):
'content-type': 'video/mp4',
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
}
m = LBRYMetadata.Metadata(metadata, process_now=True)
m = Metadata.Metadata(metadata, process_now=True)
self.assertEquals('0.0.3', m.version)

View file

@ -2,7 +2,7 @@ import mock
import requests
from twisted.trial import unittest
from lbrynet.lbrynet_daemon import LBRYDaemon
from lbrynet.lbrynet_daemon import Daemon
class MiscTests(unittest.TestCase):
@ -18,9 +18,9 @@ class MiscTests(unittest.TestCase):
"tag_name": "v0.3.8",
"prerelease": False
}
with mock.patch('lbrynet.lbrynet_daemon.LBRYDaemon.requests') as req:
with mock.patch('lbrynet.lbrynet_daemon.Daemon.requests') as req:
req.get.return_value = response
self.assertEqual('0.3.8', LBRYDaemon.get_lbrynet_version_from_github())
self.assertEqual('0.3.8', Daemon.get_lbrynet_version_from_github())
def test_error_is_thrown_if_prerelease(self):
response = mock.create_autospec(requests.Response)
@ -28,11 +28,11 @@ class MiscTests(unittest.TestCase):
"tag_name": "v0.3.8",
"prerelease": True
}
with mock.patch('lbrynet.lbrynet_daemon.LBRYDaemon.requests') as req:
with mock.patch('lbrynet.lbrynet_daemon.Daemon.requests') as req:
req.get.return_value = response
with self.assertRaises(Exception):
LBRYDaemon.get_lbrynet_version_from_github()
Daemon.get_lbrynet_version_from_github()
def test_error_is_thrown_when_version_cant_be_parsed(self):
with self.assertRaises(Exception):
LBRYDaemon.get_version_from_tag('garbage')
Daemon.get_version_from_tag('garbage')

View file

@ -1,14 +1,14 @@
from twisted.trial import unittest
from lbrynet.lbrynet_daemon import LBRYDaemonCLI
from lbrynet.lbrynet_daemon import DaemonCLI
class LBRYDaemonCLITests(unittest.TestCase):
class DaemonCLITests(unittest.TestCase):
def test_guess_type(self):
self.assertEqual('0.3.8', LBRYDaemonCLI.guess_type('0.3.8'))
self.assertEqual(0.3, LBRYDaemonCLI.guess_type('0.3'))
self.assertEqual(3, LBRYDaemonCLI.guess_type('3'))
self.assertEqual('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA==', LBRYDaemonCLI.guess_type('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA=='))
self.assertEqual(0.3, LBRYDaemonCLI.guess_type('0.3'))
self.assertEqual('0.3.8', DaemonCLI.guess_type('0.3.8'))
self.assertEqual(0.3, DaemonCLI.guess_type('0.3'))
self.assertEqual(3, DaemonCLI.guess_type('3'))
self.assertEqual('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA==', DaemonCLI.guess_type('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA=='))
self.assertEqual(0.3, DaemonCLI.guess_type('0.3'))
def test_get_params(self):
test_params = [
@ -25,4 +25,4 @@ class LBRYDaemonCLITests(unittest.TestCase):
'n': 5,
'address': 'bY13xeAjLrsjP4KGETwStK2a9UgKgXVTXu'
}
self.assertDictEqual(test_r, LBRYDaemonCLI.get_params_from_kwargs(test_params))
self.assertDictEqual(test_r, DaemonCLI.get_params_from_kwargs(test_params))