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 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2022 Nexedi SA and Contributors. # Copyright (C) 2022-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # 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 # it under the terms of the GNU General Public License version 3, or (at your
...@@ -53,13 +53,14 @@ def connect(wsuri): # -> Conn ...@@ -53,13 +53,14 @@ def connect(wsuri): # -> Conn
ws.connect(wsuri) ws.connect(wsuri)
except Exception as ex: except Exception as ex:
raise ConnError("connect") from ex raise ConnError("connect") from ex
return Conn(ws) return Conn(ws, wsuri)
# Conn represents WebSocket connection to a service. # Conn represents WebSocket connection to a service.
# #
# It provides functionality to issue requests, and (TODO) to receive notifications. # It provides functionality to issue requests, and (TODO) to receive notifications.
# Conn should be created via connect. # Conn should be created via connect.
class Conn: class Conn:
# .wsuri websocket uri of the service
# ._ws websocket connection to service # ._ws websocket connection to service
# ._srv_ready_msg message we got for "ready" # ._srv_ready_msg message we got for "ready"
...@@ -71,7 +72,7 @@ class Conn: ...@@ -71,7 +72,7 @@ class Conn:
# ._rx_wg sync.WorkGroup for spawned _serve_recv # ._rx_wg sync.WorkGroup for spawned _serve_recv
# ._down_once sync.Once # ._down_once sync.Once
def __init__(conn, ws): def __init__(conn, ws, wsuri):
try: try:
msg0_raw = ws.recv() msg0_raw = ws.recv()
msg0 = json.loads(msg0_raw) msg0 = json.loads(msg0_raw)
...@@ -82,6 +83,7 @@ class Conn: ...@@ -82,6 +83,7 @@ class Conn:
ws.close() ws.close()
raise ConnError("handshake") from ex raise ConnError("handshake") from ex
conn.wsuri = wsuri
conn._ws = ws conn._ws = ws
conn._srv_ready_msg = msg0 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