forked from LBRYCommunity/lbry-sdk
make peer list query trackers
This commit is contained in:
parent
7d560df9fd
commit
3dc145fe68
3 changed files with 20 additions and 8 deletions
|
@ -725,7 +725,7 @@ class TrackerAnnouncerComponent(Component):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def component(self):
|
def component(self):
|
||||||
return self
|
return self.tracker_client
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def running(self):
|
def running(self):
|
||||||
|
|
|
@ -44,7 +44,7 @@ from lbry.error import (
|
||||||
from lbry.extras import system_info
|
from lbry.extras import system_info
|
||||||
from lbry.extras.daemon import analytics
|
from lbry.extras.daemon import analytics
|
||||||
from lbry.extras.daemon.components import WALLET_COMPONENT, DATABASE_COMPONENT, DHT_COMPONENT, BLOB_COMPONENT
|
from lbry.extras.daemon.components import WALLET_COMPONENT, DATABASE_COMPONENT, DHT_COMPONENT, BLOB_COMPONENT
|
||||||
from lbry.extras.daemon.components import FILE_MANAGER_COMPONENT, DISK_SPACE_COMPONENT
|
from lbry.extras.daemon.components import FILE_MANAGER_COMPONENT, DISK_SPACE_COMPONENT, TRACKER_ANNOUNCER_COMPONENT
|
||||||
from lbry.extras.daemon.components import EXCHANGE_RATE_MANAGER_COMPONENT, UPNP_COMPONENT
|
from lbry.extras.daemon.components import EXCHANGE_RATE_MANAGER_COMPONENT, UPNP_COMPONENT
|
||||||
from lbry.extras.daemon.componentmanager import RequiredCondition
|
from lbry.extras.daemon.componentmanager import RequiredCondition
|
||||||
from lbry.extras.daemon.componentmanager import ComponentManager
|
from lbry.extras.daemon.componentmanager import ComponentManager
|
||||||
|
@ -4971,21 +4971,26 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
if not is_valid_blobhash(blob_hash):
|
if not is_valid_blobhash(blob_hash):
|
||||||
# TODO: use error from lbry.error
|
# TODO: use error from lbry.error
|
||||||
raise Exception("invalid blob hash")
|
raise Exception("invalid blob hash")
|
||||||
peers = []
|
|
||||||
peer_q = asyncio.Queue(loop=self.component_manager.loop)
|
peer_q = asyncio.Queue(loop=self.component_manager.loop)
|
||||||
|
if self.component_manager.has_component(TRACKER_ANNOUNCER_COMPONENT):
|
||||||
|
tracker = self.component_manager.get_component(TRACKER_ANNOUNCER_COMPONENT)
|
||||||
|
tracker_peers = await tracker.get_kademlia_peer_list(bytes.fromhex(blob_hash))
|
||||||
|
log.info("Found %d peers for %s from trackers.", len(tracker_peers), blob_hash[:8])
|
||||||
|
peer_q.put_nowait(tracker_peers)
|
||||||
|
peers = []
|
||||||
await self.dht_node._peers_for_value_producer(blob_hash, peer_q)
|
await self.dht_node._peers_for_value_producer(blob_hash, peer_q)
|
||||||
while not peer_q.empty():
|
while not peer_q.empty():
|
||||||
peers.extend(peer_q.get_nowait())
|
peers.extend(peer_q.get_nowait())
|
||||||
results = [
|
results = {
|
||||||
{
|
(peer.address, peer.tcp_port): {
|
||||||
"node_id": hexlify(peer.node_id).decode(),
|
"node_id": hexlify(peer.node_id).decode() if peer.node_id else None,
|
||||||
"address": peer.address,
|
"address": peer.address,
|
||||||
"udp_port": peer.udp_port,
|
"udp_port": peer.udp_port,
|
||||||
"tcp_port": peer.tcp_port,
|
"tcp_port": peer.tcp_port,
|
||||||
}
|
}
|
||||||
for peer in peers
|
for peer in peers
|
||||||
]
|
}
|
||||||
return paginate_list(results, page, page_size)
|
return paginate_list(list(results.values()), page, page_size)
|
||||||
|
|
||||||
@requires(DATABASE_COMPONENT)
|
@requires(DATABASE_COMPONENT)
|
||||||
async def jsonrpc_blob_announce(self, blob_hash=None, stream_hash=None, sd_hash=None):
|
async def jsonrpc_blob_announce(self, blob_hash=None, stream_hash=None, sd_hash=None):
|
||||||
|
|
|
@ -5,10 +5,12 @@ import struct
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
import ipaddress
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from lbry.dht.node import get_kademlia_peers_from_hosts
|
||||||
from lbry.utils import resolve_host, async_timed_cache, cache_concurrent
|
from lbry.utils import resolve_host, async_timed_cache, cache_concurrent
|
||||||
from lbry.wallet.stream import StreamController
|
from lbry.wallet.stream import StreamController
|
||||||
from lbry import version
|
from lbry import version
|
||||||
|
@ -195,6 +197,11 @@ class TrackerClient:
|
||||||
found.append(result)
|
found.append(result)
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
async def get_kademlia_peer_list(self, info_hash):
|
||||||
|
responses = await self.get_peer_list(info_hash)
|
||||||
|
peers = [(str(ipaddress.ip_address(peer.address)), peer.port) for ann in responses for peer in ann.peers]
|
||||||
|
return await get_kademlia_peers_from_hosts(peers)
|
||||||
|
|
||||||
async def _probe_server(self, info_hash, tracker_host, tracker_port, stopped=False):
|
async def _probe_server(self, info_hash, tracker_host, tracker_port, stopped=False):
|
||||||
result = None
|
result = None
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue