Skip to content

Commit

Permalink
fruity: Handle USB TunnelConnection dropping
Browse files Browse the repository at this point in the history
Which happens on e.g. an iOS userspace reboot.
  • Loading branch information
oleavr committed Sep 18, 2024
1 parent 24dc7f4 commit 539f359
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/fruity/device-monitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,7 @@ namespace Frida.Fruity {
ncm_peer = yield NcmPeer.locate (usb_device, cancellable);

tunnel = new PortableUsbTunnel (usb_device, ncm_peer, pairing_store);
tunnel.lost.connect (on_tunnel_lost);
try {
yield tunnel.open (cancellable);
} catch (Error e) {
Expand All @@ -1208,6 +1209,10 @@ namespace Frida.Fruity {
throw_api_error (e);
}
}

private void on_tunnel_lost () {
tunnel_request = null;
}
}

private class NcmPeer {
Expand Down Expand Up @@ -1420,6 +1425,8 @@ namespace Frida.Fruity {
}

private sealed class PortableUsbTunnel : Object, Tunnel {
public signal void lost ();

public UsbDevice usb_device {
get;
construct;
Expand Down Expand Up @@ -1474,6 +1481,7 @@ namespace Frida.Fruity {
var pairing_service = yield PairingService.open (pairing_transport, pairing_store, cancellable);

TunnelConnection tc = yield pairing_service.open_tunnel (ncm_peer.ip, netstack, cancellable);
tc.close.connect (on_tunnel_connection_close);

var rsd_endpoint = (InetSocketAddress) Object.new (typeof (InetSocketAddress),
address: tc.remote_address,
Expand Down Expand Up @@ -1505,6 +1513,10 @@ namespace Frida.Fruity {
);
return yield netstack.open_tcp_connection (endpoint, cancellable);
}

private void on_tunnel_connection_close () {
lost ();
}
}

private sealed class PortableCoreDeviceNetworkTransport : Object, Transport {
Expand Down
4 changes: 4 additions & 0 deletions src/fruity/xpc.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,8 @@ namespace Frida.Fruity {
}

public sealed class TunnelConnection : Object, AsyncInitable {
public signal void close ();

public InetSocketAddress address {
get;
construct;
Expand Down Expand Up @@ -2021,6 +2023,8 @@ namespace Frida.Fruity {
}

public void cancel () {
if (connection != null)
close ();
connection = null;
socket = null;

Expand Down

0 comments on commit 539f359

Please sign in to comment.