From 06832b94d485248e43118d410837904695fd88e2 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 2 Jun 2022 12:58:21 -0400 Subject: [PATCH] Add vnc password auth, connection reset logic Now that we have working client auth thanks to: https://github.com/barneygale/asyncvnc/pull/4 and related issue, we can use a pw for the vnc server, though we should eventually auto-generate a random one from a docker super obviously. Add logic to the data reset hack loop to do a connection reset after 2 failed/timeout attempts at the regular data reset. We need to also add this logic around reconnectionn events that are due to the host network connection: aka roaming that's faster then timing logic builtin to the gateway. --- dockering/ib/run_x11_vnc.sh | 2 +- piker/brokers/ib.py | 56 +++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/dockering/ib/run_x11_vnc.sh b/dockering/ib/run_x11_vnc.sh index c87dc2bb..c7c088b6 100755 --- a/dockering/ib/run_x11_vnc.sh +++ b/dockering/ib/run_x11_vnc.sh @@ -13,4 +13,4 @@ x11vnc \ -autoport 3003 \ # can't use this because of ``asyncvnc`` issue: # https://github.com/barneygale/asyncvnc/issues/1 - # -passwd "$VNC_SERVER_PASSWORD" + -passwd 'ibcansmbz' diff --git a/piker/brokers/ib.py b/piker/brokers/ib.py index 26198a59..a1de5c4c 100644 --- a/piker/brokers/ib.py +++ b/piker/brokers/ib.py @@ -1588,29 +1588,55 @@ async def get_bars( hist_ev = proxy.status_event( 'HMDS data farm connection is OK:ushmds' ) - # live_ev = proxy.status_event( - # # 'Market data farm connection is OK:usfuture' - # 'Market data farm connection is OK:usfarm' - # ) - # port = proxy._aio_ns.ib.client.port - await data_reset_hack() + # XXX: other event messages we might want to try and + # wait for but i wasn't able to get any of this + # reliable.. + # reconnect_start = proxy.status_event( + # 'Market data farm is connecting:usfuture' + # ) + # live_ev = proxy.status_event( + # 'Market data farm connection is OK:usfuture' + # ) # try to wait on the reset event(s) to arrive, a timeout # will trigger a retry up to 6 times (for now). - for i in range(6): - with trio.move_on_after(6) as cs: + tries: int = 6 + reset_type: str = 'data' + resends: int = 0 + + for i in range(1, tries): + + log.warning(f'Sending reset request {reset_type}') + await data_reset_hack(reset_type=reset_type) + reset_type = 'data' + + with trio.move_on_after(3) as cs: for name, ev in [ + # TODO: not sure if waiting on other events + # is all that useful here or not. in theory + # you could wait on one of the ones above + # first to verify the reset request was + # sent? ('history', hist_ev), - # ('live', live_ev), ]: await ev.wait() log.info(f"{name} DATA RESET") break + if cs.cancelled_caught: fails += 1 - if cs.cancelled_caught: - log.warning(f'Data reset hack failed, retrying {i}...') + log.warning( + f'Data reset {name} timeout, retrying {i}.' + ) + + if resends > 1: + # on each 3rd timeout, do a full connection + # reset instead. + reset_type = 'connection' + resends = 0 + else: + resends += 1 continue @@ -2219,7 +2245,6 @@ async def trades_dialogue( assert account in accounts_def accounts.add(account) - # for client in _client_cache.values(): for client in aioclients.values(): for pos in client.positions(): @@ -2560,8 +2585,15 @@ async def data_reset_hack( async with asyncvnc.connect( 'localhost', port=5900, + password='ibcansmbz', ) as client: + # move to middle of screen + # 640x1800 + client.mouse.move( + x=100, + y=100, + ) client.mouse.click() client.keyboard.press('Ctrl', 'Alt', key) # keys are stacked