Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Apr 19, 2022
1 parent e9c0905 commit 944cc7b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
73 changes: 37 additions & 36 deletions src/tribler/core/components/ipv8/eva_protocol.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
"""EVA protocol: a protocol for transferring big binary data over ipv8.
Limitations and other useful information described in the corresponding class.
An example of use:
>>> import os
>>> from ipv8.community import Community
>>> class MyCommunity(EVAProtocolMixin, Community):
... community_id = os.urandom(20)
...
>>> def __init__(self, *args, **kwargs):
... super().__init__(*args, **kwargs)
... self.eva_init()
...
... self.eva.register_receive_callback(self.on_receive)
... self.eva.register_send_complete_callback(self.on_send_complete)
... self.eva.register_error_callback(self.on_error)
...
>>> async def my_function(self, peer):
... await self.eva.send_binary(peer, b'info1', b'data1')
... await self.eva.send_binary(peer, b'info2', b'data2')
... await self.eva.send_binary(peer, b'info3', b'data3')
...
>>> async def on_receive(self, result):
... self.logger.info(f'Data has been received: {result}')
...
>>> async def on_send_complete(self, result):
... self.logger.info(f'Transfer has been completed: {result}')
...
>>> async def on_error(self, peer, exception):
... self.logger.error(f'Error has been occurred: {exception}')
"""
EVA protocol: a protocol for transferring big binary data over ipv8.
Limitations and other useful information described in the corresponding class.
An example of use:
>>> import os
>>> from ipv8.community import Community
>>> class MyCommunity(EVAProtocolMixin, Community):
... community_id = os.urandom(20)
...
>>> def __init__(self, *args, **kwargs):
... super().__init__(*args, **kwargs)
... self.eva_init()
...
... self.eva.register_receive_callback(self.on_receive)
... self.eva.register_send_complete_callback(self.on_send_complete)
... self.eva.register_error_callback(self.on_error)
...
>>> async def my_function(self, peer):
... await self.eva.send_binary(peer, b'info1', b'data1')
... await self.eva.send_binary(peer, b'info2', b'data2')
... await self.eva.send_binary(peer, b'info3', b'data3')
...
>>> async def on_receive(self, result):
... self.logger.info(f'Data has been received: {result}')
...
>>> async def on_send_complete(self, result):
... self.logger.info(f'Transfer has been completed: {result}')
...
>>> async def on_error(self, peer, exception):
... self.logger.error(f'Error has been occurred: {exception}')
"""
__version__ = '2.0.0'

Expand All @@ -41,7 +41,7 @@
from collections import defaultdict, deque
from dataclasses import dataclass
from enum import Enum, auto
from random import randint
from random import SystemRandom
from typing import Awaitable, Callable, Dict, Optional, Type

from ipv8.lazy_community import lazy_wrapper
Expand Down Expand Up @@ -153,6 +153,7 @@ class Transfer: # pylint: disable=too-many-instance-attributes
def __init__(self, transfer_type: TransferType, info: bytes, data: bytes, data_size: int, block_count: int,
nonce: int, peer: Peer, protocol, future: Optional[Future] = None, window_size: int = 0,
updated: float = 0):
""" This class has been used internally by the EVA protocol"""
self.type = transfer_type
self.info = info
self.data = data
Expand Down Expand Up @@ -305,6 +306,7 @@ def __init__( # pylint: disable=too-many-arguments

self.retransmit_enabled = True
self.terminate_by_timeout_enabled = terminate_by_timeout_enabled
self.random = SystemRandom()

community.register_task('scheduled send', self.send_scheduled, interval=scheduled_send_interval_in_sec)

Expand Down Expand Up @@ -362,7 +364,7 @@ def send_binary(self, peer: Peer, info: bytes, data: bytes, nonce: Optional[int]
data=data,
data_size=data_size,
block_count=math.ceil(data_size / self.block_size),
nonce=nonce if nonce is not None else randint(0, MAX_U64),
nonce=nonce if nonce is not None else self.random.randint(0, MAX_U64),
future=Future(),
peer=peer,
protocol=self
Expand Down Expand Up @@ -593,8 +595,7 @@ def send_scheduled(self):
self.start_outgoing_transfer(transfer)

def shutdown(self):
""" This method terminates all current transfers
"""
"""This method terminates all current transfers"""
logger.info('Shutting down...')
transfers = list(self.incoming.values()) + list(self.outgoing.values())
for transfer in transfers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def test_send_scheduled_with_transfers_limit(eva: EVAProtocol):
assert len(eva.scheduled['peer3']) == 1


def test_send_write_request_released_transfer(eva: EVAProtocol, peer):
def test_send_write_request_released_transfer(eva: EVAProtocol):
transfer = Mock()
transfer.released = True
assert not eva.send_write_request(transfer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import string
from asyncio import sleep
from binascii import unhexlify
from datetime import datetime
from json import dumps
from operator import attrgetter
from os import urandom
Expand All @@ -11,12 +10,9 @@

from ipv8.keyvault.crypto import default_eccrypto
from ipv8.test.base import TestBase

from pony.orm import db_session
from pony.orm.dbapiprovider import OperationalError

import pytest

from tribler.core.components.metadata_store.db.orm_bindings.channel_node import NEW
from tribler.core.components.metadata_store.db.serialization import CHANNEL_THUMBNAIL, CHANNEL_TORRENT, REGULAR_TORRENT
from tribler.core.components.metadata_store.db.store import MetadataStore
Expand All @@ -29,6 +25,7 @@
from tribler.core.utilities.unicode import hexlify
from tribler.core.utilities.utilities import random_infohash


# pylint: disable=protected-access


Expand Down Expand Up @@ -550,6 +547,7 @@ async def test_dont_drop_silent_peer_on_empty_response(self):
self.nodes[1].overlay.rqc_settings.max_channel_query_back = 0

was_called = []

async def mock_on_remote_select_response(*_, **__):
was_called.append(True)
return []
Expand Down

0 comments on commit 944cc7b

Please sign in to comment.