npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

foglet-ndp

v5.0.1

Published

This project aims to provide a simple neighbours delegated protocol and implement various SPARQL query delegation protocols

Downloads

111

Readme

Foglet - Neighbours Delegated Protocol (NDP)

Build Status

Keywords: Simple Neighbours delegated protocol, Random peer sampling, adaptive, browser-to-browser communication, WebRTC

This project aims to provide a simple neighbours delegated protocol in order to reduce query execution time. It works with a random peer sampling protocol [1] and foglet-core [2]. It uses Linked Data Fragments ldf to query endpoints.

By default it uses the Ladda Query Delegation Protocol.

Install

npm install foglet-ndp

Usage

We provide a bundle for you, just add foglet-ndp.bundle.js to your html page. The following example works like a charm and is avalaible in the folder example/ !

!!! You need a signaling server in order to run the example, foglet-core has one embedded, just run: cd node_modules/foglet-core && npm run server

const NDP = require('foglet-ndp').NDP;

const endpoint = 'https://query.wikidata.org/bigdata/ldf';
const request = [
	'PREFIX wd: <http://www.wikidata.org/entity/> SELECT * WHERE { ?s ?p wd:Q142. ?s ?p ?o . } LIMIT 10',
	'PREFIX wd: <http://www.wikidata.org/entity/> SELECT * WHERE { ?s ?p wd:Q142. ?s ?p ?o . } OFFSET 10 LIMIT 10',
	'PREFIX wd: <http://www.wikidata.org/entity/> SELECT * WHERE { ?s ?p wd:Q142. ?s ?p ?o . } OFFSET 20 LIMIT 10'
];

const f1 = new NDP({
	protocol: 'test-protocol',
	webrtc:	{
		trickle: false,
		iceServers: [] //iceServers you have to provide
	},
  room: 'test'
});

const f2 = new NDP({
	protocol: 'test-protocol',
	webrtc:	{
		trickle: false,
		iceServers: [] //iceServers you have to provide
	},
  room: 'test'
});

f1.init();
f2.init();

f1.delegationProtocol.on('ndp-answer', (response) => {
  console.log(response)
});

f1.connection().then(status =>  {
  return f1.send(request, endpoint);
});

Implementing your own delegation protocol

You can create you own custom delegation protocol by extending DelegationProtocol and provides an instance of it when creating a new Foglet-NDP.

const Q = require('q'); // use q promises for a better workflow
const DelegationProtocol = require('foglet-ndp').DelegationProtocol;
const NDP = require('foglet-ndp').NDP;

class DummyProtocol extends DelegationProtocol {

	use (foglet) {
		super.use(foglet);
		// listen for incoming delegated request
		this.foglet.onUnicast((id, message) => {
			if (message.type === 'request') {
				this.execute(message.payload)
					.then(results => this.emit('ndp-answer', results))
					.catch(error => this.emit('ndp-error', error));
			}
		});
	}

	send (data, endpoint) {
		return Q.Promise((resolve, reject) => {
			try {
				const peers = self.foglet.getNeighbours();
				self.foglet.sendUnicast({
					type: 'request',
					id: peers.i[0],
					payload: data,
					endpoint
				}, peers.i[0]); // send everything to the first peer
			} catch (e) {
				reject(e);
			}
		});
	}

	execute (data, endpoint) {
		console.log('Hey! I need to execute this:' + data + ' @' + endpoint);
		return Q(data);
	}
}

const f = new NDP({
	protocol: 'test-protocol',
	webrtc:	{
		trickle: false,
		iceServers: [] //iceServers you have to provide
	},
  room: 'test',
	delegationProtocol: new DummyProtocol()
});

// now use the foglet!

Build the bundle

npm run build:ndp

Test the library

npm test

Doc

npm run doc

Author

Grall Arnaud (Folkvir) Master student at University of Nantes

References

[1] Spray-wrtc Chat-Wane, Spray is a random peer sampling protocol inspired by both Cyclon and Scamp. It adapts the partial view of each member to the network size using local knowledge only. Therefore, without any configurations, each peer automatically adjust itself to the need of the network.

[2] foglet-core Folkvir, Foglet-core is a core library in order to provide a solid infrastructure working with spray-wrtc.

[3] ldf LDF : Linked Data Fragments is a conceptual framework that provides a uniform view on all possible interfaces to RDF, by observing that each interface partitions a dataset into its own specific kind of fragments. A Linked Data Fragment (LDF) is characterized by a specific selector (subject URI, SPARQL query, …), metadata (variable names, counts, …), and controls (links or URIs to other fragments).