Allow restart of discovery/advertising without stopping existing connections #2874
Replies: 2 comments 2 replies
-
Following up to see if something like this is on the roadmap or what I might be able to contribute to help support. Also curious if there are any serious technical limitations to something like this. |
Beta Was this translation helpful? Give feedback.
-
There seems to be a few misconceptions. Advertising, Discovery, and Connections are independent of each other. You can stop/start any of them without impacting the others. It's actually recommended that you don't continue to discover while connected if you can avoid it, as scanning will cause performance degradation for connections. It looks like we never exposed ConnectionsClient#updateAdvertisingOptions and ConnectionsClient#updateDiscoveryOptions, which are methods we added to change what you're advertising/scanning without having to stop first. We can definitely fix that. But these are optimizations which patch small issues (such as race conditions if a remote device attempts to connect to you in the window that you stopped/restarted advertising, or an optimization so you don't need to rescan for discovered targets again if you stopped/restarted discovery), and in the meanwhile you can simply stop/restart to change AdvertisingOptions/DiscoveryOptions. StopAllEndpoints is intended for when you are shutting down your application, and will stop Advertising, Discovery, and disconnect all ongoing connections. It's not intended for ongoing usage of Nearby Connections. We don't support mesh networks, and the M to N topology is how many local incoming/outgoing connections are supported at once for a single device. Typically, devices will hit device resource limits after 3-5 connections, although if you're on the same WiFi network as the other devices this limitation is more on the router than the phone. You can build mesh networks on top of Nearby Connections, but you will need to solve for the cases you mentioned (where devices leave/rejoin). |
Beta Was this translation helpful? Give feedback.
-
Background
From the following documentation, it appears that advertising and discovery processes are intended to be one-time operations:
i.e. both methods mention:
Example
Using the collaborative whiteboard example from the nearby connections overview page, let's assume you wanted to use this in a university classroom setting. The only topology that could theoretically support this number of clients (say 20+) would be M-to-N, so from a connectivity standpoint, all nodes are equal peers.
If a student leaves to go to the water fountain and this breaks the mesh (e.g. because they were a single connecting node between two large subgraphs), you would want to be able to reconnect the subgraphs of students without either of the existing graphs collapsing, and also make it easy for the student to rejoin when they come back from the fountain.
Let's say the student that left was
B
, and the nodes they sat between wereA
andC
.B
leaves, producing disconnected subgraphs represented byA
(in the main graph) andC
(in a satellite graph)A
andC
have some localized info about the graph beforeB
left, andC
knows it can try to connect toA
to reconnect the subgraphsC
would like to connect toA
, thenC
would need to callstopAllEndpoints
which would disconnect them from the rest of the satellite graph containingC
The main graph would also have to have at least one client advertising for assimilation to even be possible.
A
wants to start advertising because it is now the only unsaturated node in the main graph (i.e. sinceB
has left)A
has to callstopAllEndpoints
to start advertising againA
to collapse in the same way that the satellite graph containingC
didThis seems to show that both subgraphs have to collapse and completely reorganize any time a key node drops out. It also seems to show that clients which become unsaturated cannot re-enable discovery without breaking the whole graph down, which sort of prohibits allowing other users to drop in after initial graph creation. Leaving discovery on forever is definitely not the answer based on the documentation heavily encouraging users to call
stopDiscovery
after some initial connections are made.So it seems like having someone jump in to an existing connectivity session, or having someone leave and come back is practically very difficult if not impossible. Am I missing something? Is there a way to work around this issue?
I believe that clients can attempt to connect to previously discovered nodes even if discovery is not active, but this seems very brittle since there's no way to actually be sure those nodes are even in range, let alone whether or not they are saturated and willing to accept a connection.
Beta Was this translation helpful? Give feedback.
All reactions