Get link establishment rates via service on Android

This commit is contained in:
Mark Qvist 2024-09-14 19:55:25 +02:00
parent 3a952334ad
commit 6038bc541c
2 changed files with 45 additions and 9 deletions

View File

@ -1578,6 +1578,44 @@ class SidebandCore():
RNS.log(ed, RNS.LOG_DEBUG) RNS.log(ed, RNS.LOG_DEBUG)
return ed 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): def __start_rpc_listener(self):
try: try:
@ -1621,6 +1659,8 @@ class SidebandCore():
connection.send(True) connection.send(True)
elif "get_plugins_info" in call: elif "get_plugins_info" in call:
connection.send(self._get_plugins_info()) 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: elif "send_message" in call:
args = call["send_message"] args = call["send_message"]
send_result = self.send_message( send_result = self.send_message(

View File

@ -796,14 +796,10 @@ class RVDetails(MDRecycleView):
self.entries.append({"icon": "routes", "text": f"Current path on [b]{nhi}[/b]", "on_release": pass_job}) self.entries.append({"icon": "routes", "text": f"Current path on [b]{nhi}[/b]", "on_release": pass_job})
try: try:
mr = self.delegate.app.sideband.message_router ler = self.delegate.app.sideband.get_destination_establishment_rate(self.delegate.object_hash)
oh = self.delegate.object_hash if ler:
if oh in mr.direct_links: lers = RNS.prettyspeed(ler, "b")
ol = mr.direct_links[oh] self.entries.append({"icon": "lock-check-outline", "text": f"Direct link established, LER is [b]{lers}[/b]", "on_release": pass_job})
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})
except Exception as e: except Exception as e:
RNS.trace_exception(e) RNS.trace_exception(e)