CacheP2P icon indicating copy to clipboard operation
CacheP2P copied to clipboard

Create ExpressJS middleware

Open extensionsapp opened this issue 9 years ago • 11 comments

Hello.

How to use CacheP2P on ExpressJS 4? It's possible?

extensionsapp avatar Oct 21 '16 10:10 extensionsapp

Haven't thought about it, sounds interesting.

But the middleware would only need to add the javascript file at the end of the pages, is that what you mean?

guerrerocarlos avatar Oct 21 '16 11:10 guerrerocarlos

https://github.com/PixelsCommander/ViralJS

I think ViralJS has similar functionality.

extensionsapp avatar Oct 21 '16 12:10 extensionsapp

@extensionsapp yes, but ViralJS is susceptible to man-in-the-middle attacks. WebTorrent is encrypted and far more secure a technology than ViralJS

goatandsheep avatar Oct 21 '16 13:10 goatandsheep

@goatandsheep this is fine, make ExpressJS middleware CacheP2P.

var CacheP2P = require('cachep2p');
var CacheP2PContainer = new CacheP2P();
myExpressApp.use(CacheP2PContainer.middleware);

extensionsapp avatar Oct 21 '16 13:10 extensionsapp

@extensionsapp so the middleware would generate the security file based on the routes?

goatandsheep avatar Oct 21 '16 14:10 goatandsheep

@goatandsheep I have a two million pages on my site, need create it's list atomaticly.

document.security_sha1 = {
  'http://cachep2p.com/':                   '8a01e1d8c19294d6ad9a4af20cdab1798e4111b2',
  'http://cachep2p.com/documentation.html': 'c49db33e97c4f81d8fd7b705e707031a37fbdb1c',
  'http://cachep2p.com/contact.html':       '299e74db8950463efa30fb5f30bc17d2fcb5b801',
}

extensionsapp avatar Oct 21 '16 14:10 extensionsapp

@extensionsapp perhaps a webpack plugin

goatandsheep avatar Oct 21 '16 15:10 goatandsheep

@goatandsheep for the system to become popular, I think it would be good to work in "2 clicks".

  1. npm install cachep2p
  2. Add in code
var CacheP2P = require('cachep2p');
var CacheP2PContainer = new CacheP2P();
myExpressApp.use(CacheP2PContainer.middleware);

So it would be very good.

extensionsapp avatar Oct 21 '16 17:10 extensionsapp

@extensionsapp the only way you could to that is with a dynamic security.js file, such that the user's security file is only as big as the number of pages it has cached. When you send your response for each page, you'd send the magnet link. There's no way any user would want to store a 1 million line security file on their computer. and that would kinda defeat the purpose.

goatandsheep avatar Oct 22 '16 14:10 goatandsheep

We could modify CacheP2P to check the checksum of a specific from the server by opening something like for http://www.example.com/content1 check http://www.example.com/content1.checksum and from there, include only the checksum of the links in that page in the HTML it self, so from there on, it can rely on Caches and have the verifications to ensure all those caches are valid.

guerrerocarlos avatar Oct 22 '16 22:10 guerrerocarlos

Any update for this matter? I have implemented something similar in Python and would be glad to work on a pull request for this feature.

tjingrant avatar Sep 09 '17 17:09 tjingrant