forked from LBRYCommunity/lbry-sdk
Merge branch 'master' into note-download-blob-peer
This commit is contained in:
commit
940f517aa3
4 changed files with 74 additions and 1 deletions
|
@ -13,6 +13,7 @@ RUN apt-get update && \
|
|||
wget \
|
||||
tar unzip \
|
||||
build-essential \
|
||||
automake libtool \
|
||||
pkg-config \
|
||||
libleveldb-dev \
|
||||
python3.7 \
|
||||
|
|
|
@ -11,6 +11,7 @@ ENV DOCKER_TAG=$DOCKER_TAG DOCKER_COMMIT=$DOCKER_COMMIT
|
|||
RUN apt-get update && \
|
||||
apt-get -y --no-install-recommends install \
|
||||
wget \
|
||||
automake libtool \
|
||||
tar unzip \
|
||||
build-essential \
|
||||
pkg-config \
|
||||
|
|
|
@ -186,7 +186,7 @@ class UPbitBTCFeed(MarketFeed):
|
|||
params = {"markets": "BTC-LBC"}
|
||||
|
||||
def get_rate_from_response(self, json_response):
|
||||
if len(json_response) != 1 or 'trade_price' not in json_response[0]:
|
||||
if "error" in json_response or len(json_response) != 1 or 'trade_price' not in json_response[0]:
|
||||
raise InvalidExchangeRateResponseError(self.name, 'result not found')
|
||||
return 1.0 / float(json_response[0]['trade_price'])
|
||||
|
||||
|
|
71
scripts/troubleshoot_p2p_and_dht_webservice.py
Normal file
71
scripts/troubleshoot_p2p_and_dht_webservice.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
import asyncio
|
||||
from aiohttp import web
|
||||
|
||||
from lbry.blob_exchange.serialization import BlobRequest, BlobResponse
|
||||
from lbry.dht.constants import generate_id
|
||||
from lbry.dht.node import Node
|
||||
from lbry.dht.peer import make_kademlia_peer, PeerManager
|
||||
from lbry.extras.daemon.storage import SQLiteStorage
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
NODE = Node(
|
||||
loop, PeerManager(loop), generate_id(), 60600, 60600, 3333, None,
|
||||
storage=SQLiteStorage(None, ":memory:", loop, loop.time)
|
||||
)
|
||||
|
||||
|
||||
async def check_p2p(ip, port):
|
||||
writer = None
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(ip, port)
|
||||
writer.write(BlobRequest.make_request_for_blob_hash('0'*96).serialize())
|
||||
return BlobResponse.deserialize(await reader.readuntil(b'}')).get_address_response().lbrycrd_address
|
||||
except OSError:
|
||||
return None
|
||||
finally:
|
||||
if writer:
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
|
||||
|
||||
async def check_dht(ip, port):
|
||||
peer = make_kademlia_peer(None, ip, udp_port=int(port))
|
||||
return await NODE.protocol.get_rpc_peer(peer).ping()
|
||||
|
||||
|
||||
async def endpoint_p2p(request):
|
||||
p2p_port = request.match_info.get('p2p_port', "3333")
|
||||
try:
|
||||
address = await asyncio.wait_for(check_p2p(request.remote, p2p_port), 3)
|
||||
except asyncio.TimeoutError:
|
||||
address = None
|
||||
return {"status": address is not None, "port": p2p_port, "payment_address": address}
|
||||
|
||||
|
||||
async def endpoint_dht(request):
|
||||
dht_port = request.match_info.get('dht_port', "3333")
|
||||
try:
|
||||
response = await check_dht(request.remote, dht_port)
|
||||
except asyncio.TimeoutError:
|
||||
response = None
|
||||
return {"status": response == b'pong', "port": dht_port}
|
||||
|
||||
|
||||
async def endpoint_default(request):
|
||||
return {"dht_status": await endpoint_dht(request), "p2p_status": await endpoint_p2p(request)}
|
||||
|
||||
|
||||
def as_json_response_wrapper(endpoint):
|
||||
async def json_endpoint(*args, **kwargs):
|
||||
return web.json_response(await endpoint(*args, **kwargs))
|
||||
return json_endpoint
|
||||
|
||||
|
||||
app = web.Application()
|
||||
app.add_routes([web.get('/', as_json_response_wrapper(endpoint_default)),
|
||||
web.get('/dht/{dht_port}', as_json_response_wrapper(endpoint_dht)),
|
||||
web.get('/p2p/{p2p_port}', as_json_response_wrapper(endpoint_p2p))])
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop.create_task(NODE.start_listening("0.0.0.0"))
|
||||
web.run_app(app, port=60666)
|
Loading…
Reference in a new issue