Merge branch 'improve-reflector-commands'
This commit is contained in:
commit
b725906c95
3 changed files with 77 additions and 25 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -14,7 +14,8 @@ at anytime.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
* Added `claim_send_tip`, a command to tip the owner of a claim via a support transaction
|
* Added `claim_send_tip`, a command to tip the owner of a claim via a support transaction
|
||||||
*
|
* Added `reflector` keyword parameter to `file_reflect` command
|
||||||
|
* Added configuration options for auto re-reflect
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
*
|
*
|
||||||
|
@ -25,12 +26,9 @@ at anytime.
|
||||||
*
|
*
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
*
|
* Renamed `reflect` command to `file_reflect`
|
||||||
*
|
* Allow IP addresses to be configured as reflector servers, not just host names.
|
||||||
|
* Return list of blobs that were reflected from `file_reflect`
|
||||||
### Added
|
|
||||||
* Added configuration options for auto re-reflect
|
|
||||||
*
|
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
*
|
*
|
||||||
|
|
|
@ -2414,7 +2414,6 @@ class Daemon(AuthJSONRPCServer):
|
||||||
else:
|
else:
|
||||||
raise Exception('single argument must be specified')
|
raise Exception('single argument must be specified')
|
||||||
|
|
||||||
|
|
||||||
response = yield self._render_response(True)
|
response = yield self._render_response(True)
|
||||||
defer.returnValue(response)
|
defer.returnValue(response)
|
||||||
|
|
||||||
|
@ -2435,22 +2434,43 @@ class Daemon(AuthJSONRPCServer):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def jsonrpc_reflect(self, sd_hash):
|
def jsonrpc_file_reflect(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Reflect a stream
|
Reflect all the blobs in a file matching the filter criteria
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
reflect (<sd_hash> | --sd_hash=<sd_hash>)
|
file_reflect [--sd_hash=<sd_hash>] [--file_name=<file_name>]
|
||||||
|
[--stream_hash=<stream_hash>] [--claim_id=<claim_id>]
|
||||||
|
[--outpoint=<outpoint>] [--rowid=<rowid>] [--name=<name>]
|
||||||
|
[--reflector=<reflector>]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--sd_hash=<sd_hash> : get file with matching sd hash
|
||||||
|
--file_name=<file_name> : get file with matching file name in the
|
||||||
|
downloads folder
|
||||||
|
--stream_hash=<stream_hash> : get file with matching stream hash
|
||||||
|
--claim_id=<claim_id> : get file with matching claim id
|
||||||
|
--outpoint=<outpoint> : get file with matching claim outpoint
|
||||||
|
--rowid=<rowid> : get file with matching row id
|
||||||
|
--name=<name> : get file with matching associated name claim
|
||||||
|
--reflector=<reflector> : reflector server, ip address or url
|
||||||
|
by default choose a server from the config
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(bool) true if successful
|
(list) list of blobs reflected
|
||||||
"""
|
"""
|
||||||
|
|
||||||
lbry_file = yield self._get_lbry_file(FileID.SD_HASH, sd_hash, return_json=False)
|
reflector_server = kwargs.get('reflector', None)
|
||||||
if lbry_file is None:
|
lbry_files = yield self._get_lbry_files(**kwargs)
|
||||||
raise Exception('No file found for give sd hash')
|
|
||||||
yield reupload.reflect_stream(lbry_file)
|
if len(lbry_files) > 1:
|
||||||
defer.returnValue("Reflect success")
|
raise Exception('Too many (%i) files found, need one' % len(lbry_files))
|
||||||
|
elif not lbry_files:
|
||||||
|
raise Exception('No file found')
|
||||||
|
lbry_file = lbry_files[0]
|
||||||
|
|
||||||
|
results = yield reupload.reflect_stream(lbry_file, reflector_server=reflector_server)
|
||||||
|
defer.returnValue(results)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@AuthJSONRPCServer.flags(needed="-n", finished="-f")
|
@AuthJSONRPCServer.flags(needed="-n", finished="-f")
|
||||||
|
|
|
@ -5,29 +5,63 @@ from lbrynet import conf
|
||||||
from lbrynet.reflector import ClientFactory, BlobClientFactory
|
from lbrynet.reflector import ClientFactory, BlobClientFactory
|
||||||
|
|
||||||
|
|
||||||
|
def _is_ip(host):
|
||||||
|
try:
|
||||||
|
if len(host.split(".")) == 4 and all([0 <= int(x) <= 255 for x in host.split(".")]):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def resolve(host):
|
||||||
|
if _is_ip(host):
|
||||||
|
ip = host
|
||||||
|
else:
|
||||||
|
ip = yield reactor.resolve(host)
|
||||||
|
defer.returnValue(ip)
|
||||||
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _reflect_stream(lbry_file, reflector_server):
|
def _reflect_stream(lbry_file, reflector_server):
|
||||||
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
||||||
factory = ClientFactory(lbry_file)
|
factory = ClientFactory(lbry_file)
|
||||||
ip = yield reactor.resolve(reflector_address)
|
ip = yield resolve(reflector_address)
|
||||||
yield reactor.connectTCP(ip, reflector_port, factory)
|
yield reactor.connectTCP(ip, reflector_port, factory)
|
||||||
yield factory.finished_deferred
|
result = yield factory.finished_deferred
|
||||||
|
defer.returnValue(result)
|
||||||
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _reflect_blobs(blob_manager, blob_hashes, reflector_server):
|
def _reflect_blobs(blob_manager, blob_hashes, reflector_server):
|
||||||
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
||||||
factory = BlobClientFactory(blob_manager, blob_hashes)
|
factory = BlobClientFactory(blob_manager, blob_hashes)
|
||||||
ip = yield reactor.resolve(reflector_address)
|
ip = yield resolve(reflector_address)
|
||||||
yield reactor.connectTCP(ip, reflector_port, factory)
|
yield reactor.connectTCP(ip, reflector_port, factory)
|
||||||
yield factory.finished_deferred
|
result = yield factory.finished_deferred
|
||||||
|
defer.returnValue(result)
|
||||||
|
|
||||||
|
|
||||||
def reflect_stream(lbry_file):
|
def reflect_stream(lbry_file, reflector_server=None):
|
||||||
reflector_server = random.choice(conf.settings['reflector_servers'])
|
if reflector_server:
|
||||||
|
if len(reflector_server.split(":")) == 2:
|
||||||
|
host, port = tuple(reflector_server.split(":"))
|
||||||
|
reflector_server = host, int(port)
|
||||||
|
else:
|
||||||
|
reflector_server = reflector_server, 5566
|
||||||
|
else:
|
||||||
|
reflector_server = random.choice(conf.settings['reflector_servers'])
|
||||||
return _reflect_stream(lbry_file, reflector_server)
|
return _reflect_stream(lbry_file, reflector_server)
|
||||||
|
|
||||||
|
|
||||||
def reflect_blob_hashes(blob_hashes, blob_manager):
|
def reflect_blob_hashes(blob_hashes, blob_manager, reflector_server=None):
|
||||||
reflector_server = random.choice(conf.settings['reflector_servers'])
|
if reflector_server:
|
||||||
|
if len(reflector_server.split(":")) == 2:
|
||||||
|
host, port = tuple(reflector_server.split(":"))
|
||||||
|
reflector_server = host, int(port)
|
||||||
|
else:
|
||||||
|
reflector_server = reflector_server, 5566
|
||||||
|
else:
|
||||||
|
reflector_server = random.choice(conf.settings['reflector_servers'])
|
||||||
return _reflect_blobs(blob_manager, blob_hashes, reflector_server)
|
return _reflect_blobs(blob_manager, blob_hashes, reflector_server)
|
||||||
|
|
Loading…
Reference in a new issue