The flow of Add Peer is illustrated in the diagram.
- My devices do not want to reveal my user-id directly to the neighbors, because it's possible that the neighbor is just some random peer.
- My devices intends to connect to only my friends' devices.
- Initially in the Friend Service, when starting the PM of each friend, we try to connect to the friend-device (friend.PM.LoadPeers)
- When there is a connection established, we go through the IdentifyPeer process (service.PM.IdentifyPeer)
- When we know the user-id of the peer, we go through the FinishIdentifyPeer process (service.Ptt.FinishIdentifyPeer).
- We determine the peer-type of the peer, and register the peer to the corresponding Entities in the FinishIdentifyPeer process.
The steps is as follow:
- When starting the PM of each friend, we try to connect to the friend-device.
- When there is a connection established, we (the requester) think that the connected neighbor is our potential friend. We check with the potential-peer cache, and request identify-peer with the corresponding op-key.
- We (the receiver) receive identify-peer. If we can handle the request successfully, we issue the identify-peer-ack, and request identify-peer to the peer. Otherwise we issue identify-peer-fail to the peer.
- We (the requester) receive identify-peer-ack. If we can handle the ack successfully, we go through finish-identify-peer.
- We (the requester) receive identify-peer-fail. For now, we trust that the potential peer is our friend and we are willing to provide our identity. We issue identify-peer-with-myid to the peer.
- We (the receiver) receive identify-peer-with-myid. We would like to challenge that the peer really owns the user-id. We issue identify-peer-with-myid-challenge to the peer.
- We (the requester) receive identify-peer-with-myid-challenge. We sign the challenge and issue identify-peer-with-myid-challenge-ack to the peer.
- We (the receiver) receive identify-peer-with-myid-challenge-ack. If successfully process the ack, we issue identify-peer-with-myid-ack to the peer.
- We (the requester) receive identify-peer-with-myid-ack. If we successfully process the ack, we go through finish-identify-peer.
The flow of FinishIdentifyPeer is illustrated in the diagram. The steps is as follow:
- We determine the peer-type from all-entities.
- We validate (SetupPeer => addPeerKnownUserID) the peer with peer-type (not reaching max peers of the type).
- We set the peer-type.
- We register the peer to all the entities.
- We put the peer into the NewPeerCh channel, invoking Sync.