# Adaptive Data Synchronization Algorithm for IoT-Oriented Low-Power Wide-Area Networks
## 4 Adaptive File Synchronization
### On Double Signature Efficiency
Because of the provided signatures on-off switching feature, we define this solution as Adaptive Hashing rdiff (AH-_rdiff_). In contrast to AC-_rdiff_ where the chunk size choice is dependent of (but also constrained to, when referring to the minimum allowed size) the signature dimension, with the AH-_rdiff_ algorithm the use of signatures is defined by the chunk size. ```
1:Input: Current chunk size \(d_{t}\); Token index vector \(\mathcal{P}_{t}\)
2:\(W_{sum}=0\) chunk estimate sum metric
3:\(w=0\) step counter
4:\(N_{ac}=0\) No. consecutive, unmodified chunks
5:for\(m=2\):\(M\)
6:\(i=m-1\)
7:\(\Phi_{i}=p_{m}-p_{m-1}\) Token difference
8:if\(\Phi_{i}==d_{t}\)
9:\(N_{ac}=N_{ac}+1\)
10:else
11:if\(N_{ac}>0\)
12:\(w=w+1\)
13:\(d_{t+1,w}=d_{t}+\mu N_{ac}\)
14:\(W_{sum}=W_{sum}+d_{t+1,w}\)
15:\(N_{ac}=0\)
16:endif
17:\(N_{lUD}=\lceil\dfrac{\Phi_{t}}{d_{t}}-1\rceil\) No. updates detected
18:\(w=w+1\)
19:\(d_{t+1,w}=d_{t}-\mu N_{lUD}\) Partial chunk estimate
20:\(W_{sum}=W_{sum}+d_{t+1,w}\)
21:endif
22:endfor
23:\(d_{t+1}=W_{sum}/w\) Final chunk size estimate
24:return\(d_{t+1}\)
```  
**Algorithm 1** Procedure for adapting the chunk size ```
1:Input: chunk size estimate \(d_{t+1}\); Reference signatures size \(d_{R,ref},d_{S,ref}\)
2:\(\theta_{c}=d_{R,ref}+d_{S,ref}\) Threshold
3:if\(d_{t+1}\leq\theta_{c}\)
4:\(d_{t+1}=d_{R}+d_{S}+1\)
5:endif
6:return\(d_{t+1}\)
```

**Algorithm 2** AC-_rdiff_

### Output Delta Format and Signatures Reference Lists Update

At the end of the file synchronization occurring at time \(t\), the AC-_rdiff_ and AH-_rdiff_ algorithms return a new adapted chunk dimension to be considered during the next file synchronization procedure at time \(t+1\). Concerning AH-_rdiff_, the choice between the signature-based and signature-free synchronization approach is also determined. This reference information must be known also from the cloud, so that it can adequately handle its file update and signature generation in the next synchronization procedure. Therefore, the delta output file \(\Delta_{t}\) sent by the DIoT will contain not only the literal bytes and tokens to be used for file update, but also another field reporting the new chunk size \(d_{t+1}\). Furthermore, in AH-_rdiff_, an additional flag is employed for signaling if the use of signatures is convenient or not (Figure 5). However, it is worth noting that the addition of \(d_{t+1}\) and flag has in general an absolutely negligible impact on the delta file dimension since they can be represented in principle by only a few bits (at most, a couple of bytes). As detailed in Section 3.2, the original _rsync_ algorithm entails that every time a synchronization procedure is performed, the cloud generates two lists of reference signatures, \(\mathcal{R}\) and \(\mathcal{S}\) and sends them to the DIoT in order to start a new synchronization procedure. However, the presence of this download transmission may not be convenient, especially in networks where costs are dependent on the amount of data traffic exchanged. For instance, service fares proposed by some NB-IoT network providers are bounded to a fixed traffic threshold, beyond which additional costs may be required [32; 33]. Therefore, while the uplink data traffic is optimized thanks to the use of AC-_rdiff_ and AH-_rdiff_, a proper management of downlink communication should be also provided to save spectral resources and limit the potential costs related to the traffic volume. Figure 5: Delta structure in original _rsync_, AC-_rdiff_ and AH-_rdiff_ respectively. In this direction, we present a solution where the DIoT generates its own reference signature lists, so that the downlink interaction with the cloud is limited to very sporadic cases. Specifically, the idea is that once the adaptive algorithm (AC-_diff_ or AH-_diff_) has returned the new chunk size \(d_{t+1}\), the DIoT organizes its current file \(F_{DIoT,t}\) in chunks of size \(d_{t+1}\) bytes and calculates the corresponding signatures sets \(\mathcal{R}\) and \(\mathcal{S}\) to be used as reference in the next file synchronization.