Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit f63c256

Browse files
committed
WIP: Add protos and updated protos for mitm_mapper
1 parent 831384a commit f63c256

38 files changed

+106076
-538
lines changed

mapadroid/data_handler/StandaloneMitmMapperAndStatsHandler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ async def stats_collect_seen_type(self, encounter_ids: List[int], type_of_detect
8181
async def get_last_possibly_moved(self, worker: str) -> int:
8282
return await self.__mitm_data_handler.get_last_possibly_moved(worker)
8383

84-
async def update_latest(self, worker: str, key: str, value: Union[list, dict], timestamp_received_raw: float = None,
84+
async def update_latest(self, worker: str, key: str, value: Union[List, Dict, bytes],
85+
timestamp_received_raw: float = None,
8586
timestamp_received_receiver: float = None, location: Location = None) -> None:
8687
loop = asyncio.get_running_loop()
87-
loop.run_in_executor(None, self.__mitm_data_handler.update_latest, worker, key, value, timestamp_received_raw,
88+
loop.run_in_executor(None, self.__mitm_data_handler.update_latest, worker, key, value,
89+
timestamp_received_raw,
8890
timestamp_received_receiver, location)
8991

9092
async def request_latest(self, worker: str, key: str,

mapadroid/data_handler/grpc/MitmMapperClient.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def get_last_possibly_moved(self, worker: str) -> int:
6868
# TODO: Return time.time() to continue scans or throw a custom exception that needs to be handled?
6969
return 0
7070

71-
async def update_latest(self, worker: str, key: str, value: Union[List, Dict],
71+
async def update_latest(self, worker: str, key: str, value: Union[List, Dict, bytes],
7272
timestamp_received_raw: float = None,
7373
timestamp_received_receiver: float = None, location: Location = None) -> None:
7474
request: mitm_mapper_pb2.LatestMitmDataEntryUpdateRequest = mitm_mapper_pb2.LatestMitmDataEntryUpdateRequest()
@@ -86,6 +86,8 @@ async def update_latest(self, worker: str, key: str, value: Union[List, Dict],
8686
request.data.some_list.extend(value)
8787
elif isinstance(value, dict):
8888
request.data.some_dictionary.update(value)
89+
elif isinstance(value, bytes):
90+
request.data.raw_message = value
8991
else:
9092
raise ValueError("Cannot handle data")
9193
try:

mapadroid/data_handler/mitm_data/AbstractMitmMapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def get_last_possibly_moved(self, worker: str) -> int:
1515
pass
1616

1717
@abstractmethod
18-
async def update_latest(self, worker: str, key: str, value: Union[List, Dict],
18+
async def update_latest(self, worker: str, key: str, value: Union[List, Dict, bytes],
1919
timestamp_received_raw: float = None,
2020
timestamp_received_receiver: float = None, location: Location = None) -> None:
2121
pass

mapadroid/data_handler/mitm_data/MitmMapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self):
1919
async def get_last_possibly_moved(self, worker: str) -> int:
2020
return await self._mitm_data_handler.get_last_possibly_moved(worker)
2121

22-
async def update_latest(self, worker: str, key: str, value: Union[List, Dict],
22+
async def update_latest(self, worker: str, key: str, value: Union[List, Dict, bytes],
2323
timestamp_received_raw: float = None,
2424
timestamp_received_receiver: float = None, location: Location = None) -> None:
2525
loop = asyncio.get_running_loop()

mapadroid/data_handler/mitm_data/RedisMitmMapper.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from mapadroid.db.DbWrapper import DbWrapper
1414
from mapadroid.utils.ProtoIdentifier import ProtoIdentifier
1515
from mapadroid.utils.collections import Location
16+
import mapadroid.mitm_receiver.protos.Rpc_pb2 as pogoprotos
1617

1718

1819
class RedisMitmMapper(AbstractMitmMapper):
@@ -46,7 +47,7 @@ async def get_last_possibly_moved(self, worker: str) -> int:
4647
last_moved: Optional[int] = await self.__cache.get(RedisMitmMapper.LAST_POSSIBLY_MOVED_KEY.format(worker))
4748
return int(last_moved) if last_moved else 0
4849

49-
async def update_latest(self, worker: str, key: str, value: Union[List, Dict],
50+
async def update_latest(self, worker: str, key: str, value: Union[List, Dict, bytes],
5051
timestamp_received_raw: float = None,
5152
timestamp_received_receiver: float = None, location: Location = None) -> None:
5253
if timestamp_received_raw is None:
@@ -71,12 +72,18 @@ async def update_latest(self, worker: str, key: str, value: Union[List, Dict],
7172
await self.__parse_gmo_for_location(worker, value, timestamp_received_raw, location)
7273
await self.__cache.set(RedisMitmMapper.IS_INJECTED_KEY.format(worker), 1)
7374

74-
async def __parse_gmo_for_location(self, worker: str, gmo_payload: Dict, timestamp: int,
75+
async def __parse_gmo_for_location(self, worker: str, gmo_payload: Union[Dict, bytes], timestamp: int,
7576
location: Optional[Location]):
76-
cells = gmo_payload.get("cells", None)
77-
if not cells:
78-
return
79-
cell_ids: List[int] = [cell['id'] for cell in cells]
77+
if isinstance(gmo_payload, dict):
78+
cells = gmo_payload.get("cells", None)
79+
if not cells:
80+
return
81+
cell_ids: List[int] = [cell['id'] for cell in cells]
82+
else:
83+
# Raw proto...
84+
gmo_proto: pogoprotos.GetMapObjectsOutProto = pogoprotos.GetMapObjectsOutProto.ParseFromString(
85+
gmo_payload)
86+
cell_ids: List[int] = [cell.s2_cell_id for cell in gmo_proto.map_cell]
8087
last_cell_ids_raw: Optional[str] = await self.__cache.get(RedisMitmMapper.LAST_CELL_IDS_KEY.format(worker))
8188
last_cell_ids: List[int] = []
8289
if last_cell_ids_raw:

mapadroid/data_handler/mitm_data/holder/latest_mitm_data/LatestMitmDataEntry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
class LatestMitmDataEntry:
1111
def __init__(self, location: Optional[Location], timestamp_received: Optional[int],
12-
timestamp_of_data_retrieval: Optional[int], data: Union[List, Dict]):
12+
timestamp_of_data_retrieval: Optional[int], data: Union[List, Dict, bytes]):
1313
self.location: Optional[Location] = location
1414
# The time MAD received the data from a device/worker
1515
self.timestamp_received: Optional[int] = timestamp_received
1616
# The time that the device/worker received the data
1717
self.timestamp_of_data_retrieval: Optional[int] = timestamp_of_data_retrieval
18-
self.data: Union[List, Dict] = data
18+
self.data: Union[List, Dict, bytes] = data
1919

2020
@staticmethod
2121
async def from_json(json_data: Union[bytes, str]) -> Optional[LatestMitmDataEntry]:

0 commit comments

Comments
 (0)