Technology Stack for Decentralized Mobile Services
Total Page:16
File Type:pdf, Size:1020Kb
Technology Stack for Decentralized Mobile Services Matouš Skála Technology Stack for Decentralized Mobile Services by Matouš Skála to obtain the degree of Master of Science at the Delft University of Technology, to be defended publicly on Monday August 31, 2020 at 3:00 PM. Student number: 4893964 Project duration: November 15, 2019 – August 31, 2020 Thesis committee: Dr.ir. J.A. Pouwelse, TU Delft, supervisor Dr. J.S. Rellermeyer, TU Delft Dr. N. Yorke-Smith, TU Delft An electronic version of this thesis is available at http://repository.tudelft.nl/. Preface When I was choosing my thesis topic, I originally came up with an idea of designing a decen- tralized social network. After realizing how ambitious that goal was, I later decided to focus on more fundamental issues first and create a library that would allow for building any de- centralized applications, running purely on an overlay network consisting of smartphones. Rather than reinventing the wheel, I took inspiration from an existing networking library de- veloped at TU Delft over the last decade and created its wire-compatible implementation in Kotlin. Interestingly, in the end, I have even implemented a trivial social network to demon- strate the usage of the library, returning back to the original idea. I would like to thank my supervisor Johan Pouwelse for an endless stream of fresh ideas and valuable feedback, and to PhD students of the Delft Blockchain Lab for numerous coffee meetings and for serving me as a walking documentation of the existing codebase. Matouš Skála Prague, August 2020 iii Contents 1 Introduction1 2 Problem Description3 2.1 Antitrust Battle Against Big Tech...........................3 2.2 The Threat of Super Apps...............................4 2.3 End-to-End Principle Challenged...........................4 2.4 Freedom of Trustworthy Communication......................5 2.5 Research Focus and Structure.............................6 3 State of the Art7 3.1 Decentralized Communication Platforms......................7 3.1.1 Fediverse....................................7 3.1.2 Briar.......................................8 3.1.3 Secure Scuttlebutt...............................8 3.1.4 libp2p...................................... 10 3.1.5 IPv8....................................... 11 3.2 NAT Traversal...................................... 11 3.2.1 Background on NAT Classification...................... 12 3.2.2 Hairpinning................................... 13 3.2.3 Carrier Grade NAT............................... 13 3.2.4 Port Forwarding................................. 13 3.2.5 Session Traversal Utilities for NAT (STUN).................. 14 3.2.6 Traversal Using Relays Around NAT (TURN)................. 14 3.3 Infrastructure-Less Communication......................... 15 3.3.1 Bluetooth.................................... 15 3.3.2 Bluetooth Low Energy............................. 16 3.3.3 Wi-Fi Direct................................... 16 3.3.4 Wi-Fi Aware................................... 16 4 Protocol Design 17 4.1 Identity and Keys.................................... 17 4.2 Peer Discovery..................................... 18 4.2.1 Bootstrap Server................................ 18 4.2.2 Multicast DNS................................. 18 4.2.3 Bluetooth Advertising............................. 18 4.3 Transport Layer..................................... 18 4.3.1 Reliable vs. Unreliable Transport....................... 19 4.3.2 UDP Socket Multiplexing........................... 19 4.3.3 Secure Communication............................ 19 4.3.4 Binary File Transfer over UDP......................... 19 v vi Contents 4.4 NAT Traversal with Peer Introductions........................ 20 4.5 Symmetric NAT Traversal............................... 21 4.5.1 Topological Assumptions........................... 21 4.5.2 NAT Type Detection.............................. 22 4.5.3 Extended Peer Introduction Protocol..................... 22 4.6 Communication with Nearby Devices........................ 24 4.6.1 Introduction to Bluetooth Low Energy.................... 24 4.6.2 BLE Communication Architecture...................... 24 4.7 TrustChain: Scalable Distributed Ledger....................... 26 5 Protocol Implementation 27 5.1 System Architecture.................................. 27 5.2 Communities...................................... 28 5.2.1 Discovery Community............................. 29 5.2.2 TrustChain Community............................ 29 5.3 Discovery Strategies.................................. 29 5.3.1 Random Walk.................................. 30 5.3.2 Periodic Similarity............................... 30 5.3.3 Random Churn................................. 30 5.3.4 Bluetooth Discovery Strategy......................... 30 5.4 Bootstrap Server.................................... 30 5.5 Project Structure.................................... 31 6 Decentralized Super App 33 6.1 PeerSocial: Decentralized Social Network...................... 33 6.1.1 Trustworthy Friendship Establishment.................... 33 6.1.2 Private Messaging Protocol.......................... 34 6.1.3 Public Post Feed................................ 37 6.2 TrustChain Explorer.................................. 38 6.3 Project Structure.................................... 38 7 Evaluation 41 7.1 Analysis and Puncturing of Carrier Grade NAT.................... 41 7.1.1 Experimental Setup.............................. 42 7.1.2 Results...................................... 43 7.2 Social Graph Scalability Experiment......................... 43 7.3 Bootstrap Performance................................ 43 7.4 Blob Transfer Rate................................... 44 7.5 Power Efficiency.................................... 45 7.6 Code Quality...................................... 46 8 Conclusion 47 Bibliography 49 1 Introduction The Internet was created with the idea that any two computers connected to the shared net- work should be able to communicate with each other. It has also been built on the principles of decentralization, without any central entity having the power to take the network down. Yet, 50 years later, we live in a world where most of the services are centralized and user data are stored on the servers owned by a few large profit-oriented companies. In recent years, the idea of decentralization has attracted many in the engineering and research community. Since the introduction of cryptocurrencies in the last decade, there have been many discussions on whether we can decentralize other services, such as social media, or web. With the trend of decentralization, applications are shifting from the client- server model to peer-to-peer, which brings many challenges and calls for a new networking stack. This thesis proposes and implements a protocol for peer to peer (P2P) communication between any two devices. It is implemented as a Kotlin library which can be used on a desk- top, smartphones, tablets, and IoT devices. It can be used to deploy a truly ubiquitous net- work overlay which is available anytime and everywhere. The protocol allows any two devices to establish a direct connection by taking advantage of NAT traversal techniques to connect peers behind different types of middleboxes. When the Internet connection is not available and peers are located in proximity, the connection can be established using Bluetooth Low Energy. The robustness of the NAT traversal mechanism has been tested by conducting a con- nectivity check between devices using the networks of major mobile network operators and home broadband providers in the Netherlands. The mechanism has been shown to be capa- ble of establishing a connection in all tested network conditions. To demonstrate the usage of the library, a decentralized social network with public feeds and private end-to-end encrypted messaging has been implemented. To get feedback on the APIs and general usability of the library, 4 teams of MSc students have been asked to develop non-trivial distributed applications on top of it. Compared to the state of the art solutions, the proposed library combines both nearby and Internet connectivity, does not require any central server, works on a variety of devices under challenging network conditions, and is completely open source. 1 2 Problem Description Over the last decade, the Internet and online services have become omnipresent in everyday lives of citizens across the world – communication, shopping, transportation, accommoda- tion, or financial services are only some examples of services where most of the economic activity has already shifted to the online world. Most of these services are operated by so- called Big Tech [33], the largest and most dominant companies in the information technology industry – Facebook, Amazon, Google to name a few. In fact, 7 most valuable companies in the world are now tech companies. It seems to be nearly impossible to function in a digital world outside of the ecosystems created by the big tech. For instance, we require permission from Google and Apple to publish software for mobile devices. Their monopoly power means no other meaningful method exists to reach billions of smartphone users with newly created apps. 2.1. Antitrust Battle Against Big Tech About 2 billion users interact with Facebook every day. It maintains 75% social media mar- ket share. In a truly free market, they would compete by superior features and providing the best services for their customers to increase consumer welfare. Instead, Facebook has cho- sen to mislead and exploit consumers