# 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  
The operational framework of the proposed model unfolds through a structured sequence of five essential phases, each designed and intricately interconnected. These phases, presented in the remainder of this section, delineate the systematic progression of the protocol, outlining key stages that contribute to the overall functionality and efficacy of the model. Figure 4: Message overhead. Figure 3: Acked Messages table flowchart. Figure 2: Schematic of two required tables. * _Phase 1: Initialization Phase_  
When the connection between two nodes is established, this phase starts. It aims to delete all the acknowledged messages from the buffer of both connecting nodes and update their meeting time. Deleting acknowledged messages will reduce the dropping of undelivered messages from the buffer to make room for new received messages (as we will see in phase 5) and to avoid useless transfer of messages that are already delivered, thus preventing wastage of transmitting and processing time and energy on already delivered messages. As shown in Figure 5, when the connection is established, both nodes exchange their \"Acked Messages tables\", add to their tables the delivered messages present in the received \"Acked Messages table\", and then delete the delivered messages that are present in their own buffer. Note that saving the IDs of delivered messages in a table and exchanging this table when any connection is established is much more efficient than flooding the network with an \"Ack\" message for each delivered message. This will reduce the overhead, the buffer overflow, and the energy. Moreover, the node that has sent the message will be able to detect whether the message is delivered to the destination using this acknowledgment table. After deleting acknowledged messages, both nodes test whether the other node is present in their \"Hosts table\"; if so, they update their meeting time, otherwise the node will be added to the table as well as its meeting time. Once this phase is over, the routing protocol will start the next phase. * _Phase 2: Exchange Deliverables Phase_  
The main role of this phase is to ensure that messages whose destination is the connected node (deliverable messages) are exchanged first. As the buffer contains deliverable messages, and other messages whose final recipients are other nodes in the network, it is important to first exchange the deliverable messages and then start trying to send other messages. This will ensure that the nodes with low power will act as direct delivery nodes (this is shown in phase 5), and if the connection between the nodes is closed suddenly, due to the speed of the nodes or any other malfunctioning, the deliverable messages will be delivered, thus increasing the delivery probability. As shown in Figure 6, the deliverable messages are accumulated at both nodes and then exchanged. Each node updates its \"Acked Messages table\" with the newly delivered messages, and then, if the energy is  
Figure 5: Phase 1 functionality. greater than the threshold energy, the routing protocol moves to the next phase, which illustrates the procedure to deal with other messages in the buffer. Otherwise, the connection is closed to preserve the node's energy, and thus the node acts as a direct delivery node. * _Phase 3: Procedures for Non-Deliverable Messages_ This phase is considered as the core phase of the new routing protocol. Note that at this point, the message buffer contains only non-deliverable messages, \"messages with a final destination other than the connected node\". The main goal of this phase is to accumulate messages that will be suggested to be sent to the other node in a temporary output buffer. Choosing messages that will be put in the output buffer depends on specific criteria shown in Figure 7. The first block in Figure 6 is labeled \"for each message in the buffer\" because this phase could be implemented in a way such that all the messages are processed at the same time.