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

Multiple devices not working with autorun and autostart #134

Closed
opensourcer2 opened this issue Jul 30, 2018 · 10 comments
Closed

Multiple devices not working with autorun and autostart #134

opensourcer2 opened this issue Jul 30, 2018 · 10 comments
Assignees

Comments

@opensourcer2
Copy link

I am running on RPi with Raspian Stretch. I manually install apk onto two devices. Running ./gnirehtet autorun or ./gnirehtet autostart and then connecting two devices simultaneously, only one device will work. The other device always show Disconnected from relay server. However, if I run ./gnirehtet start [serial] for each device, then both devices work. Does autorun only support a single device at a time? Is it possible to make it support multiple devices simultaneously?

@rom1v
Copy link
Collaborator

rom1v commented Jul 31, 2018

Does the other device disappear temporarily when you plug a new one?

Stop gnirehtet, unplug all the devices, and execute:

echo 0012host:track-devices | netcat localhost 5037

while it's running, plug one device, then the other. Could you paste the result, please?

Do the same with:

echo 0012host:track-devices | netcat localhost 5037 | hd

@opensourcer2
Copy link
Author

No. The first device remained working and did not disappear when the second one is plugged in.
When executing
echo 0012host:track-devices | netcat localhost 5037
I got
OKAY0000
Then plugging the first device shows

0018VS425PP28c4a5a8	offline
0017VS425PP28c4a5a8	device

Plugging in the second one shows

002eLGH3456aa1d25a	offline
VS425PP28c4a5a8	device
002dLGH3456aa1d25a	device
VS425PP28c4a5a8	device

Running
echo 0012host:track-devices | netcat localhost 5037 | hd
shows no ouput.
After plugging in the first device it shows

00000000  4f 4b 41 59 30 30 30 30  30 30 31 38 56 53 34 32  |OKAY00000018VS42|
00000010  35 50 50 32 38 63 34 61  35 61 38 09 6f 66 66 6c  |5PP28c4a5a8.offl|
00000020  69 6e 65 0a 30 30 31 37  56 53 34 32 35 50 50 32  |ine.0017VS425PP2|

Continue to plug in the second one it additionally shows

00000030  38 63 34 61 35 61 38 09  64 65 76 69 63 65 0a 30  |8c4a5a8.device.0|
00000040  30 32 65 4c 47 48 33 34  35 36 61 61 31 64 32 35  |02eLGH3456aa1d25|
00000050  61 09 6f 66 66 6c 69 6e  65 0a 56 53 34 32 35 50  |a.offline.VS425P|
00000060  50 32 38 63 34 61 35 61  38 09 64 65 76 69 63 65  |P28c4a5a8.device|
00000070  0a 30 30 32 64 4c 47 48  33 34 35 36 61 61 31 64  |.002dLGH3456aa1d|
00000080  32 35 61 09 64 65 76 69  63 65 0a 56 53 34 32 35  |25a.device.VS425|
00000090  50 50 32 38 63 34 61 35  61 38 09 64 65 76 69 63  |PP28c4a5a8.devic|

@rom1v
Copy link
Collaborator

rom1v commented Jul 31, 2018

Thank you for the results. They are as expected.

I can't reproduce the problem. With 2 devices, gnirehtet autorun enables reverse tethering on both devices. gnirehtet autostart correctly starts the client on both devices (and prints Disconnected from relay server if the relay server is not started).

@opensourcer2
Copy link
Author

OK Thanks. I will investigate further and report back.

@opensourcer2
Copy link
Author

opensourcer2 commented Aug 1, 2018

I investigate a little more and found that if both devices were plugged in before running autorun, then when I execute autorun, neither devices have reverse tethering enabled. It just stop after relay is started but no client connected.

pi@raspberrypi:~/gnirehtet-java $ ./gnirehtet autorun
2018-08-01 05:34:02.659 I Gnirehtet: Starting relay server...
2018-08-01 05:34:02.707 I Relay: Relay server started

When only one device is plugged in before running autorun, then it works

pi@raspberrypi:~/gnirehtet-java $ ./gnirehtet autorun
2018-08-01 05:20:46.886 I Gnirehtet: Starting relay server...
2018-08-01 05:20:46.934 I Relay: Relay server started
2018-08-01 05:20:47.624 I TunnelServer: Client #0 connected
2018-08-01 05:20:47.710 I TCPConnection: TCP 10.0.0.2:42981 -> 203.205.146.46:443 Open

Please see if you can reproduce this situation.

@rom1v
Copy link
Collaborator

rom1v commented Aug 1, 2018

You're right, it's broken. I first thought it was only the java version, but in fact the Rust version is also affected. I was confused because when I tested the client was already started, so the problem was not visible.

The problem is that I assumed that the track-devices command was sending 1 message per device, but it may in fact send 1 message for several devices at once (the whole list), separated by \n. https://android.googlesource.com/platform/system/core/+/oreo-release/adb/SERVICES.TXT#27

I will work on that when I have some time.

@rom1v rom1v added the bug label Aug 1, 2018
@rom1v rom1v self-assigned this Aug 1, 2018
rom1v added a commit that referenced this issue Aug 4, 2018
The old implementation assumed that track-devices provided one device
state per packet (the one that have changed). In fact, it always resends
the whole list:
<https://android.googlesource.com/platform/system/core/+/oreo-release/adb/SERVICES.TXT#27>

Therefore, keep the last connected devices list, parse the new list and
start gnirehtet client on new connected devices.

Fixes <#134>.
@rom1v
Copy link
Collaborator

rom1v commented Aug 4, 2018

I just fixed this bug on master. Please test and reopen if you still encounter issues.

@rom1v rom1v closed this as completed Aug 4, 2018
@rom1v
Copy link
Collaborator

rom1v commented Sep 3, 2018

Included in v2.3 released today.

@mythsman
Copy link

Does the other device disappear temporarily when you plug a new one?

Stop gnirehtet, unplug all the devices, and execute:

echo 0012host:track-devices | netcat localhost 5037

while it's running, plug one device, then the other. Could you paste the result, please?

Do the same with:

echo 0012host:track-devices | netcat localhost 5037 | hd

I don't know why , but in my pc , I will get FAIL0014unknown host service% if I don't add -n option in echo command.

@HMaker
Copy link

HMaker commented Mar 31, 2022

I don't know why , but in my pc , I will get FAIL0014unknown host service% if I don't add -n option in echo command.

@mythsman This is because echo by default appends a trailling new line to the message, -n removes that.

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

No branches or pull requests

4 participants