forked from LBRYCommunity/lbry-sdk
add LighthouseClient, announce sd hash after publishing
This commit is contained in:
parent
308d9f5abd
commit
6215d85581
2 changed files with 32 additions and 2 deletions
|
@ -41,6 +41,7 @@ from lbrynet.lbrynet_daemon.LBRYUIManager import LBRYUIManager
|
||||||
from lbrynet.lbrynet_daemon.LBRYDownloader import GetStream
|
from lbrynet.lbrynet_daemon.LBRYDownloader import GetStream
|
||||||
from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher
|
from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher
|
||||||
from lbrynet.lbrynet_daemon.LBRYExchangeRateManager import ExchangeRateManager
|
from lbrynet.lbrynet_daemon.LBRYExchangeRateManager import ExchangeRateManager
|
||||||
|
from lbrynet.lbrynet_daemon.Lighthouse import LighthouseClient
|
||||||
from lbrynet.core import utils
|
from lbrynet.core import utils
|
||||||
from lbrynet.core.LBRYMetadata import verify_name_characters
|
from lbrynet.core.LBRYMetadata import verify_name_characters
|
||||||
from lbrynet.core.utils import generate_id
|
from lbrynet.core.utils import generate_id
|
||||||
|
@ -160,6 +161,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.run_server = True
|
self.run_server = True
|
||||||
self.session = None
|
self.session = None
|
||||||
self.exchange_rate_manager = ExchangeRateManager()
|
self.exchange_rate_manager = ExchangeRateManager()
|
||||||
|
self.lighthouse_client = LighthouseClient()
|
||||||
self.waiting_on = {}
|
self.waiting_on = {}
|
||||||
self.streams = {}
|
self.streams = {}
|
||||||
self.pending_claims = {}
|
self.pending_claims = {}
|
||||||
|
@ -625,6 +627,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
# TODO: this was blatantly copied from jsonrpc_start_lbry_file. Be DRY.
|
# TODO: this was blatantly copied from jsonrpc_start_lbry_file. Be DRY.
|
||||||
def _start_file(f):
|
def _start_file(f):
|
||||||
d = self.lbry_file_manager.toggle_lbry_file_running(f)
|
d = self.lbry_file_manager.toggle_lbry_file_running(f)
|
||||||
|
d.addCallback(lambda _: self.lighthouse_client.announce_sd(f.sd_hash))
|
||||||
return defer.succeed("Started LBRY file")
|
return defer.succeed("Started LBRY file")
|
||||||
|
|
||||||
def _get_and_start_file(name):
|
def _get_and_start_file(name):
|
||||||
|
@ -1444,8 +1447,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
def _search(self, search):
|
def _search(self, search):
|
||||||
proxy = Proxy(random.choice(SEARCH_SERVERS))
|
return self.lighthouse_client.search(search)
|
||||||
return proxy.callRemote('search', search)
|
|
||||||
|
|
||||||
def _render_response(self, result, code):
|
def _render_response(self, result, code):
|
||||||
return defer.succeed({'result': result, 'code': code})
|
return defer.succeed({'result': result, 'code': code})
|
||||||
|
|
28
lbrynet/lbrynet_daemon/Lighthouse.py
Normal file
28
lbrynet/lbrynet_daemon/Lighthouse.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import logging
|
||||||
|
import random
|
||||||
|
from txjsonrpc.web.jsonrpc import Proxy
|
||||||
|
from twisted.internet import defer
|
||||||
|
from lbrynet.conf import SEARCH_SERVERS
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class LighthouseClient(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.servers = SEARCH_SERVERS
|
||||||
|
|
||||||
|
def _get_random_server(self):
|
||||||
|
return Proxy(random.choice(self.servers))
|
||||||
|
|
||||||
|
def _run_query(self, func, arg):
|
||||||
|
return self._get_random_server().callRemote(func, arg)
|
||||||
|
|
||||||
|
def search(self, search):
|
||||||
|
return self._run_query('search', search)
|
||||||
|
|
||||||
|
def announce_sd(self, sd_hash):
|
||||||
|
log.info("Announce sd to lighthouse")
|
||||||
|
return self._run_query('announce_sd', sd_hash)
|
||||||
|
|
||||||
|
def check_available(self, sd_hash):
|
||||||
|
return self._run_query('check_available', sd_hash)
|
Loading…
Reference in a new issue