Perform telemetry requests and updates via service on Android. Update service heartbeat monitoring.

This commit is contained in:
Mark Qvist 2024-09-16 09:59:21 +02:00
parent 6038bc541c
commit 548663655b
1 changed files with 196 additions and 114 deletions

View File

@ -1205,8 +1205,37 @@ class SidebandCore():
else:
self.setstate(f"telemetry.{RNS.hexrep(message.destination_hash, delimit=False)}.request_sending", False)
def _service_request_latest_telemetry(self, from_addr=None):
if not RNS.vendor.platformutils.is_android():
return False
else:
if self.is_client:
try:
if self.rpc_connection == None:
self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
self.rpc_connection.send({"request_latest_telemetry": {"from_addr": from_addr}})
response = self.rpc_connection.recv()
return response
except Exception as e:
RNS.log("Error while requesting latest telemetry over RPC: "+str(e), RNS.LOG_DEBUG)
RNS.trace_exception(e)
return False
else:
return False
def request_latest_telemetry(self, from_addr=None):
if self.allow_service_dispatch and self.is_client:
try:
return self._service_request_latest_telemetry(from_addr)
except Exception as e:
RNS.log("Error requesting latest telemetry: "+str(e), RNS.LOG_ERROR)
RNS.trace_exception(e)
return "not_sent"
else:
if from_addr == None or from_addr == self.lxmf_destination.hash:
return "no_address"
else:
@ -1255,8 +1284,41 @@ class SidebandCore():
else:
return "not_sent"
def _service_send_latest_telemetry(self, to_addr=None, stream=None, is_authorized_telemetry_request=False):
if not RNS.vendor.platformutils.is_android():
return False
else:
if self.is_client:
try:
if self.rpc_connection == None:
self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
self.rpc_connection.send({"send_latest_telemetry": {
"to_addr": to_addr,
"stream": stream,
"is_authorized_telemetry_request": is_authorized_telemetry_request}
})
response = self.rpc_connection.recv()
return response
except Exception as e:
RNS.log("Error while sending latest telemetry over RPC: "+str(e), RNS.LOG_DEBUG)
RNS.trace_exception(e)
return False
else:
return False
def send_latest_telemetry(self, to_addr=None, stream=None, is_authorized_telemetry_request=False):
if self.allow_service_dispatch and self.is_client:
try:
return self._service_send_latest_telemetry(to_addr, stream, is_authorized_telemetry_request)
except Exception as e:
RNS.log("Error requesting latest telemetry: "+str(e), RNS.LOG_ERROR)
RNS.trace_exception(e)
return "not_sent"
else:
if to_addr == None or to_addr == self.lxmf_destination.hash:
return "no_address"
else:
@ -1400,6 +1462,7 @@ class SidebandCore():
return []
def service_available(self):
heartbeat_stale_time = 7.5
now = time.time()
service_heartbeat = self.getstate("service.heartbeat")
if not service_heartbeat:
@ -1407,9 +1470,16 @@ class SidebandCore():
return False
else:
try:
if now - service_heartbeat > 4.0:
RNS.log("Stale service heartbeat at "+str(now), RNS.LOG_DEBUG)
if now - service_heartbeat > heartbeat_stale_time:
RNS.log("Stale service heartbeat at "+str(now)+", retrying...", RNS.LOG_DEBUG)
now = time.time()
service_heartbeat = self.getstate("service.heartbeat")
if now - service_heartbeat > heartbeat_stale_time:
RNS.log("Service heartbeat did not recover after retry", RNS.LOG_DEBUG)
return False
else:
RNS.log("Service heartbeat recovered at"+str(time), RNS.LOG_DEBUG)
return True
else:
return True
except Exception as e:
@ -1680,6 +1750,18 @@ class SidebandCore():
args["destination_hash"],
args["propagation"])
connection.send(send_result)
elif "request_latest_telemetry" in call:
args = call["request_latest_telemetry"]
send_result = self.request_latest_telemetry(args["from_addr"])
connection.send(send_result)
elif "send_latest_telemetry" in call:
args = call["send_latest_telemetry"]
send_result = self.send_latest_telemetry(
to_addr=args["to_addr"],
stream=args["stream"],
is_authorized_telemetry_request=args["is_authorized_telemetry_request"]
)
connection.send(send_result)
elif "get_lxm_progress" in call:
args = call["get_lxm_progress"]
connection.send(self.get_lxm_progress(args["lxm_hash"]))