mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-10 15:10:54 +00:00
move concurrency_limit to identify_push
Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>
This commit is contained in:
@ -40,7 +40,8 @@ logger = logging.getLogger(__name__)
|
|||||||
ID_PUSH = TProtocol("/ipfs/id/push/1.0.0")
|
ID_PUSH = TProtocol("/ipfs/id/push/1.0.0")
|
||||||
PROTOCOL_VERSION = "ipfs/0.1.0"
|
PROTOCOL_VERSION = "ipfs/0.1.0"
|
||||||
AGENT_VERSION = get_agent_version()
|
AGENT_VERSION = get_agent_version()
|
||||||
LIMIT = trio.Semaphore(10)
|
CONCURRENCY_LIMIT = 10
|
||||||
|
LIMIT = trio.Semaphore(CONCURRENCY_LIMIT)
|
||||||
|
|
||||||
|
|
||||||
def identify_push_handler_for(host: IHost) -> StreamHandlerFn:
|
def identify_push_handler_for(host: IHost) -> StreamHandlerFn:
|
||||||
|
|||||||
@ -20,6 +20,7 @@ from libp2p.identity.identify.pb.identify_pb2 import (
|
|||||||
Identify,
|
Identify,
|
||||||
)
|
)
|
||||||
from libp2p.identity.identify_push.identify_push import (
|
from libp2p.identity.identify_push.identify_push import (
|
||||||
|
CONCURRENCY_LIMIT,
|
||||||
ID_PUSH,
|
ID_PUSH,
|
||||||
_update_peerstore_from_identify,
|
_update_peerstore_from_identify,
|
||||||
identify_push_handler_for,
|
identify_push_handler_for,
|
||||||
@ -449,8 +450,6 @@ async def test_push_identify_to_peers_respects_concurrency_limit():
|
|||||||
It mocks `push_identify_to_peer` to simulate delay using sleep,
|
It mocks `push_identify_to_peer` to simulate delay using sleep,
|
||||||
allowing the test to measure and assert actual concurrency behavior.
|
allowing the test to measure and assert actual concurrency behavior.
|
||||||
"""
|
"""
|
||||||
CONCURRENCY_LIMIT = 10
|
|
||||||
LIMIT = trio.Semaphore(CONCURRENCY_LIMIT)
|
|
||||||
state = {
|
state = {
|
||||||
"concurrency_counter": 0,
|
"concurrency_counter": 0,
|
||||||
"max_observed": 0,
|
"max_observed": 0,
|
||||||
@ -458,7 +457,7 @@ async def test_push_identify_to_peers_respects_concurrency_limit():
|
|||||||
lock = trio.Lock()
|
lock = trio.Lock()
|
||||||
|
|
||||||
async def mock_push_identify_to_peer(
|
async def mock_push_identify_to_peer(
|
||||||
host, peer_id, observed_multiaddr=None
|
host, peer_id, observed_multiaddr=None, limit=trio.Semaphore(CONCURRENCY_LIMIT)
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Mock function to test concurrency by simulating an identify message.
|
Mock function to test concurrency by simulating an identify message.
|
||||||
@ -471,7 +470,7 @@ async def test_push_identify_to_peers_respects_concurrency_limit():
|
|||||||
True if the push was successful, False otherwise.
|
True if the push was successful, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
async with LIMIT:
|
async with limit:
|
||||||
async with lock:
|
async with lock:
|
||||||
state["concurrency_counter"] += 1
|
state["concurrency_counter"] += 1
|
||||||
if state["concurrency_counter"] > CONCURRENCY_LIMIT:
|
if state["concurrency_counter"] > CONCURRENCY_LIMIT:
|
||||||
|
|||||||
Reference in New Issue
Block a user