thaliproject / Thali_CordovaPlugin

Thali p2p plugin
MIT License
226 stars 44 forks source link

Investigate Wifi Direct use for Thali #1475

Open yaronyg opened 7 years ago

yaronyg commented 7 years ago

Scenario: Bluetooth... slow. Wifi.... faster.

Problem: Ideally we would just use Wifi Direct and call it a day. But Android implements a policy that requires users to confirm Wifi Direct connections. Bad.

Work Around: In theory what we can do is have one of the Android phones be a Wifi Direct Hot Spot. That can be done without interfering with normal wifi functionality. However, unless we use the Wifi Direct client ApI (and trigger the stupid permission dialog) we have to change the other's WifiManager to point at the first phone's hot spot. We would move the SSID and Password over BLE or Bluetooth.

Investigation:

  1. Fire up the code in BTLib to make sure it still behaves itself properly in terms of forming Wifi Direct Hot Spots and connecting to them.
  2. Take a look at NetworkRequest.Builder and see if there is anyway to use setNetworkSpecifier to open two simultaneous Wifi connections (I'm guessing not but I'm desperate).
  3. Measure the kind of bandwidth we get on these hotspot connections and how the bandwidth changes as more peers connect to the hotspot (e.g. do we get a linear degradation in speed or super linear?)
  4. Measure how long it takes to start a wifi hotspot and how long it takes a phone to connect to that Hotspot.
  5. How do we do IP address assignments? I just don't remember anymore how this was handled. How does the client get an IP address to use over the wifi connection? I assume we use non-routable addresses for clients and use ARP or something to claim them. What about the server? What address should it use? How does it get it?
  6. We have to test that we can successfully run SSDP which means we have access to multicast channels.
evabishchevich commented 7 years ago

Priority: 2, 6, 3, 4.

evabishchevich commented 7 years ago

NetworkRequest is not suitable for our scenario

yaronyg commented 7 years ago

NetworkRequest is 'passive'. You say "IF there is a Wifi connection with the following characteristics then we will connect" but we can't force the connection. So we can't use it.

Now we are investigating multicast support.

evabishchevich commented 7 years ago

I meant "If we already have a connection with the following characteristics we will send our data"

yaronyg commented 7 years ago

Multicast seems to work between devices connected to the group owner but the group owner doesn't seem able to listen.

So let's focus for now on what is the data perf over Wifi? And how long does it take to connect (and can we do it reliably?)

evabishchevich commented 7 years ago

I implemented base version of the test to measure the following commands chain:

  1. Find network
  2. Connect to that network
  3. Get system notification that we successfully connected

I ran described test around 10 times on Samsung S6 and got results from 1900 to 4900 milliseconds

evabishchevich commented 7 years ago

An interesting fact: On Nexus 6p and HTC 10 if we call createGroup in wifi direct, the name and the password of the created access point is always the same for particular phone. On Samsungs S6 and S7 the name and the pass are different between createGroup calls.

yaronyg commented 7 years ago

For some reason we can't setup connections. We are getting 'network unreachable' errors and we can't find any obvious reason for it.

yaronyg commented 7 years ago
  1. Figure out what the bandwidth is.
  2. We should investigate proper wifi direct, with the dialog and everything. If that works properly then if we have say 3 phones and they all want to connect to each other, will that work? in other words, can a single phone connect to multiple simultaneous wifi direct groups?
  3. If phone A has joined B's group, what happens if phone B tries to join A's group?
  4. If someone accidentally says no to the wifi direct permission dialog, what happens if we try to join that wifi direct group again?