electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 5a7c3dc4d0bcd0ab3f60108ab99bbf783ba9855c
parent 52bd0eb1a656bdd0eb32340350fb4bf82af5c690
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri, 25 Sep 2020 11:15:04 +0200

network: make MAX_INCOMING_MSG_SIZE configurable from config

requested in https://github.com/spesmilo/electrum/issues/4315#issuecomment-698730778

Diffstat:
Melectrum/interface.py | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/electrum/interface.py b/electrum/interface.py @@ -126,13 +126,13 @@ def assert_list_or_tuple(val: Any) -> None: class NotificationSession(RPCSession): - def __init__(self, *args, **kwargs): + def __init__(self, *args, interface: 'Interface', **kwargs): super(NotificationSession, self).__init__(*args, **kwargs) self.subscriptions = defaultdict(list) self.cache = {} self.default_timeout = NetworkTimeout.Generic.NORMAL self._msg_counter = itertools.count(start=1) - self.interface = None # type: Optional[Interface] + self.interface = interface # type: Interface self.cost_hard_limit = 0 # disable aiorpcx resource limits async def handle_request(self, request): @@ -209,7 +209,9 @@ class NotificationSession(RPCSession): def default_framer(self): # overridden so that max_size can be customized - return NewlineFramer(max_size=MAX_INCOMING_MSG_SIZE) + max_size = int(self.interface.network.config.get('network_max_incoming_msg_size', + MAX_INCOMING_MSG_SIZE)) + return NewlineFramer(max_size=max_size) class NetworkException(Exception): pass @@ -605,7 +607,8 @@ class Interface(Logger): return self.network.default_server == self.server async def open_session(self, sslc, exit_early=False): - async with _RSClient(session_factory=NotificationSession, + session_factory = lambda *args, iface=self, **kwargs: NotificationSession(*args, **kwargs, interface=iface) + async with _RSClient(session_factory=session_factory, host=self.host, port=self.port, ssl=sslc, proxy=self.proxy) as session: self.session = session # type: NotificationSession