Modify bash hash error message and do not add same hash more than once

This commit is contained in:
Carlos 2016-10-22 20:57:39 +03:00
parent 3ba69e169d
commit 73c22c1dea
3 changed files with 18 additions and 16 deletions

2
cachep2p.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -14,6 +14,7 @@ var cached_link_lists = {}
var all_links = [] var all_links = []
var added_links = [] var added_links = []
var history_initialized = false var history_initialized = false
var added_hashes = []
inherits(CacheP2P, EventEmitter) inherits(CacheP2P, EventEmitter)
@ -55,9 +56,10 @@ function CacheP2P(opts, callback){
self.emit('alert', "Please tell a friend to open this site's "+page_link.text+" to see it in action.") self.emit('alert', "Please tell a friend to open this site's "+page_link.text+" to see it in action.")
added_links.push(page_link.href) added_links.push(page_link.href)
sha(page_link.href, function(result){ sha(page_link.href, function(result){
if(added_hashes.indexOf(result) === -1){
var magnet = 'magnet:?xt=urn:btih:'+result+'&dn=Unnamed+Torrent+1476541118022&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.openwebtorrent.com' var magnet = 'magnet:?xt=urn:btih:'+result+'&dn=Unnamed+Torrent+1476541118022&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.openwebtorrent.com'
torrent = client.add(magnet, onTorrent) torrent = client.add(magnet, onTorrent)
added_hashes.push(result)
torrent.on('done', function (info) { torrent.on('done', function (info) {
self.emit('webtorrent', 'Cache received') self.emit('webtorrent', 'Cache received')
@ -68,6 +70,7 @@ function CacheP2P(opts, callback){
torrent.on('wire', function (wire) { torrent.on('wire', function (wire) {
self.emit('webtorrent', 'Peer ('+wire.remoteAddress+') connected over '+wire.type+' (Connection ID: '+wire.peerId.substr(0,10)+').') self.emit('webtorrent', 'Peer ('+wire.remoteAddress+') connected over '+wire.type+' (Connection ID: '+wire.peerId.substr(0,10)+').')
}) })
}
}) })
} }
} }
@ -94,7 +97,6 @@ function CacheP2P(opts, callback){
var got_page = cached_link_lists[each_url] var got_page = cached_link_lists[each_url]
for(var i = 0 ; i < all_links.length ; i++ ){ for(var i = 0 ; i < all_links.length ; i++ ){
if(all_links[i].href === got_page.url){ if(all_links[i].href === got_page.url){
console.log('found link that points to url', each_url)
var link_to_page = all_links[i] var link_to_page = all_links[i]
self.emit('alert', "Security check of content received: "+sha.sync(got_page.page)+"...") self.emit('alert', "Security check of content received: "+sha.sync(got_page.page)+"...")
self.emit('success', "Got this site's '" +all_links[i].text+"' in Cache (sha1: "+got_page.page_hash+" ✔)") self.emit('success', "Got this site's '" +all_links[i].text+"' in Cache (sha1: "+got_page.page_hash+" ✔)")
@ -133,7 +135,7 @@ function CacheP2P(opts, callback){
sha(got_page.page, function (page_hash) { sha(got_page.page, function (page_hash) {
if (page_hash != self.security_sha1[got_page.url]) { if (page_hash != self.security_sha1[got_page.url]) {
self.emit('message', 'Cached version of ' + got_page.url + ' has wrong security hash. This is possibly malicious content! Ignoring the version obtained.'); self.emit('message', 'Cached version of ' + got_page.url + ' received, has wrong security hash, rejecting it.');
return; return;
} }

View file

@ -1,7 +1,7 @@
{ {
"name": "cachep2p", "name": "cachep2p",
"description": "The Peer to Peer Cache for the Masses", "description": "The Peer to Peer Cache for the Masses",
"version": "0.1.4", "version": "0.1.5",
"author": { "author": {
"name": "Carlos Guerrero", "name": "Carlos Guerrero",
"email": "carlos@carlosguerrero.com", "email": "carlos@carlosguerrero.com",