Libswift P2p Protocol: an Analysis and Extension
Total Page:16
File Type:pdf, Size:1020Kb
Master Thesis - TRITA-ICT-EX-2012-262 LIBSWIFT P2P PROTOCOL: AN ANALYSIS AND EXTENSION Fu Tang Design and Implementation of ICT products and systems Royal Institute of Technology (KTH) [email protected] October 30th, 2012 Supervisor: Flutra Osmani Examiner: Bj¨ornKnutsson Department: ICT School, NSLab Royal Institute of Technology (KTH) 1 Abstract More and more end-users are using P2P protocols for content sharing, on-demand and live streaming, contributing considerably to overall Internet traffic. A novel P2P streaming protocol named libswift was developed to enable people experience a better service by consuming less resources and transferring less unnecessary functions and metadata. This master thesis studies the inner functioning of libswift and analyzes some of the vulnerabilities that directly impact performance of the protocol, namely download speed and response delay. By investigating the behavior of libswift in scenarios with multiple peers, we found that the lack of a peer selection mechanism inside the protocol affects download efficiency and response time. We also discovered that libswift's internal piece picking algorithm raises competition among peers, thus not fully utilizing connected peers. In addition, we found that current libswift implementation does not follow the specification for PEX peer discovery, thus we modified PEX algorithm to support another message that is used to proactively request new peers from the currently connected. Having made these observations, we designed and implemented a peer selection extension interface that allows for third-party peer selection mechanisms to be used with libswift protocol. Apropos, we tested the interface (or adapter) with an example peer selection mechanism that groups peers according to properties such as latency and locality. Preliminary experimental data shows that using our extension with an external peer selection mechanism enables libswift to select peers based on various metrics and thus enhances its download speed. We argue that libswift is a good protocol for next generation content delivery systems and it can get faster data transfer rates and lower latency by integrating efficient peer selection mechanisms. Contents I Background 7 1 Introduction 8 1.1 Basic Introduction of Libswift . .8 1.2 Problem Description . .9 1.3 Motivation . .9 1.4 Hypothesis . 10 1.5 Goal . 10 1.5.1 Tasks . 10 1.6 Structure . 11 2 Background and Related Work 12 2.1 Peer-to-Peer networks . 12 2.2 Peer-to-Peer protocols . 13 2.3 BitTorrent protocol . 14 2.3.1 Peer tracking and piece picking . 15 2.4 Libswift protocol . 16 2.4.1 Basic operations in libswift . 20 2.5 Related work . 22 2.6 Experimental Evaluation . 27 2.6.1 Extensions for libswift . 28 2.6.2 Software resources and tools . 29 3 Overview and Analysis 30 3.1 Peer discovery basics . 30 1 3.2 Peer exchange and selection . 33 3.3 Analysis of multiple-channel download . 35 3.4 Congestion control . 41 II Design and Implementation 44 4 Protocol Extensions 45 4.1 PEX REQ design . 45 4.2 Design of the adapter . 47 4.2.1 Interaction between components . 49 5 Implementation 52 5.1 Libswift modifications . 52 5.2 Implementation of the adapter module . 55 5.3 Integration with PeerSelector . 59 6 Experimental Evaluation 60 6.1 PEX modifications . 60 6.2 Adapter extension . 61 6.2.1 Experimental results . 63 6.3 Comparison of policies . 68 6.3.1 Side effects of PeerSelector . 70 III Discussion and Conclusions 71 7 Discussion 72 7.1 Libswift . 73 7.2 Extensions . 74 8 Conclusions 76 A Appendix 78 2 List of Figures 2.1 P2P network ........................... 12 2.2 Centralized network ....................... 12 2.3 Metainfo with tracker ...................... 14 2.4 Metainfo, trackerless ...................... 14 2.5 Data request and response ................... 15 2.6 Channels and file transfer ................... 17 2.7 Chunk addressing in libswift .................. 18 2.8 A libswift datagram ....................... 20 2.9 The process of connection ................... 21 2.10 The process of exchanging data ................ 21 3.1 The flow of PEX messages ................... 31 3.2 State machine of the leecher .................. 31 3.3 State machine of the seeder .................. 32 3.4 Message flow I .......................... 34 3.5 Message flow II ......................... 34 3.6 Piece picking algorithm ..................... 35 3.7 Three peers in the same swarm ................ 36 3.8 The setting for three groups .................. 36 3.9 Group 1, trial 1 ......................... 37 3.10 Group 1, trial 2 ......................... 37 3.11 Group 1, trial 3 ......................... 37 3.12 Group 1, trial 4 ......................... 37 3.13 Group 2, trial 1 ......................... 38 3 3.14 Group 2, trial 2 ......................... 38 3.15 Group 2, trial 3 ......................... 38 3.16 Group 2, trial 4 ......................... 38 3.17 Group 3, trial 1 ......................... 39 3.18 Group 3, trial 2 ......................... 39 3.19 Group 3, trial 3 ......................... 39 3.20 Group 3, trial 4 ......................... 39 3.21 Seeder's HAVE and sent DATA messages .......... 40 3.22 Congestion window size ..................... 42 3.23 Overall view ........................... 42 3.24 Detailed view ........................... 42 4.1 Sender side ............................ 46 4.2 Receiver side ........................... 46 4.3 Design overview ......................... 47 4.4 The interaction between components ............. 48 4.5 Adapter and libswift core ................... 49 4.6 Adapter and PeerSelector ................... 50 4.7 API used by PeerSelector ................... 51 4.8 API used by libswift ...................... 51 6.1 Test case 1 ............................ 61 6.2 Test case 2 ............................ 61 6.3 Download performance for Score ............... 64 6.4 Score, trial 1 ........................... 64 6.5 Score, trial 2 ........................... 64 6.6 Download performance for AS-hops ............. 65 6.7 AS-hops, trial 1 ......................... 66 6.8 AS-hops, trial 2 ......................... 66 6.9 Download performance for RTT ................ 67 6.10 RTT, Trial 1 ........................... 67 6.11 RTT, Trial 2 ........................... 67 4 6.12 Download performance for Random ............. 68 6.13 Random, Trial 1 ......................... 69 6.14 Random, Trial 2 ......................... 69 5 List of Tables 6.1 PlanetLab machine properties ................. 62 6.2 Score-selected peers ....................... 63 6.3 AS-hops-selected peers ..................... 65 6.4 RTT-selected peers ....................... 66 6.5 Comparison of policy-based performances .......... 69 6 Part I Background 7 Chapter 1 Introduction During recent years Internet grew rapidly, with many protocols and architectures developed to allow people to get information from the Internet. Apropos, P2P networks and protocols play a very important role to help the end-user retrieve and consume content. 1.1 Basic Introduction of Libswift Libswift is a recently developed P2P protocol that may be understood as BitTorrent at the transport layer [13]. Its mission is to disseminate content among a group of devices. In its current form, it is not only a file-sharing protocol, but it can also be used for streaming on-demand and live video [15]. Using libswift, a group of computers share and download the same file with each other, where each computer is a peer to other computers. These computers and the file together form a swarm. Like BitTorrent1, libswift divides the file into small pieces which can be located among a group of computers. As a result, the files and computers may be located in different countries or cities. This is why we call libswift network a content distributed network. When a user wants to retrieve pieces or the whole content, libswift is responsible to transfer that content back to the user. 1BitTorrent(software) available at http://en.wikipedia.org/wiki/BitTorrent (software) 8 1.2 Problem Description Naturally, users want to get their wanted content or some parts of it as soon as possible [20]. Libswift and other P2P protocols try to retrieve content from several computers at the same time. Just as explained above, several devices may be serving the same content, meaning that the user can download the corresponding content from any computer of the given swarm. If swarm size is, say, five or six then libswift would be requesting pieces from all five or six computers and, as a result, download speed would increase proportionally with swarm size. However, if swarm size were to be around five thousand[19], we should not allow libswift to retrieve pieces from all of the computers as resources of a local PC or a mobile device are limited, including CPU speed, memory, or traffic bandwidth. Each request to another peer would consume some of such resources. If thousands of requests were to be sent concurrently, the local device would exhaust its memory and other resources. In this thesis, we want to improve download performance by limiting the number of simultaneous requests to certain | more wisely chosen | peers only. 1.3 Motivation When we download data from different computers or any other device, we may get different download speeds from each. In a P2P network, there are many factors that may affect the performance of each peer. These factors or properties include, among others, a peer's location [20] and peer's Autonomous System (AS) [30]. Our initial motivation is to study how these properties affect the behavior of libswift and,