def __init__(self, name, ha, basedirpath, msgHandler, restricted=True, seed=None, onlyListener=False, config=None, msgRejectHandler=None): self._name = name self.ha = ha self.basedirpath = basedirpath self.msgHandler = msgHandler self.seed = seed self.config = config or getConfig() self.msgRejectHandler = msgRejectHandler or self.__defaultMsgRejectHandler self.listenerQuota = self.config.DEFAULT_LISTENER_QUOTA self.senderQuota = self.config.DEFAULT_SENDER_QUOTA self.msgLenVal = MessageLenValidator(self.config.MSG_LEN_LIMIT) self.homeDir = None # As of now there would be only one file in secretKeysDir and sigKeyDir self.publicKeysDir = None self.secretKeysDir = None self.verifKeyDir = None self.sigKeyDir = None self.signer = None self.verifiers = {} self.setupDirs() self.setupOwnKeysIfNeeded() self.setupSigning() # self.poller = test.asyncio.Poller() self.restricted = restricted self.ctx = None # type: Context self.listener = None self.auth = None # Each remote is identified uniquely by the name self._remotes = {} # type: Dict[str, Remote] self.remotesByKeys = {} # Indicates if this stack will maintain any remotes or will # communicate simply to listeners. Used in ClientZStack self.onlyListener = onlyListener self.peersWithoutRemotes = set() self._conns = set() # type: Set[str] self.rxMsgs = deque() self._created = time.perf_counter() self.last_heartbeat_at = None
def __init__(self, config=None): """ :param self: 'NodeStacked' :param config: 'stp config' """ self.outBoxes = {} # type: Dict[int, deque] self.stp_config = config or getConfig() self.msg_len_val = MessageLenValidator(self.stp_config.MSG_LEN_LIMIT)
def prepare_for_sending(msg, signer, message_splitter=lambda x: None): if isinstance(msg, CatchupRep): node.nodestack.prepare_for_sending = old part_bytes = node.nodestack.sign_and_serialize(msg, signer) # Decrease at least 6 times to increase probability of # unintentional shuffle new_limit = len(part_bytes) / 6 node.nodestack.msg_len_val = MessageLenValidator(new_limit) return old(msg, signer, message_splitter)
def __init__(self, config=None, metrics=NullMetricsCollector()): """ :param self: 'NodeStacked' :param config: 'stp config' """ self.outBoxes = {} # type: Dict[int, deque] self.stp_config = config or getConfig() self.msg_len_val = MessageLenValidator(self.stp_config.MSG_LEN_LIMIT) self.metrics = metrics self.enabled = self.stp_config.TRANSPORT_BATCH_ENABLED
def __init__(self, name, ha, basedirpath, msgHandler, restricted=True, seed=None, onlyListener=False, config=None, msgRejectHandler=None, queue_size=0, create_listener_monitor=False, metrics=NullMetricsCollector(), mt_incoming_size=None, mt_outgoing_size=None, timer=None): self._name = name self.ha = ha self.basedirpath = basedirpath self.msgHandler = msgHandler self.seed = seed self.queue_size = queue_size self.config = config or getConfig() self.msgRejectHandler = msgRejectHandler or self.__defaultMsgRejectHandler self.metrics = metrics self.mt_incoming_size = mt_incoming_size self.mt_outgoing_size = mt_outgoing_size self.listenerQuota = self.config.DEFAULT_LISTENER_QUOTA self.listenerSize = self.config.DEFAULT_LISTENER_SIZE self.senderQuota = self.config.DEFAULT_SENDER_QUOTA self.msgLenVal = MessageLenValidator(self.config.MSG_LEN_LIMIT) self.homeDir = None # As of now there would be only one file in secretKeysDir and sigKeyDir self.publicKeysDir = None self.secretKeysDir = None self.verifKeyDir = None self.sigKeyDir = None self.signer = None self.verifiers = {} self.setupDirs() self.setupOwnKeysIfNeeded() self.setupSigning() # self.poller = test.asyncio.Poller() self.restricted = restricted self.ctx = None # type: Context self.listener = None self.create_listener_monitor = create_listener_monitor self.listener_monitor = None self.auth = None # Each remote is identified uniquely by the name self._remotes = {} # type: Dict[str, Remote] self.remotesByKeys = {} # Indicates if this stack will maintain any remotes or will # communicate simply to listeners. Used in ClientZStack self.onlyListener = onlyListener self._conns = set() # type: Set[str] self.rxMsgs = deque() self._created = time.perf_counter() self.last_heartbeat_at = None self._stashed_to_disconnected = {} self._stashed_pongs = set() self._received_pings = set() self._client_message_provider = ClientMessageProvider(self.name, self.config, self.prepare_to_send, self.metrics, self.mt_outgoing_size, timer)
import pytest from plenum.common.exceptions import InvalidMessageExceedingSizeException from stp_core.validators.message_length_validator import MessageLenValidator MSG_LIMIT = 4 vldtr = MessageLenValidator(MSG_LIMIT) def test_msg_under_limit(): vldtr.validate("11".encode()) pass def test_msg_over_limit(): with pytest.raises(InvalidMessageExceedingSizeException): vldtr.validate(("1" * (MSG_LIMIT + 1)).encode())
def patch_msg_len_validators(max_len_limit, txnPoolNodeSet): for node in txnPoolNodeSet: assert hasattr(node.nodestack, 'msgLenVal') assert hasattr(node.nodestack, 'msg_len_val') node.nodestack.msgLenVal = MessageLenValidator(max_len_limit) node.nodestack.msg_len_val = MessageLenValidator(max_len_limit)