Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto stop gnirehtet app when disconnected #51

Open
twoi opened this issue Oct 19, 2017 · 14 comments · May be fixed by #399
Open

Auto stop gnirehtet app when disconnected #51

twoi opened this issue Oct 19, 2017 · 14 comments · May be fixed by #399

Comments

@twoi
Copy link

twoi commented Oct 19, 2017

In #49, we managed to come up with a script that automatically reestablishes the connection - which is great.

Now I also have a usb wired ethernet device, that I use alternatively with this reverse tethering solution. However, when the gnirehtet app is running on the device - and it stays running after pulling the plug - I cannot use the wired ethernet device until I stop gnirehtet. Then ethernet works, and when I switch back to reverse tethering, that works as well, as #49 restarts the app on the device.

So all I seem to need now to be 100% happy with this great tool, is the app to auto-stop when the usb cable is disconnected. Does it make sense to keep it running after unplugging in the first place? Because unplugging and replugging does not do the trick even when the app is running - hence the need for the script in #49 - and #49 does not require the app to stay running either. So unless there are scenarios I am not aware off, the gnirethet app should auto stop by default.

@Biswa96
Copy link

Biswa96 commented Oct 20, 2017

Yeah, it stops by default when you disconnect USB from PC. The relay server shows client disconnected.
Are you talking about this notification? Just tap it to stop. 😒

client_stop

@twoi
Copy link
Author

twoi commented Oct 20, 2017

@Biswa96 The app on the Android device continues running. The notification item (whatever the technical Android term for this would be) reads "Disconnected from the relay server" and displays a "STOP GNIREHTET" button.

@rom1v
Copy link
Collaborator

rom1v commented Oct 20, 2017

Does it make sense to keep it running after unplugging in the first place?

The rationale is that a user may use gnirehtet to connect to the trusted desktop network, and don't want to leak data if it switches back automatically to mobile network. That's why I wanted this action to be manual. (In practice, we detect the socket disconnection, not the cable unplug.)

However, we might consider adding an option to get the behavior you request, something like:

adb start -d   # disable on disconnect

@twoi
Copy link
Author

twoi commented Oct 20, 2017

OK, I see.

Having the -d parameter would work perfect for me! Except that -d is already taken - to override thedefault DNS server.

I haven't looked at the sources yet, and I'm sure you'd be able to implement this feature in 15 minutes, but if you'd prefer a pull request, do let me know.

I guess this would involve changes to all 3 projects:

  1. the desktop side java code and
  2. the rust code,
    to accept and forward the parameter to the android app and
  3. the android java app to accept the parameter from the server and actually implement the feature

@rom1v
Copy link
Collaborator

rom1v commented Oct 20, 2017

Except that -d is already taken - to override the default DNS server.

Ahah, I managed to get a name conflict with only 2 parameters 😆.

but if you'd prefer a pull request, do let me know

If you're motivated, please do :) (start on the dev branch)

If you want to implement only the java or only the rust part, I'll take care of the other if necessary.

I guess this would involve changes to all 3 projects

Correct 👍

@rom1v
Copy link
Collaborator

rom1v commented Feb 6, 2018

@twoi Do you still consider implementing the option?

@svladimirs
Copy link

adb start -d # disable on disconnect
Where and when I must do this? Before or after '@gnirehtet.exe autorun'?

@rom1v
Copy link
Collaborator

rom1v commented Mar 14, 2018

Where and when I must do this?

For now, never, it's not implemented.

@midluk
Copy link

midluk commented May 7, 2018

I use gnirehtet when I have wired network on my notebook but only unreliable wifi and/or mobile data connection. I definitely want those connection methods used when I unplug my phone (better have unreliable connection than none at all, and the connection might be better at the place I move my phone to after unplugging). But currently I always have to unlock my phone to stop gnirehtet. There definitely should be an option to stop the app automatically.
I can see the uses of preventing data from going through other untrusted channels, but are you sure that that use case is important for a majority of users?

@rom1v
Copy link
Collaborator

rom1v commented May 7, 2018

There definitely should be an option to stop the app automatically.

I'm ok with that.

I can see the uses of preventing data from going through other untrusted channels, but are you sure that that use case is important for a majority of users?

I don't know, but IMO it should have the "safe" behavior by default. As an explicit option, it's ok.

@rom1v
Copy link
Collaborator

rom1v commented Sep 18, 2018

I'll probably add an option when I have some time, but meanwhile you can just apply this change:

diff --git a/app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java b/app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java
index 7e8b716..70732cc 100644
--- a/app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java
+++ b/app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java
@@ -224,7 +224,7 @@ public class GnirehtetService extends VpnService {
                     break;
                 case RelayTunnelListener.MSG_RELAY_TUNNEL_DISCONNECTED:
                     Log.d(TAG, "Relay tunnel disconnected");
-                    vpnService.notifier.setFailure(true);
+                    vpnService.stop(vpnService);
                     break;
                 default:
             }

@tango25001
Copy link

Can someone tell me, how i get this change into the app? Thank you very much

@tango25001
Copy link

Hello I compiled the app with the above mentioned changes ans it worked fine so far - up to Android 9.

I bought a new Samsung Android 10 device and now the app does not exit automatically. Is there a solution for that?

Thank you!

@simonferndriger
Copy link

simonferndriger commented Sep 2, 2022

Hi

How can I use this if I can't compile this special feature but want to use it nevertheless? Can anyone release a version 2.6 with this addition please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants