From 6038bc541cd82ffce36176e9f8668efb863b7e7c Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 14 Sep 2024 19:55:25 +0200 Subject: [PATCH] Get link establishment rates via service on Android --- sbapp/sideband/core.py | 42 ++++++++++++++++++++++++++++++++++++++- sbapp/ui/objectdetails.py | 12 ++++------- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 97b2333..aa40c04 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -1578,7 +1578,45 @@ class SidebandCore(): RNS.log(ed, RNS.LOG_DEBUG) return ed - + def _get_destination_establishment_rate(self, destination_hash): + try: + mr = self.message_router + oh = destination_hash + ol = None + if oh in mr.direct_links: + ol = mr.direct_links[oh] + elif oh in mr.backchannel_links: + ol = mr.backchannel_links[oh] + + if ol != None: + ler = ol.get_establishment_rate() + if ler: + return ler + + return None + + except Exception as e: + RNS.trace_exception(e) + return None + + def get_destination_establishment_rate(self, destination_hash): + if not RNS.vendor.platformutils.is_android(): + return self._get_destination_establishment_rate(destination_hash) + else: + if self.is_service: + return self._get_destination_establishment_rate(destination_hash) + else: + try: + if self.rpc_connection == None: + self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key) + self.rpc_connection.send({"get_destination_establishment_rate": destination_hash}) + response = self.rpc_connection.recv() + return response + except Exception as e: + ed = "Error while getting destination link etablishment rate over RPC: "+str(e) + RNS.log(ed, RNS.LOG_DEBUG) + return None + def __start_rpc_listener(self): try: RNS.log("Starting RPC listener", RNS.LOG_DEBUG) @@ -1621,6 +1659,8 @@ class SidebandCore(): connection.send(True) elif "get_plugins_info" in call: connection.send(self._get_plugins_info()) + elif "get_destination_establishment_rate" in call: + connection.send(self._get_destination_establishment_rate(call["get_destination_establishment_rate"])) elif "send_message" in call: args = call["send_message"] send_result = self.send_message( diff --git a/sbapp/ui/objectdetails.py b/sbapp/ui/objectdetails.py index 6acb51f..38d0074 100644 --- a/sbapp/ui/objectdetails.py +++ b/sbapp/ui/objectdetails.py @@ -796,14 +796,10 @@ class RVDetails(MDRecycleView): self.entries.append({"icon": "routes", "text": f"Current path on [b]{nhi}[/b]", "on_release": pass_job}) try: - mr = self.delegate.app.sideband.message_router - oh = self.delegate.object_hash - if oh in mr.direct_links: - ol = mr.direct_links[oh] - ler = ol.get_establishment_rate() - if ler: - lers = RNS.prettyspeed(ler, "b") - self.entries.append({"icon": "lock-check-outline", "text": f"Direct link established, LER is [b]{lers}[/b]", "on_release": pass_job}) + ler = self.delegate.app.sideband.get_destination_establishment_rate(self.delegate.object_hash) + if ler: + lers = RNS.prettyspeed(ler, "b") + self.entries.append({"icon": "lock-check-outline", "text": f"Direct link established, LER is [b]{lers}[/b]", "on_release": pass_job}) except Exception as e: RNS.trace_exception(e)