# A Secure Opportunistic Network with Efficient Routing for Enhanced Efficiency and Sustainability
## 6 Our Approach: Proposed Model
### Layer 2: Proposed Routing Protocol
#### 6.2.2 Protocol Phases
However, the implementation performed in the simulator is not multithreading; it just tests each message at a time. First, we start with the case when at least one of the nodes does not meet the destination. Note that \(x\) is the time since the current node meets the destination node and \(y\) is the time since the other node meets the destination node. If the current node does not meet the message's destination node, while the other node does, the message will be copied to the output buffer. If the current node does meet the message's destination, while the other node does not, the message will not be copied to the output buffer. However, when both nodes have already met the destination, if the current node's meeting time with the destination is earlier that the other node, and the message will not be copied to the output buffer; otherwise, the message will be copied. This is shown in the flowchart in the case while testing if \(x<y\). The simulation results of the proposed approach show that the new routing protocol, in the early phases of the simulation, acts as direct delivery. That is the case when both nodes do not meet the message's destination node. This results in increased latency. To overcome this problem, in the case when both nodes have not met the message's destination node yet, a Spray and Wait logic is followed. However, the implementation of Spray and Wait here is different than the traditional one. This is why we add a message header field \"Number of Copies\". In case both nodes have not met the message's destination node, the protocol tests whether the number of copies in the message header is greater than zero. A zero value indicates that the message will not be copied to  
Figure 6: Phase 2 functionality. the output buffer. If \"Number of Copies\" is greater than zero, it is set to Floor (_old Number of Copies/2_), that is, if the \"Number of Copies\" is 3, it will become 1. And then, the message will be copied to the output buffer. This will result in spreading the message in the network in a controlled way, not like Epidemic, thus increasing the delivery probability, especially in the early phases of the simulation. * _Phase 4: Send Messages Accepted by the Receiver_ This phase and the next one run at the same time, but this phase runs at the sender side and the next one at the receiver. The sender first accumulates the metadata of all messages in the output buffer in one message and sends them to the receiver. The metadata contain the ID of the message and its size. And then, the sender waits for the receiver to send it a reply for each message. Depending on this reply, the sender decides whether to send the message or to delete it from the output buffer. Note that the receiver replies for each message based on specific criteria discussed in the fifth phase. As shown in Figure 8, the sender waits for a reply from the receiver. Each reply message contains RCV_OK or DENIED_LOW_RESOURCES, and the ID of the message the receiver replies for. If the receiver replies with RCV_OK, the sender sends a message from the output buffer whose  
Figure 7: Phase 3 functionality. ID is in the reply message and then returns to the waiting state. However, if the reply is DENIED_LOW_RESOURCES, the connection between the sender and the receiver is closed. * _Phase 5: Message Acceptance Criteria_  
This phase occurs at the receiver's side when it receives metadata sent by the sender in the fourth phase. If the receiver's node energy is below the minimum threshold, it replies with DENIED_LOW_RESOURCES to the sender and the connection is terminated. Otherwise, the receiver follows specific criteria to choose messages to be relayed in its buffer. If the receiver has enough energy and the message is not in the buffer, a check is performed regarding the message size. If the size of the message is greater than the buffer size, the message will not be accepted. If the free buffer size is greater than or equal to the message size, the message is accepted.