# Development of a Social DTN for Message Communication between SNS Group Members
## 3 How to Build a Social DTN
### DTN Routing Protocol
#### 3.4.3 Algorithm for Receiving Messages  
This subsection describes the Algorithm 2 used by the Discoverer to selectively receive a message from the Advertiser. The acceptance analysis tree in Step 3 is shown in Figure 4.  
Figure 4: Analysis tree to decide whether to accept the received message.  
```
Step 1: The Discoverer starts Nearby Connections API [13] and begins to search for the Advertiser. Step 2: If the Discoverer finds the Advertiser, it compares the Service ID of its own terminal and that of the Advertiser. Case 2-1: If the two Service IDs are not identical, the Discoverer discards the communication with the Advertiser. Go to Step 4. Case 2-2: If the two Service IDs are identical, the Discoverer collects the MAC address of the Advertiser. Go to Step 3. Step 3: The Discoverer decides as follows depending on the type of message it will send: Case 3-1: If the message is rreq_m, the Discoverer decides as follows depending on the role of its node. Case 3-1-1: If the node is a relay node, the Discoverer sets the DA in the TNA, and sets the MAC address of the node that has sent that message in the RNA in its routing table. The Discoverer stores the received message in its storage so that it can forward it to the next relay node. Go to Step 4. Case 3-1-2: If the node is the destination node, the Discoverer sets the SA in the TNA, and sets the MAC address of the node that has sent that message in the RNA in its routing table. It creates rrep_m and stores it in its storage. Go to Step 4. Case 3-2: If the message is rrep_m, the Discoverer checks the following: If 3-2: the DA in each message exists in the TNA in the routing table, THEN 3-2: the Discoverer decides as follows depending on the role of its node. Case 3-2-1: If the node is a relay node, the Discoverer takes out the RNA associated with the TNA and stores it in its storage so that it can forward it to that relay node. The Discoverer sets the SA in the TNA and sets the MAC address of the node that has sent that message in the RNA associated with that TNA in the routing table. Go to Step 4. Case 3-2-2: If the node is a source node, the Discoverer sets the SA in the TNA, and sets the MAC address of the node that has sent that message in the RNA associated with that TNA in the routing table. Go to Step 4. EMSE 3-2: the Discoverer discards the message. Go to Step 4. Case 3-3: If the message is dsnD_m, the Discoverer decides as follows: If 3-3: the DA in each message exists in the TNA in the routing table, THEN 3-3: the Discover decides as follows depending on the role of its node. Case 3-3-1: If the node is a relay node, the Discoverer checks MBoD. If 3-3-1: MBoD = 0, THEN 3-3-1: the Discoverer discards that message. Go to Step 4. ELSE 3-3-1: the Discoverer takes out the RNA associated with the TNA and stores it in its storage so that it can forward it to that relay node. Go to Step 4. Case 3-3-2: If the node is a destination node, the Discoverer takes out the data, and hands them to the application. ELSE 3-3: the Discoverer discards the message. Go to Step 4. Step 4: The Discoverer makes a transition to the halt state.
```  
**Algorithm 2** Algorithm for Receiving Messages