Adaptive random peer sampling protocol running on top of WebRTC.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

spray-wrtc Build Status JavaScript Style Guide npm version

Keywords: Random peer-sampling, adaptive, browser-to-browser communication, WebRTC

This project aims to provide a WebRTC implementation of Spray.

Spray [1] is a random peer-sampling protocol [2] inspired by both Cyclon [3] and Scamp [4]. It adapts the partial view of each member to the network size using local knowledge only. Therefore, without any configuration, each peer automatically adjust its functioning to the need of the network.



Peers joining the network inject a logarithmic number of arcs with them. Thus, a 10-peers network has on average 2.3 connections per peer, a 100-peers network has on average 4.6 connections per peer, a 1000 peers network has on average 6.9 connections per peer etc. Consequently, the number of connections scales well in terms of number of peers.

The figure shows that peers are highly clustered. Furthermore, the oldest peers have many outgoing arcs while the newest only has one outgoing arc. To solve this issue, the peers must periodically shuffle their partial view of the network.

Periodically, a peer chooses one of its neighbor to exchange with. Both peers provide half of their partial view comprising neighbors chosen at random. Both peers disconnect from the neighbors they provided and connect to the neighbors they obtained. Periodic shufflings balance the outgoing arcs among the peers. The resulting network has a low clustering coefficient.


$ npm install spray-wrtc

Find the bundle in bin/spray-wtrtc.bundle.js (debug mode) or in bin/spray-wtrtc.bundle.min.js (production mode)



Peersim [5] simulations of Spray are available at peersim-spray.


[1] B. Nédelec, J. Tanke, D. Frey, P. Molli, and A. Mostéfaoui. Spray: an Adaptive Random Peer Sampling Protocol. Technical Report, LINA-University of Nantes; INRIA Rennes - Bretagne Atlantique, Sept 2015.

[2] M. Jelasity, S. Voulgaris, R. Guerraoui, A.-M. Kermarrec, and M. Van Steen. Gossip-based peer sampling. ACM Transactions on Computer Systems (TOCS), 25(3):8, 2007.

[3] S. Voulgaris, D. Gavidia, and M. van Steen. Cyclon: Inexpensive membership management for unstructured p2p overlays. Journal of Network and Systems Management, 13(2):197–217, 2005.

[4] A. Ganesh, A.-M. Kermarrec, and L. Massoulié. Peer-to-peer membership management for gossip-based protocols. IEEE Transactions on Computers, 52(2):139–149, Feb 2003.

[5] A. Montresor and M. Jelasity. Peersim: A scalable P2P simulator. Proc. of the 9th Int. Conference on Peer-to-Peer (P2P’09), pages 99–100, Seattle, WA, Sept. 2009.