Ejemplo n.º 1
0
def test_get_extended_debug_logger_if_other_logger_in_cache():
    path = "testing.{0}".format(uuid.uuid4())
    normal_logger = get_logger(path)
    assert not isinstance(normal_logger, ExtendedDebugLogger)
    assert normal_logger.name == path

    extended_logger = get_extended_debug_logger(path)
    assert isinstance(extended_logger, ExtendedDebugLogger)
    assert extended_logger.name == path
Ejemplo n.º 2
0
def test_extended_debug_logger_pickling():
    name = "testing.{0}".format(uuid.uuid4())
    extended_logger = get_extended_debug_logger(name)
    pickled = pickle.dumps(extended_logger)

    # logging.Logger.__reduce__() returns (getLogger, name), which could give us a regular Logger
    # instance after pickling/unpickling an ExtendedDebugLogger (e.g. when crossing process
    # boundaries since the other process wouldn't have an ExtendedDebugLogger with that name in
    # the logging module's cache). This test ensures an unpickled ExtendedDebugLogger is still an
    # ExtendedDebugLogger even when it's not in the logging's module cache.
    del logging.Logger.manager.loggerDict[name]
    unpickled_logger = pickle.loads(pickled)
    assert isinstance(unpickled_logger, ExtendedDebugLogger)
Ejemplo n.º 3
0
class BaseConnectionTracker(ABC):
    """
    Base API which defines the interface that the peer pool uses to record
    information about connection failures when attempting to connect to peers
    """
    logger = get_extended_debug_logger(
        'p2p.tracking.connection.ConnectionTracker')

    def record_failure(self, remote: NodeAPI, failure: BaseP2PError) -> None:
        timeout_seconds = get_timeout_for_failure(failure)
        failure_name = type(failure).__name__

        return self.record_blacklist(remote, timeout_seconds, failure_name)

    @abstractmethod
    def record_blacklist(self, remote: NodeAPI, timeout_seconds: int,
                         reason: str) -> None:
        ...

    @abstractmethod
    async def get_blacklisted(self) -> Tuple[NodeID, ...]:
        ...
Ejemplo n.º 4
0
)
from trinity.protocol.les.api import LESV1API, LESV2API

from trinity.components.builtin.network_db.connection.tracker import ConnectionTrackerClient
from trinity.components.builtin.network_db.eth1_peer_db.tracker import (
    BaseEth1PeerTracker,
    EventBusEth1PeerTracker,
    NoopEth1PeerTracker,
)

from .boot import DAOCheckBootManager
from .context import ChainContext
from .events import (
    DisconnectPeerEvent, )

p2p_logger = get_extended_debug_logger('p2p')


class BaseChainPeer(BasePeer):
    boot_manager_class = DAOCheckBootManager
    context: ChainContext

    @cached_property
    def chain_api(self) -> Union[ETHAPI, ETHV63API, LESV1API, LESV2API]:
        return choose_eth_or_les_api(self.connection)

    @cached_property
    def head_info(self) -> HeadInfoAPI:
        return self.connection.get_logic(HeadInfo.name, HeadInfo)

    @cached_property
Ejemplo n.º 5
0
def test_get_extended_debug_logger():
    path = "testing.{0}".format(uuid.uuid4())
    logger = get_extended_debug_logger(path)
    assert isinstance(logger, ExtendedDebugLogger)
    assert logger.name == path