squash more bugs

This commit is contained in:
JJTech0130 2023-08-17 22:05:18 -04:00
parent 931bb00caa
commit 9822d6f66f
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6
4 changed files with 14 additions and 12 deletions

View file

@ -100,7 +100,11 @@ class APNSConnection:
# Check if anything currently in the queue matches the id # Check if anything currently in the queue matches the id
for payload in self._incoming_queue: for payload in self._incoming_queue:
if payload.id == id: if payload.id == id:
return payload if filter is not None:
if filter(payload):
return payload
else:
return payload
while True: while True:
await self._queue_park.wait() # Wait for a new payload to be added to the queue await self._queue_park.wait() # Wait for a new payload to be added to the queue
logger.debug(f"Woken by event, checking for {id}") logger.debug(f"Woken by event, checking for {id}")
@ -256,6 +260,7 @@ class APNSConnection:
async def send_notification(self, topic: str, payload: bytes, id=None): async def send_notification(self, topic: str, payload: bytes, id=None):
"""Sends a notification to the APNs server""" """Sends a notification to the APNs server"""
logger.debug(f"Sending notification to topic {topic}")
if id is None: if id is None:
id = random.randbytes(4) id = random.randbytes(4)
@ -280,7 +285,7 @@ class APNSConnection:
"""Waits for a notification to be received, and acks it""" """Waits for a notification to be received, and acks it"""
def f(payload: APNSPayload): def f(payload: APNSPayload):
if payload.fields_with_id(1)[0].value != sha1(topic.encode()).digest(): if payload.fields_with_id(2)[0].value != sha1(topic.encode()).digest():
return False return False
if filter is not None: if filter is not None:
return filter(payload) return filter(payload)

View file

@ -23,15 +23,15 @@ logging.getLogger("py.warnings").setLevel(logging.ERROR) # Ignore warnings from
logging.getLogger("asyncio").setLevel(logging.WARNING) logging.getLogger("asyncio").setLevel(logging.WARNING)
logging.getLogger("jelly").setLevel(logging.INFO) logging.getLogger("jelly").setLevel(logging.INFO)
logging.getLogger("nac").setLevel(logging.INFO) logging.getLogger("nac").setLevel(logging.INFO)
logging.getLogger("apns").setLevel(logging.DEBUG) logging.getLogger("apns").setLevel(logging.INFO)
logging.getLogger("albert").setLevel(logging.INFO) logging.getLogger("albert").setLevel(logging.INFO)
logging.getLogger("ids").setLevel(logging.DEBUG) logging.getLogger("ids").setLevel(logging.DEBUG)
logging.getLogger("bags").setLevel(logging.INFO) logging.getLogger("bags").setLevel(logging.INFO)
logging.getLogger("imessage").setLevel(logging.DEBUG) logging.getLogger("imessage").setLevel(logging.INFO)
logging.captureWarnings(True) logging.captureWarnings(True)
process = Popen(["git", "rev-parse", "HEAD"], stdout=PIPE) process = Popen(["git", "rev-parse", "HEAD"], stdout=PIPE) # type: ignore
(commit_hash, err) = process.communicate() (commit_hash, err) = process.communicate()
exit_code = process.wait() exit_code = process.wait()
commit_hash = commit_hash.decode().strip() commit_hash = commit_hash.decode().strip()

View file

@ -55,7 +55,6 @@ async def lookup(
if body is None: if body is None:
return False return False
body = plistlib.loads(body) body = plistlib.loads(body)
logging.warning(body.get('U'))
return body.get('U') == msg_id return body.get('U') == msg_id
payload = await conn.expect_notification(topic, check) payload = await conn.expect_notification(topic, check)

View file

@ -626,21 +626,19 @@ class iMessageUser:
await self.connection.send_notification(topic, body, message_id) await self.connection.send_notification(topic, body, message_id)
async def _receive_raw(self, c: int, topic: str) -> dict | None: async def _receive_raw(self, c: int, topic: str) -> dict:
def check(payload: apns.APNSPayload): def check(payload: apns.APNSPayload):
# Check if the "c" key matches # Check if the "c" key matches
body = payload.fields_with_id(3)[0].value body = payload.fields_with_id(3)[0].value
if body is None: if body is None:
return False return False
body = plistlib.loads(body) body = plistlib.loads(body)
if not "c" in body or "c" != c: if not "c" in body or body["c"] != c:
return False return False
return True return True
payload = await self.connection.expect_notification(topic, check) payload = await self.connection.expect_notification(topic, check)
if payload is None:
return None
body = payload.fields_with_id(3)[0].value body = payload.fields_with_id(3)[0].value
body = plistlib.loads(body) body = plistlib.loads(body)
return body return body
@ -713,8 +711,8 @@ class iMessageUser:
while count < total and time.time() - start < 2: while count < total and time.time() - start < 2:
resp = await self._receive_raw(255, topic) resp = await self._receive_raw(255, topic)
if resp is None: #if resp is None:
continue # continue
count += 1 count += 1
logger.debug(f"Received response : {resp}") logger.debug(f"Received response : {resp}")