2016-08-03 00:34:48 +02:00
|
|
|
import logging
|
|
|
|
import random
|
|
|
|
from txjsonrpc.web.jsonrpc import Proxy
|
2016-10-19 06:12:44 +02:00
|
|
|
from lbrynet import settings
|
2016-08-03 00:34:48 +02:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class LighthouseClient(object):
|
2016-08-03 23:44:32 +02:00
|
|
|
def __init__(self, servers=None):
|
2016-10-19 06:12:44 +02:00
|
|
|
self.servers = servers or settings.search_servers
|
2016-08-03 00:34:48 +02:00
|
|
|
|
|
|
|
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)
|