# Secure Transmission for Buffer-Aided Relay Networks in the Internet of Things
## 2 System Model and Relay Selection Policy
### Relay Selection Policy  
In this subsection, we investigate the max-link relay selection considering the secrecy constraints [13]. To further probe into this relay selection policy mentioned above, the number of the data packets in each buffer is modeled as a state firstly. We define \(s_{n}=\left[\varphi_{n}\left(1\right),\varphi_{n}\left(2\right),\cdots,\varphi_{ n}\left(M\right)\right]^{T}\) as a certain buffer state, where \(\varphi_{n}\left(m\right)\in\left\{0,1,\cdots,L\right\}\ \left(1\leq m\leq M\right)\) denotes the number of data packets in buffer \(B_{m}\) at state \(s_{n}\).  
For the buffer-aided relay \(R_{m}\), when its buffer is full or empty, it means that the relay cannot receive or transmit data packet, i.e., \(\varphi_{n}\left(m\right)=L\) or \(\varphi_{n}\left(m\right)=0\). According to this, \(\phi_{1,n}\left(m\right)=1\) and \(\phi_{2,n}\left(m\right)=1\) denote that the relay \(R_{m}\) can be chosen to receive and transmit data packet at state \(s_{n}\). In other words, the corresponding link is available. On the contrary, \(\phi_{1,n}\left(m\right)=0\) and \(\phi_{2,n}\left(m\right)=0\) represent the link in the first and second hops corresponding to the relay \(R_{m}\) is not available, respectively. Hence, we have \(\phi_{1,n}\left(m\right)=\left\{\begin{array}{ccc}1&,&\varphi_{n}\left(m \right)\
eq L\\ 0&,&\varphi_{n}\left(m\right)=L\end{array}\right.\) and \(\phi_{2,n}\left(m\right)=\left\{\begin{array}{ccc}1&,&\varphi_{n}\left(m \right)\
eq 0\\ 0&,&\varphi_{n}\left(m\right)=0\end{array}\right..\)  
Then, the number of available links at state \(s_{n}\) in the first or the second hops are, respectively, given by  
\[M_{1,n} = \sum_{m=1}^{M}\phi_{1,n}\left(m\right), \tag{1}\] \[M_{2,n} = \sum_{m=1}^{M}\phi_{2,n}\left(m\right). \tag{2}\]  
Based on [13], the relay selection policy can be mathematically expressed as  
\[R^{*}=\arg\max\left\{\left|h_{SR^{\prime}_{M_{1,n}}}\right|^{2},\left|h_{R^{ \prime\prime}_{M_{2,n}}}\right|^{2}\right\}, \tag{3}\]  
Figure 1: System Model.  
where \(\left|h_{SR_{M_{1,n}}^{W}}\right|^{2}=\underset{\varphi_{n}(i)\
eq L}{\max}\left\{ \left|h_{SR_{i}}\right|^{2}\right\}\) denotes the largest channel gain among \(M_{1,n}\) available links in the first hop. Similarly, \(\left|h_{R_{M_{2,n}}^{W}}\right|^{2}=\underset{\varphi_{n}(j)\
eq 0}{\max} \left\{\left|h_{R_{j}D}\right|^{2}\right\}\) is the largest channel gain among \(M_{2,n}\) available links in the second hop.  
From the above expression, we find that the relay with the strongest channel gain is always selected for data transmission. Specifically, when \(R^{*}\) is selected for reception, it receives and decodes the data packet and the packet can be stored in the buffer \(B^{*}\). Hence, the number of packets in the buffer \(B^{*}\) increases by one. Similarly, when \(R^{*}\) is chosen for transmission, the controller \(D\) receives and decodes the data packet, and the buffer \(B^{*}\) discards the packet. Thereby, the number of the packets correspondingly decreases by one. Furthermore, if the whole communication between the source sensor \(S\) and the controller \(D\) is not successful, the buffer state will remain unchanged.