From 24961dd02ce400ddebf1d0a2230688c4e89f0b8a Mon Sep 17 00:00:00 2001 From: dustinface <35775977+xdustinface@users.noreply.github.com> Date: Wed, 9 Nov 2022 01:04:56 +0100 Subject: [PATCH] server: Drop some unused code (#13867) * Drop unused `Delivery` enum * Drop unused `get_outgoing_connections` * Drop `connection_utils.py` --- chia/server/connection_utils.py | 68 --------------------------------- chia/server/outbound_message.py | 15 -------- chia/server/server.py | 8 ---- 3 files changed, 91 deletions(-) delete mode 100644 chia/server/connection_utils.py diff --git a/chia/server/connection_utils.py b/chia/server/connection_utils.py deleted file mode 100644 index 5b270fd1c13f..000000000000 --- a/chia/server/connection_utils.py +++ /dev/null @@ -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 diff --git a/chia/server/outbound_message.py b/chia/server/outbound_message.py index 1cde0f0a0646..1892f76b2d35 100644 --- a/chia/server/outbound_message.py +++ b/chia/server/outbound_message.py @@ -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): diff --git a/chia/server/server.py b/chia/server/server.py index 047c066c211e..f4ecf70efd77 100644 --- a/chia/server/server.py +++ b/chia/server/server.py @@ -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)