Commit 749e1659 authored by Kirill Smelkov's avatar Kirill Smelkov

amari: Conn: Provide a way to retrieve websocket URI to where a Conn is connected

We will soon need this to know at runtime the address of eNB service
attached by Conn to establish another connection attached to the same eNB.
parent ffffb933
# -*- coding: utf-8 -*-
# Copyright (C) 2022 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
# Copyright (C) 2022-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
......@@ -53,13 +53,14 @@ def connect(wsuri): # -> Conn
ws.connect(wsuri)
except Exception as ex:
raise ConnError("connect") from ex
return Conn(ws)
return Conn(ws, wsuri)
# Conn represents WebSocket connection to a service.
#
# It provides functionality to issue requests, and (TODO) to receive notifications.
# Conn should be created via connect.
class Conn:
# .wsuri websocket uri of the service
# ._ws websocket connection to service
# ._srv_ready_msg message we got for "ready"
......@@ -71,7 +72,7 @@ class Conn:
# ._rx_wg sync.WorkGroup for spawned _serve_recv
# ._down_once sync.Once
def __init__(conn, ws):
def __init__(conn, ws, wsuri):
try:
msg0_raw = ws.recv()
msg0 = json.loads(msg0_raw)
......@@ -82,6 +83,7 @@ class Conn:
ws.close()
raise ConnError("handshake") from ex
conn.wsuri = wsuri
conn._ws = ws
conn._srv_ready_msg = msg0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment