mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-03-21 12:41:28 +00:00
Update tests in test_tcp.py
Besides, run `make format`
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
from typing import TYPE_CHECKING, Any, Awaitable, List, Set, Tuple
|
||||
|
||||
import trio
|
||||
from async_service import Service
|
||||
import trio
|
||||
|
||||
from libp2p.network.connection.net_connection_interface import INetConn
|
||||
from libp2p.network.stream.net_stream import NetStream
|
||||
|
||||
@ -2,7 +2,6 @@ import logging
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from async_service import Service
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
import trio
|
||||
|
||||
@ -205,7 +204,7 @@ class Swarm(INetwork, Service):
|
||||
|
||||
logger.debug("successfully opened connection to peer %s", peer_id)
|
||||
# FIXME: This is a intentional barrier to prevent from the handler exiting and
|
||||
# closing the connection.
|
||||
# closing the connection. Probably change to `Service.manager.wait_finished`?
|
||||
await trio.sleep_forever()
|
||||
|
||||
try:
|
||||
@ -229,16 +228,6 @@ class Swarm(INetwork, Service):
|
||||
async def close(self) -> None:
|
||||
# TODO: Prevent from new listeners and conns being added.
|
||||
# Reference: https://github.com/libp2p/go-libp2p-swarm/blob/8be680aef8dea0a4497283f2f98470c2aeae6b65/swarm.go#L124-L134 # noqa: E501
|
||||
|
||||
# Close listeners
|
||||
# await asyncio.gather(
|
||||
# *[listener.close() for listener in self.listeners.values()]
|
||||
# )
|
||||
|
||||
# # Close connections
|
||||
# await asyncio.gather(
|
||||
# *[connection.close() for connection in self.connections.values()]
|
||||
# )
|
||||
await self.manager.stop()
|
||||
await self.manager.wait_finished()
|
||||
logger.debug("swarm successfully closed")
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import math
|
||||
import asyncio
|
||||
import logging
|
||||
import math
|
||||
from typing import Any # noqa: F401
|
||||
from typing import Awaitable, Dict, List, Optional, Tuple
|
||||
|
||||
import trio
|
||||
from async_service import Service
|
||||
import trio
|
||||
|
||||
from libp2p.exceptions import ParseError
|
||||
from libp2p.io.exceptions import IncompleteReadError
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import trio
|
||||
from contextlib import asynccontextmanager, AsyncExitStack
|
||||
from contextlib import AsyncExitStack, asynccontextmanager
|
||||
from typing import Any, AsyncIterator, Dict, Tuple, cast
|
||||
|
||||
import factory
|
||||
from async_service import background_trio_service
|
||||
import factory
|
||||
import trio
|
||||
|
||||
from libp2p import generate_new_rsa_identity, generate_peer_id_from
|
||||
from libp2p.crypto.keys import KeyPair
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import trio
|
||||
from typing import List, Sequence, Tuple
|
||||
|
||||
import multiaddr
|
||||
import trio
|
||||
|
||||
from libp2p import new_node
|
||||
from libp2p.host.basic_host import BasicHost
|
||||
|
||||
@ -25,7 +25,8 @@ class TCPListener(IListener):
|
||||
self.server = None
|
||||
self.handler = handler_function
|
||||
|
||||
async def listen(self, maddr: Multiaddr, nursery: trio.Nursery) -> bool:
|
||||
# TODO: Fix handling?
|
||||
async def listen(self, maddr: Multiaddr, nursery: trio.Nursery) -> None:
|
||||
"""
|
||||
put listener in listening mode and wait for incoming connections.
|
||||
|
||||
@ -50,16 +51,13 @@ class TCPListener(IListener):
|
||||
socket = listeners[0].socket
|
||||
self.multiaddrs.append(_multiaddr_from_socket(socket))
|
||||
|
||||
return True
|
||||
|
||||
def get_addrs(self) -> List[Multiaddr]:
|
||||
"""
|
||||
retrieve list of addresses the listener is listening on.
|
||||
|
||||
:return: return list of addrs
|
||||
"""
|
||||
# TODO check if server is listening
|
||||
return self.multiaddrs
|
||||
return tuple(self.multiaddrs)
|
||||
|
||||
async def close(self) -> None:
|
||||
"""close the listener such that no more connections can be open on this
|
||||
|
||||
Reference in New Issue
Block a user