Skip to content

Commit

Permalink
Merge pull request #957 from doronz88/bugfix/multi-iterated-bonjour-ips
Browse files Browse the repository at this point in the history
lockdown: fix handling of same ip from bonjour answers
  • Loading branch information
doronz88 authored Apr 24, 2024
2 parents a4f86f1 + d1c8be5 commit 9d8c1b6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ jobs:
matrix:
python-version: [ 3.8, 3.9, "3.10", "3.11", "3.12" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
exclude:
- os: macos-latest
python-version: 3.8
- os: macos-latest
python-version: 3.9

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Lint with flake8
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
5 changes: 5 additions & 0 deletions pymobiledevice3/lockdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ async def get_mobdev2_lockdowns(
record = plistlib.loads(file.read_bytes())
records[record['WiFiMACAddress']] = record

iterated_ips = set()
for answer in await browse_mobdev2(timeout=timeout):
if '@' not in answer.name:
continue
Expand All @@ -816,6 +817,10 @@ async def get_mobdev2_lockdowns(
continue

for ip in answer.ips:
if ip in iterated_ips:
# skip ips we already iterated over, possibly from previous queries
continue
iterated_ips.add(ip)
try:
lockdown = create_using_tcp(hostname=ip, autopair=False, pair_record=record)
except Exception:
Expand Down
11 changes: 6 additions & 5 deletions pymobiledevice3/tunneld.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def start(self) -> None:

def tunnel_exists_for_udid(self, udid: str) -> bool:
for task in self.tunnel_tasks.values():
if task.udid == udid and task.tunnel is not None:
if (task.udid == udid) and (task.tunnel is not None):
return True
return False

Expand Down Expand Up @@ -163,14 +163,15 @@ async def monitor_mobdev2_task(self) -> None:
if self.tunnel_exists_for_udid(lockdown.udid):
# skip tunnel if already exists for this udid
continue
task_identifier = f'mobdev2-{lockdown.udid}-{ip}'
try:
tunnel_service = CoreDeviceTunnelProxy(lockdown)
except InvalidServiceError:
logger.warning(f'[{lockdown.udid}-{ip}] failed to start CoreDeviceTunnelProxy - skipping')
logger.warning(f'[{task_identifier}] failed to start CoreDeviceTunnelProxy - skipping')
continue
self.tunnel_tasks[ip] = TunnelTask(
task=asyncio.create_task(self.start_tunnel_task(ip, tunnel_service),
name=f'start-tunnel-task-mobdev2-{ip}'),
self.tunnel_tasks[task_identifier] = TunnelTask(
task=asyncio.create_task(self.start_tunnel_task(task_identifier, tunnel_service),
name=f'start-tunnel-task-{task_identifier}'),
udid=lockdown.udid
)
await asyncio.sleep(MOVDEV2_INTERVAL)
Expand Down

0 comments on commit 9d8c1b6

Please sign in to comment.