Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PeerSubscribers now specify what messages they are interested in
- Loading branch information
1 parent
888f105
commit 355227d
Showing
9 changed files
with
186 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
from p2p.peer import PeerSubscriber | ||
from p2p.protocol import Command | ||
|
||
from trinity.protocol.eth.peer import ETHPeer | ||
from trinity.protocol.eth.commands import GetBlockHeaders | ||
|
||
from tests.trinity.core.peer_helpers import ( | ||
get_directly_linked_peers, | ||
) | ||
|
||
|
||
class HeadersSubscriber(PeerSubscriber): | ||
msg_queue_maxsize = 10 | ||
subscription_msg_types = {GetBlockHeaders} | ||
|
||
|
||
class AllSubscriber(PeerSubscriber): | ||
msg_queue_maxsize = 10 | ||
subscription_msg_types = {Command} | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_peer_subscriber_filters_messages(request, event_loop): | ||
peer, remote = await get_directly_linked_peers( | ||
request, | ||
event_loop, | ||
peer1_class=ETHPeer, | ||
peer2_class=ETHPeer, | ||
) | ||
|
||
header_subscriber = HeadersSubscriber() | ||
all_subscriber = AllSubscriber() | ||
|
||
peer.add_subscriber(header_subscriber) | ||
peer.add_subscriber(all_subscriber) | ||
|
||
remote.sub_proto.send_get_node_data([b'\x00' * 32]) | ||
remote.sub_proto.send_get_block_headers(0, 1, 0, False) | ||
remote.sub_proto.send_get_node_data([b'\x00' * 32]) | ||
remote.sub_proto.send_get_block_headers(1, 1, 0, False) | ||
remote.sub_proto.send_get_node_data([b'\x00' * 32]) | ||
|
||
# yeild to let remote and peer transmit. | ||
await asyncio.sleep(0.01) | ||
|
||
assert header_subscriber.queue_size == 2 | ||
assert all_subscriber.queue_size == 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.