mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-19 14:48:38 +03:00
server: Drop some unused code (#13867)
* Drop unused `Delivery` enum * Drop unused `get_outgoing_connections` * Drop `connection_utils.py`
This commit is contained in:
parent
35d5858a06
commit
24961dd02c
@ -1,68 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
from typing import Any, List, Optional, Tuple
|
||||
|
||||
from chia.server.ws_connection import WSChiaConnection
|
||||
|
||||
|
||||
async def send_all_first_reply(
|
||||
func: str, arg: Any, peers: List[WSChiaConnection], timeout=15
|
||||
) -> Optional[Tuple[Any, WSChiaConnection]]:
|
||||
"""performs an API request to peers and returns the result of the first response and the peer that sent it."""
|
||||
|
||||
async def do_func(peer_x: WSChiaConnection, func_x: str, arg_x: Any):
|
||||
method_to_call = getattr(peer_x, func_x)
|
||||
result_x = await method_to_call(arg_x)
|
||||
if result_x is not None:
|
||||
return result_x, peer_x
|
||||
else:
|
||||
await asyncio.sleep(timeout)
|
||||
return None
|
||||
|
||||
tasks = []
|
||||
for peer in peers:
|
||||
tasks.append(do_func(peer, func, arg))
|
||||
|
||||
done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|
||||
|
||||
if len(done) > 0:
|
||||
d = done.pop()
|
||||
result = d.result()
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
response, peer = result
|
||||
return response, peer
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
async def send_to_random(func: str, arg: Any, peers: List[WSChiaConnection]) -> Optional[Tuple[Any, WSChiaConnection]]:
|
||||
"""performs an API request to peers and returns the result of the first response and the peer that sent it."""
|
||||
|
||||
async def do_func(peer_x: WSChiaConnection, func_x: str, arg_x: Any):
|
||||
method_to_call = getattr(peer_x, func_x)
|
||||
result_x = await method_to_call(arg_x)
|
||||
if result_x is not None:
|
||||
return result_x, peer_x
|
||||
else:
|
||||
await asyncio.sleep(15)
|
||||
return None
|
||||
|
||||
tasks = []
|
||||
random_peer = random.choice(peers)
|
||||
tasks.append(do_func(random_peer, func, arg))
|
||||
done, pending = await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED)
|
||||
|
||||
if len(done) > 0:
|
||||
d = done.pop()
|
||||
result = d.result()
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
response, peer = result
|
||||
return response, peer
|
||||
else:
|
||||
return None
|
@ -19,21 +19,6 @@ class NodeType(IntEnum):
|
||||
DATA_LAYER = 7
|
||||
|
||||
|
||||
class Delivery(IntEnum):
|
||||
# A message is sent to the same peer that we received a message from
|
||||
RESPOND = 1
|
||||
# A message is sent to all peers
|
||||
BROADCAST = 2
|
||||
# A message is sent to all peers except the one from which we received the API call
|
||||
BROADCAST_TO_OTHERS = 3
|
||||
# A message is sent to a random peer
|
||||
RANDOM = 4
|
||||
# Pseudo-message to close the current connection
|
||||
CLOSE = 5
|
||||
# A message is sent to a specific peer
|
||||
SPECIFIC = 6
|
||||
|
||||
|
||||
@streamable
|
||||
@dataclass(frozen=True)
|
||||
class Message(Streamable):
|
||||
|
@ -698,14 +698,6 @@ class ChiaServer:
|
||||
for message in messages:
|
||||
await connection.send_message(message)
|
||||
|
||||
def get_outgoing_connections(self) -> List[WSChiaConnection]:
|
||||
result = []
|
||||
for _, connection in self.all_connections.items():
|
||||
if connection.is_outbound:
|
||||
result.append(connection)
|
||||
|
||||
return result
|
||||
|
||||
def get_full_node_outgoing_connections(self) -> List[WSChiaConnection]:
|
||||
result = []
|
||||
connections = self.get_connections(NodeType.FULL_NODE)
|
||||
|
Loading…
Reference in New Issue
Block a user