# SLoPCloud: An Efficient Solution for Locality Problem in Peer-to-Peer Cloud Systems
## 4 Proposed Solutions for Locality Problem in P2P Cloud System
### Hypercube Based Overlay Network  
In this part, we propose our locality solution for Hypercube based overlay P2P cloud systems. The basic idea of this solution is represented in [13]. As mentioned above, the main graph factors that have the major effect on the network performance are the diameter, degree, and scalability, while Hypercube seems to be a good choice with the fairly acceptable values for all of the mentioned factors, simultaneously. In x-dimension Hypercube topology, as in most well-known topologies, the number of nodes is exponentially affected by the change in the number of dimensions. However, the number of nodes is just duplicated with the unity increment in the number of dimensions. The both diameter and the degree of the graph in Hypercube topology are as equal as the number of dimensions. Accordingly, greater degree leads to more neighbors, which makes the access to other nodes easier; however, it also leads to generating more messages for search and any other network operation. As the result, the traffic of the network increases while obviously there is a trade-off between the control traffic and the access space in the network. The other considerable Hypercube property is its optimal routing algorithm. At the initialization phase of the network, network administrator sets the number of Hypercube dimensions and then arrange the position of the first set of nodes, i.e. network starting nodes, on the overlay layer. The position of each node is chosen according to the RTT between the starting nodes. The nodes with lower RTT in between are placed close to each other. While these simple steps are forming the initialization phase of the network, the new node joins the network as follows. Figure 2: Instance of 3-D Hypercube and routing presentation [13]. The new node broadcasts a message to notify all of its neighboring nodes, far away just one physical hop. Time to live (TTL) is used as a bound to limit the propagation. If the new node does not receive any response until a specific timeout, the TTL is increased by one and the operation is continued until the first response. It is worth mentioning that, since each P2P network uses a specific port to send its control messages, just the joined nodes are able to receive such a message. Hence, the responding node is probably the nearest physical node to the new node. Accordingly, we propose to place the new node beside the responder node in the overlay network. It means that the overlay addresses of the two nodes have to differ by just one bit. To assign addresses, the least significant bit is flipped and the new address is checked for whether it is assigned previously to a node. In the negative case, the address is assigned to the new node. Otherwise, the changed bit is reset and the next bit is flipped. This process continues until an address is assigned to the new node. When the new node joins the network, it calculates the RTT among itself and all other nodes that are placed in one or two hops away in the overlay network. This operation is used to update the position of nodes. For two neighbor nodes, if RTT of one node is less than the other, these two nodes are swapped. For example, in the 3-D Hypercube that is illustrated in Figure 2, one message is sent by node \(A\) to neighbor nodes with one or two hops distances and calculates RTT for each node. RTT between node \(A\) and node \(B\) is \(7 ms\), and between node \(A\) and node \(C\) is \(6 ms\). Therefore, node \(B\) and node \(C\) are displaced with each other. RTT between node \(A\) and node \(E\) is less than RTT between node \(A\) and node \(B\), however, they are not swapped because they are not in the same direction. Although node \(E\) is the second node but not the second one in the direction of node \(B\). This process is further repeated for any node that gets new overlay address. To avoid possible falling in loop and infinite repetition of this procedure, each node has to hold its state. The pseudo-code of the solution is represented in Algorithm 1.