update from master
resolve merge conflicts: lbrynet/core/client/BlobRequester.py lbrynet/core/Peer.py lbrynet/lbryfilemanager/EncryptedFileManager.py lbrynet/lbrynet_daemon/Daemon.py lbrynet/lbrynet_daemon/Publisher.py
This commit is contained in:
commit
71b989b29b
55 changed files with 1006 additions and 722 deletions
124
.appveyor.yml
124
.appveyor.yml
|
@ -12,116 +12,17 @@ notifications:
|
||||||
incoming_webhook:
|
incoming_webhook:
|
||||||
secure: LuxwG5OZnnA//gmSXzCKu8/FRqYjCgGfVFqajSsGHeQ1HQNp7rYNhQpsO8/3PK63xKJj3wzt86DJekf9q9Q5OcHa9AHXUQbEveX0psd7elw=
|
secure: LuxwG5OZnnA//gmSXzCKu8/FRqYjCgGfVFqajSsGHeQ1HQNp7rYNhQpsO8/3PK63xKJj3wzt86DJekf9q9Q5OcHa9AHXUQbEveX0psd7elw=
|
||||||
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- appveyor
|
|
||||||
- windows-setup
|
|
||||||
|
|
||||||
clone_folder: c:\projects\lbry
|
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:
|
install:
|
||||||
|
- cmd: dir C:\projects\lbry\packaging\windows\
|
||||||
|
- ps: .\packaging\windows\init.ps1
|
||||||
- nuget install secure-file -ExcludeVersion
|
- nuget install secure-file -ExcludeVersion
|
||||||
- secure-file\tools\secure-file -decrypt packaging\windows\certs\lbry2.pfx.enc -secret %pfx_key%
|
- 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:
|
build_script:
|
||||||
|
@ -130,12 +31,8 @@ build_script:
|
||||||
|
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- ps: >-
|
- ps: .\packaging\windows\test.ps1
|
||||||
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
|
|
||||||
|
|
||||||
artifacts:
|
artifacts:
|
||||||
- path: dist/*.msi
|
- path: dist/*.msi
|
||||||
|
@ -144,3 +41,16 @@ artifacts:
|
||||||
name: lbry-portable
|
name: lbry-portable
|
||||||
- path: packaging/windows/lbry-win32-app/LBRY-URI.reg
|
- path: packaging/windows/lbry-win32-app/LBRY-URI.reg
|
||||||
name: LBRY-URI
|
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
|
||||||
|
|
46
INSTALL.md
46
INSTALL.md
|
@ -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).
|
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
|
##### 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
|
##### 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.
|
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.
|
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 from source
|
||||||
#### Installing LBRY command line
|
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
##### OS X
|
Installing LBRY from source is not the recommended way to install
|
||||||
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.
|
LBRY. Only do so if you're interested in doing development work.
|
||||||
|
|
||||||
##### Linux
|
##### OS X Prerequisites
|
||||||
On Ubuntu or Mint you can install the prerequisites and lbrynet by running
|
|
||||||
|
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
|
git clone https://github.com/lbryio/lbry.git
|
||||||
cd lbry
|
cd lbry
|
||||||
sudo python setup.py install
|
python setup.py install
|
||||||
```
|
```
|
||||||
|
|
||||||
To start LBRY, run `lbrynet-daemon` in a terminal.
|
To start LBRY, run `lbrynet-daemon` in a terminal.
|
||||||
|
|
||||||
#### On windows:
|
|
||||||
|
##### On windows
|
||||||
|
|
||||||
Install [mingw32](http://www.mingw.org/) base and c++ compiler.
|
Install [mingw32](http://www.mingw.org/) base and c++ compiler.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
from lbrynet.analytics import utils
|
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):
|
class Events(object):
|
||||||
def __init__(self, context, lbry_id, session_id):
|
def __init__(self, context, lbry_id, session_id):
|
||||||
self.context = context
|
self.context = context
|
||||||
|
@ -19,6 +34,20 @@ class Events(object):
|
||||||
'timestamp': utils.now()
|
'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):
|
def make_context(platform, wallet, is_dev=False):
|
||||||
# TODO: distinguish between developer and release instances
|
# TODO: distinguish between developer and release instances
|
||||||
|
|
|
@ -7,12 +7,12 @@ from Crypto.Hash import SHA512
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
from lbrynet.core.client.ClientRequest import ClientRequest
|
from lbrynet.core.client.ClientRequest import ClientRequest
|
||||||
from lbrynet.core.Error import RequestCanceledError
|
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 lbrynet.pointtraderclient import pointtraderclient
|
||||||
from twisted.internet import defer, threads
|
from twisted.internet import defer, threads
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
from twisted.python.failure import Failure
|
from twisted.python.failure import Failure
|
||||||
from lbrynet.core.LBRYWallet import ReservedPoints
|
from lbrynet.core.Wallet import ReservedPoints
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -21,7 +21,7 @@ log = logging.getLogger(__name__)
|
||||||
class PTCWallet(object):
|
class PTCWallet(object):
|
||||||
"""This class sends payments to peers and also ensures that expected payments are received.
|
"""This class sends payments to peers and also ensures that expected payments are received.
|
||||||
This class is only intended to be used for testing."""
|
This class is only intended to be used for testing."""
|
||||||
implements(ILBRYWallet)
|
implements(IWallet)
|
||||||
|
|
||||||
def __init__(self, db_dir):
|
def __init__(self, db_dir):
|
||||||
self.db_dir = db_dir
|
self.db_dir = db_dir
|
||||||
|
|
|
@ -32,4 +32,7 @@ class Peer(object):
|
||||||
self.stats[stat_type] += count
|
self.stats[stat_type] += count
|
||||||
|
|
||||||
def __str__(self):
|
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)
|
||||||
|
|
|
@ -17,7 +17,7 @@ from twisted.internet import threads, defer
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LBRYSession(object):
|
class Session(object):
|
||||||
"""This class manages all important services common to any application that uses the network:
|
"""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,
|
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
|
this means this peer has a blob identified by the hash in question, but it can be used for other
|
||||||
|
|
|
@ -17,15 +17,15 @@ from decimal import Decimal
|
||||||
|
|
||||||
from lbryum import SimpleConfig, Network
|
from lbryum import SimpleConfig, Network
|
||||||
from lbryum.lbrycrd import COIN
|
from lbryum.lbrycrd import COIN
|
||||||
from lbryum.wallet import WalletStorage, Wallet
|
import lbryum.wallet
|
||||||
from lbryum.commands import known_commands, Commands
|
from lbryum.commands import known_commands, Commands
|
||||||
from lbryum.transaction import Transaction
|
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.client.ClientRequest import ClientRequest
|
||||||
from lbrynet.core.Error import UnknownNameError, InvalidStreamInfoError, RequestCanceledError
|
from lbrynet.core.Error import UnknownNameError, InvalidStreamInfoError, RequestCanceledError
|
||||||
from lbrynet.core.Error import InsufficientFundsError
|
from lbrynet.core.Error import InsufficientFundsError
|
||||||
from lbrynet.metadata.LBRYMetadata import Metadata
|
from lbrynet.metadata.Metadata import Metadata
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
alert = logging.getLogger("lbryalert." + __name__)
|
alert = logging.getLogger("lbryalert." + __name__)
|
||||||
|
@ -47,9 +47,9 @@ def _catch_connection_error(f):
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
|
||||||
class LBRYWallet(object):
|
class Wallet(object):
|
||||||
"""This class implements the LBRYWallet interface for the LBRYcrd payment system"""
|
"""This class implements the Wallet interface for the LBRYcrd payment system"""
|
||||||
implements(ILBRYWallet)
|
implements(IWallet)
|
||||||
|
|
||||||
_FIRST_RUN_UNKNOWN = 0
|
_FIRST_RUN_UNKNOWN = 0
|
||||||
_FIRST_RUN_YES = 1
|
_FIRST_RUN_YES = 1
|
||||||
|
@ -762,9 +762,9 @@ class LBRYWallet(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LBRYcrdWallet(LBRYWallet):
|
class LBRYcrdWallet(Wallet):
|
||||||
def __init__(self, db_dir, wallet_dir=None, wallet_conf=None, lbrycrdd_path=None):
|
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.started_lbrycrdd = False
|
||||||
self.wallet_dir = wallet_dir
|
self.wallet_dir = wallet_dir
|
||||||
self.wallet_conf = wallet_conf
|
self.wallet_conf = wallet_conf
|
||||||
|
@ -1108,10 +1108,10 @@ class LBRYcrdWallet(LBRYWallet):
|
||||||
self.lbrycrdd.wait()
|
self.lbrycrdd.wait()
|
||||||
|
|
||||||
|
|
||||||
class LBRYumWallet(LBRYWallet):
|
class LBRYumWallet(Wallet):
|
||||||
|
|
||||||
def __init__(self, db_dir):
|
def __init__(self, db_dir):
|
||||||
LBRYWallet.__init__(self, db_dir)
|
Wallet.__init__(self, db_dir)
|
||||||
self.config = None
|
self.config = None
|
||||||
self.network = None
|
self.network = None
|
||||||
self.wallet = None
|
self.wallet = None
|
||||||
|
@ -1189,8 +1189,8 @@ class LBRYumWallet(LBRYWallet):
|
||||||
|
|
||||||
def get_wallet():
|
def get_wallet():
|
||||||
path = self.config.get_wallet_path()
|
path = self.config.get_wallet_path()
|
||||||
storage = WalletStorage(path)
|
storage = lbryum.wallet.WalletStorage(path)
|
||||||
wallet = Wallet(storage)
|
wallet = lbryum.wallet.Wallet(storage)
|
||||||
if not storage.file_exists:
|
if not storage.file_exists:
|
||||||
self.first_run = True
|
self.first_run = True
|
||||||
seed = wallet.make_seed()
|
seed = wallet.make_seed()
|
|
@ -12,9 +12,25 @@ from lbrynet.core.client.ClientRequest import ClientRequest, ClientBlobRequest
|
||||||
from lbrynet.interfaces import IRequestCreator
|
from lbrynet.interfaces import IRequestCreator
|
||||||
from lbrynet.core.Offer import Negotiate, Offer
|
from lbrynet.core.Offer import Negotiate, Offer
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
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):
|
class BlobRequester(object):
|
||||||
implements(IRequestCreator)
|
implements(IRequestCreator)
|
||||||
|
|
||||||
|
@ -33,58 +49,11 @@ class BlobRequester(object):
|
||||||
self._incompatible_peers = []
|
self._incompatible_peers = []
|
||||||
|
|
||||||
######## IRequestCreator #########
|
######## IRequestCreator #########
|
||||||
|
|
||||||
def send_next_request(self, peer, protocol):
|
def send_next_request(self, peer, protocol):
|
||||||
sent_request = False
|
"""Makes an availability request, download request and price request"""
|
||||||
if self._blobs_to_download() and self._should_send_request_to(peer):
|
if not self.should_send_next_request(peer):
|
||||||
a_r = self._get_availability_request(peer)
|
return defer.succeed(False)
|
||||||
d_r = self._get_download_request(peer)
|
return self._send_next_request(peer, protocol)
|
||||||
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 and protocol in self._protocol_prices:
|
|
||||||
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)
|
|
||||||
|
|
||||||
def get_new_peers(self):
|
def get_new_peers(self):
|
||||||
d = self._get_hash_for_peer_search()
|
d = self._get_hash_for_peer_search()
|
||||||
|
@ -92,91 +61,34 @@ class BlobRequester(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
######### internal calls #########
|
######### internal calls #########
|
||||||
|
def should_send_next_request(self, peer):
|
||||||
|
return (
|
||||||
|
self._blobs_to_download() and
|
||||||
|
self._should_send_request_to(peer)
|
||||||
|
)
|
||||||
|
|
||||||
def _blobs_to_download(self):
|
def _send_next_request(self, peer, protocol):
|
||||||
needed_blobs = self.download_manager.needed_blobs()
|
log.debug('Sending a blob request for %s and %s', peer, protocol)
|
||||||
return sorted(needed_blobs, key=lambda b: b.is_downloading())
|
availability = AvailabilityRequest(self, peer, protocol, self.payment_rate_manager)
|
||||||
|
download = DownloadRequest(self, peer, protocol, self.payment_rate_manager, self.wallet)
|
||||||
|
price = PriceRequest(self, peer, protocol, self.payment_rate_manager)
|
||||||
|
|
||||||
def _get_blobs_to_request_from_peer(self, peer):
|
sent_request = False
|
||||||
all_needed = [b.blob_hash for b in self._blobs_to_download() if not b.blob_hash in self._available_blobs[peer]]
|
if availability.can_make_request():
|
||||||
# sort them so that the peer will be asked first for blobs it hasn't said it doesn't have
|
availability.make_request_and_handle_response()
|
||||||
to_request = sorted(all_needed, key=lambda b: b in self._unavailable_blobs[peer])[:20]
|
sent_request = True
|
||||||
return to_request
|
|
||||||
|
|
||||||
def _price_settled(self, protocol):
|
if download.can_make_request():
|
||||||
if protocol in self._protocol_prices:
|
try:
|
||||||
return True
|
download.make_request_and_handle_response()
|
||||||
return False
|
sent_request = True
|
||||||
|
except InsufficientFundsError as err:
|
||||||
def _get_price_request(self, peer, protocol):
|
return defer.fail(err)
|
||||||
request = None
|
if sent_request and price.can_make_request():
|
||||||
response_identifier = Negotiate.PAYMENT_RATE
|
# TODO: document why a PriceRequest is only made if an
|
||||||
if protocol not in self._protocol_prices:
|
# Availability or Download request was made
|
||||||
blobs_to_request = self._available_blobs[peer]
|
price.make_request_and_handle_response()
|
||||||
if blobs_to_request:
|
return defer.succeed(sent_request)
|
||||||
rate = self.payment_rate_manager.get_rate_blob_data(peer, blobs_to_request)
|
|
||||||
self._protocol_prices[protocol] = rate
|
|
||||||
offer = Offer(rate)
|
|
||||||
request = ClientRequest(Negotiate.make_dict_from_offer(offer), response_identifier)
|
|
||||||
log.debug("Offer rate %s to %s for %i blobs", str(rate), str(peer), len(blobs_to_request))
|
|
||||||
else:
|
|
||||||
log.debug("No blobs to request from %s", str(peer))
|
|
||||||
return request
|
|
||||||
|
|
||||||
def _handle_price_response(self, response_dict, peer, request, protocol):
|
|
||||||
if not request.response_identifier in response_dict:
|
|
||||||
return InvalidResponseError("response identifier not in response")
|
|
||||||
assert protocol in self._protocol_prices
|
|
||||||
offer = Negotiate.get_offer_from_request(response_dict)
|
|
||||||
rate = self._protocol_prices[protocol]
|
|
||||||
if offer.accepted:
|
|
||||||
log.info("Offered rate %f/mb accepted by %s", rate, str(peer.host))
|
|
||||||
return True
|
|
||||||
elif offer.too_low:
|
|
||||||
log.info("Offered rate %f/mb rejected by %s", rate, str(peer.host))
|
|
||||||
del self._protocol_prices[protocol]
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
log.warning("Price disagreement")
|
|
||||||
log.warning(offer.rate)
|
|
||||||
del self._protocol_prices[protocol]
|
|
||||||
self._price_disagreements.append(peer)
|
|
||||||
return False
|
|
||||||
|
|
||||||
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 _download_failed(self, reason, peer):
|
|
||||||
if not reason.check(DownloadCanceledError, PriceDisagreementError):
|
|
||||||
self._update_local_score(peer, -10.0)
|
|
||||||
return reason
|
|
||||||
|
|
||||||
def _record_blob_acquired(self, blob, host, rate):
|
|
||||||
d = self.blob_manager.add_blob_to_download_history(blob, host, rate)
|
|
||||||
|
|
||||||
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)
|
|
||||||
self._record_blob_acquired(str(blob), protocol.peer.host, reserved_points.amount)
|
|
||||||
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
|
|
||||||
|
|
||||||
def _get_hash_for_peer_search(self):
|
def _get_hash_for_peer_search(self):
|
||||||
r = None
|
r = None
|
||||||
|
@ -233,84 +145,77 @@ class BlobRequester(object):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _blobs_to_download(self):
|
||||||
|
needed_blobs = self.download_manager.needed_blobs()
|
||||||
|
return sorted(needed_blobs, key=lambda b: b.is_downloading())
|
||||||
|
|
||||||
def _blobs_without_sources(self):
|
def _blobs_without_sources(self):
|
||||||
return [b for b in self.download_manager.needed_blobs() if not self._hash_available(b.blob_hash)]
|
return [
|
||||||
|
b for b in self.download_manager.needed_blobs()
|
||||||
|
if not self._hash_available(b.blob_hash)
|
||||||
|
]
|
||||||
|
|
||||||
def _get_availability_request(self, peer):
|
def _price_settled(self, protocol):
|
||||||
to_request = self._get_blobs_to_request_from_peer(peer)
|
if protocol in self._protocol_prices:
|
||||||
if to_request:
|
return True
|
||||||
r_dict = {'requested_blobs': to_request}
|
return False
|
||||||
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
|
|
||||||
|
|
||||||
def _update_local_score(self, peer, amount):
|
def _update_local_score(self, peer, amount):
|
||||||
self._peers[peer] += amount
|
self._peers[peer] += amount
|
||||||
|
|
||||||
def _reserve_points(self, peer, protocol, max_bytes):
|
|
||||||
if 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)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _pay_peer(self, protocol, num_bytes, reserved_points):
|
class RequestHelper(object):
|
||||||
if num_bytes != 0 and protocol in self._protocol_prices:
|
def __init__(self, requestor, peer, protocol, payment_rate_manager):
|
||||||
point_amount = 1.0 * num_bytes * self._protocol_prices[protocol] / 2**20
|
self.requestor = requestor
|
||||||
self.wallet.send_points(reserved_points, point_amount)
|
self.peer = peer
|
||||||
self.payment_rate_manager.record_points_paid(point_amount)
|
self.protocol = protocol
|
||||||
log.debug("Pay peer %s", str(point_amount))
|
self.payment_rate_manager = payment_rate_manager
|
||||||
|
|
||||||
def _cancel_points(self, reserved_points):
|
@property
|
||||||
self.wallet.cancel_point_reservation(reserved_points)
|
def protocol_prices(self):
|
||||||
|
return self.requestor._protocol_prices
|
||||||
|
|
||||||
def _handle_availability(self, response_dict, peer, request):
|
@property
|
||||||
if not request.response_identifier in response_dict:
|
def available_blobs(self):
|
||||||
raise InvalidResponseError("response identifier not in response")
|
return self.requestor._available_blobs[self.peer]
|
||||||
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
|
|
||||||
|
|
||||||
def _handle_incoming_blob(self, response_dict, peer, request):
|
@property
|
||||||
log.debug("Handling incoming blob: %s", str(response_dict))
|
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(self):
|
||||||
|
rate = self.protocol_prices.get(self.protocol)
|
||||||
|
if rate is None:
|
||||||
|
rate = self.payment_rate_manager.get_rate_blob_data(self.peer, self.available_blobs)
|
||||||
|
self.protocol_prices[self.protocol] = rate
|
||||||
|
return rate
|
||||||
|
|
||||||
|
|
||||||
|
def _handle_incoming_blob(response_dict, peer, request):
|
||||||
if not request.response_identifier in response_dict:
|
if not request.response_identifier in response_dict:
|
||||||
return InvalidResponseError("response identifier not in response")
|
return InvalidResponseError("response identifier not in response")
|
||||||
if not type(response_dict[request.response_identifier]) == dict:
|
if not type(response_dict[request.response_identifier]) == dict:
|
||||||
return InvalidResponseError("response not a dict. got %s" %
|
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]
|
response = response_dict[request.response_identifier]
|
||||||
if 'error' in response:
|
if 'error' in response:
|
||||||
# This means we're not getting our blob for some reason
|
# This means we're not getting our blob for some reason
|
||||||
|
@ -325,26 +230,308 @@ class BlobRequester(object):
|
||||||
if not 'blob_hash' in response:
|
if not 'blob_hash' in response:
|
||||||
return InvalidResponseError("Missing the required field 'blob_hash'")
|
return InvalidResponseError("Missing the required field 'blob_hash'")
|
||||||
if not response['blob_hash'] == request.request_dict['requested_blob']:
|
if not response['blob_hash'] == request.request_dict['requested_blob']:
|
||||||
return InvalidResponseError("Incoming blob does not match expected. Incoming: %s. Expected: %s" %
|
return InvalidResponseError(
|
||||||
(response['blob_hash'], request.request_dict['requested_blob']))
|
"Incoming blob does not match expected. Incoming: %s. Expected: %s" %
|
||||||
|
(response['blob_hash'], request.request_dict['requested_blob'])
|
||||||
|
)
|
||||||
if not 'length' in response:
|
if not 'length' in response:
|
||||||
return InvalidResponseError("Missing the required field 'length'")
|
return InvalidResponseError("Missing the required field 'length'")
|
||||||
if not request.blob.set_length(response['length']):
|
if not request.blob.set_length(response['length']):
|
||||||
return InvalidResponseError("Could not set the length of the blob")
|
return InvalidResponseError("Could not set the length of the blob")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _request_failed(self, reason, request_type, peer):
|
|
||||||
if reason.check(RequestCanceledError):
|
def _handle_download_error(err, peer, blob_to_download):
|
||||||
return
|
if not err.check(DownloadCanceledError, PriceDisagreementError, RequestCanceledError):
|
||||||
if reason.check(NoResponseError):
|
log.warning("An error occurred while downloading %s from %s. Error: %s",
|
||||||
self._incompatible_peers.append(peer)
|
blob_to_download.blob_hash, str(peer), err.getTraceback())
|
||||||
log.warning("Blob requester: a request of type '%s' failed. Reason: %s, Error type: %s",
|
if err.check(PriceDisagreementError):
|
||||||
str(request_type), reason.getErrorMessage(), reason.type)
|
# Don't kill the whole connection just because a price couldn't be agreed upon.
|
||||||
self._update_local_score(peer, -10.0)
|
# Other information might be desired by other request creators at a better rate.
|
||||||
if isinstance(reason, InvalidResponseError) or isinstance(reason, NoResponseError):
|
return True
|
||||||
peer.update_score(-10.0)
|
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 PriceRequest(RequestHelper):
|
||||||
|
"""Ask a peer if a certain price is acceptable"""
|
||||||
|
def can_make_request(self):
|
||||||
|
return self.get_and_save_rate() 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()
|
||||||
|
if rate is None:
|
||||||
|
log.debug("No blobs to request from %s", str(self.peer))
|
||||||
|
raise Exception('Cannot make a price request without a payment rate')
|
||||||
|
log.debug("Offer rate %s to %s for %i blobs", str(rate), str(self.peer), len(self.available_blobs))
|
||||||
|
|
||||||
|
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 self.protocol in self.protocol_prices
|
||||||
|
response = Offer(response_dict['blob_data_payment_rate'])
|
||||||
|
rate = self.protocol_prices[self.protocol]
|
||||||
|
if response.accepted:
|
||||||
|
log.info("Offered rate %f/mb accepted by %s", rate, str(self.peer.host))
|
||||||
|
return True
|
||||||
|
elif response.too_low:
|
||||||
|
log.info("Offered rate %f/mb rejected by %s", rate, str(self.peer.host))
|
||||||
|
del self.protocol_prices[self.protocol]
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
peer.update_score(-2.0)
|
log.warning("Price disagreement")
|
||||||
if reason.check(ConnectionClosedBeforeResponseError):
|
log.warning(rate)
|
||||||
return
|
del self.protocol_prices[self.protocol]
|
||||||
|
self.requestor._price_disagreements.append(self.peer)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadRequest(RequestHelper):
|
||||||
|
"""Choose a blob and download it from a peer and also pay the peer for the data."""
|
||||||
|
def __init__(self, requester, peer, protocol, payment_rate_manager, wallet):
|
||||||
|
RequestHelper.__init__(self, requester, peer, protocol, payment_rate_manager)
|
||||||
|
self.wallet = wallet
|
||||||
|
|
||||||
|
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)
|
||||||
|
d = self.requestor.blob_manager.add_blob_to_download_history(str(blob),
|
||||||
|
str(self.peer.host),
|
||||||
|
float(self.protocol_prices[self.protocol]))
|
||||||
|
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()
|
||||||
|
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()
|
||||||
|
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
|
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)
|
|
@ -49,8 +49,8 @@ class ConnectionManager(object):
|
||||||
for peer in self._peer_connections.keys():
|
for peer in self._peer_connections.keys():
|
||||||
|
|
||||||
def close_connection(p):
|
def close_connection(p):
|
||||||
log.info("Abruptly closing a connection to %s due to downloading being paused",
|
log.info(
|
||||||
str(p))
|
"Abruptly closing a connection to %s due to downloading being paused", p)
|
||||||
|
|
||||||
if self._peer_connections[p].factory.p is not None:
|
if self._peer_connections[p].factory.p is not None:
|
||||||
d = self._peer_connections[p].factory.p.cancel_requests()
|
d = self._peer_connections[p].factory.p.cancel_requests()
|
||||||
|
@ -73,7 +73,7 @@ class ConnectionManager(object):
|
||||||
|
|
||||||
def get_next_request(self, peer, protocol):
|
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:
|
if not peer in self._peer_connections or self.stopped is True:
|
||||||
log.debug("The peer has already been told to shut down.")
|
log.debug("The peer has already been told to shut down.")
|
||||||
|
@ -148,7 +148,7 @@ class ConnectionManager(object):
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
|
||||||
if peer is not None and self.stopped is False:
|
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)
|
factory = ClientProtocolFactory(peer, self.rate_limiter, self)
|
||||||
self._peer_connections[peer] = PeerConnectionHandler(self._primary_request_creators[:],
|
self._peer_connections[peer] = PeerConnectionHandler(self._primary_request_creators[:],
|
||||||
factory)
|
factory)
|
||||||
|
@ -162,7 +162,7 @@ class ConnectionManager(object):
|
||||||
def get_new_peers(request_creators):
|
def get_new_peers(request_creators):
|
||||||
log.debug("Trying to get a new peer to connect to")
|
log.debug("Trying to get a new peer to connect to")
|
||||||
if len(request_creators) > 0:
|
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 = request_creators[0].get_new_peers()
|
||||||
d.addCallback(lambda h: h if h is not None else get_new_peers(request_creators[1:]))
|
d.addCallback(lambda h: h if h is not None else get_new_peers(request_creators[1:]))
|
||||||
return d
|
return d
|
||||||
|
@ -173,12 +173,12 @@ class ConnectionManager(object):
|
||||||
# TODO: Eventually rank them based on past performance/reputation. For now
|
# 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
|
# 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:
|
if peers is None:
|
||||||
return None
|
return None
|
||||||
for peer in peers:
|
for peer in peers:
|
||||||
if not peer in self._peer_connections:
|
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
|
return peer
|
||||||
log.debug("Couldn't find a good peer to connect to")
|
log.debug("Couldn't find a good peer to connect to")
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -93,7 +93,6 @@ class DummyBlobHandler(object):
|
||||||
|
|
||||||
|
|
||||||
class StandaloneBlobDownloader(object):
|
class StandaloneBlobDownloader(object):
|
||||||
|
|
||||||
def __init__(self, blob_hash, blob_manager, peer_finder, rate_limiter, payment_rate_manager, wallet):
|
def __init__(self, blob_hash, blob_manager, peer_finder, rate_limiter, payment_rate_manager, wallet):
|
||||||
self.blob_hash = blob_hash
|
self.blob_hash = blob_hash
|
||||||
self.blob_manager = blob_manager
|
self.blob_manager = blob_manager
|
||||||
|
|
|
@ -73,15 +73,14 @@ def _log_decorator(fn):
|
||||||
|
|
||||||
def disable_third_party_loggers():
|
def disable_third_party_loggers():
|
||||||
logging.getLogger('requests').setLevel(logging.WARNING)
|
logging.getLogger('requests').setLevel(logging.WARNING)
|
||||||
|
logging.getLogger('BitcoinRPC').setLevel(logging.INFO)
|
||||||
|
|
||||||
def disable_noisy_loggers():
|
def disable_noisy_loggers():
|
||||||
logging.getLogger('BitcoinRPC').setLevel(logging.INFO)
|
|
||||||
logging.getLogger('lbrynet.analytics.api').setLevel(logging.INFO)
|
logging.getLogger('lbrynet.analytics.api').setLevel(logging.INFO)
|
||||||
logging.getLogger('lbrynet.core').setLevel(logging.INFO)
|
logging.getLogger('lbrynet.core').setLevel(logging.INFO)
|
||||||
logging.getLogger('lbrynet.dht').setLevel(logging.INFO)
|
logging.getLogger('lbrynet.dht').setLevel(logging.INFO)
|
||||||
logging.getLogger('lbrynet.lbrynet_daemon').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.lbryfile').setLevel(logging.INFO)
|
||||||
logging.getLogger('lbrynet.lbryfilemanager').setLevel(logging.INFO)
|
logging.getLogger('lbrynet.lbryfilemanager').setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ class CryptStreamDownloader(object):
|
||||||
|
|
||||||
@param payment_rate_manager: A NegotiatedPaymentRateManager object
|
@param payment_rate_manager: A NegotiatedPaymentRateManager object
|
||||||
|
|
||||||
@param wallet: An object which implements the ILBRYWallet interface
|
@param wallet: An object which implements the IWallet interface
|
||||||
|
|
||||||
@return:
|
@return:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -233,14 +233,14 @@
|
||||||
# " foreign key(stream_hash) references lbry_files(stream_hash)" +
|
# " foreign key(stream_hash) references lbry_files(stream_hash)" +
|
||||||
# ")")
|
# ")")
|
||||||
# new_db.commit()
|
# new_db.commit()
|
||||||
# LBRYFILE_STATUS = "t"
|
# FILE_STATUS = "t"
|
||||||
# LBRYFILE_OPTIONS = "o"
|
# FILE_OPTIONS = "o"
|
||||||
# c = new_db.cursor()
|
# c = new_db.cursor()
|
||||||
# for k, v in old_db.RangeIter():
|
# for k, v in old_db.RangeIter():
|
||||||
# key_type, stream_hash = json.loads(k)
|
# key_type, stream_hash = json.loads(k)
|
||||||
# if key_type == LBRYFILE_STATUS:
|
# if key_type == FILE_STATUS:
|
||||||
# try:
|
# 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:
|
# except KeyError:
|
||||||
# rate = None
|
# rate = None
|
||||||
# c.execute("insert into lbry_file_options values (?, ?, ?)",
|
# c.execute("insert into lbry_file_options values (?, ?, ?)",
|
||||||
|
|
|
@ -548,13 +548,13 @@ class IStreamDescriptorValidator(Interface):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class ILBRYWallet(Interface):
|
class IWallet(Interface):
|
||||||
"""
|
"""
|
||||||
Send and receive payments.
|
Send and receive payments.
|
||||||
|
|
||||||
To send a payment, a payment reservation must be obtained first. This guarantees that a payment
|
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
|
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.
|
be canceled.
|
||||||
"""
|
"""
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
|
|
@ -11,7 +11,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DBLBRYFileMetadataManager(object):
|
class DBEncryptedFileMetadataManager(object):
|
||||||
"""Store and provide access to LBRY file metadata using sqlite"""
|
"""Store and provide access to LBRY file metadata using sqlite"""
|
||||||
|
|
||||||
def __init__(self, db_dir):
|
def __init__(self, db_dir):
|
||||||
|
@ -243,7 +243,7 @@ class DBLBRYFileMetadataManager(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class TempLBRYFileMetadataManager(object):
|
class TempEncryptedFileMetadataManager(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.streams = {}
|
self.streams = {}
|
||||||
self.stream_blobs = {}
|
self.stream_blobs = {}
|
|
@ -11,7 +11,7 @@ import os
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
LBRYFileStreamType = "lbryfile"
|
EncryptedFileStreamType = "lbryfile"
|
||||||
|
|
||||||
|
|
||||||
def save_sd_info(stream_info_manager, sd_info, ignore_duplicate=False):
|
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):
|
def format_info(stream_info):
|
||||||
fields = {}
|
fields = {}
|
||||||
fields['stream_type'] = LBRYFileStreamType
|
fields['stream_type'] = EncryptedFileStreamType
|
||||||
fields['stream_name'] = stream_info[1]
|
fields['stream_name'] = stream_info[1]
|
||||||
fields['key'] = stream_info[0]
|
fields['key'] = stream_info[0]
|
||||||
fields['suggested_file_name'] = stream_info[2]
|
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
|
return d
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileStreamDescriptorValidator(object):
|
class EncryptedFileStreamDescriptorValidator(object):
|
||||||
def __init__(self, raw_info):
|
def __init__(self, raw_info):
|
||||||
self.raw_info = raw_info
|
self.raw_info = raw_info
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from lbrynet.cryptstream.client.CryptStreamDownloader import CryptStreamDownload
|
||||||
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
|
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
|
||||||
from lbrynet.core.StreamDescriptor import StreamMetadata
|
from lbrynet.core.StreamDescriptor import StreamMetadata
|
||||||
from lbrynet.interfaces import IStreamDownloaderFactory
|
from lbrynet.interfaces import IStreamDownloaderFactory
|
||||||
from lbrynet.lbryfile.client.LBRYFileMetadataHandler import LBRYFileMetadataHandler
|
from lbrynet.lbryfile.client.EncryptedFileMetadataHandler import EncryptedFileMetadataHandler
|
||||||
import os
|
import os
|
||||||
from twisted.internet import defer, threads, reactor
|
from twisted.internet import defer, threads, reactor
|
||||||
from twisted.python.procutils import which
|
from twisted.python.procutils import which
|
||||||
|
@ -19,7 +19,7 @@ import traceback
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileDownloader(CryptStreamDownloader):
|
class EncryptedFileDownloader(CryptStreamDownloader):
|
||||||
"""Classes which inherit from this class download LBRY files"""
|
"""Classes which inherit from this class download LBRY files"""
|
||||||
|
|
||||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
|
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
|
||||||
|
@ -120,10 +120,10 @@ class LBRYFileDownloader(CryptStreamDownloader):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def _get_metadata_handler(self, download_manager):
|
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)
|
implements(IStreamDownloaderFactory)
|
||||||
|
|
||||||
def __init__(self, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
def __init__(self, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||||
|
@ -165,10 +165,10 @@ class LBRYFileDownloaderFactory(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileSaver(LBRYFileDownloader):
|
class EncryptedFileSaver(EncryptedFileDownloader):
|
||||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
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):
|
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)
|
stream_info_manager, payment_rate_manager, wallet, upload_allowed)
|
||||||
self.download_directory = download_directory
|
self.download_directory = download_directory
|
||||||
self.file_name = file_name
|
self.file_name = file_name
|
||||||
|
@ -182,7 +182,7 @@ class LBRYFileSaver(LBRYFileDownloader):
|
||||||
return str(self.file_name)
|
return str(self.file_name)
|
||||||
|
|
||||||
def set_stream_info(self):
|
def set_stream_info(self):
|
||||||
d = LBRYFileDownloader.set_stream_info(self)
|
d = EncryptedFileDownloader.set_stream_info(self)
|
||||||
|
|
||||||
def set_file_name():
|
def set_file_name():
|
||||||
if self.file_name is None:
|
if self.file_name is None:
|
||||||
|
@ -195,7 +195,7 @@ class LBRYFileSaver(LBRYFileDownloader):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def stop(self, err=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())
|
d.addCallback(lambda _: self._delete_from_info_manager())
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -257,15 +257,15 @@ class LBRYFileSaver(LBRYFileDownloader):
|
||||||
return self.stream_info_manager.delete_stream(self.stream_hash)
|
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,
|
def __init__(self, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||||
wallet, download_directory):
|
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)
|
stream_info_manager, wallet)
|
||||||
self.download_directory = download_directory
|
self.download_directory = download_directory
|
||||||
|
|
||||||
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info, upload_allowed):
|
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.stream_info_manager, payment_rate_manager, self.wallet,
|
||||||
self.download_directory, upload_allowed)
|
self.download_directory, upload_allowed)
|
||||||
|
|
||||||
|
@ -274,16 +274,16 @@ class LBRYFileSaverFactory(LBRYFileDownloaderFactory):
|
||||||
return "Save"
|
return "Save"
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileOpener(LBRYFileDownloader):
|
class EncryptedFileOpener(EncryptedFileDownloader):
|
||||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||||
payment_rate_manager, wallet, upload_allowed):
|
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)
|
stream_info_manager, payment_rate_manager, wallet, upload_allowed)
|
||||||
self.process = None
|
self.process = None
|
||||||
self.process_log = None
|
self.process_log = None
|
||||||
|
|
||||||
def stop(self, err=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())
|
d.addCallback(lambda _: self._delete_from_info_manager())
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ class LBRYFileOpener(LBRYFileDownloader):
|
||||||
return self.stream_info_manager.delete_stream(self.stream_hash)
|
return self.stream_info_manager.delete_stream(self.stream_hash)
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileOpenerFactory(LBRYFileDownloaderFactory):
|
class EncryptedFileOpenerFactory(EncryptedFileDownloaderFactory):
|
||||||
def can_download(self, sd_validator):
|
def can_download(self, sd_validator):
|
||||||
if which('vlc'):
|
if which('vlc'):
|
||||||
return True
|
return True
|
||||||
|
@ -346,7 +346,7 @@ class LBRYFileOpenerFactory(LBRYFileDownloaderFactory):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info, upload_allowed):
|
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)
|
self.stream_info_manager, payment_rate_manager, self.wallet, upload_allowed)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
|
@ -7,7 +7,7 @@ from lbrynet.interfaces import IMetadataHandler
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileMetadataHandler(object):
|
class EncryptedFileMetadataHandler(object):
|
||||||
implements(IMetadataHandler)
|
implements(IMetadataHandler)
|
||||||
|
|
||||||
def __init__(self, stream_hash, stream_info_manager, download_manager):
|
def __init__(self, stream_hash, stream_info_manager, download_manager):
|
|
@ -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
|
from lbrynet.core.DownloadOption import DownloadOption, DownloadOptionChoice
|
||||||
|
|
||||||
|
|
||||||
def add_lbry_file_to_sd_identifier(sd_identifier):
|
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):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -16,9 +16,9 @@ from twisted.protocols.basic import FileSender
|
||||||
log = logging.getLogger(__name__)
|
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,
|
def __init__(self, blob_manager, lbry_file_manager, name=None,
|
||||||
key=None, iv_generator=None, suggested_file_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
|
into chunks and encrypted, and then a stream descriptor file with the stream parameters
|
||||||
and other metadata is written to disk.
|
and other metadata is written to disk.
|
||||||
|
|
||||||
@param session: An LBRYSession object.
|
@param session: An Session object.
|
||||||
@type session: LBRYSession
|
@type session: Session
|
||||||
|
|
||||||
@param lbry_file_manager: The LBRYFileManager object this LBRY File will be added to.
|
@param lbry_file_manager: The EncryptedFileManager object this LBRY File will be added to.
|
||||||
@type lbry_file_manager: LBRYFileManager
|
@type lbry_file_manager: EncryptedFileManager
|
||||||
|
|
||||||
@param file_name: The path to the plain file.
|
@param file_name: The path to the plain file.
|
||||||
@type file_name: string
|
@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)
|
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)
|
key, iv_generator, suggested_file_name)
|
||||||
|
|
||||||
def start_stream():
|
def start_stream():
|
|
@ -5,8 +5,8 @@ Download LBRY Files from LBRYnet and save them to disk.
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
|
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
|
||||||
from lbrynet.core.StreamDescriptor import StreamMetadata
|
from lbrynet.core.StreamDescriptor import StreamMetadata
|
||||||
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaver, LBRYFileDownloader
|
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaver, EncryptedFileDownloader
|
||||||
from lbrynet.lbryfilemanager.LBRYFileStatusReport import LBRYFileStatusReport
|
from lbrynet.lbryfilemanager.EncryptedFileStatusReport import EncryptedFileStatusReport
|
||||||
from lbrynet.interfaces import IStreamDownloaderFactory
|
from lbrynet.interfaces import IStreamDownloaderFactory
|
||||||
from lbrynet.lbryfile.StreamDescriptor import save_sd_info
|
from lbrynet.lbryfile.StreamDescriptor import save_sd_info
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
@ -15,7 +15,7 @@ import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ManagedLBRYFileDownloader(LBRYFileSaver):
|
class ManagedEncryptedFileDownloader(EncryptedFileSaver):
|
||||||
|
|
||||||
STATUS_RUNNING = "running"
|
STATUS_RUNNING = "running"
|
||||||
STATUS_STOPPED = "stopped"
|
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,
|
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,
|
lbry_file_manager, payment_rate_manager, wallet, download_directory, upload_allowed,
|
||||||
file_name=None):
|
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,
|
stream_info_manager, payment_rate_manager, wallet, download_directory,
|
||||||
upload_allowed, file_name)
|
upload_allowed, file_name)
|
||||||
self.sd_hash = None
|
self.sd_hash = None
|
||||||
|
@ -68,11 +68,11 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
|
||||||
d.addCallback(lambda _: self.lbry_file_manager.get_lbry_file_status(self))
|
d.addCallback(lambda _: self.lbry_file_manager.get_lbry_file_status(self))
|
||||||
|
|
||||||
def restore_status(status):
|
def restore_status(status):
|
||||||
if status == ManagedLBRYFileDownloader.STATUS_RUNNING:
|
if status == ManagedEncryptedFileDownloader.STATUS_RUNNING:
|
||||||
return self.start()
|
return self.start()
|
||||||
elif status == ManagedLBRYFileDownloader.STATUS_STOPPED:
|
elif status == ManagedEncryptedFileDownloader.STATUS_STOPPED:
|
||||||
return defer.succeed(False)
|
return defer.succeed(False)
|
||||||
elif status == ManagedLBRYFileDownloader.STATUS_FINISHED:
|
elif status == ManagedEncryptedFileDownloader.STATUS_FINISHED:
|
||||||
self.completed = True
|
self.completed = True
|
||||||
return defer.succeed(True)
|
return defer.succeed(True)
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
|
||||||
def set_saving_status_done():
|
def set_saving_status_done():
|
||||||
self.saving_status = False
|
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:
|
if change_status is True:
|
||||||
self.saving_status = True
|
self.saving_status = True
|
||||||
d.addCallback(lambda _: self._save_status())
|
d.addCallback(lambda _: self._save_status())
|
||||||
|
@ -111,7 +111,7 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
|
||||||
s = "stopped"
|
s = "stopped"
|
||||||
else:
|
else:
|
||||||
s = "running"
|
s = "running"
|
||||||
status = LBRYFileStatusReport(self.file_name, num_completed, num_known, s)
|
status = EncryptedFileStatusReport(self.file_name, num_completed, num_known, s)
|
||||||
return status
|
return status
|
||||||
|
|
||||||
d = self.stream_info_manager.get_blobs_for_stream(self.stream_hash)
|
d = self.stream_info_manager.get_blobs_for_stream(self.stream_hash)
|
||||||
|
@ -121,7 +121,7 @@ class ManagedLBRYFileDownloader(LBRYFileSaver):
|
||||||
|
|
||||||
def _start(self):
|
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))
|
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):
|
def _save_status(self):
|
||||||
if self.completed is True:
|
if self.completed is True:
|
||||||
s = ManagedLBRYFileDownloader.STATUS_FINISHED
|
s = ManagedEncryptedFileDownloader.STATUS_FINISHED
|
||||||
elif self.stopped is True:
|
elif self.stopped is True:
|
||||||
s = ManagedLBRYFileDownloader.STATUS_STOPPED
|
s = ManagedEncryptedFileDownloader.STATUS_STOPPED
|
||||||
else:
|
else:
|
||||||
s = ManagedLBRYFileDownloader.STATUS_RUNNING
|
s = ManagedEncryptedFileDownloader.STATUS_RUNNING
|
||||||
return self.lbry_file_manager.change_lbry_file_status(self, s)
|
return self.lbry_file_manager.change_lbry_file_status(self, s)
|
||||||
|
|
||||||
def _get_progress_manager(self, download_manager):
|
def _get_progress_manager(self, download_manager):
|
||||||
return FullStreamProgressManager(self._finished_downloading, self.blob_manager, download_manager)
|
return FullStreamProgressManager(self._finished_downloading, self.blob_manager, download_manager)
|
||||||
|
|
||||||
|
|
||||||
class ManagedLBRYFileDownloaderFactory(object):
|
class ManagedEncryptedFileDownloaderFactory(object):
|
||||||
implements(IStreamDownloaderFactory)
|
implements(IStreamDownloaderFactory)
|
||||||
|
|
||||||
def __init__(self, lbry_file_manager):
|
def __init__(self, lbry_file_manager):
|
|
@ -9,10 +9,10 @@ from twisted.enterprise import adbapi
|
||||||
from twisted.internet import defer, task, reactor
|
from twisted.internet import defer, task, reactor
|
||||||
from twisted.python.failure import Failure
|
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.core.PaymentRateManager import NegotiatedPaymentRateManager
|
from lbrynet.core.PaymentRateManager import NegotiatedPaymentRateManager
|
||||||
|
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
||||||
|
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory
|
||||||
|
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
|
||||||
from lbrynet.cryptstream.client.CryptStreamDownloader import AlreadyStoppedError, CurrentlyStoppingError
|
from lbrynet.cryptstream.client.CryptStreamDownloader import AlreadyStoppedError, CurrentlyStoppingError
|
||||||
from lbrynet.core.sqlite_helpers import rerun_if_locked
|
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__)
|
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.
|
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
|
self.download_directory = download_directory
|
||||||
else:
|
else:
|
||||||
self.download_directory = os.getcwd()
|
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):
|
def setup(self):
|
||||||
d = self._open_db()
|
d = self._open_db()
|
||||||
|
@ -68,8 +68,8 @@ class LBRYFileManager(object):
|
||||||
return dl
|
return dl
|
||||||
|
|
||||||
def _add_to_sd_identifier(self):
|
def _add_to_sd_identifier(self):
|
||||||
downloader_factory = ManagedLBRYFileDownloaderFactory(self)
|
downloader_factory = ManagedEncryptedFileDownloaderFactory(self)
|
||||||
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, downloader_factory)
|
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, downloader_factory)
|
||||||
|
|
||||||
def _start_lbry_files(self):
|
def _start_lbry_files(self):
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class LBRYFileManager(object):
|
||||||
if not download_directory:
|
if not download_directory:
|
||||||
download_directory = self.download_directory
|
download_directory = self.download_directory
|
||||||
payment_rate_manager.min_blob_data_payment_rate = blob_data_rate
|
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.peer_finder,
|
||||||
self.session.rate_limiter,
|
self.session.rate_limiter,
|
||||||
self.session.blob_manager,
|
self.session.blob_manager,
|
||||||
|
@ -208,7 +208,7 @@ class LBRYFileManager(object):
|
||||||
def _save_lbry_file(self, stream_hash, data_payment_rate):
|
def _save_lbry_file(self, stream_hash, data_payment_rate):
|
||||||
def do_save(db_transaction):
|
def do_save(db_transaction):
|
||||||
db_transaction.execute("insert into lbry_file_options values (?, ?, ?)",
|
db_transaction.execute("insert into lbry_file_options values (?, ?, ?)",
|
||||||
(data_payment_rate, ManagedLBRYFileDownloader.STATUS_STOPPED,
|
(data_payment_rate, ManagedEncryptedFileDownloader.STATUS_STOPPED,
|
||||||
stream_hash))
|
stream_hash))
|
||||||
return db_transaction.lastrowid
|
return db_transaction.lastrowid
|
||||||
return self.sql_db.runInteraction(do_save)
|
return self.sql_db.runInteraction(do_save)
|
||||||
|
@ -237,7 +237,7 @@ class LBRYFileManager(object):
|
||||||
def _get_lbry_file_status(self, rowid):
|
def _get_lbry_file_status(self, rowid):
|
||||||
d = self.sql_db.runQuery("select status from lbry_file_options where rowid = ?",
|
d = self.sql_db.runQuery("select status from lbry_file_options where rowid = ?",
|
||||||
(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
|
return d
|
||||||
|
|
||||||
@rerun_if_locked
|
@rerun_if_locked
|
|
@ -1,4 +1,4 @@
|
||||||
class LBRYFileStatusReport(object):
|
class EncryptedFileStatusReport(object):
|
||||||
def __init__(self, name, num_completed, num_known, running_status):
|
def __init__(self, name, num_completed, num_known, running_status):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.num_completed = num_completed
|
self.num_completed = num_completed
|
|
@ -5,7 +5,7 @@ import logging
|
||||||
import sys
|
import sys
|
||||||
from lbrynet.lbrylive.LiveStreamCreator import StdOutLiveStreamCreator
|
from lbrynet.lbrylive.LiveStreamCreator import StdOutLiveStreamCreator
|
||||||
from lbrynet.core.BlobManager import TempBlobManager
|
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.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory
|
||||||
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||||
|
@ -16,7 +16,7 @@ from lbrynet.dht.node import Node
|
||||||
from twisted.internet import defer, task
|
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."""
|
"""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,
|
def __init__(self, peer_port, dht_node_port, known_dht_nodes,
|
||||||
stream_info_manager_class=DBLiveStreamMetadataManager, blob_manager_class=TempBlobManager):
|
stream_info_manager_class=DBLiveStreamMetadataManager, blob_manager_class=TempBlobManager):
|
||||||
|
@ -29,7 +29,7 @@ class LBRYStdinUploader():
|
||||||
"""
|
"""
|
||||||
self.peer_port = peer_port
|
self.peer_port = peer_port
|
||||||
self.lbry_server_port = None
|
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,
|
stream_info_manager_class=stream_info_manager_class,
|
||||||
dht_node_class=Node, dht_node_port=dht_node_port,
|
dht_node_class=Node, dht_node_port=dht_node_port,
|
||||||
known_dht_nodes=known_dht_nodes, peer_port=self.peer_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")
|
logging.basicConfig(level=logging.WARNING, filename="ul.log")
|
||||||
if len(sys.argv) == 4:
|
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:
|
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:
|
else:
|
||||||
print "Usage: lbrynet-stdin-uploader <stream_name> <peer_port> <dht_node_port>" \
|
print "Usage: lbrynet-stdin-uploader <stream_name> <peer_port> <dht_node_port>" \
|
||||||
" [<dht_bootstrap_host> <dht_bootstrap port>]"
|
" [<dht_bootstrap_host> <dht_bootstrap port>]"
|
|
@ -4,9 +4,9 @@
|
||||||
import logging
|
import logging
|
||||||
import sys
|
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.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.client.StandaloneBlobDownloader import StandaloneBlobDownloader
|
||||||
from lbrynet.core.StreamDescriptor import BlobStreamDescriptorReader
|
from lbrynet.core.StreamDescriptor import BlobStreamDescriptorReader
|
||||||
from lbrynet.lbrylive.PaymentRateManager import BaseLiveStreamPaymentRateManager
|
from lbrynet.lbrylive.PaymentRateManager import BaseLiveStreamPaymentRateManager
|
||||||
|
@ -16,7 +16,7 @@ from lbrynet.dht.node import Node
|
||||||
from twisted.internet import task
|
from twisted.internet import task
|
||||||
|
|
||||||
|
|
||||||
class LBRYStdoutDownloader():
|
class StdoutDownloader():
|
||||||
"""This class downloads a live stream from the network and outputs it to standard out."""
|
"""This class downloads a live stream from the network and outputs it to standard out."""
|
||||||
def __init__(self, dht_node_port, known_dht_nodes,
|
def __init__(self, dht_node_port, known_dht_nodes,
|
||||||
stream_info_manager_class=DBLiveStreamMetadataManager, blob_manager_class=TempBlobManager):
|
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,
|
stream_info_manager_class=stream_info_manager_class,
|
||||||
dht_node_class=Node, dht_node_port=dht_node_port, known_dht_nodes=known_dht_nodes,
|
dht_node_class=Node, dht_node_port=dht_node_port, known_dht_nodes=known_dht_nodes,
|
||||||
use_upnp=False)
|
use_upnp=False)
|
||||||
|
@ -55,7 +55,7 @@ class LBRYStdoutDownloader():
|
||||||
d.addCallbacks(self.read_sd_file)
|
d.addCallbacks(self.read_sd_file)
|
||||||
|
|
||||||
def start_stream(stream_hash):
|
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.session.rate_limiter, self.session.blob_manager,
|
||||||
self.stream_info_manager, self.payment_rate_manager,
|
self.stream_info_manager, self.payment_rate_manager,
|
||||||
self.session.wallet)
|
self.session.wallet)
|
||||||
|
@ -76,9 +76,9 @@ def launch_stdout_downloader():
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING, filename="dl.log")
|
logging.basicConfig(level=logging.WARNING, filename="dl.log")
|
||||||
if len(sys.argv) == 3:
|
if len(sys.argv) == 3:
|
||||||
downloader = LBRYStdoutDownloader(int(sys.argv[2]), [])
|
downloader = StdoutDownloader(int(sys.argv[2]), [])
|
||||||
elif len(sys.argv) == 5:
|
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:
|
else:
|
||||||
print "Usage: lbrynet-stdout-downloader <sd_hash> <peer_port> <dht_node_port>" \
|
print "Usage: lbrynet-stdout-downloader <sd_hash> <peer_port> <dht_node_port>" \
|
||||||
" [<dht_bootstrap_host> <dht_bootstrap port>]"
|
" [<dht_bootstrap_host> <dht_bootstrap port>]"
|
|
@ -84,7 +84,7 @@ def get_sd_info(stream_info_manager, stream_hash, include_blobs):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class LBRYLiveStreamDescriptorValidator(object):
|
class LiveStreamDescriptorValidator(object):
|
||||||
implements(IStreamDescriptorValidator)
|
implements(IStreamDescriptorValidator)
|
||||||
|
|
||||||
def __init__(self, raw_info):
|
def __init__(self, raw_info):
|
||||||
|
|
|
@ -12,7 +12,7 @@ from lbrynet.interfaces import IStreamDownloaderFactory
|
||||||
from lbrynet.lbrylive.StreamDescriptor import LiveStreamType
|
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,
|
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||||
payment_rate_manager, wallet, upload_allowed):
|
payment_rate_manager, wallet, upload_allowed):
|
||||||
|
@ -39,10 +39,10 @@ class LiveStreamDownloader(CryptStreamDownloader):
|
||||||
return defer.succeed(True)
|
return defer.succeed(True)
|
||||||
|
|
||||||
|
|
||||||
class LBRYLiveStreamDownloader(LiveStreamDownloader):
|
class LiveStreamDownloader(_LiveStreamDownloader):
|
||||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||||
payment_rate_manager, wallet, upload_allowed):
|
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)
|
stream_info_manager, payment_rate_manager, wallet, upload_allowed)
|
||||||
|
|
||||||
#self.writer = process.ProcessWriter(reactor, self, 'write', 1)
|
#self.writer = process.ProcessWriter(reactor, self, 'write', 1)
|
||||||
|
@ -65,17 +65,17 @@ class LBRYLiveStreamDownloader(LiveStreamDownloader):
|
||||||
return write_func
|
return write_func
|
||||||
|
|
||||||
|
|
||||||
class FullLiveStreamDownloader(LiveStreamDownloader):
|
class FullLiveStreamDownloader(_LiveStreamDownloader):
|
||||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||||
payment_rate_manager, wallet, upload_allowed):
|
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,
|
blob_manager, stream_info_manager, payment_rate_manager,
|
||||||
wallet, upload_allowed)
|
wallet, upload_allowed)
|
||||||
self.file_handle = None
|
self.file_handle = None
|
||||||
self.file_name = None
|
self.file_name = None
|
||||||
|
|
||||||
def set_stream_info(self):
|
def set_stream_info(self):
|
||||||
d = LiveStreamDownloader.set_stream_info(self)
|
d = _LiveStreamDownloader.set_stream_info(self)
|
||||||
|
|
||||||
def set_file_name_if_unset():
|
def set_file_name_if_unset():
|
||||||
if not self.file_name:
|
if not self.file_name:
|
||||||
|
@ -88,7 +88,7 @@ class FullLiveStreamDownloader(LiveStreamDownloader):
|
||||||
|
|
||||||
def stop(self, err=None):
|
def stop(self, err=None):
|
||||||
d = self._close_file()
|
d = self._close_file()
|
||||||
d.addBoth(lambda _: LiveStreamDownloader.stop(self, err))
|
d.addBoth(lambda _: _LiveStreamDownloader.stop(self, err))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
|
@ -96,7 +96,7 @@ class FullLiveStreamDownloader(LiveStreamDownloader):
|
||||||
d = self._open_file()
|
d = self._open_file()
|
||||||
else:
|
else:
|
||||||
d = defer.succeed(True)
|
d = defer.succeed(True)
|
||||||
d.addCallback(lambda _: LiveStreamDownloader._start(self))
|
d.addCallback(lambda _: _LiveStreamDownloader._start(self))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _open_file(self):
|
def _open_file(self):
|
||||||
|
|
|
@ -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
|
from lbrynet.core.DownloadOption import DownloadOption, DownloadOptionChoice
|
||||||
|
|
||||||
|
|
||||||
def add_live_stream_to_sd_identifier(sd_identifier, base_live_stream_payment_rate_manager):
|
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))
|
LiveStreamOptions(base_live_stream_payment_rate_manager))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,10 @@ from yapsy.PluginManager import PluginManager
|
||||||
from twisted.internet import defer, threads, stdio, task, error
|
from twisted.internet import defer, threads, stdio, task, error
|
||||||
from jsonrpc.proxy import JSONRPCProxy
|
from 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.ConsoleControl import ConsoleControl
|
||||||
from lbrynet.lbrynet_console.LBRYSettings import LBRYSettings
|
from lbrynet.lbrynet_console.Settings import Settings
|
||||||
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
|
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.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.utils import generate_id
|
||||||
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier
|
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.BlobRequestHandler import BlobRequestHandlerFactory
|
||||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||||
from lbrynet.core.PTCWallet import PTCWallet
|
from lbrynet.core.PTCWallet import PTCWallet
|
||||||
from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier
|
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
|
||||||
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileOpenerFactory
|
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileOpenerFactory
|
||||||
from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
|
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
|
||||||
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
|
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager, TempEncryptedFileMetadataManager
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import ApplicationStatusFactory, GetWalletBalancesFactory, ShutDownFactory
|
from lbrynet.lbrynet_console.ControlHandlers import ApplicationStatusFactory, GetWalletBalancesFactory, ShutDownFactory
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import ImmediateAnnounceAllBlobsFactory
|
from lbrynet.lbrynet_console.ControlHandlers import ImmediateAnnounceAllBlobsFactory
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import LBRYFileStatusFactory, DeleteLBRYFileChooserFactory
|
from lbrynet.lbrynet_console.ControlHandlers import EncryptedFileStatusFactory, DeleteEncryptedFileChooserFactory
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import ToggleLBRYFileRunningChooserFactory
|
from lbrynet.lbrynet_console.ControlHandlers import ToggleEncryptedFileRunningChooserFactory
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import ModifyApplicationDefaultsFactory
|
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 ShowPublishedSDHashesChooserFactory
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import CreatePlainStreamDescriptorChooserFactory
|
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 AddStreamFromSDFactory, AddStreamFromLBRYcrdNameFactory
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import ClaimNameFactory, GetNewWalletAddressFactory
|
from lbrynet.lbrynet_console.ControlHandlers import ClaimNameFactory, GetNewWalletAddressFactory
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import ShowServerStatusFactory, ModifyServerSettingsFactory
|
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 PeerStatsAndSettingsChooserFactory, PublishFactory
|
||||||
from lbrynet.lbrynet_console.ControlHandlers import BlockchainStatusFactory
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
alert = logging.getLogger("lbryalert." + __name__)
|
alert = logging.getLogger("lbryalert." + __name__)
|
||||||
|
|
||||||
|
|
||||||
class LBRYConsole():
|
class Console():
|
||||||
"""A class which can upload and download file streams to and from the network"""
|
"""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,
|
def __init__(self, peer_port, dht_node_port, known_dht_nodes, fake_wallet,
|
||||||
lbrycrd_conf, lbrycrd_dir, use_upnp, data_dir, created_data_dir,
|
lbrycrd_conf, lbrycrd_dir, use_upnp, data_dir, created_data_dir,
|
||||||
|
@ -93,7 +93,7 @@ class LBRYConsole():
|
||||||
self.command_handlers = []
|
self.command_handlers = []
|
||||||
self.query_handlers = {}
|
self.query_handlers = {}
|
||||||
|
|
||||||
self.settings = LBRYSettings(self.db_dir)
|
self.settings = Settings(self.db_dir)
|
||||||
self.blob_request_payment_rate_manager = None
|
self.blob_request_payment_rate_manager = None
|
||||||
self.lbryid = None
|
self.lbryid = None
|
||||||
self.sd_identifier = StreamDescriptorIdentifier()
|
self.sd_identifier = StreamDescriptorIdentifier()
|
||||||
|
@ -239,7 +239,7 @@ class LBRYConsole():
|
||||||
|
|
||||||
alert.info("Databases loaded.")
|
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,
|
blob_dir=self.blobfile_dir, dht_node_port=self.dht_node_port,
|
||||||
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port,
|
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port,
|
||||||
use_upnp=self.use_upnp, wallet=results['wallet'])
|
use_upnp=self.use_upnp, wallet=results['wallet'])
|
||||||
|
@ -297,11 +297,11 @@ class LBRYConsole():
|
||||||
"catch up with our blockchain.\n", points_string)
|
"catch up with our blockchain.\n", points_string)
|
||||||
|
|
||||||
def _setup_lbry_file_manager(self):
|
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()
|
d = self.lbry_file_metadata_manager.setup()
|
||||||
|
|
||||||
def set_lbry_file_manager():
|
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()
|
return self.lbry_file_manager.setup()
|
||||||
|
|
||||||
d.addCallback(lambda _: set_lbry_file_manager())
|
d.addCallback(lambda _: set_lbry_file_manager())
|
||||||
|
@ -309,11 +309,11 @@ class LBRYConsole():
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _setup_lbry_file_opener(self):
|
def _setup_lbry_file_opener(self):
|
||||||
stream_info_manager = TempLBRYFileMetadataManager()
|
stream_info_manager = TempEncryptedFileMetadataManager()
|
||||||
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, stream_info_manager,
|
self.session.blob_manager, stream_info_manager,
|
||||||
self.session.wallet)
|
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)
|
return defer.succeed(True)
|
||||||
|
|
||||||
def _setup_control_handlers(self):
|
def _setup_control_handlers(self):
|
||||||
|
@ -323,20 +323,20 @@ class LBRYConsole():
|
||||||
ModifyApplicationDefaultsFactory(self),
|
ModifyApplicationDefaultsFactory(self),
|
||||||
ShutDownFactory(self),
|
ShutDownFactory(self),
|
||||||
PeerStatsAndSettingsChooserFactory(self.session.peer_manager),
|
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,
|
AddStreamFromSDFactory(self.sd_identifier, self.session.base_payment_rate_manager,
|
||||||
self.session.wallet),
|
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),
|
self.lbry_file_manager),
|
||||||
ToggleLBRYFileRunningChooserFactory(self.lbry_file_manager),
|
ToggleEncryptedFileRunningChooserFactory(self.lbry_file_manager),
|
||||||
CreateLBRYFileFactory(self.session, self.lbry_file_manager),
|
CreateEncryptedFileFactory(self.session, self.lbry_file_manager),
|
||||||
PublishStreamDescriptorChooserFactory(self.lbry_file_metadata_manager,
|
PublishStreamDescriptorChooserFactory(self.lbry_file_metadata_manager,
|
||||||
self.session.blob_manager),
|
self.session.blob_manager),
|
||||||
ShowPublishedSDHashesChooserFactory(self.lbry_file_metadata_manager,
|
ShowPublishedSDHashesChooserFactory(self.lbry_file_metadata_manager,
|
||||||
self.lbry_file_manager),
|
self.lbry_file_manager),
|
||||||
CreatePlainStreamDescriptorChooserFactory(self.lbry_file_manager),
|
CreatePlainStreamDescriptorChooserFactory(self.lbry_file_manager),
|
||||||
ShowLBRYFileStreamHashChooserFactory(self.lbry_file_manager),
|
ShowEncryptedFileStreamHashChooserFactory(self.lbry_file_manager),
|
||||||
ModifyLBRYFileOptionsChooserFactory(self.lbry_file_manager),
|
ModifyEncryptedFileOptionsChooserFactory(self.lbry_file_manager),
|
||||||
AddStreamFromHashFactory(self.sd_identifier, self.session, self.session.wallet),
|
AddStreamFromHashFactory(self.sd_identifier, self.session, self.session.wallet),
|
||||||
StatusFactory(self, self.session.rate_limiter, self.lbry_file_manager,
|
StatusFactory(self, self.session.rate_limiter, self.lbry_file_manager,
|
||||||
self.session.blob_manager, self.session.wallet if not self.fake_wallet else None),
|
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)
|
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,
|
lbrycrd_conf=args.lbrycrd_wallet_conf, lbrycrd_dir=args.lbrycrd_wallet_dir,
|
||||||
use_upnp=not args.disable_upnp, data_dir=data_dir,
|
use_upnp=not args.disable_upnp, data_dir=data_dir,
|
||||||
created_data_dir=created_data_dir, lbrycrdd_path=args.lbrycrdd_path)
|
created_data_dir=created_data_dir, lbrycrdd_path=args.lbrycrdd_path)
|
|
@ -2,8 +2,8 @@ import logging
|
||||||
|
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
||||||
from lbrynet.lbryfilemanager.LBRYFileCreator import create_lbry_file
|
from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file
|
||||||
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloader
|
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
||||||
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob, create_plain_sd
|
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob, create_plain_sd
|
||||||
from lbrynet.lbrynet_console.interfaces import ICommandHandler, ICommandHandlerFactory
|
from lbrynet.lbrynet_console.interfaces import ICommandHandler, ICommandHandlerFactory
|
||||||
from lbrynet.core.StreamDescriptor import download_sd_blob
|
from lbrynet.core.StreamDescriptor import download_sd_blob
|
||||||
|
@ -418,7 +418,7 @@ class ShutDownFactory(CommandHandlerFactory):
|
||||||
full_help = "Shut down"
|
full_help = "Shut down"
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileStatus(CommandHandler):
|
class EncryptedFileStatus(CommandHandler):
|
||||||
#prompt_description = "Print status information for all LBRY Files"
|
#prompt_description = "Print status information for all LBRY Files"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file_manager):
|
def __init__(self, console, lbry_file_manager):
|
||||||
|
@ -446,8 +446,8 @@ class LBRYFileStatus(CommandHandler):
|
||||||
self.console.sendLine(''.join(status_strings))
|
self.console.sendLine(''.join(status_strings))
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileStatusFactory(CommandHandlerFactory):
|
class EncryptedFileStatusFactory(CommandHandlerFactory):
|
||||||
control_handler_class = LBRYFileStatus
|
control_handler_class = EncryptedFileStatus
|
||||||
command = "lbryfile-status"
|
command = "lbryfile-status"
|
||||||
short_help = "Print status information for LBRY files"
|
short_help = "Print status information for LBRY files"
|
||||||
full_help = "Print the status information for all streams that are being saved to disk." \
|
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>"
|
"Usage: get <name>"
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileChooser(RecursiveCommandHandler):
|
class EncryptedFileChooser(RecursiveCommandHandler):
|
||||||
|
|
||||||
def __init__(self, console, lbry_file_manager, factory_class, *args, **kwargs):
|
def __init__(self, console, lbry_file_manager, factory_class, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -1014,23 +1014,23 @@ class LBRYFileChooser(RecursiveCommandHandler):
|
||||||
return control_handler_factories
|
return control_handler_factories
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileChooserFactory(CommandHandlerFactory):
|
class EncryptedFileChooserFactory(CommandHandlerFactory):
|
||||||
def get_prompt_description(self):
|
def get_prompt_description(self):
|
||||||
lbry_file = self.args[0]
|
lbry_file = self.args[0]
|
||||||
return lbry_file.file_name
|
return lbry_file.file_name
|
||||||
|
|
||||||
|
|
||||||
class DeleteLBRYFileChooser(LBRYFileChooser):
|
class DeleteEncryptedFileChooser(EncryptedFileChooser):
|
||||||
#prompt_description = "Delete LBRY File"
|
#prompt_description = "Delete LBRY File"
|
||||||
|
|
||||||
def __init__(self, console, stream_info_manager, blob_manager, lbry_file_manager):
|
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,
|
stream_info_manager, blob_manager, lbry_file_manager,
|
||||||
exit_after_one_done=True)
|
exit_after_one_done=True)
|
||||||
|
|
||||||
|
|
||||||
class DeleteLBRYFileChooserFactory(CommandHandlerFactory):
|
class DeleteEncryptedFileChooserFactory(CommandHandlerFactory):
|
||||||
control_handler_class = DeleteLBRYFileChooser
|
control_handler_class = DeleteEncryptedFileChooser
|
||||||
command = "delete-lbryfile"
|
command = "delete-lbryfile"
|
||||||
short_help = "Delete an LBRY file"
|
short_help = "Delete an LBRY file"
|
||||||
full_help = "Delete an LBRY file which has been downloaded or created by this application.\n" \
|
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."
|
"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"
|
#prompt_description = "Delete LBRY File"
|
||||||
delete_data_prompt = "Also delete data? (y/n): "
|
delete_data_prompt = "Also delete data? (y/n): "
|
||||||
confirm_prompt = "Are you sure? (y/n): "
|
confirm_prompt = "Are you sure? (y/n): "
|
||||||
|
@ -1106,27 +1106,27 @@ class DeleteLBRYFile(CommandHandler):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class DeleteLBRYFileFactory(LBRYFileChooserFactory):
|
class DeleteEncryptedFileFactory(EncryptedFileChooserFactory):
|
||||||
control_handler_class = DeleteLBRYFile
|
control_handler_class = DeleteEncryptedFile
|
||||||
|
|
||||||
|
|
||||||
class ToggleLBRYFileRunningChooser(LBRYFileChooser):
|
class ToggleEncryptedFileRunningChooser(EncryptedFileChooser):
|
||||||
#prompt_description = "Toggle whether an LBRY File is running"
|
#prompt_description = "Toggle whether an LBRY File is running"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file_manager):
|
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)
|
lbry_file_manager, exit_after_one_done=True)
|
||||||
|
|
||||||
|
|
||||||
class ToggleLBRYFileRunningChooserFactory(CommandHandlerFactory):
|
class ToggleEncryptedFileRunningChooserFactory(CommandHandlerFactory):
|
||||||
control_handler_class = ToggleLBRYFileRunningChooser
|
control_handler_class = ToggleEncryptedFileRunningChooser
|
||||||
command = "toggle-running"
|
command = "toggle-running"
|
||||||
short_help = "Toggle whether an LBRY file is running"
|
short_help = "Toggle whether an LBRY file is running"
|
||||||
full_help = "Toggle whether an LBRY file, which is being saved by this application," \
|
full_help = "Toggle whether an LBRY file, which is being saved by this application," \
|
||||||
"is currently being downloaded."
|
"is currently being downloaded."
|
||||||
|
|
||||||
|
|
||||||
class ToggleLBRYFileRunning(CommandHandler):
|
class ToggleEncryptedFileRunning(CommandHandler):
|
||||||
#prompt_description = "Toggle whether an LBRY File is running"
|
#prompt_description = "Toggle whether an LBRY File is running"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file, lbry_file_manager):
|
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
|
return "An unexpected error occurred. See %s for details." % log_file
|
||||||
|
|
||||||
|
|
||||||
class ToggleLBRYFileRunningFactory(LBRYFileChooserFactory):
|
class ToggleEncryptedFileRunningFactory(EncryptedFileChooserFactory):
|
||||||
control_handler_class = ToggleLBRYFileRunning
|
control_handler_class = ToggleEncryptedFileRunning
|
||||||
|
|
||||||
|
|
||||||
class CreateLBRYFile(CommandHandler):
|
class CreateEncryptedFile(CommandHandler):
|
||||||
#prompt_description = "Create an LBRY File from file"
|
#prompt_description = "Create an LBRY File from file"
|
||||||
line_prompt = "File name: "
|
line_prompt = "File name: "
|
||||||
|
|
||||||
|
@ -1179,13 +1179,13 @@ class CreateLBRYFile(CommandHandler):
|
||||||
|
|
||||||
def set_status(self, lbry_file_downloader):
|
def set_status(self, lbry_file_downloader):
|
||||||
d = self.lbry_file_manager.change_lbry_file_status(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())
|
d.addCallback(lambda _: lbry_file_downloader.restore())
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class CreateLBRYFileFactory(CommandHandlerFactory):
|
class CreateEncryptedFileFactory(CommandHandlerFactory):
|
||||||
control_handler_class = CreateLBRYFile
|
control_handler_class = CreateEncryptedFile
|
||||||
command = "create-lbryfile"
|
command = "create-lbryfile"
|
||||||
short_help = "LBRYize a file"
|
short_help = "LBRYize a file"
|
||||||
full_help = "Encrypt a file, split it into chunks, and make those chunks available on LBRYnet. Also " \
|
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."
|
"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"
|
#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):
|
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,
|
stream_info_manager, blob_manager, lbry_file_manager,
|
||||||
exit_after_one_done=True)
|
exit_after_one_done=True)
|
||||||
|
|
||||||
|
@ -1243,15 +1243,15 @@ class PublishStreamDescriptor(CommandHandler):
|
||||||
# return d
|
# return d
|
||||||
|
|
||||||
|
|
||||||
class PublishStreamDescriptorFactory(LBRYFileChooserFactory):
|
class PublishStreamDescriptorFactory(EncryptedFileChooserFactory):
|
||||||
control_handler_class = PublishStreamDescriptor
|
control_handler_class = PublishStreamDescriptor
|
||||||
|
|
||||||
|
|
||||||
class ShowPublishedSDHashesChooser(LBRYFileChooser):
|
class ShowPublishedSDHashesChooser(EncryptedFileChooser):
|
||||||
#prompt_description = "Show published stream descriptors for an LBRY File"
|
#prompt_description = "Show published stream descriptors for an LBRY File"
|
||||||
|
|
||||||
def __init__(self, console, stream_info_manager, lbry_file_manager):
|
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)
|
stream_info_manager, lbry_file_manager)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1288,15 +1288,15 @@ class ShowPublishedSDHashes(CommandHandler):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class ShowPublishedSDHashesFactory(LBRYFileChooserFactory):
|
class ShowPublishedSDHashesFactory(EncryptedFileChooserFactory):
|
||||||
control_handler_class = ShowPublishedSDHashes
|
control_handler_class = ShowPublishedSDHashes
|
||||||
|
|
||||||
|
|
||||||
class CreatePlainStreamDescriptorChooser(LBRYFileChooser):
|
class CreatePlainStreamDescriptorChooser(EncryptedFileChooser):
|
||||||
#prompt_description = "Create a plain stream descriptor file for an LBRY File"
|
#prompt_description = "Create a plain stream descriptor file for an LBRY File"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file_manager):
|
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,
|
CreatePlainStreamDescriptorFactory, lbry_file_manager,
|
||||||
exit_after_one_done=True)
|
exit_after_one_done=True)
|
||||||
|
|
||||||
|
@ -1352,26 +1352,26 @@ class CreatePlainStreamDescriptor(CommandHandler):
|
||||||
return defer.succeed(file_name)
|
return defer.succeed(file_name)
|
||||||
|
|
||||||
|
|
||||||
class CreatePlainStreamDescriptorFactory(LBRYFileChooserFactory):
|
class CreatePlainStreamDescriptorFactory(EncryptedFileChooserFactory):
|
||||||
control_handler_class = CreatePlainStreamDescriptor
|
control_handler_class = CreatePlainStreamDescriptor
|
||||||
|
|
||||||
|
|
||||||
class ShowLBRYFileStreamHashChooser(LBRYFileChooser):
|
class ShowEncryptedFileStreamHashChooser(EncryptedFileChooser):
|
||||||
#prompt_description = "Show an LBRY File's stream hash (not usually what you want)"
|
#prompt_description = "Show an LBRY File's stream hash (not usually what you want)"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file_manager):
|
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):
|
class ShowEncryptedFileStreamHashChooserFactory(CommandHandlerFactory):
|
||||||
control_handler_class = ShowLBRYFileStreamHashChooser
|
control_handler_class = ShowEncryptedFileStreamHashChooser
|
||||||
command = "lbryfile-streamhash"
|
command = "lbryfile-streamhash"
|
||||||
short_help = "Show an LBRY file's stream hash"
|
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" \
|
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."
|
" 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)"
|
#prompt_description = "Show an LBRY File's stream hash (not usually what you want)"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file):
|
def __init__(self, console, lbry_file):
|
||||||
|
@ -1383,11 +1383,11 @@ class ShowLBRYFileStreamHash(CommandHandler):
|
||||||
self.finished_deferred.callback(None)
|
self.finished_deferred.callback(None)
|
||||||
|
|
||||||
|
|
||||||
class ShowLBRYFileStreamHashFactory(LBRYFileChooserFactory):
|
class ShowEncryptedFileStreamHashFactory(EncryptedFileChooserFactory):
|
||||||
control_handler_class = ShowLBRYFileStreamHash
|
control_handler_class = ShowEncryptedFileStreamHash
|
||||||
|
|
||||||
|
|
||||||
class ModifyLBRYFileDataPaymentRate(ModifyPaymentRate):
|
class ModifyEncryptedFileDataPaymentRate(ModifyPaymentRate):
|
||||||
prompt_description = "Modify LBRY File data payment rate"
|
prompt_description = "Modify LBRY File data payment rate"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file, lbry_file_manager):
|
def __init__(self, console, lbry_file, lbry_file_manager):
|
||||||
|
@ -1415,19 +1415,19 @@ class ModifyLBRYFileDataPaymentRate(ModifyPaymentRate):
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
class ModifyLBRYFileDataPaymentRateFactory(CommandHandlerFactory):
|
class ModifyEncryptedFileDataPaymentRateFactory(CommandHandlerFactory):
|
||||||
control_handler_class = ModifyLBRYFileDataPaymentRate
|
control_handler_class = ModifyEncryptedFileDataPaymentRate
|
||||||
|
|
||||||
|
|
||||||
class ModifyLBRYFileOptionsChooser(LBRYFileChooser):
|
class ModifyEncryptedFileOptionsChooser(EncryptedFileChooser):
|
||||||
#prompt_description = "Modify an LBRY File's options"
|
#prompt_description = "Modify an LBRY File's options"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file_manager):
|
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):
|
class ModifyEncryptedFileOptionsChooserFactory(CommandHandlerFactory):
|
||||||
control_handler_class = ModifyLBRYFileOptionsChooser
|
control_handler_class = ModifyEncryptedFileOptionsChooser
|
||||||
command = "modify-lbryfile-options"
|
command = "modify-lbryfile-options"
|
||||||
short_help = "Modify an LBRY file's options"
|
short_help = "Modify an LBRY file's options"
|
||||||
full_help = "Modify an LBRY file's options. Options include, and are limited to, " \
|
full_help = "Modify an LBRY file's options. Options include, and are limited to, " \
|
||||||
|
@ -1435,7 +1435,7 @@ class ModifyLBRYFileOptionsChooserFactory(CommandHandlerFactory):
|
||||||
"this LBRY file."
|
"this LBRY file."
|
||||||
|
|
||||||
|
|
||||||
class ModifyLBRYFileOptions(RecursiveCommandHandler):
|
class ModifyEncryptedFileOptions(RecursiveCommandHandler):
|
||||||
#prompt_description = "Modify an LBRY File's options"
|
#prompt_description = "Modify an LBRY File's options"
|
||||||
|
|
||||||
def __init__(self, console, lbry_file, lbry_file_manager):
|
def __init__(self, console, lbry_file, lbry_file_manager):
|
||||||
|
@ -1445,12 +1445,12 @@ class ModifyLBRYFileOptions(RecursiveCommandHandler):
|
||||||
|
|
||||||
def _get_control_handler_factories(self):
|
def _get_control_handler_factories(self):
|
||||||
factories = []
|
factories = []
|
||||||
factories.append(ModifyLBRYFileDataPaymentRateFactory(self.lbry_file, self.lbry_file_manager))
|
factories.append(ModifyEncryptedFileDataPaymentRateFactory(self.lbry_file, self.lbry_file_manager))
|
||||||
return factories
|
return factories
|
||||||
|
|
||||||
|
|
||||||
class ModifyLBRYFileOptionsFactory(LBRYFileChooserFactory):
|
class ModifyEncryptedFileOptionsFactory(EncryptedFileChooserFactory):
|
||||||
control_handler_class = ModifyLBRYFileOptions
|
control_handler_class = ModifyEncryptedFileOptions
|
||||||
|
|
||||||
|
|
||||||
class ClaimName(CommandHandler):
|
class ClaimName(CommandHandler):
|
||||||
|
@ -1821,7 +1821,7 @@ class Publish(CommandHandler):
|
||||||
def set_status(self, lbry_file_downloader):
|
def set_status(self, lbry_file_downloader):
|
||||||
self.lbry_file = lbry_file_downloader
|
self.lbry_file = lbry_file_downloader
|
||||||
d = self.lbry_file_manager.change_lbry_file_status(self.lbry_file,
|
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())
|
d.addCallback(lambda _: lbry_file_downloader.restore())
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -2354,7 +2354,7 @@ class PeerStatsAndSettingsChooserFactory(CommandHandlerFactory):
|
||||||
"which peers to connect to."
|
"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):
|
def __init__(self, console, lbry_file, stream_info_manager, blob_manager, lbry_file_manager):
|
||||||
CommandHandler.__init__(self, console)
|
CommandHandler.__init__(self, console)
|
||||||
self.lbry_file = lbry_file
|
self.lbry_file = lbry_file
|
||||||
|
@ -2371,11 +2371,11 @@ class LBRYFileStatusModifier(CommandHandler):
|
||||||
if self.current_handler is None:
|
if self.current_handler is None:
|
||||||
if line:
|
if line:
|
||||||
if line.lower() == 'd':
|
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.stream_info_manager, self.blob_manager,
|
||||||
self.lbry_file_manager)
|
self.lbry_file_manager)
|
||||||
elif line.lower() == 't':
|
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)
|
self.lbry_file_manager)
|
||||||
else:
|
else:
|
||||||
self.console.sendLine("Invalid selection\n")
|
self.console.sendLine("Invalid selection\n")
|
||||||
|
@ -2444,7 +2444,7 @@ class Status(CommandHandler):
|
||||||
self.console.sendLine("Invalid choice.\n")
|
self.console.sendLine("Invalid choice.\n")
|
||||||
self.finished_deferred.callback(None)
|
self.finished_deferred.callback(None)
|
||||||
return
|
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.lbry_file_manager.stream_info_manager,
|
||||||
self.blob_manager, self.lbry_file_manager)
|
self.blob_manager, self.lbry_file_manager)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from yapsy.IPlugin import IPlugin
|
from yapsy.IPlugin import IPlugin
|
||||||
|
|
||||||
|
|
||||||
class LBRYPlugin(IPlugin):
|
class Plugin(IPlugin):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
IPlugin.__init__(self)
|
IPlugin.__init__(self)
|
|
@ -18,7 +18,7 @@ def run_in_thread(fn):
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
class LBRYSettings(object):
|
class Settings(object):
|
||||||
NAME = "settings.db"
|
NAME = "settings.db"
|
||||||
def __init__(self, db_dir):
|
def __init__(self, db_dir):
|
||||||
self.db_dir = db_dir
|
self.db_dir = db_dir
|
|
@ -1,4 +1,4 @@
|
||||||
from lbrynet.lbrynet_console import LBRYPlugin
|
from lbrynet.lbrynet_console import Plugin
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from lbrynet.conf import MIN_VALUABLE_BLOB_HASH_PAYMENT_RATE, MIN_VALUABLE_BLOB_INFO_PAYMENT_RATE
|
from lbrynet.conf import MIN_VALUABLE_BLOB_HASH_PAYMENT_RATE, MIN_VALUABLE_BLOB_INFO_PAYMENT_RATE
|
||||||
from BlindRepeater import BlindRepeater
|
from BlindRepeater import BlindRepeater
|
||||||
|
@ -13,10 +13,10 @@ from ValuableBlobQueryHandler import ValuableBlobHashQueryHandlerFactory
|
||||||
from PaymentRateManager import BlindRepeaterPaymentRateManager
|
from PaymentRateManager import BlindRepeaterPaymentRateManager
|
||||||
|
|
||||||
|
|
||||||
class BlindRepeaterPlugin(LBRYPlugin.LBRYPlugin):
|
class BlindRepeaterPlugin(Plugin.Plugin):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
LBRYPlugin.LBRYPlugin.__init__(self)
|
Plugin.Plugin.__init__(self)
|
||||||
self.enabled = False
|
self.enabled = False
|
||||||
self.blind_info_manager = None
|
self.blind_info_manager = None
|
||||||
self.valuable_blob_length_query_handler = None
|
self.valuable_blob_length_query_handler = None
|
||||||
|
|
|
@ -31,19 +31,19 @@ from lbrynet.core.PaymentRateManager import NegotiatedPaymentRateManager
|
||||||
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||||
from lbrynet.core.Error import UnknownNameError, InsufficientFundsError, InvalidNameError
|
from lbrynet.core.Error import UnknownNameError, InsufficientFundsError, InvalidNameError
|
||||||
from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
|
from lbrynet.lbryfile.StreamDescriptor import EncryptedFileStreamType
|
||||||
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaverFactory, LBRYFileOpenerFactory
|
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaverFactory, EncryptedFileOpenerFactory
|
||||||
from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier
|
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
|
||||||
from lbrynet.lbrynet_daemon.LBRYUIManager import LBRYUIManager
|
from lbrynet.lbrynet_daemon.UIManager import UIManager
|
||||||
from lbrynet.lbrynet_daemon.LBRYDownloader import GetStream
|
from lbrynet.lbrynet_daemon.Downloader import GetStream
|
||||||
from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher
|
from lbrynet.lbrynet_daemon.Publisher import Publisher
|
||||||
from lbrynet.lbrynet_daemon.LBRYExchangeRateManager import ExchangeRateManager
|
from lbrynet.lbrynet_daemon.ExchangeRateManager import ExchangeRateManager
|
||||||
from lbrynet.lbrynet_daemon.Lighthouse import LighthouseClient
|
from lbrynet.lbrynet_daemon.Lighthouse import LighthouseClient
|
||||||
from lbrynet.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 log_support
|
||||||
from lbrynet.core import utils
|
from lbrynet.core import utils
|
||||||
from lbrynet.core.utils import generate_id
|
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, \
|
from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, DEFAULT_MAX_SEARCH_RESULTS, \
|
||||||
KNOWN_DHT_NODES, DEFAULT_MAX_KEY_FEE, DEFAULT_WALLET, \
|
KNOWN_DHT_NODES, DEFAULT_MAX_KEY_FEE, DEFAULT_WALLET, \
|
||||||
DEFAULT_SEARCH_TIMEOUT, DEFAULT_CACHE_TIME, DEFAULT_UI_BRANCH, \
|
DEFAULT_SEARCH_TIMEOUT, DEFAULT_CACHE_TIME, DEFAULT_UI_BRANCH, \
|
||||||
|
@ -51,11 +51,11 @@ from lbrynet.conf import MIN_BLOB_DATA_PAYMENT_RATE, DEFAULT_MAX_SEARCH_RESULTS,
|
||||||
from lbrynet.conf import DEFAULT_SD_DOWNLOAD_TIMEOUT
|
from lbrynet.conf import DEFAULT_SD_DOWNLOAD_TIMEOUT
|
||||||
from lbrynet.conf import DEFAULT_TIMEOUT
|
from lbrynet.conf import DEFAULT_TIMEOUT
|
||||||
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier, download_sd_blob, BlobStreamDescriptorReader
|
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.PTCWallet import PTCWallet
|
||||||
from lbrynet.core.LBRYWallet import LBRYcrdWallet, LBRYumWallet
|
from lbrynet.core.Wallet import LBRYcrdWallet, LBRYumWallet
|
||||||
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
|
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
|
||||||
from lbrynet.lbryfile.LBRYFileMetadataManager import DBLBRYFileMetadataManager, TempLBRYFileMetadataManager
|
from lbrynet.lbryfile.EncryptedFileMetadataManager import DBEncryptedFileMetadataManager, TempEncryptedFileMetadataManager
|
||||||
from lbrynet import reflector
|
from lbrynet import reflector
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
if os.path.isfile(lbrynet_log):
|
if os.path.isfile(lbrynet_log):
|
||||||
with open(lbrynet_log, 'r') as f:
|
with open(lbrynet_log, 'r') as f:
|
||||||
PREVIOUS_LBRYNET_LOG = len(f.read())
|
PREVIOUS_NET_LOG = len(f.read())
|
||||||
else:
|
else:
|
||||||
PREVIOUS_LBRYNET_LOG = 0
|
PREVIOUS_NET_LOG = 0
|
||||||
|
|
||||||
INITIALIZING_CODE = 'initializing'
|
INITIALIZING_CODE = 'initializing'
|
||||||
LOADING_DB_CODE = 'loading_db'
|
LOADING_DB_CODE = 'loading_db'
|
||||||
|
@ -137,7 +137,7 @@ class Parameters(object):
|
||||||
self.__dict__.update(kwargs)
|
self.__dict__.update(kwargs)
|
||||||
|
|
||||||
|
|
||||||
class LBRYDaemon(jsonrpc.JSONRPC):
|
class Daemon(jsonrpc.JSONRPC):
|
||||||
"""
|
"""
|
||||||
LBRYnet daemon, a jsonrpc interface to lbry functions
|
LBRYnet daemon, a jsonrpc interface to lbry functions
|
||||||
"""
|
"""
|
||||||
|
@ -378,9 +378,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
# self.lbrynet_connection_checker = LoopingCall(self._check_lbrynet_connection)
|
# self.lbrynet_connection_checker = LoopingCall(self._check_lbrynet_connection)
|
||||||
|
|
||||||
self.sd_identifier = StreamDescriptorIdentifier()
|
self.sd_identifier = StreamDescriptorIdentifier()
|
||||||
self.stream_info_manager = TempLBRYFileMetadataManager()
|
self.stream_info_manager = TempEncryptedFileMetadataManager()
|
||||||
self.settings = LBRYSettings(self.db_dir)
|
self.settings = Settings(self.db_dir)
|
||||||
self.lbry_ui_manager = LBRYUIManager(root)
|
self.lbry_ui_manager = UIManager(root)
|
||||||
self.blob_request_payment_rate_manager = None
|
self.blob_request_payment_rate_manager = None
|
||||||
self.lbry_file_metadata_manager = None
|
self.lbry_file_metadata_manager = None
|
||||||
self.lbry_file_manager = None
|
self.lbry_file_manager = None
|
||||||
|
@ -559,10 +559,13 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.send_heartbeat.start(60)
|
self.send_heartbeat.start(60)
|
||||||
|
|
||||||
def _send_heartbeat(self):
|
def _send_heartbeat(self):
|
||||||
log.debug('Sending heartbeat')
|
|
||||||
heartbeat = self._events.heartbeat()
|
heartbeat = self._events.heartbeat()
|
||||||
self.analytics_api.track(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):
|
def _get_platform(self):
|
||||||
r = {
|
r = {
|
||||||
"processor": platform.processor(),
|
"processor": platform.processor(),
|
||||||
|
@ -685,7 +688,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self._add_to_pending_claims(name, txid)
|
self._add_to_pending_claims(name, txid)
|
||||||
|
|
||||||
def _process_lbry_file(name, lbry_file):
|
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
|
# TODO: check for sd_hash in addition to txid
|
||||||
ready_to_start = (
|
ready_to_start = (
|
||||||
lbry_file and
|
lbry_file and
|
||||||
|
@ -805,11 +808,11 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
|
|
||||||
def _upload_log(self, log_type=None, exclude_previous=False, force=False):
|
def _upload_log(self, log_type=None, exclude_previous=False, force=False):
|
||||||
if self.upload_log or force:
|
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 os.path.isfile(lp):
|
||||||
if exclude_previous:
|
if exclude_previous:
|
||||||
f = open(lp, "r")
|
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()
|
log_contents = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
|
@ -1015,11 +1018,11 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
|
|
||||||
def _setup_lbry_file_manager(self):
|
def _setup_lbry_file_manager(self):
|
||||||
self.startup_status = STARTUP_STAGES[3]
|
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()
|
d = self.lbry_file_metadata_manager.setup()
|
||||||
|
|
||||||
def set_lbry_file_manager():
|
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.lbry_file_metadata_manager,
|
||||||
self.sd_identifier,
|
self.sd_identifier,
|
||||||
download_directory=self.download_directory)
|
download_directory=self.download_directory)
|
||||||
|
@ -1066,7 +1069,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def create_session(results):
|
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,
|
blob_dir=self.blobfile_dir, dht_node_port=self.dht_node_port,
|
||||||
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port,
|
known_dht_nodes=self.known_dht_nodes, peer_port=self.peer_port,
|
||||||
use_upnp=self.use_upnp, wallet=results['wallet'])
|
use_upnp=self.use_upnp, wallet=results['wallet'])
|
||||||
|
@ -1080,14 +1083,14 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
return dl
|
return dl
|
||||||
|
|
||||||
def _setup_stream_identifier(self):
|
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.blob_manager, self.stream_info_manager,
|
||||||
self.session.wallet, self.download_directory)
|
self.session.wallet, self.download_directory)
|
||||||
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, file_saver_factory)
|
self.sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, file_saver_factory)
|
||||||
file_opener_factory = LBRYFileOpenerFactory(self.session.peer_finder, self.session.rate_limiter,
|
file_opener_factory = EncryptedFileOpenerFactory(self.session.peer_finder, self.session.rate_limiter,
|
||||||
self.session.blob_manager, self.stream_info_manager,
|
self.session.blob_manager, self.stream_info_manager,
|
||||||
self.session.wallet)
|
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)
|
return defer.succeed(None)
|
||||||
|
|
||||||
def _download_sd_blob(self, sd_hash, timeout=DEFAULT_SD_DOWNLOAD_TIMEOUT):
|
def _download_sd_blob(self, sd_hash, timeout=DEFAULT_SD_DOWNLOAD_TIMEOUT):
|
||||||
|
@ -1114,6 +1117,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
Add a lbry file to the file manager, start the download, and return the new lbry file.
|
Add a lbry file to the file manager, start the download, and return the new lbry file.
|
||||||
If it already exists in the file manager, return the existing lbry file
|
If it already exists in the file manager, return the existing lbry file
|
||||||
"""
|
"""
|
||||||
|
self._send_download_started(name)
|
||||||
helper = _DownloadNameHelper(
|
helper = _DownloadNameHelper(
|
||||||
self, name, timeout, download_directory, file_name, wait_for_write)
|
self, name, timeout, download_directory, file_name, wait_for_write)
|
||||||
|
|
||||||
|
@ -1160,7 +1164,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
force_refresh: if True, always go out to the blockchain to resolve.
|
force_refresh: if True, always go out to the blockchain to resolve.
|
||||||
"""
|
"""
|
||||||
if name.startswith('lbry://'):
|
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)
|
helper = _ResolveNameHelper(self, name, force_refresh)
|
||||||
return helper.get_deferred()
|
return helper.get_deferred()
|
||||||
|
|
||||||
|
@ -2648,16 +2652,14 @@ class _DownloadNameHelper(object):
|
||||||
def _setup_stream(self, stream_info):
|
def _setup_stream(self, stream_info):
|
||||||
stream_hash = get_sd_hash(stream_info)
|
stream_hash = get_sd_hash(stream_info)
|
||||||
d = self.daemon._get_lbry_file_by_sd_hash(stream_hash)
|
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
|
return d
|
||||||
|
|
||||||
def _add_results_callback(self, stream_info):
|
def _prepend_stream_info(self, lbry_file, stream_info):
|
||||||
def add_results(l):
|
if lbry_file:
|
||||||
if l:
|
if os.path.isfile(os.path.join(self.download_directory, lbry_file.file_name)):
|
||||||
if os.path.isfile(os.path.join(self.download_directory, l.file_name)):
|
return defer.succeed((stream_info, lbry_file))
|
||||||
return defer.succeed((stream_info, l))
|
|
||||||
return defer.succeed((stream_info, None))
|
return defer.succeed((stream_info, None))
|
||||||
return add_results
|
|
||||||
|
|
||||||
def wait_or_get_stream(self, args):
|
def wait_or_get_stream(self, args):
|
||||||
stream_info, lbry_file = args
|
stream_info, lbry_file = args
|
|
@ -12,7 +12,7 @@ from twisted.internet import reactor, defer
|
||||||
from jsonrpc.proxy import JSONRPCProxy
|
from jsonrpc.proxy import JSONRPCProxy
|
||||||
|
|
||||||
from lbrynet.core import log_support
|
from lbrynet.core import log_support
|
||||||
from lbrynet.lbrynet_daemon.LBRYDaemonServer import LBRYDaemonServer, LBRYDaemonRequest
|
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer, DaemonRequest
|
||||||
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_PORT, \
|
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_PORT, \
|
||||||
UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
||||||
|
|
||||||
|
@ -73,6 +73,8 @@ def start():
|
||||||
parser.add_argument('--no-launch', dest='launchui', action="store_false")
|
parser.add_argument('--no-launch', dest='launchui', action="store_false")
|
||||||
parser.add_argument('--log-to-console', dest='logtoconsole', action="store_true")
|
parser.add_argument('--log-to-console', dest='logtoconsole', action="store_true")
|
||||||
parser.add_argument('--quiet', dest='quiet', 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)
|
parser.set_defaults(branch=False, launchui=True, logtoconsole=False, quiet=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -81,6 +83,7 @@ def start():
|
||||||
if args.logtoconsole:
|
if args.logtoconsole:
|
||||||
log_support.configure_console(level='DEBUG')
|
log_support.configure_console(level='DEBUG')
|
||||||
log_support.disable_third_party_loggers()
|
log_support.disable_third_party_loggers()
|
||||||
|
if not args.verbose:
|
||||||
log_support.disable_noisy_loggers()
|
log_support.disable_noisy_loggers()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -104,7 +107,7 @@ def start():
|
||||||
print "To quit press ctrl-c or call 'stop' via the API"
|
print "To quit press ctrl-c or call 'stop' via the API"
|
||||||
|
|
||||||
if test_internet_connection():
|
if test_internet_connection():
|
||||||
lbry = LBRYDaemonServer()
|
lbry = DaemonServer()
|
||||||
|
|
||||||
d = lbry.start(branch=args.branch if args.branch else DEFAULT_UI_BRANCH,
|
d = lbry.start(branch=args.branch if args.branch else DEFAULT_UI_BRANCH,
|
||||||
user_specified=args.ui,
|
user_specified=args.ui,
|
||||||
|
@ -114,7 +117,7 @@ def start():
|
||||||
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
||||||
|
|
||||||
lbrynet_server = server.Site(lbry.root)
|
lbrynet_server = server.Site(lbry.root)
|
||||||
lbrynet_server.requestFactory = LBRYDaemonRequest
|
lbrynet_server.requestFactory = DaemonRequest
|
||||||
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
|
reactor.listenTCP(API_PORT, lbrynet_server, interface=API_INTERFACE)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
|
@ -15,11 +15,11 @@ from twisted.internet import defer, interfaces, error, reactor, threads
|
||||||
|
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
|
|
||||||
from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon
|
from lbrynet.lbrynet_daemon.Daemon import Daemon
|
||||||
from lbrynet.conf import API_ADDRESS, UI_ADDRESS, DEFAULT_UI_BRANCH, LOG_FILE_NAME
|
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":
|
if sys.platform != "darwin":
|
||||||
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
data_dir = os.path.join(os.path.expanduser("~"), ".lbrynet")
|
||||||
else:
|
else:
|
||||||
|
@ -31,7 +31,7 @@ lbrynet_log = os.path.join(data_dir, LOG_FILE_NAME)
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LBRYDaemonRequest(server.Request):
|
class DaemonRequest(server.Request):
|
||||||
"""
|
"""
|
||||||
For LBRY specific request functionality. Currently just provides
|
For LBRY specific request functionality. Currently just provides
|
||||||
handling for large multipart POST requests, taken from here:
|
handling for large multipart POST requests, taken from here:
|
||||||
|
@ -231,7 +231,7 @@ class LBRYindex(resource.Resource):
|
||||||
return static.File(os.path.join(self.ui_dir, "index.html")).render_GET(request)
|
return static.File(os.path.join(self.ui_dir, "index.html")).render_GET(request)
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileStreamer(object):
|
class EncryptedFileStreamer(object):
|
||||||
"""
|
"""
|
||||||
Writes downloaded LBRY file to request as the download comes in, pausing and resuming as requested
|
Writes downloaded LBRY file to request as the download comes in, pausing and resuming as requested
|
||||||
used for Chrome
|
used for Chrome
|
||||||
|
@ -315,13 +315,13 @@ class LBRYFileStreamer(object):
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
|
|
||||||
class HostedLBRYFile(resource.Resource):
|
class HostedEncryptedFile(resource.Resource):
|
||||||
def __init__(self, api):
|
def __init__(self, api):
|
||||||
self._api = api
|
self._api = api
|
||||||
self._producer = None
|
self._producer = None
|
||||||
resource.Resource.__init__(self)
|
resource.Resource.__init__(self)
|
||||||
|
|
||||||
# todo: fix LBRYFileStreamer and use it instead of static.File
|
# todo: fix EncryptedFileStreamer and use it instead of static.File
|
||||||
# def makeProducer(self, request, stream):
|
# def makeProducer(self, request, stream):
|
||||||
# def _save_producer(producer):
|
# def _save_producer(producer):
|
||||||
# self._producer = producer
|
# self._producer = producer
|
||||||
|
@ -333,7 +333,7 @@ class HostedLBRYFile(resource.Resource):
|
||||||
# path = os.path.join(self._api.download_directory, stream.file_name)
|
# path = os.path.join(self._api.download_directory, stream.file_name)
|
||||||
#
|
#
|
||||||
# d = stream.get_total_bytes()
|
# d = stream.get_total_bytes()
|
||||||
# d.addCallback(lambda size: _save_producer(LBRYFileStreamer(request, path, start, stop, size)))
|
# d.addCallback(lambda size: _save_producer(EncryptedFileStreamer(request, path, start, stop, size)))
|
||||||
# d.addCallback(lambda _: request.registerProducer(self._producer, streaming=True))
|
# d.addCallback(lambda _: request.registerProducer(self._producer, streaming=True))
|
||||||
# # request.notifyFinish().addCallback(lambda _: self._producer.stopProducing())
|
# # request.notifyFinish().addCallback(lambda _: self._producer.stopProducing())
|
||||||
# request.notifyFinish().addErrback(self._responseFailed, d)
|
# request.notifyFinish().addErrback(self._responseFailed, d)
|
||||||
|
@ -362,7 +362,7 @@ class HostedLBRYFile(resource.Resource):
|
||||||
# call.addErrback(lambda err: log.info("Error: " + str(err)))
|
# call.addErrback(lambda err: log.info("Error: " + str(err)))
|
||||||
# call.cancel()
|
# call.cancel()
|
||||||
|
|
||||||
class LBRYFileUpload(resource.Resource):
|
class EncryptedFileUpload(resource.Resource):
|
||||||
"""
|
"""
|
||||||
Accepts a file sent via the file upload widget in the web UI, saves
|
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
|
it into a temporary dir, and responds with a JSON string containing
|
||||||
|
@ -401,12 +401,12 @@ class LBRYFileUpload(resource.Resource):
|
||||||
return json.dumps(newpath)
|
return json.dumps(newpath)
|
||||||
|
|
||||||
|
|
||||||
class LBRYDaemonServer(object):
|
class DaemonServer(object):
|
||||||
def _setup_server(self, wallet):
|
def _setup_server(self, wallet):
|
||||||
self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active"))
|
self.root = LBRYindex(os.path.join(os.path.join(data_dir, "lbry-ui"), "active"))
|
||||||
self._api = LBRYDaemon(self.root, wallet_type=wallet)
|
self._api = Daemon(self.root, wallet_type=wallet)
|
||||||
self.root.putChild("view", HostedLBRYFile(self._api))
|
self.root.putChild("view", HostedEncryptedFile(self._api))
|
||||||
self.root.putChild("upload", LBRYFileUpload(self._api))
|
self.root.putChild("upload", EncryptedFileUpload(self._api))
|
||||||
self.root.putChild(API_ADDRESS, self._api)
|
self.root.putChild(API_ADDRESS, self._api)
|
||||||
return defer.succeed(True)
|
return defer.succeed(True)
|
||||||
|
|
|
@ -10,8 +10,8 @@ from twisted.internet.task import LoopingCall
|
||||||
|
|
||||||
from lbrynet.core.Error import InsufficientFundsError, KeyFeeAboveMaxAllowed
|
from lbrynet.core.Error import InsufficientFundsError, KeyFeeAboveMaxAllowed
|
||||||
from lbrynet.core.StreamDescriptor import download_sd_blob
|
from lbrynet.core.StreamDescriptor import download_sd_blob
|
||||||
from lbrynet.metadata.LBRYFee import LBRYFeeValidator
|
from lbrynet.metadata.Fee import FeeValidator
|
||||||
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloaderFactory
|
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory
|
||||||
from lbrynet.conf import DEFAULT_TIMEOUT, LOG_FILE_NAME
|
from lbrynet.conf import DEFAULT_TIMEOUT, LOG_FILE_NAME
|
||||||
|
|
||||||
INITIALIZING_CODE = 'initializing'
|
INITIALIZING_CODE = 'initializing'
|
||||||
|
@ -85,7 +85,7 @@ class GetStream(object):
|
||||||
|
|
||||||
def _convert_max_fee(self):
|
def _convert_max_fee(self):
|
||||||
if isinstance(self.max_key_fee, dict):
|
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":
|
if max_fee.currency_symbol == "LBC":
|
||||||
return max_fee.amount
|
return max_fee.amount
|
||||||
return self.exchange_rate_manager.to_lbc(self.fee).amount
|
return self.exchange_rate_manager.to_lbc(self.fee).amount
|
||||||
|
@ -104,7 +104,7 @@ class GetStream(object):
|
||||||
|
|
||||||
def get_downloader_factory(metadata):
|
def get_downloader_factory(metadata):
|
||||||
for factory in metadata.factories:
|
for factory in metadata.factories:
|
||||||
if isinstance(factory, ManagedLBRYFileDownloaderFactory):
|
if isinstance(factory, ManagedEncryptedFileDownloaderFactory):
|
||||||
return factory, metadata
|
return factory, metadata
|
||||||
raise Exception('No suitable factory was found in {}'.format(metadata.factories))
|
raise Exception('No suitable factory was found in {}'.format(metadata.factories))
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ class GetStream(object):
|
||||||
self.stream_hash = self.stream_info['sources']['lbry_sd_hash']
|
self.stream_hash = self.stream_info['sources']['lbry_sd_hash']
|
||||||
|
|
||||||
if 'fee' in self.stream_info:
|
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()
|
max_key_fee = self._convert_max_fee()
|
||||||
if self.exchange_rate_manager.to_lbc(self.fee).amount > max_key_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,
|
log.info("Key fee %f above limit of %f didn't download lbry://%s" % (self.fee.amount,
|
|
@ -6,7 +6,7 @@ import googlefinance
|
||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer, reactor
|
||||||
from twisted.internet.task import LoopingCall
|
from twisted.internet.task import LoopingCall
|
||||||
|
|
||||||
from lbrynet.metadata.LBRYFee import LBRYFeeValidator
|
from lbrynet.metadata.Fee import FeeValidator
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -161,12 +161,12 @@ class ExchangeRateManager(object):
|
||||||
def to_lbc(self, fee):
|
def to_lbc(self, fee):
|
||||||
if fee is None:
|
if fee is None:
|
||||||
return None
|
return None
|
||||||
if not isinstance(fee, LBRYFeeValidator):
|
if not isinstance(fee, FeeValidator):
|
||||||
fee_in = LBRYFeeValidator(fee)
|
fee_in = FeeValidator(fee)
|
||||||
else:
|
else:
|
||||||
fee_in = fee
|
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),
|
'amount': self.convert_currency(fee_in.currency_symbol, "LBC", fee_in.amount),
|
||||||
'address': fee_in.address
|
'address': fee_in.address
|
||||||
|
@ -216,12 +216,12 @@ class DummyExchangeRateManager(object):
|
||||||
def to_lbc(self, fee):
|
def to_lbc(self, fee):
|
||||||
if fee is None:
|
if fee is None:
|
||||||
return None
|
return None
|
||||||
if not isinstance(fee, LBRYFeeValidator):
|
if not isinstance(fee, FeeValidator):
|
||||||
fee_in = LBRYFeeValidator(fee)
|
fee_in = FeeValidator(fee)
|
||||||
else:
|
else:
|
||||||
fee_in = fee
|
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),
|
'amount': self.convert_currency(fee_in.currency_symbol, "LBC", fee_in.amount),
|
||||||
'address': fee_in.address
|
'address': fee_in.address
|
|
@ -7,10 +7,10 @@ import random
|
||||||
from appdirs import user_data_dir
|
from appdirs import user_data_dir
|
||||||
|
|
||||||
from lbrynet.core.Error import InsufficientFundsError
|
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.lbryfile.StreamDescriptor import publish_sd_blob
|
||||||
from lbrynet.metadata.LBRYMetadata import Metadata
|
from lbrynet.metadata.Metadata import Metadata
|
||||||
from lbrynet.lbryfilemanager.LBRYFileDownloader import ManagedLBRYFileDownloader
|
from lbrynet.lbryfilemanager.EncryptedFileDownloader import ManagedEncryptedFileDownloader
|
||||||
from lbrynet import reflector
|
from lbrynet import reflector
|
||||||
from lbrynet.conf import LOG_FILE_NAME, REFLECTOR_SERVERS
|
from lbrynet.conf import LOG_FILE_NAME, REFLECTOR_SERVERS
|
||||||
from twisted.internet import threads, defer, reactor
|
from twisted.internet import threads, defer, reactor
|
||||||
|
@ -123,7 +123,7 @@ class Publisher(object):
|
||||||
|
|
||||||
def set_status(self):
|
def set_status(self):
|
||||||
log.debug('Setting status')
|
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())
|
d.addCallback(lambda _: self.lbry_file.restore())
|
||||||
return d
|
return d
|
||||||
|
|
|
@ -27,7 +27,7 @@ lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME)
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LBRYUIManager(object):
|
class UIManager(object):
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
if sys.platform != "darwin":
|
if sys.platform != "darwin":
|
||||||
self.data_dir = os.path.join(os.path.expanduser("~"), '.lbrynet')
|
self.data_dir = os.path.join(os.path.expanduser("~"), '.lbrynet')
|
|
@ -80,7 +80,7 @@ class USDFeeValidator(Validator):
|
||||||
Validator.__init__(self, fee)
|
Validator.__init__(self, fee)
|
||||||
|
|
||||||
|
|
||||||
class LBRYFeeValidator(Validator):
|
class FeeValidator(Validator):
|
||||||
CV001 = "0.0.1"
|
CV001 = "0.0.1"
|
||||||
CURRENT_CURRENCY_VERSION = CV001
|
CURRENT_CURRENCY_VERSION = CV001
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from lbrynet.metadata.Validator import Validator, skip_validate
|
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
|
from lbrynet.conf import SOURCE_TYPES
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -83,4 +83,4 @@ class Metadata(Validator):
|
||||||
|
|
||||||
def _load_fee(self):
|
def _load_fee(self):
|
||||||
if 'fee' in self:
|
if 'fee' in self:
|
||||||
self.update({'fee': LBRYFeeValidator(self['fee'])})
|
self.update({'fee': FeeValidator(self['fee'])})
|
|
@ -1,3 +1,3 @@
|
||||||
from lbrynet.reflector.server.server import ReflectorServerFactory as ServerFactory
|
from lbrynet.reflector.server.server import ReflectorServerFactory as ServerFactory
|
||||||
from lbrynet.reflector.client.client import LBRYFileReflectorClientFactory as ClientFactory
|
from lbrynet.reflector.client.client import EncryptedFileReflectorClientFactory as ClientFactory
|
||||||
from lbrynet.reflector.client.client import LBRYBlobReflectorClientFactory as BlobClientFactory
|
from lbrynet.reflector.client.client import BlobReflectorClientFactory as BlobClientFactory
|
||||||
|
|
|
@ -61,7 +61,7 @@ class IncompleteResponseError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileReflectorClient(Protocol):
|
class EncryptedFileReflectorClient(Protocol):
|
||||||
|
|
||||||
# Protocol stuff
|
# Protocol stuff
|
||||||
|
|
||||||
|
@ -238,8 +238,8 @@ class LBRYFileReflectorClient(Protocol):
|
||||||
self.transport.loseConnection()
|
self.transport.loseConnection()
|
||||||
|
|
||||||
|
|
||||||
class LBRYFileReflectorClientFactory(ClientFactory):
|
class EncryptedFileReflectorClientFactory(ClientFactory):
|
||||||
protocol = LBRYFileReflectorClient
|
protocol = EncryptedFileReflectorClient
|
||||||
|
|
||||||
def __init__(self, blob_manager, stream_info_manager, stream_hash):
|
def __init__(self, blob_manager, stream_info_manager, stream_hash):
|
||||||
self.blob_manager = blob_manager
|
self.blob_manager = blob_manager
|
||||||
|
@ -269,7 +269,7 @@ class LBRYFileReflectorClientFactory(ClientFactory):
|
||||||
log.debug("connection failed: %s", reason)
|
log.debug("connection failed: %s", reason)
|
||||||
|
|
||||||
|
|
||||||
class LBRYBlobReflectorClient(Protocol):
|
class BlobReflectorClient(Protocol):
|
||||||
# Protocol stuff
|
# Protocol stuff
|
||||||
|
|
||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
|
@ -424,8 +424,8 @@ class LBRYBlobReflectorClient(Protocol):
|
||||||
self.transport.loseConnection()
|
self.transport.loseConnection()
|
||||||
|
|
||||||
|
|
||||||
class LBRYBlobReflectorClientFactory(ClientFactory):
|
class BlobReflectorClientFactory(ClientFactory):
|
||||||
protocol = LBRYBlobReflectorClient
|
protocol = BlobReflectorClient
|
||||||
|
|
||||||
def __init__(self, blob_manager, blobs):
|
def __init__(self, blob_manager, blobs):
|
||||||
self.blob_manager = blob_manager
|
self.blob_manager = blob_manager
|
||||||
|
|
95
packaging/windows/init.ps1
Normal file
95
packaging/windows/init.ps1
Normal 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
|
15
packaging/windows/install.ps1
Normal file
15
packaging/windows/install.ps1
Normal 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
|
||||||
|
}
|
4
packaging/windows/test.ps1
Normal file
4
packaging/windows/test.ps1
Normal 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
|
||||||
|
|
10
setup.py
10
setup.py
|
@ -57,9 +57,9 @@ console_scripts = [
|
||||||
# 'lbrynet-rpc-node-cli = lbrynet.node_rpc_cli:main',
|
# 'lbrynet-rpc-node-cli = lbrynet.node_rpc_cli:main',
|
||||||
# 'lbrynet-lookup-hosts-for-hash = lbrynet.dht_scripts:get_hosts_for_hash_in_dht',
|
# '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-announce_hash_to_dht = lbrynet.dht_scripts:announce_hash_to_dht',
|
||||||
'lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:start',
|
'lbrynet-daemon = lbrynet.lbrynet_daemon.DaemonControl:start',
|
||||||
'stop-lbrynet-daemon = lbrynet.lbrynet_daemon.LBRYDaemonControl:stop',
|
'stop-lbrynet-daemon = lbrynet.lbrynet_daemon.DaemonControl:stop',
|
||||||
'lbrynet-cli = lbrynet.lbrynet_daemon.LBRYDaemonCLI:main'
|
'lbrynet-cli = lbrynet.lbrynet_daemon.DaemonCLI:main'
|
||||||
]
|
]
|
||||||
|
|
||||||
if platform == LINUX:
|
if platform == LINUX:
|
||||||
|
@ -303,7 +303,7 @@ elif platform == WINDOWS:
|
||||||
)
|
)
|
||||||
|
|
||||||
daemon_exe = Executable(
|
daemon_exe = Executable(
|
||||||
script=os.path.join(daemon_dir, 'LBRYDaemonControl.py'),
|
script=os.path.join(daemon_dir, 'DaemonControl.py'),
|
||||||
icon=win_icon,
|
icon=win_icon,
|
||||||
# shortcutName="lbrynet-daemon",
|
# shortcutName="lbrynet-daemon",
|
||||||
# shortcutDir='DesktopFolder',
|
# shortcutDir='DesktopFolder',
|
||||||
|
@ -311,7 +311,7 @@ elif platform == WINDOWS:
|
||||||
)
|
)
|
||||||
|
|
||||||
cli_exe = Executable(
|
cli_exe = Executable(
|
||||||
script=os.path.join(daemon_dir, 'LBRYDaemonCLI.py'),
|
script=os.path.join(daemon_dir, 'DaemonCLI.py'),
|
||||||
icon=win_icon,
|
icon=win_icon,
|
||||||
# shortcutName="lbrynet-cli",
|
# shortcutName="lbrynet-cli",
|
||||||
# shortcutDir='DesktopFolder',
|
# shortcutDir='DesktopFolder',
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import shutil
|
import shutil
|
||||||
from multiprocessing import Process, Event, Queue
|
from multiprocessing import Process, Event, Queue
|
||||||
import logging
|
import logging
|
||||||
|
import platform
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
import io
|
import io
|
||||||
|
@ -16,17 +17,17 @@ from lbrynet.lbrylive.PaymentRateManager import BaseLiveStreamPaymentRateManager
|
||||||
from lbrynet.lbrylive.PaymentRateManager import LiveStreamPaymentRateManager
|
from lbrynet.lbrylive.PaymentRateManager import LiveStreamPaymentRateManager
|
||||||
from lbrynet.lbrylive.LiveStreamMetadataManager import DBLiveStreamMetadataManager
|
from lbrynet.lbrylive.LiveStreamMetadataManager import DBLiveStreamMetadataManager
|
||||||
from lbrynet.lbrylive.LiveStreamMetadataManager import TempLiveStreamMetadataManager
|
from lbrynet.lbrylive.LiveStreamMetadataManager import TempLiveStreamMetadataManager
|
||||||
from lbrynet.lbryfile.LBRYFileMetadataManager import TempLBRYFileMetadataManager, DBLBRYFileMetadataManager
|
from lbrynet.lbryfile.EncryptedFileMetadataManager import TempEncryptedFileMetadataManager, DBEncryptedFileMetadataManager
|
||||||
from lbrynet.lbryfilemanager.LBRYFileManager import LBRYFileManager
|
from lbrynet.lbryfilemanager.EncryptedFileManager import EncryptedFileManager
|
||||||
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
||||||
from lbrynet.core.PTCWallet import PointTraderKeyQueryHandlerFactory, PointTraderKeyExchanger
|
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.client.StandaloneBlobDownloader import StandaloneBlobDownloader
|
||||||
from lbrynet.core.StreamDescriptor import BlobStreamDescriptorWriter
|
from lbrynet.core.StreamDescriptor import BlobStreamDescriptorWriter
|
||||||
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier
|
from lbrynet.core.StreamDescriptor import StreamDescriptorIdentifier
|
||||||
from lbrynet.core.StreamDescriptor import download_sd_blob
|
from lbrynet.core.StreamDescriptor import download_sd_blob
|
||||||
from lbrynet.lbryfilemanager.LBRYFileCreator import create_lbry_file
|
from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file
|
||||||
from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier
|
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
|
||||||
from lbrynet.lbryfile.StreamDescriptor import get_sd_info
|
from lbrynet.lbryfile.StreamDescriptor import get_sd_info
|
||||||
from twisted.internet import defer, threads, task, error
|
from twisted.internet import defer, threads, task, error
|
||||||
from twisted.trial.unittest import TestCase
|
from twisted.trial.unittest import TestCase
|
||||||
|
@ -41,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.LiveStreamOptions import add_live_stream_to_sd_identifier
|
||||||
from lbrynet.lbrylive.client.LiveStreamDownloader import add_full_live_stream_downloader_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.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.reflector.server.server import ReflectorServerFactory
|
||||||
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
|
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
|
||||||
|
|
||||||
|
@ -50,6 +51,15 @@ log_format = "%(funcName)s(): %(message)s"
|
||||||
logging.basicConfig(level=logging.WARNING, format=log_format)
|
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):
|
class FakeNode(object):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
@ -232,13 +242,13 @@ def start_lbry_uploader(sd_hash_queue, kill_event, dead_event, file_size, ul_rat
|
||||||
db_dir = "server"
|
db_dir = "server"
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
|
|
||||||
session = 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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
||||||
|
|
||||||
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:
|
if ul_rate_limit is not None:
|
||||||
session.rate_limiter.set_ul_limit(ul_rate_limit)
|
session.rate_limiter.set_ul_limit(ul_rate_limit)
|
||||||
|
@ -349,14 +359,14 @@ def start_lbry_reuploader(sd_hash, kill_event, dead_event, ready_event, n, ul_ra
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
os.mkdir(blob_dir)
|
os.mkdir(blob_dir)
|
||||||
|
|
||||||
session = 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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer,
|
||||||
blob_dir=None, peer_port=peer_port,
|
blob_dir=None, peer_port=peer_port,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
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:
|
if ul_rate_limit is not None:
|
||||||
session.rate_limiter.set_ul_limit(ul_rate_limit)
|
session.rate_limiter.set_ul_limit(ul_rate_limit)
|
||||||
|
@ -463,7 +473,7 @@ def start_live_server(sd_hash_queue, kill_event, dead_event):
|
||||||
db_dir = "server"
|
db_dir = "server"
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
|
|
||||||
session = 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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
||||||
|
|
||||||
|
@ -608,7 +618,7 @@ def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow):
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
os.mkdir(blob_dir)
|
os.mkdir(blob_dir)
|
||||||
|
|
||||||
session = 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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer,
|
||||||
blob_dir=blob_dir, peer_port=peer_port,
|
blob_dir=blob_dir, peer_port=peer_port,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
||||||
|
@ -781,14 +791,14 @@ class TestTransfer(TestCase):
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
os.mkdir(blob_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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer,
|
||||||
blob_dir=blob_dir, peer_port=5553,
|
blob_dir=blob_dir, peer_port=5553,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
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):
|
def make_downloader(metadata, prm):
|
||||||
info_validator = metadata.validator
|
info_validator = metadata.validator
|
||||||
|
@ -845,6 +855,7 @@ class TestTransfer(TestCase):
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@require_system('Linux')
|
||||||
def test_live_transfer(self):
|
def test_live_transfer(self):
|
||||||
|
|
||||||
sd_hash_queue = Queue()
|
sd_hash_queue = Queue()
|
||||||
|
@ -865,7 +876,7 @@ class TestTransfer(TestCase):
|
||||||
db_dir = "client"
|
db_dir = "client"
|
||||||
os.mkdir(db_dir)
|
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_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=None,
|
||||||
peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
||||||
|
|
||||||
|
@ -940,6 +951,7 @@ class TestTransfer(TestCase):
|
||||||
d.addBoth(stop)
|
d.addBoth(stop)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@require_system('Linux')
|
||||||
def test_last_blob_retrieval(self):
|
def test_last_blob_retrieval(self):
|
||||||
|
|
||||||
kill_event = Event()
|
kill_event = Event()
|
||||||
|
@ -969,7 +981,7 @@ class TestTransfer(TestCase):
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
os.mkdir(blob_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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer,
|
||||||
blob_dir=blob_dir, peer_port=5553,
|
blob_dir=blob_dir, peer_port=5553,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
||||||
|
@ -1049,14 +1061,14 @@ class TestTransfer(TestCase):
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
os.mkdir(blob_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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer,
|
||||||
blob_dir=blob_dir, peer_port=5553, use_upnp=False,
|
blob_dir=blob_dir, peer_port=5553, use_upnp=False,
|
||||||
rate_limiter=rate_limiter, wallet=wallet)
|
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):
|
def make_downloader(metadata, prm):
|
||||||
info_validator = metadata.validator
|
info_validator = metadata.validator
|
||||||
|
@ -1165,14 +1177,14 @@ class TestTransfer(TestCase):
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
os.mkdir(blob_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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer,
|
||||||
blob_dir=None, peer_port=5553,
|
blob_dir=None, peer_port=5553,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
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):
|
def start_additional_uploaders(sd_hash):
|
||||||
for i in range(1, num_uploaders):
|
for i in range(1, num_uploaders):
|
||||||
|
@ -1283,14 +1295,14 @@ class TestStreamify(TestCase):
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
os.mkdir(blob_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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer,
|
||||||
blob_dir=blob_dir, peer_port=5553,
|
blob_dir=blob_dir, peer_port=5553,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
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 = self.session.setup()
|
||||||
d.addCallback(lambda _: self.stream_info_manager.setup())
|
d.addCallback(lambda _: self.stream_info_manager.setup())
|
||||||
|
@ -1335,14 +1347,14 @@ class TestStreamify(TestCase):
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
os.mkdir(blob_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,
|
peer_finder=peer_finder, hash_announcer=hash_announcer,
|
||||||
blob_dir=blob_dir, peer_port=5553,
|
blob_dir=blob_dir, peer_port=5553,
|
||||||
use_upnp=False, rate_limiter=rate_limiter, wallet=wallet)
|
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):
|
def start_lbry_file(lbry_file):
|
||||||
logging.debug("Calling lbry_file.start()")
|
logging.debug("Calling lbry_file.start()")
|
||||||
|
|
|
@ -12,10 +12,10 @@ from lbrynet.core import PeerManager
|
||||||
from lbrynet.core import RateLimiter
|
from lbrynet.core import RateLimiter
|
||||||
from lbrynet.core import Session
|
from lbrynet.core import Session
|
||||||
from lbrynet.core import StreamDescriptor
|
from lbrynet.core import StreamDescriptor
|
||||||
from lbrynet.lbryfile import LBRYFileMetadataManager
|
from lbrynet.lbryfile import EncryptedFileMetadataManager
|
||||||
from lbrynet.lbryfile.client import LBRYFileOptions
|
from lbrynet.lbryfile.client import EncryptedFileOptions
|
||||||
from lbrynet.lbryfilemanager import LBRYFileCreator
|
from lbrynet.lbryfilemanager import EncryptedFileCreator
|
||||||
from lbrynet.lbryfilemanager import LBRYFileManager
|
from lbrynet.lbryfilemanager import EncryptedFileManager
|
||||||
|
|
||||||
from tests import mocks
|
from tests import mocks
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class TestReflector(unittest.TestCase):
|
||||||
db_dir = "client"
|
db_dir = "client"
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
|
|
||||||
self.session = Session.LBRYSession(
|
self.session = Session.Session(
|
||||||
conf.MIN_BLOB_DATA_PAYMENT_RATE,
|
conf.MIN_BLOB_DATA_PAYMENT_RATE,
|
||||||
db_dir=db_dir,
|
db_dir=db_dir,
|
||||||
lbryid="abcd",
|
lbryid="abcd",
|
||||||
|
@ -94,16 +94,16 @@ class TestReflector(unittest.TestCase):
|
||||||
wallet=wallet
|
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.session, self.stream_info_manager, sd_identifier)
|
||||||
|
|
||||||
self.server_blob_manager = BlobManager.TempBlobManager(hash_announcer)
|
self.server_blob_manager = BlobManager.TempBlobManager(hash_announcer)
|
||||||
|
|
||||||
d = self.session.setup()
|
d = self.session.setup()
|
||||||
d.addCallback(lambda _: self.stream_info_manager.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.lbry_file_manager.setup())
|
||||||
d.addCallback(lambda _: self.server_blob_manager.setup())
|
d.addCallback(lambda _: self.server_blob_manager.setup())
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ class TestReflector(unittest.TestCase):
|
||||||
|
|
||||||
def create_stream():
|
def create_stream():
|
||||||
test_file = mocks.GenFile(5209343, b''.join([chr(i + 3) for i in xrange(0, 64, 6)]))
|
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.session,
|
||||||
self.lbry_file_manager,
|
self.lbry_file_manager,
|
||||||
"test_file",
|
"test_file",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import mock
|
import mock
|
||||||
from lbrynet.metadata import LBRYMetadata
|
from lbrynet.metadata import Metadata
|
||||||
from lbrynet.lbrynet_daemon import LBRYExchangeRateManager
|
from lbrynet.lbrynet_daemon import ExchangeRateManager
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
|
|
||||||
class LBRYFeeFormatTest(unittest.TestCase):
|
class FeeFormatTest(unittest.TestCase):
|
||||||
def test_fee_created_with_correct_inputs(self):
|
def test_fee_created_with_correct_inputs(self):
|
||||||
fee_dict = {
|
fee_dict = {
|
||||||
'USD': {
|
'USD': {
|
||||||
|
@ -13,11 +13,11 @@ class LBRYFeeFormatTest(unittest.TestCase):
|
||||||
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fee = LBRYMetadata.LBRYFeeValidator(fee_dict)
|
fee = Metadata.FeeValidator(fee_dict)
|
||||||
self.assertEqual(10.0, fee['USD']['amount'])
|
self.assertEqual(10.0, fee['USD']['amount'])
|
||||||
|
|
||||||
|
|
||||||
class LBRYFeeTest(unittest.TestCase):
|
class FeeTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
patcher = mock.patch('time.time')
|
patcher = mock.patch('time.time')
|
||||||
self.time = patcher.start()
|
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}}
|
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)
|
self.assertEqual(60.0, manager.to_lbc(fee_dict).amount)
|
|
@ -1,4 +1,4 @@
|
||||||
from lbrynet.metadata import LBRYMetadata
|
from lbrynet.metadata import Metadata
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
def test_assertion_if_no_metadata(self):
|
def test_assertion_if_no_metadata(self):
|
||||||
metadata = {}
|
metadata = {}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
LBRYMetadata.Metadata(metadata)
|
Metadata.Metadata(metadata)
|
||||||
|
|
||||||
def test_assertion_if_source_is_missing(self):
|
def test_assertion_if_source_is_missing(self):
|
||||||
metadata = {
|
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',
|
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
||||||
}
|
}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
LBRYMetadata.Metadata(metadata)
|
Metadata.Metadata(metadata)
|
||||||
|
|
||||||
def test_metadata_works_without_fee(self):
|
def test_metadata_works_without_fee(self):
|
||||||
metadata = {
|
metadata = {
|
||||||
|
@ -33,7 +33,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
'content-type': 'audio/mpeg',
|
'content-type': 'audio/mpeg',
|
||||||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
'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)
|
self.assertFalse('fee' in m)
|
||||||
|
|
||||||
def test_assertion_if_invalid_source(self):
|
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',
|
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
||||||
}
|
}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
LBRYMetadata.Metadata(metadata)
|
Metadata.Metadata(metadata)
|
||||||
|
|
||||||
def test_assertion_if_missing_v001_field(self):
|
def test_assertion_if_missing_v001_field(self):
|
||||||
metadata = {
|
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'
|
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg'
|
||||||
}
|
}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
LBRYMetadata.Metadata(metadata)
|
Metadata.Metadata(metadata)
|
||||||
|
|
||||||
def test_version_is_001_if_all_fields_are_present(self):
|
def test_version_is_001_if_all_fields_are_present(self):
|
||||||
metadata = {
|
metadata = {
|
||||||
|
@ -78,7 +78,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
'content-type': 'audio/mpeg',
|
'content-type': 'audio/mpeg',
|
||||||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
'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)
|
self.assertEquals('0.0.1', m.version)
|
||||||
|
|
||||||
def test_assertion_if_there_is_an_extra_field(self):
|
def test_assertion_if_there_is_an_extra_field(self):
|
||||||
|
@ -95,7 +95,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
'MYSTERYFIELD': '?'
|
'MYSTERYFIELD': '?'
|
||||||
}
|
}
|
||||||
with self.assertRaises(AssertionError):
|
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):
|
def test_version_is_002_if_all_fields_are_present(self):
|
||||||
metadata = {
|
metadata = {
|
||||||
|
@ -112,7 +112,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
'content-type': 'video/mp4',
|
'content-type': 'video/mp4',
|
||||||
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
'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)
|
self.assertEquals('0.0.2', m.version)
|
||||||
|
|
||||||
def test_version_is_003_if_all_fields_are_present(self):
|
def test_version_is_003_if_all_fields_are_present(self):
|
||||||
|
@ -130,7 +130,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
'content_type': 'video/mp4',
|
'content_type': 'video/mp4',
|
||||||
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
'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)
|
self.assertEquals('0.0.3', m.version)
|
||||||
|
|
||||||
def test_version_claimed_is_001_but_version_is_002(self):
|
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'
|
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
||||||
}
|
}
|
||||||
with self.assertRaises(AssertionError):
|
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):
|
def test_version_claimed_is_002_but_version_is_003(self):
|
||||||
metadata = {
|
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'
|
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
||||||
}
|
}
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
LBRYMetadata.Metadata(metadata, process_now=False)
|
Metadata.Metadata(metadata, process_now=False)
|
||||||
|
|
||||||
def test_version_001_ports_to_003(self):
|
def test_version_001_ports_to_003(self):
|
||||||
metadata = {
|
metadata = {
|
||||||
|
@ -181,7 +181,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
'content-type': 'audio/mpeg',
|
'content-type': 'audio/mpeg',
|
||||||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
'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)
|
self.assertEquals('0.0.3', m.version)
|
||||||
|
|
||||||
def test_version_002_ports_to_003(self):
|
def test_version_002_ports_to_003(self):
|
||||||
|
@ -199,5 +199,5 @@ class MetadataTest(unittest.TestCase):
|
||||||
'content-type': 'video/mp4',
|
'content-type': 'video/mp4',
|
||||||
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
'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)
|
self.assertEquals('0.0.3', m.version)
|
|
@ -2,7 +2,7 @@ import mock
|
||||||
import requests
|
import requests
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
from lbrynet.lbrynet_daemon import LBRYDaemon
|
from lbrynet.lbrynet_daemon import Daemon
|
||||||
|
|
||||||
|
|
||||||
class MiscTests(unittest.TestCase):
|
class MiscTests(unittest.TestCase):
|
||||||
|
@ -18,9 +18,9 @@ class MiscTests(unittest.TestCase):
|
||||||
"tag_name": "v0.3.8",
|
"tag_name": "v0.3.8",
|
||||||
"prerelease": False
|
"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
|
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):
|
def test_error_is_thrown_if_prerelease(self):
|
||||||
response = mock.create_autospec(requests.Response)
|
response = mock.create_autospec(requests.Response)
|
||||||
|
@ -28,11 +28,11 @@ class MiscTests(unittest.TestCase):
|
||||||
"tag_name": "v0.3.8",
|
"tag_name": "v0.3.8",
|
||||||
"prerelease": True
|
"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
|
req.get.return_value = response
|
||||||
with self.assertRaises(Exception):
|
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):
|
def test_error_is_thrown_when_version_cant_be_parsed(self):
|
||||||
with self.assertRaises(Exception):
|
with self.assertRaises(Exception):
|
||||||
LBRYDaemon.get_version_from_tag('garbage')
|
Daemon.get_version_from_tag('garbage')
|
|
@ -1,14 +1,14 @@
|
||||||
from twisted.trial import unittest
|
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):
|
def test_guess_type(self):
|
||||||
self.assertEqual('0.3.8', LBRYDaemonCLI.guess_type('0.3.8'))
|
self.assertEqual('0.3.8', DaemonCLI.guess_type('0.3.8'))
|
||||||
self.assertEqual(0.3, LBRYDaemonCLI.guess_type('0.3'))
|
self.assertEqual(0.3, DaemonCLI.guess_type('0.3'))
|
||||||
self.assertEqual(3, LBRYDaemonCLI.guess_type('3'))
|
self.assertEqual(3, DaemonCLI.guess_type('3'))
|
||||||
self.assertEqual('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA==', LBRYDaemonCLI.guess_type('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA=='))
|
self.assertEqual('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA==', DaemonCLI.guess_type('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA=='))
|
||||||
self.assertEqual(0.3, LBRYDaemonCLI.guess_type('0.3'))
|
self.assertEqual(0.3, DaemonCLI.guess_type('0.3'))
|
||||||
|
|
||||||
def test_get_params(self):
|
def test_get_params(self):
|
||||||
test_params = [
|
test_params = [
|
||||||
|
@ -25,4 +25,4 @@ class LBRYDaemonCLITests(unittest.TestCase):
|
||||||
'n': 5,
|
'n': 5,
|
||||||
'address': 'bY13xeAjLrsjP4KGETwStK2a9UgKgXVTXu'
|
'address': 'bY13xeAjLrsjP4KGETwStK2a9UgKgXVTXu'
|
||||||
}
|
}
|
||||||
self.assertDictEqual(test_r, LBRYDaemonCLI.get_params_from_kwargs(test_params))
|
self.assertDictEqual(test_r, DaemonCLI.get_params_from_kwargs(test_params))
|
Loading…
Reference in a new issue