## 4 Social Awareness in the Semantic Web of Things
### Cooperative Service/Resource Discovery
Finally, it updates its original post \(P_{1}\) with the updated set of selected services, uncovered parts and like values. The process goes on until at least one of the following conditions becomes true:  
* The request is fully covered or the covering procedure reaches a minimum threshold \(l_{min}\) of like (i.e., satisfaction) value. When a device reaches this limit value, the covering procedure can be stopped, and there is no need to forward the potentially uncovered part of the request to other friends. In this way, each device can prevent the network from being flooded with unnecessary communication which can degrade performance and lead to delays or lost messages;
* A maximum distance \(d_{max}\) from the request source is reached in the social graph. It represents the maximum number of hops a message can make from its original sender during the discovery process. In particular, a direct friend has a depth of 1, whereas a friend of a friend has a depth of 2. This parameter ensures that only nodes within a relevant proximity receive the message, improving the overall efficiency of the network by focusing communication on the most pertinent areas. Basically, the proposed protocol exploits a classic expanding ring search, with the peculiarity that it is not based on topological distance, but on social distance. The proposed service/resource discovery is a distributed process, as outlined in Algorithm 1. When a device holds a request, after performing the local covering process, updating the comment (with the uncovered part of the request) and the like value (with the coverage ratio), (lines 1-4) is finally ready to exploit its social capabilities to identify friends who can advantageously help it in fulfilling the request (lines 5-7). Every friend device receiving the updated request verifies that the distance constraint in the social graph from the original sender is satisfied and starts a new decentralized covering. Then, the uncovered part of the request and the like value are updated. The _forward_to_friends_ procedure (Algorithm 2) goes on recursively to the next level of friends until the request is fully covered, or the like threshold \(l_{min}\) is met, or the social distance limit is reached. ```
0: Device \(D\), Request \(R\), minimum threshold of like \(l_{\min}\), maximum distance \(d_{\max}\)
0: Distributed Service/Resource Discovery
1:\(P\leftarrow\) create_post(\(D,R\)) [Create a post for the request \(R\)]
2:cover_request(\(D,P\)) [ Cover the request \(R\) with \(D\)'s available services]
3:\(l_{test}\_{uncovered\_part}\gets P.\_{commun}[-1]\_{uncovered\_part}\) [Initialize the latest uncovered part]
4:\(l_{test}\_{like\_value}\leftarrow\)\(P.\_{like}\_value\) [Initialize the latest like value]
5:if(\(l_{test}\_{like\_value}<l_{\min}\)and\(l_{test}\_{uncovered\_part}<\)null)then
6: forward_to_friends(\(D,P,l_{test}\_{uncovered\_part},l_{test}\_{like\_value},l_{\min},d_{\max}\)) [Forward the new request to friends]
7:endif
```  
**Algorithm 1**Procedure \(Distributed\_Discovery(D,R,l_{min},d_{max})\)  
```
0: Device \(D\), Post \(P\), Uncovered Part \(U\), Like value \(like\), minimum threshold of like \(l_{\min}\), maximum distance \(d_{\max}\)
0: Forward request to friends
1:if calculate_social_distance(\(D,F\)) \(\leq d_{\max}\)then
2:for\(F\) in select_friends(\(D\))do
3: forward_post(\(F\), \(P\), \(U\)) [Forward the post to the friend \(F\)]
4: cover_request(\(F\), \(U\)) [Cover the request \(U\) with \(F\)'s available services]
5:\(U\gets P.\_{link}\_{value}\)[Update the latest uncovered part]
6:\(like\gets P.\_{link}\_{value}\)[Update the latest like value]
7:if(\(like>l_{\min}\)or\(U=null\))then
8:break(Check if the request is fully covered or meets the like threshold)
9:endif
10: forward_to_friends(\(F\), \(P\), \(U\), \(like\), \(l_{\min}\), \(d_{\max}\)) [Recursively forward the request to the next level of friends]
11:endfor
12:endif
```  
**Algorithm 2**Procedure \(forward\_to\_friends(D,P,U,like,l_{min},d_{\max})\)Both \(l_{min}\) and \(d_{max}\) are tunable parameters.