Social media, which is used by most individuals, has become an integral part of modern lifestyle. However, these social networks use centralized servers to store user data, which is an approach shown to have many disadvantages such as users having no control over their data or the platform they use. This proposal presents a decentralized social network that utilizes the user's device as storage, while ensuring that data remains secure and authentic, with complete control over user data residing with the user. Furthermore, the implementation of a user data decentralization protocol, along with the design and deployment of a client application capable of seamless communication with other network peers via the decentralized protocol, form the central components of the proposed solution. This protocol is designed to not only be used in the proposed social network, but also to be used in other decentralized systems, such as distributed applications, and other decentralized sharing platforms. RPC style is used to implement the protocol, and LibP2P is used as a base for the protocol which give very robust and flexible P2P foundation for the P2P protocol. Finally, the proposed solution is evaluated by creating a demo social network application, and testing the performance of the decentralized protocol against a traditional REST AP by creating benchmarks applications.
We decided to build Docker images for both hub and peer. it is really easy to build and deploy across different environments.
We created docker compose file to run both hub and peer in the same environment, and linked them together giving the hub address to the peer as an environment variable.
LibP2P is a industrial standard library which use in IPFS, Ethereum, and other blockchain projects for P2P communication. It is a very extensive library, and flexible to use for different purposes. In this project, we use LibP2P to build a P2P communication protocol for our decentralized social media platform. LibP2P has different implementations in different languages, such as Go, JavaScript, Rust, and Java. For this project, we use Go implementation of LibP2P, which is the most mature one.
DeMedia P2P communication protocol is RPC style protocol, for that reason, we use LibP2P's RPC implementation (go-libp2p-gorpc).
LibP2P RPC is a protocol which is built on top of LibP2P, and it is give RPC support for LibP2P with few additional features like
streaming RPC calls using channels and Contexts and async calls.
Multiaddr is a protocol which is used to identify a peer in the network. It is made up of multiple layers of protocols, and it is encode in more human readable way.
First we get information about the peer from the multiaddr, then we do DNS resolution to get the IP address of the peer.
For the DNS resolution, we use the go-multiaddr-dns library.
After we get the address of the peer, we establish a connection with that peer.
RPC client creation is the next step, we use go-libp2p-gorpc library to create RPC client.
Then we cast request payload to byte array, and send it to the peer.
In peer side, we create RPC server, and register RPC methods. After that, we start RPC server, and wait for the requests. When we get a request, we cast request payload to the request struct, and call the related method.
That's how we implement P2P communication protocol for DeMedia.
For the testing, we check how two docker containers communicate with each other.
As mentioned in the results section, P2P communication protocol can not gives effective perform like rest API. It is because of the nature of the P2P communication protocol. It is not designed for the high performance, it is designed for the decentralized communication. It takes more time to establish a connection with the peer. In decentralized systems, it is not a big problem, because we don't need to establish a connection with the peer every time. We can establish a connection with the peer once, and use that connection for the rest of the communication.
Currently, we can not find any reusable P2P communication protocol which flexible enough to use in different decentralized systems. For that reason, we decided to build our own P2P communication protocol. We use LibP2P as a base for our P2P communication protocol. LibP2P is a very extensive library, and it is flexible enough to make different P2P communication protocols. Even DeMedia P2P communication protocol is under perform compare to the rest API, it is still a good solution for the decentralized systems. P2P communication protocol take more time to route the request to the peer, but it is more secure and decentralized. Finding a peer in the network is the most challenging and complex part of any P2P communication protocol. DeMedia P2P communication protocol is not an exception, it is also challenging to find a peer in the network. If someone wants make this protocol more efficient, they should focus on the network discovery part of the protocol. They can be use different techniques to make network discovery more efficient, such as DHT, gossip protocol, and so on.