# Blockchain-Assisted Adaptive Reconfiguration Method for Trusted UAV Network
## 4 Recommended Scheme
As shown in Figure 2.  
```
1:\(AssessmentNeighbours(TrustState_{i},message_{i})\)
2:#Running in \(ID_{i}\)
3:#0: Timeout for forwarding delay. \(t1\): Timeout for non-forwarding. 4:let:\(t0\gets v1(ms),t1\gets v2(ms)\)
5:#Obtain the list of current neighbor nodes of node \(ID_{i}\)
6:\(curNeighbours[]\gets getNeisFromNDP()\)
7:# The sending time, which is used to accumulate the forwarding timeout. 8:\(curtime\gets getlocaltime()\)
9:#Discount\({}_{j}\): Trustworthiness discount for one forwarding behavior of neighboring nodes \(ID_{j}\). \(count\): The forwarding times of node \(ID_{i}\) during the cycle. 10:\(Discount_{j}\gets 0\)
11:upon received \(message_{j-i}\) from neighbors do
12:# parsing the behavior of neighbor \(ID_{j}\)
13:\(timeout\gets getlocaltime()-curtime\)
14:#message\({}_{j-i}\): The message returned by neighbor node \(ID_{j}\), which is sent by \(ID_{i}\) to determine whether \(ID_{j}\) has tampering behavior. 15:if\(timeout<t0\)then
16:if\(message_{j-i}=message_{i}\)then
17:\(Discount_{j}\gets 0\)
18:endif
19:if\(message_{j-i}\
eq message_{i}\)then
20:\(Discount_{j}\leftarrow-3\)
21:endif
22:if\(timeout>t0\)then
23:if\(message_{j-i}=message_{i}\)then
24:\(Discount_{j}\leftarrow-1\)
25:endif
26:if\(message_{j-i}\
eq message_{i}\)then
27:\(Discount_{j}\leftarrow-3\)
28:endif
29:endif
30:#According to the list of neighbors obtained by NDP protocol, find out the nodes that do not forward data on timeout and define them as selfish nodes. 31:if\(timeout>t1\) and \(ID_{j}\in curNeighbours\)then
32:\(Discount_{j}\leftarrow-2\) /*selfish behavior*/
33:endif
34:#Accumulated trustworthiness loss of neighbor nodes. 35:\(TrustState_{i}.curScore_{j}=TrustState_{i}.curScore_{j}+Discount_{j}\)
36:Output:{TrustState}
```  
**Algorithm 1** Function: AssessmentNeighbours with \(TrustState_{i}\) and \(message_{i}\)
```
1:\(\prime\)**Running in an UAV \(ID_{i}\)*/**
2:\(\#\)\(StateData_{i}\): State Transaction of \(ID_{i}\) in a cycle. 3:Let\(StateData_{i}\leftarrow\{\}\)
4:\(\#\)Pre_Nei: List of original neighboring nodes. 5:Let\(\textit{Pre\_Neis}\leftarrow\{\}\)
6:\(\#\)Cur_Neis: List of current neighboring nodes. 7:Let\(\textit{Cur\_Neis}\leftarrow\{\}\)
8:\(\#\)\(\textit{TrustState}_{i}\): Node \(ID_{i}\)'s neighboring nodes trust discount accumulation. 9:Let\(\textit{TrustState}_{i}\leftarrow\{\}\)
10:\(\#\)\(\textit{bRequireConsensus}\): Node \(ID_{i}\) active request consensus flag. 11:Let\(\textit{bRequireConsensus}\leftarrow\textit{false}\)
12:\(\#\)The number of times node \(ID_{i}\) sends data in the consensus cycle. 13:Let\(nCount\gets 0\)
14:\(\#\)At the beginning of a new consensus cycle, the list of neighbors is taken out and used as a reference for the change of neighbor nodes during the cycle. 15:\(\textit{Pre\_Neis}\gets\textit{GetNeighboursFromNDP}()\)
16:while true do
17:\(\#\)Received Consensus Flag from Authorized Nodes
18:if\(ConsensusFlag=true\)then
19:\(\textit{bRequireConsensus}\leftarrow\textit{true}\)
20:endif
21:\(\#\) Multicast message packets to neighboring nodes. 22:\(Multi\_cast(message_{i},curNeighbours)\)
23:\(\#\) Number of times sent increases. 24:\(count\gets count+1\)
25:\(\#\)Monitor and score the behavior of all neighboring nodes. 26:\(\textit{TrustState}_{i}\leftarrow\textit{AssessmentNeighbours}(\textit{TrustState}_{i}, \textit{message}_{i}\)
27:\(\#\) There are scores less than or equal to 10 in \(\textit{TrustState}_{i}\), requesting to start consensus and reconfigure the network, and isolate the untrustworthy nodes. 28:if\(\textit{ExistIntrustedNeighbour}(\textit{TrustState}_{i})=true\)then
29:\(\textit{bRequireConsensus}\leftarrow\textit{true}\)
30:endif
31:\(\#\)Obtain the latest neighbor node list of node \(ID_{i}\). 32:\(\textit{Cur\_Neis}\leftarrow\textit{GetNeighboursFromNDP}()\)
33:\(\#\) If the change in the list of node \(ID_{i}\) neighbor nodes is too large, request consensus to reconfigure the network.