---
# System prepended metadata

title: Requirement

---

![](https://i.imgur.com/y6iZJ50.png)
Brain storming BLE

# Requirement
- Device doesn't need to connect to people that are not in the same topic - so it will use priority and weight

- Device shouldn't connect to two topics if it's part of it. - that will be solved by priority

- Device can be part of a n-group should advertise on all groups that is a member - that should be working as expected. - Check how many services or characteristic can device have.

- Service - Berty only 1 - Limit 20-25 on each device
- Topic - Characteristic
- Descriptor - Available or Not Topic YES/NO

- Usually no limit on how many you can. But after test:
- Services - 20-25 total problem might be PRIMARY_SECONDARY you can change it and should be good but better with characteristics.
- Characteristics - as many as you need tested with 100.
- Descriptor - i believe only 1-5 per characteristic

- Groups can contain n-member - here we have a limit of 4 devices in total so each device can be connected to 3 more without any issue. After that rejects connection.

## Topic priority? - 
Put a weight for each peer based on shared topic between peers.
- peer A is in group 1, 2, 3.
- peer B is in group 1, 3
- peer C is in group 3.
So for peer A, peer B has weight=2, peer C has weight=1

Weight is calculated by how many common groups is shared between the peers.

Problem here is that you will have to actually connect with the other devices to get Characteristic to be able to calculate weight.

App layer knows how many topics are available and shared between people? Topics and the shared weight can be calculated.

App knows Topics and knows people in topics? Yes? so it can calculate weight. 

- Device 1 comes to topic flowers start advertising
- Device 1 leaves flowers now it starts advertising on all topics
- Device 1 enters topic cars start advertising on that topic

- Everybody around me on the same topic is visible to me so i can add anybody but actually connecting to each one we have to request a connect and accept a connection.

- topic everyone on the topic request/accept each other to add and then connect to all on the topic

- problem is reconnect won't work properly if you have topic on cars 10 people pair of 3 will connect next pair of 3 maybe to the next one connectGatt. You can't verify that the first pair of 3 has the next 3 devices 


for(all topics has shared people weight ) {
    people (PeerID) with more weight? connect to them first. We connect to the next weight available
    and if any space left connect to the highest possible weight
    
}


# Scanner
- proceed connections only when it has 3 connections max, so ignore all other found devices

# White list
## add
* device found and the client try to connect to a device
* server is connected to that device


# Workflow

* Device A's scanner found device B, adds it to whitelist, and try to connect
* Device A's scanner found device C, adds it to whitelist, and try to connect
* Device A's scanner found device D, adds it to whitelist, and try to connect
* Device A's scanner found device E, don't add it to whitelist because connection limit reached
* Device A cannot be connected to the device D and after 3 attempt, add device D to the blacklist
* Device A has no connection from Device B and after a timeout of 30s, device A disconnect. It try 3 times and after add device B to the blacklist. Device D is remove from the blacklist to the whitelist if a new device is not being added to the chain in the meantime. If whitelist is full we delete the last removed from blacklist.
* Before deleting Device D, device A's scanner found device E and added it the the whitelist and try to connect to it.

- Don't implement the solution. Device's will eventually reconnect with the device they couldn't after one of the devices drop from the chain. For example we have 5 devices and 1 and 4 couldn't connect but the rest connected. In certain moment device 2 dropped from the chain and after that 1 and 4 reconnect. Now all devices are connected normally. And if any device comes won't be added. Mostly for the Android on IOS might be added 1 more.

- Only implement a limit in the client, no white/black list.
    - device A client connected to C, D, E
    - device A server connected to B, C, D
    - device B client connected to C, D, E 
    - device C client connected to B, D, E - D, C, E
    - device D client connected to B, C, E - B, C, D
    - device E client connected to A, B, C - A, B, C


- device A - B, C, D, fail with D try again with D 
- device B - A, C, E but D was available connected
- device C - A, B,
- device E -> A (drop) 3 connected (stop scanning advertising) 30 sec start again so find C
- device D <- A frozen block (drop)
- all the devices will do the same as E and A at the same time

Connection time will be: time * timeout * devicesCount around

2xtimeouts one is OS and one is your timeout gatt.close so it works

Timeout can be decrease by handling your own cycle to speed up connection between multiple devices.

Something to take in mind that if many devices around timeouts will need more time to success.
Stop scanner when client is connected to 3 devices - stop advertising when server has 3 connections
When the server has 1 connection, the client try to connect to that remote client. The problem is that the client doesn't have the remote 4-digit because it didn't scan that device before. So we can do that only if the server handshake is done.

client device that write and read to the server has a new mac than the one fron the scanner because of privacy this is not always and not all device are like that

A client will connect to the server but the B server/client wont be connected so no handshake for the B server/client connectToGatt no handshake

- client B -> server A
- Server A (client A) connect -> server B

- device E - already have D, B connected so 3rd A
- device D <- device A frozen block

4
-1. If you have more connection doesn't even trigger connection.
0. You need client to connect to do below operations
1. Client (A) read server (B) peerID
2. Client (A) write its own peerID on server (B)

Only when you have read from server only client because of privacy you have 2 mac address on connection.

Server has MAC Address
Client has Mac Address
When read/write happens new MAC Address happens

Device A
After 30 s, the client will disconnect from C, D only, so it will have only 1 active connection.
So scanner will try to connect to 2 other devices (B, C, H, etc). Request priority for the connection you already have. I did balanced. It has to be done after connection or after service discovery because Service discovery will request Low_Latency and also requestMtu request Low_Latency. It has to be done before handshake.

- device A client connected to nobody
- device A server connected to E
- We have 100 devices around
- The scanner have to connected to device E in priority
- The whitelist has two fields: mac address and 4-digits
- So the scanner parse this list before every connection
- Scanner has 3 devices now but 1 of them power off? What now?
- whitelist: B, C, D and we lost B because power off. What now? How do you remove B from whiteList? On Disconnected we remove B from whitelist. So after that new device will be added to whiteList size will be checked. 
- 10 devices connected to the server, so 10 devices in the whitelist but scanner check the limit in the meantime. 

1) in the for loop, we try to find each devices in the whitelist in the foundmap to prioritize them connection.
2) after the for loop, if we have less than 3 connections, we can proceed connection to scan result normally.

- Another solution would be to:
- Add a random group service id for 4 people in the group or each chat everytime it's created and devices will be looking only for that serviceID rather than implementing the logic for the block in the SDK
- For example Device A makes group with Device B and creates the service which will be 4545 and then DeviceB search for devices on 4545 :)

- Conversation Groupd - ID? pass the ID to BLE Driver
- Device 1 - Service for each device to only filter 
- Device 2 - Service for each device to only filter 
- Device 3 - Service for each device to only filter 
- Device 4 - Service for each device to only filter 

## Device A
### Whitelist - check on limit here 3 reconnect attemp
* Device B 30 sec? attemp no ok blacklist
* Device C
* Device E
### Blacklist - decrease connection size 2
* Device B
* Device D
### Connecting
### Connected
* Device C

## Device B
### Whitelist
* Device C
* Device D
* Device E
### Blacklist
### Connecting
### Connected

## Device C
### Whitelist
### Blacklist
### Connecting
### Connected

## Device D
### Whitelist
### Blacklist
### Connecting
### Connected

## Device E
### Whitelist
### Blacklist
### Connecting
### Connected


