项目作者: RAN3D

项目描述 :
Query Delegation Protocols with Foglet
高级语言: JavaScript
项目地址: git://github.com/RAN3D/foglet-ndp.git
创建时间: 2017-01-16T13:04:24Z
项目社区:https://github.com/RAN3D/foglet-ndp

开源协议:MIT License

下载


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

  1. 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

  1. const NDP = require('foglet-ndp').NDP;
  2. const endpoint = 'https://query.wikidata.org/bigdata/ldf';
  3. const request = [
  4. 'PREFIX wd: <http://www.wikidata.org/entity></http:> SELECT * WHERE { ?s ?p wd:Q142. ?s ?p ?o . } LIMIT 10',
  5. 'PREFIX wd: <http://www.wikidata.org/entity></http:> SELECT * WHERE { ?s ?p wd:Q142. ?s ?p ?o . } OFFSET 10 LIMIT 10',
  6. 'PREFIX wd: <http://www.wikidata.org/entity></http:> SELECT * WHERE { ?s ?p wd:Q142. ?s ?p ?o . } OFFSET 20 LIMIT 10'
  7. ];
  8. const f1 = new NDP({
  9. protocol: 'test-protocol',
  10. webrtc: {
  11. trickle: false,
  12. iceServers: [] //iceServers you have to provide
  13. },
  14. room: 'test'
  15. });
  16. const f2 = new NDP({
  17. protocol: 'test-protocol',
  18. webrtc: {
  19. trickle: false,
  20. iceServers: [] //iceServers you have to provide
  21. },
  22. room: 'test'
  23. });
  24. f1.init();
  25. f2.init();
  26. f1.delegationProtocol.on('ndp-answer', (response) => {
  27. console.log(response)
  28. });
  29. f1.connection().then(status => {
  30. return f1.send(request, endpoint);
  31. });

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.

  1. const Q = require('q'); // use q promises for a better workflow
  2. const DelegationProtocol = require('foglet-ndp').DelegationProtocol;
  3. const NDP = require('foglet-ndp').NDP;
  4. class DummyProtocol extends DelegationProtocol {
  5. use (foglet) {
  6. super.use(foglet);
  7. // listen for incoming delegated request
  8. this.foglet.onUnicast((id, message) => {
  9. if (message.type === 'request') {
  10. this.execute(message.payload)
  11. .then(results => this.emit('ndp-answer', results))
  12. .catch(error => this.emit('ndp-error', error));
  13. }
  14. });
  15. }
  16. send (data, endpoint) {
  17. return Q.Promise((resolve, reject) => {
  18. try {
  19. const peers = self.foglet.getNeighbours();
  20. self.foglet.sendUnicast({
  21. type: 'request',
  22. id: peers.i[0],
  23. payload: data,
  24. endpoint
  25. }, peers.i[0]); // send everything to the first peer
  26. } catch (e) {
  27. reject(e);
  28. }
  29. });
  30. }
  31. execute (data, endpoint) {
  32. console.log('Hey! I need to execute this:' + data + ' @' + endpoint);
  33. return Q(data);
  34. }
  35. }
  36. const f = new NDP({
  37. protocol: 'test-protocol',
  38. webrtc: {
  39. trickle: false,
  40. iceServers: [] //iceServers you have to provide
  41. },
  42. room: 'test',
  43. delegationProtocol: new DummyProtocol()
  44. });
  45. // now use the foglet!

Build the bundle

  1. npm run build:ndp

Test the library

  1. npm test

Doc

  1. 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).